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

Function runStatus

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

Source from the content-addressed store, hash-verified

485// ---------------------------------------------------------------
486
487async function runStatus(
488 client: GitClient,
489 args: string[],
490 input: GitCliInput,
491): Promise<GitCliResult> {
492 // `git status [--porcelain[=v2]] [--short | -s]`
493 const parsed = parseFlags(args, {
494 porcelain: { kind: "value-or-bool" },
495 short: { kind: "bool", alias: ["s"] },
496 });
497 if ("error" in parsed) {
498 return { stdout: "", stderr: `git status: ${parsed.error}\n`, exitCode: 129 };
499 }
500 if (parsed.positional.length > 0) {
501 return {
502 stdout: "",
503 stderr: `git status: unexpected argument '${parsed.positional[0]}'\n`,
504 exitCode: 129,
505 };
506 }
507 // Format selection. The bare default is porcelain v2 — the
508 // typed CLI surface is intentionally machine-readable and the
509 // long-form human output is deferred. `--porcelain=v1` (and the
510 // `1` spelling git also accepts) selects the v1 `XY <path>`
511 // shape that the bulk of tooling parses.
512 const porcelain = parsed.flags.porcelain;
513 const useShort = parsed.flags.short === true;
514 const isV1 = porcelain === "v1" || porcelain === "1";
515 const isV2 = porcelain === undefined || porcelain === true || porcelain === "v2";
516 if (porcelain !== undefined && porcelain !== true && !isV1 && !isV2) {
517 return {
518 stdout: "",
519 stderr: `git status: unsupported --porcelain value '${porcelain}'\n`,
520 exitCode: 129,
521 };
522 }
523 const dir = resolveDir(undefined, input.cwd);
524 let entries: StatusEntry[];
525 try {
526 entries = await client.status({ dir });
527 } catch (cause) {
528 return mapGitError("status", cause);
529 }
530 const stdout = useShort
531 ? formatShort(entries)
532 : isV1
533 ? formatPorcelainV1(entries)
534 : formatPorcelainV2(entries);
535 return { stdout, stderr: "", exitCode: 0 };
536}
537
538// ---------------------------------------------------------------
539// add

Callers 1

runGitCliFunction · 0.85

Calls 7

resolveDirFunction · 0.85
mapGitErrorFunction · 0.85
formatShortFunction · 0.85
formatPorcelainV1Function · 0.85
formatPorcelainV2Function · 0.85
parseFlagsFunction · 0.70
statusMethod · 0.65

Tested by

no test coverage detected