Skip to content

skip if there are no non-.md changes vs base branch before checking if there's a PR#18

Merged
joshalbrecht merged 9 commits into
mainfrom
ev/branch-check-ordering
May 26, 2026
Merged

skip if there are no non-.md changes vs base branch before checking if there's a PR#18
joshalbrecht merged 9 commits into
mainfrom
ev/branch-check-ordering

Conversation

@evgunter
Copy link
Copy Markdown
Collaborator

Problem

Stopping on the base branch (main) nags with:

ERROR: No PR found for branch main.
ERROR: Please create a draft PR using: gh pr create --draft

even though stop_hook_orchestrator.sh has explicit "no PR needed on the base branch" logic.

Root cause

Ordering bug. The informational-session skip (base branch / no diff vs base / .md-only) was Step 6, after the Step 5 ensure-pr gate. On the base branch, ensure-pr runs gh pr view <base>, finds nothing, and exit 2s — the orchestrator propagates that and never reaches the Step 6 skip. The base-branch guard was effectively dead code on that path.

(Same ordering also defeated the no-diff / .md-only skip on a feature branch whose PR isn't open yet.)

Fix

Move the informational-session detection block ahead of ensure-pr. It has no dependency on the PR step (PR_NUMBER is only consumed later, in the parallel gate phase), and the fetch/merge step still runs first, so the "CI starts early" optimization is preserved for real PR sessions. Pure reorder + renumber; no logic change inside either block.

Verification

shellcheck -x output is identical to main (no new warnings). Functional test in throwaway repos:

Scenario Before After
on main, clean exit 2 ❌ exit 0 ✅ base-branch skip
feature branch, no diff vs base exit 2 exit 0 ✅
feature branch, .py diff exit 2 (enforced) exit 2 ✅ still enforces PR
feature branch, .md-only diff exit 2 exit 0 ✅

🤖 Generated with Claude Code

evgunter and others added 5 commits May 25, 2026 15:08
The orchestrator's "skip when on the base branch / no diff / .md-only"
logic lived in Step 6, *after* the Step 5 ensure-pr gate. On the base
branch, ensure-pr called `gh pr view <base>`, found no PR, and exited 2
before the base-branch skip could ever run -- so stopping on `main`
nagged with "No PR found for branch main. Please create a draft PR".

Move the informational-session detection ahead of ensure-pr. It has no
dependency on the PR step (PR_NUMBER is only consumed later in the gate
phase), so base-branch / no-diff / .md-only sessions now exit 0 cleanly
while real code changes still hit the PR requirement unchanged.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The step also skips on the base branch and when there's no diff vs base
yet -- not just .md-only sessions -- so "informational" undersold it.
Rename the section + README to "gate-skip detection" and enumerate all
three cases. Also reorder the README step list to match the code: the
skip check now runs before the Push + PR check.

Config key (stop_hook.skip_informational) and the IS_INFORMATIONAL_ONLY
variable are left unchanged -- the key is a settings contract.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
No changes vs base subsumes it.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Drop the historical 'previously ran after ensure-pr' note (that's commit
history, not current behavior) and tighten the case list.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@evgunter evgunter changed the title stop hook: run informational/base-branch skip before PR enforcement do .md-only/base-branch skip before checking if there's a PR May 25, 2026
@evgunter evgunter changed the title do .md-only/base-branch skip before checking if there's a PR skip if there are no non-.md changes vs base branch before checking if there's a PR May 25, 2026
evgunter and others added 4 commits May 25, 2026 15:22
…test

An empty diff trivially has no non-.md files, so the two were the same
skip decision split only to log different strings. Fold them into a
single check vs the base branch. Skip decision and exit codes unchanged
(verified across base / no-diff / .py / .md-only / mixed cases); only
the info log message changes. Base-branch check stays separate -- it
needs no diff and so does not depend on the fetch in Step 4.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…in/<base>

The diff is vs origin/\$BASE_BRANCH, not the local base branch; "vs it"
blurred that. Name the ref explicitly.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Listing "base branch" alongside it in a one-line summary reads as a
subset (the origin/<base> distinction that makes it not one is invisible
there). The detailed Step 5 comment keeps both cases + names the ref.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
"Gate-skip detection" named the action, not the detected condition, and
read as jargon. Name the condition instead. Also drop the double-negative
"no non-.md changes" from comments + log in favor of "only .md / empty"
phrasing. Behavior unchanged; verified across base/no-diff/.py/.md cases.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@evgunter evgunter marked this pull request as ready for review May 25, 2026 22:38
@joshalbrecht
Copy link
Copy Markdown
Contributor

lgtm, thanks for this!

@joshalbrecht joshalbrecht merged commit 12ca3bd into main May 26, 2026
@evgunter evgunter deleted the ev/branch-check-ordering branch May 26, 2026 19:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants