@osdlc/typed-git 0.15.0 → 0.17.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 +26 -0
- package/README.md +92 -17
- 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 +81 -13
- package/dist/verbs.js +114 -27
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
# @osdlc/typed-git
|
|
2
2
|
|
|
3
|
+
## 0.17.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 6236a97: `diffText`, `diffAddedFile` and `diffNameStatus` pass fixed flags that pin their output against the git settings named below, and `diffText` and `diffNameStatus` never read a rev as a path.
|
|
8
|
+
|
|
9
|
+
- `diffText` and `diffAddedFile` always pass `--no-color --no-ext-diff --no-textconv --src-prefix=a/ --dst-prefix=b/ --no-relative --submodule=short --unified=3`. Their text is a plain unified diff with `a/` and `b/` prefixes and three lines of context under `color.ui`, `color.diff`, `diff.external`, a `diff.<driver>.command` or textconv driver, `diff.noprefix`, `diff.mnemonicPrefix`, `diff.srcPrefix`, `diff.dstPrefix`, `diff.relative`, `diff.submodule` and `diff.context`, so none of those settings stops `git apply` taking it. Other settings still apply: rename detection (`diff.renames`), `diff.ignoreSubmodules` and `diff.algorithm`, and the `GIT_DIFF_OPTS` environment variable, where `-u0` overrides the three lines of context. These are the two verbs whose output changes under a colour setting.
|
|
10
|
+
- `diffNameStatus` always passes `--no-color --no-relative`. `--no-color` is a guard: git never coloured that output.
|
|
11
|
+
- **Breaking:** under `diff.relative=true` with a cwd below the repository root, `diffNameStatus` and `diffText` now give paths relative to the root and list changes outside the cwd, where they gave paths relative to the cwd and left those changes out.
|
|
12
|
+
- **Breaking:** `diffText` and `diffNameStatus` pass `--` after the rev or range, with or without paths. A rev that names a file but no revision now throws, where it returned that file's diff. A branch that shares its name with a file or folder now works, where git refused it as ambiguous.
|
|
13
|
+
- `diffStat`, `diffCheck`, `log` and `logLines` with no `format`, and `grep` without `noColor` still follow the user's colour setting. `diffNameOnly`, `diffStat` and `diffCheck` still follow `diff.relative`. The README's new "Diff output and the user's git configuration" section lists them.
|
|
14
|
+
- **Breaking for fake runners:** the argv of three verbs changed, so a `CommandRunner` keyed on the old argv no longer matches and gives its default reply. To migrate, key the fake on the new argv. `--` is passed once, when there is a rev, a range or a path.
|
|
15
|
+
- `diffText`: `diff --no-color --no-ext-diff --no-textconv --src-prefix=a/ --dst-prefix=b/ --no-relative --submodule=short --unified=3 [--cached] [--binary] [rev] [--] [paths]`. It was `diff [--cached] [--binary] [rev] [-- paths]`. The eight flags follow `diff`, and `--` follows a rev even with no paths.
|
|
16
|
+
- `diffAddedFile`: `diff --no-color --no-ext-diff --no-textconv --src-prefix=a/ --dst-prefix=b/ --no-relative --submodule=short --unified=3 --no-index -- /dev/null <path>`. It was `diff --no-index -- /dev/null <path>`.
|
|
17
|
+
- `diffNameStatus`: `diff --no-color --no-relative --name-status -z [--cached] [--no-renames] [range] [--] [paths]`. It was `diff --name-status -z [--cached] [--no-renames] [range] [-- paths]`. The two flags follow `diff`, and `--` follows a range even with no paths.
|
|
18
|
+
|
|
19
|
+
## 0.16.0
|
|
20
|
+
|
|
21
|
+
### Minor Changes
|
|
22
|
+
|
|
23
|
+
- 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.
|
|
24
|
+
|
|
25
|
+
`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.
|
|
26
|
+
|
|
27
|
+
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.
|
|
28
|
+
|
|
3
29
|
## 0.15.0
|
|
4
30
|
|
|
5
31
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -125,8 +125,10 @@ release, with a CHANGELOG entry that starts with `Breaking:`.
|
|
|
125
125
|
This package exists for plain TypeScript callers that want a synchronous form,
|
|
126
126
|
typed results and a declared absence value per verb.
|
|
127
127
|
|
|
128
|
-
The Rust crate `typed-git` is this
|
|
129
|
-
|
|
128
|
+
The Rust crate [`typed-git`](https://crates.io/crates/typed-git) is this
|
|
129
|
+
package's twin. Its version number is behind this package's: a later release
|
|
130
|
+
of the crate closes the gap and takes this package's number. Their APIs
|
|
131
|
+
differ.
|
|
130
132
|
|
|
131
133
|
## Quick look
|
|
132
134
|
|
|
@@ -313,6 +315,35 @@ record is two. A split written by hand often gets this wrong.
|
|
|
313
315
|
under `{ long: true }`; a tree or submodule reports `null`, because `--long`
|
|
314
316
|
prints `-` there and a fabricated `0` would be worse than nothing.
|
|
315
317
|
|
|
318
|
+
## Diff output and the user's git configuration
|
|
319
|
+
|
|
320
|
+
`diffText` and `diffAddedFile` return a plain unified diff with `a/` and `b/`
|
|
321
|
+
prefixes and three lines of context. Both always pass `--no-color`,
|
|
322
|
+
`--no-ext-diff`, `--no-textconv`, `--src-prefix=a/`, `--dst-prefix=b/`,
|
|
323
|
+
`--no-relative`, `--submodule=short` and `--unified=3`. So `color.ui`,
|
|
324
|
+
`color.diff`, `diff.external`, a `diff.<driver>.command` or textconv driver,
|
|
325
|
+
`diff.noprefix`, `diff.mnemonicPrefix`, `diff.srcPrefix`, `diff.dstPrefix`,
|
|
326
|
+
`diff.relative`, `diff.submodule` and `diff.context` do not change the text,
|
|
327
|
+
and none of them stops `git apply` taking it. Other settings still apply:
|
|
328
|
+
rename detection (`diff.renames`), `diff.ignoreSubmodules` and
|
|
329
|
+
`diff.algorithm`. The `GIT_DIFF_OPTS` environment variable also still applies:
|
|
330
|
+
`-u0` there overrides the three lines of context.
|
|
331
|
+
|
|
332
|
+
`diffNameStatus` passes `--no-relative`, so its paths are relative to the
|
|
333
|
+
repository root and cover the whole repository when the cwd is below the
|
|
334
|
+
root. It passes `--no-color` as a guard: git does not colour that output.
|
|
335
|
+
|
|
336
|
+
`diffNameOnly`, `diffStat` and `diffCheck` still follow `diff.relative`. From
|
|
337
|
+
a folder below the root their paths are relative to that folder and changes
|
|
338
|
+
outside it are left out, so their paths can differ from `diffNameStatus`'s.
|
|
339
|
+
|
|
340
|
+
These verbs follow the user's colour setting. Under `color.ui=always` their
|
|
341
|
+
output holds escape codes: `diffStat`, `diffCheck`, `log` and `logLines` with
|
|
342
|
+
no `format`, and `grep` without `noColor`. Verbs that read a fixed machine
|
|
343
|
+
format, such as `diffNameOnly`, `diffTree`, `statusPorcelain`,
|
|
344
|
+
`statusEntries`, `branches` and `worktrees`, get no escape codes: git does not
|
|
345
|
+
colour that output.
|
|
346
|
+
|
|
316
347
|
## Exit codes that are answers
|
|
317
348
|
|
|
318
349
|
Two verbs carry their answer in the exit code rather than in stdout. Both are
|
|
@@ -707,7 +738,7 @@ exit throws the classified failure.
|
|
|
707
738
|
| `symbolicRef(ref)` | `symbolic-ref <ref>` | `128` → `null` |
|
|
708
739
|
| `currentBranch()` | `branch --show-current` | none — `null` when detached |
|
|
709
740
|
| `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 |
|
|
741
|
+
| `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
742
|
| `isDirty({ paths })` | `statusPorcelain().length > 0` | none |
|
|
712
743
|
| `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
744
|
| `branches(pattern)` | `branch --list --format=%(refname:lstrip=2)` | none |
|
|
@@ -728,11 +759,11 @@ exit throws the classified failure.
|
|
|
728
759
|
| `forEachRef(pattern, { format, sort, count })` | `for-each-ref` | none — lines verbatim |
|
|
729
760
|
| `refs(pattern)` | `forEachRef` + `parseRefRows` | none |
|
|
730
761
|
| `diffNameOnly({ cached, diffFilter, rangeArgs, paths })` | `diff --name-only -z` | none |
|
|
731
|
-
| `diffNameStatus({ cached, range, noRenames, paths })` | `diff --name-status -z` | none |
|
|
762
|
+
| `diffNameStatus({ cached, range, noRenames, paths })` | `diff --no-color --no-relative --name-status -z [--cached] [--no-renames] [range] [--] [paths]` | none — `--` is passed once, when there is a range or a path, so git never reads the range as a path |
|
|
732
763
|
| `diffStat({ rangeArgs, paths })` | `diff --stat` | none — raw stdout |
|
|
733
764
|
| `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 |
|
|
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 |
|
|
765
|
+
| `diffText(rev?, { staged, binary, paths })` | `diff --no-color --no-ext-diff --no-textconv --src-prefix=a/ --dst-prefix=b/ --no-relative --submodule=short --unified=3 [--cached] [--binary] [rev] [--] [paths]` | none — empty string only when nothing differs; a bad rev or a non-repository throws; `--` is passed once, when there is a rev or a path, so git never reads the rev as a path; the text is plain under the [settings the flags pin](#diff-output-and-the-users-git-configuration); `binary` writes a binary file's change as a patch `git apply` replays |
|
|
766
|
+
| `diffAddedFile(relPath)` | `diff --no-color --no-ext-diff --no-textconv --src-prefix=a/ --dst-prefix=b/ --no-relative --submodule=short --unified=3 --no-index -- /dev/null <path>` | none — exit 1 with output is success; exit 1 with no output, or exit 2, throws; the text is plain, as for `diffText` |
|
|
736
767
|
| `log(opts)` | `log` | none — raw stdout, unsplit |
|
|
737
768
|
| `logLines(opts)` | `log`, split and filtered | none |
|
|
738
769
|
| `lsTree(rev, { recursive, long, paths })` | `ls-tree -z` | none |
|
|
@@ -811,6 +842,8 @@ other non-zero exit throws.
|
|
|
811
842
|
| --- | --- |
|
|
812
843
|
| `raw(argv, opts)` | Run anything. Returns `CommandResult`; you read `exitCode`. |
|
|
813
844
|
| `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. |
|
|
845
|
+
| `rawBytes(argv, opts)` | `raw` with stdout as a `Buffer`: the bytes git wrote, never decoded. Experimental. |
|
|
846
|
+
| `rawBytesChecked(argv, opts)` | `rawChecked` with stdout as a `Buffer`. Experimental. |
|
|
814
847
|
| `at(cwd)` | The same client rooted elsewhere, reusing the runner or backend. |
|
|
815
848
|
| `try.*` | The whole surface again, returning `Result<T, GitFailure>` (from `@osdlc/result`) instead of throwing. |
|
|
816
849
|
| `soft.*` | Every verb with an absence value, returning it instead of throwing. |
|
|
@@ -820,6 +853,44 @@ several refs in one transaction, or a patch from `diff --unified`. A git
|
|
|
820
853
|
command gets its own verb only when it has a parser worth sharing or an
|
|
821
854
|
absence worth declaring.
|
|
822
855
|
|
|
856
|
+
### Byte-exact output
|
|
857
|
+
|
|
858
|
+
Every verb, `raw` and `rawChecked` decode stdout as UTF-8. Bytes that are not
|
|
859
|
+
valid UTF-8 become U+FFFD, so a blob, a file name or a patch line in another
|
|
860
|
+
encoding changes on the way. `rawBytes` and `rawBytesChecked` return stdout
|
|
861
|
+
as the bytes git wrote. Stderr stays text, and a failure reads as it does for
|
|
862
|
+
`rawChecked`.
|
|
863
|
+
|
|
864
|
+
```ts
|
|
865
|
+
const blob = git.rawBytesChecked(["cat-file", "blob", "HEAD:logo.png"]).stdout;
|
|
866
|
+
createHash("sha256").update(blob).digest("hex"); // the hash of the blob itself
|
|
867
|
+
|
|
868
|
+
git.rawBytesChecked(["status", "--porcelain", "-z", "--ignored"]).stdout; // names as stored
|
|
869
|
+
git.rawBytesChecked(["diff", "--cached", "--binary"]).stdout; // a patch, byte for byte
|
|
870
|
+
```
|
|
871
|
+
|
|
872
|
+
They run on a second runner, `bytesRunner` (a `BytesCommandRunner` on `Git`,
|
|
873
|
+
an `AsyncBytesCommandRunner` on `cliBackend`). Without a `runner` it defaults
|
|
874
|
+
to command-seam's bytes runner, with the same absolute-`PATH` rule. A client
|
|
875
|
+
given a `runner` and no `bytesRunner` throws `UnsupportedRequest` from both,
|
|
876
|
+
so a fake or a supervised runner is never bypassed by a default spawn:
|
|
877
|
+
|
|
878
|
+
```ts
|
|
879
|
+
new Git(cwd, { runner: fake, bytesRunner: fakeBytes });
|
|
880
|
+
new AsyncGit(cwd, { backend: cliBackend({ runner, bytesRunner }) });
|
|
881
|
+
```
|
|
882
|
+
|
|
883
|
+
They are experimental because command-seam's bytes runners are. `input` is
|
|
884
|
+
still a string, so bytes cannot be piped in yet (see [Limits](#limits)).
|
|
885
|
+
|
|
886
|
+
Two verb options cover the common byte-sensitive cases without dropping to
|
|
887
|
+
`rawBytes`. `statusEntries({ ignored: true })` adds each ignored file as a
|
|
888
|
+
`{ x: "!", y: "!" }` row. `diffText(rev, { binary: true })` writes a binary
|
|
889
|
+
file's change as a `GIT binary patch`, which is ASCII, so the string holds it
|
|
890
|
+
intact and `rawChecked(["apply"], { input: patch })` replays it. A text file
|
|
891
|
+
whose lines are not UTF-8 still loses bytes in `diffText`. Read that patch
|
|
892
|
+
with `rawBytesChecked`.
|
|
893
|
+
|
|
823
894
|
## Driving the CLI, or something else
|
|
824
895
|
|
|
825
896
|
`AsyncGit` calls a `GitBackend`, which takes a `GitRequest` (a plain,
|
|
@@ -843,7 +914,7 @@ await new AsyncGit(cwd, { backend }).worktrees(); // UnsupportedReques
|
|
|
843
914
|
```
|
|
844
915
|
|
|
845
916
|
Because a request is data, it can also be logged, queued, or replayed. The
|
|
846
|
-
|
|
917
|
+
exceptions are `raw` and `rawBytes`, which are argv by definition.
|
|
847
918
|
|
|
848
919
|
## Injecting the subprocess seam
|
|
849
920
|
|
|
@@ -892,13 +963,15 @@ A fake without the pin must answer `["--version"]` (once per runner) with
|
|
|
892
963
|
|
|
893
964
|
`runner: undefined` is the same as omitting it, so a caller holding an optional
|
|
894
965
|
runner passes it straight through, without a conditional spread. `cliBackend`
|
|
895
|
-
accepts it too.
|
|
966
|
+
accepts it too. The same holds for `bytesRunner`, the runner behind
|
|
967
|
+
`rawBytes` (see [Byte-exact output](#byte-exact-output)). A fake `runner`
|
|
968
|
+
needs a fake `bytesRunner` beside it before `rawBytes` can run.
|
|
896
969
|
|
|
897
970
|
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`.
|
|
971
|
+
`spawnRunnerBytes`, `spawnRunnerBytesAsync`, `runChecked`, `runCheckedAsync`
|
|
972
|
+
and `asAsync` are re-exported from command-seam, so wiring a runner or catching
|
|
973
|
+
a `CommandFailed` needs one import rather than two. Import other runners, such
|
|
974
|
+
as `streamRunner`, from `@osdlc/command-seam`.
|
|
902
975
|
|
|
903
976
|
## Also: git references
|
|
904
977
|
|
|
@@ -1056,11 +1129,13 @@ de-duplicate.
|
|
|
1056
1129
|
the classified failure. `AsyncGit` has no such cap. The `maxOutputBytes` call
|
|
1057
1130
|
option sets the cap for one call on either client. Output cut short at a
|
|
1058
1131
|
cap or a timeout is a failure, never an answer.
|
|
1059
|
-
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1132
|
+
- Verbs return text. Only `rawBytes` and `rawBytesChecked` return stdout as
|
|
1133
|
+
bytes. `input` is a string on every call, `rawBytes` and `hashObject` too,
|
|
1134
|
+
because command-seam takes stdin as a string. For binary stdin, such as
|
|
1135
|
+
`hash-object --stdin` on a binary file or `apply` of a patch read with
|
|
1136
|
+
`rawBytes`, write the bytes to a file and pass its path
|
|
1137
|
+
(`hash-object <file>`, `apply <file>`). See
|
|
1138
|
+
[D-04](docs/planning/decisions/D-04-byte-output.md).
|
|
1064
1139
|
- Output is captured, never streamed. For live progress from `clone` or
|
|
1065
1140
|
`fetch`, run git through command-seam's `streamRunner`.
|
|
1066
1141
|
- `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
|
|
@@ -600,7 +628,15 @@ export interface DiffNameStatusOptions {
|
|
|
600
628
|
paths?: string[] | undefined;
|
|
601
629
|
}
|
|
602
630
|
/**
|
|
603
|
-
* Changed paths with their status
|
|
631
|
+
* Changed paths with their status
|
|
632
|
+
* (`git diff --no-color --no-relative --name-status -z`).
|
|
633
|
+
*
|
|
634
|
+
* `--no-relative` is always passed, so with a cwd below the repository root
|
|
635
|
+
* the paths are still relative to the root and changes outside the cwd are
|
|
636
|
+
* still listed, whatever `diff.relative` says. `--no-color` is passed as a
|
|
637
|
+
* guard: git does not colour this output. The range is followed by `--`, so
|
|
638
|
+
* git never reads it as a path: a range that names a file but no revision
|
|
639
|
+
* throws, and a branch that shares its name with a file works.
|
|
604
640
|
*
|
|
605
641
|
* `absent: []` — no changes is exit 0 with empty stdout, including before the
|
|
606
642
|
* first commit, where `--cached` diffs against the empty tree. Outside a
|
|
@@ -717,13 +753,43 @@ export interface DiffTreeOptions {
|
|
|
717
753
|
export interface DiffTextOptions {
|
|
718
754
|
/** `--cached` — diff the index against `rev` (or HEAD) rather than the worktree. */
|
|
719
755
|
staged?: boolean | undefined;
|
|
756
|
+
/**
|
|
757
|
+
* `--binary`: write a binary file's change as a `GIT binary patch` that
|
|
758
|
+
* `git apply` can replay, instead of the one line `Binary files … differ`.
|
|
759
|
+
* The patch is ASCII (base85), so the decode to a string keeps it intact.
|
|
760
|
+
*/
|
|
761
|
+
binary?: boolean | undefined;
|
|
720
762
|
/** Pathspecs, passed after `--`. */
|
|
721
763
|
paths?: string[] | undefined;
|
|
722
764
|
}
|
|
723
765
|
/**
|
|
724
|
-
* The unified diff text (`git diff
|
|
725
|
-
*
|
|
726
|
-
*
|
|
766
|
+
* The unified diff text (`git diff --no-color --no-ext-diff --no-textconv
|
|
767
|
+
* --src-prefix=a/ --dst-prefix=b/ --no-relative --submodule=short
|
|
768
|
+
* --unified=3 [--cached] [--binary] [rev] [--] [paths]`), for the same rev
|
|
769
|
+
* and staged shape {@link diffNameStatus} lists paths for. `--` is passed
|
|
770
|
+
* once, when there is a rev or a path. Empty when nothing differs.
|
|
771
|
+
* {@link diffNameOnly} selects the same paths except under `diff.relative`,
|
|
772
|
+
* which it still follows.
|
|
773
|
+
*
|
|
774
|
+
* The text is a plain unified diff with `a/` and `b/` prefixes and three
|
|
775
|
+
* lines of context. The flags that are always passed turn off colour codes
|
|
776
|
+
* (`color.ui`, `color.diff`), an external diff tool (`diff.external`, a
|
|
777
|
+
* `diff.<driver>.command`), textconv conversion, other prefixes
|
|
778
|
+
* (`diff.noprefix`, `diff.mnemonicPrefix`, `diff.srcPrefix`,
|
|
779
|
+
* `diff.dstPrefix`) and `diff.relative`, which with a cwd below the
|
|
780
|
+
* repository root would drop changes outside it. They also keep a submodule
|
|
781
|
+
* change as a `Subproject commit` patch, whatever `diff.submodule` says, and
|
|
782
|
+
* the context at three lines, whatever `diff.context` says. Other settings
|
|
783
|
+
* still apply: rename detection (`diff.renames`), `diff.ignoreSubmodules` and
|
|
784
|
+
* `diff.algorithm`; so does the `GIT_DIFF_OPTS` environment variable, where
|
|
785
|
+
* `-u0` overrides the three lines of context. The rev is followed by `--`, so git never reads it as a
|
|
786
|
+
* path: a rev that names a file but no revision throws, and a branch that
|
|
787
|
+
* shares its name with a file works.
|
|
788
|
+
*
|
|
789
|
+
* The text is decoded as UTF-8. A text file whose lines are not valid UTF-8
|
|
790
|
+
* comes back with U+FFFD in them, and the patch no longer applies. For a
|
|
791
|
+
* patch that must replay byte for byte, run the same argv through
|
|
792
|
+
* `rawBytesChecked`.
|
|
727
793
|
*
|
|
728
794
|
* `absent: []`. A rev that does not resolve exits 128, and outside a
|
|
729
795
|
* repository `git diff` exits 129. Both throw, so "git failed" never reads as
|
|
@@ -731,10 +797,12 @@ export interface DiffTextOptions {
|
|
|
731
797
|
*/
|
|
732
798
|
export declare function diffText(rev?: string | undefined, opts?: DiffTextOptions): GitVerb<string>;
|
|
733
799
|
/**
|
|
734
|
-
* One untracked file rendered as an all-added diff
|
|
735
|
-
*
|
|
736
|
-
*
|
|
737
|
-
*
|
|
800
|
+
* One untracked file rendered as an all-added diff (`diff --no-color
|
|
801
|
+
* --no-ext-diff --no-textconv --src-prefix=a/ --dst-prefix=b/ --no-relative
|
|
802
|
+
* --submodule=short --unified=3 --no-index -- /dev/null <path>`), so a new
|
|
803
|
+
* file reaches a consumer in the same shape as a modified one: the flags are
|
|
804
|
+
* the ones {@link diffText} passes, and the text is as plain. An empty
|
|
805
|
+
* existing file still gives a diff header.
|
|
738
806
|
*
|
|
739
807
|
* `--no-index` exits 1 whenever the inputs differ, which for a real file is
|
|
740
808
|
* always, so exit 1 is the success case. git also exits 1, with empty stdout,
|
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
|
|
@@ -194,6 +218,33 @@ function depthArg(verb, depth) {
|
|
|
194
218
|
function optionalPositional(verb, param, value) {
|
|
195
219
|
return value === undefined ? undefined : positional(verb, param, value);
|
|
196
220
|
}
|
|
221
|
+
/**
|
|
222
|
+
* Appends `[rev] [--] [paths]` to a `git diff` argv. `--` follows a rev even
|
|
223
|
+
* with no paths, so git never reads the rev as a path.
|
|
224
|
+
*/
|
|
225
|
+
function pushRevAndPaths(argv, rev, paths) {
|
|
226
|
+
if (rev !== undefined)
|
|
227
|
+
argv.push(rev);
|
|
228
|
+
if (rev !== undefined || (paths !== undefined && paths.length > 0))
|
|
229
|
+
argv.push('--');
|
|
230
|
+
argv.push(...(paths ?? []));
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* The `git diff` flags that pin patch text against the user's git settings:
|
|
234
|
+
* no colour codes, no external diff tool, no textconv conversion, the `a/`
|
|
235
|
+
* and `b/` prefixes, paths that are not cut to the cwd, a submodule change as
|
|
236
|
+
* a `Subproject commit` patch, and three lines of context.
|
|
237
|
+
*/
|
|
238
|
+
const PLAIN_PATCH = [
|
|
239
|
+
'--no-color',
|
|
240
|
+
'--no-ext-diff',
|
|
241
|
+
'--no-textconv',
|
|
242
|
+
'--src-prefix=a/',
|
|
243
|
+
'--dst-prefix=b/',
|
|
244
|
+
'--no-relative',
|
|
245
|
+
'--submodule=short',
|
|
246
|
+
'--unified=3',
|
|
247
|
+
];
|
|
197
248
|
/** The child env that makes git print English, whatever the caller's locale. */
|
|
198
249
|
const C_LOCALE = Object.freeze({ LC_ALL: 'C' });
|
|
199
250
|
// ── queries ─────────────────────────────────────────────────────────────────
|
|
@@ -371,14 +422,20 @@ export function statusPorcelain(opts = {}) {
|
|
|
371
422
|
}
|
|
372
423
|
/**
|
|
373
424
|
* 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
|
-
|
|
425
|
+
* (`git status --porcelain -z --untracked-files=all`, plus `--ignored` with
|
|
426
|
+
* `ignored`). Untracked directories are expanded to their files. Paths are
|
|
427
|
+
* verbatim, never quoted, and a rename or copy yields one entry (its source
|
|
428
|
+
* path is dropped). Empty on a clean tree; throws outside a repository.
|
|
429
|
+
*
|
|
430
|
+
* Paths are decoded as UTF-8, so a name that is not valid UTF-8 comes back
|
|
431
|
+
* with U+FFFD in it. Read such names through `rawBytesChecked`.
|
|
432
|
+
*/
|
|
433
|
+
export function statusEntries(opts = {}) {
|
|
434
|
+
const argv = ['status', '--porcelain', '-z', '--untracked-files=all'];
|
|
435
|
+
if (opts.ignored === true)
|
|
436
|
+
argv.push('--ignored');
|
|
380
437
|
return {
|
|
381
|
-
argv
|
|
438
|
+
argv,
|
|
382
439
|
absent: NONE,
|
|
383
440
|
parse(r) {
|
|
384
441
|
const fields = nulFields(r);
|
|
@@ -845,7 +902,15 @@ export function hasStagedChanges() {
|
|
|
845
902
|
};
|
|
846
903
|
}
|
|
847
904
|
/**
|
|
848
|
-
* Changed paths with their status
|
|
905
|
+
* Changed paths with their status
|
|
906
|
+
* (`git diff --no-color --no-relative --name-status -z`).
|
|
907
|
+
*
|
|
908
|
+
* `--no-relative` is always passed, so with a cwd below the repository root
|
|
909
|
+
* the paths are still relative to the root and changes outside the cwd are
|
|
910
|
+
* still listed, whatever `diff.relative` says. `--no-color` is passed as a
|
|
911
|
+
* guard: git does not colour this output. The range is followed by `--`, so
|
|
912
|
+
* git never reads it as a path: a range that names a file but no revision
|
|
913
|
+
* throws, and a branch that shares its name with a file works.
|
|
849
914
|
*
|
|
850
915
|
* `absent: []` — no changes is exit 0 with empty stdout, including before the
|
|
851
916
|
* first commit, where `--cached` diffs against the empty tree. Outside a
|
|
@@ -854,15 +919,13 @@ export function hasStagedChanges() {
|
|
|
854
919
|
* See {@link DiffEntry} for what a rename record costs a naive parser.
|
|
855
920
|
*/
|
|
856
921
|
export function diffNameStatus(opts = {}) {
|
|
857
|
-
const argv = ['diff', '--name-status', '-z'];
|
|
922
|
+
const argv = ['diff', '--no-color', '--no-relative', '--name-status', '-z'];
|
|
858
923
|
if (opts.cached)
|
|
859
924
|
argv.push('--cached');
|
|
860
925
|
if (opts.noRenames)
|
|
861
926
|
argv.push('--no-renames');
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
if (opts.paths !== undefined && opts.paths.length > 0)
|
|
865
|
-
argv.push('--', ...opts.paths);
|
|
927
|
+
const range = optionalPositional('diffNameStatus', 'range', opts.range);
|
|
928
|
+
pushRevAndPaths(argv, range, opts.paths);
|
|
866
929
|
return { argv, absent: NONE, parse: nameStatusEntries };
|
|
867
930
|
}
|
|
868
931
|
/**
|
|
@@ -963,30 +1026,54 @@ export function lsTree(rev, opts = {}) {
|
|
|
963
1026
|
};
|
|
964
1027
|
}
|
|
965
1028
|
/**
|
|
966
|
-
* The unified diff text (`git diff
|
|
967
|
-
*
|
|
968
|
-
*
|
|
1029
|
+
* The unified diff text (`git diff --no-color --no-ext-diff --no-textconv
|
|
1030
|
+
* --src-prefix=a/ --dst-prefix=b/ --no-relative --submodule=short
|
|
1031
|
+
* --unified=3 [--cached] [--binary] [rev] [--] [paths]`), for the same rev
|
|
1032
|
+
* and staged shape {@link diffNameStatus} lists paths for. `--` is passed
|
|
1033
|
+
* once, when there is a rev or a path. Empty when nothing differs.
|
|
1034
|
+
* {@link diffNameOnly} selects the same paths except under `diff.relative`,
|
|
1035
|
+
* which it still follows.
|
|
1036
|
+
*
|
|
1037
|
+
* The text is a plain unified diff with `a/` and `b/` prefixes and three
|
|
1038
|
+
* lines of context. The flags that are always passed turn off colour codes
|
|
1039
|
+
* (`color.ui`, `color.diff`), an external diff tool (`diff.external`, a
|
|
1040
|
+
* `diff.<driver>.command`), textconv conversion, other prefixes
|
|
1041
|
+
* (`diff.noprefix`, `diff.mnemonicPrefix`, `diff.srcPrefix`,
|
|
1042
|
+
* `diff.dstPrefix`) and `diff.relative`, which with a cwd below the
|
|
1043
|
+
* repository root would drop changes outside it. They also keep a submodule
|
|
1044
|
+
* change as a `Subproject commit` patch, whatever `diff.submodule` says, and
|
|
1045
|
+
* the context at three lines, whatever `diff.context` says. Other settings
|
|
1046
|
+
* still apply: rename detection (`diff.renames`), `diff.ignoreSubmodules` and
|
|
1047
|
+
* `diff.algorithm`; so does the `GIT_DIFF_OPTS` environment variable, where
|
|
1048
|
+
* `-u0` overrides the three lines of context. The rev is followed by `--`, so git never reads it as a
|
|
1049
|
+
* path: a rev that names a file but no revision throws, and a branch that
|
|
1050
|
+
* shares its name with a file works.
|
|
1051
|
+
*
|
|
1052
|
+
* The text is decoded as UTF-8. A text file whose lines are not valid UTF-8
|
|
1053
|
+
* comes back with U+FFFD in them, and the patch no longer applies. For a
|
|
1054
|
+
* patch that must replay byte for byte, run the same argv through
|
|
1055
|
+
* `rawBytesChecked`.
|
|
969
1056
|
*
|
|
970
1057
|
* `absent: []`. A rev that does not resolve exits 128, and outside a
|
|
971
1058
|
* repository `git diff` exits 129. Both throw, so "git failed" never reads as
|
|
972
1059
|
* "no diff". `git.try.diffText` reports them as `{ ok: false }`.
|
|
973
1060
|
*/
|
|
974
1061
|
export function diffText(rev, opts = {}) {
|
|
975
|
-
const argv = ['diff'];
|
|
1062
|
+
const argv = ['diff', ...PLAIN_PATCH];
|
|
976
1063
|
if (opts.staged === true)
|
|
977
1064
|
argv.push('--cached');
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
if (opts.paths !== undefined && opts.paths.length > 0)
|
|
982
|
-
argv.push('--', ...opts.paths);
|
|
1065
|
+
if (opts.binary === true)
|
|
1066
|
+
argv.push('--binary');
|
|
1067
|
+
pushRevAndPaths(argv, optionalPositional('diffText', 'rev', rev), opts.paths);
|
|
983
1068
|
return { argv, absent: NONE, parse: (r) => r.stdout };
|
|
984
1069
|
}
|
|
985
1070
|
/**
|
|
986
|
-
* One untracked file rendered as an all-added diff
|
|
987
|
-
*
|
|
988
|
-
*
|
|
989
|
-
*
|
|
1071
|
+
* One untracked file rendered as an all-added diff (`diff --no-color
|
|
1072
|
+
* --no-ext-diff --no-textconv --src-prefix=a/ --dst-prefix=b/ --no-relative
|
|
1073
|
+
* --submodule=short --unified=3 --no-index -- /dev/null <path>`), so a new
|
|
1074
|
+
* file reaches a consumer in the same shape as a modified one: the flags are
|
|
1075
|
+
* the ones {@link diffText} passes, and the text is as plain. An empty
|
|
1076
|
+
* existing file still gives a diff header.
|
|
990
1077
|
*
|
|
991
1078
|
* `--no-index` exits 1 whenever the inputs differ, which for a real file is
|
|
992
1079
|
* always, so exit 1 is the success case. git also exits 1, with empty stdout,
|
|
@@ -995,7 +1082,7 @@ export function diffText(rev, opts = {}) {
|
|
|
995
1082
|
*/
|
|
996
1083
|
export function diffAddedFile(relPath) {
|
|
997
1084
|
return {
|
|
998
|
-
argv: ['diff', '--no-index', '--', '/dev/null', relPath],
|
|
1085
|
+
argv: ['diff', ...PLAIN_PATCH, '--no-index', '--', '/dev/null', relPath],
|
|
999
1086
|
absent: [1],
|
|
1000
1087
|
parse(r, ranArgv) {
|
|
1001
1088
|
if (r.exitCode !== 0 && r.stdout === '')
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@osdlc/typed-git",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.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",
|