From f93dee37333a106a308933f6a0e4268462f9c0c0 Mon Sep 17 00:00:00 2001 From: Tibsfox Date: Sun, 5 Apr 2026 10:43:31 -0700 Subject: [PATCH 1/2] fix(gsd): use main_branch preference in worktree creation --- src/resources/extensions/gsd/auto-worktree.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/resources/extensions/gsd/auto-worktree.ts b/src/resources/extensions/gsd/auto-worktree.ts index a0275619a..ef1f72e8e 100644 --- a/src/resources/extensions/gsd/auto-worktree.ts +++ b/src/resources/extensions/gsd/auto-worktree.ts @@ -1049,12 +1049,20 @@ export function createAutoWorktree( reuseExistingBranch: true, }); } else { - // Fresh start — create branch from integration branch + // Fresh start — create branch from integration branch. + // Use the same 3-tier fallback as mergeMilestoneToMain (#3461): + // 1. META.json integration branch (explicit per-milestone override) + // 2. git.main_branch preference (user's configured working branch) + // 3. nativeDetectMainBranch (origin/HEAD auto-detection) + // Without tier 2, projects with main_branch=dev but origin/HEAD→master + // would fork worktrees from the wrong (stale) branch. const integrationBranch = readIntegrationBranch(basePath, milestoneId) ?? undefined; + const gitPrefs = loadEffectiveGSDPreferences()?.preferences?.git; + const startPoint = integrationBranch ?? gitPrefs?.main_branch ?? undefined; info = createWorktree(basePath, milestoneId, { branch, - startPoint: integrationBranch, + startPoint, }); } From 107efc5bff9af2b4c6716612cdae6146e6783e1f Mon Sep 17 00:00:00 2001 From: Tibsfox Date: Sun, 5 Apr 2026 11:55:21 -0700 Subject: [PATCH 2/2] test(gsd): add worktree main_branch preference test --- .../gsd/tests/worktree-main-branch.test.ts | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/resources/extensions/gsd/tests/worktree-main-branch.test.ts diff --git a/src/resources/extensions/gsd/tests/worktree-main-branch.test.ts b/src/resources/extensions/gsd/tests/worktree-main-branch.test.ts new file mode 100644 index 000000000..f691f73bd --- /dev/null +++ b/src/resources/extensions/gsd/tests/worktree-main-branch.test.ts @@ -0,0 +1,20 @@ +/** + * Regression test for #3461: createAutoWorktree must use git.main_branch + * preference when META.json integration branch is absent. + */ +import { test } from "node:test"; +import assert from "node:assert/strict"; +import { readFileSync } from "node:fs"; +import { join } from "node:path"; + +test("auto-worktree.ts includes main_branch preference in startPoint fallback (#3461)", () => { + const src = readFileSync( + join(import.meta.dirname, "..", "auto-worktree.ts"), + "utf-8", + ); + // The fix adds gitPrefs?.main_branch to the startPoint fallback chain + assert.ok( + src.includes("gitPrefs?.main_branch") || src.includes("prefs.main_branch"), + "createAutoWorktree must check git.main_branch preference before falling back to nativeDetectMainBranch", + ); +});