@osdlc/typed-git 0.5.0 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/verbs.ts CHANGED
@@ -9,6 +9,8 @@
9
9
  *
10
10
  * {@link gate} is the single place a git result becomes either a value or a
11
11
  * `CommandFailed`. Both clients call it, so they cannot disagree.
12
+ *
13
+ * `GitVerb` and `gate` are internal: the package entries do not export them.
12
14
  */
13
15
 
14
16
  import { CommandFailed, type CommandResult } from '@osdlc/command-seam'
@@ -21,13 +23,20 @@ export interface GitVerb<T> {
21
23
  argv: string[]
22
24
  /** Written to the child's stdin when set. */
23
25
  input?: string | undefined
26
+ /**
27
+ * Environment entries the verb needs, set over the client's and the call's
28
+ * `env`. The integration verbs set `LC_ALL=C` here so their parsers read
29
+ * English git output.
30
+ */
31
+ env?: Readonly<Record<string, string>> | undefined
24
32
  /**
25
33
  * Exit codes that mean "asked and answered: not there" for this verb — not
26
34
  * "git failed". `config --get` exits 1 for an unset key, `cat-file -e` exits
27
35
  * 1 for a missing object. Those codes reach {@link GitVerb.parse}, which
28
36
  * turns them into the verb's absence value; any other non-zero exit throws.
29
37
  *
30
- * A mutation declares `[]`: nothing about a failed `push` is an answer. That
38
+ * A mutation declares `[]`: nothing about a failed `push` is an answer
39
+ * (`configRemoveSection` is the one exception). That
31
40
  * is the whole checked/unchecked distinction, so there is no `checked` flag
32
41
  * to contradict it.
33
42
  */
@@ -61,9 +70,17 @@ export interface GitVerb<T> {
61
70
  * this table (`configGet`, `resolveRef`, `mergeBase`, `checkIgnore`,
62
71
  * `isAncestor`, `grep`, `revParse`). Read as an absence it would answer "no
63
72
  * such key / ref / match" for a git that never ran.
73
+ *
74
+ * A result flagged `outputIncomplete` is a failure too. The child exited, but
75
+ * the runner stopped reading at the output cap (`maxOutputBytes`) or at a
76
+ * timeout, so a parse would read cut-short output as the whole answer.
64
77
  */
65
78
  export function gate<T>(verb: GitVerb<T>, result: CommandResult, argv?: string[]): T {
66
- if (result.neverExited || (result.exitCode !== 0 && !verb.absent.includes(result.exitCode))) {
79
+ if (
80
+ result.neverExited ||
81
+ result.outputIncomplete ||
82
+ (result.exitCode !== 0 && !verb.absent.includes(result.exitCode))
83
+ ) {
67
84
  throw new CommandFailed(argv ?? verb.argv, result)
68
85
  }
69
86
  return verb.parse(result, argv ?? verb.argv)
@@ -85,6 +102,20 @@ export function mergeEnv(
85
102
  return { ...base, ...call }
86
103
  }
87
104
 
105
+ /**
106
+ * Split a variadic `revParse` call into its string args and a trailing
107
+ * options object, when there is one. Shared by `Git` and `AsyncGit`.
108
+ */
109
+ export function splitTrailingOptions<O extends object>(
110
+ args: ReadonlyArray<string | O>,
111
+ ): [string[], O] {
112
+ const last = args[args.length - 1]
113
+ if (last !== undefined && typeof last !== 'string') {
114
+ return [args.slice(0, -1) as string[], last]
115
+ }
116
+ return [args as string[], {} as O]
117
+ }
118
+
88
119
  /**
89
120
  * The `--git-dir=` / `--work-tree=` flags that bind an invocation to one
90
121
  * repository, or `[]` when neither is set. Shared by `Git` and `cliBackend`.
@@ -222,6 +253,67 @@ function nothing(): void {}
222
253
  /** No exit code is an answer here — the gate throws on any non-zero exit. */
223
254
  const NONE: readonly number[] = []
224
255
 
256
+ /**
257
+ * Refuse a ref, remote, URL, path, pattern or config-key positional that
258
+ * starts with `-`.
259
+ *
260
+ * git reads such a value as an option. `--upload-pack=<cmd>` given as a remote
261
+ * runs `<cmd>`. The check throws a `TypeError` before anything spawns, so
262
+ * `try` and `soft` let it through. Write `./-name` for a path that starts with
263
+ * `-`, and `@{-1}` for the previous branch.
264
+ */
265
+ function positional(verb: string, param: string, value: string): string {
266
+ if (value.startsWith('-')) {
267
+ throw new TypeError(
268
+ `typed-git: ${verb}: ${param} must not start with "-" (got ${JSON.stringify(value)})`,
269
+ )
270
+ }
271
+ return value
272
+ }
273
+
274
+ /**
275
+ * A config key for the `config` reads: {@link positional}, plus a section and
276
+ * a name.
277
+ *
278
+ * git exits 1 for a key with no `.`, or one that starts or ends with `.`. That
279
+ * is the code the reads take as "unset", so a typo would read as no value. The
280
+ * check throws a `TypeError` instead, before anything spawns.
281
+ */
282
+ function configKey(verb: string, key: string): string {
283
+ positional(verb, 'key', key)
284
+ if (!key.includes('.') || key.startsWith('.') || key.endsWith('.')) {
285
+ throw new TypeError(
286
+ `typed-git: ${verb}: key must be <section>.<name> (got ${JSON.stringify(key)})`,
287
+ )
288
+ }
289
+ return key
290
+ }
291
+
292
+ /**
293
+ * A `--depth` value, refused with a `TypeError` unless it is a positive safe
294
+ * integer. git rejects the others too, but only after it runs.
295
+ */
296
+ function depthArg(verb: string, depth: number): string {
297
+ if (!Number.isSafeInteger(depth) || depth < 1) {
298
+ throw new TypeError(
299
+ `typed-git: ${verb}: depth must be a positive integer (got ${JSON.stringify(depth)})`,
300
+ )
301
+ }
302
+ return `--depth=${depth}`
303
+ }
304
+
305
+ /** {@link positional}, for an optional value. */
306
+ function optionalPositional(
307
+ verb: string,
308
+ param: string,
309
+ value: string | undefined,
310
+ ): string | undefined {
311
+ return value === undefined ? undefined : positional(verb, param, value)
312
+ }
313
+
314
+ /** The child env that makes git print English, whatever the caller's locale. */
315
+ const C_LOCALE: Readonly<Record<string, string>> = Object.freeze({ LC_ALL: 'C' })
316
+
225
317
  // ── queries ─────────────────────────────────────────────────────────────────
226
318
 
227
319
  /**
@@ -233,7 +325,7 @@ const NONE: readonly number[] = []
233
325
  */
234
326
  export function showAtRev(rev: string, relPath: string): GitVerb<string | null> {
235
327
  return {
236
- argv: ['show', `${rev}:${relPath}`],
328
+ argv: ['show', `${positional('showAtRev', 'rev', rev)}:${relPath}`],
237
329
  absent: [128],
238
330
  // NOT trimmedOrNull: file content is returned verbatim, trailing newline
239
331
  // included, because a caller round-tripping a blob must get its bytes.
@@ -270,7 +362,7 @@ export function revParse(...args: string[]): GitVerb<string | null> {
270
362
  */
271
363
  export function resolveRef(ref: string): GitVerb<string | null> {
272
364
  return {
273
- argv: ['rev-parse', '--verify', '--quiet', ref],
365
+ argv: ['rev-parse', '--verify', '--quiet', positional('resolveRef', 'ref', ref)],
274
366
  absent: [1],
275
367
  parse: trimmedOrNull,
276
368
  }
@@ -324,6 +416,20 @@ export function gitCommonDir(): GitVerb<string | null> {
324
416
  }
325
417
  }
326
418
 
419
+ /**
420
+ * This worktree's own `.git` dir as an absolute path, or null outside a repo
421
+ * (`rev-parse --absolute-git-dir`).
422
+ *
423
+ * In a linked worktree it is `<common>/worktrees/<name>`, not the shared dir
424
+ * {@link gitCommonDir} gives. Per-worktree state lives here: a rebase in
425
+ * progress is a `rebase-merge` or `rebase-apply` directory in it.
426
+ *
427
+ * `absent: [128]`, as for {@link gitCommonDir}: "not a repository" is an answer.
428
+ */
429
+ export function gitDir(): GitVerb<string | null> {
430
+ return { argv: ['rev-parse', '--absolute-git-dir'], absent: [128], parse: trimmedOrNull }
431
+ }
432
+
327
433
  /**
328
434
  * The full refname a symbolic ref points at, or null when it is not one.
329
435
  *
@@ -337,7 +443,11 @@ export function gitCommonDir(): GitVerb<string | null> {
337
443
  * rather than taking the last segment: the name may contain slashes.
338
444
  */
339
445
  export function symbolicRef(ref: string): GitVerb<string | null> {
340
- return { argv: ['symbolic-ref', ref], absent: [128], parse: trimmedOrNull }
446
+ return {
447
+ argv: ['symbolic-ref', positional('symbolicRef', 'ref', ref)],
448
+ absent: [128],
449
+ parse: trimmedOrNull,
450
+ }
341
451
  }
342
452
 
343
453
  /**
@@ -352,13 +462,7 @@ export function currentBranch(): GitVerb<string | null> {
352
462
  return { argv: ['branch', '--show-current'], absent: NONE, parse: trimmedOrNull }
353
463
  }
354
464
 
355
- /**
356
- * `git status --porcelain` lines; empty array on a clean tree, and a throw
357
- * outside a repository (exit 128).
358
- *
359
- * Verbatim: the first two columns are the status, so ` M f.ts` (unstaged
360
- * modification) must not be trimmed down to `M f.ts` (staged one).
361
- */
465
+ /** Options for {@link statusPorcelain}. */
362
466
  export interface StatusPorcelainOptions {
363
467
  /**
364
468
  * Pathspecs, passed after `--`. Narrows the report to one subtree.
@@ -366,7 +470,13 @@ export interface StatusPorcelainOptions {
366
470
  paths?: string[] | undefined
367
471
  }
368
472
 
369
- /** `git status --porcelain` lines. See {@link StatusPorcelainOptions}. */
473
+ /**
474
+ * `git status --porcelain` lines; empty array on a clean tree, and a throw
475
+ * outside a repository (exit 128).
476
+ *
477
+ * Verbatim: the first two columns are the status, so ` M f.ts` (unstaged
478
+ * modification) must not be trimmed down to `M f.ts` (staged one).
479
+ */
370
480
  export function statusPorcelain(opts: StatusPorcelainOptions = {}): GitVerb<string[]> {
371
481
  const argv = ['status', '--porcelain']
372
482
  if (opts.paths !== undefined && opts.paths.length > 0) argv.push('--', ...opts.paths)
@@ -417,7 +527,7 @@ export function statusEntries(): GitVerb<StatusEntry[]> {
417
527
  /** Local branch shortnames matching `pattern` (all when omitted). */
418
528
  export function branches(pattern?: string | undefined): GitVerb<string[]> {
419
529
  const argv = ['branch', '--list', '--format=%(refname:short)']
420
- if (pattern !== undefined) argv.push(pattern)
530
+ if (pattern !== undefined) argv.push(positional('branches', 'pattern', pattern))
421
531
  return { argv, absent: NONE, parse: trimmedLines }
422
532
  }
423
533
 
@@ -470,7 +580,11 @@ export function worktrees(): GitVerb<Worktree[]> {
470
580
  * (exit 1). A rev that does not resolve exits 128 and throws.
471
581
  */
472
582
  export function mergeBase(a: string, b: string): GitVerb<string | null> {
473
- return { argv: ['merge-base', a, b], absent: [1], parse: trimmedOrNull }
583
+ return {
584
+ argv: ['merge-base', positional('mergeBase', 'a', a), positional('mergeBase', 'b', b)],
585
+ absent: [1],
586
+ parse: trimmedOrNull,
587
+ }
474
588
  }
475
589
 
476
590
  /**
@@ -482,7 +596,7 @@ export function mergeBase(a: string, b: string): GitVerb<string | null> {
482
596
  */
483
597
  export function logSubject(ref: string): GitVerb<string | null> {
484
598
  return {
485
- argv: ['log', '-1', '--format=%s', ref],
599
+ argv: ['log', '-1', '--format=%s', positional('logSubject', 'ref', ref)],
486
600
  absent: [128],
487
601
  parse(r) {
488
602
  if (r.exitCode !== 0) return null
@@ -493,9 +607,73 @@ export function logSubject(ref: string): GitVerb<string | null> {
493
607
  }
494
608
  }
495
609
 
610
+ /** Which config file a `config` verb reads or writes. */
611
+ export type ConfigScope = 'local' | 'global' | 'system'
612
+
613
+ /** Options for {@link configGet}, {@link configGetAll} and {@link configGetBool}. */
614
+ export interface ConfigGetOptions {
615
+ /**
616
+ * Read one file only. Omitted means every file git reads, the last value
617
+ * winning. `local` outside a repository exits 128 and throws.
618
+ */
619
+ scope?: ConfigScope | undefined
620
+ }
621
+
622
+ /** The `config` read argv: the scope flag when one is given, the flags, the checked key. */
623
+ function configRead(flags: string[], key: string, opts: ConfigGetOptions): string[] {
624
+ const argv = ['config']
625
+ if (opts.scope !== undefined) argv.push(`--${opts.scope}`)
626
+ argv.push(...flags, key)
627
+ return argv
628
+ }
629
+
496
630
  /** `git config --get <key>`, or null when unset (exit 1). */
497
- export function configGet(key: string): GitVerb<string | null> {
498
- return { argv: ['config', '--get', key], absent: [1], parse: trimmedOrNull }
631
+ export function configGet(key: string, opts: ConfigGetOptions = {}): GitVerb<string | null> {
632
+ return {
633
+ argv: configRead(['--get'], configKey('configGet', key), opts),
634
+ absent: [1],
635
+ parse: trimmedOrNull,
636
+ }
637
+ }
638
+
639
+ /**
640
+ * Every value of a multi-valued key (`git config --get-all -z <key>`), in the
641
+ * order git reads them. `[]` when the key is unset (exit 1).
642
+ *
643
+ * `-z` ends each value with NUL, so a value holding a newline stays whole and
644
+ * an empty value is kept as `""`. Values are verbatim, not trimmed.
645
+ */
646
+ export function configGetAll(key: string, opts: ConfigGetOptions = {}): GitVerb<string[]> {
647
+ return {
648
+ argv: configRead(['--get-all', '-z'], configKey('configGetAll', key), opts),
649
+ absent: [1],
650
+ parse(r) {
651
+ if (r.exitCode !== 0) return []
652
+ // Each value ends with NUL, so the last field is always the empty tail.
653
+ return r.stdout.split('\x00').slice(0, -1)
654
+ },
655
+ }
656
+ }
657
+
658
+ /**
659
+ * A key read as a boolean (`git config --type=bool --get <key>`), or null when
660
+ * unset (exit 1).
661
+ *
662
+ * git does the reading: `yes`, `on`, `1` and a bare key are `true`. A value
663
+ * git cannot read as a boolean exits 128 and throws.
664
+ */
665
+ export function configGetBool(key: string, opts: ConfigGetOptions = {}): GitVerb<boolean | null> {
666
+ return {
667
+ argv: configRead(['--type=bool', '--get'], configKey('configGetBool', key), opts),
668
+ absent: [1],
669
+ parse(r, ranArgv) {
670
+ if (r.exitCode !== 0) return null
671
+ const out = r.stdout.trim()
672
+ if (out === 'true') return true
673
+ if (out === 'false') return false
674
+ throw new CommandFailed(ranArgv, r)
675
+ },
676
+ }
499
677
  }
500
678
 
501
679
  /**
@@ -515,18 +693,13 @@ export function configGet(key: string): GitVerb<string | null> {
515
693
  */
516
694
  export function objectExists(rev: string): GitVerb<boolean> {
517
695
  return {
518
- argv: ['cat-file', '-e', rev],
696
+ argv: ['cat-file', '-e', positional('objectExists', 'rev', rev)],
519
697
  absent: [1, 128],
520
698
  parse: (r) => r.exitCode === 0,
521
699
  }
522
700
  }
523
701
 
524
- /**
525
- * `ls-remote` rows for a remote (optionally pattern- and kind-filtered).
526
- *
527
- * `absent: []` — a remote with no matching refs answers with exit 0 and no
528
- * output, so `[]` means "no refs". An unreachable remote exits 128 and throws.
529
- */
702
+ /** Options for {@link lsRemote}. */
530
703
  export interface LsRemoteOptions {
531
704
  /** `--heads` — branches only. */
532
705
  heads?: boolean | undefined
@@ -534,7 +707,12 @@ export interface LsRemoteOptions {
534
707
  tags?: boolean | undefined
535
708
  }
536
709
 
537
- /** Refs on a remote, optionally pattern-filtered. See {@link LsRemoteOptions}. */
710
+ /**
711
+ * `ls-remote` rows for a remote (optionally pattern- and kind-filtered).
712
+ *
713
+ * `absent: []` — a remote with no matching refs answers with exit 0 and no
714
+ * output, so `[]` means "no refs". An unreachable remote exits 128 and throws.
715
+ */
538
716
  export function lsRemote(
539
717
  remote: string,
540
718
  pattern?: string | undefined,
@@ -543,8 +721,8 @@ export function lsRemote(
543
721
  const argv = ['ls-remote']
544
722
  if (opts.heads) argv.push('--heads')
545
723
  if (opts.tags) argv.push('--tags')
546
- argv.push(remote)
547
- if (pattern !== undefined) argv.push(pattern)
724
+ argv.push(positional('lsRemote', 'remote', remote))
725
+ if (pattern !== undefined) argv.push(positional('lsRemote', 'pattern', pattern))
548
726
  return {
549
727
  argv,
550
728
  absent: NONE,
@@ -715,7 +893,9 @@ export function forEachRef(
715
893
  const argv = ['for-each-ref', `--format=${opts.format ?? REF_FORMAT}`]
716
894
  if (opts.sort !== undefined) argv.push(`--sort=${opts.sort}`)
717
895
  if (opts.count !== undefined) argv.push(`--count=${opts.count}`)
718
- argv.push(...(typeof pattern === 'string' ? [pattern] : pattern))
896
+ for (const p of typeof pattern === 'string' ? [pattern] : pattern) {
897
+ argv.push(positional('forEachRef', 'pattern', p))
898
+ }
719
899
  return { argv, absent: NONE, parse: lines }
720
900
  }
721
901
 
@@ -764,7 +944,8 @@ export function diffNameOnly(opts: DiffNameOnlyOptions = {}): GitVerb<string[]>
764
944
  const argv = ['diff', '--name-only', '-z']
765
945
  if (opts.cached) argv.push('--cached')
766
946
  if (opts.diffFilter !== undefined) argv.push(`--diff-filter=${opts.diffFilter}`)
767
- if (opts.rangeArgs !== undefined) argv.push(...opts.rangeArgs)
947
+ for (const token of opts.rangeArgs ?? [])
948
+ argv.push(positional('diffNameOnly', 'rangeArgs', token))
768
949
  if (opts.paths !== undefined && opts.paths.length > 0) argv.push('--', ...opts.paths)
769
950
  return { argv, absent: NONE, parse: nulFields }
770
951
  }
@@ -783,7 +964,7 @@ export interface DiffStatOptions {
783
964
  */
784
965
  export function diffStat(opts: DiffStatOptions = {}): GitVerb<string> {
785
966
  const argv = ['diff', '--stat']
786
- if (opts.rangeArgs !== undefined) argv.push(...opts.rangeArgs)
967
+ for (const token of opts.rangeArgs ?? []) argv.push(positional('diffStat', 'rangeArgs', token))
787
968
  if (opts.paths !== undefined && opts.paths.length > 0) argv.push('--', ...opts.paths)
788
969
  return { argv, absent: NONE, parse: (r) => r.stdout }
789
970
  }
@@ -842,7 +1023,7 @@ export function diffNameStatus(opts: DiffNameStatusOptions = {}): GitVerb<DiffEn
842
1023
  const argv = ['diff', '--name-status', '-z']
843
1024
  if (opts.cached) argv.push('--cached')
844
1025
  if (opts.noRenames) argv.push('--no-renames')
845
- if (opts.range !== undefined) argv.push(opts.range)
1026
+ if (opts.range !== undefined) argv.push(positional('diffNameStatus', 'range', opts.range))
846
1027
  if (opts.paths !== undefined && opts.paths.length > 0) argv.push('--', ...opts.paths)
847
1028
  return { argv, absent: NONE, parse: nameStatusEntries }
848
1029
  }
@@ -909,11 +1090,11 @@ export function log(opts: LogOptions = {}): GitVerb<string> {
909
1090
  if (opts.nameStatus) argv.push('--name-status')
910
1091
  if (opts.numstat) argv.push('--numstat')
911
1092
  if (opts.relative) argv.push('--relative')
912
- if (opts.rev !== undefined) argv.push(opts.rev)
913
- if (opts.range !== undefined) argv.push(opts.range)
1093
+ if (opts.rev !== undefined) argv.push(positional('log', 'rev', opts.rev))
1094
+ if (opts.range !== undefined) argv.push(positional('log', 'range', opts.range))
914
1095
  // `--not` negates every rev after it, so the positive revs must precede it.
915
1096
  if (opts.notRefs !== undefined && opts.notRefs.length > 0) {
916
- argv.push('--not', ...opts.notRefs)
1097
+ argv.push('--not', ...opts.notRefs.map((ref) => positional('log', 'notRefs', ref)))
917
1098
  }
918
1099
  if (opts.paths !== undefined && opts.paths.length > 0) argv.push('--', ...opts.paths)
919
1100
  // Verbatim, trailing newline included: the caller's format decides where a
@@ -957,7 +1138,7 @@ export function lsTree(rev: string, opts: LsTreeOptions = {}): GitVerb<TreeEntry
957
1138
  const argv = ['ls-tree', '-z']
958
1139
  if (opts.recursive) argv.push('-r')
959
1140
  if (opts.long) argv.push('--long')
960
- argv.push(rev)
1141
+ argv.push(positional('lsTree', 'rev', rev))
961
1142
  if (opts.paths !== undefined && opts.paths.length > 0) argv.push('--', ...opts.paths)
962
1143
  return {
963
1144
  argv,
@@ -1012,47 +1193,54 @@ export interface DiffTreeOptions {
1012
1193
  paths?: string[] | undefined
1013
1194
  }
1014
1195
 
1196
+ /** Options for {@link diffText}. */
1197
+ export interface DiffTextOptions {
1198
+ /** `--cached` — diff the index against `rev` (or HEAD) rather than the worktree. */
1199
+ staged?: boolean | undefined
1200
+ /** Pathspecs, passed after `--`. */
1201
+ paths?: string[] | undefined
1202
+ }
1203
+
1015
1204
  /**
1016
- * The unified diff text itself, for the same rev/staged shape
1017
- * {@link diffNameOnly} selects paths for. Empty string on failure or when
1205
+ * The unified diff text (`git diff [--cached] [rev] [-- paths]`), for the same
1206
+ * rev and staged shape {@link diffNameOnly} selects paths for. Empty when
1018
1207
  * nothing differs.
1208
+ *
1209
+ * `absent: []`. A rev that does not resolve exits 128, and outside a
1210
+ * repository `git diff` exits 129. Both throw, so "git failed" never reads as
1211
+ * "no diff". `git.try.diffText` reports them as `{ ok: false }`.
1019
1212
  */
1020
- export function diffText(
1021
- rev?: string | undefined,
1022
- opts: { staged?: boolean | undefined; paths?: string[] | undefined } = {},
1023
- ): GitVerb<string> {
1213
+ export function diffText(rev?: string | undefined, opts: DiffTextOptions = {}): GitVerb<string> {
1024
1214
  const argv = ['diff']
1025
1215
  if (opts.staged === true) argv.push('--cached')
1026
- if (rev !== undefined) argv.push(rev)
1216
+ const from = optionalPositional('diffText', 'rev', rev)
1217
+ if (from !== undefined) argv.push(from)
1027
1218
  if (opts.paths !== undefined && opts.paths.length > 0) argv.push('--', ...opts.paths)
1028
- // Any non-zero exit is reported as "no diff" rather than thrown: a bad rev
1029
- // (128) and being outside a repository (129) both mean there is nothing to
1030
- // judge, which is what the caller acts on either way.
1031
- return { argv, absent: [1, 128, 129], parse: (r) => (r.exitCode === 0 ? r.stdout : '') }
1219
+ return { argv, absent: NONE, parse: (r) => r.stdout }
1032
1220
  }
1033
1221
 
1034
1222
  /**
1035
1223
  * One untracked file rendered as an all-added diff
1036
1224
  * (`diff --no-index -- /dev/null <path>`), so a new file reaches a consumer in
1037
- * the same shape as a modified one. Empty string when unreadable.
1225
+ * the same shape as a modified one. An empty existing file still gives a diff
1226
+ * header.
1038
1227
  *
1039
1228
  * `--no-index` exits 1 whenever the inputs differ, which for a real file is
1040
- * always — so a non-zero exit here is the success case, and only empty output
1041
- * means failure.
1229
+ * always, so exit 1 is the success case. git also exits 1, with empty stdout,
1230
+ * for a path it cannot read; that throws `CommandFailed`. Exit 2 (a usage or
1231
+ * read error) throws too.
1042
1232
  */
1043
1233
  export function diffAddedFile(relPath: string): GitVerb<string> {
1044
1234
  return {
1045
1235
  argv: ['diff', '--no-index', '--', '/dev/null', relPath],
1046
- // 1 is the SUCCESS case here — `--no-index` returns it whenever the inputs
1047
- // differ, which for a real file is always. 2 is its usage/read error, and
1048
- // yields the empty stdout the parser already treats as failure.
1049
- absent: [1, 2],
1050
- parse: (r) => r.stdout,
1236
+ absent: [1],
1237
+ parse(r, ranArgv) {
1238
+ if (r.exitCode !== 0 && r.stdout === '') throw new CommandFailed(ranArgv, r)
1239
+ return r.stdout
1240
+ },
1051
1241
  }
1052
1242
  }
1053
1243
 
1054
- // ── mutations (checked — the caller throws CommandFailed on non-zero) ────────
1055
-
1056
1244
  /**
1057
1245
  * The paths and statuses one commit changed (`git diff-tree --name-status -z`).
1058
1246
  *
@@ -1071,7 +1259,7 @@ export function diffTree(rev: string, opts: DiffTreeOptions = {}): GitVerb<DiffE
1071
1259
  if (opts.root) argv.push('--root')
1072
1260
  if (opts.noRenames) argv.push('--no-renames')
1073
1261
  if (opts.findRenames) argv.push('-M')
1074
- argv.push('--name-status', '-z', rev)
1262
+ argv.push('--name-status', '-z', positional('diffTree', 'rev', rev))
1075
1263
  if (opts.paths !== undefined && opts.paths.length > 0) argv.push('--', ...opts.paths)
1076
1264
  return { argv, absent: NONE, parse: nameStatusEntries }
1077
1265
  }
@@ -1097,7 +1285,7 @@ export function diffTreeNumstat(rev: string, opts: DiffTreeOptions = {}): GitVer
1097
1285
  const argv = ['diff-tree', '-r', '--no-commit-id']
1098
1286
  if (opts.root) argv.push('--root')
1099
1287
  if (opts.noRenames) argv.push('--no-renames')
1100
- argv.push('--numstat', '-z', rev)
1288
+ argv.push('--numstat', '-z', positional('diffTreeNumstat', 'rev', rev))
1101
1289
  if (opts.paths !== undefined && opts.paths.length > 0) argv.push('--', ...opts.paths)
1102
1290
  return {
1103
1291
  argv,
@@ -1157,7 +1345,8 @@ export function grep(pattern: string, opts: GrepOptions = {}): GitVerb<string[]>
1157
1345
  if (opts.lineNumber) argv.push('-n')
1158
1346
  if (opts.extendedRegexp) argv.push('-E')
1159
1347
  if (opts.noColor) argv.push('--no-color')
1160
- argv.push(pattern)
1348
+ // `-e` marks the pattern as a pattern, so one that starts with `-` is searched for.
1349
+ argv.push('-e', pattern)
1161
1350
  if (opts.paths !== undefined && opts.paths.length > 0) argv.push('--', ...opts.paths)
1162
1351
  return { argv, absent: [1], parse: lines }
1163
1352
  }
@@ -1173,7 +1362,12 @@ export function grep(pattern: string, opts: GrepOptions = {}): GitVerb<string[]>
1173
1362
  */
1174
1363
  export function isAncestor(a: string, b: string): GitVerb<boolean> {
1175
1364
  return {
1176
- argv: ['merge-base', '--is-ancestor', a, b],
1365
+ argv: [
1366
+ 'merge-base',
1367
+ '--is-ancestor',
1368
+ positional('isAncestor', 'a', a),
1369
+ positional('isAncestor', 'b', b),
1370
+ ],
1177
1371
  absent: [1],
1178
1372
  parse: (r) => r.exitCode === 0,
1179
1373
  }
@@ -1198,7 +1392,13 @@ export interface AheadBehind {
1198
1392
  * rev that does not resolve exits 128 and throws.
1199
1393
  */
1200
1394
  export function aheadBehind(base: string, tip: string): GitVerb<AheadBehind> {
1201
- const argv = ['rev-list', '--left-right', '--count', `${base}...${tip}`]
1395
+ positional('aheadBehind', 'tip', tip)
1396
+ const argv = [
1397
+ 'rev-list',
1398
+ '--left-right',
1399
+ '--count',
1400
+ `${positional('aheadBehind', 'base', base)}...${tip}`,
1401
+ ]
1202
1402
  return {
1203
1403
  argv,
1204
1404
  absent: NONE,
@@ -1214,7 +1414,7 @@ export function aheadBehind(base: string, tip: string): GitVerb<AheadBehind> {
1214
1414
  }
1215
1415
 
1216
1416
  /**
1217
- * Configured remote names (`git remote`).
1417
+ * Configured remote names (`git remote`). The clients call it as `remotes()`.
1218
1418
  *
1219
1419
  * `absent: []` — a repository with no remotes is exit 0 with empty stdout.
1220
1420
  * Outside a repository git exits 128 and this throws.
@@ -1223,18 +1423,76 @@ export function remote(): GitVerb<string[]> {
1223
1423
  return { argv: ['remote'], absent: NONE, parse: trimmedLines }
1224
1424
  }
1225
1425
 
1426
+ /** Options for {@link remoteGetUrl} and {@link remoteGetUrls}. */
1427
+ export interface RemoteGetUrlOptions {
1428
+ /**
1429
+ * `--push` — the push URL. git falls back to the fetch URL when the remote
1430
+ * sets no `pushurl`.
1431
+ */
1432
+ push?: boolean | undefined
1433
+ }
1434
+
1226
1435
  /**
1227
1436
  * A remote's fetch URL (`git remote get-url <name>`), or null when no remote
1228
- * by that name is configured.
1437
+ * by that name is configured. With `push`, its push URL. When a remote has
1438
+ * several URLs this is the first; {@link remoteGetUrls} gives them all.
1229
1439
  *
1230
1440
  * `absent: [2]` — measured: git reports an unknown remote as exit 2, not 1 or
1231
1441
  * 128. Outside a repository it exits 128 and this throws.
1232
1442
  */
1233
- export function remoteGetUrl(name: string): GitVerb<string | null> {
1234
- return { argv: ['remote', 'get-url', name], absent: [2], parse: trimmedOrNull }
1443
+ export function remoteGetUrl(name: string, opts: RemoteGetUrlOptions = {}): GitVerb<string | null> {
1444
+ const argv = ['remote', 'get-url']
1445
+ if (opts.push) argv.push('--push')
1446
+ argv.push(positional('remoteGetUrl', 'name', name))
1447
+ return { argv, absent: [2], parse: trimmedOrNull }
1235
1448
  }
1236
1449
 
1237
- // ── mutations (absent: [] — any non-zero exit throws CommandFailed) ──────────
1450
+ /**
1451
+ * Every URL a remote has (`git remote get-url --all <name>`), or `[]` when no
1452
+ * remote by that name is configured (exit 2).
1453
+ *
1454
+ * A remote can carry several URLs (`remote set-url --add`). A caller that
1455
+ * checks a remote before deleting something compares all of them, not the
1456
+ * first.
1457
+ */
1458
+ export function remoteGetUrls(name: string, opts: RemoteGetUrlOptions = {}): GitVerb<string[]> {
1459
+ const argv = ['remote', 'get-url', '--all']
1460
+ if (opts.push) argv.push('--push')
1461
+ argv.push(positional('remoteGetUrls', 'name', name))
1462
+ return { argv, absent: [2], parse: trimmedLines }
1463
+ }
1464
+
1465
+ /**
1466
+ * The branch a remote's HEAD points at, as a full refname such as
1467
+ * `refs/heads/main` (`git ls-remote --symref <remote> HEAD`).
1468
+ *
1469
+ * It asks the remote over the network. {@link symbolicRef} on
1470
+ * `refs/remotes/<remote>/HEAD` reads the local copy instead, which a clone
1471
+ * may never have set.
1472
+ *
1473
+ * `absent: []`. null means the remote answered but names no default branch:
1474
+ * an empty repository, or a detached HEAD. An unreachable remote exits 128
1475
+ * and throws.
1476
+ */
1477
+ export function remoteHead(remote: string): GitVerb<string | null> {
1478
+ return {
1479
+ argv: ['ls-remote', '--symref', positional('remoteHead', 'remote', remote), 'HEAD'],
1480
+ absent: NONE,
1481
+ parse(r) {
1482
+ // `ref: refs/heads/main<TAB>HEAD`, then the `<sha><TAB>HEAD` row.
1483
+ for (const line of splitLines(r.stdout)) {
1484
+ const m = /^ref: (\S+)\tHEAD$/.exec(line)
1485
+ if (m !== null) return m[1]!
1486
+ }
1487
+ return null
1488
+ },
1489
+ }
1490
+ }
1491
+
1492
+ // ── mutations ───────────────────────────────────────────────────────────────
1493
+ //
1494
+ // absent: [], so any non-zero exit throws CommandFailed. `configRemoveSection`
1495
+ // is the one exception: it declares 128.
1238
1496
 
1239
1497
  /** Options for {@link fetch}. */
1240
1498
  export interface FetchOptions {
@@ -1250,6 +1508,13 @@ export interface FetchOptions {
1250
1508
  * and a caller that only wanted refs updated gets a corrupted one.
1251
1509
  */
1252
1510
  noWriteFetchHead?: boolean | undefined
1511
+ /**
1512
+ * `--depth=<n>` — limit the fetched history to `n` commits from each tip.
1513
+ * Anything but a positive integer throws a `TypeError`.
1514
+ */
1515
+ depth?: number | undefined
1516
+ /** `--no-tags` — fetch no tags beyond those the refspecs name. */
1517
+ noTags?: boolean | undefined
1253
1518
  }
1254
1519
 
1255
1520
  /**
@@ -1269,8 +1534,14 @@ export function fetch(
1269
1534
  if (opts.quiet) argv.push('--quiet')
1270
1535
  if (opts.prune) argv.push('--prune')
1271
1536
  if (opts.noWriteFetchHead) argv.push('--no-write-fetch-head')
1272
- argv.push(remote)
1273
- if (refspec !== undefined) argv.push(...(typeof refspec === 'string' ? [refspec] : refspec))
1537
+ if (opts.depth !== undefined) argv.push(depthArg('fetch', opts.depth))
1538
+ if (opts.noTags) argv.push('--no-tags')
1539
+ argv.push(positional('fetch', 'remote', remote))
1540
+ if (refspec !== undefined) {
1541
+ for (const spec of typeof refspec === 'string' ? [refspec] : refspec) {
1542
+ argv.push(positional('fetch', 'refspec', spec))
1543
+ }
1544
+ }
1274
1545
  return { argv, absent: NONE, parse: nothing }
1275
1546
  }
1276
1547
 
@@ -1374,25 +1645,26 @@ export interface ConfigSetOptions {
1374
1645
  * Which file to write. Omitted means git's default: `--local` inside a
1375
1646
  * repository, something else outside one.
1376
1647
  */
1377
- scope?: 'local' | 'global' | 'system' | undefined
1648
+ scope?: ConfigScope | undefined
1378
1649
  }
1379
1650
 
1380
1651
  /** `git config <key> <value>` — the write twin of {@link configGet}. */
1381
1652
  export function configSet(key: string, value: string, opts: ConfigSetOptions = {}): GitVerb<void> {
1382
1653
  const argv = ['config']
1383
1654
  if (opts.scope !== undefined) argv.push(`--${opts.scope}`)
1384
- argv.push(key, value)
1655
+ argv.push(positional('configSet', 'key', key), value)
1385
1656
  return { argv, absent: NONE, parse: nothing }
1386
1657
  }
1387
1658
 
1388
1659
  /**
1389
1660
  * `git config --remove-section <name>`: true when removed, false when there was
1390
1661
  * no such section. `absent: [128]` also covers "not a repository", which git
1391
- * spells the same way.
1662
+ * spells the same way, so `false` can also mean git could not ask. It is a
1663
+ * mutation, so it has no `soft` form.
1392
1664
  */
1393
1665
  export function configRemoveSection(name: string): GitVerb<boolean> {
1394
1666
  return {
1395
- argv: ['config', '--remove-section', name],
1667
+ argv: ['config', '--remove-section', positional('configRemoveSection', 'name', name)],
1396
1668
  absent: [128],
1397
1669
  parse: (r) => r.exitCode === 0,
1398
1670
  }
@@ -1419,13 +1691,17 @@ export function init(path?: string | undefined, opts: InitOptions = {}): GitVerb
1419
1691
  if (opts.quiet) argv.push('--quiet')
1420
1692
  if (opts.bare) argv.push('--bare')
1421
1693
  if (opts.initialBranch !== undefined) argv.push('-b', opts.initialBranch)
1422
- if (path !== undefined) argv.push(path)
1694
+ const target = optionalPositional('init', 'path', path)
1695
+ if (target !== undefined) argv.push(target)
1423
1696
  return { argv, absent: NONE, parse: nothing }
1424
1697
  }
1425
1698
 
1426
1699
  /** Options for {@link clone}. */
1427
1700
  export interface CloneOptions {
1428
- /** `--depth <n>` — a shallow clone with that much history. */
1701
+ /**
1702
+ * `--depth=<n>` — a shallow clone with that much history. Anything but a
1703
+ * positive integer throws a `TypeError`.
1704
+ */
1429
1705
  depth?: number | undefined
1430
1706
  /**
1431
1707
  * `--branch <ref>` — the branch or tag to land on.
@@ -1436,12 +1712,26 @@ export interface CloneOptions {
1436
1712
  branch?: string | undefined
1437
1713
  /** `--bare` — a store with no working tree. */
1438
1714
  bare?: boolean | undefined
1715
+ /**
1716
+ * `--mirror` — a bare store that copies every ref of the source, and whose
1717
+ * `fetch` overwrites them. Implies `bare`.
1718
+ *
1719
+ * Its refspec `+refs/*:refs/*` covers every ref, tags included. So with
1720
+ * `mirror`, `noTags` has no effect, and `singleBranch` holds for the clone
1721
+ * only: a later fetch gets every ref. git refuses `mirror` with `branch`
1722
+ * (exit 128).
1723
+ */
1724
+ mirror?: boolean | undefined
1725
+ /** `--single-branch` — fetch only the branch the clone lands on. */
1726
+ singleBranch?: boolean | undefined
1727
+ /** `--no-tags` — fetch no tags, now or on a later fetch. */
1728
+ noTags?: boolean | undefined
1439
1729
  /** `--quiet` — suppress the progress lines. */
1440
1730
  quiet?: boolean | undefined
1441
1731
  }
1442
1732
 
1443
1733
  /**
1444
- * `git clone [--depth n] [--branch ref] [--bare] <url> [dest]`.
1734
+ * `git clone [--depth=n] [--branch ref] [--bare|--mirror] <url> [dest]`.
1445
1735
  *
1446
1736
  * The one verb in this table that does not run inside a repository — it
1447
1737
  * makes one. A client's `cwd` is where a relative `dest` resolves, and both
@@ -1455,10 +1745,14 @@ export function clone(
1455
1745
  const argv = ['clone']
1456
1746
  if (opts.quiet) argv.push('--quiet')
1457
1747
  if (opts.bare) argv.push('--bare')
1458
- if (opts.depth !== undefined) argv.push('--depth', String(opts.depth))
1748
+ if (opts.mirror) argv.push('--mirror')
1749
+ if (opts.singleBranch) argv.push('--single-branch')
1750
+ if (opts.noTags) argv.push('--no-tags')
1751
+ if (opts.depth !== undefined) argv.push(depthArg('clone', opts.depth))
1459
1752
  if (opts.branch !== undefined) argv.push('--branch', opts.branch)
1460
- argv.push(url)
1461
- if (dest !== undefined) argv.push(dest)
1753
+ argv.push(positional('clone', 'url', url))
1754
+ const target = optionalPositional('clone', 'dest', dest)
1755
+ if (target !== undefined) argv.push(target)
1462
1756
  return { argv, absent: NONE, parse: nothing }
1463
1757
  }
1464
1758
 
@@ -1493,11 +1787,11 @@ export function forceWithLeaseArg(lease: ForceLease): string {
1493
1787
  /**
1494
1788
  * Push a refspec.
1495
1789
  *
1496
- * `forceWithLease` takes `true` for the bare `--force-with-lease`, or a
1497
- * {@link ForceLease} for the pinned form. Pin it whenever the expected remote
1498
- * sha is known: the bare flag trusts whatever the local remote-tracking ref
1499
- * happens to say, and a background fetch can quietly bring that up to date —
1500
- * after which the lease vetoes nothing and a concurrent push is erased.
1790
+ * `forceWithLease` takes a {@link ForceLease} for the pinned form, or `true`
1791
+ * for the bare `--force-with-lease`. `true` is the unsafe form. It trusts
1792
+ * whatever the local remote-tracking ref says, and a background fetch can
1793
+ * bring that up to date. The lease then vetoes nothing, and a concurrent push
1794
+ * is erased. Pin the lease whenever the expected remote sha is known.
1501
1795
  */
1502
1796
  export function push(
1503
1797
  remote: string,
@@ -1511,13 +1805,17 @@ export function push(
1511
1805
  else if (lease !== undefined && lease !== false) {
1512
1806
  throw new Error(`force-with-lease: unsupported value ${JSON.stringify(lease)}`)
1513
1807
  }
1514
- argv.push(remote, refspec)
1808
+ argv.push(positional('push', 'remote', remote), positional('push', 'refspec', refspec))
1515
1809
  return { argv, absent: NONE, parse: nothing }
1516
1810
  }
1517
1811
 
1518
1812
  /** `git reset --hard <rev>`. */
1519
1813
  export function resetHard(rev: string): GitVerb<void> {
1520
- return { argv: ['reset', '--hard', rev], absent: NONE, parse: nothing }
1814
+ return {
1815
+ argv: ['reset', '--hard', positional('resetHard', 'rev', rev)],
1816
+ absent: NONE,
1817
+ parse: nothing,
1818
+ }
1521
1819
  }
1522
1820
 
1523
1821
  /** Options for {@link clean}. */
@@ -1540,7 +1838,7 @@ export function deleteBranch(
1540
1838
  opts: { force?: boolean | undefined } = {},
1541
1839
  ): GitVerb<void> {
1542
1840
  return {
1543
- argv: ['branch', opts.force ? '-D' : '-d', name],
1841
+ argv: ['branch', opts.force ? '-D' : '-d', positional('deleteBranch', 'name', name)],
1544
1842
  absent: NONE,
1545
1843
  parse: nothing,
1546
1844
  }
@@ -1554,7 +1852,16 @@ export function deleteBranch(
1554
1852
  * `branch.<name>.*` config section in place.
1555
1853
  */
1556
1854
  export function deleteRef(ref: string, opts: { expected: string }): GitVerb<void> {
1557
- return { argv: ['update-ref', '-d', ref, opts.expected], absent: NONE, parse: nothing }
1855
+ return {
1856
+ argv: [
1857
+ 'update-ref',
1858
+ '-d',
1859
+ positional('deleteRef', 'ref', ref),
1860
+ positional('deleteRef', 'expected', opts.expected),
1861
+ ],
1862
+ absent: NONE,
1863
+ parse: nothing,
1864
+ }
1558
1865
  }
1559
1866
 
1560
1867
  /** `git worktree add [--detach] [-b branch] <path> [startPoint]`. */
@@ -1569,8 +1876,9 @@ export function worktreeAdd(
1569
1876
  const argv = ['worktree', 'add']
1570
1877
  if (opts.detach) argv.push('--detach')
1571
1878
  if (opts.branch !== undefined) argv.push('-b', opts.branch)
1572
- argv.push(path)
1573
- if (opts.startPoint !== undefined) argv.push(opts.startPoint)
1879
+ argv.push(positional('worktreeAdd', 'path', path))
1880
+ const start = optionalPositional('worktreeAdd', 'startPoint', opts.startPoint)
1881
+ if (start !== undefined) argv.push(start)
1574
1882
  return { argv, absent: NONE, parse: nothing }
1575
1883
  }
1576
1884
 
@@ -1581,7 +1889,7 @@ export function worktreeRemove(
1581
1889
  ): GitVerb<void> {
1582
1890
  const argv = ['worktree', 'remove']
1583
1891
  if (opts.force) argv.push('--force')
1584
- argv.push(path)
1892
+ argv.push(positional('worktreeRemove', 'path', path))
1585
1893
  return { argv, absent: NONE, parse: nothing }
1586
1894
  }
1587
1895
 
@@ -1599,7 +1907,7 @@ export function worktreeMove(
1599
1907
  ): GitVerb<void> {
1600
1908
  const argv = ['worktree', 'move']
1601
1909
  if (opts.force) argv.push('--force')
1602
- argv.push(from, to)
1910
+ argv.push(positional('worktreeMove', 'from', from), positional('worktreeMove', 'to', to))
1603
1911
  return { argv, absent: NONE, parse: nothing }
1604
1912
  }
1605
1913
 
@@ -1610,7 +1918,16 @@ export function worktreePrune(): GitVerb<void> {
1610
1918
 
1611
1919
  /** `git remote add <name> <url>`. */
1612
1920
  export function remoteAdd(name: string, url: string): GitVerb<void> {
1613
- return { argv: ['remote', 'add', name, url], absent: NONE, parse: nothing }
1921
+ return {
1922
+ argv: [
1923
+ 'remote',
1924
+ 'add',
1925
+ positional('remoteAdd', 'name', name),
1926
+ positional('remoteAdd', 'url', url),
1927
+ ],
1928
+ absent: NONE,
1929
+ parse: nothing,
1930
+ }
1614
1931
  }
1615
1932
 
1616
1933
  // ── integration ─────────────────────────────────────────────────────────────
@@ -1636,16 +1953,19 @@ export function remoteAdd(name: string, url: string): GitVerb<void> {
1636
1953
  // An unknown ref exits 1 exactly like a conflict, so the exit code alone
1637
1954
  // cannot tell them apart. The discriminator is that a conflict always writes
1638
1955
  // its report to stdout and a refusal writes nothing there — a structural
1639
- // signal rather than a string match, because git's messages are translatable
1640
- // and a locale must not change what an outcome means.
1956
+ // signal rather than a string match.
1957
+ //
1958
+ // `fastForward`, `alreadyUpToDate` and the conflict list do read git's text.
1959
+ // That text is translatable, so `merge`, `rebase` and `rebaseContinue` run
1960
+ // with `LC_ALL=C`, and a caller's locale does not change an outcome.
1641
1961
 
1642
1962
  /** How an integration attempt ended. */
1643
1963
  export type IntegrationOutcome<Extra> =
1644
1964
  | ({ status: 'clean' } & Extra)
1645
1965
  /**
1646
- * Conflicted. `conflicts` is a best-effort read of git's own report — it
1647
- * has no parseable form for rename/rename or rename/delete, and it is
1648
- * translatable, so it can be empty on a real conflict. Ask
1966
+ * Conflicted. `conflicts` is a best-effort read of git's own report. It has
1967
+ * no parseable form for rename/rename or rename/delete, so it can be empty
1968
+ * on a real conflict. Ask
1649
1969
  * {@link lsFilesUnmerged} or `diffNameOnly({ diffFilter: "U" })` for the
1650
1970
  * authoritative list.
1651
1971
  */
@@ -1716,9 +2036,10 @@ export function merge(ref: string, opts: MergeOptions = {}): GitVerb<MergeOutcom
1716
2036
  if (opts.noCommit) argv.push('--no-commit')
1717
2037
  if (opts.ffOnly) argv.push('--ff-only')
1718
2038
  if (opts.message !== undefined) argv.push('-m', opts.message)
1719
- argv.push(ref)
2039
+ argv.push(positional('merge', 'ref', ref))
1720
2040
  const verb: GitVerb<MergeOutcome> = {
1721
2041
  argv,
2042
+ env: C_LOCALE,
1722
2043
  absent: [1],
1723
2044
  parse(r, ranArgv) {
1724
2045
  if (r.exitCode !== 0) return conflictOrThrow(ranArgv, r)
@@ -1758,9 +2079,10 @@ export interface RebaseOptions {
1758
2079
  export function rebase(onto: string, opts: RebaseOptions = {}): GitVerb<RebaseOutcome> {
1759
2080
  const argv = ['rebase']
1760
2081
  if (opts.autostash) argv.push('--autostash')
1761
- argv.push(onto)
2082
+ argv.push(positional('rebase', 'onto', onto))
1762
2083
  const verb: GitVerb<RebaseOutcome> = {
1763
2084
  argv,
2085
+ env: C_LOCALE,
1764
2086
  absent: [1],
1765
2087
  parse(r, ranArgv) {
1766
2088
  if (r.exitCode !== 0) return conflictOrThrow(ranArgv, r)
@@ -1791,6 +2113,7 @@ export function rebaseAbort(): GitVerb<void> {
1791
2113
  export function rebaseContinue(): GitVerb<RebaseOutcome> {
1792
2114
  const verb: GitVerb<RebaseOutcome> = {
1793
2115
  argv: ['-c', 'core.editor=true', 'rebase', '--continue'],
2116
+ env: C_LOCALE,
1794
2117
  absent: [1],
1795
2118
  parse(r, ranArgv) {
1796
2119
  if (r.exitCode !== 0) return conflictOrThrow(ranArgv, r)
@@ -1853,7 +2176,7 @@ export function mergeTree(
1853
2176
  ): GitVerb<MergeTreeOutcome> {
1854
2177
  const argv = ['merge-tree', '--write-tree', '--name-only', '-z']
1855
2178
  if (opts.mergeBase !== undefined) argv.push(`--merge-base=${opts.mergeBase}`)
1856
- argv.push(ours, theirs)
2179
+ argv.push(positional('mergeTree', 'ours', ours), positional('mergeTree', 'theirs', theirs))
1857
2180
  return {
1858
2181
  argv,
1859
2182
  absent: [1],
@@ -1931,7 +2254,8 @@ export type ConflictSide = 'ours' | 'theirs'
1931
2254
  /**
1932
2255
  * `git checkout --ours|--theirs -- <paths>` — resolve paths to one side.
1933
2256
  *
1934
- * `absent: []` — a checkout that did not happen is not an answer.
2257
+ * `absent: []` — a checkout that did not happen is not an answer. Both
2258
+ * clients return without running git when `paths` is empty.
1935
2259
  *
1936
2260
  * Note the sharp edge git leaves here: on a path that is not conflicted this
1937
2261
  * exits 0 and does nothing. There is no error to catch, so a caller working
@@ -1971,6 +2295,6 @@ export function checkout(ref: string, opts: CheckoutOptions = {}): GitVerb<void>
1971
2295
  const argv = ['checkout']
1972
2296
  if (opts.force) argv.push('--force')
1973
2297
  if (opts.branch !== undefined) argv.push(opts.resetBranch ? '-B' : '-b', opts.branch)
1974
- argv.push(ref)
2298
+ argv.push(positional('checkout', 'ref', ref))
1975
2299
  return { argv, absent: NONE, parse: nothing }
1976
2300
  }