Skip to content

Commit 3c3546f

Browse files
maria-rcksnateEc
andcommitted
fix(server): preserve nested bare repositories during cleanup
Co-authored-by: Yukun Shan <[email protected]>
1 parent 40986b2 commit 3c3546f

2 files changed

Lines changed: 23 additions & 3 deletions

File tree

‎apps/server/src/storageCleanup.test.ts‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -485,8 +485,10 @@ const runCleanupTest = <A, E>(
485485
it.live.each([
486486
{ policy: "tracked-changes", kind: "worktree" },
487487
{ policy: "tracked-changes", kind: "repository" },
488+
{ policy: "tracked-changes", kind: "bare" },
488489
{ policy: "uncommitted-changes", kind: "worktree" },
489490
{ policy: "uncommitted-changes", kind: "repository" },
491+
{ policy: "uncommitted-changes", kind: "bare" },
490492
] as const)("keeps an ignored nested $policy / $kind", ({ policy, kind }) =>
491493
runCleanupTest(
492494
Effect.gen(function* () {
@@ -496,7 +498,13 @@ it.live.each([
496498
if (kind === "worktree") {
497499
yield* command(repo, ["worktree", "add", "-b", "nested", nested]);
498500
} else {
499-
yield* command(repo, ["clone", "--no-hardlinks", repo, nested]);
501+
yield* command(repo, [
502+
"clone",
503+
"--no-hardlinks",
504+
...(kind === "bare" ? ["--bare"] : []),
505+
repo,
506+
nested,
507+
]);
500508
}
501509
yield* fs.writeFileString(`${nested}/uncommitted.txt`, "irreplaceable work\n");
502510
expect((yield* command(worktree, ["status", "--porcelain"])).stdout).toBe("");
@@ -506,7 +514,14 @@ it.live.each([
506514
reason: "Contains a nested Git repository",
507515
});
508516
expect(yield* fs.readFileString(`${nested}/uncommitted.txt`)).toBe("irreplaceable work\n");
509-
expect((yield* command(nested, ["rev-parse", "--show-toplevel"])).stdout.trim()).toBe(nested);
517+
expect(
518+
(yield* command(nested, [
519+
"-c",
520+
"safe.bareRepository=all",
521+
"rev-parse",
522+
"--is-bare-repository",
523+
])).stdout.trim(),
524+
).toBe(String(kind === "bare"));
510525
}),
511526
),
512527
);

‎apps/server/src/storageCleanup.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,12 @@ const make = Effect.gen(function* () {
334334
const names = yield* fs.readDirectory(target);
335335
// Git status omits ignored repositories, and worktree remove deletes them.
336336
// Registered submodules have their own recursive safety checks below.
337-
if (inspectRepositories && names.includes(".git") && !repositories.has(pathKey(target)))
337+
if (
338+
inspectRepositories &&
339+
!repositories.has(pathKey(target)) &&
340+
(names.includes(".git") ||
341+
(names.includes("HEAD") && names.includes("objects") && names.includes("refs")))
342+
)
338343
return { bytes: null, reason: "contains a nested Git repository" };
339344
entries += names.length;
340345
if (entries > 2_000_000) return incomplete;

0 commit comments

Comments
 (0)