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

Function runInit

packages/computer/src/git/cli.ts:446–481  ·  view source on GitHub ↗
(
  client: GitClient,
  args: string[],
  input: GitCliInput,
)

Source from the content-addressed store, hash-verified

444// ---------------------------------------------------------------
445
446async function runInit(
447 client: GitClient,
448 args: string[],
449 input: GitCliInput,
450): Promise<GitCliResult> {
451 // `git init [--initial-branch=<name>] [--bare] [<dir>]`
452 const parsed = parseFlags(args, {
453 "initial-branch": { kind: "value", alias: ["b"] },
454 bare: { kind: "bool" },
455 });
456 if ("error" in parsed) {
457 return { stdout: "", stderr: `git init: ${parsed.error}\n`, exitCode: 129 };
458 }
459 if (parsed.positional.length > 1) {
460 return {
461 stdout: "",
462 stderr: `git init: unexpected argument '${parsed.positional[1]}'\n`,
463 exitCode: 129,
464 };
465 }
466 const dir = resolveDir(parsed.positional[0], input.cwd);
467 try {
468 await client.init({
469 dir,
470 defaultBranch: parsed.flags["initial-branch"] as string | undefined,
471 bare: parsed.flags.bare === true,
472 });
473 } catch (cause) {
474 return mapGitError("init", cause);
475 }
476 return {
477 stdout: `Initialized empty Git repository in ${dir}/.git/\n`,
478 stderr: "",
479 exitCode: 0,
480 };
481}
482
483// ---------------------------------------------------------------
484// status

Callers 1

runGitCliFunction · 0.85

Calls 4

resolveDirFunction · 0.85
mapGitErrorFunction · 0.85
parseFlagsFunction · 0.70
initMethod · 0.65

Tested by

no test coverage detected