diff options
| author | mhegazy <mhegazy@users.noreply.github.com> | 2026-11-05 22:30:42 +0000 |
|---|---|---|
| committer | Claude <noreply@anthropic.com> | 2026-11-05 22:30:42 +0000 |
| commit | 6ba0afbdce92bdafd4b3c7323ba57328455257f4 (patch) | |
| tree | 0298cecc8b3ec7dd4c4aaa1fb90cb0fe6d15e55c /plugins/security-guidance/hooks/gitutil.py | |
| parent | a6e9f5b1f95d3b997cf496e58541fd80b0f2f934 (diff) | |
| parent | 81a14a7f0ab55316795a8eab350393e852d47384 (diff) | |
Merge main into mhegazy/sg-interp-reparse-telemetry
Both sides add a metric after the launcher probe timings on the
SessionStart row; keep launcher_direct, then interp_reparse as the last key.
Diffstat (limited to 'plugins/security-guidance/hooks/gitutil.py')
| -rw-r--r-- | plugins/security-guidance/hooks/gitutil.py | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/plugins/security-guidance/hooks/gitutil.py b/plugins/security-guidance/hooks/gitutil.py index ec51e3c6..75d08298 100644 --- a/plugins/security-guidance/hooks/gitutil.py +++ b/plugins/security-guidance/hooks/gitutil.py @@ -27,8 +27,39 @@ import time from _base import debug_log +def _git_program(windows=os.name == "nt"): + """How to start git. On Windows a bare name is looked up in the process's + working directory before PATH, and the hooks run in the project, so a + `git.exe` there would start in place of the installed one. Name the first + git.exe on PATH instead, leaving out relative entries, the working + directory, and folders inside the project (unless the project holds the + home folder, and with it the user's own tools). With none, a path that + does not exist: git is reported missing, as it would be anywhere else.""" + if not windows: + return "git" + def norm(p): + return os.path.normcase(os.path.normpath(p)) + try: + cwd = norm(os.getcwd()) + except OSError: + cwd = "" + home = norm(os.path.expanduser("~")) + os.sep + roots = [norm(r) for r in (cwd, os.environ.get("CLAUDE_PROJECT_DIR")) if r] + roots = [r.rstrip(os.sep) + os.sep for r in roots if not home.startswith(r.rstrip(os.sep) + os.sep)] + for d in os.environ.get("PATH", "").split(os.pathsep): + d = d.strip().strip('"') + if not d or not os.path.isabs(d) or norm(d) == cwd: + continue + if any((norm(d) + os.sep).startswith(r) for r in roots): + continue + path = os.path.join(d, "git.exe") + if os.path.isfile(path): + return path + return os.path.join(os.path.dirname(os.path.abspath(__file__)), "git.exe") + + GIT_CMD = [ - "git", + _git_program(), "-c", "core.fsmonitor=false", "-c", "core.hooksPath=/dev/null", # core.quotePath=false: emit raw UTF-8 in path-emitting commands instead @@ -62,6 +93,10 @@ GIT_CMD = [ # _drop_gitlinks for the commands that take no such setting. "-c", "diff.ignoreSubmodules=all", "-c", "diff.submodule=short", + # `git log` and `git show` print commit metadata for the hooks to parse. + # With log.showSignature set they would also verify each signed commit, + # adding lines to the output and starting the program gpg.program names. + "-c", "log.showSignature=false", ] # diff.ignoreSubmodules is a default that the repository's own settings for @@ -74,6 +109,7 @@ SAFE_GIT_CONFIG = ( ("core.hooksPath", "/dev/null"), ("diff.ignoreSubmodules", "all"), ("diff.submodule", "short"), + ("log.showSignature", "false"), ) # The hook's git runs in the background beside the session's own git. Without |
