Refresh the verified checkpoint for a detached HEAD (CB-8A Draft policy). Detached HEADs are only coherent with Draft views: the workspace is verified against the view's projected tree and the checkpoint is written with a `None` symref. Anything else stays unsupported.
(
root: &Path,
head: &HeadObservation,
)
| 2227 | /// verified against the view's projected tree and the checkpoint is written |
| 2228 | /// with a `None` symref. Anything else stays unsupported. |
| 2229 | fn refresh_detached_checkpoint( |
| 2230 | root: &Path, |
| 2231 | head: &HeadObservation, |
| 2232 | ) -> CliResult<CheckpointRefresh> { |
| 2233 | use atomic_core::pristine::ViewScope; |
| 2234 | |
| 2235 | let HeadObservation::Detached { oid } = head else { |
| 2236 | return Ok(CheckpointRefresh::SkippedUnsupportedHead); |
| 2237 | }; |
| 2238 | let repo = Repository::open(root).map_err(CliError::from)?; |
| 2239 | let working_copy = repo.require_working_copy_id().map_err(CliError::from)?; |
| 2240 | let view = repo |
| 2241 | .desired_view_name(working_copy) |
| 2242 | .map_err(CliError::from)?; |
| 2243 | let view_state = repo |
| 2244 | .get_view_info(&view) |
| 2245 | .map_err(CliError::from)? |
| 2246 | .state |
| 2247 | .to_string(); |
| 2248 | if repo.get_view_info(&view).map_err(CliError::from)?.scope != ViewScope::Draft { |
| 2249 | return Ok(CheckpointRefresh::SkippedUnsupportedHead); |
| 2250 | } |
| 2251 | let git = open_git(root)?; |
| 2252 | require_clean_git_worktree(&git)?; |
| 2253 | let commit = git |
| 2254 | .find_commit(*oid) |
| 2255 | .map_err(|error| git_error(format!("detached HEAD commit is unreadable: {error}")))?; |
| 2256 | let policy = conversion_policy(&git)?; |
| 2257 | let project = repo |
| 2258 | .project_tree(&view, &policy) |
| 2259 | .map_err(|error| git_error(format!("cannot project Atomic tree: {error}")))?; |
| 2260 | if project.git.root.as_bytes() != commit.tree_id().as_bytes() { |
| 2261 | return Ok(CheckpointRefresh::SkippedViewMismatch); |
| 2262 | } |
| 2263 | verify_complete_equivalence(&repo, &view, root, &git, "Git shim verification")?; |
| 2264 | drop(repo); |
| 2265 | let snapshot = ShimSnapshot { |
| 2266 | view, |
| 2267 | atomic_state: view_state, |
| 2268 | git_head: oid.to_string(), |
| 2269 | git_tree: commit.tree_id().to_string(), |
| 2270 | }; |
| 2271 | write_workspace_metadata(root, &snapshot)?; |
| 2272 | Ok(CheckpointRefresh::Refreshed) |
| 2273 | } |
| 2274 | |
| 2275 | /// CB-13A R2: the operations-head layer of `shim verify`, collected |
| 2276 | /// read-only through the public operation log. |
no test coverage detected