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

Function resolve_common_dir

atomic-cli/src/commands/git/observation.rs:1439–1468  ·  view source on GitHub ↗
(worktree_git_dir: &Path)

Source from the content-addressed store, hash-verified

1437}
1438
1439pub(super) fn resolve_common_dir(worktree_git_dir: &Path) -> Result<PathBuf, ObservationError> {
1440 let path = worktree_git_dir.join("commondir");
1441 let bytes = match fs::read(&path) {
1442 Ok(bytes) => bytes,
1443 Err(error) if error.kind() == io::ErrorKind::NotFound => {
1444 return Ok(worktree_git_dir.to_path_buf());
1445 }
1446 Err(error) => {
1447 return Err(ObservationError::new(format!(
1448 "cannot read Git common-dir pointer '{}': {error}",
1449 path.display()
1450 )));
1451 }
1452 };
1453 let value = bytes.strip_suffix(b"\n").unwrap_or(&bytes);
1454 let value = value.strip_suffix(b"\r").unwrap_or(value);
1455 if value.is_empty() || value.contains(&0) || value.contains(&b'\n') || value.contains(&b'\r') {
1456 return Err(ObservationError::new(format!(
1457 "Git common-dir pointer '{}' is malformed",
1458 path.display()
1459 )));
1460 }
1461 let value = std::str::from_utf8(value).map_err(|_| {
1462 ObservationError::new(format!(
1463 "Git common-dir pointer '{}' is not valid UTF-8",
1464 path.display()
1465 ))
1466 })?;
1467 resolve_path(Path::new(value), worktree_git_dir)
1468}
1469
1470fn resolve_path(path: &Path, base: &Path) -> Result<PathBuf, ObservationError> {
1471 let absolute = if path.is_absolute() {

Callers 2

detect_linked_worktreeFunction · 0.85
observe_open_repositoryFunction · 0.85

Calls 5

resolve_pathFunction · 0.85
readFunction · 0.50
kindMethod · 0.45
is_emptyMethod · 0.45
containsMethod · 0.45

Tested by

no test coverage detected