MCPcopy Create free account
hub / github.com/cloudflare/computer / initWith

Function initWith

packages/computer/src/git/init.ts:43–70  ·  view source on GitHub ↗
(opts: InitWithDeps)

Source from the content-addressed store, hash-verified

41}
42
43export async function initWith(opts: InitWithDeps): Promise<void> {
44 const dir = opts.dir ?? "/";
45 const defaultBranch = opts.defaultBranch ?? "main";
46 const bare = opts.bare ?? false;
47
48 // Detect "already a repo" up front so we can throw the typed
49 // error. isomorphic-git's `init` is documented as idempotent,
50 // so without this probe a second call would silently succeed.
51 if (!bare) {
52 const probe = (opts.fs as InitFsProbe).promises?.stat;
53 if (typeof probe === "function") {
54 try {
55 await probe(joinPath(dir, ".git"));
56 throw new AlreadyInitializedError(dir);
57 } catch (cause) {
58 if (cause instanceof AlreadyInitializedError) throw cause;
59 // anything else — including the expected ENOENT —
60 // means "no repo here; safe to init".
61 }
62 }
63 }
64
65 try {
66 await opts.git.init({ fs: opts.fs, dir, bare, defaultBranch });
67 } catch (cause) {
68 throw new GitError("EINITFAIL", `git init failed: ${errorMessage(cause)}`, { cause });
69 }
70}
71
72function joinPath(base: string, segment: string): string {
73 if (base.endsWith("/")) return `${base}${segment}`;

Callers 2

initFunction · 0.85
init.test.tsFile · 0.85

Calls 3

joinPathFunction · 0.70
errorMessageFunction · 0.70
initMethod · 0.65

Tested by

no test coverage detected