diff options
| author | Mohamed Hegazy <mhegazy@anthropic.com> | 2026-11-04 19:36:21 +0000 |
|---|---|---|
| committer | Claude <noreply@anthropic.com> | 2026-11-04 20:06:27 +0000 |
| commit | 2dd1569edd65f7f41cb04790dec1780cbc1e5511 (patch) | |
| tree | 9c58f2fa03c48b0d02275ab2552e1939d468e2b2 /plugins/security-guidance/hooks/gitutil.py | |
| parent | fa4eb54397ee2faccb6940512a19c017cb1337f3 (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/hooks/gitutil.py')
| -rw-r--r-- | plugins/security-guidance/hooks/gitutil.py | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/plugins/security-guidance/hooks/gitutil.py b/plugins/security-guidance/hooks/gitutil.py index ec51e3c6..1a0a65e2 100644 --- a/plugins/security-guidance/hooks/gitutil.py +++ b/plugins/security-guidance/hooks/gitutil.py @@ -800,20 +800,20 @@ def _drop_gitlinks(top, env, tmp_index): anything else runs on the copy. A gitlink marks a directory that is, or can be, another repository (see diff.ignoreSubmodules in GIT_CMD): `git stash create` takes no flag like IGNORE_SUBMODULES, and `git add` - reads the gitlinks its paths cover. An entry whose directory has no - `.git` stays: git starts nothing there, and without the entry an older - `git stash create` fails on the empty directory. `top` is the work - tree's top directory. Returns True on success, False on any failure; the - copy must not be used then.""" + reads the gitlinks its paths cover. Every gitlink goes, including one + whose directory has no `.git` now: whether git starts something there is + decided when git runs, not here. Without the entry, `git stash create` on + git older than 2.34 fails on a submodule that is not checked out, and the + baseline falls back to HEAD. `top` is the work tree's top directory. + Returns True on success, False on any failure; the copy must not be used + then.""" try: if not _may_have_gitlinks(tmp_index): return True gitlinks = _gitlink_paths(top, env) if gitlinks is None: return False - top_b = os.fsencode(top) - nested = sorted(p for p in gitlinks - if os.path.lexists(os.path.join(top_b, p, b".git"))) + nested = sorted(gitlinks) if not nested: return True mtime_ns = os.stat(tmp_index).st_mtime_ns |
