@osdlc/typed-git 0.5.0 → 0.5.3
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/CHANGELOG.md +83 -36
- package/LICENSE-APACHE +202 -0
- package/README.md +133 -30
- package/async.ts +109 -32
- package/backend.ts +57 -12
- package/client.ts +18 -8
- package/dist/async.d.ts +59 -23
- package/dist/async.d.ts.map +1 -1
- package/dist/async.js +87 -29
- package/dist/backend.d.ts +50 -9
- package/dist/backend.d.ts.map +1 -1
- package/dist/backend.js +25 -3
- package/dist/client.d.ts +10 -7
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +10 -7
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/outcome.d.ts +6 -1
- package/dist/outcome.d.ts.map +1 -1
- package/dist/remote-url.d.ts +3 -0
- package/dist/remote-url.d.ts.map +1 -1
- package/dist/remote-url.js +3 -0
- package/dist/soft.d.ts +7 -1
- package/dist/soft.d.ts.map +1 -1
- package/dist/soft.js +7 -1
- package/dist/sync.d.ts +74 -24
- package/dist/sync.d.ts.map +1 -1
- package/dist/sync.js +99 -28
- package/dist/testing.d.ts +54 -26
- package/dist/testing.d.ts.map +1 -1
- package/dist/testing.js +11 -4
- package/dist/verbs.d.ts +163 -41
- package/dist/verbs.d.ts.map +1 -1
- package/dist/verbs.js +342 -83
- package/index.ts +2 -2
- package/outcome.ts +13 -5
- package/package.json +11 -6
- package/remote-url.ts +3 -0
- package/soft.ts +7 -1
- package/sync.ts +114 -31
- package/testing.ts +64 -32
- package/verbs.ts +427 -103
- /package/{LICENSE → LICENSE-MIT} +0 -0
package/README.md
CHANGED
|
@@ -15,8 +15,40 @@ it does not fit a browser, and it is not an implementation of git.
|
|
|
15
15
|
npm install @osdlc/typed-git
|
|
16
16
|
```
|
|
17
17
|
|
|
18
|
-
The package is ESM only. It needs
|
|
19
|
-
|
|
18
|
+
The package is ESM only. It needs Node `^22.22.2 || ^24.15.0 || >=26.0.0`, the
|
|
19
|
+
range its dependency `hosted-git-info` needs, and a `git` executable on
|
|
20
|
+
`PATH`. Its types use the global `AbortSignal`, so a project needs
|
|
21
|
+
`@types/node` or the DOM lib.
|
|
22
|
+
|
|
23
|
+
## Runtimes and platforms
|
|
24
|
+
|
|
25
|
+
Node.js, on macOS, Linux and Windows. CI runs the tests and the built package
|
|
26
|
+
on Linux and macOS, on Node 22 and 24. Windows is supported but not tested in
|
|
27
|
+
CI yet.
|
|
28
|
+
|
|
29
|
+
The minimum git version is the oldest one CI tests. CI uses the git that the
|
|
30
|
+
GitHub-hosted runners ship. On 2026-10-20 that was git 2.55.0 on
|
|
31
|
+
`ubuntu-latest` (Ubuntu 24.04) and git 2.56.0 on `macos-latest` (macOS 26), as
|
|
32
|
+
the checkout step logs it. So the tested minimum is git 2.55.0. Older git may
|
|
33
|
+
work, but no test shows it. The behaviour tables below were measured against
|
|
34
|
+
git 2.50.1. A verb that needs a newer git than you have fails with git's own
|
|
35
|
+
error and throws `CommandFailed`. `mergeTree` needs git 2.38 or later.
|
|
36
|
+
|
|
37
|
+
Bun runs the tests. It is not a tested runtime for consumers.
|
|
38
|
+
|
|
39
|
+
## Stability
|
|
40
|
+
|
|
41
|
+
The package is on the 0.x line. A breaking change ships only in a new minor
|
|
42
|
+
release, with a CHANGELOG entry that starts with `Breaking:`.
|
|
43
|
+
|
|
44
|
+
- `Git`, `AsyncGit`, `cliBackend`, the verbs, `git.try`, `git.soft`, the
|
|
45
|
+
URL and checkout helpers, and `./testing` are stable in 0.x.
|
|
46
|
+
- `GitBackend`, `GitRequest`, `GitResults` and `partialBackend` are
|
|
47
|
+
experimental. Each new verb adds a request kind, so a minor release can
|
|
48
|
+
break a backend written as an exhaustive `switch`. Use `partialBackend`
|
|
49
|
+
rather than an exhaustive switch. Their TSDoc carries `@experimental`.
|
|
50
|
+
- `remote()` is deprecated. Use `remotes()`. `remote()` will be removed at
|
|
51
|
+
1.0.
|
|
20
52
|
|
|
21
53
|
## Similar packages
|
|
22
54
|
|
|
@@ -26,6 +58,14 @@ the global `AbortSignal`, so a project needs `@types/node` or the DOM lib.
|
|
|
26
58
|
pure JavaScript. It needs no `git` binary and runs in browsers.
|
|
27
59
|
- [nodegit](https://www.npmjs.com/package/nodegit) binds libgit2 and needs a
|
|
28
60
|
native build.
|
|
61
|
+
- [@effected/git](https://www.npmjs.com/package/@effected/git) wraps the CLI
|
|
62
|
+
for programs built on Effect.
|
|
63
|
+
|
|
64
|
+
This package exists for plain TypeScript callers that want a synchronous form,
|
|
65
|
+
typed results and a declared absence value per verb.
|
|
66
|
+
|
|
67
|
+
The Rust crate `typed-git` is this package's twin. The two keep the same major
|
|
68
|
+
and minor version. Their APIs differ. The crate is not on crates.io yet.
|
|
29
69
|
|
|
30
70
|
## Quick look
|
|
31
71
|
|
|
@@ -111,8 +151,9 @@ const dirty = git.soft.statusPorcelain(); // string[] — [] on a broken repo
|
|
|
111
151
|
```
|
|
112
152
|
|
|
113
153
|
It is the one-liner for `const r = git.try.resolveRef(x); return r.ok ? r.value : null`.
|
|
114
|
-
Verbs
|
|
115
|
-
|
|
154
|
+
Verbs whose absence is not `null`, `[]` or `false` have no soft form: the
|
|
155
|
+
outcome verbs such as `merge`, and `checkIgnore`, `aheadBehind` and `diffText`,
|
|
156
|
+
plus every mutation. Reach for `try`. Boolean verbs fall back to
|
|
116
157
|
`false`, which also means "could not ask": `soft.isDirty` reads a broken repo
|
|
117
158
|
as clean, so do not gate a destructive action on it. `soft`
|
|
118
159
|
catches `CommandFailed` only, exactly like `try`, and one table
|
|
@@ -128,8 +169,7 @@ breakage remain indistinguishable — they keep exactly the weakness this
|
|
|
128
169
|
contract removes elsewhere.
|
|
129
170
|
|
|
130
171
|
Eight verbs declare 128 as absence: `showAtRev`, `topLevel`, `gitCommonDir`,
|
|
131
|
-
`symbolicRef`, `logSubject`, `objectExists
|
|
132
|
-
`diffText`. `try` and `soft` inherit it, because 128 is a declared absence
|
|
172
|
+
`gitDir`, `symbolicRef`, `logSubject`, `objectExists` and `configRemoveSection`. `try` and `soft` inherit it, because 128 is a declared absence
|
|
133
173
|
there: `git.try.logSubject("HEAD")` outside a repository is `{ ok: true,
|
|
134
174
|
value: null }`, not a failure. The contract narrows the failure surface; it
|
|
135
175
|
does not eliminate it.
|
|
@@ -273,10 +313,14 @@ all of 1/2/3 is both-modified, 1+3 is we-deleted, 1+2 is they-deleted, 2+3
|
|
|
273
313
|
with no base is add/add. A resolver that assumes both-modified deletes files.
|
|
274
314
|
For the paths alone, `diffNameOnly({ diffFilter: "U" })` is cheaper.
|
|
275
315
|
|
|
316
|
+
`merge`, `rebase` and `rebaseContinue` run with `LC_ALL=C`, over the client,
|
|
317
|
+
backend and call `env`, so `fastForward`, `alreadyUpToDate` and `conflicts` do
|
|
318
|
+
not change with the caller's locale. Other verbs keep the caller's locale.
|
|
319
|
+
|
|
276
320
|
One sharp edge git leaves in `checkoutSide`: on a path that is *not*
|
|
277
321
|
conflicted it exits 0 and does nothing. There is no error to catch, so take
|
|
278
322
|
the path list from `lsFilesUnmerged()` in the same breath, not from an
|
|
279
|
-
earlier one.
|
|
323
|
+
earlier one. An empty path list returns without running git.
|
|
280
324
|
|
|
281
325
|
## Asking without checking out
|
|
282
326
|
|
|
@@ -331,8 +375,10 @@ git.resolveRef("refs/heads/main"); // sha, or null when the ref does not resolv
|
|
|
331
375
|
git.hasHistory(); // resolveRef("HEAD") !== null
|
|
332
376
|
git.headRef(); // "main", or the literal "HEAD" when detached
|
|
333
377
|
git.currentBranch(); // "main", or null when detached
|
|
334
|
-
git.
|
|
378
|
+
git.remotes(); // ["origin", …]; [] when there are none
|
|
335
379
|
git.remoteGetUrl("origin"); // URL, or null — git exits 2 for an unknown remote
|
|
380
|
+
git.remoteGetUrls("origin"); // every URL; [] for an unknown remote
|
|
381
|
+
git.remoteHead("origin"); // "refs/heads/main", asked over the network
|
|
336
382
|
git.remoteOwnerRepo(); // { owner, repo, host, port } for origin, or null
|
|
337
383
|
git.remoteOwnerRepo("upstream"); // …for any remote; AsyncGit awaits the same
|
|
338
384
|
git.remoteAdd("origin", url);
|
|
@@ -341,7 +387,10 @@ git.remoteAdd("origin", url);
|
|
|
341
387
|
`remoteOwnerRepo(remote = "origin")` is `remoteGetUrl` plus a parse: `null`
|
|
342
388
|
when there is no such remote or its URL names no project. The parse is
|
|
343
389
|
host-agnostic (`parseRemoteUrl`: scp-style and `scheme://[user@]host[:port]/…`),
|
|
344
|
-
so a self-hosted Forgejo or Gitea answers, which `parseGitUrl` would not.
|
|
390
|
+
so a self-hosted Forgejo or Gitea answers, which `parseGitUrl` would not. Two
|
|
391
|
+
limits: a path with groups, `group/sub/repo`, gives owner `sub` and repo
|
|
392
|
+
`repo`; and a port is read only from an `http(s)://` URL. The port of an
|
|
393
|
+
`ssh://` URL is dropped (`port: null`). It
|
|
345
394
|
throws outside a repository like `remoteGetUrl`; use `git.try.remoteOwnerRepo()`
|
|
346
395
|
to fold that into a failed outcome.
|
|
347
396
|
|
|
@@ -358,8 +407,31 @@ needs to print.
|
|
|
358
407
|
Every method exists on both `Git` and `AsyncGit` with the same name and
|
|
359
408
|
arguments; the async one returns a promise. Each also mirrors onto
|
|
360
409
|
`git.try.*`, which returns `{ ok, value } | { ok, error }` instead of throwing.
|
|
361
|
-
Every method takes call options (`timeoutMs`, `env`,
|
|
362
|
-
side) as its last argument
|
|
410
|
+
Every method takes call options (`timeoutMs`, `env`, `maxOutputBytes`, and
|
|
411
|
+
`signal` on the async side) as its last argument. `revParse` is variadic, so its options are the
|
|
412
|
+
trailing argument that is not a string.
|
|
413
|
+
|
|
414
|
+
### Arguments that start with `-`
|
|
415
|
+
|
|
416
|
+
A ref, remote, URL, path, ref pattern or config key argument that starts with
|
|
417
|
+
`-` could be read by git as an option, for example `--upload-pack=...` or
|
|
418
|
+
`--output=<file>`. Forty-two verbs refuse it: they throw a `TypeError`
|
|
419
|
+
before git runs. In `log` this covers `rev`, `range` and each `notRefs` entry.
|
|
420
|
+
In `diffNameOnly` and `diffStat` it covers each `rangeArgs` token. The message is
|
|
421
|
+
`typed-git: <verb>: <param> must not start with "-" (got "...")`. `try` and
|
|
422
|
+
`soft` do not catch it, because it is a `TypeError`. On `AsyncGit` with
|
|
423
|
+
`cliBackend` it is a rejection. A backend that is not the CLI gets the request
|
|
424
|
+
unchecked. `revParse` is not guarded, because it passes flags on by design.
|
|
425
|
+
Paths after `--` are not affected. `grep` passes its pattern with `-e`, so a
|
|
426
|
+
pattern that starts with `-` is searched for, not refused.
|
|
427
|
+
|
|
428
|
+
To pass a path that starts with `-`, write `./-name`. For the previous branch,
|
|
429
|
+
write `@{-1}` instead of `-` in `checkout` and `merge`.
|
|
430
|
+
|
|
431
|
+
The three config reads also refuse a key with no section or no name: no `.`,
|
|
432
|
+
or a leading or trailing `.`. git exits 1 for such a key, the code the reads
|
|
433
|
+
take as unset. `clone` and `fetch` refuse a `depth` that is not a positive
|
|
434
|
+
integer. Both checks throw a `TypeError` before git runs.
|
|
363
435
|
|
|
364
436
|
### Queries
|
|
365
437
|
|
|
@@ -375,6 +447,7 @@ exit throws `CommandFailed`.
|
|
|
375
447
|
| `headRef()` | `rev-parse --abbrev-ref HEAD` | none — literal `"HEAD"` when detached |
|
|
376
448
|
| `topLevel()` | `rev-parse --show-toplevel` | `128` → `null` (not a repository) |
|
|
377
449
|
| `gitCommonDir()` | `rev-parse --path-format=absolute --git-common-dir` | `128` → `null` |
|
|
450
|
+
| `gitDir()` | `rev-parse --absolute-git-dir` | `128` → `null` — this worktree's own dir, `<common>/worktrees/<name>` in a linked worktree |
|
|
378
451
|
| `mainCheckout()` | the parent of `gitCommonDir()` | `null` outside a repository |
|
|
379
452
|
| `symbolicRef(ref)` | `symbolic-ref <ref>` | `128` → `null` |
|
|
380
453
|
| `currentBranch()` | `branch --show-current` | none — `null` when detached |
|
|
@@ -386,7 +459,9 @@ exit throws `CommandFailed`.
|
|
|
386
459
|
| `worktrees()` | `worktree list --porcelain` | none — rows carry `locked` and `lockReason` |
|
|
387
460
|
| `mergeBase(a, b)` | `merge-base <a> <b>` | `1` → `null` (unrelated histories) |
|
|
388
461
|
| `logSubject(ref)` | `log -1 --format=%s <ref>` | `128` → `null` |
|
|
389
|
-
| `configGet(key)` | `config --get <key>` | `1` → `null` (unset) |
|
|
462
|
+
| `configGet(key, { scope })` | `config [--local\|--global\|--system] --get <key>` | `1` → `null` (unset) |
|
|
463
|
+
| `configGetAll(key, { scope })` | `config --get-all -z <key>` | `1` → `[]` (unset) — every value, verbatim |
|
|
464
|
+
| `configGetBool(key, { scope })` | `config --type=bool --get <key>` | `1` → `null` (unset) — a value git cannot read as a boolean throws |
|
|
390
465
|
| `objectExists(rev)` | `cat-file -e <rev>` | `1`, `128` → `false` — see the caveat below |
|
|
391
466
|
| `lsRemote(remote, pattern, { heads, tags })` | `ls-remote` | none |
|
|
392
467
|
| `checkIgnore(paths)` | `check-ignore --stdin -z` | `1` → empty set (none ignored) |
|
|
@@ -399,6 +474,8 @@ exit throws `CommandFailed`.
|
|
|
399
474
|
| `diffNameStatus({ cached, range, noRenames, paths })` | `diff --name-status -z` | none |
|
|
400
475
|
| `diffStat({ rangeArgs, paths })` | `diff --stat` | none — raw stdout |
|
|
401
476
|
| `diffCheck({ paths })` | `diff --check` | `1`, `2` → `{ ok: false, output }` |
|
|
477
|
+
| `diffText(rev?, { staged, paths })` | `diff [--cached] [rev]` | none — empty string only when nothing differs; a bad rev or a non-repository throws |
|
|
478
|
+
| `diffAddedFile(relPath)` | `diff --no-index -- /dev/null <path>` | none — exit 1 with output is success; exit 1 with no output, or exit 2, throws |
|
|
402
479
|
| `log(opts)` | `log` | none — raw stdout, unsplit |
|
|
403
480
|
| `logLines(opts)` | `log`, split and filtered | none |
|
|
404
481
|
| `lsTree(rev, { recursive, long, paths })` | `ls-tree -z` | none |
|
|
@@ -407,8 +484,11 @@ exit throws `CommandFailed`.
|
|
|
407
484
|
| `grep(pattern, { extendedRegexp, lineNumber, noColor, paths })` | `grep` | `1` → `[]` (no match) |
|
|
408
485
|
| `isAncestor(a, b)` | `merge-base --is-ancestor` | `1` → `false` |
|
|
409
486
|
| `aheadBehind(base, tip)` | `rev-list --left-right --count <base>...<tip>` | none |
|
|
410
|
-
| `
|
|
411
|
-
| `
|
|
487
|
+
| `remotes()` | `remote` | none — names, not remotes |
|
|
488
|
+
| `remote()` | `remote` | none — deprecated alias of `remotes()` |
|
|
489
|
+
| `remoteGetUrl(name, { push })` | `remote get-url [--push] <name>` | `2` → `null` (unknown remote) — the first URL |
|
|
490
|
+
| `remoteGetUrls(name, { push })` | `remote get-url --all [--push] <name>` | `2` → `[]` (unknown remote) |
|
|
491
|
+
| `remoteHead(remote)` | `ls-remote --symref <remote> HEAD` | none — the full refname, or `null` when the remote names no default branch; an unreachable remote throws |
|
|
412
492
|
| `remoteOwnerRepo(remote = "origin")` | `remote get-url <remote>`, parsed | `2` or an unparseable URL → `null` |
|
|
413
493
|
|
|
414
494
|
`objectExists` declares both `1` and `128` absent, so `false` cannot tell an
|
|
@@ -417,18 +497,21 @@ empty repository from a dangling HEAD or a missing object store. Use
|
|
|
417
497
|
|
|
418
498
|
### Mutations
|
|
419
499
|
|
|
420
|
-
Every mutation declares no absence: a non-zero
|
|
421
|
-
because the only sane handling of "the write did
|
|
500
|
+
Every mutation except `configRemoveSection` declares no absence: a non-zero
|
|
501
|
+
exit throws `CommandFailed`, because the only sane handling of "the write did
|
|
502
|
+
not happen" is to surface it. `configRemoveSection` declares 128 absent and
|
|
503
|
+
returns `false` when there is no such section.
|
|
422
504
|
|
|
423
505
|
| Method | git |
|
|
424
506
|
| --- | --- |
|
|
425
|
-
| `fetch(remote, refspec, { prune, quiet, noWriteFetchHead })` | `fetch` |
|
|
507
|
+
| `fetch(remote, refspec, { prune, quiet, noWriteFetchHead, depth, noTags })` | `fetch` |
|
|
426
508
|
| `add(paths, { all, update, intentToAdd })` | `add` (paths go after `--`) |
|
|
427
509
|
| `commit({ message, body } \| { messageFile } \| { messageStdin }, { allowEmpty, amend, noVerify, signoff })` | `commit` — one message source, enforced by the types; `messageStdin` is `-F -` with the string on stdin, no temp file |
|
|
428
|
-
| `push(remote, refspec, { forceWithLease })` | `push` — `forceWithLease` takes `true` or a pinned `{ ref, expect }` (`expect: null` = ref must be absent); `forceWithLeaseArg(lease)` is the pure formatter |
|
|
510
|
+
| `push(remote, refspec, { forceWithLease })` | `push` — `forceWithLease` takes `true` or a pinned `{ ref, expect }` (`expect: null` = ref must be absent); `forceWithLeaseArg(lease)` is the pure formatter. `true` is the bare form: it overwrites whatever is on the remote, so prefer the pinned form |
|
|
429
511
|
| `configSet(key, value, { scope })` | `config` |
|
|
512
|
+
| `configRemoveSection(name)` | `config --remove-section` — `false` when there is no such section |
|
|
430
513
|
| `init(path, { bare, initialBranch, quiet })` | `init` |
|
|
431
|
-
| `clone(url, dest, { depth, branch, bare, quiet })` | `clone` — a relative `dest` resolves in the client's working directory; `branch` takes a branch or a tag, not a sha |
|
|
514
|
+
| `clone(url, dest, { depth, branch, bare, mirror, singleBranch, noTags, quiet })` | `clone` — a relative `dest` resolves in the client's working directory; `branch` takes a branch or a tag, not a sha; with `mirror`, `noTags` has no effect and `singleBranch` holds for the clone only |
|
|
432
515
|
| `resetHard(rev)` | `reset --hard` |
|
|
433
516
|
| `clean({ directories })` | `clean -f`, or `-fd` — ignored files are kept |
|
|
434
517
|
| `deleteBranch(name, { force })` | `branch -d` / `-D` |
|
|
@@ -460,7 +543,7 @@ throws.
|
|
|
460
543
|
| Method | What |
|
|
461
544
|
| --- | --- |
|
|
462
545
|
| `raw(argv, opts)` | Run anything. Returns `CommandResult`; you read `exitCode`. |
|
|
463
|
-
| `rawChecked(argv, opts)` | Same, but throws `CommandFailed` on a non-zero exit. |
|
|
546
|
+
| `rawChecked(argv, opts)` | Same, but throws `CommandFailed` on a non-zero exit or on output cut short at a cap or a timeout. |
|
|
464
547
|
| `at(cwd)` | The same client rooted elsewhere, reusing the runner or backend. |
|
|
465
548
|
| `try.*` | The whole surface again, returning `GitOutcome<T>` instead of throwing. |
|
|
466
549
|
| `soft.*` | Every verb with an absence value, returning it instead of throwing. |
|
|
@@ -570,10 +653,12 @@ parseRepoRef("./a/local/path"); // null — the input names no repository
|
|
|
570
653
|
|
|
571
654
|
## Subpath exports
|
|
572
655
|
|
|
573
|
-
`@osdlc/typed-git/client` is everything above except
|
|
574
|
-
`gitSshUrl
|
|
575
|
-
|
|
576
|
-
|
|
656
|
+
`@osdlc/typed-git/client` is everything above except the URL parsers
|
|
657
|
+
(`parseGitUrl`, `gitSshUrl`, `parseRepoRef` and their types) and the checkout
|
|
658
|
+
walks (`checkoutRoot`, `discoverCheckouts`, `scanForCheckouts`, their types,
|
|
659
|
+
`DEFAULT_MAX_DEPTH` and `DEFAULT_WARN_AFTER`). It has no `hosted-git-info` on
|
|
660
|
+
your module graph. That package stays in `dependencies` either way — a bundle
|
|
661
|
+
saving, not an install one.
|
|
577
662
|
|
|
578
663
|
`@osdlc/typed-git/testing` builds throwaway repositories:
|
|
579
664
|
|
|
@@ -588,10 +673,16 @@ one.
|
|
|
588
673
|
genuine publish into an empty store.
|
|
589
674
|
|
|
590
675
|
`cleanup()` is manual. Nothing removes a fixture when the process exits, so
|
|
591
|
-
call it in a `finally` block or an `afterEach`.
|
|
676
|
+
call it in a `finally` block or an `afterEach`. The helpers have named option
|
|
677
|
+
and result types: `MakeOriginAndCheckoutOptions`, `OriginAndCheckout`,
|
|
678
|
+
`MakeBareAndWorkerOptions` and `BareAndWorker`.
|
|
592
679
|
|
|
593
680
|
All of them pin an identity and the commit dates through the environment, so a
|
|
594
|
-
suite that asserts on a sha gets the same sha every run.
|
|
681
|
+
suite that asserts on a sha gets the same sha every run. Only the identity
|
|
682
|
+
(and `commit.gpgsign=false` in the fixture repository) is isolated.
|
|
683
|
+
`core.hooksPath`, `commit.template`, `init.templateDir`, `core.autocrlf` and
|
|
684
|
+
other global or system git config still apply. To isolate them, set
|
|
685
|
+
`GIT_CONFIG_GLOBAL` and `GIT_CONFIG_NOSYSTEM` through `identity`. The identity is bound
|
|
595
686
|
as the fixture client's **client-level `env`**, so every call through
|
|
596
687
|
`fixture.git` carries it — the suite's own calls included, not just the ones
|
|
597
688
|
the fixture makes. `IDENTITY` is exported and frozen, so a suite asserting on
|
|
@@ -601,8 +692,9 @@ files, { date, env })` overrides them for one commit.
|
|
|
601
692
|
Pass `parent` to put two related repos under one directory (and `dir` to name
|
|
602
693
|
one exactly) — the way to have a suite delete a single tree at the end, or
|
|
603
694
|
assert on relative paths between two repositories. `cleanup()` removes the
|
|
604
|
-
`dir` you named. The one from `makeBareAndWorker` removes its whole `parent
|
|
605
|
-
|
|
695
|
+
`dir` you named. The one from `makeBareAndWorker` removes its whole `parent`,
|
|
696
|
+
including a `parent` you passed in. `makeOriginAndCheckout` removes only its
|
|
697
|
+
two repositories. Do not point either at anything you want to keep.
|
|
606
698
|
|
|
607
699
|
```ts
|
|
608
700
|
import { makeGitFixture } from "@osdlc/typed-git/testing";
|
|
@@ -655,14 +747,25 @@ de-duplicate.
|
|
|
655
747
|
- No call has a default timeout. Pass `timeoutMs` where a hung `git` would
|
|
656
748
|
hurt.
|
|
657
749
|
- `Git` kills a child that writes more than 256 MB to one stream and throws
|
|
658
|
-
`CommandFailed`. `AsyncGit` has no such cap.
|
|
750
|
+
`CommandFailed`. `AsyncGit` has no such cap. The `maxOutputBytes` call
|
|
751
|
+
option sets the cap for one call on either client. Output cut short at a
|
|
752
|
+
cap or a timeout is a failure, never an answer.
|
|
753
|
+
- stdout is text. There is no verb or call option that returns raw bytes,
|
|
754
|
+
such as a binary blob. Use command-seam's `spawnRunnerBytes` for that.
|
|
755
|
+
`raw` and `rawChecked` take `input` as a string, so binary stdin, such as
|
|
756
|
+
`hash-object --stdin` on a binary file, needs that runner too.
|
|
757
|
+
- Output is captured, never streamed. For live progress from `clone` or
|
|
758
|
+
`fetch`, run git through command-seam's `streamRunner`.
|
|
659
759
|
- `Git` cannot cancel a call. `AsyncGit` takes a `signal`.
|
|
660
760
|
- A `CommandFailed` carries `argv`, `result` and `detail`. Read `detail` for
|
|
661
761
|
the message, because git writes some failure text to stdout.
|
|
662
762
|
- `UnsupportedRequest` is not a `CommandFailed`, so `try` and `soft` let it
|
|
663
763
|
through.
|
|
764
|
+
- `merge`, `rebase` and `rebaseContinue` run with `LC_ALL=C`. Any other verb
|
|
765
|
+
that reads git's messages assumes English output, so a localized git can
|
|
766
|
+
change what it returns.
|
|
664
767
|
- Test fixtures need a manual `cleanup()`.
|
|
665
768
|
|
|
666
769
|
## License
|
|
667
770
|
|
|
668
|
-
MIT
|
|
771
|
+
`MIT OR Apache-2.0`, at your option.
|
package/async.ts
CHANGED
|
@@ -25,10 +25,12 @@ import { SOFT_TABLE } from './soft.ts'
|
|
|
25
25
|
import {
|
|
26
26
|
parseRefRows,
|
|
27
27
|
splitLines,
|
|
28
|
+
splitTrailingOptions,
|
|
28
29
|
type AddOptions,
|
|
29
30
|
type AheadBehind,
|
|
30
31
|
type CommitOptions,
|
|
31
32
|
type CheckoutOptions,
|
|
33
|
+
type ConfigGetOptions,
|
|
32
34
|
type CloneOptions,
|
|
33
35
|
type ConflictSide,
|
|
34
36
|
type MergeOptions,
|
|
@@ -37,6 +39,7 @@ import {
|
|
|
37
39
|
type MergeTreeOutcome,
|
|
38
40
|
type RebaseOptions,
|
|
39
41
|
type RebaseOutcome,
|
|
42
|
+
type RemoteGetUrlOptions,
|
|
40
43
|
type TaggedFile,
|
|
41
44
|
type UnmergedEntry,
|
|
42
45
|
type ConfigSetOptions,
|
|
@@ -44,6 +47,7 @@ import {
|
|
|
44
47
|
type DiffNameOnlyOptions,
|
|
45
48
|
type DiffStatOptions,
|
|
46
49
|
type DiffNameStatusOptions,
|
|
50
|
+
type DiffTextOptions,
|
|
47
51
|
type DiffTreeOptions,
|
|
48
52
|
type FetchOptions,
|
|
49
53
|
type ForEachRefOptions,
|
|
@@ -78,8 +82,11 @@ type DistributiveOmit<T, K extends PropertyKey> = T extends unknown ? Omit<T, K>
|
|
|
78
82
|
function splitCallOptions<T extends GitCallOptions>(
|
|
79
83
|
opts: T,
|
|
80
84
|
): [GitCallOptions, DistributiveOmit<T, keyof GitCallOptions>] {
|
|
81
|
-
const { timeoutMs, signal, env, ...rest } = opts
|
|
82
|
-
return [
|
|
85
|
+
const { timeoutMs, signal, env, maxOutputBytes, ...rest } = opts
|
|
86
|
+
return [
|
|
87
|
+
{ timeoutMs, signal, env, maxOutputBytes },
|
|
88
|
+
rest as DistributiveOmit<T, keyof GitCallOptions>,
|
|
89
|
+
]
|
|
83
90
|
}
|
|
84
91
|
|
|
85
92
|
/** A typed, awaitable git client bound to one working directory. */
|
|
@@ -151,8 +158,8 @@ export class AsyncGit {
|
|
|
151
158
|
|
|
152
159
|
/**
|
|
153
160
|
* Checked argv passthrough — rejects with `CommandFailed` on a non-zero
|
|
154
|
-
* exit
|
|
155
|
-
* {@link Git.rawChecked}.
|
|
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}.
|
|
156
163
|
*/
|
|
157
164
|
rawChecked(
|
|
158
165
|
argv: string[],
|
|
@@ -172,9 +179,13 @@ export class AsyncGit {
|
|
|
172
179
|
return this.backend.execute(this.cwd, { kind: 'showAtRev', rev, relPath }, opts)
|
|
173
180
|
}
|
|
174
181
|
|
|
175
|
-
/**
|
|
176
|
-
|
|
177
|
-
|
|
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)
|
|
178
189
|
}
|
|
179
190
|
|
|
180
191
|
/** The sha `ref` resolves to, or null. See {@link Git.resolveRef}. */
|
|
@@ -205,6 +216,14 @@ export class AsyncGit {
|
|
|
205
216
|
return this.backend.execute(this.cwd, { kind: 'gitCommonDir' }, opts)
|
|
206
217
|
}
|
|
207
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
|
+
|
|
208
227
|
/**
|
|
209
228
|
* What a symbolic ref points at (full refname), or null when it is not one.
|
|
210
229
|
* See {@link Git.symbolicRef}.
|
|
@@ -271,9 +290,25 @@ export class AsyncGit {
|
|
|
271
290
|
return this.backend.execute(this.cwd, { kind: 'logSubject', ref }, opts)
|
|
272
291
|
}
|
|
273
292
|
|
|
274
|
-
/** `git config --get <key>`, or null when unset. */
|
|
275
|
-
configGet(key: string, opts: GitCallOptions = {}): Promise<string | null> {
|
|
276
|
-
|
|
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)
|
|
277
312
|
}
|
|
278
313
|
|
|
279
314
|
/** True iff `rev` resolves to an object. */
|
|
@@ -326,19 +361,25 @@ export class AsyncGit {
|
|
|
326
361
|
return this.backend.execute(this.cwd, { kind: 'lsFilesTagged' }, opts)
|
|
327
362
|
}
|
|
328
363
|
|
|
329
|
-
/**
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
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
|
+
)
|
|
337
375
|
}
|
|
338
376
|
|
|
339
|
-
/**
|
|
340
|
-
|
|
341
|
-
|
|
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)
|
|
342
383
|
}
|
|
343
384
|
|
|
344
385
|
/** `for-each-ref` rows, one line each, in the caller's format. */
|
|
@@ -441,13 +482,44 @@ export class AsyncGit {
|
|
|
441
482
|
}
|
|
442
483
|
|
|
443
484
|
/** Configured remote names (`git remote`); `[]` when there are none. */
|
|
444
|
-
|
|
485
|
+
remotes(opts: GitCallOptions = {}): Promise<string[]> {
|
|
445
486
|
return this.backend.execute(this.cwd, { kind: 'remote' }, opts)
|
|
446
487
|
}
|
|
447
488
|
|
|
448
|
-
/**
|
|
449
|
-
|
|
450
|
-
|
|
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)
|
|
451
523
|
}
|
|
452
524
|
|
|
453
525
|
/** The coordinate a remote's URL names, or null. See {@link Git.remoteOwnerRepo}. */
|
|
@@ -514,11 +586,9 @@ export class AsyncGit {
|
|
|
514
586
|
}
|
|
515
587
|
|
|
516
588
|
/**
|
|
517
|
-
* Push a refspec.
|
|
518
|
-
*
|
|
519
|
-
*
|
|
520
|
-
* remote-tracking ref, which a fetch in this same process may have just
|
|
521
|
-
* updated.
|
|
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}.
|
|
522
592
|
*/
|
|
523
593
|
push(
|
|
524
594
|
remote: string,
|
|
@@ -551,7 +621,10 @@ export class AsyncGit {
|
|
|
551
621
|
return this.backend.execute(this.cwd, { kind: 'deleteBranch', name, force: opts.force }, opts)
|
|
552
622
|
}
|
|
553
623
|
|
|
554
|
-
/**
|
|
624
|
+
/**
|
|
625
|
+
* Remove config section `name`; false when it was absent. See
|
|
626
|
+
* `configRemoveSection` in `verbs.ts`.
|
|
627
|
+
*/
|
|
555
628
|
configRemoveSection(name: string, opts: GitCallOptions = {}): Promise<boolean> {
|
|
556
629
|
return this.backend.execute(this.cwd, { kind: 'configRemoveSection', name }, opts)
|
|
557
630
|
}
|
|
@@ -663,8 +736,12 @@ export class AsyncGit {
|
|
|
663
736
|
return this.backend.execute(this.cwd, { kind: 'lsFilesUnmerged' }, opts)
|
|
664
737
|
}
|
|
665
738
|
|
|
666
|
-
/**
|
|
739
|
+
/**
|
|
740
|
+
* Resolve conflicted `paths` to one side wholesale. An empty list resolves
|
|
741
|
+
* without calling the backend. See {@link Git.checkoutSide}.
|
|
742
|
+
*/
|
|
667
743
|
checkoutSide(side: ConflictSide, paths: string[], opts: GitCallOptions = {}): Promise<void> {
|
|
744
|
+
if (paths.length === 0) return Promise.resolve()
|
|
668
745
|
return this.backend.execute(this.cwd, { kind: 'checkoutSide', side, paths }, opts)
|
|
669
746
|
}
|
|
670
747
|
|