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

Function verify_receive_updates

atomic-cli/src/commands/git/verify_receive.rs:69–164  ·  view source on GitHub ↗

The stdin-independent core of the verifier (also the test seam).

(
    root: &Path,
    unprotected: &[String],
    input: &str,
)

Source from the content-addressed store, hash-verified

67
68/// The stdin-independent core of the verifier (also the test seam).
69pub(crate) fn verify_receive_updates(
70 root: &Path,
71 unprotected: &[String],
72 input: &str,
73) -> CliResult<()> {
74 let lines: Vec<String> = input
75 .lines()
76 .map(str::trim)
77 .filter(|line| !line.is_empty())
78 .map(ToString::to_string)
79 .collect();
80 if lines.is_empty() {
81 return Err(CliError::GitError {
82 message: "verify-receive received no ref-update lines; refusing (fail closed)"
83 .to_string(),
84 });
85 }
86
87 let repo = Repository::open_readonly(root).map_err(CliError::Repository)?;
88 let git_repo = GitRepository::open(root).map_err(|error| CliError::GitError {
89 message: format!("cannot open receiving Git repository: {error}"),
90 })?;
91
92 let mut refusals: Vec<ReceiveRefusal> = Vec::new();
93 let mut verified = 0usize;
94
95 for line in &lines {
96 let Some((old, new, ref_name)) = parse_ref_update(line) else {
97 refusals.push(ReceiveRefusal {
98 ref_name: line.to_string(),
99 reason: "malformed ref-update line (expected '<old> <new> <ref>')".to_string(),
100 });
101 continue;
102 };
103
104 if is_unprotected(ref_name, unprotected) {
105 print_info(&format!(
106 "{ref_name}: explicitly unprotected; no managed-provenance verification"
107 ));
108 continue;
109 }
110
111 // Deletions move no state to verify.
112 if new.is_zero() {
113 verified += 1;
114 continue;
115 }
116
117 match verify_ref_update(&repo, &git_repo, old, new, ref_name) {
118 Ok(delta) => {
119 verified += 1;
120 print_info(&format!(
121 "{ref_name}: verified {delta} change(s) at the receiving boundary"
122 ));
123 }
124 Err(reason) => refusals.push(ReceiveRefusal {
125 ref_name: ref_name.to_string(),
126 reason,

Calls 14

openFunction · 0.85
parse_ref_updateFunction · 0.85
is_unprotectedFunction · 0.85
print_infoFunction · 0.85
verify_ref_updateFunction · 0.85
print_warningFunction · 0.85
print_successFunction · 0.85
emit_lossyMethod · 0.80
collectMethod · 0.45
linesMethod · 0.45
is_emptyMethod · 0.45
pushMethod · 0.45