Repositories / agent-snapshot.git

agent-snapshot.git

Clone (read-only): git clone http://git.guha-anderson.com/git/agent-snapshot.git

Branch

Capture after blobs for written files

Author
Arjun Guha <a.guha@northeastern.edu>
Date
2026-05-02 10:27:59 -0400
Commit
2120b056f4688acdffce5534393ae1a2dfeeafbd
src/main.cpp
index 2e67c31..f96aa29 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -205,9 +205,17 @@ bool path_is_at_or_under(const fs::path& path, const fs::path& root) {
   return true;
 }
 
+bool is_git_internal_path(const fs::path& path) {
+  for (const auto& part : path) {
+    if (part == ".git") return true;
+  }
+  return false;
+}
+
 bool is_ignored_path(const fs::path& raw_path) {
   if (raw_path.empty()) return false;
   fs::path path = best_effort_canonical(raw_path);
+  if (is_git_internal_path(path)) return true;
   for (const auto& ignored : ignored_paths) {
     if (path_is_at_or_under(path, ignored)) return true;
   }
@@ -467,7 +475,10 @@ void finalize_records() {
     rec.after = stat_metadata(path).value_or(Metadata{});
     if (!rec.after.exists) rec.after.tombstone = rec.operations.count("delete") > 0;
     rec.after_git = classify_git(path);
-    if (should_capture_content(path, rec.after, rec.after_git)) {
+    const bool written_regular_file =
+        rec.operations.count("write") > 0 && rec.after.exists && rec.after.regular;
+    if ((written_regular_file && !owned_by_other_and_not_writable(path)) ||
+        should_capture_content(path, rec.after, rec.after_git)) {
       rec.after.blob = store_blob(path);
     }
   }