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

Method resolve_path

atomic-cli/src/commands/init.rs:386–407  ·  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

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