fix for sync with no local trunk#125
Open
skarim wants to merge 1 commit into
Open
Conversation
When the trunk branch (e.g. main) doesn't exist locally — only the
remote tracking ref (origin/main) exists — `fastForwardTrunk` called
`git rev-parse main origin/main` which failed, emitting:
⚠ Could not compare trunk main with remote — skipping trunk update
This also caused `stackNeedsRebase` to always return true (since
`IsAncestor("main", ...)` errors out), forcing an unnecessary rebase
and force-push on every sync.
Add a `BranchExists` check at the top of `fastForwardTrunk`. If the
local trunk doesn't exist, return silently — there's nothing to
fast-forward, and the remote tracking ref is sufficient for rebasing
via git's DWIM resolution.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug in gh stack sync where the fastForwardTrunk function would emit a confusing warning ("Could not compare trunk main with remote — skipping trunk update") when the trunk branch (e.g., main) doesn't exist locally — only the remote tracking ref (origin/main) is present. The fix adds an early BranchExists check to skip the fast-forward silently when there's no local trunk to update.
Changes:
- Add a
BranchExists(trunk)guard at the top offastForwardTrunk()to return early when the local trunk doesn't exist - Set
BranchExistsFndefault innewSyncMockto maintain correctness of existing sync tests after the new guard - Add a new test
TestSync_NoLocalTrunk_SkipsSilentlyverifying the silent skip behavior
Show a summary per file
| File | Description |
|---|---|
| cmd/utils.go | Adds BranchExists(trunk) early return to fastForwardTrunk() |
| cmd/sync_test.go | Adds BranchExistsFn default to newSyncMock and adds new test for no-local-trunk scenario |
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: 0
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.
When the trunk branch (e.g.
main) doesn't exist locally — only the remote tracking ref (origin/main) exists —fastForwardTrunkrunsgit rev-parse main origin/mainwhich fails, emitting:This also causes
stackNeedsRebaseto always returntrue(sinceIsAncestor("main", ...)errors out), forcing an unnecessary rebase and force-push on every sync. The remote tracking ref is sufficient for rebasing via git's DWIM resolution — there's nothing to fast-forward when no local trunk exists.Changes
cmd/utils.go: addBranchExists(trunk)early return infastForwardTrunk()— skip silently when the local trunk doesn't existcmd/sync_test.go: addBranchExistsFndefault (true) tonewSyncMock+ newTestSync_NoLocalTrunk_SkipsSilentlytestStack created with GitHub Stacks CLI • Give Feedback 💬