Repositories / agent-snapshot.git
agent-snapshot.git
Clone (read-only): git clone http://git.guha-anderson.com/git/agent-snapshot.git
@@ -0,0 +1,6 @@ +from pathlib import Path + +root = Path(__file__).resolve().parents[1] +path = root / "testdata" / "clean.txt" + +path.write_text(path.read_text())
@@ -0,0 +1,5 @@ +from pathlib import Path + +root = Path(__file__).resolve().parents[1] + +(root / ".git" / "delete_me").write_text("internal git scratch\n")
@@ -48,6 +48,14 @@ def pristine_testdata(): @pytest.fixture(autouse=True) +def pristine_git_internal_file(): + internal = ROOT / ".git" / "delete_me" + internal.unlink(missing_ok=True) + yield + internal.unlink(missing_ok=True) + + +@pytest.fixture(autouse=True) def ignore_config(tmp_path, monkeypatch): config_home = tmp_path / "xdg-config" config_path = config_home / "agent-snapshot" / "ignore.json" @@ -172,6 +180,23 @@ def test_clean_git_tracked_read_records_repo_without_blob(tmp_path): assert any(repo["root"] == str(ROOT.resolve()) for repo in snap.manifest["git_repositories"]) +def test_git_internal_directory_writes_are_ignored(tmp_path): + snap = capture(tmp_path, PYTHON, "test_programs/write_git_internal.py") + manifest_paths = {item["path"] for item in snap.manifest["files"]} + + assert str((ROOT / ".git" / "delete_me").resolve()) not in manifest_paths + + +def test_written_clean_git_tracked_file_gets_after_blob(tmp_path): + snap = capture(tmp_path, PYTHON, "test_programs/rewrite_clean_tracked.py") + clean = snap.file(TESTDATA / "clean.txt") + + assert "write" in clean["operations"] + assert clean["git"]["tracked"] is True + assert clean["git"]["dirty"] is False + assert snap.blob_text(clean["after"]["blob"]) == (TESTDATA / "clean.txt").read_text() + + def test_dirty_untracked_created_and_deleted_files_are_captured(tmp_path): # This test covers the cases where Git metadata is not enough: # - dirty tracked files differ from HEAD, so their content must be blobbed