`atomic git shim publish --branch `: explicit Draft publication (RFC §8.1, CB-10A AC-2). Publication is create-only and guarded (CB-10A review R3): the shared workspace boundary must accept the workspace before any baseline or ref mutation (Git sequence markers, conflicted/staged index, dirty or unaligned state all refuse), an occupied target branch is a typed refusal, and the ref wr
(view: &str, branch: &str)
| 594 | /// locked and re-compared under Git's own ref lock — behind a journaled |
| 595 | /// expected-absent operation with leased receipts. |
| 596 | pub(crate) fn run_publish(view: &str, branch: &str) -> CliResult<()> { |
| 597 | let root = crate::commands::find_repository_root()?; |
| 598 | let mut repo = Repository::open(&root).map_err(CliError::from)?; |
| 599 | let info = repo.get_view_info(view).map_err(CliError::from)?; |
| 600 | if !matches!(info.scope, ViewScope::Draft) { |
| 601 | return Err(CliError::GitError { |
| 602 | message: format!( |
| 603 | "view '{view}' is {} and already maps to a Git ref; publish applies to Draft views", |
| 604 | if info.scope == ViewScope::Shared { |
| 605 | "shared" |
| 606 | } else { |
| 607 | "unknown-scope" |
| 608 | } |
| 609 | ), |
| 610 | }); |
| 611 | } |
| 612 | if is_ephemeral_view_name(view) { |
| 613 | // Publishing an ephemeral view gives it a branch; the mapping policy |
| 614 | // moves from "no extra ref" to the branch-backed mapping. |
| 615 | } |
| 616 | |
| 617 | // Review R3: the workspace preflight runs BEFORE any baseline or ref |
| 618 | // mutation; a refused publication mutates nothing. |
| 619 | let workspace = enter_workspace(&mut repo, WorkspaceTxnMode::Reconcile)?; |
| 620 | let working_copy = workspace.working_copy(); |
| 621 | let git = GitRepository::open(&root).map_err(|error| CliError::GitError { |
| 622 | message: format!("cannot open Git repository: {error}"), |
| 623 | })?; |
| 624 | crate::commands::git::shim::require_clean_git_worktree(&git)?; |
| 625 | |
| 626 | let target_ref = format!("refs/heads/{branch}"); |
| 627 | // Review R3: publication is create-only. An occupied target is never a |
| 628 | // permissible update — moving existing history requires explicit |
| 629 | // authorization that this command does not have. |
| 630 | if let Ok(reference) = git.find_reference(&target_ref) { |
| 631 | let tip = reference |
| 632 | .target() |
| 633 | .map(|oid| oid.to_string()) |
| 634 | .unwrap_or_else(|| "<symbolic>".to_string()); |
| 635 | return Err(git_error(format!( |
| 636 | "refusing to publish view '{view}': target branch 'refs/heads/{branch}' already \ |
| 637 | exists at {tip}; publication is create-only — delete or rename the branch first" |
| 638 | ))); |
| 639 | } |
| 640 | |
| 641 | let (baseline, _) = ensure_baseline_mapping(&repo, working_copy, &git, view)?; |
| 642 | let draft_ref = baseline |
| 643 | .local_ref |
| 644 | .clone() |
| 645 | .unwrap_or_else(|| format!("refs/atomic/views/{view}")); |
| 646 | let commit = git |
| 647 | .find_reference(&draft_ref) |
| 648 | .ok() |
| 649 | .and_then(|reference| reference.target()) |
| 650 | .or_else(|| { |
| 651 | // An ephemeral draft keeps its adopted commit as the publication |
| 652 | // point. |
| 653 | super::shadow::ephemeral_original_commit(&git, view) |
no test coverage detected