Skip to content

Commit 2219b7e

Browse files
fix(server): commit-search bases still get a worktree when HEAD is unborn
hasCommit appends ^{commit}, which turns a :/text commit search into a search for different text, so the no-commits check misread a valid commit-search base as an empty repository. Skip the check for :/ bases, as checkWorktreeBase already does. AI-assisted; verified with the tests and tools listed above.
1 parent 416d018 commit 2219b7e

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,6 +1224,24 @@ it.effect("starts a new worktree thread in a repository with no commits", () =>
12241224
),
12251225
);
12261226

1227+
it.effect("checks out a commit-search base when the current branch has no commits", () => {
1228+
const harness = makeHarness({ hasCommit: () => Effect.succeed(false) });
1229+
return Effect.gen(function* () {
1230+
const launches = yield* ThreadLaunch.ThreadLaunchService;
1231+
const launched = yield* launches.launch(
1232+
launchInput({
1233+
command: "command:launch:commit-search",
1234+
thread: "thread:launch:commit-search",
1235+
message: "Say hello",
1236+
workspace: { type: "worktree", baseRef: ":/initial", branch: "feature" },
1237+
}),
1238+
);
1239+
const projection = yield* preparationSettled(launched.threadId);
1240+
assert.equal(projection.thread.worktreePath, "/repo-worktrees/feature");
1241+
assert.equal(harness.createWorktree.mock.calls[0]?.[0]?.refName, ":/initial");
1242+
}).pipe(Effect.provide(harness.layer));
1243+
});
1244+
12271245
it.effect("fetches the origin base from the remote it already resolved", () => {
12281246
let fetchInput: Deferred.Deferred<unknown> | null = null;
12291247
const harness = makeHarness({

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,9 @@ const make = Effect.gen(function* () {
541541
if (shouldFetch) yield* setupTracker.stageStatus(threadId, "fetch", "done");
542542
const unborn = yield* Effect.gen(function* () {
543543
const cwd = project.workspaceRoot;
544-
if (yield* git.hasCommit({ cwd, refName: "HEAD" })) return false;
544+
// `:/text` is a commit search, which cannot be asked for a commit type.
545+
if (startRef.startsWith(":") || (yield* git.hasCommit({ cwd, refName: "HEAD" })))
546+
return false;
545547
return !(yield* git.hasCommit({ cwd, refName: startRef === "-" ? "@{-1}" : startRef }));
546548
}).pipe(Effect.mapError(mapError(input, "provision-worktree", threadId)));
547549
if (unborn) {

0 commit comments

Comments
 (0)