Skip to content

Commit dc6c1aa

Browse files
fix(server): accept a fresh separate-git-dir checkout as a project
A checkout made with git init --separate-git-dir has no index until its first add, so a missing index alone rejected it. Also require linked worktrees, which a checkout cannot have before its first commit. AI-assisted; verified with the tests and tools listed above.
1 parent c03936a commit dc6c1aa

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

‎apps/server/src/project/ProjectService.test.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,16 @@ it.layer(layerTest)("ProjectService", (it) => {
571571
const checkout = NodePath.join(fixture, "separate-git-dir");
572572
NodeFS.mkdirSync(checkout);
573573
git(checkout, "init", "-b", "develop", "--separate-git-dir", ".metadata", checkout);
574+
// Before its first commit it has neither an index nor worktrees.
575+
const fresh = NodePath.join(fixture, "fresh-separate-git-dir");
576+
NodeFS.mkdirSync(fresh);
577+
git(fresh, "init", "-b", "develop", "--separate-git-dir", ".metadata", fresh);
578+
yield* service.create({
579+
commandId: CommandId.make("command:bare-root:fresh"),
580+
projectId: ProjectId.make("project:bare-root:fresh"),
581+
title: "fresh separate git dir",
582+
workspaceRoot: fresh,
583+
});
574584
NodeFS.writeFileSync(NodePath.join(checkout, ".gitignore"), ".metadata/\nworktrees/\n");
575585
git(checkout, "add", ".gitignore");
576586
git(checkout, "commit", "-m", "init");

‎apps/server/src/project/ProjectService.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ export const make = Effect.gen(function* () {
259259

260260
// A `.bare` container (`.git` points at a repo inside the root) makes git see the repo metadata
261261
// and sibling worktrees as changes. A primary checkout with its separate git dir inside looks
262-
// the same, but has an index; a bare repository never gets one.
262+
// the same, but gets an index before it can have linked worktrees; a bare repository never does.
263263
const rejectBareRepositoryContainer = Effect.fn("ProjectService.rejectBareRepositoryContainer")(
264264
function* (projectId: ProjectId, workspaceRoot: string) {
265265
const realPath = (candidate: string) =>
@@ -285,6 +285,10 @@ export const make = Effect.gen(function* () {
285285
.exists(path.join(gitDir, "index"))
286286
.pipe(Effect.orElseSucceed(() => true));
287287
if (hasIndex) return;
288+
const worktrees = yield* fileSystem
289+
.readDirectory(path.join(gitDir, "worktrees"))
290+
.pipe(Effect.orElseSucceed((): ReadonlyArray<string> => []));
291+
if (worktrees.length === 0) return;
288292
return yield* new ProjectInvalidError({
289293
projectId,
290294
detail: `${workspaceRoot} holds a bare repository and its worktrees. Add an individual worktree as the project instead.`,

0 commit comments

Comments
 (0)