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

Function _git_dir

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

Absolute shared `.git` directory for repo_root. Uses `rev-parse --git-common-dir` so linked worktrees resolve to the SHARED gitdir, not the per-worktree `.git/worktrees/ /`. That way push-sweep's reviewed-shas record (and the bash-hook-once sentinel) is per-clone — a commit rev

(repo_root)

Source from the content-addressed store, hash-verified

154
155
156def _git_dir(repo_root):
157 """Absolute shared `.git` directory for repo_root.
158
159 Uses `rev-parse --git-common-dir` so linked worktrees resolve to the
160 SHARED gitdir, not the per-worktree `.git/worktrees/<name>/`. That way
161 push-sweep&#x27;s reviewed-shas record (and the bash-hook-once sentinel)
162 is per-clone — a commit reviewed in one worktree counts as reviewed
163 if a different worktree later pushes it. Returns None on failure so
164 callers can degrade (push-sweep state is best-effort).
165 """
166 try:
167 r = subprocess.run(
168 [*GIT_CMD, "rev-parse", "--git-common-dir"],
169 cwd=repo_root, capture_output=True, text=True, timeout=5,
170 )
171 if r.returncode != 0:
172 return None
173 d = r.stdout.strip()
174 return d if os.path.isabs(d) else os.path.join(repo_root, d)
175 except (subprocess.TimeoutExpired, FileNotFoundError, OSError):
176 return None
177
178
179def _git_rev_list_range(repo_root, base, head="HEAD"):

Callers 2

_reviewed_shas_pathFunction · 0.90
_claim_bash_hook_onceFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected