MCPcopy Create free account
hub / github.com/anthropics/claude-code / _git_diff_range

Function _git_diff_range

plugins/security-guidance/hooks/gitutil.py:193–210  ·  view source on GitHub ↗

`git diff -p base head` as text on success, None on error. Distinguishing failure from success-with-empty-diff matters: the push-sweep caller marks the tail reviewed when the diff is empty (nothing to review), but on failure (timeout, non-zero exit, missing git) it must NOT mark the

(repo_root, base, head="HEAD")

Source from the content-addressed store, hash-verified

191
192
193def _git_diff_range(repo_root, base, head="HEAD"):
194 """`git diff -p base head` as text on success, None on error.
195
196 Distinguishing failure from success-with-empty-diff matters: the push-sweep
197 caller marks the tail reviewed when the diff is empty (nothing to review),
198 but on failure (timeout, non-zero exit, missing git) it must NOT mark
199 them reviewed — otherwise unreviewed commits get permanently silenced.
200 """
201 try:
202 r = subprocess.run(
203 [*GIT_CMD, "diff", "-p", "--no-color", "--no-ext-diff", base, head],
204 cwd=repo_root, capture_output=True, timeout=30,
205 )
206 if r.returncode != 0:
207 return None
208 return r.stdout.decode("utf-8", errors="replace")
209 except (subprocess.TimeoutExpired, FileNotFoundError, OSError):
210 return None
211
212
213def _detect_main_branch(repo_root):

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected