Skip to content

fix for sync with no local trunk#125

Open
skarim wants to merge 1 commit into
skarim/push-explicit-leasefrom
skarim/fix-no-local-trunk
Open

fix for sync with no local trunk#125
skarim wants to merge 1 commit into
skarim/push-explicit-leasefrom
skarim/fix-no-local-trunk

Conversation

@skarim

@skarim skarim commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator

When the trunk branch (e.g. main) doesn't exist locally — only the remote tracking ref (origin/main) exists — fastForwardTrunk runs git rev-parse main origin/main which fails, emitting:

⚠ Could not compare trunk main with remote — skipping trunk update

This also causes stackNeedsRebase to always return true (since IsAncestor("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: add BranchExists(trunk) early return in fastForwardTrunk() — skip silently when the local trunk doesn't exist
  • cmd/sync_test.go: add BranchExistsFn default (true) to newSyncMock + new TestSync_NoLocalTrunk_SkipsSilently test

Stack created with GitHub Stacks CLIGive Feedback 💬

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.
@skarim skarim marked this pull request as ready for review June 12, 2026 15:39
Copilot AI review requested due to automatic review settings June 12, 2026 15:39

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 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 of fastForwardTrunk() to return early when the local trunk doesn't exist
  • Set BranchExistsFn default in newSyncMock to maintain correctness of existing sync tests after the new guard
  • Add a new test TestSync_NoLocalTrunk_SkipsSilently verifying 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

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.

2 participants