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