Skip to content

Commit cd1f94d

Browse files
fix(server): empty-repo fallback keeps - and :/text worktree bases
The no-commit probe appended `^{commit}` to the raw base, so `:/text` searched for a different message and `-` was not read as `@{-1}`. With an unborn HEAD both probes failed and a valid worktree request ran in the project folder. Probe `-` as `@{-1}` and leave `:/text` searches to `git worktree add`, as checkWorktreeBase already does. AI-assisted; verified with the tests and tools listed above. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent fd4439f commit cd1f94d

2 files changed

Lines changed: 59 additions & 1 deletion

File tree

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

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,6 +1155,60 @@ it.effect.each(["stable", "upstream/release"])(
11551155
),
11561156
);
11571157

1158+
it.effect.each([":/initial", "-"])(
1159+
"creates a worktree from %s while HEAD is an unborn branch",
1160+
(baseRef) =>
1161+
Effect.gen(function* () {
1162+
const fs = yield* FileSystem.FileSystem;
1163+
const git = yield* GitVcsDriver.GitVcsDriver;
1164+
const directory = yield* fs.makeTempDirectoryScoped({ prefix: "launch-unborn-head-" });
1165+
const cwd = `${directory}/repo`;
1166+
const worktreePath = `${directory}/worktree`;
1167+
yield* fs.makeDirectory(cwd);
1168+
const command = (at: string, args: string[]) =>
1169+
git.execute({ operation: "launch-test", cwd: at, args });
1170+
yield* command(cwd, ["init", "-b", "main"]);
1171+
yield* command(cwd, ["config", "user.name", "Test"]);
1172+
yield* command(cwd, ["config", "user.email", "[email protected]"]);
1173+
yield* command(cwd, ["commit", "--allow-empty", "-m", "initial"]);
1174+
const expected = (yield* command(cwd, ["rev-parse", "main"])).stdout.trim();
1175+
// Leaving main makes it `@{-1}`; the orphan switch adds no reflog entry.
1176+
yield* command(cwd, ["checkout", "-b", "side"]);
1177+
yield* command(cwd, ["checkout", "--orphan", "unborn"]);
1178+
1179+
const harness = makeHarness({
1180+
hasCommit: ({ refName }) =>
1181+
command(cwd, ["rev-parse", "--verify", `${refName}^{commit}`]).pipe(
1182+
Effect.as(true),
1183+
Effect.orElseSucceed(() => false),
1184+
),
1185+
createWorktree: (input, options) =>
1186+
git.createWorktree({ ...input, cwd, path: worktreePath }, options),
1187+
});
1188+
yield* Effect.gen(function* () {
1189+
const launches = yield* ThreadLaunch.ThreadLaunchService;
1190+
const launched = yield* launches.launch(
1191+
launchInput({
1192+
command: `command:launch:unborn-head:${baseRef}`,
1193+
thread: `thread:launch:unborn-head:${baseRef}`,
1194+
message: "Reply with OK only",
1195+
workspace: { type: "worktree", baseRef, branch: "feature", startFromOrigin: false },
1196+
}),
1197+
);
1198+
const projection = yield* preparationSettled(launched.threadId);
1199+
assert.equal(projection.thread.worktreePath, worktreePath);
1200+
assert.equal((yield* command(worktreePath, ["rev-parse", "HEAD"])).stdout.trim(), expected);
1201+
}).pipe(Effect.provide(harness.layer));
1202+
}).pipe(
1203+
Effect.provide(
1204+
GitVcsDriver.layer.pipe(
1205+
Layer.provide(ServerConfig.layerTest(process.cwd(), { prefix: "launch-unborn-git-" })),
1206+
Layer.provideMerge(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer)),
1207+
),
1208+
),
1209+
),
1210+
);
1211+
11581212
it.effect("fetches the origin base from the remote it already resolved", () => {
11591213
let fetchInput: Deferred.Deferred<unknown> | null = null;
11601214
const harness = makeHarness({

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,11 @@ const make = Effect.gen(function* () {
441441
git
442442
.hasCommit({ cwd: project.workspaceRoot, refName })
443443
.pipe(Effect.mapError(mapError(input, "provision-worktree", threadId)));
444-
if (!(yield* hasCommit(startRef)) && !(yield* hasCommit("HEAD"))) {
444+
// Probe as checkWorktreeBase does: `-` is the previous checkout, and a `:/text`
445+
// search cannot take `^{commit}`, so leave it to `git worktree add`.
446+
const startRefHasCommit =
447+
startRef.startsWith(":") || (yield* hasCommit(startRef === "-" ? "@{-1}" : startRef));
448+
if (!startRefHasCommit && !(yield* hasCommit("HEAD"))) {
445449
branch = null;
446450
yield* setupTracker.stageStatus(
447451
threadId,

0 commit comments

Comments
 (0)