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

Function record_reference_transaction

atomic-cli/src/commands/git/hooks.rs:1078–1121  ·  view source on GitHub ↗

CB-9B: journal `reference-transaction` evidence from Git's actual wire format (review blocker 5): the transaction state arrives as `argv[1]` and stdin carries ` ` lines. This is authoritative evidence only that a *committed* ref transaction moved a ref (RFC §5.4); it is never rewrite identity and never triggers import or reconciliation. `preparing`, `prepared`, and `a

(root: &Path, state: &str)

Source from the content-addressed store, hash-verified

1076/// are journal evidence that a transaction ran, but they are NOT proof of
1077/// movement.
1078pub(crate) fn record_reference_transaction(root: &Path, state: &str) -> CliResult<()> {
1079 let root = canonical_root(root)?;
1080 let state = state.to_ascii_lowercase();
1081 // Git ≥2.55 invokes the hook with four states: `preparing` and
1082 // `prepared` (a transaction is staged), `committed` (it landed), and
1083 // `aborted` (it failed). Only `committed` proves movement.
1084 if !matches!(
1085 state.as_str(),
1086 "committed" | "prepared" | "preparing" | "aborted"
1087 ) {
1088 return Err(git_error(format!(
1089 "reference-transaction state must be committed|preparing|prepared|aborted, got '{state}'"
1090 )));
1091 }
1092 let mut stdin = io::stdin().lock();
1093 let mut input = String::new();
1094 stdin
1095 .read_to_string(&mut input)
1096 .map_err(|error| git_error(format!("cannot read reference-transaction input: {error}")))?;
1097 drop(stdin);
1098
1099 let transactions = reference_transaction_entries(&input)?;
1100
1101 if transactions.is_empty() {
1102 return Ok(());
1103 }
1104
1105 let event = RefTransactionEventEvidence {
1106 version: EVENT_VERSION,
1107 record_type: "reference-transaction",
1108 event_id: Uuid::new_v4().to_string(),
1109 recorded_at: Utc::now().to_rfc3339(),
1110 advisory: true,
1111 worktree_root: root.clone(),
1112 interpretation: if state == "committed" {
1113 REF_INTERPRETATION_COMMITTED
1114 } else {
1115 REF_INTERPRETATION_NOT_MOVED
1116 },
1117 state,
1118 transactions,
1119 };
1120 append_journal_record(&root, &event)
1121}
1122
1123/// Parse reference-transaction stdin lines into recorded movements.
1124///

Callers 1

runMethod · 0.85

Calls 7

canonical_rootFunction · 0.85
append_journal_recordFunction · 0.85
lockMethod · 0.80
git_errorFunction · 0.70
is_emptyMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected