Skip to content

The agent that grows with you

fix(source-check): strip inherited pathspec modes from read-only git probes

kshitijk4poor064f2f6b09cc
diff --git a/hermes_cli/source_check.py b/hermes_cli/source_check.py
index bda26d17ab9..3397ce7af96 100644
--- a/hermes_cli/source_check.py
+++ b/hermes_cli/source_check.py
@@ -42,8 +42,11 @@ def source_git_env() -> dict[str, str]:
from hermes_cli._subprocess_compat import NO_LAZY_FETCH_ENV, noninteractive_git_env
env = noninteractive_git_env()
+ # Pathspec-mode overrides change how every probe's path arguments match
+ # (GIT_LITERAL_PATHSPECS turns a ":(literal)" magic prefix into filename text).
for key in ("GIT_DIR", "GIT_WORK_TREE", "GIT_COMMON_DIR", "GIT_INDEX_FILE",
- "GIT_OBJECT_DIRECTORY", "GIT_ALTERNATE_OBJECT_DIRECTORIES", "GIT_SHALLOW_FILE", "GIT_NAMESPACE"):
+ "GIT_OBJECT_DIRECTORY", "GIT_ALTERNATE_OBJECT_DIRECTORIES", "GIT_SHALLOW_FILE", "GIT_NAMESPACE",
+ "GIT_LITERAL_PATHSPECS", "GIT_GLOB_PATHSPECS", "GIT_NOGLOB_PATHSPECS", "GIT_ICASE_PATHSPECS"):
env.pop(key, None)
env["GIT_OPTIONAL_LOCKS"] = "0"
env.update(NO_LAZY_FETCH_ENV)
diff --git a/tests/plugins/test_disk_cleanup_plugin.py b/tests/plugins/test_disk_cleanup_plugin.py
index 534e66f5461..9a4ad34f9b4 100644
--- a/tests/plugins/test_disk_cleanup_plugin.py
+++ b/tests/plugins/test_disk_cleanup_plugin.py
@@ -303,6 +303,11 @@ class TestGitWorktreeFilesNeverCleaned:
assert dg._inside_git_worktree(scratch) is False
assert dg.guess_category(tracked) is None
assert dg.guess_category(scratch) == "test"
+ # An inherited pathspec mode must not make the tracked-file probe miss.
+ for mode in ("GIT_LITERAL_PATHSPECS", "GIT_GLOB_PATHSPECS", "GIT_ICASE_PATHSPECS"):
+ monkeypatch.setenv(mode, "1")
+ assert dg._inside_git_worktree(tracked) is True, mode
+ monkeypatch.delenv(mode)
# A stale pre-fix entry is dropped by quick()'s re-validation, not deleted, while
# untracked scratch beside it in the same repo is still cleaned.