MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / enable_anchor_inner

Function enable_anchor_inner

atomic-cli/src/commands/git/anchor.rs:89–168  ·  view source on GitHub ↗
(
    root: &Path,
    options: &EnableAnchorOptions,
)

Source from the content-addressed store, hash-verified

87}
88
89fn enable_anchor_inner(
90 root: &Path,
91 options: &EnableAnchorOptions,
92) -> CliResult<EnableAnchorOutcome> {
93 let Some(key_file) = options.binding_key_file.as_ref() else {
94 return Ok(EnableAnchorOutcome::NotAnchored {
95 refusal: ShimAnchorRefusal::DirtyState {
96 detail: "no --binding-key-file was provided, so the Anchor cannot be signed; \
97 shim enable signs the Anchor with an explicitly supplied Ed25519 \
98 key file only"
99 .to_string(),
100 },
101 });
102 };
103 let signer = load_signing_key(key_file)?;
104
105 let mut repo = Repository::open(root).map_err(CliError::from)?;
106 let git = super::shim::open_git(root)?;
107
108 if options.adopt_atomic {
109 // Explicit remediation: project the Atomic state onto Git through the
110 // safe Atomic-origin path (journaled ref move), then re-prove
111 // equivalence. Pending work is preserved by refusing dirty inputs.
112 let working_copy = repo.require_working_copy_id().map_err(CliError::from)?;
113 let current = current_heads(&repo, working_copy, &git)?;
114 project_atomic_to_git(root, &repo, working_copy, &git, &current).map_err(|error| {
115 CliError::GitError {
116 message: format!(
117 "adopt-atomic remediation refused: {error}; pending work is preserved \
118 until CB-7B — commit or record it, then retry"
119 ),
120 }
121 })?;
122 print_info(
123 "Projected the Atomic state onto Git HEAD (--adopt-atomic); re-proving equivalence.",
124 );
125 }
126
127 // CB-10B (RFC §8.6): assemble the bounded `changes.pack` fallback from the
128 // repository's own hash-verified change store before the anchor publishes.
129 let changes_pack = if options.with_changes_pack {
130 let view = repo
131 .desired_view_name(repo.require_working_copy_id().map_err(CliError::from)?)
132 .map_err(CliError::from)?;
133 let ordered: Vec<atomic_core::Hash> = repo
134 .effective_history(Some(&view))
135 .map_err(CliError::from)?
136 .iter()
137 .map(|entry| entry.hash)
138 .collect();
139 Some(super::binding::assemble_changes_pack_from_view(
140 &repo,
141 ordered.as_slice(),
142 )?)
143 } else {
144 None
145 };
146

Callers 1

run_enable_anchorFunction · 0.85

Calls 15

load_signing_keyFunction · 0.85
openFunction · 0.85
current_headsFunction · 0.85
project_atomic_to_gitFunction · 0.85
print_infoFunction · 0.85
RepositoryClass · 0.85
as_refMethod · 0.80
desired_view_nameMethod · 0.80
effective_historyMethod · 0.80

Tested by

no test coverage detected