fix(sync): respect sync.branch config when no upstream tracking (#640)
* fix(sync): respect sync.branch config when no upstream tracking When sync.branch is explicitly configured, bd sync should use worktree-based sync even if the current branch has no upstream tracking. This fixes the issue where jj (Jujutsu) colocated repos and git worktrees without upstream would incorrectly fall back to --from-main mode. The fix checks for sync.branch configuration BEFORE the upstream check, allowing the configured sync branch to take precedence. Affected workflows: - jj colocated repos (always use detached HEAD) - Git worktrees not tracking a remote - Temporary checkouts for testing Fixes #638 * test(sync): add regression tests for sync.branch priority over upstream check Add tests verifying that when sync.branch is configured, bd sync does NOT fall back to --from-main mode even without upstream tracking. This covers: - sync.branch configured without upstream (should use worktree sync) - No sync.branch and no upstream (should fallback to from-main) - Detached HEAD with sync.branch (jj workflow, should use worktree sync) These tests ensure the fix for GH#638 doesn't regress. --------- Co-authored-by: Charles P. Cross <cpdata@users.noreply.github.com>
This commit is contained in:
@@ -179,9 +179,20 @@ Use --merge to merge the sync branch back to main branch.`,
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// GH#638: Check sync.branch BEFORE upstream check
|
||||
// When sync.branch is configured, we should use worktree-based sync even if
|
||||
// the current branch has no upstream (e.g., detached HEAD in jj, git worktrees)
|
||||
var hasSyncBranchConfig bool
|
||||
if err := ensureStoreActive(); err == nil && store != nil {
|
||||
if syncBranch, _ := syncbranch.Get(ctx, store); syncBranch != "" {
|
||||
hasSyncBranchConfig = true
|
||||
}
|
||||
}
|
||||
|
||||
// Preflight: check for upstream tracking
|
||||
// If no upstream, automatically switch to --from-main mode (gt-ick9: ephemeral branch support)
|
||||
if !noPull && !gitHasUpstream() {
|
||||
// GH#638: Skip this fallback if sync.branch is explicitly configured
|
||||
if !noPull && !gitHasUpstream() && !hasSyncBranchConfig {
|
||||
if hasGitRemote(ctx) {
|
||||
// Remote exists but no upstream - use from-main mode
|
||||
fmt.Println("→ No upstream configured, using --from-main mode")
|
||||
|
||||
Reference in New Issue
Block a user