@osdlc/typed-git 0.5.3 → 0.6.0

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.
Files changed (49) hide show
  1. package/CHANGELOG.md +30 -1
  2. package/CONTRIBUTING.md +3 -4
  3. package/README.md +40 -16
  4. package/dist/async.d.ts +3 -4
  5. package/dist/async.js +3 -3
  6. package/dist/backend.d.ts +1 -2
  7. package/dist/checkout-root.d.ts +0 -1
  8. package/dist/client.d.ts +2 -2
  9. package/dist/client.js +1 -0
  10. package/dist/failure.d.ts +64 -0
  11. package/dist/failure.js +126 -0
  12. package/dist/git-url.d.ts +0 -1
  13. package/dist/index.d.ts +1 -2
  14. package/dist/index.js +1 -1
  15. package/dist/outcome.d.ts +13 -18
  16. package/dist/outcome.js +21 -16
  17. package/dist/remote-url.d.ts +0 -1
  18. package/dist/soft.d.ts +0 -1
  19. package/dist/sync.d.ts +5 -5
  20. package/dist/sync.js +4 -3
  21. package/dist/testing.d.ts +0 -1
  22. package/dist/verbs.d.ts +5 -7
  23. package/dist/verbs.js +18 -11
  24. package/package.json +10 -23
  25. package/async.ts +0 -753
  26. package/backend.ts +0 -574
  27. package/checkout-root.ts +0 -164
  28. package/client.ts +0 -102
  29. package/dist/async.d.ts.map +0 -1
  30. package/dist/backend.d.ts.map +0 -1
  31. package/dist/checkout-root.d.ts.map +0 -1
  32. package/dist/client.d.ts.map +0 -1
  33. package/dist/git-url.d.ts.map +0 -1
  34. package/dist/index.d.ts.map +0 -1
  35. package/dist/outcome.d.ts.map +0 -1
  36. package/dist/remote-url.d.ts.map +0 -1
  37. package/dist/soft.d.ts.map +0 -1
  38. package/dist/sync.d.ts.map +0 -1
  39. package/dist/testing.d.ts.map +0 -1
  40. package/dist/verbs.d.ts.map +0 -1
  41. package/git-url.ts +0 -102
  42. package/hosted-git-info.d.ts +0 -24
  43. package/index.ts +0 -52
  44. package/outcome.ts +0 -191
  45. package/remote-url.ts +0 -46
  46. package/soft.ts +0 -60
  47. package/sync.ts +0 -827
  48. package/testing.ts +0 -291
  49. package/verbs.ts +0 -2300
package/backend.ts DELETED
@@ -1,574 +0,0 @@
1
- /**
2
- * The backend seam — what `AsyncGit` talks to, and the thing you swap when
3
- * git should not come from a subprocess.
4
- *
5
- * A backend takes a {@link GitRequest} — a plain, serializable description of
6
- * one git operation — and returns its typed result. That is deliberately not
7
- * argv: argv is a CLI detail, and a backend built on a pure-JavaScript git
8
- * implementation has no argv to receive. Describing the operation instead of
9
- * the invocation is what lets the same client drive either.
10
- *
11
- * It also means a request can be logged, queued, or replayed as data. The one
12
- * request that cannot cross that line is `raw`, which is argv by definition; a
13
- * non-CLI backend rejects it with {@link UnsupportedRequest}.
14
- *
15
- * The seam is experimental: `GitBackend`, `GitRequest`, `GitResults` and
16
- * `partialBackend`. Each new verb adds a request kind, which breaks a backend
17
- * written as an exhaustive switch. Such a change can land in a minor release.
18
- * `cliBackend` and `AsyncGit` are stable.
19
- */
20
-
21
- import {
22
- resolveRunnerAsync,
23
- type AsyncCommandRunner,
24
- type AsyncCommandRunOptions,
25
- type CommandResult,
26
- } from '@osdlc/command-seam'
27
-
28
- import * as v from './verbs.ts'
29
- import {
30
- gate,
31
- mergeEnv,
32
- repoPrefix,
33
- type AddOptions,
34
- type AheadBehind,
35
- type CheckoutOptions,
36
- type CloneOptions,
37
- type CommitOptions,
38
- type ConfigGetOptions,
39
- type ConfigSetOptions,
40
- type ConflictSide,
41
- type DiffEntry,
42
- type DiffNameOnlyOptions,
43
- type DiffStatOptions,
44
- type DiffNameStatusOptions,
45
- type DiffTextOptions,
46
- type DiffTreeOptions,
47
- type FetchOptions,
48
- type ForEachRefOptions,
49
- type ForceLease,
50
- type GitVerb,
51
- type GrepOptions,
52
- type InitOptions,
53
- type LogOptions,
54
- type IgnoreMatch,
55
- type LsFilesOptions,
56
- type LsRemoteOptions,
57
- type LsTreeOptions,
58
- type MergeOptions,
59
- type MergeOutcome,
60
- type MergeTreeOptions,
61
- type MergeTreeOutcome,
62
- type NumstatEntry,
63
- type RebaseOptions,
64
- type RebaseOutcome,
65
- type RemoteGetUrlOptions,
66
- type RemoteRef,
67
- type CleanOptions,
68
- type DiffCheckOptions,
69
- type DiffCheckResult,
70
- type StatusEntry,
71
- type StatusPorcelainOptions,
72
- type TreeEntry,
73
- type TaggedFile,
74
- type UnmergedEntry,
75
- type Worktree,
76
- type WorktreeMoveOptions,
77
- } from './verbs.ts'
78
-
79
- /** Per-call concerns that are not part of the operation itself. */
80
- export interface GitCallOptions {
81
- /**
82
- * Hard cap on the call; a backend that cannot enforce one may ignore it.
83
- * Without it there is no cap, and the default async runner has no output
84
- * cap either. An invalid value throws (sync) or rejects (async), as in command-seam:
85
- * `RangeError` for 0, a negative value or `NaN`; `TypeError` for a
86
- * non-number.
87
- */
88
- timeoutMs?: number | undefined
89
- /** Mid-flight cancellation, where the backend supports it. */
90
- signal?: AbortSignal | undefined
91
- /**
92
- * Entries merged over the parent environment for this call only. Per-call
93
- * rather than part of the request, like `timeoutMs`: it describes how the
94
- * invocation runs, not what operation was asked for.
95
- */
96
- env?: Record<string, string> | undefined
97
- /**
98
- * Cap on each output stream, in bytes. Past it the runner kills the child
99
- * and the call throws (sync) or rejects (async) with `CommandFailed`, so
100
- * cut-short output is never read as an answer. A backend that cannot
101
- * enforce it may ignore it. Without it the async runner has no cap and the
102
- * sync runner caps at 256 MB.
103
- */
104
- maxOutputBytes?: number | undefined
105
- }
106
-
107
- /**
108
- * One git operation, described rather than invoked.
109
- *
110
- * Optional fields are spelled `?: T | undefined` rather than `?: T`: a request
111
- * is normally built by spreading a caller's options, and under
112
- * `exactOptionalPropertyTypes` a present-but-undefined property is not the
113
- * same as an absent one. Both mean "not given" here.
114
- *
115
- * @experimental Each new verb adds a kind, in a minor release.
116
- */
117
- export type GitRequest =
118
- | { kind: 'showAtRev'; rev: string; relPath: string }
119
- | { kind: 'revParse'; args: string[] }
120
- | { kind: 'resolveRef'; ref: string }
121
- | { kind: 'headRef' }
122
- // `topLevel` / `gitCommonDir` are their own kinds rather than a `revParse`
123
- // with fixed args because they answer a different question: for them a
124
- // non-repository is an answer (`null`), and for `revParse` it is a failure.
125
- | { kind: 'topLevel' }
126
- | { kind: 'gitCommonDir' }
127
- | { kind: 'gitDir' }
128
- | { kind: 'symbolicRef'; ref: string }
129
- | { kind: 'currentBranch' }
130
- | ({ kind: 'statusPorcelain' } & StatusPorcelainOptions)
131
- | { kind: 'statusEntries' }
132
- | { kind: 'branches'; pattern?: string | undefined }
133
- | { kind: 'worktrees' }
134
- | { kind: 'mergeBase'; a: string; b: string }
135
- | { kind: 'logSubject'; ref: string }
136
- | ({ kind: 'configGet'; key: string } & ConfigGetOptions)
137
- | ({ kind: 'configGetAll'; key: string } & ConfigGetOptions)
138
- | ({ kind: 'configGetBool'; key: string } & ConfigGetOptions)
139
- | { kind: 'objectExists'; rev: string }
140
- | ({ kind: 'lsRemote'; remote: string; pattern?: string | undefined } & LsRemoteOptions)
141
- | { kind: 'checkIgnore'; relPaths: string[] }
142
- | { kind: 'checkIgnoreVerbose'; relPaths: string[] }
143
- | { kind: 'isAncestor'; a: string; b: string }
144
- | { kind: 'aheadBehind'; base: string; tip: string }
145
- // The Tier 1 queries carry their verb's option bag rather than restating
146
- // its fields: the option types live in `verbs.ts` beside the argv they
147
- // build, and a request that spread them by hand would drift from it.
148
- | ({ kind: 'lsFiles' } & LsFilesOptions)
149
- | { kind: 'lsFilesTagged' }
150
- | ({ kind: 'forEachRef'; pattern: string | string[] } & ForEachRefOptions)
151
- | ({ kind: 'diffNameOnly' } & DiffNameOnlyOptions)
152
- | ({ kind: 'diffStat' } & DiffStatOptions)
153
- | ({ kind: 'diffCheck' } & DiffCheckOptions)
154
- | ({ kind: 'diffNameStatus' } & DiffNameStatusOptions)
155
- | ({ kind: 'log' } & LogOptions)
156
- | ({ kind: 'lsTree'; rev: string } & LsTreeOptions)
157
- | ({ kind: 'diffTree'; rev: string } & DiffTreeOptions)
158
- | ({ kind: 'diffTreeNumstat'; rev: string } & DiffTreeOptions)
159
- | ({ kind: 'grep'; pattern: string } & GrepOptions)
160
- | ({ kind: 'diffText'; rev?: string | undefined } & DiffTextOptions)
161
- | { kind: 'diffAddedFile'; relPath: string }
162
- | ({
163
- kind: 'fetch'
164
- remote: string
165
- refspec?: string | string[] | undefined
166
- } & FetchOptions)
167
- | ({ kind: 'add'; paths: string[] } & AddOptions)
168
- | ({ kind: 'commit' } & CommitOptions)
169
- | ({ kind: 'configSet'; key: string; value: string } & ConfigSetOptions)
170
- | { kind: 'configRemoveSection'; name: string }
171
- | ({ kind: 'init'; path?: string | undefined } & InitOptions)
172
- | ({ kind: 'clone'; url: string; dest?: string | undefined } & CloneOptions)
173
- | {
174
- kind: 'push'
175
- remote: string
176
- refspec: string
177
- forceWithLease?: boolean | ForceLease | undefined
178
- }
179
- | { kind: 'resetHard'; rev: string }
180
- | ({ kind: 'clean' } & CleanOptions)
181
- | { kind: 'deleteBranch'; name: string; force?: boolean | undefined }
182
- | { kind: 'deleteRef'; ref: string; expected: string }
183
- | {
184
- kind: 'worktreeAdd'
185
- path: string
186
- branch?: string | undefined
187
- startPoint?: string | undefined
188
- detach?: boolean | undefined
189
- }
190
- | { kind: 'worktreeRemove'; path: string; force?: boolean | undefined }
191
- | ({ kind: 'worktreeMove'; from: string; to: string } & WorktreeMoveOptions)
192
- | { kind: 'worktreePrune' }
193
- | ({ kind: 'merge'; ref: string } & MergeOptions)
194
- | { kind: 'mergeAbort' }
195
- | ({ kind: 'rebase'; onto: string } & RebaseOptions)
196
- | { kind: 'rebaseAbort' }
197
- | { kind: 'rebaseContinue' }
198
- | ({ kind: 'mergeTree'; ours: string; theirs: string } & MergeTreeOptions)
199
- | { kind: 'lsFilesUnmerged' }
200
- | { kind: 'checkoutSide'; side: ConflictSide; paths: string[] }
201
- | ({ kind: 'checkout'; ref: string } & CheckoutOptions)
202
- | { kind: 'remote' }
203
- | ({ kind: 'remoteGetUrl'; name: string } & RemoteGetUrlOptions)
204
- | ({ kind: 'remoteGetUrls'; name: string } & RemoteGetUrlOptions)
205
- | { kind: 'remoteHead'; remote: string }
206
- | { kind: 'remoteAdd'; name: string; url: string }
207
- | { kind: 'raw'; argv: string[]; input?: string | undefined; checked?: boolean | undefined }
208
-
209
- /**
210
- * The result type each request kind resolves to.
211
- *
212
- * @experimental It grows with {@link GitRequest}.
213
- */
214
- export interface GitResults {
215
- showAtRev: string | null
216
- revParse: string | null
217
- resolveRef: string | null
218
- headRef: string | null
219
- topLevel: string | null
220
- gitCommonDir: string | null
221
- gitDir: string | null
222
- symbolicRef: string | null
223
- currentBranch: string | null
224
- statusPorcelain: string[]
225
- statusEntries: StatusEntry[]
226
- branches: string[]
227
- worktrees: Worktree[]
228
- mergeBase: string | null
229
- logSubject: string | null
230
- configGet: string | null
231
- configGetAll: string[]
232
- configGetBool: boolean | null
233
- objectExists: boolean
234
- lsRemote: RemoteRef[]
235
- checkIgnore: Set<string>
236
- checkIgnoreVerbose: IgnoreMatch[]
237
- isAncestor: boolean
238
- aheadBehind: AheadBehind
239
- lsFiles: string[]
240
- lsFilesTagged: TaggedFile[]
241
- forEachRef: string[]
242
- diffNameOnly: string[]
243
- diffStat: string
244
- diffCheck: DiffCheckResult
245
- diffNameStatus: DiffEntry[]
246
- log: string
247
- lsTree: TreeEntry[]
248
- diffTree: DiffEntry[]
249
- diffTreeNumstat: NumstatEntry[]
250
- grep: string[]
251
- diffText: string
252
- diffAddedFile: string
253
- fetch: void
254
- add: void
255
- commit: void
256
- configSet: void
257
- configRemoveSection: boolean
258
- init: void
259
- clone: void
260
- push: void
261
- resetHard: void
262
- clean: void
263
- deleteBranch: void
264
- deleteRef: void
265
- worktreeAdd: void
266
- worktreeRemove: void
267
- worktreeMove: void
268
- worktreePrune: void
269
- merge: MergeOutcome
270
- mergeAbort: void
271
- rebase: RebaseOutcome
272
- rebaseAbort: void
273
- rebaseContinue: RebaseOutcome
274
- mergeTree: MergeTreeOutcome
275
- lsFilesUnmerged: UnmergedEntry[]
276
- checkoutSide: void
277
- checkout: void
278
- remote: string[]
279
- remoteGetUrl: string | null
280
- remoteGetUrls: string[]
281
- remoteHead: string | null
282
- remoteAdd: void
283
- raw: CommandResult
284
- }
285
-
286
- /** Every request kind, as a union of string literals. */
287
- export type GitRequestKind = GitRequest['kind']
288
-
289
- /**
290
- * Where git actually happens. Implement this to drive the client with
291
- * something other than the `git` CLI.
292
- *
293
- * A request resolves to its value — including the absence value (`null`,
294
- * `[]`, `false`) for a state the verb declares absent, such as an unset
295
- * config key. It rejects with `CommandFailed` — or whatever error the backend
296
- * considers equivalent — when git failed rather than answered.
297
- *
298
- * @experimental New request kinds land in minor releases. Use
299
- * {@link partialBackend} rather than an exhaustive switch.
300
- */
301
- export interface GitBackend {
302
- execute<R extends GitRequest>(
303
- cwd: string,
304
- request: R,
305
- opts?: GitCallOptions,
306
- ): Promise<GitResults[R['kind']]>
307
- }
308
-
309
- /** Thrown by a backend asked for an operation it cannot perform. */
310
- export class UnsupportedRequest extends Error {
311
- readonly kind: string
312
- constructor(kind: string, backend: string) {
313
- super(`${backend} cannot perform '${kind}'`)
314
- this.name = 'UnsupportedRequest'
315
- this.kind = kind
316
- }
317
- }
318
-
319
- /** Translate a request into the CLI verb that performs it. */
320
- function toVerb(request: GitRequest): GitVerb<unknown> {
321
- switch (request.kind) {
322
- case 'showAtRev':
323
- return v.showAtRev(request.rev, request.relPath)
324
- case 'revParse':
325
- return v.revParse(...request.args)
326
- case 'resolveRef':
327
- return v.resolveRef(request.ref)
328
- case 'headRef':
329
- return v.headRef()
330
- case 'topLevel':
331
- return v.topLevel()
332
- case 'gitCommonDir':
333
- return v.gitCommonDir()
334
- case 'gitDir':
335
- return v.gitDir()
336
- case 'symbolicRef':
337
- return v.symbolicRef(request.ref)
338
- case 'currentBranch':
339
- return v.currentBranch()
340
- case 'statusPorcelain':
341
- return v.statusPorcelain(request)
342
- case 'statusEntries':
343
- return v.statusEntries()
344
- case 'branches':
345
- return v.branches(request.pattern)
346
- case 'worktrees':
347
- return v.worktrees()
348
- case 'mergeBase':
349
- return v.mergeBase(request.a, request.b)
350
- case 'logSubject':
351
- return v.logSubject(request.ref)
352
- case 'configGet':
353
- return v.configGet(request.key, request)
354
- case 'configGetAll':
355
- return v.configGetAll(request.key, request)
356
- case 'configGetBool':
357
- return v.configGetBool(request.key, request)
358
- case 'objectExists':
359
- return v.objectExists(request.rev)
360
- case 'lsRemote':
361
- return v.lsRemote(request.remote, request.pattern, request)
362
- case 'isAncestor':
363
- return v.isAncestor(request.a, request.b)
364
- case 'aheadBehind':
365
- return v.aheadBehind(request.base, request.tip)
366
- case 'checkIgnore':
367
- return v.checkIgnore(request.relPaths)
368
- case 'checkIgnoreVerbose':
369
- return v.checkIgnoreVerbose(request.relPaths)
370
- case 'lsFiles':
371
- return v.lsFiles(request)
372
- case 'lsFilesTagged':
373
- return v.lsFilesTagged()
374
- case 'forEachRef':
375
- return v.forEachRef(request.pattern, request)
376
- case 'diffNameOnly':
377
- return v.diffNameOnly(request)
378
- case 'diffStat':
379
- return v.diffStat(request)
380
- case 'diffCheck':
381
- return v.diffCheck(request)
382
- case 'diffNameStatus':
383
- return v.diffNameStatus(request)
384
- case 'log':
385
- return v.log(request)
386
- case 'lsTree':
387
- return v.lsTree(request.rev, request)
388
- case 'diffTree':
389
- return v.diffTree(request.rev, request)
390
- case 'diffTreeNumstat':
391
- return v.diffTreeNumstat(request.rev, request)
392
- case 'grep':
393
- return v.grep(request.pattern, request)
394
- case 'diffText':
395
- return v.diffText(request.rev, request)
396
- case 'diffAddedFile':
397
- return v.diffAddedFile(request.relPath)
398
- case 'fetch':
399
- return v.fetch(request.remote, request.refspec, request)
400
- case 'add':
401
- return v.add(request.paths, request)
402
- case 'commit':
403
- return v.commit(request)
404
- case 'configSet':
405
- return v.configSet(request.key, request.value, request)
406
- case 'configRemoveSection':
407
- return v.configRemoveSection(request.name)
408
- case 'init':
409
- return v.init(request.path, request)
410
- case 'clone':
411
- return v.clone(request.url, request.dest, request)
412
- case 'push':
413
- return v.push(request.remote, request.refspec, {
414
- forceWithLease: request.forceWithLease,
415
- })
416
- case 'resetHard':
417
- return v.resetHard(request.rev)
418
- case 'clean':
419
- return v.clean(request)
420
- case 'deleteBranch':
421
- return v.deleteBranch(request.name, { force: request.force })
422
- case 'deleteRef':
423
- return v.deleteRef(request.ref, { expected: request.expected })
424
- case 'worktreeAdd':
425
- return v.worktreeAdd(request.path, request)
426
- case 'worktreeRemove':
427
- return v.worktreeRemove(request.path, { force: request.force })
428
- case 'worktreeMove':
429
- return v.worktreeMove(request.from, request.to, request)
430
- case 'worktreePrune':
431
- return v.worktreePrune()
432
- case 'merge':
433
- return v.merge(request.ref, request)
434
- case 'mergeAbort':
435
- return v.mergeAbort()
436
- case 'rebase':
437
- return v.rebase(request.onto, request)
438
- case 'rebaseAbort':
439
- return v.rebaseAbort()
440
- case 'rebaseContinue':
441
- return v.rebaseContinue()
442
- case 'mergeTree':
443
- return v.mergeTree(request.ours, request.theirs, request)
444
- case 'lsFilesUnmerged':
445
- return v.lsFilesUnmerged()
446
- case 'checkoutSide':
447
- return v.checkoutSide(request.side, request.paths)
448
- case 'checkout':
449
- return v.checkout(request.ref, request)
450
- case 'remote':
451
- return v.remote()
452
- case 'remoteGetUrl':
453
- return v.remoteGetUrl(request.name, request)
454
- case 'remoteGetUrls':
455
- return v.remoteGetUrls(request.name, request)
456
- case 'remoteHead':
457
- return v.remoteHead(request.remote)
458
- case 'remoteAdd':
459
- return v.remoteAdd(request.name, request.url)
460
- case 'raw': {
461
- const verb: GitVerb<CommandResult> = {
462
- argv: request.argv,
463
- // Unchecked `raw` bypasses the gate entirely (see `execute`), so this
464
- // declaration only matters for the checked door, where nothing is
465
- // absence.
466
- absent: [],
467
- parse: (r) => r,
468
- }
469
- if (request.input !== undefined) verb.input = request.input
470
- return verb
471
- }
472
- }
473
- }
474
-
475
- /**
476
- * The default backend: every request becomes a `git` subprocess, run through
477
- * an {@link AsyncCommandRunner} so the caller decides how spawning happens
478
- * (and tests inject a fake).
479
- */
480
- export function cliBackend(
481
- opts: {
482
- runner?: AsyncCommandRunner | undefined
483
- /**
484
- * Which repository to drive, as `--git-dir` / `--work-tree` prefixed onto
485
- * every invocation. They live on the backend rather than on `GitRequest`
486
- * because they are CLI flags: a backend built on a pure-JavaScript git has
487
- * no `--git-dir` to receive, so "which repository" binds the thing that
488
- * spawns git.
489
- */
490
- gitDir?: string | undefined
491
- workTree?: string | undefined
492
- /**
493
- * Entries merged over the parent environment on every call this backend
494
- * makes, under any per-call `env`. Binds an identity or a
495
- * `GIT_SSH_COMMAND` once, rather than threading it through call sites.
496
- */
497
- env?: Record<string, string> | undefined
498
- } = {},
499
- ): GitBackend {
500
- const runner = resolveRunnerAsync('git', opts.runner)
501
- const prefix = repoPrefix(opts.gitDir, opts.workTree)
502
- return {
503
- async execute<R extends GitRequest>(
504
- cwd: string,
505
- request: R,
506
- callOpts: GitCallOptions = {},
507
- ): Promise<GitResults[R['kind']]> {
508
- const verb = toVerb(request)
509
- const runOpts: AsyncCommandRunOptions = { cwd }
510
- if (callOpts.timeoutMs !== undefined) runOpts.timeoutMs = callOpts.timeoutMs
511
- if (callOpts.signal !== undefined) runOpts.signal = callOpts.signal
512
- if (callOpts.maxOutputBytes !== undefined) runOpts.maxOutputBytes = callOpts.maxOutputBytes
513
- // Per-call entries win over the backend's, matching `Git`.
514
- const env = mergeEnv(opts.env, callOpts.env)
515
- if (env !== undefined) runOpts.env = env
516
- if (verb.input !== undefined) runOpts.input = verb.input
517
- // The verb's own entries (the C locale) win over the backend's and the call's.
518
- if (verb.env !== undefined) runOpts.env = { ...runOpts.env, ...verb.env }
519
- const argv = prefix.length === 0 ? verb.argv : [...prefix, ...verb.argv]
520
- const result = await runner.run(argv, runOpts)
521
- // Unchecked `raw` is the one door outside the gate: it hands back
522
- // whatever came out, at any exit code. Everything else uses the same
523
- // gate the sync client does.
524
- const req: GitRequest = request
525
- const gated = req.kind !== 'raw' || req.checked === true
526
- // The prefixed argv is what ran, so it is what a `CommandFailed` reports.
527
- const value = gated ? gate(verb, result, argv) : verb.parse(result, argv)
528
- // `GitResults` restates the verb table's return types for callers; the
529
- // two are kept in step by hand, which this cast is the seam for.
530
- return value as GitResults[R['kind']]
531
- },
532
- }
533
- }
534
-
535
- /**
536
- * Wrap a partial implementation: any request kind the object does not handle
537
- * rejects with {@link UnsupportedRequest} instead of failing as `undefined`.
538
- * The way to ship a backend that covers the operations it can and says so
539
- * about the rest.
540
- *
541
- * @experimental Part of the backend seam; see {@link GitBackend}.
542
- */
543
- export function partialBackend(
544
- name: string,
545
- impl: Partial<{
546
- [K in GitRequestKind]: (
547
- cwd: string,
548
- request: Extract<GitRequest, { kind: K }>,
549
- opts: GitCallOptions,
550
- ) => Promise<GitResults[K]>
551
- }>,
552
- ): GitBackend {
553
- return {
554
- execute<R extends GitRequest>(
555
- cwd: string,
556
- request: R,
557
- opts: GitCallOptions = {},
558
- ): Promise<GitResults[R['kind']]> {
559
- const handler = impl[request.kind]
560
- if (handler === undefined) {
561
- return Promise.reject(new UnsupportedRequest(request.kind, name))
562
- }
563
- // The lookup narrows `impl` to the union of every handler signature;
564
- // the key that selected it is the same key that types the result, which
565
- // the indexed access cannot express. Sound by construction.
566
- const run = handler as unknown as (
567
- c: string,
568
- r: R,
569
- o: GitCallOptions,
570
- ) => Promise<GitResults[R['kind']]>
571
- return run(cwd, request, opts)
572
- },
573
- }
574
- }