Skip to content

Commit ca8f60f

Browse files
fix(server): fall back to the project folder only when no branch has commits
Bases such as main...other resolve for git worktree add but not for rev-parse --verify, so an orphan HEAD beside real branches wrongly took the project-folder fallback. Fall back only when the repository has no local branches, and let Git resolve the base otherwise, as on main. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent a60f814 commit ca8f60f

2 files changed

Lines changed: 29 additions & 4 deletions

File tree

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

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1289,14 +1289,33 @@ it.effect.each(["stable", "upstream/release"])(
12891289
),
12901290
);
12911291

1292-
it.effect("starts a new worktree thread in a repository with no commits", () =>
1292+
it.effect.each([
1293+
{ name: "a repository with no commits", setup: [], baseRef: "main", worktree: false },
1294+
{
1295+
name: "an orphan branch beside branches with commits",
1296+
setup: [
1297+
["commit", "--allow-empty", "-m", "initial"],
1298+
["branch", "other"],
1299+
["checkout", "--orphan", "empty"],
1300+
],
1301+
baseRef: "main...other",
1302+
worktree: true,
1303+
},
1304+
])("launches a new worktree thread from $name", (scenario) =>
12931305
Effect.gen(function* () {
12941306
const fs = yield* FileSystem.FileSystem;
12951307
const git = yield* GitVcsDriver.GitVcsDriver;
12961308
const directory = yield* fs.makeTempDirectoryScoped({ prefix: "launch-unborn-" });
12971309
const cwd = `${directory}/repo`;
12981310
yield* fs.makeDirectory(cwd);
1299-
yield* git.execute({ operation: "launch-test", cwd, args: ["init", "-b", "main"] });
1311+
for (const args of [
1312+
["init", "-b", "main"],
1313+
["config", "user.email", "[email protected]"],
1314+
["config", "user.name", "Test"],
1315+
...scenario.setup,
1316+
]) {
1317+
yield* git.execute({ operation: "launch-test", cwd, args });
1318+
}
13001319

13011320
const harness = makeHarness({
13021321
hasCommit: ({ refName }) =>
@@ -1310,6 +1329,7 @@ it.effect("starts a new worktree thread in a repository with no commits", () =>
13101329
Effect.as(true),
13111330
Effect.orElseSucceed(() => false),
13121331
),
1332+
git: { listLocalBranchNames: () => git.listLocalBranchNames(cwd) },
13131333
createWorktree: (input, options) =>
13141334
git.createWorktree({ ...input, cwd, path: `${directory}/worktree` }, options),
13151335
});
@@ -1320,11 +1340,14 @@ it.effect("starts a new worktree thread in a repository with no commits", () =>
13201340
command: "command:launch:unborn",
13211341
thread: "thread:launch:unborn",
13221342
message: "Say hello",
1323-
workspace: { type: "worktree", baseRef: "main" },
1343+
workspace: { type: "worktree", baseRef: scenario.baseRef, branch: "feature" },
13241344
}),
13251345
);
13261346
const projection = yield* preparationSettled(launched.threadId);
1327-
assert.equal(projection.thread.worktreePath, null);
1347+
assert.equal(
1348+
projection.thread.worktreePath,
1349+
scenario.worktree ? `${directory}/worktree` : null,
1350+
);
13281351
assert.equal(projection.runs[0]?.status, "starting");
13291352
}).pipe(Effect.provide(harness.layer));
13301353
}).pipe(

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,8 @@ const make = Effect.gen(function* () {
559559
// `:/text` is a commit search, which cannot be asked for a commit type.
560560
if (startRef.startsWith(":") || (yield* git.hasCommit({ cwd, refName: "HEAD" })))
561561
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;
562564
return !(yield* git.hasCommit({ cwd, refName: startRef === "-" ? "@{-1}" : startRef }));
563565
}).pipe(Effect.mapError(mapError(input, "provision-worktree", threadId)));
564566
if (unborn) {

0 commit comments

Comments
 (0)