From 4924bbe6b22b2d026e936192f9fb0f61a7999023 Mon Sep 17 00:00:00 2001 From: Lex Christopherson Date: Fri, 13 Mar 2026 22:47:14 -0600 Subject: [PATCH] fix: update integration branch when user starts auto-mode from a different branch (#300) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit writeIntegrationBranch was unconditionally skipping if any integration branch was already recorded, even if the user started auto-mode from a different branch. Now it only skips when the recorded branch matches — if it differs, the record is updated so slices merge to the correct target. Co-Authored-By: Claude Opus 4.6 (1M context) --- src/resources/extensions/gsd/git-service.ts | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/resources/extensions/gsd/git-service.ts b/src/resources/extensions/gsd/git-service.ts index d4e07245f..2a376bd7a 100644 --- a/src/resources/extensions/gsd/git-service.ts +++ b/src/resources/extensions/gsd/git-service.ts @@ -101,24 +101,25 @@ export function readIntegrationBranch(basePath: string, milestoneId: string): st /** * Persist the integration branch for a milestone. * - * Called once when auto-mode starts on a milestone. Records the branch - * the user was on at that point, so that slice branches merge back to it - * instead of the repo's default branch. + * Called when auto-mode starts on a milestone. Records the branch the user + * was on at that point, so that slice branches merge back to it instead of + * the repo's default branch. Idempotent when the branch matches; updates + * the record when the user starts from a different branch. * * The file is committed immediately so it survives branch switches — the * pre-switch auto-commit excludes `.gsd/` to avoid merge conflicts, and * uncommitted `.gsd/` files are discarded during checkout. - * - * Skips writing if an integration branch is already recorded (idempotent - * across restarts) or if the current branch is already a GSD slice branch. */ export function writeIntegrationBranch(basePath: string, milestoneId: string, branch: string): void { // Don't record slice branches as the integration target if (SLICE_BRANCH_RE.test(branch)) return; - // Don't overwrite an existing integration branch - if (readIntegrationBranch(basePath, milestoneId) !== null) return; // Validate if (!VALID_BRANCH_NAME.test(branch)) return; + // Skip if already recorded with the same branch (idempotent across restarts). + // If recorded with a different branch, update it — the user started auto-mode + // from a new branch and expects slices to merge back there (#300). + const existing_branch = readIntegrationBranch(basePath, milestoneId); + if (existing_branch === branch) return; const metaFile = milestoneMetaPath(basePath, milestoneId); mkdirSync(join(basePath, ".gsd", "milestones", milestoneId), { recursive: true });