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

Function _diff_pathspec

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

Convert absolute touched-paths to repo-relative pathspec args for git diff. Paths outside cwd (e.g. ~/.claude/…) are dropped. Returns the list to splice after `--`, or [] for an unrestricted diff. realpath both sides so the macOS /var ↔ /private/var symlink doesn't make in-repo paths

(cwd, paths)

Source from the content-addressed store, hash-verified

68
69
70def _diff_pathspec(cwd, paths):
71 """Convert absolute touched-paths to repo-relative pathspec args for
72 git diff. Paths outside cwd (e.g. ~/.claude/…) are dropped. Returns the
73 list to splice after `--`, or [] for an unrestricted diff. realpath both
74 sides so the macOS /var ↔ /private/var symlink doesn't make in-repo
75 paths look external."""
76 if not paths:
77 return []
78 cwd_abs = os.path.realpath(cwd)
79 rel = []
80 for p in paths:
81 try:
82 r = os.path.relpath(os.path.realpath(p), cwd_abs)
83 except ValueError:
84 continue
85 if r.startswith(".."):
86 continue
87 rel.append(r)
88 return ["--"] + rel if rel else []
89
90
91@contextlib.contextmanager

Callers 1

get_git_diffFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected