summaryrefslogtreecommitdiff
path: root/plugins/security-guidance/tests
diff options
context:
space:
mode:
authorMohamed Hegazy <mhegazy@anthropic.com>2026-11-04 19:36:21 +0000
committerClaude <noreply@anthropic.com>2026-11-04 20:06:27 +0000
commit2dd1569edd65f7f41cb04790dec1780cbc1e5511 (patch)
tree9c58f2fa03c48b0d02275ab2552e1939d468e2b2 /plugins/security-guidance/tests
parentfa4eb54397ee2faccb6940512a19c017cb1337f3 (diff)
security-guidance: drop every gitlink from the index copy
Whether git starts something in a gitlink's directory is decided when git runs, so the check for a .git there beforehand can go stale. Remove all of them from the copy. On git older than 2.34 the baseline for a submodule that is not checked out falls back to HEAD. Co-authored-by: mhegazy <mhegazy@anthropic.com>
Diffstat (limited to 'plugins/security-guidance/tests')
-rw-r--r--plugins/security-guidance/tests/test_nested_repos.py18
1 files changed, 13 insertions, 5 deletions
diff --git a/plugins/security-guidance/tests/test_nested_repos.py b/plugins/security-guidance/tests/test_nested_repos.py
index 3c93a580..addf9c2e 100644
--- a/plugins/security-guidance/tests/test_nested_repos.py
+++ b/plugins/security-guidance/tests/test_nested_repos.py
@@ -318,8 +318,9 @@ def test_untracked_file_name_is_not_read_as_a_pattern(outer, git_env):
assert name in copy and "other.py" not in copy
-def test_gitlink_without_a_repository_stays_in_the_copy(outer, marker, git_env):
- """A submodule that is not checked out: an empty directory."""
+def test_gitlink_without_a_repository_is_removed_from_the_copy(outer, marker, git_env):
+ """A submodule that is not checked out: an empty directory. Its entry goes
+ too, since a `.git` can appear there before git runs."""
nested = _record_nested_repo(outer, marker)
# Moved, not deleted: git's object files are read-only on Windows.
nested.rename(outer.parent / "moved-away")
@@ -330,9 +331,16 @@ def test_gitlink_without_a_repository_stays_in_the_copy(outer, marker, git_env):
copy = _index_entries(outer, env)
baseline = diffstate.capture_git_baseline(str(outer))
- assert "160000" in copy
- assert baseline and baseline != git(outer, "rev-parse", "HEAD").strip()
- assert diffstate.last_baseline_fail == 0
+ assert "160000" not in copy
+ assert "160000" in git(outer, "ls-files", "-s")
+ head = git(outer, "rev-parse", "HEAD").strip()
+ version = tuple(int(n) for n in git(outer, "--version").split()[2].split(".")[:2])
+ if version >= (2, 34):
+ assert baseline and baseline != head
+ assert diffstate.last_baseline_fail == 0
+ else: # `git stash create` fails on the empty directory
+ assert baseline == head
+ assert diffstate.last_baseline_fail == 1
def test_gitlinks_listed_by_a_git_without_sparse_listing(outer, marker, git_env, monkeypatch):