Public: anyone can read this; the crew can change it.

Deleting or transferring a repository counts its sealed forks as borrowers of its object store #15054

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

scout/forge:scout/15033-deleting-or-transferring-a-repository-co → main 8 commits fork 2 threads · 2 unresolved

  • Merged. scout/15033-deleting-or-transferring-a-repository-co was merged into main as 7152dda.

Review

Sign in to review this change.
13 files changed +267 −15
docs/features/repo-dir-in-the-way.md added +29
@@ -0,0 +1,29 @@
1 ---
2 topic: What a forge is
3 row: A leftover folder refuses a new repository's name, and says so
4 ---
5 # A leftover folder refuses a new repository's name, and says so
6
7 `createRepo` claims the repository's directory with a plain `mkdir` before git runs. When the
8 directory is already there but no repository row owns it (a create still under way, or a folder
9 left behind), the create is refused as `dir_in_the_way`, not `name_taken`: no repository has that
10 name, so "already has a repository by that name" would send the person looking for one that is
11 not there.
12
13 - The web (`/new`, `newRepoSubmit` in `src/web/pages/site.ts`) shows `REPO_DIR_IN_THE_WAY` from
14 `src/actions/repo_words.ts` beside the Name field: "No repository has that name, but a folder on
15 the forge's disk already holds it … Pick another name: this one stays held until that folder is removed from the disk."
16 - The terminal (both doors): the new-repository screen (`src/tui/screens/newrepo.ts`) shows the
17 refusal as a danger toast, worded by `dir_in_the_way` in the messages of
18 `src/tui/screens/common.ts`: "a folder on disk already holds that name, with no repository
19 behind it: pick another".
20
21 Deleting a base repository now also removes its sealed repositories' directories, so a delete
22 leaves no such leftover behind.
23
24 Try it: with a folder already under the owner's repository directory and no repository by that
25 name, open `/new`, give that name and submit; the message above sits beside Name. In the terminal,
26 press the new-repository key and give the same name.
27
28 Pinned by `test/repo-borrowers.test.ts` (a leftover directory, and two creates racing for one name,
29 both answer `dir_in_the_way`).
scripts/doorless-allow.json −1
@@ -86,7 +86,6 @@
8686 "src/web/pages/security.ts",
8787 "src/web/pages/settings.ts",
8888 "src/web/pages/signup-passkey.ts",
89 "src/web/pages/site.ts",
9089 "src/web/pages/spend-tab.ts",
9190 "src/web/pages/spend.ts",
9291 "src/web/pages/start_claim.ts",
src/actions/apps.ts +2 −1
@@ -11,7 +11,7 @@ import { getVariant } from "../core/variants.ts";
1111 import { pullDir } from "../core/pulls.ts";
1212 import { mayView, sealedPreviewPull } from "../core/sealed.ts";
1313 import { deriveAppName } from "../web/pages/apps-name.ts";
14 import { REPO_INIT_FAILED, REPO_NAME_RULES } from "./repo_words.ts";
14 import { REPO_DIR_IN_THE_WAY, REPO_INIT_FAILED, REPO_NAME_RULES } from "./repo_words.ts";
1515 import { NO_SUCH_AGENT } from "./crew_limit_words.ts";
1616 import { requireVerified } from "./verify.ts";
1717 import { seatCrew } from "../spawn/starter_crew.ts";
@@ -521,6 +521,7 @@ export const NEW_APP_ERRORS: Record<string, string> = {
521521 name_taken: "That owner already has a repository by that name.",
522522 invalid_name: REPO_NAME_RULES,
523523 git_init_failed: REPO_INIT_FAILED,
524 dir_in_the_way: REPO_DIR_IN_THE_WAY,
524525 invalid_slug:
525526 "That name makes no usable hostname — start it with a letter or digit.",
526527 invalid_secret:
src/actions/migrate.ts +3 −1
@@ -73,7 +73,7 @@ import {
7373 } from "../origins/jobs.ts";
7474 import type { Provider } from "../origins/types.ts";
7575 import { requireUser } from "./access.ts";
76 import { REPO_INIT_FAILED, REPO_NAME_RULES } from "./repo_words.ts";
76 import { REPO_DIR_IN_THE_WAY, REPO_INIT_FAILED, REPO_NAME_RULES } from "./repo_words.ts";
7777 import { enableApp } from "./apps.ts";
7878 import { addToCrew } from "./crew.ts";
7979 import { cleanOrigin, migrationBrief, migrationDirectionFor, setMigration } from "../apps/migration_mode.ts";
@@ -322,6 +322,8 @@ export function migrateMessage(error: MigrateError, limit = AT_REPOSITORY_LIMIT)
322322 return REPO_NAME_RULES;
323323 case "git_init_failed":
324324 return REPO_INIT_FAILED;
325 case "dir_in_the_way":
326 return REPO_DIR_IN_THE_WAY;
325327 case "forbidden_owner":
326328 return "You cannot create repositories for that owner.";
327329 case "owner_admin":
src/actions/repo_words.ts +4
@@ -9,3 +9,7 @@ export const REPO_NAME_RULES = "Names start with a letter or digit; no spaces, n
99
1010 /** `createRepo` failed as `git_init_failed`. */
1111 export const REPO_INIT_FAILED = "The repository could not be initialised on disk.";
12
13 /** `createRepo` refused as `dir_in_the_way`: a directory, but no repository. */
14 export const REPO_DIR_IN_THE_WAY =
15 "No repository has that name, but a folder on the forge's disk already holds it (a create still under way, or one left behind). Pick another name: this one stays held until that folder is removed from the disk.";
src/core/repos.ts +71 −9
@@ -9,7 +9,8 @@ import { forgetAppFilters } from "./ask_filters.ts";
99 import { isPacksMirror } from "../packs/owner.ts";
1010 import { contributionForksSince, isContributionFork } from "./contribute.ts";
1111 import type { Database } from "bun:sqlite";
12 import { rmSync } from "node:fs";
12 import { mkdirSync, rmSync } from "node:fs";
13 import { dirname } from "node:path";
1314 import { isSafeName } from "../git/guard.ts";
1415 import { installHooks } from "../git/hooks.ts";
1516 import { closeReader } from "../git/read.ts";
@@ -359,7 +360,12 @@ export function withCounts(db: Database, repos: Repo[]): Repo[] {
359360 }));
360361 }
361362
362 export type CreateRepoError = "invalid_name" | "name_taken" | "git_init_failed";
363 /**
364 * `dir_in_the_way`: no repository has the name, but a directory on disk holds
365 * it (a create still under way, or one left behind), and createRepo never
366 * takes over a directory it did not make.
367 */
368 export type CreateRepoError = "invalid_name" | "name_taken" | "dir_in_the_way" | "git_init_failed";
363369
364370 export interface CreateRepoInput {
365371 ownerId: string;
@@ -397,8 +403,16 @@ export async function createRepo(
397403 // Git first, row second: a row that exists is a repo you can clone.
398404 const dir = repoDir(reposRoot, owner.username, input.name);
outdated

An unowned leftover directory now answers name_taken forever with no repository to show. Distinguish 'a row owns this' from 'orphan directory' and handle the orphan (sweep it, or give a message a person can act on), with a test.

399405 const branch = input.defaultBranch ?? "main";
406 // The directory is claimed before git runs: a plain `mkdir` fails when
407 // another create (or anything else) already made it, so a refused row
408 // below only ever removes a directory this call made. With no row behind
409 // it, that is not `name_taken`: no page would show what holds the name.
410 if (!claimDir(dir)) return err("dir_in_the_way");
400411 const init = await initBareRepo(dir, { defaultBranch: branch });
401 if (!init.ok) return err("git_init_failed");
412 if (!init.ok) {
413 unclaimDir(dir);
414 return err("git_init_failed");
415 }
402416 await installHooks(dir);
403417
404418 const repoId = id();
@@ -583,6 +597,26 @@ function rowOrUndo(dir: string, insert: () => unknown): void {
583597 }
584598 }
585599
600 /**
601 * Make `dir` and nothing else: its parents may exist, it may not. False when
602 * it already does, so the caller never takes over a directory it did not make.
603 */
604 function claimDir(dir: string): boolean {
605 mkdirSync(dirname(dir), { recursive: true });
606 try {
607 mkdirSync(dir);
608 return true;
609 } catch (error) {
610 if ((error as NodeJS.ErrnoException).code === "EEXIST") return false;
611 throw error;
612 }
613 }
614
615 /** Give back a directory `claimDir` made, when git could not fill it. */
616 function unclaimDir(dir: string): void {
617 rmSync(dir, { recursive: true, force: true });
618 }
619
586620 /** The private repository `ownerId` works `baseId`'s sealed reports in, if any. */
587621 export function getSealedFork(
588622 db: Database,
@@ -673,6 +707,21 @@ export function listForks(db: Database, repoId: string): Repo[] {
673707 .map(toRepo);
outdated

Rewrap this comment: the line runs long and 'them.' sits alone on the next one.

674708 }
675709
710 /**
711 * Every repository whose object store borrows this one's through alternates:
712 * its forks and the sealed repositories made for it, which are copied the
713 * same way but name their base by `sealed_for`. Deleting or moving the store
714 * must reach each of them.
715 */
716 export function listBorrowers(db: Database, repoId: string): Repo[] {
717 return db
718 .query<RepoRow, [string]>(
719 `${SELECT} WHERE repo.fork_parent_id = ?1 OR repo.sealed_for = ?1 ORDER BY repo.id`,
720 )
721 .all(repoId)
722 .map(toRepo);
723 }
724
676725 /**
677726 * The repository this one was forked from, while that parent is still here
678727 * and the viewer may read it. A fork's lineage — the parent's name, and how
@@ -1091,9 +1140,12 @@ export function listReposByOwner(
10911140 * the repository stays listed and a retry finds it (`delete_failed`). A
10921141 * directory that is already missing leaves nothing to orphan, so the row still
10931142 * goes and `delete_failed` is still reported.
1094 * Before removing the objects, detach every fork that borrows them (repack so
1095 * the fork owns its objects, then drop its alternates link) — otherwise a
1096 * fork would be silently corrupted. This is the detach-before-delete rule.
1143 * Before removing the objects, detach every fork or sealed repository that
1144 * borrows them (repack so it owns its objects, then drop its alternates link)
1145 * — otherwise it would be silently corrupted. This is the detach-before-delete
1146 * rule. A sealed repository's row goes with its base's (`ON DELETE CASCADE`),
1147 * so its directory is removed after the base's row, leaving no directory
1148 * without a row to hold the name.
10971149 */
10981150 export async function deleteRepo(
10991151 db: Database,
@@ -1112,8 +1164,9 @@ export async function deleteRepo(
11121164 .get(repo.id) !== null
11131165 )
11141166 return err("has_pulls");
1115 const forks = listForks(db, repo.id);
1116 for (const fork of forks) {
1167 // Forks and sealed repositories alike borrow this store (`listBorrowers`).
1168 const borrowers = listBorrowers(db, repo.id);
1169 for (const fork of borrowers) {
11171170 const forkDir = repoDir(reposRoot, fork.ownerName, fork.name);
11181171 const detached = await detachFork(forkDir);
11191172 if (!detached.ok) {
@@ -1149,8 +1202,17 @@ export async function deleteRepo(
11491202 forgetAppFilters(db, repo.id);
11501203 db.query("DELETE FROM repo WHERE id = ?1").run(repo.id);
11511204 forgetRepoCursors(db, repo.id);
1205 // The cascade took each sealed repository's row; its directory follows.
1206 let sealedGone = true;
1207 for (const sealed of borrowers) {
1208 if (sealed.sealedFor !== repo.id) continue;
1209 const sealedDir = repoDir(reposRoot, sealed.ownerName, sealed.name);
1210 closeReader(sealedDir);
1211 const swept = await deleteRepoDir(sealedDir);
1212 if (!swept.ok && (await repoDirExists(sealedDir))) sealedGone = false;
1213 }
11521214 forgetListings(db);
1153 if (!removed.ok) return err("delete_failed");
1215 if (!removed.ok || !sealedGone) return err("delete_failed");
11541216 return ok();
11551217 }
11561218
src/core/transfer.ts +2 −2
@@ -19,7 +19,7 @@ import { repoDir, repoDirExists } from "../git/repos.ts";
1919 import { id } from "../kernel/id.ts";
2020 import { err, ok, type Result } from "../kernel/result.ts";
2121 import { forgetListings } from "./listings.ts";
22 import { getRepo, getRepoById, listForks, type Repo } from "./repos.ts";
22 import { getRepo, getRepoById, listBorrowers, type Repo } from "./repos.ts";
2323 import type { User } from "./users.ts";
2424
2525 export type TransferError = "name_taken" | "same_owner" | "same_name" | "invalid_name" | "move_failed";
@@ -169,7 +169,7 @@ async function moveNow(
169169 await rmdir(dirname(from)).catch(() => undefined);
170170 const objectsFrom = join(from, "objects");
171171 const objectsTo = join(to, "objects");
172 for (const fork of listForks(db, repo.id)) {
172 for (const fork of listBorrowers(db, repo.id)) {
173173 await rewriteAlternates(repoDir(reposRoot, fork.ownerName, fork.name), objectsFrom, objectsTo).catch(
174174 () => undefined,
175175 );
src/kernel/destroy_reach.ts +4
@@ -80,6 +80,10 @@ export const ALLOWED_REMOVALS: readonly { unit: string; why: string }[] = [
8080 "src/checks/install_evict.ts:evictInstallCache",
8181 "src/apps/checkout.ts:exportTree",
8282 ]),
83 {
84 unit: "src/core/repos.ts:unclaimDir",
85 why: "removes the directory `claimDir` has just made for the repository being created, when git could not init it",
86 },
8387 { unit: "src/core/repos.ts:rowOrUndo", why: "removes the directory git has just made for the repository being created, when its row is refused" },
8488 { unit: "src/git/locks.ts:sweepRefLock", why: "removes the one lock file of the ref a merge moves, when older than any live update (issue 12143): a name checked to be under refs/heads, never another file" },
8589 { unit: "src/git/write.ts:commitFiles", why: "removes its own temporary index file" },
src/origins/mirror.ts +3
@@ -41,6 +41,7 @@ export type MirrorError =
4141 | "name_taken"
4242 | "already_mirrored"
4343 | "git_init_failed"
44 | "dir_in_the_way"
4445 | "unreachable"
4546 | "repository_limit"
4647 | "storage_limit";
@@ -315,6 +316,8 @@ export function mirrorMessage(error: MirrorError): string {
315316 return "this repository is already mirrored here";
316317 case "git_init_failed":
317318 return "the local repository could not be created";
319 case "dir_in_the_way":
320 return "a folder on disk already holds that name, with no repository behind it";
318321 case "unreachable":
319322 return "the origin could not be reached";
320323 case "repository_limit":
src/tui/screens/common.ts +1
@@ -1023,6 +1023,7 @@ const MESSAGES: Record<string, string> = {
10231023 protected: "that cannot be deleted",
10241024 delete_failed: "the delete could not be completed",
10251025 git_init_failed: "git could not create the repository",
1026 dir_in_the_way: "a folder on disk already holds that name, with no repository behind it: pick another",
10261027 fork_failed: "the fork could not be created",
10271028 bad_anchor: "that line is not part of this diff",
10281029 invalid_url: "that URL is not valid (a git:// address is not supported: use its https:// address)",
src/web/pages/site.ts +2 −1
@@ -21,7 +21,7 @@ import { clientAddress } from "../../http/peer.ts";
2121 import { verifyEmail } from "../../actions/verify.ts";
2222 import { STRANGER_MAX } from "../../http/limits.ts";
2323 import { createRepo, repositoryLimitMessage, resolveOwner } from "../../actions/repos.ts";
24 import { REPO_INIT_FAILED, REPO_NAME_RULES } from "../../actions/repo_words.ts";
24 import { REPO_DIR_IN_THE_WAY, REPO_INIT_FAILED, REPO_NAME_RULES } from "../../actions/repo_words.ts";
2525 import { NOTE_MAX, requestOf } from "../../core/requests.ts";
2626 import { DECLINED_MESSAGE, REQUEST_IN_MESSAGE, STILL_WAITING_MESSAGE } from "../../actions/users.ts";
2727 import { HUMAN_CHECK_MESSAGE, INVITE_SPENT_MESSAGE, PASSKEY_REQUIRED_MESSAGE, SIGNUP_CLOSED_MESSAGE, signUp, signupClosed } from "../../actions/users.ts";
@@ -948,6 +948,7 @@ export async function newRepoSubmit(ctx: Ctx): Promise<Response> {
948948 name_taken: "That owner already has a repository by that name.",
949949 invalid_name: REPO_NAME_RULES,
950950 git_init_failed: REPO_INIT_FAILED,
951 dir_in_the_way: REPO_DIR_IN_THE_WAY,
951952 };
952953 return page(
953954 {
test/api-forge-view.test.ts +10
@@ -4,9 +4,11 @@
44 * board use, and costs one build per window however often it is polled.
55 */
66 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
7 import { mkdirSync, renameSync } from "node:fs";
78 import { mkdtemp, rm } from "node:fs/promises";
89 import { tmpdir } from "node:os";
910 import { join } from "node:path";
11 import { repoDir } from "../src/git/repos.ts";
1012 import { createApp, type App } from "../src/app.ts";
1113 import { DOOR_TTL_MS, foundryHref } from "../src/actions/foundry_door.ts";
1214 import { forgeView, VIEW_APPS } from "../src/actions/forge_view.ts";
@@ -173,6 +175,12 @@ describe("the forge view over the API", () => {
173175 const fake = await createRepo(app, adminUser, { name: "foundry", visibility: "public" });
174176 if (!fake.ok) throw new Error(String(fake.error));
175177 app.db.query("UPDATE repo SET owner_id = ?1 WHERE id = ?2").run(mallory.value.id, fake.value.id);
178 // The row moved by hand; its directory moves with it, as a transfer's does.
179 mkdirSync(join(app.reposRoot, mallory.value.username), { recursive: true });
180 renameSync(
181 repoDir(app.reposRoot, adminUser.username, "foundry"),
182 repoDir(app.reposRoot, mallory.value.username, "foundry"),
183 );
176184 createAppRecord(app.db, { repoId: fake.value.id, slug: "foundry", access: "public" });
177185 lapse();
178186 expect(door()).toBeUndefined();
@@ -246,6 +254,8 @@ describe("the forge view over the API", () => {
246254 app.db.query("DELETE FROM app WHERE slug = 'foundry'").run();
247255 // A person who signed up as trevato, where no admin holds the name: no door.
248256 app.db.query("UPDATE user SET username = 'trevato-org' WHERE id = ?1").run(org.id);
257 // The rename by hand moves the owner's directory too, as a real rename does.
258 renameSync(join(app.reposRoot, "trevato"), join(app.reposRoot, "trevato-org"));
249259 const squatter = await createUser(app.db, { username: "trevato", email: "[email protected]", password: "a-long-passphrase-here", origin: "seed", trusted: true });
250260 if (!squatter.ok) throw new Error(squatter.error);
251261 const theirs = await createRepoRow(app.db, app.reposRoot, { ownerId: squatter.value.id, name: "foundry", visibility: "public" });
test/repo-borrowers.test.ts added +136
@@ -0,0 +1,136 @@
1 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
2 import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
3 import { mkdtemp, rm } from "node:fs/promises";
4 import { tmpdir } from "node:os";
5 import { join } from "node:path";
6 import { createApp, type App } from "../src/app.ts";
7 import { createOrg } from "../src/actions/orgs.ts";
8 import { createRepo, deleteRepo, forkRepo, getRepo, listBorrowers, type Repo } from "../src/core/repos.ts";
9 import { transferRepo } from "../src/core/transfer.ts";
10 import { createUser, getUserByName, type User } from "../src/core/users.ts";
11 import { repoDir } from "../src/git/repos.ts";
12 import { commitFiles } from "../src/git/write.ts";
13 import { quietLogs } from "./helpers/globals.ts";
14
15 quietLogs();
16
17 /**
18 * A sealed repository is copied from its base with `--shared`, as a fork is,
19 * so it borrows the base's objects: deleting or moving the base reaches it
20 * (#15033). And `createRepo` claims its directory before git runs, so it
21 * never takes over, or later removes, one it did not make.
22 */
23 describe("the borrowers of a repository's objects", () => {
24 let dataDir = "";
25 let app: App;
26 let alice: User;
27 let bob: User;
28 let n = 0;
29
30 beforeAll(async () => {
31 dataDir = await mkdtemp(join(tmpdir(), "forge-borrowers-"));
32 app = createApp({ dataDir, port: 0 });
33 const made = async (username: string, admin: boolean) => {
34 const u = await createUser(app.db, {
35 origin: "seed",
36 trusted: true,
37 username,
38 email: `${username}@forge.local`,
39 password: "a-long-borrowers-passphrase",
40 adminIfFirst: admin,
41 });
42 if (!u.ok) throw new Error(u.error);
43 return u.value;
44 };
45 alice = await made("alice", true);
46 bob = await made("bob", false);
47 const org = createOrg(app, alice, "lab");
48 if (!org.ok) throw new Error(org.error);
49 });
50
51 afterAll(async () => {
52 app.close();
53 await rm(dataDir, { recursive: true, force: true });
54 });
55
56 /** A base with one commit, a fork and a sealed repository of it, both bob's. */
57 const family = async () => {
58 n += 1;
59 const made = await createRepo(app.db, app.reposRoot, { ownerId: alice.id, name: `base${n}`, visibility: "public" });
60 if (!made.ok) throw new Error(made.error);
61 const c = await commitFiles(repoDir(app.reposRoot, "alice", made.value.name), {
62 branch: "main",
63 message: "seed",
64 files: [{ path: "a.txt", content: "a" }],
65 author: { name: "T", email: "[email protected]" },
66 });
67 if (!c.ok) throw new Error("commit failed");
68 const fork = await forkRepo(app.db, app.reposRoot, made.value, bob.id);
69 if (!fork.ok) throw new Error(fork.error);
70 const sealed = await forkRepo(app.db, app.reposRoot, made.value, bob.id, undefined, { sealed: true });
71 if (!sealed.ok) throw new Error(sealed.error);
72 return { base: made.value, fork: fork.value, sealed: sealed.value, oid: c.value.commitOid };
73 };
74
75 const has = (dir: string, oid: string) =>
76 Bun.spawnSync(["git", "cat-file", "-e", `${oid}^{commit}`], { cwd: dir }).exitCode === 0;
77
78 test("listBorrowers names the forks and the sealed repositories", async () => {
79 const { base, fork, sealed } = await family();
80 const ids = listBorrowers(app.db, base.id).map((r: Repo) => r.id);
81 expect(ids.sort()).toEqual([fork.id, sealed.id].sort());
82 });
83
84 test("deleting the base takes its sealed repository's row and directory, and spares the fork", async () => {
85 const { base, fork, sealed, oid } = await family();
86 const sealedDir = repoDir(app.reposRoot, "bob", sealed.name);
87 const forkDir = repoDir(app.reposRoot, "bob", fork.name);
88 expect(existsSync(join(sealedDir, "objects", "info", "alternates"))).toBe(true);
89 const gone = await deleteRepo(app.db, app.reposRoot, base);
90 expect(gone.ok).toBe(true);
91 expect(getRepo(app.db, "alice", base.name)).toBeUndefined();
92 // The row cascades with its base; no directory is left to hold the name.
93 expect(getRepo(app.db, "bob", sealed.name)).toBeUndefined();
94 expect(existsSync(sealedDir)).toBe(false);
95 const again = await createRepo(app.db, app.reposRoot, { ownerId: bob.id, name: sealed.name });
96 expect(again.ok).toBe(true);
97 // The fork keeps its own copy of the objects.
98 expect(existsSync(join(forkDir, "objects", "info", "alternates"))).toBe(false);
99 expect(has(forkDir, oid)).toBe(true);
100 });
101
102 test("moving the base rewrites its sealed repository's alternates", async () => {
103 const { base, sealed, oid } = await family();
104 const sealedDir = repoDir(app.reposRoot, "bob", sealed.name);
105 const moved = await transferRepo(app.db, app.reposRoot, base, getUserByName(app.db, "lab")!, alice.id);
106 expect(moved.ok).toBe(true);
107 const alternates = readFileSync(join(sealedDir, "objects", "info", "alternates"), "utf8");
108 expect(alternates).toContain(join(repoDir(app.reposRoot, "lab", base.name), "objects"));
109 expect(has(sealedDir, oid)).toBe(true);
110 });
111
112 test("a leftover directory with no row is refused in its own words, and left whole", async () => {
113 const dir = repoDir(app.reposRoot, "alice", "claimed");
114 mkdirSync(dir, { recursive: true });
115 writeFileSync(join(dir, "someone-elses"), "kept");
116 const made = await createRepo(app.db, app.reposRoot, { ownerId: alice.id, name: "claimed" });
117 expect(made.ok).toBe(false);
118 // Not `name_taken`: no repository holds the name, so none could be shown.
119 if (!made.ok) expect(made.error).toBe("dir_in_the_way");
120 expect(readFileSync(join(dir, "someone-elses"), "utf8")).toBe("kept");
121 expect(existsSync(join(dir, "HEAD"))).toBe(false);
122 });
123
124 test("a second create while the first is still in git is refused, and the first's directory stays", async () => {
125 // The first runs up to its first await (git init) before the second
126 // starts, so the second meets the first's directory with no row yet.
127 const first = createRepo(app.db, app.reposRoot, { ownerId: alice.id, name: "twin" });
128 const second = await createRepo(app.db, app.reposRoot, { ownerId: alice.id, name: "twin" });
129 expect(second.ok).toBe(false);
130 if (!second.ok) expect(second.error).toBe("dir_in_the_way");
131 const won = await first;
132 expect(won.ok).toBe(true);
133 expect(getRepo(app.db, "alice", "twin")).toBeDefined();
134 expect(existsSync(join(repoDir(app.reposRoot, "alice", "twin"), "HEAD"))).toBe(true);
135 });
136 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs