1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
import { describe, it, expect, beforeAll, afterAll } from "bun:test";
import { mkdtempSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { countRepoCommits } from "../lib/import-helper";
function git(cwd: string, ...args: string[]) {
const p = Bun.spawnSync(["git", ...args], { cwd, stdout: "pipe", stderr: "pipe" });
if (p.exitCode !== 0) {
throw new Error(`git ${args.join(" ")} failed: ${new TextDecoder().decode(p.stderr)}`);
}
}
let root = "";
beforeAll(() => {
root = mkdtempSync(join(tmpdir(), "import-empty-guard-"));
});
afterAll(() => {
if (root) rmSync(root, { recursive: true, force: true });
});
describe("countRepoCommits — the import empty-guard", () => {
it("returns 0 for a freshly-init'd EMPTY bare repo (the phantom-import case)", async () => {
const empty = join(root, "empty.git");
git(root, "init", "--bare", empty);
expect(await countRepoCommits(empty)).toBe(0);
});
it("returns 0 for a path that isn't a git repo at all", async () => {
expect(await countRepoCommits(join(root, "does-not-exist"))).toBe(0);
});
it("returns > 0 once the repo actually has history", async () => {
const work = join(root, "work");
git(root, "init", "-b", "main", work);
git(work, "config", "user.email", "t@t.com");
git(work, "config", "user.name", "t");
Bun.spawnSync(["git", "-C", work, "commit", "--allow-empty", "-m", "seed"], { stdout: "pipe", stderr: "pipe" });
const mirror = join(root, "mirror.git");
git(root, "clone", "--bare", "--mirror", work, mirror);
expect(await countRepoCommits(mirror)).toBeGreaterThan(0);
});
});
|