@osdlc/typed-git 0.10.0 → 0.12.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,42 @@
1
1
  # @osdlc/typed-git
2
2
 
3
+ ## 0.12.0
4
+
5
+ ### Minor Changes
6
+
7
+ - e0aaba5: **Breaking:** `push` and `pushPorcelain` are now one verb. `push(remote, refspec | refspecs, { atomic, delete, forceWithLease })` runs `git push --porcelain` and returns the `PushReport` that `pushPorcelain` returned, with one result per ref. A rejected ref no longer throws: check each ref's `flag`, or `report.refs.some((r) => r.flag === '!')`. A failure that reaches no ref still throws, as before. `pushPorcelain` and `PushPorcelainOptions` are removed; rename the call to `push`.
8
+
9
+ New `PUSH_REJECTIONS`: for every `PushRejection`, a one-line `message`, an `explanation`, a `hint` and a `docs` link into git's manual. The README's new "Rejection reference" section has the same text.
10
+
11
+ New rejection `atomic-failed` for the other refs of a failed `--atomic` push (`atomic push failed`, `atomic transaction failed`), which were `other`.
12
+
13
+ The push tests now also replay output recorded from git 2.47.3 and 2.56.0, before and after git 2.51 reworded the remote's reasons. `tests/fixtures/push/record-push.mjs` records a new version.
14
+
15
+ ## 0.11.1
16
+
17
+ ### Patch Changes
18
+
19
+ - 7fe7f51: `parseRemoteRepo` reads `ssh.github.com` (GitHub's SSH over port 443) and `www.github.com` as `github.com`, so a remote on either names the same repository as one on `github.com`.
20
+
21
+ ## 0.11.0
22
+
23
+ ### Minor Changes
24
+
25
+ - 82d9841: Add `cherry(upstream, head?)` and `commitTree(tree, { parents, message })` to `Git` and `AsyncGit`.
26
+
27
+ - `cherry` runs `git cherry` and returns `{ sha, equivalent }` per commit on `head` that `upstream` lacks. Output it cannot read throws instead of being skipped. `soft.cherry` falls back to `[]`.
28
+ - `commitTree` runs `git commit-tree` and returns the new commit's sha. It writes an object and no ref, and needs a git identity. A reply that is not a sha throws.
29
+ - Both refuse a leading-dash revision before spawning, like the other revision-taking verbs.
30
+ - ebe0e0d: typed-git knows which git it runs, and which features need a newer one. The supported floor is git 2.34 (Ubuntu 22.04 LTS). One table, `GIT_FEATURES`, lists the features newer than that: `merge-tree --write-tree` (git 2.38), `merge-tree --merge-base` (2.40) and `worktree list -z` (2.36). The README's new "Git versions" section is checked against it.
31
+
32
+ - A verb that uses one of these features runs `git --version` first and caches it per runner and per effective `PATH`. Other verbs never run it. The probe runs in the OS temp directory, and a failed probe names the verb that asked (`git worktree: …`) and is not cached. Concurrent `AsyncGit` callers share one probe, which runs with no caller's signal and a fixed 15 s limit; each caller waits under its own `timeoutMs` and `signal`. The first gated call can take up to the probe's time plus its own `timeoutMs`. `git.version()` and `await asyncGit.version()` return the parsed version, `{ major, minor, patch, text }`, for plain, Apple (`2.39.3 (Apple Git-146)`), Windows (`2.45.1.windows.1`) and rc builds.
33
+ - **Breaking:** new `GitFailureKind` `unsupported-git`. On a git older than the feature, `mergeTree` fails with it before git runs ("merge-tree --write-tree needs git 2.38 or later; found 2.34.1."), where it failed as a generic `exit` with git's usage error. On a git older than 2.34, `worktrees()` and `mergeTree()` now fail as `unsupported-git` with the feature `typed-git`. `worktrees()` worked there before; a caller that used `git.soft.worktrees()` now gets `[]` on such a git, so do not read that `[]` as "no worktrees" where it matters. The failure carries `unsupported: { feature, needs, have }`. An exhaustive `switch` over `GitFailureKind` needs the new case. `git.try` returns it and `git.soft` falls back on it, like any other failure.
34
+ - **Breaking:** `GitFailure.cause` is now optional (`CommandFailed | undefined`), as in `@osdlc/typed-gh`. It is absent only for `unsupported-git`, where git did not run. Read `error.cause?.result`.
35
+ - `worktrees()` runs `worktree list --porcelain -z` on git 2.36 or later (#381). A path holding a newline parses, and `lockReason` is the reason as written, where it came back C-quoted. Older git runs the newline form as before.
36
+ - **Breaking for fake runners:** a `CommandRunner` behind `worktrees()` or `mergeTree()` is now also asked for `["--version"]`. To migrate, pin the version with the new `gitVersion` option: `new Git(cwd, { runner, gitVersion: '2.55.0' })` or `cliBackend({ runner, gitVersion: '2.55.0' })`. Gated verbs then use it and never run `git --version`, `version()` returns it, and `at()` keeps it. It takes `'2.55.0'` or a whole `git version …` line, and throws a `RangeError` at construction for anything else. A fake without the pin must answer `--version` with `git version <x.y.z>`; output that is not a version line fails as `exit`.
37
+ - `cliBackend` does the version check. A backend other than the CLI gets every request unchecked, and answers the new `version` request kind itself (`partialBackend` rejects it with `UnsupportedRequest` when it is not implemented).
38
+ - New exports: `GIT_FEATURES`, `GIT_FLOOR`, `gitSupports`, `parseGitVersion`, `compareGitVersions`, and the types `GitVersion`, `GitFeature`, `GitFeatureSpec`, `GitRelease` and `UnsupportedGit`.
39
+
3
40
  ## 0.10.0
4
41
 
5
42
  ### Minor Changes
package/README.md CHANGED
@@ -29,16 +29,74 @@ Node.js, on macOS, Linux and Windows. CI runs the tests and the built package
29
29
  on Linux and macOS, on Node 22 and 24. Windows is supported but not tested in
30
30
  CI yet.
31
31
 
32
- The minimum git version is the oldest one CI tests. CI uses the git that the
33
- GitHub-hosted runners ship. On 2026-10-20 that was git 2.55.0 on
34
- `ubuntu-latest` (Ubuntu 24.04) and git 2.56.0 on `macos-latest` (macOS 26), as
35
- the checkout step logs it. So the tested minimum is git 2.55.0. Older git may
36
- work, but no test shows it. The behaviour tables below were measured against
37
- git 2.50.1. A verb that needs a newer git than you have fails with git's own
38
- error and throws the classified failure. `mergeTree` needs git 2.38 or later.
32
+ It needs git 2.34 or later, the git of Ubuntu 22.04 LTS. See [Git versions](#git-versions).
39
33
 
40
34
  The tests run on Vitest under Node. Bun is not a tested runtime for consumers.
41
35
 
36
+ ## Git versions
37
+
38
+ The supported floor is git 2.34, the git of Ubuntu 22.04 LTS. CI tests the
39
+ git that the GitHub-hosted runners ship. On 2026-10-20 that was git 2.55.0 on
40
+ `ubuntu-latest` (Ubuntu 24.04) and git 2.56.0 on `macos-latest` (macOS 26), as
41
+ the checkout step logs it. An `old git` job also runs this package's tests,
42
+ and pr-update's and trust-repo's, on git 2.34 on Ubuntu 22.04, so the floor
43
+ and the fallbacks below run against a real git. The behaviour tables below
44
+ were measured against git 2.50.1.
45
+
46
+ Every flag typed-git passes unconditionally is in git 2.34. A few features are
47
+ newer, and one table (`GIT_FEATURES`, in `src/features.ts`) lists them:
48
+
49
+ | Feature | Needs git | Used by | On an older git |
50
+ | --- | --- | --- | --- |
51
+ | `merge-tree --write-tree` | 2.38 | `mergeTree` | throws `unsupported-git` |
52
+ | `merge-tree --merge-base` | 2.40 | `mergeTree({ mergeBase })` | throws `unsupported-git` |
53
+ | `worktree list -z` | 2.36 | `worktrees` | newline-split `worktree list --porcelain`: a path with a newline breaks it, and a lock reason comes back C-quoted |
54
+
55
+ A verb that uses one of these runs `git --version` first, once per runner,
56
+ and caches the answer. A client that never calls such a verb never runs it.
57
+ `git.version()` (and `await asyncGit.version()`) returns the same parsed
58
+ version: `{ major, minor, patch, text }`, where `text` keeps a vendor suffix
59
+ such as `2.39.3 (Apple Git-146)` or `2.45.1.windows.1`.
60
+
61
+ The answer is cached per runner and per effective `PATH` (the call's `env`
62
+ over the client's over the process's; `PATHEXT` too on Windows), because the
63
+ default runner runs whichever `git` that `PATH` finds. The probe runs in the
64
+ OS temp directory, so a missing cwd cannot fail it; the verb itself still
65
+ runs in its own cwd. A failed probe is not cached, and its failure names the
66
+ verb that asked (`git worktree: …`), not `--version`.
67
+
68
+ `AsyncGit` callers that probe at the same time share one probe. It runs with
69
+ no caller's `signal` and a fixed 15 s limit. Each caller waits under its own
70
+ `timeoutMs` and `signal`, so one that gives up rejects alone. The sync client
71
+ probes under the call's `timeoutMs` (15 s at most). Either way the first gated
72
+ call can take up to the probe's time plus its own `timeoutMs`.
73
+
74
+ The `gitVersion` option pins the version instead: `new Git(cwd, { runner,
75
+ gitVersion: "2.55.0" })`, or `cliBackend({ runner, gitVersion: "2.55.0" })`.
76
+ It takes a version string, either `"2.55.0"` or a whole
77
+ `"git version 2.39.3 (Apple Git-146)"` line. Gated verbs then use it and
78
+ never run `git --version`, `version()` returns it, and `at()` keeps it. An
79
+ unparsable value throws a `RangeError` when the client or backend is built.
80
+ It is the way to put a fake runner behind a gated verb, and to test either
81
+ side of a feature.
82
+
83
+ On a git older than a feature, a verb with a fallback runs it, and one
84
+ without fails as `unsupported-git` before git runs:
85
+
86
+ ```ts
87
+ const r = git.try.mergeTree("main", "topic");
88
+ if (!r.ok && r.error.kind === "unsupported-git") {
89
+ // r.error.message: "merge-tree --write-tree needs git 2.38 or later; found 2.34.1."
90
+ // r.error.unsupported: { feature, needs, have }
91
+ }
92
+ ```
93
+
94
+ Below 2.34 every one of these verbs fails that way, with the feature
95
+ `typed-git`, and no fallback is tried. Verbs that need no newer feature run
96
+ on any git without a version check. A backend other than `cliBackend` has no
97
+ git version, so `AsyncGit` checks nothing for it; it answers or rejects each
98
+ request itself.
99
+
42
100
  ## Stability
43
101
 
44
102
  The package is on the 0.x line. A breaking change ships only in a new minor
@@ -141,7 +199,8 @@ use(r.value);
141
199
  The error is a `GitFailure`: a `Failure` from `@osdlc/result` with a `kind` to
142
200
  branch on, a one-line `message` and a `hint` for a person (`describe(error)`
143
201
  joins them), git's own output in `detail`, the `argv` and `exitCode`, and the
144
- `CommandFailed` it was read from in `cause`.
202
+ `CommandFailed` it was read from in `cause`. An `unsupported-git` failure has
203
+ no `cause`, because git did not run; it carries `unsupported` instead.
145
204
 
146
205
  The methods that throw (`git.push()` and the rest) throw the same failure,
147
206
  wrapped in a `FailureError` (`error.failure`). So a CLI that reports a thrown
@@ -161,6 +220,7 @@ line for a failure from `git.try.*`.
161
220
  | `not-authenticated` | `Authentication failed`, `Permission denied (publickey)`, `could not read Username`, `unable to access` with HTTP 401 or 403 | `The remote refused the credentials.` / `Check that you are signed in to the host, or that your SSH key is added.` |
162
221
  | `not-found` | `unable to access` with HTTP 404 | `The remote repository was not found, or you cannot see it.` / `Check the remote URL, and that your account can see the repository.` |
163
222
  | `tls` | `unable to access` with `SSL certificate problem` | `The remote's TLS certificate could not be verified.` / `Check the system clock and CA certificates, or the remote's certificate.` |
223
+ | `unsupported-git` | the local git is older than the verb needs (see [Git versions](#git-versions)); git did not run, so there is no `cause` | `merge-tree --write-tree needs git 2.38 or later; found 2.34.1.` / `Upgrade git to 2.38 or later from https://git-scm.com.` |
164
224
  | `not-executable`, `bad-cwd`, `timeout`, `output-cap`, `signal`, `aborted`, `spawn` | as in `@osdlc/command-seam` | command-seam's message, no hint |
165
225
  | `exit` | any other non-zero exit | git's first stderr line |
166
226
 
@@ -350,7 +410,7 @@ For the paths alone, `diffNameOnly({ diffFilter: "U" })` is cheaper.
350
410
 
351
411
  `merge`, `rebase` and `rebaseContinue` run with `LC_ALL=C`, over the client,
352
412
  backend and call `env`, so `fastForward`, `alreadyUpToDate` and `conflicts` do
353
- not change with the caller's locale. `pushPorcelain` does the same for its
413
+ not change with the caller's locale. `push` does the same for its
354
414
  reasons. Other verbs keep the caller's locale.
355
415
 
356
416
  One trap in `checkoutSide`: on a path that is not conflicted, git exits 0 and
@@ -385,12 +445,11 @@ nothing depends on where `HEAD` happens to be.
385
445
 
386
446
  ## Pushing: a rejected ref is a value
387
447
 
388
- `push` throws when git exits non-zero. `pushPorcelain` runs
389
- `git push --porcelain` and returns one result per ref, so a lease that lost a
390
- race is an answer you can branch on, not stderr you grep:
448
+ `push` runs `git push --porcelain` and returns one result per ref, so a
449
+ lease that lost a race is an answer you can branch on, not stderr you grep:
391
450
 
392
451
  ```ts
393
- const report = git.pushPorcelain("origin", `${next}:refs/heads/lease`, {
452
+ const report = git.push("origin", `${next}:refs/heads/lease`, {
394
453
  forceWithLease: { ref: "refs/heads/lease", expect: seen },
395
454
  });
396
455
  const ref = report.refs[0];
@@ -401,14 +460,18 @@ if (ref.flag === "!") {
401
460
  case "lock-failed": // another writer moved or deleted it at the remote
402
461
  case "already-exists": // a create lost to another writer
403
462
  return retry();
404
- default: // tag-exists, ref-conflict, hook-declined, non-fast-forward, other
405
- throw new Error(`${ref.dst}: ${ref.rawReason} ${ref.detail ?? ""}`);
463
+ default: {
464
+ const info = PUSH_REJECTIONS[ref.rejection];
465
+ throw new Error(`${ref.dst}: ${info.message} ${info.hint} See ${info.docs}`);
466
+ }
406
467
  }
407
468
  }
408
469
  ```
409
470
 
410
- It takes a refspec or a list, and `{ atomic, forceWithLease }`, where
411
- `forceWithLease` also takes one lease per ref. `flag` is git's status
471
+ A rejected ref does not throw, so a caller that ignores the report misses it:
472
+ check `flag`, or `report.refs.some((r) => r.flag === "!")`. It takes a refspec
473
+ or a list, and `{ atomic, delete, forceWithLease }`, where `forceWithLease`
474
+ also takes one lease per ref. `flag` is git's status
412
475
  character: `' '` fast-forward, `'+'` forced, `'-'` deleted, `'*'` new, `'!'`
413
476
  rejected, `'='` up to date. A failure that reaches no ref still throws the
414
477
  classified failure: an unknown remote, auth, network, TLS, a refspec that
@@ -429,7 +492,7 @@ wording has changed across versions:
429
492
  | `<ref>` beside an existing `<ref>/child` | `(refname conflict)` | `(failed to update ref)` + `'<ref>/child' exists; cannot create '<ref>'` | `ref-conflict` |
430
493
  | a remote hook refused it | `(pre-receive hook declined)`, `(hook declined)` | same | `hook-declined` |
431
494
  | a `.lock` file in the way, an unwritable refs directory | `(reference already exists)`, `(failed to update refs)` + `Unable to create '….lock'` | `(failed to update ref)` + the same | `other` |
432
- | the other refs of a failed `--atomic` push | `[rejected] (atomic push failed)`, `[remote rejected] (atomic transaction failed)` | same | `other` |
495
+ | the other refs of a failed `--atomic` push | `[rejected] (atomic push failed)`, `[remote rejected] (atomic transaction failed)` | same | `atomic-failed` |
433
496
 
434
497
  The "+ …" text is the remote's `cannot lock ref '<ref>': …` line. git prints
435
498
  it on stderr, not on the ref line, and `detail` carries it for the ref it
@@ -443,6 +506,68 @@ remote prints the detail, and that reads as `other`.
443
506
  This table is the one list of wordings. `tests/push.test.ts` covers each
444
507
  row, against real git or as a canned row in `CANNED`.
445
508
 
509
+ `tests/push-fixtures.test.ts` replays output recorded from real git, one file
510
+ per version under `tests/fixtures/push/`: today git 2.47.3, from before the
511
+ 2.51 rewording, and git 2.56.0. Every file must read the same way. To add a
512
+ version, run `node tests/fixtures/push/record-push.mjs` with that git on
513
+ `PATH`; a new wording fails the test until `pushRejection` in `src/verbs.ts`
514
+ maps it, and this table gains the row.
515
+
516
+ ### Rejection reference
517
+
518
+ `PUSH_REJECTIONS[rejection]` holds, for every value, a one-line `message`, an
519
+ `explanation`, a `hint` and a `docs` link into git's own manual. Each one in
520
+ brief, with the same link:
521
+
522
+ **`stale`**: the remote ref is not where the lease expected it. With
523
+ `--force-with-lease`, git compares the remote ref with the expected value
524
+ before sending anything; they differed, so someone pushed since you looked.
525
+ A create-only lease (`expect: null`) fails this way when the ref exists.
526
+ Fetch, look at what changed, and push again with the new expected value.
527
+ [git-push: --force-with-lease](https://git-scm.com/docs/git-push#Documentation/git-push.txt---force-with-lease)
528
+
529
+ **`non-fast-forward`**: the push would discard commits on the remote, and was
530
+ not forced. `fetch first` means this git does not have the remote commits at
531
+ all; `needs force` that one side is not a commit. Fetch and integrate, or
532
+ force with a pinned lease.
533
+ [git-push: note about fast-forwards](https://git-scm.com/docs/git-push#_note_about_fast_forwards)
534
+
535
+ **`tag-exists`**: the tag is already on the remote, and git does not move a
536
+ tag unless forced. A retry fails the same way. Push a new tag name, or force
537
+ the push if replacing the tag is intended.
538
+ [git-push: push rules](https://git-scm.com/docs/git-push#_push_rules)
539
+
540
+ **`already-exists`**: another push created the ref first: the remote found it
541
+ already there when it locked it. Fetch, look at what the other push created,
542
+ and decide whether to push again.
543
+ [git-push: --force-with-lease](https://git-scm.com/docs/git-push#Documentation/git-push.txt---force-with-lease)
544
+
545
+ **`ref-conflict`**: ref names are paths, so `refs/heads/x` and
546
+ `refs/heads/x/child` cannot both exist. Nothing raced. Pick a name that is
547
+ not a prefix or an extension of an existing ref, or delete the other ref.
548
+ git's manual has no page on this clash, so the link is to the output format.
549
+ [git-push: output](https://git-scm.com/docs/git-push#_output)
550
+
551
+ **`lock-failed`**: the lease check passed, but when the remote locked the ref
552
+ it no longer held the expected value, or no longer existed: another push won
553
+ a race at the remote. Treat it like a stale lease.
554
+ [git-push: --force-with-lease](https://git-scm.com/docs/git-push#Documentation/git-push.txt---force-with-lease)
555
+
556
+ **`hook-declined`**: a `pre-receive` hook refused the whole push, or an
557
+ `update` hook this ref. GitHub reports branch protection as `protected branch
558
+ hook declined`. The hook's own message is in the `remote:` lines on stderr.
559
+ [githooks: pre-receive](https://git-scm.com/docs/githooks#pre-receive)
560
+
561
+ **`atomic-failed`**: with `--atomic` the remote updates every ref or none.
562
+ This ref was fine on its own; another ref in the report carries the cause.
563
+ [git-push: --atomic](https://git-scm.com/docs/git-push#Documentation/git-push.txt---atomic)
564
+
565
+ **`other`**: a reason this library does not classify, kept verbatim in
566
+ `rawReason` and `detail`: a stale lock file or an unwritable refs directory
567
+ on the remote, or settings such as `receive.denyCurrentBranch` and
568
+ `receive.denyDeletes`.
569
+ [git-push: output](https://git-scm.com/docs/git-push#_output)
570
+
446
571
  ## `log` hands back bytes
447
572
 
448
573
  ```ts
@@ -541,6 +666,7 @@ exit throws the classified failure.
541
666
  | `resolveRef(ref)` | `rev-parse --verify --quiet <ref>` | `1` → `null` |
542
667
  | `hasHistory()` | `resolveRef("HEAD") !== null` | — |
543
668
  | `headRef()` | `rev-parse --abbrev-ref HEAD` | none — literal `"HEAD"` when detached |
669
+ | `version()` | `--version`, once per runner | none — `{ major, minor, patch, text }`; see [Git versions](#git-versions) |
544
670
  | `topLevel()` | `rev-parse --show-toplevel` | `128` → `null` (not a repository) |
545
671
  | `gitCommonDir()` | `rev-parse --path-format=absolute --git-common-dir` | `128` → `null` |
546
672
  | `gitDir()` | `rev-parse --absolute-git-dir` | `128` → `null` — this worktree's own dir, `<common>/worktrees/<name>` in a linked worktree |
@@ -553,7 +679,7 @@ exit throws the classified failure.
553
679
  | `hasStagedChanges()` | `diff --cached --quiet` | `1` → `true`, `0` → `false` — on an unborn HEAD the index is compared against the empty tree; outside a repository (`129`) it throws |
554
680
  | `branches(pattern)` | `branch --list --format=%(refname:lstrip=2)` | none |
555
681
  | `branchExists(name)` | `branches(name).includes(name)` | none |
556
- | `worktrees()` | `worktree list --porcelain` | none — rows carry `locked` and `lockReason` |
682
+ | `worktrees()` | `worktree list --porcelain -z` (git 2.36; the newline form before) | none — rows carry `locked` and `lockReason` |
557
683
  | `mergeBase(a, b)` | `merge-base <a> <b>` | `1` → `null` (unrelated histories) |
558
684
  | `logSubject(ref)` | `log -1 --format=%s <ref>` | `128` → `null` |
559
685
  | `configGet(key, { scope })` | `config [--local\|--global\|--system] --get <key>` | `1` → `null` (unset) |
@@ -581,6 +707,8 @@ exit throws the classified failure.
581
707
  | `grep(pattern, { extendedRegexp, lineNumber, noColor, paths })` | `grep` | `1` → `[]` (no match) |
582
708
  | `isAncestor(a, b)` | `merge-base --is-ancestor` | `1` → `false` |
583
709
  | `aheadBehind(base, tip)` | `rev-list --left-right --count <base>...<tip>` | none |
710
+ | `cherry(upstream, head)` | `cherry <upstream> [<head>]` | none — `{ sha, equivalent }` per commit; empty output is `[]`, an unreadable line throws |
711
+ | `commitTree(tree, { parents, message })` | `commit-tree <tree> [-p <parent>]... -m <message>` | none — writes an object and no ref; needs a git identity |
584
712
  | `remotes()` | `remote` | none — names, not remotes |
585
713
  | `remote()` | `remote` | none — deprecated alias of `remotes()` |
586
714
  | `remoteGetUrl(name, { push })` | `remote get-url [--push] <name>` | `2` → `null` (unknown remote) — the first URL |
@@ -597,7 +725,7 @@ empty repository from a dangling HEAD or a missing object store. Use
597
725
  Every mutation except `configRemoveSection` declares no absence: a non-zero
598
726
  exit throws the classified failure, because the only sane handling of "the write did
599
727
  not happen" is to surface it. `configRemoveSection` declares 128 absent and
600
- returns `false` when there is no such section. `pushPorcelain`, listed under
728
+ returns `false` when there is no such section. `push`, listed under
601
729
  Integration, declares exit 1 absent and returns the rejected refs.
602
730
 
603
731
  | Method | git |
@@ -605,7 +733,6 @@ Integration, declares exit 1 absent and returns the rejected refs.
605
733
  | `fetch(remote, refspec, { prune, quiet, noWriteFetchHead, depth, noTags })` | `fetch` |
606
734
  | `add(paths, { all, update, intentToAdd })` | `add` (paths go after `--`) |
607
735
  | `commit({ message, body } \| { messageFile } \| { messageStdin }, plus { allowEmpty, amend, noVerify, signoff, paths } in the same object)` | `commit` — one argument, e.g. `commit({ message, allowEmpty: true })`; one message source, enforced by the types; `messageStdin` is `-F -` with the string on stdin, no temp file. `paths` appends `-- <paths…>`: only those paths are committed, from the working tree, and anything else staged stays staged. An empty `paths` throws a `TypeError`, because git would commit everything staged |
608
- | `push(remote, refspec, { forceWithLease, delete })` | `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. `delete` is `--delete`, and a pinned lease deletes only while the remote ref holds `expect`. To learn why a push was rejected, use `pushPorcelain` |
609
736
  | `configSet(key, value, { scope })` | `config` |
610
737
  | `configRemoveSection(name)` | `config --remove-section` — `false` when there is no such section |
611
738
  | `init(path, { bare, initialBranch, quiet })` | `init` |
@@ -639,7 +766,7 @@ other non-zero exit throws.
639
766
  | `rebaseContinue()` | `-c core.editor=true rebase --continue` | `RebaseOutcome` |
640
767
  | `mergeTree(ours, theirs, { mergeBase })` | `merge-tree --write-tree --name-only -z` | `MergeTreeOutcome` |
641
768
  | `lsFilesUnmerged()` | `ls-files -u -z` | `UnmergedEntry[]` — mode, sha, stage, path |
642
- | `pushPorcelain(remote, refspec \| refspecs, { atomic, forceWithLease })` | `push --porcelain` | `PushReport` — `{ refs, stderr }`, one `PushRefResult` per ref; a `'!'` ref also has `rejection` and `detail`; exit 1 without a rejected ref throws |
769
+ | `push(remote, refspec \| refspecs, { atomic, delete, forceWithLease })` | `push --porcelain` | `PushReport` — `{ refs, stderr }`, one `PushRefResult` per ref; a `'!'` ref also has `rejection` and `detail`, explained in `PUSH_REJECTIONS`; exit 1 without a rejected ref throws. `forceWithLease` takes `true`, a pinned `{ ref, expect }` (`expect: null` = ref must be absent) or one per ref; `forceWithLeaseArg(lease)` is the pure formatter. `true` is the bare form: it overwrites whatever is on the remote, so prefer the pinned form. `delete` is `--delete`, and a pinned lease deletes only while the remote ref holds `expect` |
643
770
 
644
771
  ### Escape hatches and re-rooting
645
772
 
@@ -713,6 +840,18 @@ The default runner finds `git` on absolute `PATH` entries only, so a file named
713
840
  `git` in the checkout cannot run in its place. A real runner you build yourself
714
841
  should do the same: `spawnRunner("git", { absolutePathOnly: true })`.
715
842
 
843
+ A fake runner behind a version-gated verb (`worktrees`, `mergeTree`; see
844
+ [Git versions](#git-versions)) would also be asked for `git --version`. Pin
845
+ the version so it is not:
846
+
847
+ ```ts
848
+ const git = new Git("/nowhere", { runner: recording, gitVersion: "2.55.0" });
849
+ git.worktrees(); // runs `worktree list --porcelain -z`, and no `--version`
850
+ ```
851
+
852
+ A fake without the pin must answer `["--version"]` (once per runner) with
853
+ `git version <x.y.z>`, or the gated verb fails as `exit`.
854
+
716
855
  `runner: undefined` is the same as omitting it, so a caller holding an optional
717
856
  runner passes it straight through, without a conditional spread. `cliBackend`
718
857
  accepts it too.
@@ -749,7 +888,9 @@ Use it for a remote read from a checkout (any host); use `parseGitUrl` /
749
888
  host and any other alike. It tries `parseGitUrl` first, so shorthand reads as
750
889
  GitHub and a GitLab nested group stays whole in `owner`, then falls back to
751
890
  `parseRemoteUrl`, so a GitHub Enterprise or self-hosted Forgejo remote
752
- answers too. `host` is lower-cased and carries no port. Decide which forge a
891
+ answers too. `host` is lower-cased and carries no port, and GitHub's other
892
+ names for itself (`ssh.github.com`, its SSH over port 443, and
893
+ `www.github.com`) read as `github.com`. Decide which forge a
753
894
  remote is on from `host`, not from the URL text.
754
895
 
755
896
  ```ts
@@ -757,6 +898,8 @@ parseRemoteRepo("git@github.com:acme/widgets.git");
757
898
  // { host: "github.com", owner: "acme", repo: "widgets" }
758
899
  parseRemoteRepo("https://forge.example.com:3000/team/app.git");
759
900
  // { host: "forge.example.com", owner: "team", repo: "app" }
901
+ parseRemoteRepo("ssh://git@ssh.github.com:443/acme/widgets.git");
902
+ // { host: "github.com", owner: "acme", repo: "widgets" }
760
903
  parseRemoteRepo("/srv/git/repo.git"); // null — a local path names no project
761
904
  ```
762
905
 
@@ -888,7 +1031,7 @@ de-duplicate.
888
1031
  `CommandFailed`, with the raw `result`.
889
1032
  - `UnsupportedRequest` is not a git failure, so `try` and `soft` let it
890
1033
  through.
891
- - `merge`, `rebase`, `rebaseContinue` and `pushPorcelain` run with `LC_ALL=C`. Any other verb
1034
+ - `merge`, `rebase`, `rebaseContinue` and `push` run with `LC_ALL=C`. Any other verb
892
1035
  that reads git's messages assumes English output, so a localized git can
893
1036
  change what it returns.
894
1037
  - Test fixtures need a manual `cleanup()`.
package/dist/async.d.ts CHANGED
@@ -14,9 +14,10 @@
14
14
  */
15
15
  import type { CommandResult } from '@osdlc/command-seam';
16
16
  import { type GitBackend, type GitCallOptions } from './backend.ts';
17
+ import type { GitVersion } from './git-version.ts';
17
18
  import { type Soft, type TriedAsync } from './outcome.ts';
18
19
  import { type RemoteCoordinate } from './remote-url.ts';
19
- import { type AddOptions, type AheadBehind, type CommitOptions, type CheckoutOptions, type ConfigGetOptions, type CloneOptions, type ConflictSide, type MergeOptions, type MergeOutcome, type MergeTreeOptions, type MergeTreeOutcome, type RebaseOptions, type RebaseOutcome, type RemoteGetUrlOptions, type TaggedFile, type UnmergedEntry, type ConfigSetOptions, type DiffEntry, type DiffNameOnlyOptions, type DiffStatOptions, type DiffNameStatusOptions, type DiffTextOptions, type DiffTreeOptions, type FetchOptions, type ForEachRefOptions, type GrepOptions, type InitOptions, type LogOptions, type IgnoreMatch, type LsFilesOptions, type LsRemoteOptions, type LsTreeOptions, type NumstatEntry, type PushPorcelainOptions, type PushReport, type RemoteRef, type CleanOptions, type DiffCheckOptions, type DiffCheckResult, type StatusEntry, type StatusPorcelainOptions, type TreeEntry, type Worktree, type WorktreeAddOptions, type WorktreeMoveOptions, type GcOptions, type PushOptions, type RemoteSetBranchesOptions, type RemoteSetHeadOptions } from './verbs.ts';
20
+ import { type AddOptions, type AheadBehind, type CherryEntry, type CommitTreeOptions, type CommitOptions, type CheckoutOptions, type ConfigGetOptions, type CloneOptions, type ConflictSide, type MergeOptions, type MergeOutcome, type MergeTreeOptions, type MergeTreeOutcome, type RebaseOptions, type RebaseOutcome, type RemoteGetUrlOptions, type TaggedFile, type UnmergedEntry, type ConfigSetOptions, type DiffEntry, type DiffNameOnlyOptions, type DiffStatOptions, type DiffNameStatusOptions, type DiffTextOptions, type DiffTreeOptions, type FetchOptions, type ForEachRefOptions, type GrepOptions, type InitOptions, type LogOptions, type IgnoreMatch, type LsFilesOptions, type LsRemoteOptions, type LsTreeOptions, type NumstatEntry, type PushReport, type RemoteRef, type CleanOptions, type DiffCheckOptions, type DiffCheckResult, type StatusEntry, type StatusPorcelainOptions, type TreeEntry, type Worktree, type WorktreeAddOptions, type WorktreeMoveOptions, type GcOptions, type PushOptions, type RemoteSetBranchesOptions, type RemoteSetHeadOptions } from './verbs.ts';
20
21
  /** A typed, awaitable git client bound to one working directory. */
21
22
  export declare class AsyncGit {
22
23
  readonly cwd: string;
@@ -74,6 +75,14 @@ export declare class AsyncGit {
74
75
  rawChecked(argv: string[], opts?: GitCallOptions & {
75
76
  input?: string | undefined;
76
77
  }): Promise<CommandResult>;
78
+ /**
79
+ * The git the backend runs, from `git --version`; see {@link Git.version}.
80
+ * `cliBackend` probes once per runner and caches it, or returns its
81
+ * `gitVersion` option without running anything. A non-CLI backend has
82
+ * no git version unless it answers the `version` request itself;
83
+ * `partialBackend` rejects it with `UnsupportedRequest` otherwise.
84
+ */
85
+ version(opts?: GitCallOptions): Promise<GitVersion>;
77
86
  /** A file's content at a rev, null if absent. */
78
87
  showAtRev(rev: string, relPath: string, opts?: GitCallOptions): Promise<string | null>;
79
88
  /** A file's content at a rev, rejecting when the path is missing. See {@link Git.showAtRevChecked}. */
@@ -215,6 +224,13 @@ export declare class AsyncGit {
215
224
  isAncestor(a: string, b: string, opts?: GitCallOptions): Promise<boolean>;
216
225
  /** How far `tip` has diverged from `base`. See {@link AheadBehind}. */
217
226
  aheadBehind(base: string, tip: string, opts?: GitCallOptions): Promise<AheadBehind>;
227
+ /**
228
+ * Commits on `head` (default `HEAD`) that `upstream` lacks, each marked by
229
+ * whether `upstream` has the same patch. See {@link CherryEntry}.
230
+ */
231
+ cherry(upstream: string, head?: string, opts?: GitCallOptions): Promise<CherryEntry[]>;
232
+ /** Write a commit for `tree` and return its sha; no ref moves. Needs a git identity. */
233
+ commitTree(tree: string, commitOpts: CommitTreeOptions, opts?: GitCallOptions): Promise<string>;
218
234
  /** Configured remote names (`git remote`); `[]` when there are none. */
219
235
  remotes(opts?: GitCallOptions): Promise<string[]>;
220
236
  /**
@@ -255,17 +271,11 @@ export declare class AsyncGit {
255
271
  /** `git clone [--depth n] [--branch ref] <url> [dest]`, from this client's `cwd`. */
256
272
  clone(url: string, dest?: string | undefined, opts?: GitCallOptions & CloneOptions): Promise<void>;
257
273
  /**
258
- * Push a refspec. A {@link ForceLease} pins `--force-with-lease`.
259
- * `{forceWithLease: true}` adds the bare flag, which is the unsafe form.
260
- * `{delete: true}` deletes `refspec` on the remote. See {@link Git.push}.
261
- */
262
- push(remote: string, refspec: string, opts?: GitCallOptions & PushOptions): Promise<void>;
263
- /**
264
- * `git push --porcelain`, read into one result per ref. A rejected ref comes
265
- * back with a typed `rejection` rather than a rejection of the promise. See
266
- * {@link Git.pushPorcelain}.
274
+ * Push one refspec or several, read into one result per ref. A rejected
275
+ * ref comes back with a typed `rejection` rather than a rejection of the
276
+ * promise. See {@link Git.push}.
267
277
  */
268
- pushPorcelain(remote: string, refspec: string | string[], opts?: GitCallOptions & PushPorcelainOptions): Promise<PushReport>;
278
+ push(remote: string, refspec: string | readonly string[], opts?: GitCallOptions & PushOptions): Promise<PushReport>;
269
279
  /** `git clean -f`, plus `-d` with `directories`. Ignored files are kept. */
270
280
  clean(opts?: GitCallOptions & CleanOptions): Promise<void>;
271
281
  /** `git reset --hard <rev>`. */
package/dist/async.js CHANGED
@@ -97,6 +97,16 @@ export class AsyncGit {
97
97
  return this.backend.execute(this.cwd, { kind: 'raw', argv, checked: true, input: opts.input }, opts);
98
98
  }
99
99
  // ── queries ───────────────────────────────────────────────────────────────
100
+ /**
101
+ * The git the backend runs, from `git --version`; see {@link Git.version}.
102
+ * `cliBackend` probes once per runner and caches it, or returns its
103
+ * `gitVersion` option without running anything. A non-CLI backend has
104
+ * no git version unless it answers the `version` request itself;
105
+ * `partialBackend` rejects it with `UnsupportedRequest` otherwise.
106
+ */
107
+ version(opts = {}) {
108
+ return this.backend.execute(this.cwd, { kind: 'version' }, opts);
109
+ }
100
110
  /** A file's content at a rev, null if absent. */
101
111
  showAtRev(rev, relPath, opts = {}) {
102
112
  return this.backend.execute(this.cwd, { kind: 'showAtRev', rev, relPath }, opts);
@@ -363,6 +373,17 @@ export class AsyncGit {
363
373
  aheadBehind(base, tip, opts = {}) {
364
374
  return this.backend.execute(this.cwd, { kind: 'aheadBehind', base, tip }, opts);
365
375
  }
376
+ /**
377
+ * Commits on `head` (default `HEAD`) that `upstream` lacks, each marked by
378
+ * whether `upstream` has the same patch. See {@link CherryEntry}.
379
+ */
380
+ cherry(upstream, head, opts = {}) {
381
+ return this.backend.execute(this.cwd, { kind: 'cherry', upstream, head }, opts);
382
+ }
383
+ /** Write a commit for `tree` and return its sha; no ref moves. Needs a git identity. */
384
+ commitTree(tree, commitOpts, opts = {}) {
385
+ return this.backend.execute(this.cwd, { kind: 'commitTree', tree, ...commitOpts }, opts);
386
+ }
366
387
  /** Configured remote names (`git remote`); `[]` when there are none. */
367
388
  remotes(opts = {}) {
368
389
  return this.backend.execute(this.cwd, { kind: 'remote' }, opts);
@@ -437,21 +458,13 @@ export class AsyncGit {
437
458
  return this.backend.execute(this.cwd, { kind: 'clone', url, dest, ...req }, call);
438
459
  }
439
460
  /**
440
- * Push a refspec. A {@link ForceLease} pins `--force-with-lease`.
441
- * `{forceWithLease: true}` adds the bare flag, which is the unsafe form.
442
- * `{delete: true}` deletes `refspec` on the remote. See {@link Git.push}.
461
+ * Push one refspec or several, read into one result per ref. A rejected
462
+ * ref comes back with a typed `rejection` rather than a rejection of the
463
+ * promise. See {@link Git.push}.
443
464
  */
444
465
  push(remote, refspec, opts = {}) {
445
- return this.backend.execute(this.cwd, { kind: 'push', remote, refspec, forceWithLease: opts.forceWithLease, delete: opts.delete }, opts);
446
- }
447
- /**
448
- * `git push --porcelain`, read into one result per ref. A rejected ref comes
449
- * back with a typed `rejection` rather than a rejection of the promise. See
450
- * {@link Git.pushPorcelain}.
451
- */
452
- pushPorcelain(remote, refspec, opts = {}) {
453
466
  const [call, req] = splitCallOptions(opts);
454
- return this.backend.execute(this.cwd, { kind: 'pushPorcelain', remote, refspec, ...req }, call);
467
+ return this.backend.execute(this.cwd, { kind: 'push', remote, refspec, ...req }, call);
455
468
  }
456
469
  /** `git clean -f`, plus `-d` with `directories`. Ignored files are kept. */
457
470
  clean(opts = {}) {
package/dist/backend.d.ts CHANGED
@@ -18,7 +18,8 @@
18
18
  * `cliBackend` and `AsyncGit` are stable.
19
19
  */
20
20
  import { type AsyncCommandRunner, type CommandResult } from '@osdlc/command-seam';
21
- import { type AddOptions, type AheadBehind, type CheckoutOptions, type CloneOptions, type CommitOptions, type ConfigGetOptions, type ConfigSetOptions, type ConflictSide, type DiffEntry, type DiffNameOnlyOptions, type DiffStatOptions, type DiffNameStatusOptions, type DiffTextOptions, type DiffTreeOptions, type FetchOptions, type ForEachRefOptions, type GcOptions, type GrepOptions, type InitOptions, type LogOptions, type IgnoreMatch, type LsFilesOptions, type LsRemoteOptions, type LsTreeOptions, type MergeOptions, type MergeOutcome, type MergeTreeOptions, type MergeTreeOutcome, type NumstatEntry, type PushOptions, type PushPorcelainOptions, type PushReport, type RemoteSetBranchesOptions, type RemoteSetHeadOptions, type WorktreeAddOptions, type RebaseOptions, type RebaseOutcome, type RemoteGetUrlOptions, type RemoteRef, type CleanOptions, type DiffCheckOptions, type DiffCheckResult, type StatusEntry, type StatusPorcelainOptions, type TreeEntry, type TaggedFile, type UnmergedEntry, type Worktree, type WorktreeMoveOptions } from './verbs.ts';
21
+ import { type GitVersion } from './git-version.ts';
22
+ import { type AddOptions, type AheadBehind, type CherryEntry, type CommitTreeOptions, type CheckoutOptions, type CloneOptions, type CommitOptions, type ConfigGetOptions, type ConfigSetOptions, type ConflictSide, type DiffEntry, type DiffNameOnlyOptions, type DiffStatOptions, type DiffNameStatusOptions, type DiffTextOptions, type DiffTreeOptions, type FetchOptions, type ForEachRefOptions, type GcOptions, type GrepOptions, type InitOptions, type LogOptions, type IgnoreMatch, type LsFilesOptions, type LsRemoteOptions, type LsTreeOptions, type MergeOptions, type MergeOutcome, type MergeTreeOptions, type MergeTreeOutcome, type NumstatEntry, type PushOptions, type PushReport, type RemoteSetBranchesOptions, type RemoteSetHeadOptions, type WorktreeAddOptions, type RebaseOptions, type RebaseOutcome, type RemoteGetUrlOptions, type RemoteRef, type CleanOptions, type DiffCheckOptions, type DiffCheckResult, type StatusEntry, type StatusPorcelainOptions, type TreeEntry, type TaggedFile, type UnmergedEntry, type Worktree, type WorktreeMoveOptions } from './verbs.ts';
22
23
  /** Per-call concerns that are not part of the operation itself. */
23
24
  export interface GitCallOptions {
24
25
  /**
@@ -57,6 +58,8 @@ export interface GitCallOptions {
57
58
  * @experimental Each new verb adds a kind, in a minor release.
58
59
  */
59
60
  export type GitRequest = {
61
+ kind: 'version';
62
+ } | {
60
63
  kind: 'showAtRev';
61
64
  rev: string;
62
65
  relPath: string;
@@ -129,7 +132,14 @@ export type GitRequest = {
129
132
  kind: 'aheadBehind';
130
133
  base: string;
131
134
  tip: string;
135
+ } | {
136
+ kind: 'cherry';
137
+ upstream: string;
138
+ head?: string | undefined;
132
139
  } | ({
140
+ kind: 'commitTree';
141
+ tree: string;
142
+ } & CommitTreeOptions) | ({
133
143
  kind: 'lsFiles';
134
144
  } & LsFilesOptions) | {
135
145
  kind: 'lsFilesTagged';
@@ -192,12 +202,8 @@ export type GitRequest = {
192
202
  } & CloneOptions) | ({
193
203
  kind: 'push';
194
204
  remote: string;
195
- refspec: string;
196
- } & PushOptions) | ({
197
- kind: 'pushPorcelain';
198
- remote: string;
199
- refspec: string | string[];
200
- } & PushPorcelainOptions) | {
205
+ refspec: string | readonly string[];
206
+ } & PushOptions) | {
201
207
  kind: 'resetHard';
202
208
  rev: string;
203
209
  } | ({
@@ -287,6 +293,7 @@ export type GitRequest = {
287
293
  * @experimental It grows with {@link GitRequest}.
288
294
  */
289
295
  export interface GitResults {
296
+ version: GitVersion;
290
297
  showAtRev: string | null;
291
298
  showAtRevChecked: string;
292
299
  revParse: string | null;
@@ -312,6 +319,8 @@ export interface GitResults {
312
319
  checkIgnoreVerbose: IgnoreMatch[];
313
320
  isAncestor: boolean;
314
321
  aheadBehind: AheadBehind;
322
+ cherry: CherryEntry[];
323
+ commitTree: string;
315
324
  lsFiles: string[];
316
325
  lsFilesTagged: TaggedFile[];
317
326
  forEachRef: string[];
@@ -334,8 +343,7 @@ export interface GitResults {
334
343
  configRemoveSection: boolean;
335
344
  init: void;
336
345
  clone: void;
337
- push: void;
338
- pushPorcelain: PushReport;
346
+ push: PushReport;
339
347
  resetHard: void;
340
348
  clean: void;
341
349
  deleteBranch: void;
@@ -375,6 +383,12 @@ export type GitRequestKind = GitRequest['kind'];
375
383
  * config key. It rejects with the classified failure — or whatever error the backend
376
384
  * considers equivalent — when git failed rather than answered.
377
385
  *
386
+ * The git version check is `cliBackend`'s: it probes `git --version` before
387
+ * a request whose verb needs a newer git (see `features.ts`) and rejects with
388
+ * the `unsupported-git` failure when the git is too old. Another backend has
389
+ * no git version to check, so it gets every request and decides itself. It
390
+ * may reject one with that same failure, or with {@link UnsupportedRequest}.
391
+ *
378
392
  * @experimental New request kinds land in minor releases. Use
379
393
  * {@link partialBackend} rather than an exhaustive switch.
380
394
  */
@@ -409,6 +423,13 @@ export declare function cliBackend(opts?: {
409
423
  * `GIT_SSH_COMMAND` once, instead of passing it on every call.
410
424
  */
411
425
  env?: Record<string, string> | undefined;
426
+ /**
427
+ * Pins the git version: `'2.55.0'`, or a whole `git version …` line.
428
+ * Version-gated requests then use it and never run `git --version`, and
429
+ * the `version` request returns it. Set it with a fake runner. An
430
+ * unparsable value throws a `RangeError` here.
431
+ */
432
+ gitVersion?: string | undefined;
412
433
  }): GitBackend;
413
434
  /**
414
435
  * Wrap a partial implementation: any request kind the object does not handle