Observe the current Git metadata truth through Git's own APIs.
(root: &Path)
| 122 | |
| 123 | /// Observe the current Git metadata truth through Git's own APIs. |
| 124 | pub(crate) fn observe(root: &Path) -> CliResult<Self> { |
| 125 | let observation = observe_git(root).map_err(|error| CliError::StaleBaseline { |
| 126 | report: format!("shim watch cannot observe Git metadata truth: {error}"), |
| 127 | })?; |
| 128 | let base = match observation { |
| 129 | GitObservation::NoGit { .. } => return Ok(Self::default()), |
| 130 | GitObservation::Repository(repository) => Self { |
| 131 | head_oid: repository.head.oid().map(|oid| oid.to_string()), |
| 132 | head_symref: match &repository.head { |
| 133 | HeadObservation::Attached { symref, .. } => Some(symref.clone()), |
| 134 | _ => None, |
| 135 | }, |
| 136 | head_tree: repository.head_tree_oid.map(|oid| oid.to_string()), |
| 137 | index_digest: Some(repository.index.canonical_digest.0.clone()), |
| 138 | refs_digest: Some(repository.refs_digest.0.clone()), |
| 139 | busy_signature: None, |
| 140 | }, |
| 141 | }; |
| 142 | // The Git-owned transaction state is truth the digests cannot see: |
| 143 | // a lock or marker file's presence changes what the shim may do |
| 144 | // even when every digest is unchanged (review R6). |
| 145 | let metadata = observe_git_metadata(root).map_err(|error| CliError::StaleBaseline { |
| 146 | report: format!("shim watch cannot observe Git state for the hint: {error}"), |
| 147 | })?; |
| 148 | Ok(Self { |
| 149 | busy_signature: match GitQuiescence::evaluate(&metadata) { |
| 150 | GitQuiescence::Quiescent { .. } => None, |
| 151 | GitQuiescence::Busy { reason, detail } => Some(format!("{reason}: {detail}")), |
| 152 | }, |
| 153 | ..base |
| 154 | }) |
| 155 | } |
| 156 | |
| 157 | /// Whether this state differs from `baseline` — i.e. whether a hint |
| 158 | /// fired. Equal states (including the daemon's own prior writes) |
nothing calls this directly
no test coverage detected