( client: GitClient, args: string[], input: GitCliInput, )
| 444 | // --------------------------------------------------------------- |
| 445 | |
| 446 | async 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 |
no test coverage detected