From 902e3be6d8336636e8d8c128b9b32ab84be3679d Mon Sep 17 00:00:00 2001 From: Tibsfox Date: Mon, 6 Apr 2026 19:12:54 -0700 Subject: [PATCH] fix(gsd): validate main_branch preference exists before using in merge mergeMilestoneToMain used prefs.main_branch without checking if the branch exists in the repo. A stale preference (e.g. "master" when repo uses "main") caused merge failure. Now validates with nativeBranchExists before using the preference, falling through to nativeDetectMainBranch if invalid. Closes #3589 Co-Authored-By: Claude Opus 4.6 (1M context) --- src/resources/extensions/gsd/auto-worktree.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/resources/extensions/gsd/auto-worktree.ts b/src/resources/extensions/gsd/auto-worktree.ts index a0275619a..d2420257f 100644 --- a/src/resources/extensions/gsd/auto-worktree.ts +++ b/src/resources/extensions/gsd/auto-worktree.ts @@ -1453,8 +1453,13 @@ export function mergeMilestoneToMain( originalBasePath_, milestoneId, ); + // Validate prefs.main_branch exists before using it — a stale preference + // (e.g. "master" when repo uses "main") causes merge failure (#3589). + const validatedPrefBranch = prefs.main_branch && nativeBranchExists(originalBasePath_, prefs.main_branch) + ? prefs.main_branch + : undefined; const mainBranch = - integrationBranch ?? prefs.main_branch ?? nativeDetectMainBranch(originalBasePath_); + integrationBranch ?? validatedPrefBranch ?? nativeDetectMainBranch(originalBasePath_); // Remove transient project-root state files before any branch or merge // operation. Untracked milestone metadata can otherwise block squash merges.