Skip to content

Fix pre-PR gate sentinel path for git worktrees#28

Merged
alexander-yevsyukov merged 2 commits into
masterfrom
claude/pre-pr-gate-worktree
Jul 1, 2026
Merged

Fix pre-PR gate sentinel path for git worktrees#28
alexander-yevsyukov merged 2 commits into
masterfrom
claude/pre-pr-gate-worktree

Conversation

@alexander-yevsyukov

Copy link
Copy Markdown
Contributor

Problem

scripts/pre-pr-gate.sh — the PreToolUse hook that blocks gh pr create until
/pre-pr has passed — stored and read its sentinel at
$(git rev-parse --show-toplevel)/.git/pre-pr.ok.

In a linked git worktree, $repo_root/.git is a file (a gitdir: pointer),
not a directory, so that path can be neither written nor read. The gate therefore
always blocked gh pr create from a worktree, even after /pre-pr had fully
passed. (Hit while opening SpineEventEngine/config#722
from a Claude Code worktree.)

Fix

Resolve the real git directory with git rev-parse --absolute-git-dir and place
the sentinel there:

  • worktree → the per-worktree git dir (…/.git/worktrees/<name>/)
  • plain clone → …/.git/

so the change is backward-compatible.

Docs updated to match the same resolved-git-dir location:

  • skills/pre-pr/SKILL.md — sentinel write (§6) and the check-links short-circuit read.
  • claude/commands/pre-pr.md — the "Sentinel location" line.
  • skills/check-links/SKILL.md — the sibling check-links.ok sentinel (consumed by
    pre-pr), which had the identical bug.

Verification

bash -n clean. Functional test in a real linked worktree (where .git is a file):

scenario exit meaning
gh pr create, no sentinel 2 blocked — gate still gates
gh pr create, sentinel in git dir 0 allowed — fix works
non-gh pr create command 0 unaffected

🤖 Generated with Claude Code

`pre-pr-gate.sh` wrote and read its sentinel at
`$(git rev-parse --show-toplevel)/.git/pre-pr.ok`. In a linked git worktree
`.git` is a file (a `gitdir:` pointer), not a directory, so that path can be
neither written nor read — the gate always blocked `gh pr create` from a
worktree, even after `/pre-pr` had passed.

Resolve the real git directory with `git rev-parse --absolute-git-dir` and place
the sentinel there. That is the per-worktree git dir in a worktree and plain
`.git` in a regular clone, so the change is backward-compatible.

Update the `pre-pr` skill and command, and the sibling `check-links` sentinel
(which `pre-pr` consumes), to document the same resolved-git-dir location.

Verified in a real linked worktree: the gate still blocks without a sentinel and
now allows once the sentinel is written to the git dir; a plain clone is
unaffected.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings June 30, 2026 16:49

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes the pre-pr gate sentinel location so gh pr create is correctly unblocked after /pre-pr succeeds when working in linked Git worktrees (where .git is a gitdir: pointer file, not a directory). This updates both the hook implementation and the related documentation to reflect “store/read sentinels from the resolved git directory” behavior.

Changes:

  • Update scripts/pre-pr-gate.sh to resolve the git directory via git rev-parse --absolute-git-dir and read pre-pr.ok from there.
  • Update pre-pr and check-links skill docs to describe writing/reading sentinels from the git directory (worktree-safe).
  • Update the Claude /pre-pr command docs to match the new sentinel location guidance.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
scripts/pre-pr-gate.sh Reads the pre-pr.ok sentinel from the resolved git directory to support linked worktrees.
skills/pre-pr/SKILL.md Updates pre-pr.ok sentinel and check-links.ok cache documentation to reference the git directory.
skills/check-links/SKILL.md Updates check-links.ok sentinel documentation to be worktree-safe.
claude/commands/pre-pr.md Updates the documented sentinel location to align with the worktree-safe approach.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread scripts/pre-pr-gate.sh
Comment thread skills/pre-pr/SKILL.md
Comment thread skills/check-links/SKILL.md Outdated
Comment thread claude/commands/pre-pr.md Outdated
@alexander-yevsyukov alexander-yevsyukov self-assigned this Jun 30, 2026
@alexander-yevsyukov alexander-yevsyukov moved this to In Review in v2.0 Jun 30, 2026
@alexander-yevsyukov alexander-yevsyukov moved this from In Review to 🏗 In progress in v2.0 Jun 30, 2026
Address Copilot review on PR #28:

- pre-pr-gate.sh: fall back to `git rev-parse --git-dir` when
  `--absolute-git-dir` is unavailable (Git < 2.13), absolute-izing a
  relative result, so git-dir resolution can no longer fail open via
  `|| exit 0`. On old Git the gate now fails closed (blocks) instead.
- Align the three sentinel-location docs (the `pre-pr` and `check-links`
  skills and the /pre-pr command) on `--absolute-git-dir`, matching the
  command the hook uses to read the sentinel.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@alexander-yevsyukov alexander-yevsyukov moved this from 🏗 In progress to In Review in v2.0 Jun 30, 2026
@alexander-yevsyukov alexander-yevsyukov merged commit 17194ca into master Jul 1, 2026
@alexander-yevsyukov alexander-yevsyukov deleted the claude/pre-pr-gate-worktree branch July 1, 2026 14:04
@github-project-automation github-project-automation Bot moved this from In Review to ✅ Done in v2.0 Jul 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants