MCPcopy
hub / github.com/anthropics/claude-code / _git_name_only

Function _git_name_only

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

Return the set of repo-root-relative paths that differ from `base`, or None if git failed (unresolvable ref, not a repo, timeout). Callers must distinguish None (error → don't trust as a filter) from set() (genuinely nothing changed). `-c core.quotePath=false -z` keeps non-ASCII and

(cwd, base, include_untracked=False)

Source from the content-addressed store, hash-verified

301
302
303def _git_name_only(cwd, base, include_untracked=False):
304 """Return the set of repo-root-relative paths that differ from `base`,
305 or None if git failed (unresolvable ref, not a repo, timeout). Callers
306 must distinguish None (error → don't trust as a filter) from set()
307 (genuinely nothing changed). `-c core.quotePath=false -z` keeps non-ASCII
308 and space-containing paths intact."""
309 def _run(env):
310 result = subprocess.run(
311 [*GIT_CMD, "-c", "core.quotePath=false", "diff", "--name-only", "-z", base],
312 cwd=cwd, capture_output=True, text=True, timeout=30,
313 env=env,
314 )
315 if result.returncode != 0:
316 debug_log(f"_git_name_only({base!r}) rc={result.returncode}: {result.stderr[:200]}")
317 return None
318 return {p for p in result.stdout.split("\0") if p}
319
320 try:
321 if not include_untracked:
322 return _run(None)
323 with _temp_index(cwd) as env:
324 return _run(env)
325 except (subprocess.TimeoutExpired, FileNotFoundError, OSError) as e:
326 debug_log(f"_git_name_only({base!r}) error: {e}")
327 return None
328
329
330def _git_status_porcelain(cwd):

Callers 1

compute_v2_review_setFunction · 0.90

Calls 3

debug_logFunction · 0.90
_temp_indexFunction · 0.85
_runFunction · 0.70

Tested by

no test coverage detected