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

Function managed_commit_selection_mismatch

atomic-agent/src/record/mod.rs:1040–1095  ·  view source on GitHub ↗

Why recording this turn would NOT reproduce `commit` exactly, or `None` when it would (CB-12A follow-up AC-8). A clean Git worktree only proves "worktree == commit tree" in Git's terms. The recorder decides for itself what a turn contains: tracked changes in `status` (already narrowed by any ownership manifest) plus the untracked paths it will auto-add. A commit is exact only when those two sets

(
    repo_root: &Path,
    parent: &str,
    commit: &str,
    status: &RepositoryStatus,
    untracked_paths: &[String],
)

Source from the content-addressed store, hash-verified

1038/// directory in the commit therefore keeps the durable refusal instead of a
1039/// partial record.
1040fn managed_commit_selection_mismatch(
1041 repo_root: &Path,
1042 parent: &str,
1043 commit: &str,
1044 status: &RepositoryStatus,
1045 untracked_paths: &[String],
1046) -> Option<String> {
1047 use atomic_repository::status::FileStatus;
1048 use std::collections::BTreeSet;
1049
1050 let Some(changed) = commit_changed_paths(repo_root, parent, commit) else {
1051 return Some("the commit's changed paths are unreadable".to_string());
1052 };
1053 if changed.is_empty() {
1054 return Some("the commit changes no content".to_string());
1055 }
1056 for entry in &changed {
1057 let regular = |mode: &str| mode == GIT_ABSENT_MODE || mode == GIT_REGULAR_MODE;
1058 if !regular(&entry.old_mode) || !regular(&entry.new_mode) {
1059 return Some(format!(
1060 "'{}' is not a regular file in the commit (mode {} -> {})",
1061 entry.path, entry.old_mode, entry.new_mode
1062 ));
1063 }
1064 }
1065 if let Some(path) = file_directory_swap(&changed) {
1066 return Some(format!(
1067 "the commit replaces a file with a directory, or a directory with a file, at \
1068 '{path}', which one Atomic change cannot record"
1069 ));
1070 }
1071 let committed: BTreeSet<&str> = changed.iter().map(|entry| entry.path.as_str()).collect();
1072 let tracked: Vec<String> = status
1073 .entries()
1074 .iter()
1075 .filter(|entry| !matches!(entry.status(), FileStatus::Clean | FileStatus::Untracked))
1076 .map(|entry| entry.path().to_string_lossy().to_string())
1077 .collect();
1078 let recorded: BTreeSet<&str> = tracked
1079 .iter()
1080 .chain(untracked_paths.iter())
1081 .map(String::as_str)
1082 .filter(|path| !is_atomic_private_path(path))
1083 .collect();
1084 if let Some(path) = committed.difference(&recorded).next() {
1085 return Some(format!(
1086 "the commit changes '{path}', which this turn would not record"
1087 ));
1088 }
1089 if let Some(path) = recorded.difference(&committed).next() {
1090 return Some(format!(
1091 "this turn would record '{path}', which the commit does not change"
1092 ));
1093 }
1094 None
1095}
1096
1097/// The durable refusal for a managed commit that Git calls exact but whose

Calls 10

commit_changed_pathsFunction · 0.85
file_directory_swapFunction · 0.85
is_atomic_private_pathFunction · 0.85
entriesMethod · 0.80
is_emptyMethod · 0.45
collectMethod · 0.45
iterMethod · 0.45
as_strMethod · 0.45
pathMethod · 0.45
nextMethod · 0.45

Tested by

no test coverage detected