The shared bound bootstrap for an existing Git checkout (RFC §7.3 via the CB-7A anchor machinery). `key_file` signs the Anchor when supplied; the the shim otherwise stays unanchored with the resurrection still journaled. Refuses active Git sequences (merge/rebase in progress) and dirty bootstraps rather than silently merging: the worktree must be clean relative to HEAD, matching the §7.3 clean-ad
(
root: &Path,
key_file: Option<&Path>,
remote_name: &str,
include_degraded: bool,
)
| 346 | /// bootstraps rather than silently merging: the worktree must be clean |
| 347 | /// relative to HEAD, matching the §7.3 clean-adoption gate. |
| 348 | pub(crate) fn adopt_git_checkout( |
| 349 | root: &Path, |
| 350 | key_file: Option<&Path>, |
| 351 | remote_name: &str, |
| 352 | include_degraded: bool, |
| 353 | ) -> CliResult<BootstrapOutcome> { |
| 354 | let mut repo = Repository::open(root).map_err(CliError::Repository)?; |
| 355 | let git = open_git(root)?; |
| 356 | |
| 357 | // Active Git sequences are Git-owned transactions: the bootstrap refuses |
| 358 | // instead of modeling half-applied state (RFC §7.4). |
| 359 | let head = git.head().map_err(|error| CliError::GitError { |
| 360 | message: format!("cannot resolve Git HEAD: {error}"), |
| 361 | })?; |
| 362 | let head_oid = head.target().ok_or_else(|| CliError::GitError { |
| 363 | message: "Git HEAD does not point directly at a commit".to_string(), |
| 364 | })?; |
| 365 | let head_hex = head_oid.to_string(); |
| 366 | |
| 367 | // CB-10B review R4: the shared sequence/dirty preflight, with typed |
| 368 | // evidence for each refusal — an active Git sequence (merge/rebase) and |
| 369 | // a dirty worktree are refused BEFORE any fetch, install, resurrection |
| 370 | // or anchoring runs. A partially dirty adoption would model half-applied |
| 371 | // state the §7.3 clean-adoption gate never verified. |
| 372 | if git.path().join("MERGE_HEAD").exists() { |
| 373 | return Err(CliError::GitError { |
| 374 | message: "refusing to bootstrap: a Git merge is in progress (MERGE_HEAD exists); complete or abort the merge, then re-run the bootstrap" |
| 375 | .to_string(), |
| 376 | }); |
| 377 | } |
| 378 | for sequence_dir in ["rebase-merge", "rebase-apply"] { |
| 379 | if git.path().join(sequence_dir).exists() { |
| 380 | return Err(CliError::GitError { |
| 381 | message: format!( |
| 382 | "refusing to bootstrap: a Git rebase is in progress ({sequence_dir} exists); \ |
| 383 | complete or abort the rebase, then re-run the bootstrap" |
| 384 | ), |
| 385 | }); |
| 386 | } |
| 387 | } |
| 388 | { |
| 389 | let mut statuses = git.statuses(None).map_err(|error| CliError::GitError { |
| 390 | message: format!("cannot inspect the worktree: {error}"), |
| 391 | })?; |
| 392 | let dirty: Vec<String> = statuses |
| 393 | .iter() |
| 394 | .filter(|entry| { |
| 395 | // Untracked files are the ordinary pre-bootstrap state for a |
| 396 | // fresh clone checkout; STAGED or MODIFIED tracked state is |
| 397 | // the partial adoption the gate refuses. |
| 398 | !entry.status().is_wt_new() |
| 399 | }) |
| 400 | .map(|entry| entry.path().unwrap_or("<unknown>").to_string()) |
| 401 | .collect(); |
| 402 | if !dirty.is_empty() { |
| 403 | return Err(CliError::GitError { |
| 404 | message: format!( |
| 405 | "refusing to bootstrap: the worktree has uncommitted tracked state ({}); \ |
no test coverage detected