GitServiceImpl.getMainBranch() was designed to detect manual /worktree worktrees (worktree/<name> branches) but incorrectly applied the same logic to auto-mode worktrees (milestone/<MID> branches). When no worktree/<name> branch existed, it fell back to the current branch, which in certain contexts could be main, causing slice commits to land on main instead of the milestone branch. Fix: Detect if currently on a milestone/* branch first (auto-mode case) and return it, before checking for worktree/* branches (manual worktree case). - Modify getMainBranch() to detect milestone branches first - Add test verifying getMainBranch() returns correct branch in auto-worktree - All tests pass, build succeeds Fixes #1526
This commit is contained in:
parent
f83a85eb7c
commit
df76eea764
2 changed files with 31 additions and 1 deletions
|
|
@ -479,9 +479,20 @@ export class GitServiceImpl {
|
|||
|
||||
const wtName = detectWorktreeName(this.basePath);
|
||||
if (wtName) {
|
||||
// Auto-mode worktrees use milestone/<MID> branches (wtName = milestone ID)
|
||||
const milestoneBranch = `milestone/${wtName}`;
|
||||
const currentBranch = nativeGetCurrentBranch(this.basePath);
|
||||
|
||||
// If we're on a milestone/<MID> branch, use it (auto-mode case)
|
||||
if (currentBranch.startsWith("milestone/")) {
|
||||
return currentBranch;
|
||||
}
|
||||
|
||||
// Otherwise check for manual worktree branch (worktree/<name>)
|
||||
const wtBranch = `worktree/${wtName}`;
|
||||
if (nativeBranchExists(this.basePath, wtBranch)) return wtBranch;
|
||||
return nativeGetCurrentBranch(this.basePath);
|
||||
|
||||
return currentBranch;
|
||||
}
|
||||
|
||||
// Repo-level default detection: origin/HEAD → main → master → current branch.
|
||||
|
|
|
|||
|
|
@ -153,6 +153,25 @@ async function main(): Promise<void> {
|
|||
// After teardown, originalBase should be null
|
||||
assertEq(getAutoWorktreeOriginalBase(), null, "no split-brain: originalBase cleared");
|
||||
|
||||
// ─── #1526: getMainBranch returns milestone branch in auto-worktree ──
|
||||
console.log("\n=== #1526: getMainBranch() returns milestone/<MID> in auto-worktree ===");
|
||||
{
|
||||
const { GitServiceImpl } = await import("../git-service.ts");
|
||||
|
||||
// Create worktree
|
||||
const wtPath = createAutoWorktree(tempDir, "M005");
|
||||
// Don't set main_branch pref so getMainBranch falls through to worktree detection
|
||||
const gitService = new GitServiceImpl(wtPath);
|
||||
gitService.setMilestoneId("M005");
|
||||
|
||||
// Verify getMainBranch returns the milestone branch
|
||||
const mainBranch = gitService.getMainBranch();
|
||||
assertEq(mainBranch, "milestone/M005", "getMainBranch returns milestone/<MID> in auto-worktree");
|
||||
|
||||
// Cleanup
|
||||
teardownAutoWorktree(tempDir, "M005");
|
||||
}
|
||||
|
||||
// ─── #778: reconcile plan checkboxes on re-attach ─────────────────
|
||||
console.log("\n=== #778: reconcile plan checkboxes on re-attach ===");
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue