fix: update integration branch when user starts auto-mode from a different branch (#300)

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) <noreply@anthropic.com>
This commit is contained in:
Lex Christopherson 2026-03-13 22:47:14 -06:00
parent 9feca64496
commit 4924bbe6b2

View file

@ -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 });