Skip to content

feat(zsh): narrate ghsq/ghrb's post-merge branch switch - #355

Merged
laurigates merged 1 commit into
mainfrom
feat/ghsq-narrate-go-home
Aug 7, 2026
Merged

feat(zsh): narrate ghsq/ghrb's post-merge branch switch#355
laurigates merged 1 commit into
mainfrom
feat/ghsq-narrate-go-home

Conversation

@laurigates

Copy link
Copy Markdown
Owner

What

ghsq/ghrb relocate you to the base branch when the branch you're standing on has a merged PR. That move was announced by one line, printed after it happened:

  ⇣ #268 was merged — on main, pulling

It now explains itself first:

  ⇣ what  feat/argocd-health-progressing-card → main — git switch main && git pull --ff-only
    why   this branch's PR #268 is MERGED (already merged before this run, 2026-08-06 14:22Z) — its commits are already on main
    kept  local branch feat/argocd-health-progressing-card — delete with git branch -d feat/argocd-health-progressing-card

Why

Behaviour is unchanged — the gate was already correct (state == MERGED, read authoritatively from the API). What was missing is transparency about which branch is being left, on whose authority, and what happened to it.

Two specific gaps this closes:

  • "this run" vs "earlier". The guard is "this branch's PR is merged", not "…was merged by this run", so it also fires when you were already standing on a branch merged days ago while merging unrelated PRs. That's correct — the branch is stale either way — but it reads as a non-sequitur when the PR named in the message isn't one of the numbers on screen. The label now says which case it is.
  • Ordering. git switch prints Your branch is behind 'origin/main'… itself, and the old message came after it — so the first thing you saw was a consequence of an unexplained action. what/why now print before the switch, and are therefore also present when the switch fails.

The kept line answers the question the old output invited: nothing local is deleted here, only the remote-tracking ref gets pruned by the fetch.

How

  • _gh_home_if_merged takes a second argument: the PR numbers this invocation acted on. ghsq/ghrb pass the picker's TSV column (or the single arg-form number).
  • "by this run" is decided by set membership, not by clocks. Comparing mergedAt against a locally captured start time would misdate merges landing seconds either side of the run under local-vs-GitHub skew. The picker only ever lists OPEN PRs, so "was selected AND is now MERGED" means this run merged it. mergedAt prints either way as the ground truth behind the label.
  • Also narrated: the already-on-base case, and the switch-refused case (still exits 1 and stays put).

Testing

Behavioural harness with stubbed gh/git over ten paths, under setopt extended_glob (which the interactive shell has set, and which is what makes #-in-pattern bugs surface):

Case Expected
merged by this run / merged earlier correct label, timestamp shown
empty acted set (arg form, skipped) falls back to "before this run"
local branch absent no kept line
already on base branch pull-only variant
switch refused (dirty tree) warning, exit 1, stays put
PR still OPEN / no PR for branch completely silent
mergedAt missing label without timestamp
detached HEAD labelled, no kept line

Plus zsh -n on the rendered ~/.zshrc, and chezmoi diff reviewed pre-apply to confirm no target-side drift was clobbered.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Mbyb2ptbDET8P11pPyqToe

The go-home helper relocated you to the base branch with a single line
("#268 was merged — on main, pulling"), printed *after* the switch. That
left two things unexplained.

First, the guard is "this branch's PR is MERGED", not "…was merged by
this run" — so it also fires when you were already standing on a branch
merged days ago, while merging unrelated PRs. Correct (the branch is
stale either way), but it reads as a non-sequitur when the PR numbers on
screen are not the one named in the message.

Second, git's own "Your branch is behind 'origin/main'" chatter landed
*before* the explanation, so the first thing you saw was a consequence.

Now the move is narrated before it happens:

  ⇣ what  feat/foo → main — git switch main && git pull --ff-only
    why   this branch's PR #268 is MERGED (already merged before this
          run, 2026-08-06 14:22Z) — its commits are already on main
    kept  local branch feat/foo — delete with git branch -d feat/foo

"by this run" vs "before this run" is decided by membership in the set of
PR numbers the invocation acted on (passed in by ghsq/ghrb), never by
comparing clocks — local-vs-GitHub skew would misdate a merge landing
seconds either side of the run. The picker only lists OPEN PRs, so
"was selected AND is now MERGED" means this run merged it. mergedAt
prints either way as the ground truth behind the label.

The "kept" line answers the question the old output invited: the local
branch is never deleted here, only the remote-tracking ref is pruned.

Verified with a stubbed-gh/git harness over ten paths: merged-by-this-run,
merged-earlier, empty acted set, local branch absent, already on base,
switch refused (exit 1, stays put), PR still OPEN and no-PR (both silent),
mergedAt missing, and detached HEAD — under `setopt extended_glob`, which
the interactive shell has set.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Mbyb2ptbDET8P11pPyqToe
@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

⚠️ Broken Links Detected

Summary

Status Count
🔍 Total 170
✅ Successful 160
⏳ Timeouts 0
🔀 Redirected 0
👻 Excluded 9
❓ Unknown 0
🚫 Errors 1

Errors per input

Errors in docs/macos-automation.md


Please fix the broken links before merging.

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

🤖 Claude analyzed the CI failures but determined no code changes are needed.

Failed workflow: https://github.com/laurigates/dotfiles/actions/runs/31163996781

This may indicate:

  • Flaky tests
  • Infrastructure issues
  • Transient failures
  • Configuration problems outside the codebase

Please review the failure logs manually.

@laurigates
laurigates merged commit 1ea3c8f into main Aug 7, 2026
6 of 8 checks passed
@laurigates
laurigates deleted the feat/ghsq-narrate-go-home branch August 7, 2026 09:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant