Rebase stacks onto the latest remote trunk - #330
Open
skarim wants to merge 2 commits into
Open
Conversation
Fetch the configured trunk explicitly before sync or rebase and use that fetched ref whenever the local trunk cannot be safely updated, while preserving local-only and locally-ahead trunks. Fail instead of reporting success when the fetch or rebase never starts, carry the resolved trunk through conflict recovery, and verify the resulting ancestry before sync pushes or either command reports success.
Contributor
There was a problem hiding this comment.
Pull request overview
Updates rebase and sync flows to target the freshly fetched remote trunk and fail safely when rebases cannot start or ancestry verification fails.
Changes:
- Resolves and fetches an authoritative trunk target.
- Adds fatal rebase-start error handling and post-rebase verification.
- Extends recovery state, mocks, and integration tests.
Show a summary per file
| File | Description |
|---|---|
cmd/rebase.go |
Uses resolved trunk targets and verifies ancestry. |
cmd/rebase_test.go |
Updates rebase mocks. |
cmd/sync.go |
Rebases and verifies before pushing. |
cmd/sync_test.go |
Updates sync ancestry behavior. |
cmd/trunk_target_test.go |
Tests trunk resolution and failure paths. |
cmd/utils.go |
Implements trunk targeting and stack verification. |
cmd/utils_test.go |
Updates helper tests. |
internal/git/git.go |
Adds rebase-start errors and delegates. |
internal/git/gitops.go |
Adds exact branch fetch and upstream lookup. |
internal/git/mock_ops.go |
Extends Git mocks. |
internal/git/rebase_start_test.go |
Adds Git integration coverage. |
internal/modify/apply.go |
Handles refused modify rebases as fatal. |
Review details
Comments suppressed due to low confidence (1)
cmd/utils.go:1178
- A start refusal on a later branch can occur after earlier branches were successfully rebased. Returning only
Errleaves those earlier refs rewritten without recovery metadata or restoration, so rerunning may replay commits from the old parent history. Keep the error fatal, but restoreOriginalRefsin both callers or persist a recoverable partial-cascade state.
if git.IsRebaseStartError(rebaseErr) {
return cascadeRebaseResult{
Rebased: result.Rebased,
Err: fmt.Errorf("could not start rebase of %s onto %s: %w", br.Branch, base, rebaseErr),
}
- Files reviewed: 12/12 changed files
- Comments generated: 4
- Review effort level: Medium
Roll back branches already rewritten when a later rebase cannot start or final ancestry verification fails, preventing retries from replaying stale history. Preserve retryable modify state without repeating completed work, and add regression coverage for remote-qualified trunk normalization.
This was referenced Jul 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
gh stack syncmerged approved PRs into bottom branch #155Summary
gh stack rebaseandgh stack synccould report success while leaving a stack on a stale trunk, particularly when the local trunk was checked out in another worktree, had diverged from the remote, or the fetch failed.This change fetches the trunk explicitly and rebases onto the fresh remote ref when the local branch cannot be updated, while preserving locally-ahead and local-only trunks. It also treats rebases that git refuses to start as failures and verifies the resulting ancestry before reporting success or pushing from
sync.Testing
go vet ./...go test -race -count=1 ./...rebaseandsyncagainst a six-layer stack withmainlocked in another worktree