Skip to content

Commit f0ad8c5

Browse files
authored
Merge pull request #80 from netresearch/feat/retro-pr-race-and-worktree-hooks
docs: PR-race, self-merge, and fresh-worktree-hook learnings
2 parents d69c991 + 32ce8e2 commit f0ad8c5

2 files changed

Lines changed: 59 additions & 0 deletions

File tree

skills/git-workflow/references/git-hooks-setup.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,27 @@ against the repo root, before inspecting it.
142142
`/dev/null` — is portable to Windows) and `git push --no-verify`. Never
143143
make the bypass the default; fix the hook environment or commit from the
144144
primary checkout when possible.
145+
146+
### Fresh worktree: missing deps and stale `hooksPath`
147+
148+
A freshly-created worktree often breaks pre-commit/pre-push hooks — and can even
149+
abort the worktree creation itself:
150+
151+
- It has no `vendor/`/`node_modules`, so a hook binary (`vendor/bin/grumphp`,
152+
`captainhook`, a husky script) is missing.
153+
- A stale or broken `core.hooksPath` points at a nonexistent binary in **another**
154+
worktree.
155+
156+
Either failure aborts worktree-add, commits, and pushes. Bypass cleanly and
157+
**scoped** — don't disable hooks globally:
158+
159+
```bash
160+
git -c core.hooksPath=/dev/null commit -s ... # scoped to this one command
161+
git push --no-verify
162+
```
163+
164+
(`core.hooksPath="$(mktemp -d)"` is the Windows-portable equivalent — see the
165+
controlled-bypass note above.) CI is authoritative for these repos (see "Hooks
166+
Are Fast Feedback — CI Is the Gate"), so a scoped bypass here is safe. Also: in a
167+
fresh worktree, `Read` a file before `Write`/`Edit` — there is no cached state
168+
for a path the tooling has not seen yet.

skills/git-workflow/references/pull-request-workflow.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,6 +1018,41 @@ Other ruleset rules to expect: `required_approving_review_count`, `required_revi
10181018
> about merge-readiness — see the Merge-Gate Command above plus this ruleset
10191019
> call. Discovering gates one round-trip at a time is the anti-pattern.
10201020
1021+
## Self-Authored PR Merge (Permission Classifier)
1022+
1023+
When you drive your own PR to merge (e.g. via `/pr-finish`), the auto-mode
1024+
permission classifier blocks self-merges and admin self-bypass — a self-authored
1025+
merge is treated as requiring a human. Do **not** attempt the merge twice and
1026+
then bounce to the human; two denials read as stalling.
1027+
1028+
- Recognize up front that finishing a self-authored PR will hit the classifier,
1029+
and settle the merge path **before** starting.
1030+
- For archive/cleanup tasks, take the local-clone + signed-commit + PR path from
1031+
the start — not a Contents-API commit or an admin bypass the classifier will
1032+
reject.
1033+
- If a human merge is genuinely required, ask **one** structured question up
1034+
front rather than discovering the block via two denials.
1035+
1036+
## Shared-Account and Parallel-Job PR Races
1037+
1038+
When several agent jobs run under the **same** git/GitHub identity (a shared
1039+
bot/CI account), a PR can be force-pushed or merged out from under your review or
1040+
take-over by a parallel job — and you cannot prove your own job didn't do it.
1041+
Defend:
1042+
1043+
1. **Snapshot head + merge state** at the start of any review/take-over, and
1044+
re-check immediately before acting; abort or rebase if it moved:
1045+
1046+
```bash
1047+
gh pr view <NUMBER> --json headRefOid,state,mergeStateStatus
1048+
```
1049+
1050+
2. **Never trust a pre-existing shared worktree** for review/fix — a parallel job
1051+
may churn or delete it mid-task. Create your own isolated worktree for the PR
1052+
branch (or off a freshly-fetched `origin/main` if starting a new branch).
1053+
3. **`gh pr diff` vs the file you `Read` disagree?** The branch was force-pushed
1054+
between calls — re-fetch and re-derive from the committed state on origin.
1055+
10211056
## Signed Commits with Rebase Merge
10221057

10231058
### The Problem

0 commit comments

Comments
 (0)