Skip to content

fix for rev-parse error when rebasing over deleted branches#41

Merged
skarim merged 1 commit into
skarim/fix-fast-forwardfrom
skarim/fix-rebase-deleted
Apr 20, 2026
Merged

fix for rev-parse error when rebasing over deleted branches#41
skarim merged 1 commit into
skarim/fix-fast-forwardfrom
skarim/fix-rebase-deleted

Conversation

@skarim

@skarim skarim commented Apr 16, 2026

Copy link
Copy Markdown
Collaborator

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.

Copilot AI review requested due to automatic review settings April 16, 2026 14:58

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses a failure during gh stack rebase when the stack contains merged branches whose local refs no longer exist (e.g., branch auto-deleted after merge), by avoiding git rev-parse on refs that can’t be resolved.

Changes:

  • Skip merged branches that don’t exist locally when building the ref list for RevParseMap, preventing rev-parse errors.
  • Update existing rebase tests to account for the new BranchExists behavior.
  • Add a new regression test covering the “merged + deleted branch” scenario.
Show a summary per file
File Description
cmd/rebase.go Excludes merged non-existent branches from the batch RevParseMap resolution to prevent rev-parse failures.
cmd/rebase_test.go Adjusts mocks for the new branch-existence check and adds a regression test for deleted merged branches.

Copilot's findings

Tip

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

  • Files reviewed: 2/2 changed files
  • Comments generated: 2

Comment thread cmd/rebase.go
Comment thread cmd/rebase_test.go

@Lukeghenco Lukeghenco left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Great solution for this.

@skarim skarim force-pushed the skarim/fix-fast-forward branch from 688c1c4 to d2b6b2a Compare April 17, 2026 05:28
@skarim skarim force-pushed the skarim/fix-rebase-deleted branch from 08a7f7b to fba004c Compare April 17, 2026 05:28
@skarim skarim merged commit 2fc5b08 into main Apr 20, 2026
6 checks passed
@skarim skarim deleted the skarim/fix-rebase-deleted branch April 20, 2026 14:17
skarim added a commit that referenced this pull request Apr 20, 2026
* fix for rev-parse error when rebasing over deleted branches
ryanclark added a commit to ryanclark/gh-stack that referenced this pull request Jun 19, 2026
Ports the still-applicable upstream changes since the fork point, adapted
to this fork's standard-GitHub-API architecture (no private stack backend;
stack deps tracked via "Requires #N"). Each change was test-driven.

Bug fixes:
- github#56  guard GraphQL PR-number conversion against int32 overflow
- github#41  skip merged+deleted branches when rebasing (rev-parse error)
- github#42  same fix on the sync path
- github#43  --onto rebase for merged branches: backfill refs, pre-seed onto
       state, stale-base fallback via merge-base
- github#39  always anchor branch diffs on the merge-base (inflated diff counts)
- github#95  sync now cascades when the stack is stale even if trunk is current;
       rebase skips queued branches (IsSkipped)
- github#80  view --json resolves directly with typed exit codes (no prompt)
- github#49  (Part A) ignore stale merged/closed PRs for reused branch names
       (the backend ListStacks path is intentionally omitted)

Features (standard API only):
- github#108 trunk command       - github#51  switch command
- github#74  unstack -> active    - github#101 add adopts existing branch
- github#40  fast-forward branches behind their remote
- github#76  draft PRs by default + --open (adds MarkPRReadyForReview)
- github#77  seed PR body from repo template (keeps "Requires #N")
- github#94  sync --prune merged branches

Infra / cleanup:
- github#103/github#110 bump github.com/cli/cli/v2 to v2.93.0 (go get + tidy)
- github#89  remove placeholder `merge` command + docs
- fix stale `unstack [branch]` docs

Note: this commit is layered on in-progress local work (go-git ops,
PR/commit caching, discover command) that shares the same files, so the
two are committed together. Full suite green: build, vet, go test ./...
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.

3 participants