Skip to content

bugfixes for rebase, sync, and view#33

Closed
skarim wants to merge 11 commits intomainfrom
skarim/bugfixes
Closed

bugfixes for rebase, sync, and view#33
skarim wants to merge 11 commits intomainfrom
skarim/bugfixes

Conversation

@skarim
Copy link
Copy Markdown
Collaborator

@skarim skarim commented Apr 15, 2026

Assorted bugfixes for rebase, sync, and view

1. Fix inflated diff counts in gh stack view TUI

When the local base branch (e.g. main) had advanced past a branch's fork point, gh stack view showed inflated file counts and diff stats because the two-dot diff compared full trees instead of diffing from the fork point.

Fix: Always use git merge-base to find the fork point for diff computation, not just for merged branches.

2. Fast-forward stack branches that are behind their remote

In certain situations, when there was an upstream commit not present on local, gh stack rebase and gh stack sync would rebase on top of the stale local ref, effectively dropping the new commits.

Fix: Before the cascade rebase, both rebase and sync now detect stack branches where the local ref is strictly behind the remote tracking branch and fast-forward them. If the branch has diverged, it's left alone (the push step handles that). For sync, a branch fast-forward also triggers the cascade rebase even if trunk hasn't moved.

3. Fix rev-parse error when rebasing over deleted branches

When a merged branch's remote ref was deleted (e.g. "Automatically delete head branches"), gh stack rebase would fail with a rev-parse error because it tried to resolve refs for all branches, including ones that no longer exist.

Fix: Filter out merged branches that don't exist locally before calling RevParseMulti to snapshot original refs. These branches are already skipped during the actual rebase cascade.

4. Fix rev-parse error during sync with deleted branches

Same root cause as 3, but in the gh stack sync code path. The branch-ref snapshot before rebase included deleted branches, causing a rev-parse failure.

Fix: Apply the same guard — skip merged branches that don't exist locally when building the ref snapshot.

5. Fix --onto rebase for merged branches (fixes #31)

When a branch in the stack is merged on remote, subsequent rebase and sync operations need to use git rebase --onto to transplant the next branch onto trunk. Fixes for this in a couple of areas:

  • Deleted merged branch: The merged branch's ref no longer exists locally, so originalRefs had no entry and ontoOldBase was empty — causing git rebase --onto main "" b2 to fail. Fixed by backfilling originalRefs from the persisted BranchRef.Head SHA in the stack file.
  • --upstack flag: When using --upstack, the rebase loop starts at the current branch, so it never iterates over merged branches below it and never sets needsOnto. Fixed by checking the immediate predecessor first.
  • Stale refs on repeated runs: After the first rebase handles a merged branch, the old base SHA becomes stale (no longer an ancestor of the target). A second run would replay already-applied commits, causing spurious conflicts. Fixed by adding an IsAncestor guard that falls back to merge-base when the old base is stale.

6. Pre-flight check for stacked PR availability in gh stack submit

When running gh stack submit on a repo that doesn't have stacked PRs enabled, the command would push branches and create PRs before discovering that stacked PRs aren't enabled for the repository.

Fix: Before pushing or creating PRs, submit now calls the list stacks API to verify stacked PRs is enabled on the repo. If stacks aren't available, the user is prompted interactively to create regular (unstacked) PRs instead. In non-interactive mode, the command exits with an error.

Also includes some minor fixes for styling on the docs site.

Copilot AI review requested due to automatic review settings April 15, 2026 23:29
@skarim skarim changed the title Skarim/bugfixes bugfixes for rebase, sync, and view Apr 15, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Assorted bugfixes across the gh stack CLI aimed at making stack rebases/syncs safer with remote changes, and making the TUI diff stats accurate when branches diverge from trunk. Also updates docs copy and the docs site social/diagram assets.

Changes:

  • Fix gh stack view TUI diff/file counts by always anchoring diffs at the git merge-base fork point.
  • In sync and rebase, fast-forward local stack branches that are strictly behind their remote tracking branches before cascading rebases.
  • Avoid rev-parse failures when merged branches have been deleted by skipping non-existent merged branches during ref snapshotting; plus docs/site updates (OG tags, inline SVG component, social card).
Show a summary per file
File Description
skills/gh-stack/SKILL.md Updates CLI workflow documentation wording around merge handling and rebase behavior.
internal/tui/stackview/data.go Uses git merge-base for diff base selection for all branches to avoid inflated diffs.
internal/tui/stackview/data_test.go Adds tests covering merge-base anchoring in diverged and linear histories.
internal/git/git.go Updates comment wording around --onto usage for merged PR scenarios.
cmd/utils.go Adds fastForwardBranches helper to advance local refs when behind remote.
cmd/sync.go Runs branch fast-forwarding prior to cascade rebase; skips non-existent merged branches in ref snapshot.
cmd/sync_test.go Expands sync tests for branch FF triggering rebase and merged-branch-deletion scenarios.
cmd/rebase.go Runs branch fast-forwarding prior to cascade rebase; skips non-existent merged branches in ref snapshot.
cmd/rebase_test.go Adds rebase tests for FF behavior and merged-branch-deletion scenarios.
docs/src/content/docs/reference/cli.md Updates rebase command documentation wording (merged PR handling).
README.md Updates rebase command documentation wording (merged PR handling).
docs/src/content/docs/index.mdx Switches from static SVG asset to an Astro component for the stack diagram.
docs/src/components/StackDiagram.astro New inline-SVG diagram component to improve theme behavior and Safari compatibility.
docs/src/assets/stack-diagram.svg Removes the old static SVG asset.
docs/public/github-social-card.jpg Adds a social preview image used by OG/Twitter meta tags.
docs/astro.config.mjs Updates site description and adds OG/Twitter meta tags for social sharing.

Copilot's findings

Tip

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

  • Files reviewed: 14/16 changed files
  • Comments generated: 5

Comment thread cmd/sync.go
Comment thread cmd/utils.go
Comment thread cmd/rebase_test.go Outdated
Comment thread cmd/sync_test.go Outdated
Comment thread cmd/rebase.go
@skarim skarim force-pushed the skarim/bugfixes branch 2 times, most recently from 0779491 to 2267892 Compare April 16, 2026 14:37
@skarim
Copy link
Copy Markdown
Collaborator Author

skarim commented Apr 16, 2026

closing this PR in favor of a cleaner stack: #39, #40, #41, #42, #43, #44

@skarim skarim closed this Apr 16, 2026
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.

gh stack rebase --upstack doesn't detect squash-merged branches below the current branch

2 participants