@osdlc/typed-git 0.15.0 → 0.16.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 +10 -0
- package/README.md +57 -13
- package/dist/async.d.ts +26 -7
- package/dist/async.js +27 -7
- package/dist/backend.d.ts +24 -11
- package/dist/backend.js +27 -18
- package/dist/client.d.ts +4 -4
- package/dist/client.js +3 -3
- package/dist/failure.d.ts +9 -0
- package/dist/failure.js +15 -0
- package/dist/outcome.d.ts +7 -6
- package/dist/sync.d.ts +42 -9
- package/dist/sync.js +50 -9
- package/dist/verbs.d.ts +47 -8
- package/dist/verbs.js +47 -10
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# @osdlc/typed-git
|
|
2
2
|
|
|
3
|
+
## 0.16.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- cde222c: Byte-exact output. `rawBytes(argv, opts)` and `rawBytesChecked(argv, opts)` on `Git` and `AsyncGit` return stdout as a `Buffer`, the bytes git wrote, for output that is hashed or replayed: a blob, `status -z` with names that are not UTF-8, `diff --binary` of a file in another encoding. `rawBytesChecked` fails as `rawChecked` does. They run on a new `bytesRunner` option on `Git` and `cliBackend`, which defaults to command-seam's bytes runner when no `runner` is given. A client given a `runner` and no `bytesRunner` throws `UnsupportedRequest` from both, so an injected runner is never bypassed. All three are experimental, as command-seam's bytes runners are. `input` is still a string.
|
|
8
|
+
|
|
9
|
+
`statusEntries({ ignored: true })` adds `--ignored` and reports each ignored file as a `{ x: '!', y: '!' }` entry. `diffText(rev, { binary: true })` adds `--binary`, so a binary file's change is a patch `git apply` replays. `StatusEntriesOptions` is exported, and so are `spawnRunnerBytes`, `spawnRunnerBytesAsync`, `BytesCommandRunner` and `AsyncBytesCommandRunner` from command-seam.
|
|
10
|
+
|
|
11
|
+
The experimental backend seam gets a `rawBytes` request kind, and the `statusEntries` and `diffText` requests take the optional `ignored` and `binary` fields. A backend that ignores them answers without ignored files and without binary patches.
|
|
12
|
+
|
|
3
13
|
## 0.15.0
|
|
4
14
|
|
|
5
15
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -707,7 +707,7 @@ exit throws the classified failure.
|
|
|
707
707
|
| `symbolicRef(ref)` | `symbolic-ref <ref>` | `128` → `null` |
|
|
708
708
|
| `currentBranch()` | `branch --show-current` | none — `null` when detached |
|
|
709
709
|
| `statusPorcelain({ paths })` | `status --porcelain` | none |
|
|
710
|
-
| `statusEntries()` | `status --porcelain -z --untracked-files=all` | none — `{ x, y, path }` rows; a rename is one row, with the source dropped |
|
|
710
|
+
| `statusEntries({ ignored })` | `status --porcelain -z --untracked-files=all [--ignored]` | none — `{ x, y, path }` rows; a rename is one row, with the source dropped; `ignored` adds each ignored file as a `!` row |
|
|
711
711
|
| `isDirty({ paths })` | `statusPorcelain().length > 0` | none |
|
|
712
712
|
| `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 |
|
|
713
713
|
| `branches(pattern)` | `branch --list --format=%(refname:lstrip=2)` | none |
|
|
@@ -731,7 +731,7 @@ exit throws the classified failure.
|
|
|
731
731
|
| `diffNameStatus({ cached, range, noRenames, paths })` | `diff --name-status -z` | none |
|
|
732
732
|
| `diffStat({ rangeArgs, paths })` | `diff --stat` | none — raw stdout |
|
|
733
733
|
| `diffCheck({ paths })` | `diff --check` | `1`, `2` → `{ ok: false, output }` |
|
|
734
|
-
| `diffText(rev?, { staged, paths })` | `diff [--cached] [rev]` | none — empty string only when nothing differs; a bad rev or a non-repository throws |
|
|
734
|
+
| `diffText(rev?, { staged, binary, paths })` | `diff [--cached] [--binary] [rev]` | none — empty string only when nothing differs; a bad rev or a non-repository throws; `binary` writes a binary file's change as a patch `git apply` replays |
|
|
735
735
|
| `diffAddedFile(relPath)` | `diff --no-index -- /dev/null <path>` | none — exit 1 with output is success; exit 1 with no output, or exit 2, throws |
|
|
736
736
|
| `log(opts)` | `log` | none — raw stdout, unsplit |
|
|
737
737
|
| `logLines(opts)` | `log`, split and filtered | none |
|
|
@@ -811,6 +811,8 @@ other non-zero exit throws.
|
|
|
811
811
|
| --- | --- |
|
|
812
812
|
| `raw(argv, opts)` | Run anything. Returns `CommandResult`; you read `exitCode`. |
|
|
813
813
|
| `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. |
|
|
814
|
+
| `rawBytes(argv, opts)` | `raw` with stdout as a `Buffer`: the bytes git wrote, never decoded. Experimental. |
|
|
815
|
+
| `rawBytesChecked(argv, opts)` | `rawChecked` with stdout as a `Buffer`. Experimental. |
|
|
814
816
|
| `at(cwd)` | The same client rooted elsewhere, reusing the runner or backend. |
|
|
815
817
|
| `try.*` | The whole surface again, returning `Result<T, GitFailure>` (from `@osdlc/result`) instead of throwing. |
|
|
816
818
|
| `soft.*` | Every verb with an absence value, returning it instead of throwing. |
|
|
@@ -820,6 +822,44 @@ several refs in one transaction, or a patch from `diff --unified`. A git
|
|
|
820
822
|
command gets its own verb only when it has a parser worth sharing or an
|
|
821
823
|
absence worth declaring.
|
|
822
824
|
|
|
825
|
+
### Byte-exact output
|
|
826
|
+
|
|
827
|
+
Every verb, `raw` and `rawChecked` decode stdout as UTF-8. Bytes that are not
|
|
828
|
+
valid UTF-8 become U+FFFD, so a blob, a file name or a patch line in another
|
|
829
|
+
encoding changes on the way. `rawBytes` and `rawBytesChecked` return stdout
|
|
830
|
+
as the bytes git wrote. Stderr stays text, and a failure reads as it does for
|
|
831
|
+
`rawChecked`.
|
|
832
|
+
|
|
833
|
+
```ts
|
|
834
|
+
const blob = git.rawBytesChecked(["cat-file", "blob", "HEAD:logo.png"]).stdout;
|
|
835
|
+
createHash("sha256").update(blob).digest("hex"); // the hash of the blob itself
|
|
836
|
+
|
|
837
|
+
git.rawBytesChecked(["status", "--porcelain", "-z", "--ignored"]).stdout; // names as stored
|
|
838
|
+
git.rawBytesChecked(["diff", "--cached", "--binary"]).stdout; // a patch, byte for byte
|
|
839
|
+
```
|
|
840
|
+
|
|
841
|
+
They run on a second runner, `bytesRunner` (a `BytesCommandRunner` on `Git`,
|
|
842
|
+
an `AsyncBytesCommandRunner` on `cliBackend`). Without a `runner` it defaults
|
|
843
|
+
to command-seam's bytes runner, with the same absolute-`PATH` rule. A client
|
|
844
|
+
given a `runner` and no `bytesRunner` throws `UnsupportedRequest` from both,
|
|
845
|
+
so a fake or a supervised runner is never bypassed by a default spawn:
|
|
846
|
+
|
|
847
|
+
```ts
|
|
848
|
+
new Git(cwd, { runner: fake, bytesRunner: fakeBytes });
|
|
849
|
+
new AsyncGit(cwd, { backend: cliBackend({ runner, bytesRunner }) });
|
|
850
|
+
```
|
|
851
|
+
|
|
852
|
+
They are experimental because command-seam's bytes runners are. `input` is
|
|
853
|
+
still a string, so bytes cannot be piped in yet (see [Limits](#limits)).
|
|
854
|
+
|
|
855
|
+
Two verb options cover the common byte-sensitive cases without dropping to
|
|
856
|
+
`rawBytes`. `statusEntries({ ignored: true })` adds each ignored file as a
|
|
857
|
+
`{ x: "!", y: "!" }` row. `diffText(rev, { binary: true })` writes a binary
|
|
858
|
+
file's change as a `GIT binary patch`, which is ASCII, so the string holds it
|
|
859
|
+
intact and `rawChecked(["apply"], { input: patch })` replays it. A text file
|
|
860
|
+
whose lines are not UTF-8 still loses bytes in `diffText`. Read that patch
|
|
861
|
+
with `rawBytesChecked`.
|
|
862
|
+
|
|
823
863
|
## Driving the CLI, or something else
|
|
824
864
|
|
|
825
865
|
`AsyncGit` calls a `GitBackend`, which takes a `GitRequest` (a plain,
|
|
@@ -843,7 +883,7 @@ await new AsyncGit(cwd, { backend }).worktrees(); // UnsupportedReques
|
|
|
843
883
|
```
|
|
844
884
|
|
|
845
885
|
Because a request is data, it can also be logged, queued, or replayed. The
|
|
846
|
-
|
|
886
|
+
exceptions are `raw` and `rawBytes`, which are argv by definition.
|
|
847
887
|
|
|
848
888
|
## Injecting the subprocess seam
|
|
849
889
|
|
|
@@ -892,13 +932,15 @@ A fake without the pin must answer `["--version"]` (once per runner) with
|
|
|
892
932
|
|
|
893
933
|
`runner: undefined` is the same as omitting it, so a caller holding an optional
|
|
894
934
|
runner passes it straight through, without a conditional spread. `cliBackend`
|
|
895
|
-
accepts it too.
|
|
935
|
+
accepts it too. The same holds for `bytesRunner`, the runner behind
|
|
936
|
+
`rawBytes` (see [Byte-exact output](#byte-exact-output)). A fake `runner`
|
|
937
|
+
needs a fake `bytesRunner` beside it before `rawBytes` can run.
|
|
896
938
|
|
|
897
939
|
The runner and result types, `CommandFailed`, `spawnRunner`, `spawnRunnerAsync`,
|
|
898
|
-
`
|
|
899
|
-
so wiring a runner or catching
|
|
900
|
-
two. Import other runners, such
|
|
901
|
-
`@osdlc/command-seam`.
|
|
940
|
+
`spawnRunnerBytes`, `spawnRunnerBytesAsync`, `runChecked`, `runCheckedAsync`
|
|
941
|
+
and `asAsync` are re-exported from command-seam, so wiring a runner or catching
|
|
942
|
+
a `CommandFailed` needs one import rather than two. Import other runners, such
|
|
943
|
+
as `streamRunner`, from `@osdlc/command-seam`.
|
|
902
944
|
|
|
903
945
|
## Also: git references
|
|
904
946
|
|
|
@@ -1056,11 +1098,13 @@ de-duplicate.
|
|
|
1056
1098
|
the classified failure. `AsyncGit` has no such cap. The `maxOutputBytes` call
|
|
1057
1099
|
option sets the cap for one call on either client. Output cut short at a
|
|
1058
1100
|
cap or a timeout is a failure, never an answer.
|
|
1059
|
-
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1101
|
+
- Verbs return text. Only `rawBytes` and `rawBytesChecked` return stdout as
|
|
1102
|
+
bytes. `input` is a string on every call, `rawBytes` and `hashObject` too,
|
|
1103
|
+
because command-seam takes stdin as a string. For binary stdin, such as
|
|
1104
|
+
`hash-object --stdin` on a binary file or `apply` of a patch read with
|
|
1105
|
+
`rawBytes`, write the bytes to a file and pass its path
|
|
1106
|
+
(`hash-object <file>`, `apply <file>`). See
|
|
1107
|
+
[D-04](docs/planning/decisions/D-04-byte-output.md).
|
|
1064
1108
|
- Output is captured, never streamed. For live progress from `clone` or
|
|
1065
1109
|
`fetch`, run git through command-seam's `streamRunner`.
|
|
1066
1110
|
- `Git` cannot cancel a call. `AsyncGit` takes a `signal`.
|
package/dist/async.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ import { type GitBackend, type GitCallOptions } from './backend.ts';
|
|
|
17
17
|
import type { GitVersion } from './git-version.ts';
|
|
18
18
|
import { type Soft, type TriedAsync } from './outcome.ts';
|
|
19
19
|
import { type RemoteCoordinate } from './remote-url.ts';
|
|
20
|
-
import { type AddOptions, type AheadBehind, type CherryEntry, type CommitTreeOptions, type CommitOptions, type HashObjectOptions, type MktreeEntry, type UpdateRefOptions, type CheckoutOptions, type ConfigGetOptions, type CloneOptions, type ConflictSide, type MergeOptions, type MergeOutcome, type MergeTreeOptions, type MergeTreeOutcome, type RebaseOptions, type RebaseOutcome, type RemoteGetUrlOptions, type IndexSubmodule, 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
|
+
import { type AddOptions, type AheadBehind, type CherryEntry, type CommitTreeOptions, type CommitOptions, type HashObjectOptions, type MktreeEntry, type UpdateRefOptions, type CheckoutOptions, type ConfigGetOptions, type CloneOptions, type ConflictSide, type MergeOptions, type MergeOutcome, type MergeTreeOptions, type MergeTreeOutcome, type RebaseOptions, type RebaseOutcome, type RemoteGetUrlOptions, type IndexSubmodule, 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 StatusEntriesOptions, type StatusEntry, type StatusPorcelainOptions, type TreeEntry, type Worktree, type WorktreeAddOptions, type WorktreeMoveOptions, type GcOptions, type PushOptions, type RemoteSetBranchesOptions, type RemoteSetHeadOptions } from './verbs.ts';
|
|
21
21
|
/** A typed, awaitable git client bound to one working directory. */
|
|
22
22
|
export declare class AsyncGit {
|
|
23
23
|
readonly cwd: string;
|
|
@@ -44,9 +44,9 @@ export declare class AsyncGit {
|
|
|
44
44
|
* Every method again, resolving to a `Result<T, GitFailure>` instead of
|
|
45
45
|
* rejecting. A declared absence is `ok: true`; see `./outcome.ts`.
|
|
46
46
|
*
|
|
47
|
-
* The type leaves out `raw
|
|
48
|
-
* wraps them too: `git.try.raw(argv)`
|
|
49
|
-
* Call those
|
|
47
|
+
* The type leaves out the `raw*` methods
|
|
48
|
+
* and `at`, but at runtime the proxy wraps them too: `git.try.raw(argv)`
|
|
49
|
+
* resolves to `{ ok: true, value }`. Call those on the client itself.
|
|
50
50
|
*/
|
|
51
51
|
get try(): TriedAsync<AsyncGit>;
|
|
52
52
|
/**
|
|
@@ -56,7 +56,7 @@ export declare class AsyncGit {
|
|
|
56
56
|
* `null` both for a missing ref and for a broken repo. Use `try` when the
|
|
57
57
|
* failure itself matters.
|
|
58
58
|
*
|
|
59
|
-
* As with `try`, the proxy also wraps `raw
|
|
59
|
+
* As with `try`, the proxy also wraps the `raw*` methods and `at` at
|
|
60
60
|
* runtime, though the type leaves them out.
|
|
61
61
|
*/
|
|
62
62
|
get soft(): Soft<AsyncGit>;
|
|
@@ -75,6 +75,25 @@ export declare class AsyncGit {
|
|
|
75
75
|
rawChecked(argv: string[], opts?: GitCallOptions & {
|
|
76
76
|
input?: string | undefined;
|
|
77
77
|
}): Promise<CommandResult>;
|
|
78
|
+
/**
|
|
79
|
+
* {@link AsyncGit.raw} with stdout as the bytes git wrote, never decoded.
|
|
80
|
+
* Rejects with `UnsupportedRequest` when the backend has no bytes
|
|
81
|
+
* runner (see `cliBackend`), as a non-CLI backend does. See {@link Git.rawBytes}.
|
|
82
|
+
*
|
|
83
|
+
* @experimental command-seam's bytes runners are experimental.
|
|
84
|
+
*/
|
|
85
|
+
rawBytes(argv: string[], opts?: GitCallOptions & {
|
|
86
|
+
input?: string | undefined;
|
|
87
|
+
}): Promise<CommandResult<Buffer>>;
|
|
88
|
+
/**
|
|
89
|
+
* {@link AsyncGit.rawBytes} that rejects with the classified failure, as
|
|
90
|
+
* {@link AsyncGit.rawChecked} does. See {@link Git.rawBytesChecked}.
|
|
91
|
+
*
|
|
92
|
+
* @experimental command-seam's bytes runners are experimental.
|
|
93
|
+
*/
|
|
94
|
+
rawBytesChecked(argv: string[], opts?: GitCallOptions & {
|
|
95
|
+
input?: string | undefined;
|
|
96
|
+
}): Promise<CommandResult<Buffer>>;
|
|
78
97
|
/**
|
|
79
98
|
* The git the backend runs, from `git --version`; see {@link Git.version}.
|
|
80
99
|
* `cliBackend` probes once per runner and caches it, or returns its
|
|
@@ -127,8 +146,8 @@ export declare class AsyncGit {
|
|
|
127
146
|
* outside a repository. `paths` narrows the report to those pathspecs.
|
|
128
147
|
*/
|
|
129
148
|
statusPorcelain(opts?: GitCallOptions & StatusPorcelainOptions): Promise<string[]>;
|
|
130
|
-
/** Every changed or untracked file,
|
|
131
|
-
statusEntries(opts?: GitCallOptions): Promise<StatusEntry[]>;
|
|
149
|
+
/** Every changed or untracked file, and ignored ones with `ignored`. See {@link Git.statusEntries}. */
|
|
150
|
+
statusEntries(opts?: GitCallOptions & StatusEntriesOptions): Promise<StatusEntry[]>;
|
|
132
151
|
/** True iff anything is staged. See {@link Git.hasStagedChanges}. */
|
|
133
152
|
hasStagedChanges(opts?: GitCallOptions): Promise<boolean>;
|
|
134
153
|
/** True iff the working tree has any staged/unstaged/untracked change. */
|
package/dist/async.js
CHANGED
|
@@ -59,9 +59,9 @@ export class AsyncGit {
|
|
|
59
59
|
* Every method again, resolving to a `Result<T, GitFailure>` instead of
|
|
60
60
|
* rejecting. A declared absence is `ok: true`; see `./outcome.ts`.
|
|
61
61
|
*
|
|
62
|
-
* The type leaves out `raw
|
|
63
|
-
* wraps them too: `git.try.raw(argv)`
|
|
64
|
-
* Call those
|
|
62
|
+
* The type leaves out the `raw*` methods
|
|
63
|
+
* and `at`, but at runtime the proxy wraps them too: `git.try.raw(argv)`
|
|
64
|
+
* resolves to `{ ok: true, value }`. Call those on the client itself.
|
|
65
65
|
*/
|
|
66
66
|
get try() {
|
|
67
67
|
return (this.tried ??= triedAsync(this));
|
|
@@ -73,7 +73,7 @@ export class AsyncGit {
|
|
|
73
73
|
* `null` both for a missing ref and for a broken repo. Use `try` when the
|
|
74
74
|
* failure itself matters.
|
|
75
75
|
*
|
|
76
|
-
* As with `try`, the proxy also wraps `raw
|
|
76
|
+
* As with `try`, the proxy also wraps the `raw*` methods and `at` at
|
|
77
77
|
* runtime, though the type leaves them out.
|
|
78
78
|
*/
|
|
79
79
|
get soft() {
|
|
@@ -96,6 +96,25 @@ export class AsyncGit {
|
|
|
96
96
|
rawChecked(argv, opts = {}) {
|
|
97
97
|
return this.backend.execute(this.cwd, { kind: 'raw', argv, checked: true, input: opts.input }, opts);
|
|
98
98
|
}
|
|
99
|
+
/**
|
|
100
|
+
* {@link AsyncGit.raw} with stdout as the bytes git wrote, never decoded.
|
|
101
|
+
* Rejects with `UnsupportedRequest` when the backend has no bytes
|
|
102
|
+
* runner (see `cliBackend`), as a non-CLI backend does. See {@link Git.rawBytes}.
|
|
103
|
+
*
|
|
104
|
+
* @experimental command-seam's bytes runners are experimental.
|
|
105
|
+
*/
|
|
106
|
+
rawBytes(argv, opts = {}) {
|
|
107
|
+
return this.backend.execute(this.cwd, { kind: 'rawBytes', argv, input: opts.input }, opts);
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* {@link AsyncGit.rawBytes} that rejects with the classified failure, as
|
|
111
|
+
* {@link AsyncGit.rawChecked} does. See {@link Git.rawBytesChecked}.
|
|
112
|
+
*
|
|
113
|
+
* @experimental command-seam's bytes runners are experimental.
|
|
114
|
+
*/
|
|
115
|
+
rawBytesChecked(argv, opts = {}) {
|
|
116
|
+
return this.backend.execute(this.cwd, { kind: 'rawBytes', argv, checked: true, input: opts.input }, opts);
|
|
117
|
+
}
|
|
99
118
|
// ── queries ───────────────────────────────────────────────────────────────
|
|
100
119
|
/**
|
|
101
120
|
* The git the backend runs, from `git --version`; see {@link Git.version}.
|
|
@@ -190,9 +209,10 @@ export class AsyncGit {
|
|
|
190
209
|
const [call, req] = splitCallOptions(opts);
|
|
191
210
|
return this.backend.execute(this.cwd, { kind: 'statusPorcelain', ...req }, call);
|
|
192
211
|
}
|
|
193
|
-
/** Every changed or untracked file,
|
|
212
|
+
/** Every changed or untracked file, and ignored ones with `ignored`. See {@link Git.statusEntries}. */
|
|
194
213
|
statusEntries(opts = {}) {
|
|
195
|
-
|
|
214
|
+
const [call, req] = splitCallOptions(opts);
|
|
215
|
+
return this.backend.execute(this.cwd, { kind: 'statusEntries', ...req }, call);
|
|
196
216
|
}
|
|
197
217
|
/** True iff anything is staged. See {@link Git.hasStagedChanges}. */
|
|
198
218
|
hasStagedChanges(opts = {}) {
|
|
@@ -289,7 +309,7 @@ export class AsyncGit {
|
|
|
289
309
|
*/
|
|
290
310
|
diffText(rev, opts = {}) {
|
|
291
311
|
const [call, req] = splitCallOptions(opts);
|
|
292
|
-
return this.backend.execute(this.cwd, { kind: 'diffText', rev, staged: req.staged, paths: req.paths }, call);
|
|
312
|
+
return this.backend.execute(this.cwd, { kind: 'diffText', rev, staged: req.staged, binary: req.binary, paths: req.paths }, call);
|
|
293
313
|
}
|
|
294
314
|
/**
|
|
295
315
|
* One untracked file rendered as an all-added diff. A path git cannot read
|
package/dist/backend.d.ts
CHANGED
|
@@ -9,17 +9,17 @@
|
|
|
9
9
|
* the same client work with either.
|
|
10
10
|
*
|
|
11
11
|
* It also means a request can be logged, queued, or replayed as data. The
|
|
12
|
-
*
|
|
13
|
-
*
|
|
12
|
+
* exceptions are `raw` and `rawBytes`, which are argv by definition. A non-CLI
|
|
13
|
+
* backend rejects them with {@link UnsupportedRequest}.
|
|
14
14
|
*
|
|
15
15
|
* The interface is experimental: `GitBackend`, `GitRequest`, `GitResults` and
|
|
16
16
|
* `partialBackend`. Each new verb adds a request kind, which breaks a backend
|
|
17
17
|
* written as an exhaustive switch. Such a change can land in a minor release.
|
|
18
18
|
* `cliBackend` and `AsyncGit` are stable.
|
|
19
19
|
*/
|
|
20
|
-
import { type AsyncCommandRunner, type CommandResult } from '@osdlc/command-seam';
|
|
20
|
+
import { type AsyncBytesCommandRunner, type AsyncCommandRunner, type CommandResult } from '@osdlc/command-seam';
|
|
21
21
|
import { type GitVersion } from './git-version.ts';
|
|
22
|
-
import { type AddOptions, type AheadBehind, type CherryEntry, type CommitTreeOptions, type HashObjectOptions, type MktreeEntry, type UpdateRefOptions, 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 IndexSubmodule, type TaggedFile, type UnmergedEntry, type Worktree, type WorktreeMoveOptions } from './verbs.ts';
|
|
22
|
+
import { type AddOptions, type AheadBehind, type CherryEntry, type CommitTreeOptions, type HashObjectOptions, type MktreeEntry, type UpdateRefOptions, 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 StatusEntriesOptions, type StatusEntry, type StatusPorcelainOptions, type TreeEntry, type IndexSubmodule, type TaggedFile, type UnmergedEntry, type Worktree, type WorktreeMoveOptions } from './verbs.ts';
|
|
23
23
|
/** Per-call concerns that are not part of the operation itself. */
|
|
24
24
|
export interface GitCallOptions {
|
|
25
25
|
/**
|
|
@@ -88,9 +88,9 @@ export type GitRequest = {
|
|
|
88
88
|
kind: 'currentBranch';
|
|
89
89
|
} | ({
|
|
90
90
|
kind: 'statusPorcelain';
|
|
91
|
-
} & StatusPorcelainOptions) | {
|
|
91
|
+
} & StatusPorcelainOptions) | ({
|
|
92
92
|
kind: 'statusEntries';
|
|
93
|
-
} | {
|
|
93
|
+
} & StatusEntriesOptions) | {
|
|
94
94
|
kind: 'branches';
|
|
95
95
|
pattern?: string | undefined;
|
|
96
96
|
} | {
|
|
@@ -298,6 +298,11 @@ export type GitRequest = {
|
|
|
298
298
|
argv: string[];
|
|
299
299
|
input?: string | undefined;
|
|
300
300
|
checked?: boolean | undefined;
|
|
301
|
+
} | {
|
|
302
|
+
kind: 'rawBytes';
|
|
303
|
+
argv: string[];
|
|
304
|
+
input?: string | undefined;
|
|
305
|
+
checked?: boolean | undefined;
|
|
301
306
|
};
|
|
302
307
|
/**
|
|
303
308
|
* The result type each request kind resolves to.
|
|
@@ -387,6 +392,7 @@ export interface GitResults {
|
|
|
387
392
|
remoteSetBranches: void;
|
|
388
393
|
gc: void;
|
|
389
394
|
raw: CommandResult;
|
|
395
|
+
rawBytes: CommandResult<Buffer>;
|
|
390
396
|
}
|
|
391
397
|
/** Every request kind, as a union of string literals. */
|
|
392
398
|
export type GitRequestKind = GitRequest['kind'];
|
|
@@ -411,20 +417,27 @@ export type GitRequestKind = GitRequest['kind'];
|
|
|
411
417
|
export interface GitBackend {
|
|
412
418
|
execute<R extends GitRequest>(cwd: string, request: R, opts?: GitCallOptions): Promise<GitResults[R['kind']]>;
|
|
413
419
|
}
|
|
414
|
-
/** Thrown by a backend asked for an operation it cannot perform. */
|
|
415
|
-
export declare class UnsupportedRequest extends Error {
|
|
416
|
-
readonly kind: string;
|
|
417
|
-
constructor(kind: string, backend: string);
|
|
418
|
-
}
|
|
419
420
|
/**
|
|
420
421
|
* The default backend: every request becomes a `git` subprocess, run through
|
|
421
422
|
* an {@link AsyncCommandRunner} so the caller decides how spawning happens
|
|
422
423
|
* (and tests inject a fake). The default runner spawns the `git` found on an
|
|
423
424
|
* absolute `PATH` entry, so a `git` file in the checkout cannot run in its
|
|
424
425
|
* place.
|
|
426
|
+
*
|
|
427
|
+
* `rawBytes` runs on a second runner, `bytesRunner`, which keeps stdout as
|
|
428
|
+
* bytes. Without `runner` it defaults to `spawnRunnerBytesAsync` with the same
|
|
429
|
+
* `PATH` rule. A backend given a `runner` and no `bytesRunner` rejects
|
|
430
|
+
* `rawBytes` with {@link UnsupportedRequest}, so a fake or a supervised runner
|
|
431
|
+
* is never bypassed by a default spawn.
|
|
425
432
|
*/
|
|
426
433
|
export declare function cliBackend(opts?: {
|
|
427
434
|
runner?: AsyncCommandRunner | undefined;
|
|
435
|
+
/**
|
|
436
|
+
* The runner for `rawBytes`. See the function doc for its default.
|
|
437
|
+
*
|
|
438
|
+
* @experimental command-seam's bytes runners are experimental.
|
|
439
|
+
*/
|
|
440
|
+
bytesRunner?: AsyncBytesCommandRunner | undefined;
|
|
428
441
|
/**
|
|
429
442
|
* The repository to work on, added to every call as `--git-dir` /
|
|
430
443
|
* `--work-tree`. They are set on the backend, not on `GitRequest`, because
|
package/dist/backend.js
CHANGED
|
@@ -9,28 +9,20 @@
|
|
|
9
9
|
* the same client work with either.
|
|
10
10
|
*
|
|
11
11
|
* It also means a request can be logged, queued, or replayed as data. The
|
|
12
|
-
*
|
|
13
|
-
*
|
|
12
|
+
* exceptions are `raw` and `rawBytes`, which are argv by definition. A non-CLI
|
|
13
|
+
* backend rejects them with {@link UnsupportedRequest}.
|
|
14
14
|
*
|
|
15
15
|
* The interface is experimental: `GitBackend`, `GitRequest`, `GitResults` and
|
|
16
16
|
* `partialBackend`. Each new verb adds a request kind, which breaks a backend
|
|
17
17
|
* written as an exhaustive switch. Such a change can land in a minor release.
|
|
18
18
|
* `cliBackend` and `AsyncGit` are stable.
|
|
19
19
|
*/
|
|
20
|
-
import { spawnRunnerAsync, } from '@osdlc/command-seam';
|
|
20
|
+
import { spawnRunnerAsync, spawnRunnerBytesAsync, } from '@osdlc/command-seam';
|
|
21
|
+
import { UnsupportedRequest } from "./failure.js";
|
|
21
22
|
import { versionedVerb } from "./features.js";
|
|
22
23
|
import { pinnedGitVersion, probeGitVersionAsync, versionVerb, } from "./git-version.js";
|
|
23
24
|
import * as v from "./verbs.js";
|
|
24
|
-
import { gate, mergeEnv, repoPrefix, } from "./verbs.js";
|
|
25
|
-
/** Thrown by a backend asked for an operation it cannot perform. */
|
|
26
|
-
export class UnsupportedRequest extends Error {
|
|
27
|
-
kind;
|
|
28
|
-
constructor(kind, backend) {
|
|
29
|
-
super(`${backend} cannot perform '${kind}'`);
|
|
30
|
-
this.name = 'UnsupportedRequest';
|
|
31
|
-
this.kind = kind;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
25
|
+
import { bytesRunnerFor, gate, gateBytes, mergeEnv, repoPrefix, } from "./verbs.js";
|
|
34
26
|
/** Translate a request into the CLI verb that performs it. */
|
|
35
27
|
function toVerb(request) {
|
|
36
28
|
switch (request.kind) {
|
|
@@ -59,7 +51,7 @@ function toVerb(request) {
|
|
|
59
51
|
case 'statusPorcelain':
|
|
60
52
|
return v.statusPorcelain(request);
|
|
61
53
|
case 'statusEntries':
|
|
62
|
-
return v.statusEntries();
|
|
54
|
+
return v.statusEntries(request);
|
|
63
55
|
case 'branches':
|
|
64
56
|
return v.branches(request.pattern);
|
|
65
57
|
case 'worktrees':
|
|
@@ -216,9 +208,16 @@ function toVerb(request) {
|
|
|
216
208
|
* (and tests inject a fake). The default runner spawns the `git` found on an
|
|
217
209
|
* absolute `PATH` entry, so a `git` file in the checkout cannot run in its
|
|
218
210
|
* place.
|
|
211
|
+
*
|
|
212
|
+
* `rawBytes` runs on a second runner, `bytesRunner`, which keeps stdout as
|
|
213
|
+
* bytes. Without `runner` it defaults to `spawnRunnerBytesAsync` with the same
|
|
214
|
+
* `PATH` rule. A backend given a `runner` and no `bytesRunner` rejects
|
|
215
|
+
* `rawBytes` with {@link UnsupportedRequest}, so a fake or a supervised runner
|
|
216
|
+
* is never bypassed by a default spawn.
|
|
219
217
|
*/
|
|
220
218
|
export function cliBackend(opts = {}) {
|
|
221
219
|
const runner = opts.runner ?? spawnRunnerAsync('git', { absolutePathOnly: true });
|
|
220
|
+
const bytesRunner = bytesRunnerFor(opts, () => spawnRunnerBytesAsync('git', { absolutePathOnly: true }));
|
|
222
221
|
const pinned = pinnedGitVersion(opts.gitVersion);
|
|
223
222
|
// A failed probe names `report`: the gated verb's argv, so a missing git
|
|
224
223
|
// reads `git worktree: …` rather than `git --version: …`.
|
|
@@ -233,7 +232,6 @@ export function cliBackend(opts = {}) {
|
|
|
233
232
|
const prefix = repoPrefix(opts.gitDir, opts.workTree);
|
|
234
233
|
return {
|
|
235
234
|
async execute(cwd, request, callOpts = {}) {
|
|
236
|
-
const gated = toVerb(request);
|
|
237
235
|
const runOpts = { cwd };
|
|
238
236
|
if (callOpts.timeoutMs !== undefined)
|
|
239
237
|
runOpts.timeoutMs = callOpts.timeoutMs;
|
|
@@ -251,6 +249,17 @@ export function cliBackend(opts = {}) {
|
|
|
251
249
|
if (req.kind === 'version') {
|
|
252
250
|
return (await versionOf(runOpts, ['--version']));
|
|
253
251
|
}
|
|
252
|
+
if (req.kind === 'rawBytes') {
|
|
253
|
+
if (bytesRunner === undefined) {
|
|
254
|
+
throw new UnsupportedRequest(req.kind, 'cliBackend with a runner and no bytesRunner');
|
|
255
|
+
}
|
|
256
|
+
if (req.input !== undefined)
|
|
257
|
+
runOpts.input = req.input;
|
|
258
|
+
const argv = prefix.length === 0 ? req.argv : [...prefix, ...req.argv];
|
|
259
|
+
const result = await bytesRunner.run(argv, runOpts);
|
|
260
|
+
return (req.checked === true ? gateBytes(result, argv) : result);
|
|
261
|
+
}
|
|
262
|
+
const gated = toVerb(req);
|
|
254
263
|
// A verb that needs a git feature runs in the form this git supports,
|
|
255
264
|
// or rejects as `unsupported-git`. Others never probe.
|
|
256
265
|
const verb = gated.needs === undefined
|
|
@@ -263,9 +272,9 @@ export function cliBackend(opts = {}) {
|
|
|
263
272
|
runOpts.env = { ...runOpts.env, ...verb.env };
|
|
264
273
|
const argv = prefix.length === 0 ? verb.argv : [...prefix, ...verb.argv];
|
|
265
274
|
const result = await runner.run(argv, runOpts);
|
|
266
|
-
// Unchecked `raw
|
|
267
|
-
// result at any exit code. Everything
|
|
268
|
-
// the sync client uses.
|
|
275
|
+
// Unchecked `raw`, and unchecked `rawBytes` above, are the only requests
|
|
276
|
+
// that skip `gate`: they return the result at any exit code. Everything
|
|
277
|
+
// else goes through the same `gate` the sync client uses.
|
|
269
278
|
const checked = req.kind !== 'raw' || req.checked === true;
|
|
270
279
|
// The prefixed argv is what ran, so it is what a `CommandFailed` reports.
|
|
271
280
|
const value = checked ? gate(verb, result, argv) : verb.parse(result, argv);
|
package/dist/client.d.ts
CHANGED
|
@@ -17,10 +17,10 @@
|
|
|
17
17
|
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
|
-
export { cliBackend, partialBackend,
|
|
21
|
-
export { classifyGitFailure, describeGitFailure, type GitFailure, type GitFailureKind, } from './failure.ts';
|
|
20
|
+
export { cliBackend, partialBackend, type GitBackend, type GitCallOptions, type GitRequest, type GitRequestKind, type GitResults, } from './backend.ts';
|
|
21
|
+
export { classifyGitFailure, describeGitFailure, UnsupportedRequest, type GitFailure, type GitFailureKind, } from './failure.ts';
|
|
22
22
|
export { type Soft, type TriedAsync, type TriedSync } from './outcome.ts';
|
|
23
23
|
export { GIT_FEATURES, GIT_FLOOR, gitSupports, type GitFeature, type GitFeatureSpec, type GitRelease, type UnsupportedGit, } from './features.ts';
|
|
24
24
|
export { compareGitVersions, parseGitVersion, type GitVersion } from './git-version.ts';
|
|
25
|
-
export { forceWithLeaseArg, parseRefRows, PUSH_REJECTIONS, REF_FORMAT, type AddOptions, type AheadBehind, type CherryEntry, type CommitTreeOptions, 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 GcOptions, type GrepOptions, type HashObjectOptions, type InitOptions, type IntegrationOutcome, type LogOptions, type IgnoreMatch, type LsFilesOptions, type LsRemoteOptions, type LsTreeOptions, type MergeOptions, type MergeOutcome, type MergeTreeOptions, type MergeTreeOutcome, type MktreeEntry, type NumstatEntry, type PushFlag, type PushOptions, type PushRefResult, type PushRejection, type PushRejectionInfo, type PushReport, type RebaseOptions, type RebaseOutcome, type RemoteGetUrlOptions, type RemoteRef, type RemoteSetBranchesOptions, type RemoteSetHeadOptions, type StatusEntry, type StatusPorcelainOptions, type IndexSubmodule, type TaggedFile, type TreeEntry, type UnmergedEntry, type UpdateRefOptions, type Worktree, type WorktreeAddOptions, type WorktreeMoveOptions, } from './verbs.ts';
|
|
26
|
-
export { asAsync, CommandFailed, runChecked, runCheckedAsync, spawnRunner, spawnRunnerAsync, type AsyncCommandRunner, type AsyncCommandRunOptions, type CommandResult, type CommandRunner, type CommandRunOptions, } from '@osdlc/command-seam';
|
|
25
|
+
export { forceWithLeaseArg, parseRefRows, PUSH_REJECTIONS, REF_FORMAT, type AddOptions, type AheadBehind, type CherryEntry, type CommitTreeOptions, 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 GcOptions, type GrepOptions, type HashObjectOptions, type InitOptions, type IntegrationOutcome, type LogOptions, type IgnoreMatch, type LsFilesOptions, type LsRemoteOptions, type LsTreeOptions, type MergeOptions, type MergeOutcome, type MergeTreeOptions, type MergeTreeOutcome, type MktreeEntry, type NumstatEntry, type PushFlag, type PushOptions, type PushRefResult, type PushRejection, type PushRejectionInfo, type PushReport, type RebaseOptions, type RebaseOutcome, type RemoteGetUrlOptions, type RemoteRef, type RemoteSetBranchesOptions, type RemoteSetHeadOptions, type StatusEntriesOptions, type StatusEntry, type StatusPorcelainOptions, type IndexSubmodule, type TaggedFile, type TreeEntry, type UnmergedEntry, type UpdateRefOptions, type Worktree, type WorktreeAddOptions, type WorktreeMoveOptions, } from './verbs.ts';
|
|
26
|
+
export { asAsync, CommandFailed, runChecked, runCheckedAsync, spawnRunner, spawnRunnerAsync, spawnRunnerBytes, spawnRunnerBytesAsync, type AsyncBytesCommandRunner, type AsyncCommandRunner, type AsyncCommandRunOptions, type BytesCommandRunner, type CommandResult, type CommandRunner, type CommandRunOptions, } from '@osdlc/command-seam';
|
package/dist/client.js
CHANGED
|
@@ -17,8 +17,8 @@
|
|
|
17
17
|
export { Git } from "./sync.js";
|
|
18
18
|
export { AsyncGit } from "./async.js";
|
|
19
19
|
export { parseRemoteUrl } from "./remote-url.js";
|
|
20
|
-
export { cliBackend, partialBackend,
|
|
21
|
-
export { classifyGitFailure, describeGitFailure, } from "./failure.js";
|
|
20
|
+
export { cliBackend, partialBackend, } from "./backend.js";
|
|
21
|
+
export { classifyGitFailure, describeGitFailure, UnsupportedRequest, } from "./failure.js";
|
|
22
22
|
export {} from "./outcome.js";
|
|
23
23
|
export { GIT_FEATURES, GIT_FLOOR, gitSupports, } from "./features.js";
|
|
24
24
|
export { compareGitVersions, parseGitVersion } from "./git-version.js";
|
|
@@ -26,4 +26,4 @@ export { forceWithLeaseArg, parseRefRows, PUSH_REJECTIONS, REF_FORMAT, } from ".
|
|
|
26
26
|
// The command-seam exports are re-exported so a caller wiring a runner or catching
|
|
27
27
|
// a failure needs one import, not two. `@osdlc/command-seam` is the package
|
|
28
28
|
// that owns these; it is usable on its own, without a git client.
|
|
29
|
-
export { asAsync, CommandFailed, runChecked, runCheckedAsync, spawnRunner, spawnRunnerAsync, } from '@osdlc/command-seam';
|
|
29
|
+
export { asAsync, CommandFailed, runChecked, runCheckedAsync, spawnRunner, spawnRunnerAsync, spawnRunnerBytes, spawnRunnerBytesAsync, } from '@osdlc/command-seam';
|
package/dist/failure.d.ts
CHANGED
|
@@ -84,3 +84,12 @@ export declare function gitFailureError(error: unknown): unknown;
|
|
|
84
84
|
* `CommandFailed` is classified here.
|
|
85
85
|
*/
|
|
86
86
|
export declare function thrownGitFailure(error: unknown): GitFailure | null;
|
|
87
|
+
/**
|
|
88
|
+
* Thrown by a backend asked for an operation it cannot perform, and by a
|
|
89
|
+
* client asked for one its runners cannot run (`rawBytes` on a `Git` given a
|
|
90
|
+
* `runner` and no `bytesRunner`). It is not a {@link GitFailure}: no git ran.
|
|
91
|
+
*/
|
|
92
|
+
export declare class UnsupportedRequest extends Error {
|
|
93
|
+
readonly kind: string;
|
|
94
|
+
constructor(kind: string, backend: string);
|
|
95
|
+
}
|
package/dist/failure.js
CHANGED
|
@@ -146,3 +146,18 @@ export function thrownGitFailure(error) {
|
|
|
146
146
|
}
|
|
147
147
|
return null;
|
|
148
148
|
}
|
|
149
|
+
/**
|
|
150
|
+
* Thrown by a backend asked for an operation it cannot perform, and by a
|
|
151
|
+
* client asked for one its runners cannot run (`rawBytes` on a `Git` given a
|
|
152
|
+
* `runner` and no `bytesRunner`). It is not a {@link GitFailure}: no git ran.
|
|
153
|
+
*/
|
|
154
|
+
// Lives here, not in backend.ts, so the sync client can throw it without
|
|
155
|
+
// importing the async backend.
|
|
156
|
+
export class UnsupportedRequest extends Error {
|
|
157
|
+
kind;
|
|
158
|
+
constructor(kind, backend) {
|
|
159
|
+
super(`${backend} cannot perform '${kind}'`);
|
|
160
|
+
this.name = 'UnsupportedRequest';
|
|
161
|
+
this.kind = kind;
|
|
162
|
+
}
|
|
163
|
+
}
|
package/dist/outcome.d.ts
CHANGED
|
@@ -20,13 +20,14 @@
|
|
|
20
20
|
import type { Result } from '@osdlc/result';
|
|
21
21
|
import { type GitFailure } from './failure.ts';
|
|
22
22
|
/**
|
|
23
|
-
* The methods `try` mirrors: everything except `raw
|
|
24
|
-
* and `try` itself. `raw
|
|
25
|
-
* `
|
|
26
|
-
*
|
|
27
|
-
* function property,
|
|
23
|
+
* The methods `try` mirrors: everything except the `raw*` methods, `at`,
|
|
24
|
+
* and `try` itself. The unchecked `raw*` methods already return a
|
|
25
|
+
* `CommandResult` and never throw for a failed git; the checked ones exist
|
|
26
|
+
* to throw. `at(cwd)` returns a new client that has its own `.try`. The
|
|
27
|
+
* types leave them out, but the runtime proxy wraps every function property,
|
|
28
|
+
* these included.
|
|
28
29
|
*/
|
|
29
|
-
type Triable<C> = Omit<C, 'raw' | 'rawChecked' | 'at' | 'try' | 'soft' | 'cwd'>;
|
|
30
|
+
type Triable<C> = Omit<C, 'raw' | 'rawChecked' | 'rawBytes' | 'rawBytesChecked' | 'at' | 'try' | 'soft' | 'cwd'>;
|
|
30
31
|
/** Every synchronous client method, returning a `Result<T, GitFailure>`. */
|
|
31
32
|
export type TriedSync<C> = {
|
|
32
33
|
[K in keyof Triable<C>]: Triable<C>[K] extends (...a: infer A) => infer R ? (...a: A) => Result<R, GitFailure> : never;
|
package/dist/sync.d.ts
CHANGED
|
@@ -15,11 +15,11 @@
|
|
|
15
15
|
* Not here: any protocol with its own conflict rules, such as a lease
|
|
16
16
|
* service's compare-and-swap ref operations. That is not general git.
|
|
17
17
|
*/
|
|
18
|
-
import { type CommandResult, type CommandRunner } from '@osdlc/command-seam';
|
|
18
|
+
import { type BytesCommandRunner, type CommandResult, type CommandRunner } from '@osdlc/command-seam';
|
|
19
19
|
import { type GitVersion } from './git-version.ts';
|
|
20
20
|
import { type Soft, type TriedSync } from './outcome.ts';
|
|
21
21
|
import { type RemoteCoordinate } from './remote-url.ts';
|
|
22
|
-
import { type AddOptions, type AheadBehind, type CherryEntry, type CommitTreeOptions, type CommitOptions, type HashObjectOptions, type MktreeEntry, type UpdateRefOptions, type CheckoutOptions, type ConfigGetOptions, type CloneOptions, type ConflictSide, type MergeOptions, type MergeOutcome, type MergeTreeOptions, type MergeTreeOutcome, type RebaseOptions, type RebaseOutcome, type RemoteGetUrlOptions, type IndexSubmodule, 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';
|
|
22
|
+
import { type AddOptions, type AheadBehind, type CherryEntry, type CommitTreeOptions, type CommitOptions, type HashObjectOptions, type MktreeEntry, type UpdateRefOptions, type CheckoutOptions, type ConfigGetOptions, type CloneOptions, type ConflictSide, type MergeOptions, type MergeOutcome, type MergeTreeOptions, type MergeTreeOutcome, type RebaseOptions, type RebaseOutcome, type RemoteGetUrlOptions, type IndexSubmodule, 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 StatusEntriesOptions, type StatusEntry, type StatusPorcelainOptions, type TreeEntry, type Worktree, type WorktreeAddOptions, type WorktreeMoveOptions, type GcOptions, type PushOptions, type RemoteSetBranchesOptions, type RemoteSetHeadOptions } from './verbs.ts';
|
|
23
23
|
/**
|
|
24
24
|
* Per-call concerns that are not part of the operation itself.
|
|
25
25
|
*
|
|
@@ -48,6 +48,7 @@ export interface GitSyncCallOptions {
|
|
|
48
48
|
export declare class Git {
|
|
49
49
|
readonly cwd: string;
|
|
50
50
|
private readonly runner;
|
|
51
|
+
private readonly bytesRunner;
|
|
51
52
|
private readonly boundGitDir;
|
|
52
53
|
private readonly workTree;
|
|
53
54
|
private readonly env;
|
|
@@ -84,16 +85,24 @@ export declare class Git {
|
|
|
84
85
|
* `git --version`, and {@link Git.version} returns it. Set it with a fake
|
|
85
86
|
* runner, so the fake answers only the verbs under test. An unparsable
|
|
86
87
|
* value throws a `RangeError` here.
|
|
88
|
+
*
|
|
89
|
+
* `bytesRunner` runs {@link Git.rawBytes} and {@link Git.rawBytesChecked},
|
|
90
|
+
* which keep stdout as bytes. Without `runner` it defaults to
|
|
91
|
+
* `spawnRunnerBytes` with the same `PATH` rule. A client given a `runner`
|
|
92
|
+
* and no `bytesRunner` throws `UnsupportedRequest` from those two, so a
|
|
93
|
+
* fake or a supervised runner is never bypassed by a default spawn. It is
|
|
94
|
+
* experimental, as command-seam's bytes runners are.
|
|
87
95
|
*/
|
|
88
96
|
constructor(cwd: string, opts?: {
|
|
89
97
|
runner?: CommandRunner | undefined;
|
|
98
|
+
bytesRunner?: BytesCommandRunner | undefined;
|
|
90
99
|
gitDir?: string | undefined;
|
|
91
100
|
workTree?: string | undefined;
|
|
92
101
|
env?: Record<string, string> | undefined;
|
|
93
102
|
gitVersion?: string | undefined;
|
|
94
103
|
});
|
|
95
104
|
/**
|
|
96
|
-
* The same client in a different directory, with the same
|
|
105
|
+
* The same client in a different directory, with the same runners,
|
|
97
106
|
* repository options, client-level `env` and `gitVersion`.
|
|
98
107
|
*/
|
|
99
108
|
at(cwd: string): Git;
|
|
@@ -103,9 +112,9 @@ export declare class Git {
|
|
|
103
112
|
* or `{ ok: false, error }` with a classified {@link GitFailure}.
|
|
104
113
|
* A declared absence is `ok: true`. See `./outcome.ts`.
|
|
105
114
|
*
|
|
106
|
-
* The type leaves out `raw
|
|
107
|
-
* wraps them too: `git.try.raw(argv)`
|
|
108
|
-
* those
|
|
115
|
+
* The type leaves out the `raw*` methods
|
|
116
|
+
* and `at`, but at runtime the proxy wraps them too: `git.try.raw(argv)`
|
|
117
|
+
* returns `{ ok: true, value }`. Call those on the client itself.
|
|
109
118
|
*/
|
|
110
119
|
get try(): TriedSync<Git>;
|
|
111
120
|
/**
|
|
@@ -115,7 +124,7 @@ export declare class Git {
|
|
|
115
124
|
* `null` both for a missing ref and for a broken repo. Use `try` when the
|
|
116
125
|
* failure itself matters.
|
|
117
126
|
*
|
|
118
|
-
* As with `try`, the proxy also wraps `raw
|
|
127
|
+
* As with `try`, the proxy also wraps the `raw*` methods and `at` at
|
|
119
128
|
* runtime, though the type leaves them out.
|
|
120
129
|
*/
|
|
121
130
|
get soft(): Soft<Git>;
|
|
@@ -134,6 +143,30 @@ export declare class Git {
|
|
|
134
143
|
rawChecked(argv: string[], opts?: GitSyncCallOptions & {
|
|
135
144
|
input?: string | undefined;
|
|
136
145
|
}): CommandResult;
|
|
146
|
+
/**
|
|
147
|
+
* {@link Git.raw} with stdout as the bytes git wrote, never decoded: for
|
|
148
|
+
* output that is hashed or replayed, such as a blob, `status -z` with
|
|
149
|
+
* names that are not UTF-8, or `diff --binary` of a file that is not
|
|
150
|
+
* UTF-8. Stderr is still text. Runs on the `bytesRunner`; throws
|
|
151
|
+
* `UnsupportedRequest` when the client has none (see the constructor).
|
|
152
|
+
*
|
|
153
|
+
* @experimental command-seam's bytes runners are experimental.
|
|
154
|
+
*/
|
|
155
|
+
rawBytes(argv: string[], opts?: GitSyncCallOptions & {
|
|
156
|
+
input?: string | undefined;
|
|
157
|
+
}): CommandResult<Buffer>;
|
|
158
|
+
/**
|
|
159
|
+
* {@link Git.rawBytes} that throws the classified failure on a non-zero
|
|
160
|
+
* exit, or on output cut short at the output cap or a timeout, as
|
|
161
|
+
* {@link Git.rawChecked} does. The failure's `cause.result.stdout` is the
|
|
162
|
+
* stdout decoded as UTF-8.
|
|
163
|
+
*
|
|
164
|
+
* @experimental command-seam's bytes runners are experimental.
|
|
165
|
+
*/
|
|
166
|
+
rawBytesChecked(argv: string[], opts?: GitSyncCallOptions & {
|
|
167
|
+
input?: string | undefined;
|
|
168
|
+
}): CommandResult<Buffer>;
|
|
169
|
+
private bytes;
|
|
137
170
|
/** The verb's argv, after this client's `--git-dir` / `--work-tree` flags. */
|
|
138
171
|
private argv;
|
|
139
172
|
private runOpts;
|
|
@@ -224,8 +257,8 @@ export declare class Git {
|
|
|
224
257
|
* a repository. `paths` narrows the report to those pathspecs.
|
|
225
258
|
*/
|
|
226
259
|
statusPorcelain(opts?: GitSyncCallOptions & StatusPorcelainOptions): string[];
|
|
227
|
-
/** Every changed or untracked file,
|
|
228
|
-
statusEntries(opts?: GitSyncCallOptions): StatusEntry[];
|
|
260
|
+
/** Every changed or untracked file, and ignored ones with `ignored`. See {@link statusEntries} in `verbs.ts`. */
|
|
261
|
+
statusEntries(opts?: GitSyncCallOptions & StatusEntriesOptions): StatusEntry[];
|
|
229
262
|
/**
|
|
230
263
|
* True iff anything is staged (`diff --cached --quiet` exits 1). On an
|
|
231
264
|
* unborn HEAD the index is compared against the empty tree. See
|
package/dist/sync.js
CHANGED
|
@@ -16,18 +16,20 @@
|
|
|
16
16
|
* service's compare-and-swap ref operations. That is not general git.
|
|
17
17
|
*/
|
|
18
18
|
import { basename, dirname, resolve } from 'node:path';
|
|
19
|
-
import { spawnRunner, } from '@osdlc/command-seam';
|
|
19
|
+
import { spawnRunner, spawnRunnerBytes, } from '@osdlc/command-seam';
|
|
20
|
+
import { UnsupportedRequest } from "./failure.js";
|
|
20
21
|
import { versionedVerb } from "./features.js";
|
|
21
22
|
import { pinnedGitVersion, probeGitVersion } from "./git-version.js";
|
|
22
23
|
import { softSync, triedSync } from "./outcome.js";
|
|
23
24
|
import { parseRemoteUrl } from "./remote-url.js";
|
|
24
25
|
import { SOFT_TABLE } from "./soft.js";
|
|
25
26
|
import * as v from "./verbs.js";
|
|
26
|
-
import { gate, mergeEnv, parseRefRows, repoPrefix, splitLines, splitTrailingOptions, } from "./verbs.js";
|
|
27
|
+
import { bytesRunnerFor, gate, gateBytes, mergeEnv, parseRefRows, repoPrefix, splitLines, splitTrailingOptions, } from "./verbs.js";
|
|
27
28
|
/** A typed git client bound to one working directory. */
|
|
28
29
|
export class Git {
|
|
29
30
|
cwd;
|
|
30
31
|
runner;
|
|
32
|
+
bytesRunner;
|
|
31
33
|
boundGitDir;
|
|
32
34
|
workTree;
|
|
33
35
|
env;
|
|
@@ -64,23 +66,32 @@ export class Git {
|
|
|
64
66
|
* `git --version`, and {@link Git.version} returns it. Set it with a fake
|
|
65
67
|
* runner, so the fake answers only the verbs under test. An unparsable
|
|
66
68
|
* value throws a `RangeError` here.
|
|
69
|
+
*
|
|
70
|
+
* `bytesRunner` runs {@link Git.rawBytes} and {@link Git.rawBytesChecked},
|
|
71
|
+
* which keep stdout as bytes. Without `runner` it defaults to
|
|
72
|
+
* `spawnRunnerBytes` with the same `PATH` rule. A client given a `runner`
|
|
73
|
+
* and no `bytesRunner` throws `UnsupportedRequest` from those two, so a
|
|
74
|
+
* fake or a supervised runner is never bypassed by a default spawn. It is
|
|
75
|
+
* experimental, as command-seam's bytes runners are.
|
|
67
76
|
*/
|
|
68
77
|
constructor(cwd, opts = {}) {
|
|
69
78
|
this.cwd = cwd;
|
|
70
79
|
this.gitVersionOption = opts.gitVersion;
|
|
71
80
|
this.pinnedVersion = pinnedGitVersion(opts.gitVersion);
|
|
72
81
|
this.runner = opts.runner ?? spawnRunner('git', { absolutePathOnly: true });
|
|
82
|
+
this.bytesRunner = bytesRunnerFor(opts, () => spawnRunnerBytes('git', { absolutePathOnly: true }));
|
|
73
83
|
this.boundGitDir = opts.gitDir;
|
|
74
84
|
this.workTree = opts.workTree;
|
|
75
85
|
this.env = opts.env;
|
|
76
86
|
}
|
|
77
87
|
/**
|
|
78
|
-
* The same client in a different directory, with the same
|
|
88
|
+
* The same client in a different directory, with the same runners,
|
|
79
89
|
* repository options, client-level `env` and `gitVersion`.
|
|
80
90
|
*/
|
|
81
91
|
at(cwd) {
|
|
82
92
|
return new Git(cwd, {
|
|
83
93
|
runner: this.runner,
|
|
94
|
+
bytesRunner: this.bytesRunner,
|
|
84
95
|
gitDir: this.boundGitDir,
|
|
85
96
|
workTree: this.workTree,
|
|
86
97
|
env: this.env,
|
|
@@ -93,9 +104,9 @@ export class Git {
|
|
|
93
104
|
* or `{ ok: false, error }` with a classified {@link GitFailure}.
|
|
94
105
|
* A declared absence is `ok: true`. See `./outcome.ts`.
|
|
95
106
|
*
|
|
96
|
-
* The type leaves out `raw
|
|
97
|
-
* wraps them too: `git.try.raw(argv)`
|
|
98
|
-
* those
|
|
107
|
+
* The type leaves out the `raw*` methods
|
|
108
|
+
* and `at`, but at runtime the proxy wraps them too: `git.try.raw(argv)`
|
|
109
|
+
* returns `{ ok: true, value }`. Call those on the client itself.
|
|
99
110
|
*/
|
|
100
111
|
get try() {
|
|
101
112
|
return (this.tried ??= triedSync(this));
|
|
@@ -107,7 +118,7 @@ export class Git {
|
|
|
107
118
|
* `null` both for a missing ref and for a broken repo. Use `try` when the
|
|
108
119
|
* failure itself matters.
|
|
109
120
|
*
|
|
110
|
-
* As with `try`, the proxy also wraps `raw
|
|
121
|
+
* As with `try`, the proxy also wraps the `raw*` methods and `at` at
|
|
111
122
|
* runtime, though the type leaves them out.
|
|
112
123
|
*/
|
|
113
124
|
get soft() {
|
|
@@ -135,6 +146,36 @@ export class Git {
|
|
|
135
146
|
verb.input = opts.input;
|
|
136
147
|
return this.exec(verb, opts);
|
|
137
148
|
}
|
|
149
|
+
/**
|
|
150
|
+
* {@link Git.raw} with stdout as the bytes git wrote, never decoded: for
|
|
151
|
+
* output that is hashed or replayed, such as a blob, `status -z` with
|
|
152
|
+
* names that are not UTF-8, or `diff --binary` of a file that is not
|
|
153
|
+
* UTF-8. Stderr is still text. Runs on the `bytesRunner`; throws
|
|
154
|
+
* `UnsupportedRequest` when the client has none (see the constructor).
|
|
155
|
+
*
|
|
156
|
+
* @experimental command-seam's bytes runners are experimental.
|
|
157
|
+
*/
|
|
158
|
+
rawBytes(argv, opts = {}) {
|
|
159
|
+
return this.bytes().run(this.argv(argv), this.runOpts(opts));
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* {@link Git.rawBytes} that throws the classified failure on a non-zero
|
|
163
|
+
* exit, or on output cut short at the output cap or a timeout, as
|
|
164
|
+
* {@link Git.rawChecked} does. The failure's `cause.result.stdout` is the
|
|
165
|
+
* stdout decoded as UTF-8.
|
|
166
|
+
*
|
|
167
|
+
* @experimental command-seam's bytes runners are experimental.
|
|
168
|
+
*/
|
|
169
|
+
rawBytesChecked(argv, opts = {}) {
|
|
170
|
+
const ran = this.argv(argv);
|
|
171
|
+
return gateBytes(this.bytes().run(ran, this.runOpts(opts)), ran);
|
|
172
|
+
}
|
|
173
|
+
bytes() {
|
|
174
|
+
if (this.bytesRunner === undefined) {
|
|
175
|
+
throw new UnsupportedRequest('rawBytes', 'Git with a runner and no bytesRunner');
|
|
176
|
+
}
|
|
177
|
+
return this.bytesRunner;
|
|
178
|
+
}
|
|
138
179
|
/** The verb's argv, after this client's `--git-dir` / `--work-tree` flags. */
|
|
139
180
|
argv(argv) {
|
|
140
181
|
const prefix = repoPrefix(this.boundGitDir, this.workTree);
|
|
@@ -311,9 +352,9 @@ export class Git {
|
|
|
311
352
|
statusPorcelain(opts = {}) {
|
|
312
353
|
return this.exec(v.statusPorcelain(opts), opts);
|
|
313
354
|
}
|
|
314
|
-
/** Every changed or untracked file,
|
|
355
|
+
/** Every changed or untracked file, and ignored ones with `ignored`. See {@link statusEntries} in `verbs.ts`. */
|
|
315
356
|
statusEntries(opts = {}) {
|
|
316
|
-
return this.exec(v.statusEntries(), opts);
|
|
357
|
+
return this.exec(v.statusEntries(opts), opts);
|
|
317
358
|
}
|
|
318
359
|
/**
|
|
319
360
|
* True iff anything is staged (`diff --cached --quiet` exits 1). On an
|
package/dist/verbs.d.ts
CHANGED
|
@@ -87,6 +87,22 @@ export interface GitVerb<T> {
|
|
|
87
87
|
* timeout, so a parse would read cut-short output as the whole answer.
|
|
88
88
|
*/
|
|
89
89
|
export declare function gate<T>(verb: GitVerb<T>, result: CommandResult, argv?: string[]): T;
|
|
90
|
+
/**
|
|
91
|
+
* Gate for a bytes runner's result: returns it, or throws a `FailureError`
|
|
92
|
+
* with the classified `GitFailure` on a non-zero exit, `neverExited` or
|
|
93
|
+
* `outputIncomplete`. The `CommandFailed` cause holds stdout decoded as UTF-8.
|
|
94
|
+
*/
|
|
95
|
+
export declare function gateBytes(result: CommandResult<Buffer>, argv: string[]): CommandResult<Buffer>;
|
|
96
|
+
/**
|
|
97
|
+
* The bytes runner a client runs `rawBytes` on: the `bytesRunner` passed,
|
|
98
|
+
* else the default spawn, but only when no `runner` was passed either.
|
|
99
|
+
* `undefined` means the client throws `UnsupportedRequest` from its bytes
|
|
100
|
+
* calls. See the `Git` constructor.
|
|
101
|
+
*/
|
|
102
|
+
export declare function bytesRunnerFor<B>(opts: {
|
|
103
|
+
runner?: unknown;
|
|
104
|
+
bytesRunner?: B | undefined;
|
|
105
|
+
}, spawnDefault: () => B): B | undefined;
|
|
90
106
|
/**
|
|
91
107
|
* A client-level environment bag under a per-call one, or `undefined` when
|
|
92
108
|
* neither is set (so the runner inherits the parent environment untouched
|
|
@@ -292,14 +308,26 @@ export interface StatusEntry {
|
|
|
292
308
|
/** The path; for a rename or copy, the destination. */
|
|
293
309
|
path: string;
|
|
294
310
|
}
|
|
311
|
+
/** Options for {@link statusEntries}. */
|
|
312
|
+
export interface StatusEntriesOptions {
|
|
313
|
+
/**
|
|
314
|
+
* `--ignored`: report ignored files too, as entries whose `x` and `y` are
|
|
315
|
+
* both `'!'`. This verb always passes `--untracked-files=all`, so each
|
|
316
|
+
* ignored file is its own entry, inside an ignored directory too.
|
|
317
|
+
*/
|
|
318
|
+
ignored?: boolean | undefined;
|
|
319
|
+
}
|
|
295
320
|
/**
|
|
296
321
|
* Every changed or untracked file as a {@link StatusEntry}
|
|
297
|
-
* (`git status --porcelain -z --untracked-files=all`
|
|
298
|
-
* are expanded to their files. Paths are
|
|
299
|
-
* or copy yields one entry (its source
|
|
300
|
-
* tree; throws outside a repository.
|
|
322
|
+
* (`git status --porcelain -z --untracked-files=all`, plus `--ignored` with
|
|
323
|
+
* `ignored`). Untracked directories are expanded to their files. Paths are
|
|
324
|
+
* verbatim, never quoted, and a rename or copy yields one entry (its source
|
|
325
|
+
* path is dropped). Empty on a clean tree; throws outside a repository.
|
|
326
|
+
*
|
|
327
|
+
* Paths are decoded as UTF-8, so a name that is not valid UTF-8 comes back
|
|
328
|
+
* with U+FFFD in it. Read such names through `rawBytesChecked`.
|
|
301
329
|
*/
|
|
302
|
-
export declare function statusEntries(): GitVerb<StatusEntry[]>;
|
|
330
|
+
export declare function statusEntries(opts?: StatusEntriesOptions): GitVerb<StatusEntry[]>;
|
|
303
331
|
/**
|
|
304
332
|
* Local branch names matching `pattern` (all when omitted). The name is
|
|
305
333
|
* `refs/heads/` stripped, never `%(refname:short)`, which answers
|
|
@@ -717,13 +745,24 @@ export interface DiffTreeOptions {
|
|
|
717
745
|
export interface DiffTextOptions {
|
|
718
746
|
/** `--cached` — diff the index against `rev` (or HEAD) rather than the worktree. */
|
|
719
747
|
staged?: boolean | undefined;
|
|
748
|
+
/**
|
|
749
|
+
* `--binary`: write a binary file's change as a `GIT binary patch` that
|
|
750
|
+
* `git apply` can replay, instead of the one line `Binary files … differ`.
|
|
751
|
+
* The patch is ASCII (base85), so the decode to a string keeps it intact.
|
|
752
|
+
*/
|
|
753
|
+
binary?: boolean | undefined;
|
|
720
754
|
/** Pathspecs, passed after `--`. */
|
|
721
755
|
paths?: string[] | undefined;
|
|
722
756
|
}
|
|
723
757
|
/**
|
|
724
|
-
* The unified diff text (`git diff [--cached] [rev] [-- paths]`),
|
|
725
|
-
* rev and staged shape {@link diffNameOnly} selects paths for.
|
|
726
|
-
* nothing differs.
|
|
758
|
+
* The unified diff text (`git diff [--cached] [--binary] [rev] [-- paths]`),
|
|
759
|
+
* for the same rev and staged shape {@link diffNameOnly} selects paths for.
|
|
760
|
+
* Empty when nothing differs.
|
|
761
|
+
*
|
|
762
|
+
* The text is decoded as UTF-8. A text file whose lines are not valid UTF-8
|
|
763
|
+
* comes back with U+FFFD in them, and the patch no longer applies. For a
|
|
764
|
+
* patch that must replay byte for byte, run the same argv through
|
|
765
|
+
* `rawBytesChecked`.
|
|
727
766
|
*
|
|
728
767
|
* `absent: []`. A rev that does not resolve exits 128, and outside a
|
|
729
768
|
* repository `git diff` exits 129. Both throw, so "git failed" never reads as
|
package/dist/verbs.js
CHANGED
|
@@ -51,6 +51,30 @@ export function gate(verb, result, argv) {
|
|
|
51
51
|
throw gitFailureError(error);
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
|
+
/**
|
|
55
|
+
* Gate for a bytes runner's result: returns it, or throws a `FailureError`
|
|
56
|
+
* with the classified `GitFailure` on a non-zero exit, `neverExited` or
|
|
57
|
+
* `outputIncomplete`. The `CommandFailed` cause holds stdout decoded as UTF-8.
|
|
58
|
+
*/
|
|
59
|
+
export function gateBytes(result, argv) {
|
|
60
|
+
try {
|
|
61
|
+
if (runFailed(result))
|
|
62
|
+
throw new CommandFailed(argv, result);
|
|
63
|
+
return result;
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
throw gitFailureError(error);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* The bytes runner a client runs `rawBytes` on: the `bytesRunner` passed,
|
|
71
|
+
* else the default spawn, but only when no `runner` was passed either.
|
|
72
|
+
* `undefined` means the client throws `UnsupportedRequest` from its bytes
|
|
73
|
+
* calls. See the `Git` constructor.
|
|
74
|
+
*/
|
|
75
|
+
export function bytesRunnerFor(opts, spawnDefault) {
|
|
76
|
+
return opts.bytesRunner ?? (opts.runner === undefined ? spawnDefault() : undefined);
|
|
77
|
+
}
|
|
54
78
|
/**
|
|
55
79
|
* A client-level environment bag under a per-call one, or `undefined` when
|
|
56
80
|
* neither is set (so the runner inherits the parent environment untouched
|
|
@@ -371,14 +395,20 @@ export function statusPorcelain(opts = {}) {
|
|
|
371
395
|
}
|
|
372
396
|
/**
|
|
373
397
|
* Every changed or untracked file as a {@link StatusEntry}
|
|
374
|
-
* (`git status --porcelain -z --untracked-files=all`
|
|
375
|
-
* are expanded to their files. Paths are
|
|
376
|
-
* or copy yields one entry (its source
|
|
377
|
-
* tree; throws outside a repository.
|
|
378
|
-
|
|
379
|
-
|
|
398
|
+
* (`git status --porcelain -z --untracked-files=all`, plus `--ignored` with
|
|
399
|
+
* `ignored`). Untracked directories are expanded to their files. Paths are
|
|
400
|
+
* verbatim, never quoted, and a rename or copy yields one entry (its source
|
|
401
|
+
* path is dropped). Empty on a clean tree; throws outside a repository.
|
|
402
|
+
*
|
|
403
|
+
* Paths are decoded as UTF-8, so a name that is not valid UTF-8 comes back
|
|
404
|
+
* with U+FFFD in it. Read such names through `rawBytesChecked`.
|
|
405
|
+
*/
|
|
406
|
+
export function statusEntries(opts = {}) {
|
|
407
|
+
const argv = ['status', '--porcelain', '-z', '--untracked-files=all'];
|
|
408
|
+
if (opts.ignored === true)
|
|
409
|
+
argv.push('--ignored');
|
|
380
410
|
return {
|
|
381
|
-
argv
|
|
411
|
+
argv,
|
|
382
412
|
absent: NONE,
|
|
383
413
|
parse(r) {
|
|
384
414
|
const fields = nulFields(r);
|
|
@@ -963,9 +993,14 @@ export function lsTree(rev, opts = {}) {
|
|
|
963
993
|
};
|
|
964
994
|
}
|
|
965
995
|
/**
|
|
966
|
-
* The unified diff text (`git diff [--cached] [rev] [-- paths]`),
|
|
967
|
-
* rev and staged shape {@link diffNameOnly} selects paths for.
|
|
968
|
-
* nothing differs.
|
|
996
|
+
* The unified diff text (`git diff [--cached] [--binary] [rev] [-- paths]`),
|
|
997
|
+
* for the same rev and staged shape {@link diffNameOnly} selects paths for.
|
|
998
|
+
* Empty when nothing differs.
|
|
999
|
+
*
|
|
1000
|
+
* The text is decoded as UTF-8. A text file whose lines are not valid UTF-8
|
|
1001
|
+
* comes back with U+FFFD in them, and the patch no longer applies. For a
|
|
1002
|
+
* patch that must replay byte for byte, run the same argv through
|
|
1003
|
+
* `rawBytesChecked`.
|
|
969
1004
|
*
|
|
970
1005
|
* `absent: []`. A rev that does not resolve exits 128, and outside a
|
|
971
1006
|
* repository `git diff` exits 129. Both throw, so "git failed" never reads as
|
|
@@ -975,6 +1010,8 @@ export function diffText(rev, opts = {}) {
|
|
|
975
1010
|
const argv = ['diff'];
|
|
976
1011
|
if (opts.staged === true)
|
|
977
1012
|
argv.push('--cached');
|
|
1013
|
+
if (opts.binary === true)
|
|
1014
|
+
argv.push('--binary');
|
|
978
1015
|
const from = optionalPositional('diffText', 'rev', rev);
|
|
979
1016
|
if (from !== undefined)
|
|
980
1017
|
argv.push(from);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@osdlc/typed-git",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.0",
|
|
4
4
|
"description": "A typed git client for TypeScript, sync and awaitable. Each verb declares what absence means for it; every other failure throws. git.try.* inspects, raw() bypasses — over an injectable backend that drives the git CLI or any other implementation.",
|
|
5
5
|
"license": "MIT OR Apache-2.0",
|
|
6
6
|
"author": "sksizer",
|
|
@@ -63,8 +63,8 @@
|
|
|
63
63
|
"typescript": "~6.0.3",
|
|
64
64
|
"typescript59": "npm:typescript@5.9.3",
|
|
65
65
|
"vitest": "^5.0.5",
|
|
66
|
-
"@osdlc/
|
|
67
|
-
"@osdlc/
|
|
66
|
+
"@osdlc/prettier-config": "^0.3.1",
|
|
67
|
+
"@osdlc/tsconfig": "^0.4.1"
|
|
68
68
|
},
|
|
69
69
|
"scripts": {
|
|
70
70
|
"build": "tsc -p tsconfig.build.json",
|