Skip to content

Commit feee9a2

Browse files
fix(server): fall back to the project folder only for the unborn branch itself
No local branches still leaves remote-tracking refs that Git resolves in bases like origin/main...origin/other. Take the project-folder fallback only when the base is the unborn branch HEAD points at (or HEAD) and it has no commit; Git resolves every other base, as on main. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent ca8f60f commit feee9a2

2 files changed

Lines changed: 20 additions & 15 deletions

File tree

‎apps/server/src/orchestration-v2/ThreadLaunchService.test.ts‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1292,13 +1292,15 @@ it.effect.each(["stable", "upstream/release"])(
12921292
it.effect.each([
12931293
{ name: "a repository with no commits", setup: [], baseRef: "main", worktree: false },
12941294
{
1295-
name: "an orphan branch beside branches with commits",
1295+
name: "an orphan branch beside remote-tracking branches",
12961296
setup: [
12971297
["commit", "--allow-empty", "-m", "initial"],
1298-
["branch", "other"],
1298+
["update-ref", "refs/remotes/origin/main", "HEAD"],
1299+
["update-ref", "refs/remotes/origin/other", "HEAD"],
12991300
["checkout", "--orphan", "empty"],
1301+
["branch", "-D", "main"],
13001302
],
1301-
baseRef: "main...other",
1303+
baseRef: "origin/main...origin/other",
13021304
worktree: true,
13031305
},
13041306
])("launches a new worktree thread from $name", (scenario) =>
@@ -1329,7 +1331,12 @@ it.effect.each([
13291331
Effect.as(true),
13301332
Effect.orElseSucceed(() => false),
13311333
),
1332-
git: { listLocalBranchNames: () => git.listLocalBranchNames(cwd) },
1334+
git: {
1335+
currentBranch: () =>
1336+
git
1337+
.execute({ operation: "launch-test", cwd, args: ["symbolic-ref", "--short", "HEAD"] })
1338+
.pipe(Effect.map((result) => result.stdout.trim())),
1339+
},
13331340
createWorktree: (input, options) =>
13341341
git.createWorktree({ ...input, cwd, path: `${directory}/worktree` }, options),
13351342
});

‎apps/server/src/orchestration-v2/ThreadLaunchService.ts‎

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -556,18 +556,16 @@ const make = Effect.gen(function* () {
556556
if (shouldFetch) yield* setupTracker.stageStatus(threadId, "fetch", "done");
557557
const unborn = yield* Effect.gen(function* () {
558558
const cwd = project.workspaceRoot;
559-
// `:/text` is a commit search, which cannot be asked for a commit type.
560-
if (startRef.startsWith(":") || (yield* git.hasCommit({ cwd, refName: "HEAD" })))
561-
return false;
562-
// Any local branch means Git can still resolve bases like `main...other` that rev-parse rejects.
563-
if ((yield* git.listLocalBranchNames(cwd)).length > 0) return false;
564-
return !(yield* git.hasCommit({ cwd, refName: startRef === "-" ? "@{-1}" : startRef }));
559+
if (yield* git.hasCommit({ cwd, refName: "HEAD" })) return null;
560+
// Only the unborn branch itself has nothing to check out; Git resolves any other base.
561+
const current = yield* git.currentBranch(cwd);
562+
if (startRef !== "HEAD" && startRef !== current) return null;
563+
if (yield* git.hasCommit({ cwd, refName: startRef })) return null;
564+
return { branch: current };
565565
}).pipe(Effect.mapError(mapError(input, "provision-worktree", threadId)));
566-
if (unborn) {
567-
// A repository with no commits has nothing to check out; run in the project folder.
568-
branch = yield* git
569-
.currentBranch(project.workspaceRoot)
570-
.pipe(Effect.orElseSucceed(() => null));
566+
if (unborn !== null) {
567+
// A branch with no commits has nothing to check out; run in the project folder.
568+
branch = unborn.branch;
571569
yield* setupTracker.update(threadId, (snapshot) => ({ ...snapshot, branch }));
572570
yield* setupTracker.stageStatus(threadId, "checkout", "skipped");
573571
yield* setupTracker.stageStatus(threadId, "submodules", "skipped");

0 commit comments

Comments
 (0)