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)
| 68 | |
| 69 | |
| 70 | def _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 |