Render `status --git` for the repository at `repo_root`.
(repo_root: &Path, json: bool)
| 32 | |
| 33 | /// Render `status --git` for the repository at `repo_root`. |
| 34 | pub fn run_git_status(repo_root: &Path, json: bool) -> CliResult<()> { |
| 35 | let mut repo = |
| 36 | Repository::open_readonly(repo_root).map_err(|e| CliError::InvalidRepository { |
| 37 | reason: e.to_string(), |
| 38 | })?; |
| 39 | |
| 40 | // Observe-only boundary: --git never journals or mutates. |
| 41 | let boundary = repo |
| 42 | .begin_workspace_txn(atomic_repository::WorkspaceTxnMode::Observe) |
| 43 | .map_err(CliError::Repository)?; |
| 44 | |
| 45 | let git_repo = open_git(repo_root)?; |
| 46 | let policy = conversion_policy(&git_repo)?; |
| 47 | |
| 48 | let (staging, shim, remediation_notice) = match boundary { |
| 49 | WorkspaceTxnStart::Ready(workspace) => { |
| 50 | let working_copy = workspace.working_copy(); |
| 51 | let staging = observe_staging_state(&repo, working_copy, &policy) |
| 52 | .map_err(|error| CliError::Internal(error.into()))?; |
| 53 | let shim = ShimSummary { |
| 54 | state: "aligned".to_string(), |
| 55 | origin: if workspace.checkpoint().is_some() { |
| 56 | "checkpoint".to_string() |
| 57 | } else { |
| 58 | "observed".to_string() |
| 59 | }, |
| 60 | view: workspace.view().name.clone(), |
| 61 | atomic_state: workspace.view().state.to_string(), |
| 62 | git_head: workspace |
| 63 | .checkpoint() |
| 64 | .map(|checkpoint| checkpoint.git_head.clone()), |
| 65 | git_tree: workspace |
| 66 | .checkpoint() |
| 67 | .map(|checkpoint| checkpoint.git_tree.clone()), |
| 68 | }; |
| 69 | (staging, shim, None) |
| 70 | } |
| 71 | WorkspaceTxnStart::Remediation(remediation) => { |
| 72 | let mut staging = observe_git_staging_state(repo_root, &policy) |
| 73 | .map_err(|error| CliError::Internal(error.into()))?; |
| 74 | // The remediation notice is rendered once; drop the duplicate |
| 75 | // operation-in-progress notice the raw observation produced. |
| 76 | staging |
| 77 | .notices |
| 78 | .retain(|notice| !matches!(notice, StagingNotice::GitOperationInProgress { .. })); |
| 79 | let head = git_repo.head().ok().and_then(|head| head.target()); |
| 80 | let view = repo |
| 81 | .require_working_copy_id() |
| 82 | .ok() |
| 83 | .and_then(|working_copy| repo.desired_view_name(working_copy).ok()); |
| 84 | let shim = ShimSummary { |
| 85 | state: "remediation".to_string(), |
| 86 | origin: "observed".to_string(), |
| 87 | view: view.unwrap_or_default(), |
| 88 | atomic_state: String::new(), |
| 89 | git_head: head.map(|oid| oid.to_string()), |
| 90 | git_tree: None, |
| 91 | }; |
no test coverage detected