@osdlc/typed-git 0.5.3 → 0.7.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 +44 -1
- package/CONTRIBUTING.md +3 -4
- package/README.md +40 -16
- package/dist/async.d.ts +3 -4
- package/dist/async.js +4 -3
- package/dist/backend.d.ts +1 -2
- package/dist/checkout-root.d.ts +0 -1
- package/dist/client.d.ts +2 -2
- package/dist/client.js +1 -0
- package/dist/failure.d.ts +72 -0
- package/dist/failure.js +155 -0
- package/dist/git-url.d.ts +0 -1
- package/dist/index.d.ts +1 -2
- package/dist/index.js +1 -1
- package/dist/outcome.d.ts +14 -19
- package/dist/outcome.js +21 -16
- package/dist/remote-url.d.ts +0 -1
- package/dist/soft.d.ts +0 -1
- package/dist/sync.d.ts +5 -5
- package/dist/sync.js +5 -3
- package/dist/testing.d.ts +0 -1
- package/dist/verbs.d.ts +5 -7
- package/dist/verbs.js +18 -11
- package/package.json +13 -23
- package/async.ts +0 -753
- package/backend.ts +0 -574
- package/checkout-root.ts +0 -164
- package/client.ts +0 -102
- package/dist/async.d.ts.map +0 -1
- package/dist/backend.d.ts.map +0 -1
- package/dist/checkout-root.d.ts.map +0 -1
- package/dist/client.d.ts.map +0 -1
- package/dist/git-url.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/outcome.d.ts.map +0 -1
- package/dist/remote-url.d.ts.map +0 -1
- package/dist/soft.d.ts.map +0 -1
- package/dist/sync.d.ts.map +0 -1
- package/dist/testing.d.ts.map +0 -1
- package/dist/verbs.d.ts.map +0 -1
- package/git-url.ts +0 -102
- package/hosted-git-info.d.ts +0 -24
- package/index.ts +0 -52
- package/outcome.ts +0 -191
- package/remote-url.ts +0 -46
- package/soft.ts +0 -60
- package/sync.ts +0 -827
- package/testing.ts +0 -291
- package/verbs.ts +0 -2300
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,47 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @osdlc/typed-git
|
|
2
|
+
|
|
3
|
+
## 0.7.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- b5aac07: When a git call fails and throws a `FailureError`, the error's `message` now starts with the git command, for example `git push: The remote 'origin' does not exist or is not a git repository.`, followed by the hint. Before, the message had no command, so code that ran several git calls in one `try` could not tell which one failed. `failure.message` is unchanged.
|
|
8
|
+
|
|
9
|
+
The new `describeGitFailure(failure)` builds the same `git <verb>: <message> <hint>` line for a failure returned by `git.try.*`.
|
|
10
|
+
|
|
11
|
+
If your code matches on the text of a thrown git error's `message`, it will now see the `git <verb>: ` prefix. Match on `error.failure.kind` instead.
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- 41ef520: Fix two type errors under TypeScript 5.9. The emitted `outcome.d.ts` failed with TS2536, because `Soft<C>` used a key on `Triable<C>` that TS 5.x could not prove valid. The source failed with TS2322, because `Git.soft` and `AsyncGit.soft` inferred `this` instead of the class type. A new `typecheck:ts59` script checks the package under 5.9.
|
|
16
|
+
|
|
17
|
+
## 0.6.0
|
|
18
|
+
|
|
19
|
+
### Minor Changes
|
|
20
|
+
|
|
21
|
+
- d9b0f77: **Breaking:** typed-git's plain door throws the classified failure, as typed-gh's does. A failed git call (any verb, `rawChecked`) now throws a `FailureError` whose `failure` is the `GitFailure` and whose `failure.cause` is the `CommandFailed`, where it threw the `CommandFailed` itself. The bare `CommandFailed` had only command-seam's generic `exit` kind, so a signed-out `git push` exited 1 from `runMain` instead of 23. Read `error.failure.argv` and `error.failure.cause.result` where you read `error.argv` and `error.result`.
|
|
22
|
+
|
|
23
|
+
New `GitFailureKind` `tls`: `unable to access … SSL certificate problem` is no longer `remote-unreachable`. The host answered, so retrying cannot help until the system clock, the CA certificates or the remote's certificate is fixed. `@osdlc/cli-tool` numbers `tls` 23, with the other "fix it" failures; `@osdlc/pr-update` accounts for it in its exit-table check and reads a push failure through the `FailureError`'s cause.
|
|
24
|
+
- d9b0f77: **Breaking:** `git.try.*` returns `Result<T, GitFailure>` from `@osdlc/result`. `GitOutcome` is removed. The error is a classified `GitFailure` (`kind`, `message`, `hint`, `detail`, `argv`, `exitCode`) and its `cause` is the `CommandFailed`; read the raw result at `error.cause.result`. `kind` is a `GitFailureKind`: every `@osdlc/command-seam` failure kind (`not-installed` carries the hint `Install git from https://git-scm.com.`), plus `not-a-repo`, `no-remote`, `remote-unreachable` and `not-authenticated`, read from git's stderr. `classifyGitFailure(commandFailed)` is exported. The plain verb (throws `CommandFailed`) and `git.soft.*` are unchanged. `@osdlc/result` is now a dependency.
|
|
25
|
+
- d9b0f77: A git failure with an HTTP status is no longer `remote-unreachable`. `unable to access … The requested URL returned error: 401` or `403` is `not-authenticated`, and `404` is the new kind `not-found` (`GitFailureKind` gains it), so a script that retries on `remote-unreachable` does not loop on a permission or wrong-URL problem. A refused connection, a DNS failure and a timeout stay `remote-unreachable`. The `try` and `soft` doors recognise a thrown `CommandFailed` by shape, so two installed copies of `@osdlc/command-seam` agree.
|
|
26
|
+
|
|
27
|
+
### Patch Changes
|
|
28
|
+
|
|
29
|
+
- fb712e0: Ship the compiled `dist/` only. The `bun` export condition and the TypeScript source are no longer in the package, so Bun, Node and every bundler load the same compiled ESM and `.d.ts` files. Bun still works through the compiled `dist/`.
|
|
30
|
+
- fb712e0: Make every package follow the same conventions. The published manifests and READMEs change; the runtime code and the `dist/` files do not.
|
|
31
|
+
|
|
32
|
+
- `author` is `sksizer` in every manifest (`@osdlc/typed-gh` had none).
|
|
33
|
+
- `engines.node` is no wider than any dependency's. `@osdlc/typed-gh` and `@osdlc/code-host` now declare `^22.22.2 || ^24.15.0 || >=26.0.0`, the range of `@osdlc/typed-git` and its dependency `hosted-git-info`. `@osdlc/cli-tool` and `@osdlc/trust-repo` declare `>=22`, not `>=22.18`: a `dist/` install needs no TypeScript stripping.
|
|
34
|
+
- `@osdlc/tsconfig` and `@osdlc/prettier-config` are ESM with `sideEffects: false`, and ship SECURITY.md and CONTRIBUTING.md. `@osdlc/prettier-config` has an `exports` map (`.` is `index.json`) in place of `main`.
|
|
35
|
+
- Every README has `## Install` and `## Licence` sections, and every CHANGELOG starts `# @osdlc/<name>`.
|
|
36
|
+
- `@osdlc/color` and `@osdlc/markdown-contract` no longer set a coverage threshold.
|
|
37
|
+
- `@osdlc/yaml-splice` reaches its WebAssembly glue through a `#wasm` entry in `imports`. The shipped `dist/` files are the same.
|
|
38
|
+
- Updated dependencies [d9b0f77]
|
|
39
|
+
- Updated dependencies [d9b0f77]
|
|
40
|
+
- Updated dependencies [fb712e0]
|
|
41
|
+
- Updated dependencies [fb712e0]
|
|
42
|
+
- Updated dependencies [d9b0f77]
|
|
43
|
+
- @osdlc/command-seam@0.9.0
|
|
44
|
+
- @osdlc/result@0.1.0
|
|
2
45
|
|
|
3
46
|
## 0.5.3
|
|
4
47
|
|
package/CONTRIBUTING.md
CHANGED
|
@@ -20,8 +20,8 @@ there.
|
|
|
20
20
|
## Running the tests
|
|
21
21
|
|
|
22
22
|
The repository is a pnpm workspace. Install from the repository root, then work
|
|
23
|
-
in the package directory. The tests run under
|
|
24
|
-
|
|
23
|
+
in the package directory. The tests run on Vitest under Node 22 or later.
|
|
24
|
+
`git` must be on `PATH`:
|
|
25
25
|
many tests create real temporary repositories.
|
|
26
26
|
|
|
27
27
|
```sh
|
|
@@ -44,8 +44,7 @@ pnpm run lint
|
|
|
44
44
|
pnpm run format:check
|
|
45
45
|
```
|
|
46
46
|
|
|
47
|
-
`npm run <script>`
|
|
48
|
-
is installed.
|
|
47
|
+
`npm run <script>` works the same way once the workspace is installed.
|
|
49
48
|
|
|
50
49
|
## Code style
|
|
51
50
|
|
package/README.md
CHANGED
|
@@ -15,6 +15,8 @@ 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
|
+
`pnpm add @osdlc/typed-git` and `yarn add @osdlc/typed-git` work too.
|
|
19
|
+
|
|
18
20
|
The package is ESM only. It needs Node `^22.22.2 || ^24.15.0 || >=26.0.0`, the
|
|
19
21
|
range its dependency `hosted-git-info` needs, and a `git` executable on
|
|
20
22
|
`PATH`. Its types use the global `AbortSignal`, so a project needs
|
|
@@ -32,9 +34,9 @@ GitHub-hosted runners ship. On 2026-10-20 that was git 2.55.0 on
|
|
|
32
34
|
the checkout step logs it. So the tested minimum is git 2.55.0. Older git may
|
|
33
35
|
work, but no test shows it. The behaviour tables below were measured against
|
|
34
36
|
git 2.50.1. A verb that needs a newer git than you have fails with git's own
|
|
35
|
-
error and throws
|
|
37
|
+
error and throws the classified failure. `mergeTree` needs git 2.38 or later.
|
|
36
38
|
|
|
37
|
-
|
|
39
|
+
The tests run on Vitest under Node. Bun is not a tested runtime for consumers.
|
|
38
40
|
|
|
39
41
|
## Stability
|
|
40
42
|
|
|
@@ -79,7 +81,7 @@ git.configGet("no.such.key"); // null — an unset key is an answer
|
|
|
79
81
|
git.worktrees(); // Worktree[] — throws outside a repository
|
|
80
82
|
git.commit({ message: "feat" }); // throws CommandFailed on a non-zero exit
|
|
81
83
|
|
|
82
|
-
const r = git.try.worktrees(); //
|
|
84
|
+
const r = git.try.worktrees(); // Result<Worktree[], GitFailure>
|
|
83
85
|
|
|
84
86
|
const asyncGit = new AsyncGit(process.cwd());
|
|
85
87
|
await asyncGit.currentBranch();
|
|
@@ -113,13 +115,13 @@ Every verb names the exit codes that mean "asked and answered: not there" for
|
|
|
113
115
|
*that* verb. `config --get` exits 1 for an unset key; `check-ignore` exits 1
|
|
114
116
|
for "none of these are ignored"; `merge-base` exits 1 for unrelated histories.
|
|
115
117
|
Those return the absence value — `null`, `[]`, `false` — exactly as before.
|
|
116
|
-
Any other non-zero exit throws
|
|
118
|
+
Any other non-zero exit throws the classified failure, carrying the argv and the full
|
|
117
119
|
result.
|
|
118
120
|
|
|
119
121
|
| | on a declared absence | on anything else |
|
|
120
122
|
| --- | --- | --- |
|
|
121
|
-
| **`git.verb()`** | the absence value — `null`, `[]`, `false` | throws
|
|
122
|
-
| **`git.try.verb()`** | `{ ok: true, value }` | `{ ok: false, error }` |
|
|
123
|
+
| **`git.verb()`** | the absence value — `null`, `[]`, `false` | throws the classified failure |
|
|
124
|
+
| **`git.try.verb()`** | `{ ok: true, value }` | `{ ok: false, error: GitFailure }` |
|
|
123
125
|
| **`git.raw(argv)`** | the raw `CommandResult`; you decide | the same |
|
|
124
126
|
|
|
125
127
|
Why it matters: a guard that runs `status --porcelain` outside a repository
|
|
@@ -135,8 +137,30 @@ if (!r.ok) { console.error(r.error.detail); return; }
|
|
|
135
137
|
use(r.value);
|
|
136
138
|
```
|
|
137
139
|
|
|
140
|
+
The error is a `GitFailure`: a `Failure` from `@osdlc/result` with a `kind` to
|
|
141
|
+
branch on, a one-line `message` and a `hint` for a person (`describe(error)`
|
|
142
|
+
joins them), git's own output in `detail`, the `argv` and `exitCode`, and the
|
|
143
|
+
`CommandFailed` it was read from in `cause`. The plain door throws the same failure, wrapped in a `FailureError` (`error.failure`), so a CLI that reports a thrown failure, such as `runMain` from `@osdlc/cli-tool`, shows "The remote refused the credentials" and exits 23 for a signed-out `git push`, as it does for a read. The thrown `message` names the command (`git push: The remote refused the credentials. …`); `failure.message` is the bare sentence, and `describeGitFailure(failure)` renders the same `git <verb>: <message> <hint>` line for a failure from `git.try.*`.
|
|
144
|
+
|
|
145
|
+
| `kind` | When | `message` / `hint` |
|
|
146
|
+
| --- | --- | --- |
|
|
147
|
+
| `not-installed` | git is not on `PATH` | `` `git` is not installed or not on PATH. `` / `Install git from https://git-scm.com.` |
|
|
148
|
+
| `not-a-repo` | stderr says `not a git repository` | `This is not a git repository.` / ``Run it inside a git repository, or create one with `git init`.`` |
|
|
149
|
+
| `no-remote` | `No such remote`, or `'x' does not appear to be a git repository` | `The remote 'x' does not exist.` (or `… does not exist or is not a git repository.`) / ``List the remotes with `git remote -v`.`` |
|
|
150
|
+
| `remote-unreachable` | `Could not read from remote repository`, `Could not resolve host`, `unable to access` with no HTTP status (a refused connection, a timeout) | `The remote could not be reached.` / `Check your network connection and the remote URL.` |
|
|
151
|
+
| `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.` |
|
|
152
|
+
| `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.` |
|
|
153
|
+
| `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.` |
|
|
154
|
+
| `not-executable`, `bad-cwd`, `timeout`, `output-cap`, `signal`, `aborted`, `spawn` | as in `@osdlc/command-seam` | command-seam's message, no hint |
|
|
155
|
+
| `exit` | any other non-zero exit | git's first stderr line |
|
|
156
|
+
|
|
157
|
+
The patterns are git's English messages. Under another locale git's words
|
|
158
|
+
differ and the failure is a plain `exit` with git's own line, never a wrong
|
|
159
|
+
kind. `classifyGitFailure(commandFailed)` makes the same classification for a
|
|
160
|
+
`CommandFailed` you caught yourself.
|
|
161
|
+
|
|
138
162
|
It mirrors the whole surface, sync and async, and costs nothing per verb. Two
|
|
139
|
-
rules keep it honest: it catches
|
|
163
|
+
rules keep it honest: it catches a thrown git failure and nothing else, so a
|
|
140
164
|
`TypeError` still propagates; and a declared absence is `{ ok: true }`,
|
|
141
165
|
because absence is an answer.
|
|
142
166
|
|
|
@@ -156,7 +180,7 @@ outcome verbs such as `merge`, and `checkIgnore`, `aheadBehind` and `diffText`,
|
|
|
156
180
|
plus every mutation. Reach for `try`. Boolean verbs fall back to
|
|
157
181
|
`false`, which also means "could not ask": `soft.isDirty` reads a broken repo
|
|
158
182
|
as clean, so do not gate a destructive action on it. `soft`
|
|
159
|
-
catches
|
|
183
|
+
catches a thrown git failure only, exactly like `try`, and one table
|
|
160
184
|
(`./soft.ts`, checked against both clients) defines it for `Git` and
|
|
161
185
|
`AsyncGit`.
|
|
162
186
|
|
|
@@ -237,7 +261,7 @@ git.isAncestor(sha, "origin/main");
|
|
|
237
261
|
|
|
238
262
|
An exit code only answers when git produced it. A `git` missing from PATH, a
|
|
239
263
|
timeout kill or an abort leaves the runner with no exit code of its own to
|
|
240
|
-
report, and every verb throws
|
|
264
|
+
report, and every verb throws the classified failure there — none of them reads that
|
|
241
265
|
as "no matches" or "no such key".
|
|
242
266
|
|
|
243
267
|
`aheadBehind` is here for a different reason: it owns a field order that is
|
|
@@ -406,7 +430,7 @@ needs to print.
|
|
|
406
430
|
|
|
407
431
|
Every method exists on both `Git` and `AsyncGit` with the same name and
|
|
408
432
|
arguments; the async one returns a promise. Each also mirrors onto
|
|
409
|
-
`git.try.*`, which returns `
|
|
433
|
+
`git.try.*`, which returns a `Result<T, GitFailure>` instead of throwing.
|
|
410
434
|
Every method takes call options (`timeoutMs`, `env`, `maxOutputBytes`, and
|
|
411
435
|
`signal` on the async side) as its last argument. `revParse` is variadic, so its options are the
|
|
412
436
|
trailing argument that is not a string.
|
|
@@ -436,7 +460,7 @@ integer. Both checks throw a `TypeError` before git runs.
|
|
|
436
460
|
### Queries
|
|
437
461
|
|
|
438
462
|
"Absence" is the exit code this verb declares as an answer. Any other non-zero
|
|
439
|
-
exit throws
|
|
463
|
+
exit throws the classified failure.
|
|
440
464
|
|
|
441
465
|
| Method | git | Absence → value |
|
|
442
466
|
| --- | --- | --- |
|
|
@@ -498,7 +522,7 @@ empty repository from a dangling HEAD or a missing object store. Use
|
|
|
498
522
|
### Mutations
|
|
499
523
|
|
|
500
524
|
Every mutation except `configRemoveSection` declares no absence: a non-zero
|
|
501
|
-
exit throws
|
|
525
|
+
exit throws the classified failure, because the only sane handling of "the write did
|
|
502
526
|
not happen" is to surface it. `configRemoveSection` declares 128 absent and
|
|
503
527
|
returns `false` when there is no such section.
|
|
504
528
|
|
|
@@ -543,9 +567,9 @@ throws.
|
|
|
543
567
|
| Method | What |
|
|
544
568
|
| --- | --- |
|
|
545
569
|
| `raw(argv, opts)` | Run anything. Returns `CommandResult`; you read `exitCode`. |
|
|
546
|
-
| `rawChecked(argv, opts)` | Same, but throws
|
|
570
|
+
| `rawChecked(argv, opts)` | Same, but throws the classified failure on a non-zero exit or on output cut short at a cap or a timeout. |
|
|
547
571
|
| `at(cwd)` | The same client rooted elsewhere, reusing the runner or backend. |
|
|
548
|
-
| `try.*` | The whole surface again, returning `
|
|
572
|
+
| `try.*` | The whole surface again, returning `Result<T, GitFailure>` (from `@osdlc/result`) instead of throwing. |
|
|
549
573
|
| `soft.*` | Every verb with an absence value, returning it instead of throwing. |
|
|
550
574
|
|
|
551
575
|
`raw` is the honest answer for a one-off — `update-ref`, `tag -a`, a patch
|
|
@@ -766,6 +790,6 @@ de-duplicate.
|
|
|
766
790
|
change what it returns.
|
|
767
791
|
- Test fixtures need a manual `cleanup()`.
|
|
768
792
|
|
|
769
|
-
##
|
|
793
|
+
## Licence
|
|
770
794
|
|
|
771
|
-
`MIT OR Apache-2.0`, at your option.
|
|
795
|
+
`MIT OR Apache-2.0`, at your option. See [LICENSE-MIT](./LICENSE-MIT) and [LICENSE-APACHE](./LICENSE-APACHE).
|
package/dist/async.d.ts
CHANGED
|
@@ -41,7 +41,7 @@ export declare class AsyncGit {
|
|
|
41
41
|
/** The same client rooted at a different directory (same backend). */
|
|
42
42
|
at(cwd: string): AsyncGit;
|
|
43
43
|
/**
|
|
44
|
-
* The whole surface again, resolving to a
|
|
44
|
+
* The whole surface again, resolving to a `Result<T, GitFailure>` instead of
|
|
45
45
|
* rejecting. A declared absence is `ok: true`; see `./outcome.ts`.
|
|
46
46
|
*
|
|
47
47
|
* The type leaves out `raw`, `rawChecked` and `at`, but at runtime the proxy
|
|
@@ -68,7 +68,7 @@ export declare class AsyncGit {
|
|
|
68
68
|
input?: string | undefined;
|
|
69
69
|
}): Promise<CommandResult>;
|
|
70
70
|
/**
|
|
71
|
-
* Checked argv passthrough — rejects with
|
|
71
|
+
* Checked argv passthrough — rejects with the classified failure on a non-zero
|
|
72
72
|
* exit, and on output cut short at the output cap or a timeout. Report
|
|
73
73
|
* `e.detail`, which joins both streams; see {@link Git.rawChecked}.
|
|
74
74
|
*/
|
|
@@ -295,7 +295,7 @@ export declare class AsyncGit {
|
|
|
295
295
|
/**
|
|
296
296
|
* Merge `ref` into the current branch. A conflict is a value, not a
|
|
297
297
|
* rejection: the outcome is `clean` or `conflict`. Git refusing to merge at
|
|
298
|
-
* all still rejects with
|
|
298
|
+
* all still rejects with the classified failure.
|
|
299
299
|
*/
|
|
300
300
|
merge(ref: string, opts?: MergeOptions & GitCallOptions): Promise<MergeOutcome>;
|
|
301
301
|
/** `git merge --abort`. Rejects when no merge is in progress. */
|
|
@@ -322,4 +322,3 @@ export declare class AsyncGit {
|
|
|
322
322
|
/** `git checkout [-f] [-b|-B <branch>] <ref>`. */
|
|
323
323
|
checkout(ref: string, opts?: CheckoutOptions & GitCallOptions): Promise<void>;
|
|
324
324
|
}
|
|
325
|
-
//# sourceMappingURL=async.d.ts.map
|
package/dist/async.js
CHANGED
|
@@ -57,7 +57,7 @@ export class AsyncGit {
|
|
|
57
57
|
return new AsyncGit(cwd, { backend: this.backend });
|
|
58
58
|
}
|
|
59
59
|
/**
|
|
60
|
-
* The whole surface again, resolving to a
|
|
60
|
+
* The whole surface again, resolving to a `Result<T, GitFailure>` instead of
|
|
61
61
|
* rejecting. A declared absence is `ok: true`; see `./outcome.ts`.
|
|
62
62
|
*
|
|
63
63
|
* The type leaves out `raw`, `rawChecked` and `at`, but at runtime the proxy
|
|
@@ -78,6 +78,7 @@ export class AsyncGit {
|
|
|
78
78
|
* runtime, though the type leaves them out.
|
|
79
79
|
*/
|
|
80
80
|
get soft() {
|
|
81
|
+
// Explicit type argument: otherwise TS 5.x infers the polymorphic `this`.
|
|
81
82
|
return (this.softened ??= softAsync(this, SOFT_TABLE));
|
|
82
83
|
}
|
|
83
84
|
// ── escape hatch ──────────────────────────────────────────────────────────
|
|
@@ -89,7 +90,7 @@ export class AsyncGit {
|
|
|
89
90
|
return this.backend.execute(this.cwd, { kind: 'raw', argv, input: opts.input }, opts);
|
|
90
91
|
}
|
|
91
92
|
/**
|
|
92
|
-
* Checked argv passthrough — rejects with
|
|
93
|
+
* Checked argv passthrough — rejects with the classified failure on a non-zero
|
|
93
94
|
* exit, and on output cut short at the output cap or a timeout. Report
|
|
94
95
|
* `e.detail`, which joins both streams; see {@link Git.rawChecked}.
|
|
95
96
|
*/
|
|
@@ -481,7 +482,7 @@ export class AsyncGit {
|
|
|
481
482
|
/**
|
|
482
483
|
* Merge `ref` into the current branch. A conflict is a value, not a
|
|
483
484
|
* rejection: the outcome is `clean` or `conflict`. Git refusing to merge at
|
|
484
|
-
* all still rejects with
|
|
485
|
+
* all still rejects with the classified failure.
|
|
485
486
|
*/
|
|
486
487
|
merge(ref, opts = {}) {
|
|
487
488
|
const [call, req] = splitCallOptions(opts);
|
package/dist/backend.d.ts
CHANGED
|
@@ -347,7 +347,7 @@ export type GitRequestKind = GitRequest['kind'];
|
|
|
347
347
|
*
|
|
348
348
|
* A request resolves to its value — including the absence value (`null`,
|
|
349
349
|
* `[]`, `false`) for a state the verb declares absent, such as an unset
|
|
350
|
-
* config key. It rejects with
|
|
350
|
+
* config key. It rejects with the classified failure — or whatever error the backend
|
|
351
351
|
* considers equivalent — when git failed rather than answered.
|
|
352
352
|
*
|
|
353
353
|
* @experimental New request kinds land in minor releases. Use
|
|
@@ -397,4 +397,3 @@ export declare function partialBackend(name: string, impl: Partial<{
|
|
|
397
397
|
kind: K;
|
|
398
398
|
}>, opts: GitCallOptions) => Promise<GitResults[K]>;
|
|
399
399
|
}>): GitBackend;
|
|
400
|
-
//# sourceMappingURL=backend.d.ts.map
|
package/dist/checkout-root.d.ts
CHANGED
|
@@ -86,4 +86,3 @@ export declare function scanForCheckouts(dir: string, opts?: DiscoverCheckoutsOp
|
|
|
86
86
|
* scanForCheckouts} for a caller that wants the answer and not the cost.
|
|
87
87
|
*/
|
|
88
88
|
export declare function discoverCheckouts(dir: string, opts?: DiscoverCheckoutsOptions): string[];
|
|
89
|
-
//# sourceMappingURL=checkout-root.d.ts.map
|
package/dist/client.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ export { Git, type GitSyncCallOptions } from './sync.ts';
|
|
|
18
18
|
export { AsyncGit } from './async.ts';
|
|
19
19
|
export { parseRemoteUrl, type RemoteCoordinate } from './remote-url.ts';
|
|
20
20
|
export { cliBackend, partialBackend, UnsupportedRequest, type GitBackend, type GitCallOptions, type GitRequest, type GitRequestKind, type GitResults, } from './backend.ts';
|
|
21
|
-
export {
|
|
21
|
+
export { classifyGitFailure, describeGitFailure, type GitFailure, type GitFailureKind, } from './failure.ts';
|
|
22
|
+
export { type Soft, type TriedAsync, type TriedSync } from './outcome.ts';
|
|
22
23
|
export { forceWithLeaseArg, parseRefRows, REF_FORMAT, type AddOptions, type AheadBehind, type CheckoutOptions, type CleanOptions, type CloneOptions, type CommitFlags, type CommitOptions, type ConfigGetOptions, type ConfigScope, type ConfigSetOptions, type ConflictSide, type DiffCheckOptions, type DiffCheckResult, type DiffEntry, type DiffNameOnlyOptions, type DiffNameStatusOptions, type DiffStatOptions, type DiffTextOptions, type DiffTreeOptions, type FetchOptions, type ForEachRefOptions, type ForceLease, type GrepOptions, type InitOptions, type IntegrationOutcome, type LogOptions, type IgnoreMatch, type LsFilesOptions, type LsRemoteOptions, type LsTreeOptions, type MergeOptions, type MergeOutcome, type MergeTreeOptions, type MergeTreeOutcome, type NumstatEntry, type RebaseOptions, type RebaseOutcome, type RemoteGetUrlOptions, type RemoteRef, type StatusEntry, type StatusPorcelainOptions, type TaggedFile, type TreeEntry, type UnmergedEntry, type Worktree, type WorktreeMoveOptions, } from './verbs.ts';
|
|
23
24
|
export { asAsync, CommandFailed, runChecked, runCheckedAsync, spawnRunner, spawnRunnerAsync, type AsyncCommandRunner, type AsyncCommandRunOptions, type CommandResult, type CommandRunner, type CommandRunOptions, } from '@osdlc/command-seam';
|
|
24
|
-
//# sourceMappingURL=client.d.ts.map
|
package/dist/client.js
CHANGED
|
@@ -18,6 +18,7 @@ export { Git } from "./sync.js";
|
|
|
18
18
|
export { AsyncGit } from "./async.js";
|
|
19
19
|
export { parseRemoteUrl } from "./remote-url.js";
|
|
20
20
|
export { cliBackend, partialBackend, UnsupportedRequest, } from "./backend.js";
|
|
21
|
+
export { classifyGitFailure, describeGitFailure, } from "./failure.js";
|
|
21
22
|
export {} from "./outcome.js";
|
|
22
23
|
export { forceWithLeaseArg, parseRefRows, REF_FORMAT, } from "./verbs.js";
|
|
23
24
|
// The subprocess seam is re-exported so a caller wiring a runner or catching
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* {@link GitFailure}: a failed git call, classified. The `git.try.*` door
|
|
3
|
+
* returns it as the error of a `Result`; its `cause` is the `CommandFailed`
|
|
4
|
+
* it was read from.
|
|
5
|
+
*
|
|
6
|
+
* The git-specific kinds come from git's stderr, matched in English. Git
|
|
7
|
+
* translates its messages under a non-English locale; those fall through to the
|
|
8
|
+
* subprocess layer's kind, so an unrecognised failure is still an `exit` with
|
|
9
|
+
* git's first stderr line as its message, never a wrong git kind.
|
|
10
|
+
*/
|
|
11
|
+
import { type CommandFailed, type CommandFailureKind } from '@osdlc/command-seam';
|
|
12
|
+
import { type Failure } from '@osdlc/result';
|
|
13
|
+
/**
|
|
14
|
+
* Why a git call failed:
|
|
15
|
+
*
|
|
16
|
+
* - everything `@osdlc/command-seam` reports (`not-installed`, `not-executable`,
|
|
17
|
+
* `bad-cwd`, `timeout`, `output-cap`, `signal`, `aborted`, `spawn`, `exit`);
|
|
18
|
+
* - `not-a-repo`: git ran outside a repository ("not a git repository");
|
|
19
|
+
* - `no-remote`: the named remote does not exist ("No such remote", "'x' does not
|
|
20
|
+
* appear to be a git repository");
|
|
21
|
+
* - `remote-unreachable`: the remote exists but could not be reached ("Could not
|
|
22
|
+
* read from remote repository", "Could not resolve host", "unable to access"
|
|
23
|
+
* without an HTTP status: a refused connection, a timeout);
|
|
24
|
+
* - `not-authenticated`: the remote refused the credentials ("Authentication
|
|
25
|
+
* failed", "Permission denied (publickey)", "could not read Username", "unable
|
|
26
|
+
* to access … The requested URL returned error: 401" or "403");
|
|
27
|
+
* - `not-found`: the host answered that the repository is not there ("unable to
|
|
28
|
+
* access … The requested URL returned error: 404"). Retrying will not help;
|
|
29
|
+
* - `tls`: the TLS handshake failed ("unable to access … SSL certificate
|
|
30
|
+
* problem"). The host was reached, so this is not `remote-unreachable`, and
|
|
31
|
+
* retrying will not help until the clock, the CA certificates or the remote's
|
|
32
|
+
* certificate is fixed.
|
|
33
|
+
*/
|
|
34
|
+
export type GitFailureKind = CommandFailureKind | 'not-a-repo' | 'no-remote' | 'remote-unreachable' | 'not-authenticated' | 'not-found' | 'tls';
|
|
35
|
+
/** A failed git call. `message` is one line for a person; `detail` is git's own output. */
|
|
36
|
+
export interface GitFailure extends Failure<GitFailureKind> {
|
|
37
|
+
/** The binary that ran (`git`), when the runner reports one. */
|
|
38
|
+
binary?: string | undefined;
|
|
39
|
+
/** The arguments git ran with, without the binary name. */
|
|
40
|
+
argv: string[];
|
|
41
|
+
/** git's exit code; `null` when it never reported one. */
|
|
42
|
+
exitCode: number | null;
|
|
43
|
+
/** The signal that ended git, when the runner knows it. */
|
|
44
|
+
signal?: NodeJS.Signals | null | undefined;
|
|
45
|
+
/** The `CommandFailed` this was classified from. */
|
|
46
|
+
cause: CommandFailed;
|
|
47
|
+
}
|
|
48
|
+
/** The git failure for a failed `git` run. */
|
|
49
|
+
export declare function classifyGitFailure(failed: CommandFailed): GitFailure;
|
|
50
|
+
/**
|
|
51
|
+
* One line for a person that names the git command: `git <verb>: <message>`,
|
|
52
|
+
* then the hint when there is one. The classified `message` alone does not say
|
|
53
|
+
* which command failed, so use this when the failure reaches a log or a status
|
|
54
|
+
* file without its surrounding code.
|
|
55
|
+
*/
|
|
56
|
+
export declare function describeGitFailure(failure: GitFailure): string;
|
|
57
|
+
/**
|
|
58
|
+
* What the plain door throws for a failed git call: a `FailureError` carrying
|
|
59
|
+
* the {@link GitFailure} that {@link classifyGitFailure} reads from it, with the
|
|
60
|
+
* `CommandFailed` as its `cause`. Its `message` is {@link describeGitFailure},
|
|
61
|
+
* so it names the command that failed. Anything else is returned as it is. The
|
|
62
|
+
* classified kind (a signed-out remote, an unreachable one) is what lets a CLI
|
|
63
|
+
* that reports a thrown failure number it, which a bare `CommandFailed` with
|
|
64
|
+
* only command-seam's kinds cannot.
|
|
65
|
+
*/
|
|
66
|
+
export declare function gitFailureError(error: unknown): unknown;
|
|
67
|
+
/**
|
|
68
|
+
* The failure a thrown value carries, recognised by shape so two installed
|
|
69
|
+
* copies of command-seam or result agree; `null` for any other throw. A bare
|
|
70
|
+
* `CommandFailed` is classified here.
|
|
71
|
+
*/
|
|
72
|
+
export declare function thrownGitFailure(error: unknown): GitFailure | null;
|
package/dist/failure.js
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* {@link GitFailure}: a failed git call, classified. The `git.try.*` door
|
|
3
|
+
* returns it as the error of a `Result`; its `cause` is the `CommandFailed`
|
|
4
|
+
* it was read from.
|
|
5
|
+
*
|
|
6
|
+
* The git-specific kinds come from git's stderr, matched in English. Git
|
|
7
|
+
* translates its messages under a non-English locale; those fall through to the
|
|
8
|
+
* subprocess layer's kind, so an unrecognised failure is still an `exit` with
|
|
9
|
+
* git's first stderr line as its message, never a wrong git kind.
|
|
10
|
+
*/
|
|
11
|
+
import { classifyFailure, isCommandFailed, } from '@osdlc/command-seam';
|
|
12
|
+
import { describe, FailureError, isFailure } from '@osdlc/result';
|
|
13
|
+
const INSTALL_HINT = 'Install git from https://git-scm.com.';
|
|
14
|
+
/** The git failure for a failed `git` run. */
|
|
15
|
+
export function classifyGitFailure(failed) {
|
|
16
|
+
// The client's runner may not name its binary; this is git either way, so
|
|
17
|
+
// the messages say `git` rather than "The command".
|
|
18
|
+
const f = failed.binary === undefined
|
|
19
|
+
? (classifyFailure(failed.result, { binary: 'git', argv: failed.argv }) ?? failed.failure)
|
|
20
|
+
: failed.failure;
|
|
21
|
+
const base = { ...f, cause: failed };
|
|
22
|
+
if (f.kind === 'not-installed')
|
|
23
|
+
return { ...base, hint: INSTALL_HINT };
|
|
24
|
+
if (f.kind !== 'exit')
|
|
25
|
+
return base;
|
|
26
|
+
// git's own words: stderr, then the stdout some commands explain with.
|
|
27
|
+
const text = `${failed.result.stderr}\n${failed.result.stdout}`;
|
|
28
|
+
const remote = /No such remote:? '([^']+)'/.exec(text)?.[1];
|
|
29
|
+
const notARemote = /fatal: '([^']+)' does not appear to be a git repository/.exec(text)?.[1];
|
|
30
|
+
if (/not a git repository/i.test(text)) {
|
|
31
|
+
return {
|
|
32
|
+
...base,
|
|
33
|
+
kind: 'not-a-repo',
|
|
34
|
+
message: 'This is not a git repository.',
|
|
35
|
+
hint: 'Run it inside a git repository, or create one with `git init`.',
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
if (/No such remote/.test(text)) {
|
|
39
|
+
return {
|
|
40
|
+
...base,
|
|
41
|
+
kind: 'no-remote',
|
|
42
|
+
message: remote === undefined
|
|
43
|
+
? 'That remote does not exist.'
|
|
44
|
+
: `The remote '${remote}' does not exist.`,
|
|
45
|
+
hint: 'List the remotes with `git remote -v`.',
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
if (/Authentication failed|Permission denied \(publickey\)|could not read (Username|Password)/i.test(text)) {
|
|
49
|
+
return {
|
|
50
|
+
...base,
|
|
51
|
+
kind: 'not-authenticated',
|
|
52
|
+
message: 'The remote refused the credentials.',
|
|
53
|
+
hint: 'Check that you are signed in to the host, or that your SSH key is added.',
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
// "unable to access" with a status means the host answered. A refusal or a
|
|
57
|
+
// wrong URL will not clear up by retrying, so it must not read as unreachable.
|
|
58
|
+
const status = /unable to access[^\n]*returned error: (\d{3})/.exec(text)?.[1];
|
|
59
|
+
if (status === '401' || status === '403') {
|
|
60
|
+
return {
|
|
61
|
+
...base,
|
|
62
|
+
kind: 'not-authenticated',
|
|
63
|
+
message: 'The remote refused the credentials.',
|
|
64
|
+
hint: 'Check that you are signed in to the host, or that your SSH key is added.',
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
if (status === '404') {
|
|
68
|
+
return {
|
|
69
|
+
...base,
|
|
70
|
+
kind: 'not-found',
|
|
71
|
+
message: 'The remote repository was not found, or you cannot see it.',
|
|
72
|
+
hint: 'Check the remote URL, and that your account can see the repository.',
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
if (/unable to access[^\n]*SSL certificate problem|SSL certificate problem/i.test(text)) {
|
|
76
|
+
return {
|
|
77
|
+
...base,
|
|
78
|
+
kind: 'tls',
|
|
79
|
+
message: "The remote's TLS certificate could not be verified.",
|
|
80
|
+
hint: "Check the system clock and CA certificates, or the remote's certificate.",
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
if (notARemote !== undefined) {
|
|
84
|
+
return {
|
|
85
|
+
...base,
|
|
86
|
+
kind: 'no-remote',
|
|
87
|
+
message: `The remote '${notARemote}' does not exist or is not a git repository.`,
|
|
88
|
+
hint: 'List the remotes with `git remote -v`.',
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
if (/Could not read from remote repository|Could not resolve host|unable to access/.test(text)) {
|
|
92
|
+
return {
|
|
93
|
+
...base,
|
|
94
|
+
kind: 'remote-unreachable',
|
|
95
|
+
message: 'The remote could not be reached.',
|
|
96
|
+
hint: 'Check your network connection and the remote URL.',
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
return base;
|
|
100
|
+
}
|
|
101
|
+
/** The git verb a failure ran, past any leading `-c <k=v>` / `-C <dir>` options (other global options are expected in their `--opt=value` form); `undefined` when argv has none. */
|
|
102
|
+
function gitVerb(argv) {
|
|
103
|
+
for (let i = 0; i < argv.length; i++) {
|
|
104
|
+
const arg = argv[i];
|
|
105
|
+
if (arg === '-c' || arg === '-C')
|
|
106
|
+
i++;
|
|
107
|
+
else if (!arg.startsWith('-'))
|
|
108
|
+
return arg;
|
|
109
|
+
}
|
|
110
|
+
return undefined;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* One line for a person that names the git command: `git <verb>: <message>`,
|
|
114
|
+
* then the hint when there is one. The classified `message` alone does not say
|
|
115
|
+
* which command failed, so use this when the failure reaches a log or a status
|
|
116
|
+
* file without its surrounding code.
|
|
117
|
+
*/
|
|
118
|
+
export function describeGitFailure(failure) {
|
|
119
|
+
const verb = gitVerb(failure.argv);
|
|
120
|
+
const line = describe(failure);
|
|
121
|
+
return verb === undefined ? `git: ${line}` : `git ${verb}: ${line}`;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* What the plain door throws for a failed git call: a `FailureError` carrying
|
|
125
|
+
* the {@link GitFailure} that {@link classifyGitFailure} reads from it, with the
|
|
126
|
+
* `CommandFailed` as its `cause`. Its `message` is {@link describeGitFailure},
|
|
127
|
+
* so it names the command that failed. Anything else is returned as it is. The
|
|
128
|
+
* classified kind (a signed-out remote, an unreachable one) is what lets a CLI
|
|
129
|
+
* that reports a thrown failure number it, which a bare `CommandFailed` with
|
|
130
|
+
* only command-seam's kinds cannot.
|
|
131
|
+
*/
|
|
132
|
+
export function gitFailureError(error) {
|
|
133
|
+
if (!isCommandFailed(error))
|
|
134
|
+
return error;
|
|
135
|
+
const failure = classifyGitFailure(error);
|
|
136
|
+
// FailureError's message is the bare sentence; this door adds the command.
|
|
137
|
+
const thrown = new FailureError(failure);
|
|
138
|
+
thrown.message = describeGitFailure(failure);
|
|
139
|
+
return thrown;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* The failure a thrown value carries, recognised by shape so two installed
|
|
143
|
+
* copies of command-seam or result agree; `null` for any other throw. A bare
|
|
144
|
+
* `CommandFailed` is classified here.
|
|
145
|
+
*/
|
|
146
|
+
export function thrownGitFailure(error) {
|
|
147
|
+
if (isCommandFailed(error))
|
|
148
|
+
return classifyGitFailure(error);
|
|
149
|
+
if (typeof error === 'object' && error !== null) {
|
|
150
|
+
const carried = error.failure;
|
|
151
|
+
if (isFailure(carried))
|
|
152
|
+
return carried;
|
|
153
|
+
}
|
|
154
|
+
return null;
|
|
155
|
+
}
|
package/dist/git-url.d.ts
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
* else throws; `try` inspects; `raw` bypasses.** Each verb names the exit
|
|
18
18
|
* codes that mean "not there" for it — an unset config key, a ref that does
|
|
19
19
|
* not resolve — and those return `null` / `[]` / `false`. Every other non-zero
|
|
20
|
-
* exit throws
|
|
20
|
+
* exit throws the classified failure, so "git broke" is distinct from "nothing there".
|
|
21
21
|
* `git.try.*` is the door for callers that must tolerate failure; `git.soft.*`
|
|
22
22
|
* for those whose fallback is the verb's own absence value.
|
|
23
23
|
*
|
|
@@ -34,4 +34,3 @@ export * from './client.ts';
|
|
|
34
34
|
export { parseGitUrl, gitSshUrl, parseRepoRef, type GitHostInfo, type RepoRef, type CloneProtocol, } from './git-url.ts';
|
|
35
35
|
export { checkoutRoot, discoverCheckouts, scanForCheckouts, DEFAULT_MAX_DEPTH, DEFAULT_WARN_AFTER, } from './checkout-root.ts';
|
|
36
36
|
export type { CheckoutScan, DiscoverCheckoutsOptions } from './checkout-root.ts';
|
|
37
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
* else throws; `try` inspects; `raw` bypasses.** Each verb names the exit
|
|
18
18
|
* codes that mean "not there" for it — an unset config key, a ref that does
|
|
19
19
|
* not resolve — and those return `null` / `[]` / `false`. Every other non-zero
|
|
20
|
-
* exit throws
|
|
20
|
+
* exit throws the classified failure, so "git broke" is distinct from "nothing there".
|
|
21
21
|
* `git.try.*` is the door for callers that must tolerate failure; `git.soft.*`
|
|
22
22
|
* for those whose fallback is the verb's own absence value.
|
|
23
23
|
*
|