@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/async.ts DELETED
@@ -1,753 +0,0 @@
1
- /**
2
- * `AsyncGit` — the awaitable client, bound to one working directory and one
3
- * {@link GitBackend}.
4
- *
5
- * The sync `Git` surface, promised, with one difference: what performs the
6
- * work is a backend rather than a runner. The default backend shells out to
7
- * `git`; any other implementation of {@link GitBackend} — a pure-JavaScript
8
- * git, a remote service, a recorded fixture — drives the same client
9
- * unchanged. Each method mirrors its {@link Git} twin, rejecting where that
10
- * one throws.
11
- *
12
- * Which repository is a backend concern here:
13
- * `new AsyncGit(cwd, { backend: cliBackend({ gitDir }) })`, where the sync
14
- * client takes `gitDir` on its own constructor.
15
- */
16
-
17
- import { dirname } from 'node:path'
18
-
19
- import type { CommandResult } from '@osdlc/command-seam'
20
-
21
- import { cliBackend, type GitBackend, type GitCallOptions } from './backend.ts'
22
- import { softAsync, triedAsync, type Soft, type TriedAsync } from './outcome.ts'
23
- import { parseRemoteUrl, type RemoteCoordinate } from './remote-url.ts'
24
- import { SOFT_TABLE } from './soft.ts'
25
- import {
26
- parseRefRows,
27
- splitLines,
28
- splitTrailingOptions,
29
- type AddOptions,
30
- type AheadBehind,
31
- type CommitOptions,
32
- type CheckoutOptions,
33
- type ConfigGetOptions,
34
- type CloneOptions,
35
- type ConflictSide,
36
- type MergeOptions,
37
- type MergeOutcome,
38
- type MergeTreeOptions,
39
- type MergeTreeOutcome,
40
- type RebaseOptions,
41
- type RebaseOutcome,
42
- type RemoteGetUrlOptions,
43
- type TaggedFile,
44
- type UnmergedEntry,
45
- type ConfigSetOptions,
46
- type DiffEntry,
47
- type DiffNameOnlyOptions,
48
- type DiffStatOptions,
49
- type DiffNameStatusOptions,
50
- type DiffTextOptions,
51
- type DiffTreeOptions,
52
- type FetchOptions,
53
- type ForEachRefOptions,
54
- type ForceLease,
55
- type GrepOptions,
56
- type InitOptions,
57
- type LogOptions,
58
- type IgnoreMatch,
59
- type LsFilesOptions,
60
- type LsRemoteOptions,
61
- type LsTreeOptions,
62
- type NumstatEntry,
63
- type RemoteRef,
64
- type CleanOptions,
65
- type DiffCheckOptions,
66
- type DiffCheckResult,
67
- type StatusEntry,
68
- type StatusPorcelainOptions,
69
- type TreeEntry,
70
- type Worktree,
71
- type WorktreeMoveOptions,
72
- } from './verbs.ts'
73
-
74
- /** `Omit` applied per union arm, so a discriminated option type stays a union. */
75
- type DistributiveOmit<T, K extends PropertyKey> = T extends unknown ? Omit<T, K> : never
76
-
77
- /**
78
- * Split a merged option bag into the per-call concerns and the operation's
79
- * own fields. A {@link GitRequest} must stay serializable data, so `signal`
80
- * and `timeoutMs` are separated out before the request is built.
81
- */
82
- function splitCallOptions<T extends GitCallOptions>(
83
- opts: T,
84
- ): [GitCallOptions, DistributiveOmit<T, keyof GitCallOptions>] {
85
- const { timeoutMs, signal, env, maxOutputBytes, ...rest } = opts
86
- return [
87
- { timeoutMs, signal, env, maxOutputBytes },
88
- rest as DistributiveOmit<T, keyof GitCallOptions>,
89
- ]
90
- }
91
-
92
- /** A typed, awaitable git client bound to one working directory. */
93
- export class AsyncGit {
94
- readonly cwd: string
95
- private readonly backend: GitBackend
96
- private tried: TriedAsync<AsyncGit> | undefined
97
- private softened: Soft<AsyncGit> | undefined
98
-
99
- /**
100
- * Bind a client to `cwd`. The default backend spawns the `git` CLI.
101
- *
102
- * This client takes a `backend`, where `Git` takes a `runner`. To
103
- * change how the CLI process is spawned, pass `cliBackend({ runner })`.
104
- *
105
- * `gitDir`, `workTree` and `env` live on the backend
106
- * (`cliBackend({ gitDir })`), not here: a non-CLI backend has no
107
- * `--git-dir` to receive, so they belong to the thing that spawns git.
108
- * The sync {@link Git} takes them on the client, which has no backend.
109
- */
110
- constructor(cwd: string, opts: { backend?: GitBackend | undefined } = {}) {
111
- this.cwd = cwd
112
- this.backend = opts.backend ?? cliBackend()
113
- }
114
-
115
- /** The same client rooted at a different directory (same backend). */
116
- at(cwd: string): AsyncGit {
117
- return new AsyncGit(cwd, { backend: this.backend })
118
- }
119
-
120
- /**
121
- * The whole surface again, resolving to a {@link GitOutcome} instead of
122
- * rejecting. A declared absence is `ok: true`; see `./outcome.ts`.
123
- *
124
- * The type leaves out `raw`, `rawChecked` and `at`, but at runtime the proxy
125
- * wraps them too: `git.try.raw(argv)` resolves to `{ ok: true, value }`.
126
- * Call those three on the client itself.
127
- */
128
- get try(): TriedAsync<AsyncGit> {
129
- return (this.tried ??= triedAsync(this))
130
- }
131
-
132
- /**
133
- * The tolerant door: each verb with an absence value (`null`, `[]` or
134
- * `false`) returns that value when git fails instead of throwing. For
135
- * callers that treat "could not ask" the same as "nothing there" —
136
- * `git.soft.resolveRef(x)` is `null` for a missing ref and for a broken
137
- * repo alike. Use `try` when the failure itself matters.
138
- *
139
- * As with `try`, the proxy also wraps `raw`, `rawChecked` and `at` at
140
- * runtime, though the type leaves them out.
141
- */
142
- get soft(): Soft<AsyncGit> {
143
- return (this.softened ??= softAsync(this, SOFT_TABLE))
144
- }
145
-
146
- // ── escape hatch ──────────────────────────────────────────────────────────
147
-
148
- /**
149
- * Unchecked argv passthrough. Only a CLI-shaped backend can serve this;
150
- * others reject with `UnsupportedRequest`.
151
- */
152
- raw(
153
- argv: string[],
154
- opts: GitCallOptions & { input?: string | undefined } = {},
155
- ): Promise<CommandResult> {
156
- return this.backend.execute(this.cwd, { kind: 'raw', argv, input: opts.input }, opts)
157
- }
158
-
159
- /**
160
- * Checked argv passthrough — rejects with `CommandFailed` on a non-zero
161
- * exit, and on output cut short at the output cap or a timeout. Report
162
- * `e.detail`, which joins both streams; see {@link Git.rawChecked}.
163
- */
164
- rawChecked(
165
- argv: string[],
166
- opts: GitCallOptions & { input?: string | undefined } = {},
167
- ): Promise<CommandResult> {
168
- return this.backend.execute(
169
- this.cwd,
170
- { kind: 'raw', argv, checked: true, input: opts.input },
171
- opts,
172
- )
173
- }
174
-
175
- // ── queries ───────────────────────────────────────────────────────────────
176
-
177
- /** A file's content at a rev, null if absent. */
178
- showAtRev(rev: string, relPath: string, opts: GitCallOptions = {}): Promise<string | null> {
179
- return this.backend.execute(this.cwd, { kind: 'showAtRev', rev, relPath }, opts)
180
- }
181
-
182
- /**
183
- * See {@link Git.revParse}. Call options go last, as an object. For a ref,
184
- * prefer {@link AsyncGit.resolveRef}.
185
- */
186
- revParse(...args: string[] | [...string[], GitCallOptions]): Promise<string | null> {
187
- const [argv, opts] = splitTrailingOptions<GitCallOptions>(args)
188
- return this.backend.execute(this.cwd, { kind: 'revParse', args: argv }, opts)
189
- }
190
-
191
- /** The sha `ref` resolves to, or null. See {@link Git.resolveRef}. */
192
- resolveRef(ref: string, opts: GitCallOptions = {}): Promise<string | null> {
193
- return this.backend.execute(this.cwd, { kind: 'resolveRef', ref }, opts)
194
- }
195
-
196
- /** True iff this repository has any history. See {@link Git.hasHistory}. */
197
- async hasHistory(opts: GitCallOptions = {}): Promise<boolean> {
198
- return (await this.resolveRef('HEAD', opts)) !== null
199
- }
200
-
201
- /** HEAD's shortname, `"HEAD"` when detached. See {@link Git.headRef}. */
202
- headRef(opts: GitCallOptions = {}): Promise<string | null> {
203
- return this.backend.execute(this.cwd, { kind: 'headRef' }, opts)
204
- }
205
-
206
- /** Absolute repo top-level directory, or null outside a repo. */
207
- topLevel(opts: GitCallOptions = {}): Promise<string | null> {
208
- return this.backend.execute(this.cwd, { kind: 'topLevel' }, opts)
209
- }
210
-
211
- /**
212
- * The shared `.git` dir (worktree-aware) as an absolute path, or null
213
- * outside a repo. See {@link Git.gitCommonDir}.
214
- */
215
- gitCommonDir(opts: GitCallOptions = {}): Promise<string | null> {
216
- return this.backend.execute(this.cwd, { kind: 'gitCommonDir' }, opts)
217
- }
218
-
219
- /**
220
- * This worktree's own `.git` dir as an absolute path, or null outside a
221
- * repo. See {@link Git.gitDir}.
222
- */
223
- gitDir(opts: GitCallOptions = {}): Promise<string | null> {
224
- return this.backend.execute(this.cwd, { kind: 'gitDir' }, opts)
225
- }
226
-
227
- /**
228
- * What a symbolic ref points at (full refname), or null when it is not one.
229
- * See {@link Git.symbolicRef}.
230
- */
231
- symbolicRef(ref: string, opts: GitCallOptions = {}): Promise<string | null> {
232
- return this.backend.execute(this.cwd, { kind: 'symbolicRef', ref }, opts)
233
- }
234
-
235
- /**
236
- * The primary checkout that owns this working directory, or null outside a
237
- * repository. See {@link Git.mainCheckout}.
238
- */
239
- async mainCheckout(opts: GitCallOptions = {}): Promise<string | null> {
240
- const common = await this.gitCommonDir(opts)
241
- return common === null ? null : dirname(common)
242
- }
243
-
244
- /** Current branch shortname, or null when detached. Rejects outside a repo. */
245
- currentBranch(opts: GitCallOptions = {}): Promise<string | null> {
246
- return this.backend.execute(this.cwd, { kind: 'currentBranch' }, opts)
247
- }
248
-
249
- /**
250
- * `git status --porcelain` lines; `[]` on a clean tree, and a rejection
251
- * outside a repository. `paths` narrows the report to those pathspecs.
252
- */
253
- statusPorcelain(opts: GitCallOptions & StatusPorcelainOptions = {}): Promise<string[]> {
254
- const [call, req] = splitCallOptions(opts)
255
- return this.backend.execute(this.cwd, { kind: 'statusPorcelain', ...req }, call)
256
- }
257
-
258
- /** Every changed or untracked file, from `status --porcelain -z`. */
259
- statusEntries(opts: GitCallOptions = {}): Promise<StatusEntry[]> {
260
- return this.backend.execute(this.cwd, { kind: 'statusEntries' }, opts)
261
- }
262
-
263
- /** True iff the working tree has any staged/unstaged/untracked change. */
264
- async isDirty(opts: GitCallOptions & StatusPorcelainOptions = {}): Promise<boolean> {
265
- return (await this.statusPorcelain(opts)).length > 0
266
- }
267
-
268
- /** Local branch shortnames matching `pattern` (all when omitted). */
269
- branches(pattern?: string | undefined, opts: GitCallOptions = {}): Promise<string[]> {
270
- return this.backend.execute(this.cwd, { kind: 'branches', pattern }, opts)
271
- }
272
-
273
- /** True iff local branch `name` exists (exact match). */
274
- async branchExists(name: string, opts: GitCallOptions = {}): Promise<boolean> {
275
- return (await this.branches(name, opts)).includes(name)
276
- }
277
-
278
- /** `git worktree list --porcelain`, parsed. Rejects outside a repo. */
279
- worktrees(opts: GitCallOptions = {}): Promise<Worktree[]> {
280
- return this.backend.execute(this.cwd, { kind: 'worktrees' }, opts)
281
- }
282
-
283
- /** Merge base of two revs, or null when the histories are unrelated. */
284
- mergeBase(a: string, b: string, opts: GitCallOptions = {}): Promise<string | null> {
285
- return this.backend.execute(this.cwd, { kind: 'mergeBase', a, b }, opts)
286
- }
287
-
288
- /** Subject line of a ref's HEAD commit, or null. */
289
- logSubject(ref: string, opts: GitCallOptions = {}): Promise<string | null> {
290
- return this.backend.execute(this.cwd, { kind: 'logSubject', ref }, opts)
291
- }
292
-
293
- /** `git config --get <key>`, or null when unset. `scope` reads one file only. */
294
- configGet(key: string, opts: GitCallOptions & ConfigGetOptions = {}): Promise<string | null> {
295
- const [call, req] = splitCallOptions(opts)
296
- return this.backend.execute(this.cwd, { kind: 'configGet', key, ...req }, call)
297
- }
298
-
299
- /** Every value of a multi-valued key, verbatim; `[]` when unset. */
300
- configGetAll(key: string, opts: GitCallOptions & ConfigGetOptions = {}): Promise<string[]> {
301
- const [call, req] = splitCallOptions(opts)
302
- return this.backend.execute(this.cwd, { kind: 'configGetAll', key, ...req }, call)
303
- }
304
-
305
- /** A key read as a boolean by git, or null when unset. See {@link Git.configGetBool}. */
306
- configGetBool(
307
- key: string,
308
- opts: GitCallOptions & ConfigGetOptions = {},
309
- ): Promise<boolean | null> {
310
- const [call, req] = splitCallOptions(opts)
311
- return this.backend.execute(this.cwd, { kind: 'configGetBool', key, ...req }, call)
312
- }
313
-
314
- /** True iff `rev` resolves to an object. */
315
- objectExists(rev: string, opts: GitCallOptions = {}): Promise<boolean> {
316
- return this.backend.execute(this.cwd, { kind: 'objectExists', rev }, opts)
317
- }
318
-
319
- /**
320
- * `ls-remote` rows for a remote (optionally pattern-filtered). `[]` means
321
- * the remote has no matching refs; an unreachable remote rejects.
322
- */
323
- lsRemote(
324
- remote: string,
325
- pattern?: string | undefined,
326
- opts: GitCallOptions & LsRemoteOptions = {},
327
- ): Promise<RemoteRef[]> {
328
- const [call, req] = splitCallOptions(opts)
329
- return this.backend.execute(this.cwd, { kind: 'lsRemote', remote, pattern, ...req }, call)
330
- }
331
-
332
- /**
333
- * The subset of `relPaths` that .gitignore rules ignore. Rejects outside a
334
- * repository. Fail-closed callers: see {@link Git.checkIgnore}.
335
- */
336
- checkIgnore(relPaths: string[], opts: GitCallOptions = {}): Promise<Set<string>> {
337
- if (relPaths.length === 0) return Promise.resolve(new Set())
338
- return this.backend.execute(this.cwd, { kind: 'checkIgnore', relPaths }, opts)
339
- }
340
-
341
- /**
342
- * The ignore rule (file, line, pattern) behind each of `relPaths` that a rule mentions;
343
- * see {@link Git.checkIgnoreVerbose}. Rejects outside a repository.
344
- */
345
- checkIgnoreVerbose(relPaths: string[], opts: GitCallOptions = {}): Promise<IgnoreMatch[]> {
346
- if (relPaths.length === 0) return Promise.resolve([])
347
- return this.backend.execute(this.cwd, { kind: 'checkIgnoreVerbose', relPaths }, opts)
348
- }
349
-
350
- /**
351
- * Tracked and/or untracked file paths (`ls-files -z`). Rejects outside a
352
- * repository, where `topLevel()` resolves to null. See {@link Git.lsFiles}.
353
- */
354
- lsFiles(opts: GitCallOptions & LsFilesOptions = {}): Promise<string[]> {
355
- const [call, req] = splitCallOptions(opts)
356
- return this.backend.execute(this.cwd, { kind: 'lsFiles', ...req }, call)
357
- }
358
-
359
- /** Tracked files with their `ls-files -v` tag. See {@link Git.lsFilesTagged}. */
360
- lsFilesTagged(opts: GitCallOptions = {}): Promise<TaggedFile[]> {
361
- return this.backend.execute(this.cwd, { kind: 'lsFilesTagged' }, opts)
362
- }
363
-
364
- /**
365
- * The unified diff; `""` when nothing differs. A bad rev, or a cwd outside a
366
- * repository, rejects. See {@link Git.diffText}.
367
- */
368
- diffText(rev?: string | undefined, opts: GitCallOptions & DiffTextOptions = {}): Promise<string> {
369
- const [call, req] = splitCallOptions(opts)
370
- return this.backend.execute(
371
- this.cwd,
372
- { kind: 'diffText', rev, staged: req.staged, paths: req.paths },
373
- call,
374
- )
375
- }
376
-
377
- /**
378
- * One untracked file rendered as an all-added diff. A path git cannot read
379
- * rejects. See {@link Git.diffAddedFile}.
380
- */
381
- diffAddedFile(relPath: string, opts: GitCallOptions = {}): Promise<string> {
382
- return this.backend.execute(this.cwd, { kind: 'diffAddedFile', relPath }, opts)
383
- }
384
-
385
- /** `for-each-ref` rows, one line each, in the caller's format. */
386
- forEachRef(
387
- pattern: string | string[],
388
- opts: GitCallOptions & ForEachRefOptions = {},
389
- ): Promise<string[]> {
390
- const [call, req] = splitCallOptions(opts)
391
- return this.backend.execute(this.cwd, { kind: 'forEachRef', pattern, ...req }, call)
392
- }
393
-
394
- /** Local refs matching `pattern` as `{ sha, ref }` rows. */
395
- async refs(pattern: string | string[], opts: GitCallOptions = {}): Promise<RemoteRef[]> {
396
- return parseRefRows(await this.forEachRef(pattern, opts))
397
- }
398
-
399
- /** Changed paths (`diff --name-only -z`); `[]` when nothing changed. */
400
- diffNameOnly(opts: GitCallOptions & DiffNameOnlyOptions = {}): Promise<string[]> {
401
- const [call, req] = splitCallOptions(opts)
402
- return this.backend.execute(this.cwd, { kind: 'diffNameOnly', ...req }, call)
403
- }
404
-
405
- /** The `diff --stat` summary as raw stdout. See {@link Git.diffStat}. */
406
- diffStat(opts: GitCallOptions & DiffStatOptions = {}): Promise<string> {
407
- const [call, req] = splitCallOptions(opts)
408
- return this.backend.execute(this.cwd, { kind: 'diffStat', ...req }, call)
409
- }
410
-
411
- /** `git diff --check`: whitespace errors and conflict markers; findings do not reject. */
412
- diffCheck(opts: GitCallOptions & DiffCheckOptions = {}): Promise<DiffCheckResult> {
413
- const [call, req] = splitCallOptions(opts)
414
- return this.backend.execute(this.cwd, { kind: 'diffCheck', ...req }, call)
415
- }
416
-
417
- /** Changed paths with their status; renames report the destination. */
418
- diffNameStatus(opts: GitCallOptions & DiffNameStatusOptions = {}): Promise<DiffEntry[]> {
419
- const [call, req] = splitCallOptions(opts)
420
- return this.backend.execute(this.cwd, { kind: 'diffNameStatus', ...req }, call)
421
- }
422
-
423
- /**
424
- * `git log` as raw stdout — the caller's `--format`, unsplit and untrimmed.
425
- * Rejects on an empty repository; probe {@link AsyncGit.hasHistory} first.
426
- * See {@link Git.log}.
427
- */
428
- log(opts: GitCallOptions & LogOptions = {}): Promise<string> {
429
- const [call, req] = splitCallOptions(opts)
430
- return this.backend.execute(this.cwd, { kind: 'log', ...req }, call)
431
- }
432
-
433
- /** {@link AsyncGit.log}, split into non-blank lines. See {@link Git.logLines}. */
434
- async logLines(opts: GitCallOptions & LogOptions = {}): Promise<string[]> {
435
- return splitLines(await this.log(opts))
436
- }
437
-
438
- /**
439
- * The entries of a tree at a rev (`ls-tree -z`); `[]` for a pathspec that
440
- * matches nothing, and a rejection for a rev that does not resolve.
441
- */
442
- lsTree(rev: string, opts: GitCallOptions & LsTreeOptions = {}): Promise<TreeEntry[]> {
443
- const [call, req] = splitCallOptions(opts)
444
- return this.backend.execute(this.cwd, { kind: 'lsTree', rev, ...req }, call)
445
- }
446
-
447
- /**
448
- * The paths and statuses one commit changed. Pass `root` for a commit that
449
- * may be the first one — without it a root commit reports nothing.
450
- */
451
- diffTree(rev: string, opts: GitCallOptions & DiffTreeOptions = {}): Promise<DiffEntry[]> {
452
- const [call, req] = splitCallOptions(opts)
453
- return this.backend.execute(this.cwd, { kind: 'diffTree', rev, ...req }, call)
454
- }
455
-
456
- /** Per-file line counts for one commit. See {@link Git.diffTreeNumstat}. */
457
- diffTreeNumstat(
458
- rev: string,
459
- opts: GitCallOptions & DiffTreeOptions = {},
460
- ): Promise<NumstatEntry[]> {
461
- const [call, req] = splitCallOptions(opts)
462
- return this.backend.execute(this.cwd, { kind: 'diffTreeNumstat', rev, ...req }, call)
463
- }
464
-
465
- /** Matching lines (`git grep`); `[]` for no matches, a rejection for a failure. */
466
- grep(pattern: string, opts: GitCallOptions & GrepOptions = {}): Promise<string[]> {
467
- const [call, req] = splitCallOptions(opts)
468
- return this.backend.execute(this.cwd, { kind: 'grep', pattern, ...req }, call)
469
- }
470
-
471
- /**
472
- * True iff `a` is an ancestor of `b`. A rev that does not resolve rejects
473
- * rather than reading as "no".
474
- */
475
- isAncestor(a: string, b: string, opts: GitCallOptions = {}): Promise<boolean> {
476
- return this.backend.execute(this.cwd, { kind: 'isAncestor', a, b }, opts)
477
- }
478
-
479
- /** How far `tip` has diverged from `base`. See {@link AheadBehind}. */
480
- aheadBehind(base: string, tip: string, opts: GitCallOptions = {}): Promise<AheadBehind> {
481
- return this.backend.execute(this.cwd, { kind: 'aheadBehind', base, tip }, opts)
482
- }
483
-
484
- /** Configured remote names (`git remote`); `[]` when there are none. */
485
- remotes(opts: GitCallOptions = {}): Promise<string[]> {
486
- return this.backend.execute(this.cwd, { kind: 'remote' }, opts)
487
- }
488
-
489
- /**
490
- * The same as {@link AsyncGit.remotes}.
491
- *
492
- * @deprecated Use `remotes()`. The name `remote()` reads as one remote, but
493
- * it returns every remote name. It will be removed at 1.0.
494
- */
495
- remote(opts: GitCallOptions = {}): Promise<string[]> {
496
- return this.remotes(opts)
497
- }
498
-
499
- /**
500
- * A remote's fetch URL (push URL with `push`), or null when no remote by
501
- * that name exists.
502
- */
503
- remoteGetUrl(
504
- name: string,
505
- opts: GitCallOptions & RemoteGetUrlOptions = {},
506
- ): Promise<string | null> {
507
- const [call, req] = splitCallOptions(opts)
508
- return this.backend.execute(this.cwd, { kind: 'remoteGetUrl', name, ...req }, call)
509
- }
510
-
511
- /** Every URL a remote has (push URLs with `push`); `[]` for an unknown remote. */
512
- remoteGetUrls(name: string, opts: GitCallOptions & RemoteGetUrlOptions = {}): Promise<string[]> {
513
- const [call, req] = splitCallOptions(opts)
514
- return this.backend.execute(this.cwd, { kind: 'remoteGetUrls', name, ...req }, call)
515
- }
516
-
517
- /**
518
- * The full refname the remote's HEAD points at, asked over the network; null
519
- * when the remote names none. See {@link Git.remoteHead}.
520
- */
521
- remoteHead(remote: string, opts: GitCallOptions = {}): Promise<string | null> {
522
- return this.backend.execute(this.cwd, { kind: 'remoteHead', remote }, opts)
523
- }
524
-
525
- /** The coordinate a remote's URL names, or null. See {@link Git.remoteOwnerRepo}. */
526
- async remoteOwnerRepo(
527
- remote = 'origin',
528
- opts: GitCallOptions = {},
529
- ): Promise<RemoteCoordinate | null> {
530
- const url = await this.remoteGetUrl(remote, opts)
531
- return url === null ? null : parseRemoteUrl(url)
532
- }
533
-
534
- // ── mutations (nothing is absence — any non-zero exit rejects) ────────────
535
-
536
- /** `git fetch <remote> [refspec…]`. See {@link FetchOptions} for the flags. */
537
- fetch(
538
- remote: string,
539
- refspec?: string | string[] | undefined,
540
- opts: GitCallOptions & FetchOptions = {},
541
- ): Promise<void> {
542
- const [call, req] = splitCallOptions(opts)
543
- return this.backend.execute(this.cwd, { kind: 'fetch', remote, refspec, ...req }, call)
544
- }
545
-
546
- /** Stage paths; `all` / `update` are `git add -A` / `-u`. */
547
- add(paths: string[], opts: GitCallOptions & AddOptions = {}): Promise<void> {
548
- const [call, req] = splitCallOptions(opts)
549
- return this.backend.execute(this.cwd, { kind: 'add', paths, ...req }, call)
550
- }
551
-
552
- /**
553
- * Commit with an inline message, a message file or a stdin message (exactly
554
- * one). A failing hook rejects; git writes hook output to stdout, which
555
- * `e.detail` reads.
556
- */
557
- commit(opts: GitCallOptions & CommitOptions): Promise<void> {
558
- const [call, req] = splitCallOptions(opts)
559
- return this.backend.execute(this.cwd, { kind: 'commit', ...req }, call)
560
- }
561
-
562
- /** `git config <key> <value>` — the twin of {@link AsyncGit.configGet}. */
563
- configSet(
564
- key: string,
565
- value: string,
566
- opts: GitCallOptions & ConfigSetOptions = {},
567
- ): Promise<void> {
568
- const [call, req] = splitCallOptions(opts)
569
- return this.backend.execute(this.cwd, { kind: 'configSet', key, value, ...req }, call)
570
- }
571
-
572
- /** `git init [path]`; `path` defaults to this client's `cwd`. */
573
- init(path?: string | undefined, opts: GitCallOptions & InitOptions = {}): Promise<void> {
574
- const [call, req] = splitCallOptions(opts)
575
- return this.backend.execute(this.cwd, { kind: 'init', path, ...req }, call)
576
- }
577
-
578
- /** `git clone [--depth n] [--branch ref] <url> [dest]`, from this client's `cwd`. */
579
- clone(
580
- url: string,
581
- dest?: string | undefined,
582
- opts: GitCallOptions & CloneOptions = {},
583
- ): Promise<void> {
584
- const [call, req] = splitCallOptions(opts)
585
- return this.backend.execute(this.cwd, { kind: 'clone', url, dest, ...req }, call)
586
- }
587
-
588
- /**
589
- * Push a refspec. A {@link ForceLease} pins `--force-with-lease`.
590
- * `{forceWithLease: true}` adds the bare flag, which is the unsafe form. See
591
- * {@link Git.push}.
592
- */
593
- push(
594
- remote: string,
595
- refspec: string,
596
- opts: GitCallOptions & { forceWithLease?: boolean | ForceLease | undefined } = {},
597
- ): Promise<void> {
598
- return this.backend.execute(
599
- this.cwd,
600
- { kind: 'push', remote, refspec, forceWithLease: opts.forceWithLease },
601
- opts,
602
- )
603
- }
604
-
605
- /** `git clean -f`, plus `-d` with `directories`. Ignored files are kept. */
606
- clean(opts: GitCallOptions & CleanOptions = {}): Promise<void> {
607
- const [call, req] = splitCallOptions(opts)
608
- return this.backend.execute(this.cwd, { kind: 'clean', ...req }, call)
609
- }
610
-
611
- /** `git reset --hard <rev>`. */
612
- resetHard(rev: string, opts: GitCallOptions = {}): Promise<void> {
613
- return this.backend.execute(this.cwd, { kind: 'resetHard', rev }, opts)
614
- }
615
-
616
- /** Delete a local branch (`-d`, or `-D` with `{force: true}`). */
617
- deleteBranch(
618
- name: string,
619
- opts: GitCallOptions & { force?: boolean | undefined } = {},
620
- ): Promise<void> {
621
- return this.backend.execute(this.cwd, { kind: 'deleteBranch', name, force: opts.force }, opts)
622
- }
623
-
624
- /**
625
- * Remove config section `name`; false when it was absent. See
626
- * `configRemoveSection` in `verbs.ts`.
627
- */
628
- configRemoveSection(name: string, opts: GitCallOptions = {}): Promise<boolean> {
629
- return this.backend.execute(this.cwd, { kind: 'configRemoveSection', name }, opts)
630
- }
631
-
632
- /** Delete `ref` only while it points at `expected`. See `deleteRef` in `verbs.ts`. */
633
- deleteRef(ref: string, opts: GitCallOptions & { expected: string }): Promise<void> {
634
- return this.backend.execute(this.cwd, { kind: 'deleteRef', ref, expected: opts.expected }, opts)
635
- }
636
-
637
- /** `git worktree add [--detach] [-b branch] <path> [startPoint]`. */
638
- worktreeAdd(
639
- path: string,
640
- opts: GitCallOptions & {
641
- branch?: string | undefined
642
- startPoint?: string | undefined
643
- detach?: boolean | undefined
644
- } = {},
645
- ): Promise<void> {
646
- return this.backend.execute(
647
- this.cwd,
648
- {
649
- kind: 'worktreeAdd',
650
- path,
651
- branch: opts.branch,
652
- startPoint: opts.startPoint,
653
- detach: opts.detach,
654
- },
655
- opts,
656
- )
657
- }
658
-
659
- /** `git worktree remove [--force] <path>`. */
660
- worktreeRemove(
661
- path: string,
662
- opts: GitCallOptions & { force?: boolean | undefined } = {},
663
- ): Promise<void> {
664
- return this.backend.execute(this.cwd, { kind: 'worktreeRemove', path, force: opts.force }, opts)
665
- }
666
-
667
- /** `git worktree move [--force] <from> <to>`. */
668
- worktreeMove(
669
- from: string,
670
- to: string,
671
- opts: GitCallOptions & WorktreeMoveOptions = {},
672
- ): Promise<void> {
673
- const [call, req] = splitCallOptions(opts)
674
- return this.backend.execute(this.cwd, { kind: 'worktreeMove', from, to, ...req }, call)
675
- }
676
-
677
- /** `git worktree prune`. */
678
- worktreePrune(opts: GitCallOptions = {}): Promise<void> {
679
- return this.backend.execute(this.cwd, { kind: 'worktreePrune' }, opts)
680
- }
681
-
682
- /** `git remote add <name> <url>`. */
683
- remoteAdd(name: string, url: string, opts: GitCallOptions = {}): Promise<void> {
684
- return this.backend.execute(this.cwd, { kind: 'remoteAdd', name, url }, opts)
685
- }
686
-
687
- // ── integration ───────────────────────────────────────────────────────────
688
-
689
- /**
690
- * Merge `ref` into the current branch. A conflict is a value, not a
691
- * rejection: the outcome is `clean` or `conflict`. Git refusing to merge at
692
- * all still rejects with `CommandFailed`.
693
- */
694
- merge(ref: string, opts: MergeOptions & GitCallOptions = {}): Promise<MergeOutcome> {
695
- const [call, req] = splitCallOptions(opts)
696
- return this.backend.execute(this.cwd, { kind: 'merge', ref, ...req }, call)
697
- }
698
-
699
- /** `git merge --abort`. Rejects when no merge is in progress. */
700
- mergeAbort(opts: GitCallOptions = {}): Promise<void> {
701
- return this.backend.execute(this.cwd, { kind: 'mergeAbort' }, opts)
702
- }
703
-
704
- /** Replay onto `onto`. Same outcome as {@link AsyncGit.merge}. */
705
- rebase(onto: string, opts: RebaseOptions & GitCallOptions = {}): Promise<RebaseOutcome> {
706
- const [call, req] = splitCallOptions(opts)
707
- return this.backend.execute(this.cwd, { kind: 'rebase', onto, ...req }, call)
708
- }
709
-
710
- /** `git rebase --abort`. Rejects when no rebase is in progress. */
711
- rebaseAbort(opts: GitCallOptions = {}): Promise<void> {
712
- return this.backend.execute(this.cwd, { kind: 'rebaseAbort' }, opts)
713
- }
714
-
715
- /** `git rebase --continue`, editor stubbed. May conflict again. */
716
- rebaseContinue(opts: GitCallOptions = {}): Promise<RebaseOutcome> {
717
- return this.backend.execute(this.cwd, { kind: 'rebaseContinue' }, opts)
718
- }
719
-
720
- /**
721
- * What merging `theirs` into `ours` would do — no index, no checkout, no
722
- * worktree. The cheap way to ask "would this conflict, and where", and the
723
- * merged `tree` it returns is real enough to build a commit from.
724
- */
725
- mergeTree(
726
- ours: string,
727
- theirs: string,
728
- opts: MergeTreeOptions & GitCallOptions = {},
729
- ): Promise<MergeTreeOutcome> {
730
- const [call, req] = splitCallOptions(opts)
731
- return this.backend.execute(this.cwd, { kind: 'mergeTree', ours, theirs, ...req }, call)
732
- }
733
-
734
- /** `git ls-files -u`, parsed — the stage detail behind each conflict. */
735
- lsFilesUnmerged(opts: GitCallOptions = {}): Promise<UnmergedEntry[]> {
736
- return this.backend.execute(this.cwd, { kind: 'lsFilesUnmerged' }, opts)
737
- }
738
-
739
- /**
740
- * Resolve conflicted `paths` to one side wholesale. An empty list resolves
741
- * without calling the backend. See {@link Git.checkoutSide}.
742
- */
743
- checkoutSide(side: ConflictSide, paths: string[], opts: GitCallOptions = {}): Promise<void> {
744
- if (paths.length === 0) return Promise.resolve()
745
- return this.backend.execute(this.cwd, { kind: 'checkoutSide', side, paths }, opts)
746
- }
747
-
748
- /** `git checkout [-f] [-b|-B <branch>] <ref>`. */
749
- checkout(ref: string, opts: CheckoutOptions & GitCallOptions = {}): Promise<void> {
750
- const [call, req] = splitCallOptions(opts)
751
- return this.backend.execute(this.cwd, { kind: 'checkout', ref, ...req }, call)
752
- }
753
- }