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,
)
| 2271 | /// verified against the view's projected tree and the checkpoint is written |
| 2272 | /// with a `None` symref. Anything else stays unsupported. |
| 2273 | fn refresh_detached_checkpoint( |
| 2274 | root: &Path, |
| 2275 | head: &HeadObservation, |
| 2276 | ) -> CliResult<CheckpointRefresh> { |
| 2277 | use atomic_core::pristine::ViewScope; |
| 2278 | |
| 2279 | let HeadObservation::Detached { oid } = head else { |
| 2280 | return Ok(CheckpointRefresh::SkippedUnsupportedHead); |
| 2281 | }; |
| 2282 | let repo = Repository::open(root).map_err(CliError::from)?; |
| 2283 | let working_copy = repo.require_working_copy_id().map_err(CliError::from)?; |
| 2284 | let view = repo |
| 2285 | .desired_view_name(working_copy) |
| 2286 | .map_err(CliError::from)?; |
| 2287 | let view_state = repo |
| 2288 | .get_view_info(&view) |
| 2289 | .map_err(CliError::from)? |
| 2290 | .state |
| 2291 | .to_string(); |
| 2292 | if repo.get_view_info(&view).map_err(CliError::from)?.scope != ViewScope::Draft { |
| 2293 | return Ok(CheckpointRefresh::SkippedUnsupportedHead); |
| 2294 | } |
| 2295 | let git = open_git(root)?; |
| 2296 | require_clean_git_worktree(&git)?; |
| 2297 | let commit = git |
| 2298 | .find_commit(*oid) |
| 2299 | .map_err(|error| git_error(format!("detached HEAD commit is unreadable: {error}")))?; |
| 2300 | let policy = conversion_policy(&git)?; |
| 2301 | let project = repo |
| 2302 | .project_tree(&view, &policy) |
| 2303 | .map_err(|error| git_error(format!("cannot project Atomic tree: {error}")))?; |
| 2304 | if project.git.root.as_bytes() != commit.tree_id().as_bytes() { |
| 2305 | return Ok(CheckpointRefresh::SkippedViewMismatch); |
| 2306 | } |
| 2307 | verify_complete_equivalence(&repo, &view, root, &git, "Git shim verification")?; |
| 2308 | drop(repo); |
| 2309 | let snapshot = ShimSnapshot { |
| 2310 | view, |
| 2311 | atomic_state: view_state, |
| 2312 | git_head: oid.to_string(), |
| 2313 | git_tree: commit.tree_id().to_string(), |
| 2314 | }; |
| 2315 | write_workspace_metadata(root, &snapshot)?; |
| 2316 | Ok(CheckpointRefresh::Refreshed) |
| 2317 | } |
| 2318 | |
| 2319 | /// CB-13A R2: the operations-head layer of `shim verify`, collected |
| 2320 | /// read-only through the public operation log. |
no test coverage detected