Skip to content

Commit 81c6f95

Browse files
authored
Merge pull request #205 from netresearch/retro/probe-and-pr-body-rules
docs: a probe command is read-only; write the PR body in its own call
2 parents 0702db7 + e363260 commit 81c6f95

2 files changed

Lines changed: 62 additions & 0 deletions

File tree

skills/git-workflow/references/advanced-git.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,36 @@ git merge --no-ff cherry-pick-fixes
185185

186186
## Stashing
187187

188+
### A probe command is read-only
189+
190+
Comparing two revisions, checking what a script used to do, reproducing a bug
191+
against an older build — that work is exploratory, and it must not move the
192+
working tree. Never put `git stash`, `git reset`, `git checkout --` or
193+
`git restore` inside a command whose purpose is to find something out.
194+
195+
The failure is silent, which is what makes it worth a rule. A probe that
196+
stashes uncommitted work looks exactly like a probe that found nothing: the
197+
command prints its output, the tree is quietly a different tree, and the next
198+
edit lands on top of a state nobody chose. Recovery is `git stash pop`, but
199+
only if you notice.
200+
201+
Extract the other revision instead of moving to it:
202+
203+
```bash
204+
# ✅ Compare against another revision without touching the tree
205+
git show origin/main:path/to/script.sh > /tmp/old-script.sh
206+
bash /tmp/old-script.sh --check
207+
208+
# ✅ A whole old tree, still without moving
209+
git worktree add /tmp/old-tree origin/main
210+
211+
# ❌ Wrong — mutates the working tree in the middle of an inspection
212+
old=$(cd src && git stash -q; ./script.sh; true)
213+
```
214+
215+
If a probe genuinely needs a clean tree, commit first (see the sibling rules on
216+
selective revert and selective commit) — do not stash your way there.
217+
188218
### Basic Stash Operations
189219

190220
```bash

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,38 @@ minutes apart in writing — which is exactly why the disagreement is worth
365365
catching. Two figures for one quantity means at least one is answering a
366366
question you are no longer asking.
367367

368+
### Write the body in its own tool call, after the push
369+
370+
A body that cites a commit can only be written once that commit is on the
371+
remote, and the hash belongs in it by lookup — `git rev-parse --short HEAD` or
372+
`git log -1 --format=%h` — never typed from memory. A reader who follows a
373+
wrong hash finds nothing, and the claim it supported becomes unverifiable.
374+
375+
That ordering has a second, sharper reason: **a denied command loses every side
376+
effect it contained.** Bundling the push, a heredoc that writes the body file,
377+
and `gh pr edit --body-file` into one shell invocation means a gate that rejects
378+
any part of it rejects all of it — and the parts that already ran do not roll
379+
back. Observed: the push landed, the heredoc never ran because the same call was
380+
rejected for naming a not-yet-pushed hash, and the following command failed with
381+
`no such file or directory` — a confusing error two steps downstream of the
382+
actual refusal.
383+
384+
```bash
385+
# ✅ Three calls, each with one job
386+
git push
387+
git rev-parse --short HEAD # take the hash from here
388+
# …write body.md…
389+
gh pr edit 123 --body-file body.md
390+
391+
# ❌ One call: the gate rejects the whole thing, the push already happened,
392+
# and the body file that the next step needs was never created
393+
git push && cat > body.md <<'EOF' … EOF && gh pr edit 123 --body-file body.md
394+
```
395+
396+
The general rule: never bundle a file write with a push or an API call. Keep
397+
state-changing steps separable, so a refusal costs you the step and not the
398+
scaffolding around it.
399+
368400
### When you already have the fix, lead with it
369401
370402
Issue templates order evidence before solution — they are written for reports

0 commit comments

Comments
 (0)