MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / resolve_path

Method resolve_path

atomic-cli/src/commands/init.rs:393–414  ·  view source on GitHub ↗

Resolve the target path to an absolute path. If the path is relative, it's resolved relative to the current working directory.

(&self)

Source from the content-addressed store, hash-verified

391 /// If the path is relative, it's resolved relative to the current
392 /// working directory.
393 fn resolve_path(&self) -> CliResult<PathBuf> {
394 // On Windows, Path::is_absolute() returns false for Unix-style "/foo"
395 // paths (they're drive-relative). Treat a leading '/' as absolute on
396 // all platforms so cross-platform tests and user input behave the same.
397 let looks_absolute =
398 self.path.is_absolute() || self.path.to_string_lossy().starts_with('/');
399 let path = if looks_absolute {
400 self.path.clone()
401 } else {
402 let cwd =
403 std::env::current_dir().map_err(|e| CliError::invalid_path(&self.path, Some(e)))?;
404 cwd.join(&self.path)
405 };
406
407 // Canonicalize if the path exists, otherwise just normalize it
408 if path.exists() {
409 path.canonicalize()
410 .map_err(|e| CliError::invalid_path(&self.path, Some(e)))
411 } else {
412 Ok(path)
413 }
414 }
415
416 /// Create the .atomicignore file if a kind is specified.
417 fn create_ignore_file(&self, repo_path: &Path) -> CliResult<bool> {

Callers 4

runMethod · 0.45
test_resolve_path_dotFunction · 0.45

Calls 2

cloneMethod · 0.45
existsMethod · 0.45

Tested by 3

test_resolve_path_dotFunction · 0.36