Observe Git at `root` without modifying Git, Atomic, or the working tree.
(root: &Path)
| 507 | |
| 508 | /// Observe Git at `root` without modifying Git, Atomic, or the working tree. |
| 509 | pub fn observe_git(root: &Path) -> Result<GitObservation, ObservationError> { |
| 510 | let resolved_root = resolve_path(root, root)?; |
| 511 | let git_marker_exists = fs::symlink_metadata(root.join(".git")).is_ok(); |
| 512 | let repository = match GitRepository::open(root) { |
| 513 | Ok(repository) => repository, |
| 514 | Err(error) if error.code() == ErrorCode::NotFound && !git_marker_exists => { |
| 515 | return Ok(GitObservation::NoGit { |
| 516 | root: resolved_root, |
| 517 | }); |
| 518 | } |
| 519 | Err(error) => { |
| 520 | return Err(ObservationError::new(format!( |
| 521 | "cannot read Git repository at '{}': {error}", |
| 522 | root.display() |
| 523 | ))); |
| 524 | } |
| 525 | }; |
| 526 | |
| 527 | observe_open_repository(root, &repository) |
| 528 | .map(Box::new) |
| 529 | .map(GitObservation::Repository) |
| 530 | } |
| 531 | |
| 532 | /// Observe an already-open repository. This helper is also used by the shim |
| 533 | /// to share HEAD interpretation without changing its mutating reconcile path. |