@osdlc/typed-git 0.17.0 → 0.21.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 +32 -0
- package/README.md +43 -8
- package/dist/async.d.ts +26 -2
- package/dist/async.js +67 -2
- package/dist/backend.d.ts +17 -3
- package/dist/backend.js +9 -1
- package/dist/cat-file.d.ts +78 -0
- package/dist/cat-file.js +155 -0
- package/dist/client.d.ts +2 -1
- package/dist/outcome.d.ts +4 -3
- package/dist/sync.d.ts +31 -2
- package/dist/sync.js +60 -1
- package/dist/verbs.d.ts +82 -10
- package/dist/verbs.js +120 -16
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,37 @@
|
|
|
1
1
|
# @osdlc/typed-git
|
|
2
2
|
|
|
3
|
+
## 0.21.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 3f84b08: `update` rebases with `--fork-point` when it does not know the parent's old head. A child of a PR rebased in an earlier run, without `--restack`, now leaves the parent's old commits behind when the clone's reflog still holds them, instead of replaying them onto their new versions. A fresh clone has no such reflog and rebases as before. `git.rebase(onto, { forkPoint: true })` in typed-git passes `--fork-point`.
|
|
8
|
+
|
|
9
|
+
## 0.20.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- 1ba6088: `diffText` takes `context` (`--unified=<n>`, default 3) and `findRenames` (`-M`, off by default, so `diff.renames` still applies); `diffAddedFile` takes `context`. A negative or non-integer `context` throws a `TypeError`.
|
|
14
|
+
|
|
15
|
+
## 0.19.0
|
|
16
|
+
|
|
17
|
+
### Minor Changes
|
|
18
|
+
|
|
19
|
+
- c8470d6: `catFileBatch(names, { maxBytes, chunkBytes })` and `catFileBatchChunks` (on `Git` and `AsyncGit`) read many objects byte for byte through `git cat-file --batch`: one `--batch-check` for the sizes, then `--batch` for the blobs within `maxBytes`, in groups of about `chunkBytes`. Each name maps to `text`, `binary`, `too-large`, `not-blob` or `missing`.
|
|
20
|
+
- 0ce8abc: `fetchMany(remotes, { prune, quiet, noWriteFetchHead, noTags, jobs })`: `git fetch --multiple`, every remote in one call, up to `jobs` at once. Git fetches each remote it can and exits non-zero naming any that failed.
|
|
21
|
+
- 9c0f5ae: `forEachRef` takes `contains`, which passes `--contains=<commit>` so only refs whose history holds that commit are listed.
|
|
22
|
+
|
|
23
|
+
### Patch Changes
|
|
24
|
+
|
|
25
|
+
- Updated dependencies [6d37030]
|
|
26
|
+
- @osdlc/command-seam@0.15.1
|
|
27
|
+
|
|
28
|
+
## 0.18.0
|
|
29
|
+
|
|
30
|
+
### Minor Changes
|
|
31
|
+
|
|
32
|
+
- b0ff1b3: `readTree(rev)` and `writeTree()` on `Git` and `AsyncGit` (and the verbs) run `git read-tree <rev>` and `git write-tree`. With `env: { GIT_INDEX_FILE }` on the call, they seed and read a temporary index, so a commit can be built from a working tree without touching the repository's own index.
|
|
33
|
+
- cb56f16: `submoduleUpdate()` on `Git` and `AsyncGit` (and the `submoduleUpdate` verb) runs `git submodule update --init --recursive --checkout` with the `file` and `ext` transports refused (a pull request's `.gitmodules` is not trusted): it checks out every submodule, nested ones included, at the commit the checked-out tree pins, and clones those not yet initialised.
|
|
34
|
+
|
|
3
35
|
## 0.17.0
|
|
4
36
|
|
|
5
37
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -318,16 +318,19 @@ prints `-` there and a fabricated `0` would be worse than nothing.
|
|
|
318
318
|
## Diff output and the user's git configuration
|
|
319
319
|
|
|
320
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`,
|
|
321
|
+
prefixes and, by default, three lines of context. Both always pass `--no-color`,
|
|
322
322
|
`--no-ext-diff`, `--no-textconv`, `--src-prefix=a/`, `--dst-prefix=b/`,
|
|
323
|
-
`--no-relative`, `--submodule=short` and `--unified=3
|
|
323
|
+
`--no-relative`, `--submodule=short` and `--unified=3`; `context: n` (both
|
|
324
|
+
verbs) changes the last to `--unified=<n>`, so `context: 0` gives the changed
|
|
325
|
+
lines alone. `diffText` also takes `findRenames: true` (`-M`), which reads a
|
|
326
|
+
moved file as one rename patch whatever `diff.renames` says. So `color.ui`,
|
|
324
327
|
`color.diff`, `diff.external`, a `diff.<driver>.command` or textconv driver,
|
|
325
328
|
`diff.noprefix`, `diff.mnemonicPrefix`, `diff.srcPrefix`, `diff.dstPrefix`,
|
|
326
329
|
`diff.relative`, `diff.submodule` and `diff.context` do not change the text,
|
|
327
330
|
and none of them stops `git apply` taking it. Other settings still apply:
|
|
328
|
-
rename detection (`diff.renames`), `diff.ignoreSubmodules` and
|
|
331
|
+
rename detection (`diff.renames`, unless `findRenames` is set), `diff.ignoreSubmodules` and
|
|
329
332
|
`diff.algorithm`. The `GIT_DIFF_OPTS` environment variable also still applies:
|
|
330
|
-
`-u0` there overrides the
|
|
333
|
+
`-u0` there overrides the lines of context.
|
|
331
334
|
|
|
332
335
|
`diffNameStatus` passes `--no-relative`, so its paths are relative to the
|
|
333
336
|
repository root and cover the whole repository when the cwd is below the
|
|
@@ -756,14 +759,15 @@ exit throws the classified failure.
|
|
|
756
759
|
| `lsFiles({ cached, others, excludeStandard, directory, paths })` | `ls-files -z` | none |
|
|
757
760
|
| `lsFilesTagged()` | `ls-files -v -z` | none — `{ tag, path }` rows; `S` is skip-worktree, lowercase is assume-unchanged |
|
|
758
761
|
| `submodules()` | `ls-files --stage -z` | none — `{ path, commit }` per gitlink in the index; whether one is checked out is on disk (its `.git`) |
|
|
762
|
+
| `submoduleUpdate()` | `-c protocol.file.allow=never -c protocol.ext.allow=never submodule update --init --recursive --checkout` | none; refuses `file`/`ext` URLs — checks out each submodule, nested ones too, at the commit the tree pins; clones those not yet initialised, so a `.gitmodules` URL is fetched |
|
|
759
763
|
| `forEachRef(pattern, { format, sort, count })` | `for-each-ref` | none — lines verbatim |
|
|
760
764
|
| `refs(pattern)` | `forEachRef` + `parseRefRows` | none |
|
|
761
765
|
| `diffNameOnly({ cached, diffFilter, rangeArgs, paths })` | `diff --name-only -z` | none |
|
|
762
766
|
| `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 |
|
|
763
767
|
| `diffStat({ rangeArgs, paths })` | `diff --stat` | none — raw stdout |
|
|
764
768
|
| `diffCheck({ paths })` | `diff --check` | `1`, `2` → `{ ok: false, output }` |
|
|
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
|
|
766
|
-
| `diffAddedFile(relPath)` | `diff --no-color --no-ext-diff --no-textconv --src-prefix=a/ --dst-prefix=b/ --no-relative --submodule=short --unified
|
|
769
|
+
| `diffText(rev?, { staged, binary, context, findRenames, paths })` | `diff --no-color --no-ext-diff --no-textconv --src-prefix=a/ --dst-prefix=b/ --no-relative --submodule=short --unified=<context, default 3> [--cached] [--binary] [-M] [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 |
|
|
770
|
+
| `diffAddedFile(relPath, { context })` | `diff --no-color --no-ext-diff --no-textconv --src-prefix=a/ --dst-prefix=b/ --no-relative --submodule=short --unified=<context, default 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` |
|
|
767
771
|
| `log(opts)` | `log` | none — raw stdout, unsplit |
|
|
768
772
|
| `logLines(opts)` | `log`, split and filtered | none |
|
|
769
773
|
| `lsTree(rev, { recursive, long, paths })` | `ls-tree -z` | none |
|
|
@@ -776,6 +780,8 @@ exit throws the classified failure.
|
|
|
776
780
|
| `commitTree(tree, { parents, message })` | `commit-tree <tree> [-p <parent>]... -m <message>` | none — writes an object and no ref; needs a git identity |
|
|
777
781
|
| `hashObject(content, { write })` | `hash-object [-w] --stdin` | none — the blob sha; `write` stores the blob; `content` goes on stdin as UTF-8, unfiltered |
|
|
778
782
|
| `mktree(entries)` | `mktree -z` | none — writes a tree object and no ref; each entry is `{ mode, type?, sha, path }`, one name per entry; a duplicate name, a mode git does not write, a name git reads as `.git` (including `git~1`, `.git.` and the HFS+ spellings), or a `.gitmodules` that is not a file, each of which `git fsck --strict` reports, throws a `TypeError` |
|
|
783
|
+
| `readTree(rev)` | `read-tree <rev>` | none — loads the tree into the index and leaves the working tree alone; pass `env: { GIT_INDEX_FILE }` on the call to use a temporary index |
|
|
784
|
+
| `writeTree()` | `write-tree` | none — the tree sha of the index; writes objects and no ref; a conflicted index throws |
|
|
779
785
|
| `remotes()` | `remote` | none — names, not remotes |
|
|
780
786
|
| `remote()` | `remote` | none — deprecated alias of `remotes()` |
|
|
781
787
|
| `remoteGetUrl(name, { push })` | `remote get-url [--push] <name>` | `2` → `null` (unknown remote) — the first URL |
|
|
@@ -798,6 +804,7 @@ Integration, declares exit 1 absent and returns the rejected refs.
|
|
|
798
804
|
| Method | git |
|
|
799
805
|
| --- | --- |
|
|
800
806
|
| `fetch(remote, refspec, { prune, quiet, noWriteFetchHead, depth, noTags })` | `fetch` |
|
|
807
|
+
| `fetchMany(remotes, { prune, quiet, noWriteFetchHead, noTags, jobs })` | `fetch --multiple [--jobs=<n>]` — every remote in one call, `jobs` at once; an empty list or a `jobs` that is not a positive integer throws a `TypeError` |
|
|
801
808
|
| `add(paths, { all, update, intentToAdd })` | `add` (paths go after `--`) |
|
|
802
809
|
| `commit({ message, body } \| { messageFile } \| { messageStdin }, plus { allowEmpty, amend, noVerify, signoff, paths } in the same object)` | `commit` — one argument, e.g. `commit({ message, allowEmpty: true })`; one message source, enforced by the types; `messageStdin` is `-F -` with the string on stdin, no temp file. `paths` appends `-- <paths…>`: only those paths are committed, from the working tree, and anything else staged stays staged. An empty `paths` throws a `TypeError`, because git would commit everything staged |
|
|
803
810
|
| `configSet(key, value, { scope })` | `config` |
|
|
@@ -805,7 +812,7 @@ Integration, declares exit 1 absent and returns the rejected refs.
|
|
|
805
812
|
| `init(path, { bare, initialBranch, quiet })` | `init` |
|
|
806
813
|
| `clone(url, dest, { depth, branch, bare, mirror, singleBranch, noTags, quiet })` | `clone` — a relative `dest` resolves in the client's working directory; `branch` takes a branch or a tag, not a sha; with `mirror`, `noTags` has no effect and `singleBranch` holds for the clone only |
|
|
807
814
|
| `resetHard(rev)` | `reset --hard` |
|
|
808
|
-
| `clean({ directories })` | `clean -f`,
|
|
815
|
+
| `clean({ directories, nested })` | `clean -f`, `-fd`, `-ffd` with `nested` (also nested repositories) — ignored files are kept |
|
|
809
816
|
| `deleteBranch(name, { force })` | `branch -d` / `-D` |
|
|
810
817
|
| `deleteRef(ref, { expected })` | `update-ref -d <ref> <expected>` — refuses when `ref` has moved |
|
|
811
818
|
| `updateRef(ref, sha, { oldSha, reason })` | `update-ref [-m <reason>] <ref> <sha> <oldSha>` — refuses when `ref` is not at `oldSha`; `oldSha: null` refuses when `ref` exists. `ref` is `HEAD` or a full `refs/…` name, and `oldSha` a full sha; anything else throws a `TypeError` |
|
|
@@ -830,7 +837,7 @@ other non-zero exit throws.
|
|
|
830
837
|
| Method | git | Returns |
|
|
831
838
|
| --- | --- | --- |
|
|
832
839
|
| `merge(ref, { noFf, noCommit, ffOnly, message })` | `merge --no-edit` | `MergeOutcome` — with `ffOnly`, a merge that cannot fast-forward throws |
|
|
833
|
-
| `rebase(onto, { autostash, upstream })` | `rebase` (`--onto <onto> <upstream>` with `upstream`) | `RebaseOutcome` |
|
|
840
|
+
| `rebase(onto, { autostash, upstream, forkPoint })` | `rebase` (`--onto <onto> <upstream>` with `upstream`; `--fork-point` with `forkPoint`) | `RebaseOutcome` |
|
|
834
841
|
| `rebaseContinue()` | `-c core.editor=true rebase --continue` | `RebaseOutcome` |
|
|
835
842
|
| `mergeTree(ours, theirs, { mergeBase })` | `merge-tree --write-tree --name-only -z` | `MergeTreeOutcome` |
|
|
836
843
|
| `lsFilesUnmerged()` | `ls-files -u -z` | `UnmergedEntry[]` — mode, sha, stage, path |
|
|
@@ -891,6 +898,34 @@ intact and `rawChecked(["apply"], { input: patch })` replays it. A text file
|
|
|
891
898
|
whose lines are not UTF-8 still loses bytes in `diffText`. Read that patch
|
|
892
899
|
with `rawBytesChecked`.
|
|
893
900
|
|
|
901
|
+
### Many objects at once
|
|
902
|
+
|
|
903
|
+
`catFileBatch(names, { maxBytes, chunkBytes })` reads many objects, byte for
|
|
904
|
+
byte, in a few processes rather than one `git show` each. `names` are anything
|
|
905
|
+
`git cat-file` reads, such as `rev:path` or a sha. It runs
|
|
906
|
+
`cat-file --batch-check` for the sizes, then `cat-file --batch` for the blobs
|
|
907
|
+
within `maxBytes`, in groups of about `chunkBytes` (64 MiB). It returns a map
|
|
908
|
+
from each name to one of:
|
|
909
|
+
|
|
910
|
+
| `kind` | Fields | Meaning |
|
|
911
|
+
| --- | --- | --- |
|
|
912
|
+
| `text`, `binary` | `sha`, `size`, `bytes` | a blob; `binary` has a NUL in its first 8000 bytes |
|
|
913
|
+
| `too-large` | `sha`, `size` | a blob over `maxBytes`; not read |
|
|
914
|
+
| `not-blob` | `type`, `sha`, `size` | a tree, commit or tag, such as `rev:dir`; not read |
|
|
915
|
+
| `missing` | | no such object, or a short sha that names more than one |
|
|
916
|
+
|
|
917
|
+
```ts
|
|
918
|
+
const got = git.catFileBatch(changed.map((p) => `HEAD:${p}`), { maxBytes: 1 << 20 });
|
|
919
|
+
for (const [name, e] of got) if (e.kind === "text") scan(name, e.bytes.toString("utf8"));
|
|
920
|
+
```
|
|
921
|
+
|
|
922
|
+
`catFileBatchChunks` yields the map one group at a time, so a caller can use
|
|
923
|
+
the bytes and drop them before the next read; `AsyncGit` has both, with
|
|
924
|
+
`for await` on the chunks. A name that is empty or holds a newline, a NUL or a trailing CR
|
|
925
|
+
throws `TypeError` (the protocol is one name per line). The entry `bytes` are
|
|
926
|
+
views of the group's buffer. Both run on the `bytesRunner`, so they are
|
|
927
|
+
experimental and throw `UnsupportedRequest` where `rawBytes` does.
|
|
928
|
+
|
|
894
929
|
## Driving the CLI, or something else
|
|
895
930
|
|
|
896
931
|
`AsyncGit` calls a `GitBackend`, which takes a `GitRequest` (a plain,
|
package/dist/async.d.ts
CHANGED
|
@@ -13,11 +13,12 @@
|
|
|
13
13
|
* client takes `gitDir` on its own constructor.
|
|
14
14
|
*/
|
|
15
15
|
import type { CommandResult } from '@osdlc/command-seam';
|
|
16
|
+
import { type CatFileBatchOptions, type CatFileEntry } from './cat-file.ts';
|
|
16
17
|
import { type GitBackend, type GitCallOptions } from './backend.ts';
|
|
17
18
|
import type { GitVersion } from './git-version.ts';
|
|
18
19
|
import { type Soft, type TriedAsync } from './outcome.ts';
|
|
19
20
|
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 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
|
+
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 DiffAddedFileOptions, type DiffTextOptions, type DiffTreeOptions, type FetchManyOptions, 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
22
|
/** A typed, awaitable git client bound to one working directory. */
|
|
22
23
|
export declare class AsyncGit {
|
|
23
24
|
readonly cwd: string;
|
|
@@ -94,6 +95,21 @@ export declare class AsyncGit {
|
|
|
94
95
|
rawBytesChecked(argv: string[], opts?: GitCallOptions & {
|
|
95
96
|
input?: string | undefined;
|
|
96
97
|
}): Promise<CommandResult<Buffer>>;
|
|
98
|
+
/**
|
|
99
|
+
* Many objects at once, byte-exact. Rejects with the classified failure if
|
|
100
|
+
* git fails, and with `UnsupportedRequest` when the backend has no bytes
|
|
101
|
+
* runner. See {@link Git.catFileBatch}.
|
|
102
|
+
*
|
|
103
|
+
* @experimental command-seam's bytes runners are experimental.
|
|
104
|
+
*/
|
|
105
|
+
catFileBatch(names: readonly string[], opts?: GitCallOptions & CatFileBatchOptions): Promise<Map<string, CatFileEntry>>;
|
|
106
|
+
/**
|
|
107
|
+
* {@link AsyncGit.catFileBatch} one group of blobs at a time. See
|
|
108
|
+
* {@link Git.catFileBatchChunks}.
|
|
109
|
+
*
|
|
110
|
+
* @experimental command-seam's bytes runners are experimental.
|
|
111
|
+
*/
|
|
112
|
+
catFileBatchChunks(names: readonly string[], opts?: GitCallOptions & CatFileBatchOptions): AsyncGenerator<Map<string, CatFileEntry>, void, undefined>;
|
|
97
113
|
/**
|
|
98
114
|
* The git the backend runs, from `git --version`; see {@link Git.version}.
|
|
99
115
|
* `cliBackend` probes once per runner and caches it, or returns its
|
|
@@ -203,7 +219,7 @@ export declare class AsyncGit {
|
|
|
203
219
|
* One untracked file rendered as an all-added diff. A path git cannot read
|
|
204
220
|
* rejects. See {@link Git.diffAddedFile}.
|
|
205
221
|
*/
|
|
206
|
-
diffAddedFile(relPath: string, opts?: GitCallOptions): Promise<string>;
|
|
222
|
+
diffAddedFile(relPath: string, opts?: GitCallOptions & DiffAddedFileOptions): Promise<string>;
|
|
207
223
|
/** `for-each-ref` rows, one line each, in the caller's format. */
|
|
208
224
|
forEachRef(pattern: string | string[], opts?: GitCallOptions & ForEachRefOptions): Promise<string[]>;
|
|
209
225
|
/** Local refs matching `pattern` as `{ sha, ref }` rows. */
|
|
@@ -256,6 +272,10 @@ export declare class AsyncGit {
|
|
|
256
272
|
hashObject(content: string, opts?: GitCallOptions & HashObjectOptions): Promise<string>;
|
|
257
273
|
/** Write a tree of `entries` and return its sha; no ref moves. See {@link Git.mktree}. */
|
|
258
274
|
mktree(entries: readonly MktreeEntry[], opts?: GitCallOptions): Promise<string>;
|
|
275
|
+
/** Load `rev`'s tree into the index; pass `env: { GIT_INDEX_FILE }` to use a temporary one. See {@link Git.readTree}. */
|
|
276
|
+
readTree(rev: string, opts?: GitCallOptions): Promise<void>;
|
|
277
|
+
/** Write the index as a tree and return its sha; no ref moves. See {@link Git.writeTree}. */
|
|
278
|
+
writeTree(opts?: GitCallOptions): Promise<string>;
|
|
259
279
|
/** Configured remote names (`git remote`); `[]` when there are none. */
|
|
260
280
|
remotes(opts?: GitCallOptions): Promise<string[]>;
|
|
261
281
|
/**
|
|
@@ -281,6 +301,8 @@ export declare class AsyncGit {
|
|
|
281
301
|
remoteOwnerRepo(remote?: string, opts?: GitCallOptions): Promise<RemoteCoordinate | null>;
|
|
282
302
|
/** `git fetch <remote> [refspec…]`. See {@link FetchOptions} for the flags. */
|
|
283
303
|
fetch(remote: string, refspec?: string | string[] | undefined, opts?: GitCallOptions & FetchOptions): Promise<void>;
|
|
304
|
+
/** `git fetch --multiple <remote>…`. See {@link FetchManyOptions}. */
|
|
305
|
+
fetchMany(remotes: readonly string[], opts?: GitCallOptions & FetchManyOptions): Promise<void>;
|
|
284
306
|
/** Stage paths; `all` / `update` are `git add -A` / `-u`. */
|
|
285
307
|
add(paths: string[], opts?: GitCallOptions & AddOptions): Promise<void>;
|
|
286
308
|
/**
|
|
@@ -335,6 +357,8 @@ export declare class AsyncGit {
|
|
|
335
357
|
worktreeUnlock(path: string, opts?: GitCallOptions): Promise<void>;
|
|
336
358
|
/** `git worktree prune`. */
|
|
337
359
|
worktreePrune(opts?: GitCallOptions): Promise<void>;
|
|
360
|
+
/** `git submodule update --init --recursive --checkout`, refusing `file` and `ext` URLs. See `submoduleUpdate` in verbs.ts. */
|
|
361
|
+
submoduleUpdate(opts?: GitCallOptions): Promise<void>;
|
|
338
362
|
/** `git remote add <name> <url>`. */
|
|
339
363
|
remoteAdd(name: string, url: string, opts?: GitCallOptions): Promise<void>;
|
|
340
364
|
/** `git remote set-head <remote> <branch> | --auto | --delete`. See {@link Git.remoteSetHead}. */
|
package/dist/async.js
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
* client takes `gitDir` on its own constructor.
|
|
14
14
|
*/
|
|
15
15
|
import { basename, dirname, resolve } from 'node:path';
|
|
16
|
+
import { inOrder, planCatFileBatch, } from "./cat-file.js";
|
|
16
17
|
import { cliBackend } from "./backend.js";
|
|
17
18
|
import { softAsync, triedAsync } from "./outcome.js";
|
|
18
19
|
import { parseRemoteUrl } from "./remote-url.js";
|
|
@@ -115,6 +116,44 @@ export class AsyncGit {
|
|
|
115
116
|
rawBytesChecked(argv, opts = {}) {
|
|
116
117
|
return this.backend.execute(this.cwd, { kind: 'rawBytes', argv, checked: true, input: opts.input }, opts);
|
|
117
118
|
}
|
|
119
|
+
/**
|
|
120
|
+
* Many objects at once, byte-exact. Rejects with the classified failure if
|
|
121
|
+
* git fails, and with `UnsupportedRequest` when the backend has no bytes
|
|
122
|
+
* runner. See {@link Git.catFileBatch}.
|
|
123
|
+
*
|
|
124
|
+
* @experimental command-seam's bytes runners are experimental.
|
|
125
|
+
*/
|
|
126
|
+
async catFileBatch(names, opts = {}) {
|
|
127
|
+
const all = new Map();
|
|
128
|
+
for await (const chunk of this.catFileBatchChunks(names, opts)) {
|
|
129
|
+
for (const [name, entry] of chunk)
|
|
130
|
+
all.set(name, entry);
|
|
131
|
+
}
|
|
132
|
+
return inOrder(names, all);
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* {@link AsyncGit.catFileBatch} one group of blobs at a time. See
|
|
136
|
+
* {@link Git.catFileBatchChunks}.
|
|
137
|
+
*
|
|
138
|
+
* @experimental command-seam's bytes runners are experimental.
|
|
139
|
+
*/
|
|
140
|
+
async *catFileBatchChunks(names, opts = {}) {
|
|
141
|
+
const { maxBytes, chunkBytes, ...call } = opts;
|
|
142
|
+
const plan = planCatFileBatch(names, { maxBytes, chunkBytes });
|
|
143
|
+
let step = plan.next();
|
|
144
|
+
while (step.done !== true) {
|
|
145
|
+
if (step.value.type === 'chunk') {
|
|
146
|
+
yield step.value.entries;
|
|
147
|
+
step = plan.next();
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
const { argv, input, maxOutputBytes } = step.value;
|
|
151
|
+
const run = { ...call, maxOutputBytes: call.maxOutputBytes ?? maxOutputBytes };
|
|
152
|
+
const result = await this.rawBytesChecked(argv, { ...run, input });
|
|
153
|
+
step = plan.next(result.stdout);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
118
157
|
// ── queries ───────────────────────────────────────────────────────────────
|
|
119
158
|
/**
|
|
120
159
|
* The git the backend runs, from `git --version`; see {@link Git.version}.
|
|
@@ -309,14 +348,23 @@ export class AsyncGit {
|
|
|
309
348
|
*/
|
|
310
349
|
diffText(rev, opts = {}) {
|
|
311
350
|
const [call, req] = splitCallOptions(opts);
|
|
312
|
-
return this.backend.execute(this.cwd, {
|
|
351
|
+
return this.backend.execute(this.cwd, {
|
|
352
|
+
kind: 'diffText',
|
|
353
|
+
rev,
|
|
354
|
+
staged: req.staged,
|
|
355
|
+
binary: req.binary,
|
|
356
|
+
context: req.context,
|
|
357
|
+
findRenames: req.findRenames,
|
|
358
|
+
paths: req.paths,
|
|
359
|
+
}, call);
|
|
313
360
|
}
|
|
314
361
|
/**
|
|
315
362
|
* One untracked file rendered as an all-added diff. A path git cannot read
|
|
316
363
|
* rejects. See {@link Git.diffAddedFile}.
|
|
317
364
|
*/
|
|
318
365
|
diffAddedFile(relPath, opts = {}) {
|
|
319
|
-
|
|
366
|
+
const [call, req] = splitCallOptions(opts);
|
|
367
|
+
return this.backend.execute(this.cwd, { kind: 'diffAddedFile', relPath, context: req.context }, call);
|
|
320
368
|
}
|
|
321
369
|
/** `for-each-ref` rows, one line each, in the caller's format. */
|
|
322
370
|
forEachRef(pattern, opts = {}) {
|
|
@@ -417,6 +465,14 @@ export class AsyncGit {
|
|
|
417
465
|
mktree(entries, opts = {}) {
|
|
418
466
|
return this.backend.execute(this.cwd, { kind: 'mktree', entries }, opts);
|
|
419
467
|
}
|
|
468
|
+
/** Load `rev`'s tree into the index; pass `env: { GIT_INDEX_FILE }` to use a temporary one. See {@link Git.readTree}. */
|
|
469
|
+
readTree(rev, opts = {}) {
|
|
470
|
+
return this.backend.execute(this.cwd, { kind: 'readTree', rev }, opts);
|
|
471
|
+
}
|
|
472
|
+
/** Write the index as a tree and return its sha; no ref moves. See {@link Git.writeTree}. */
|
|
473
|
+
writeTree(opts = {}) {
|
|
474
|
+
return this.backend.execute(this.cwd, { kind: 'writeTree' }, opts);
|
|
475
|
+
}
|
|
420
476
|
/** Configured remote names (`git remote`); `[]` when there are none. */
|
|
421
477
|
remotes(opts = {}) {
|
|
422
478
|
return this.backend.execute(this.cwd, { kind: 'remote' }, opts);
|
|
@@ -461,6 +517,11 @@ export class AsyncGit {
|
|
|
461
517
|
const [call, req] = splitCallOptions(opts);
|
|
462
518
|
return this.backend.execute(this.cwd, { kind: 'fetch', remote, refspec, ...req }, call);
|
|
463
519
|
}
|
|
520
|
+
/** `git fetch --multiple <remote>…`. See {@link FetchManyOptions}. */
|
|
521
|
+
fetchMany(remotes, opts = {}) {
|
|
522
|
+
const [call, req] = splitCallOptions(opts);
|
|
523
|
+
return this.backend.execute(this.cwd, { kind: 'fetchMany', remotes, ...req }, call);
|
|
524
|
+
}
|
|
464
525
|
/** Stage paths; `all` / `update` are `git add -A` / `-u`. */
|
|
465
526
|
add(paths, opts = {}) {
|
|
466
527
|
const [call, req] = splitCallOptions(opts);
|
|
@@ -553,6 +614,10 @@ export class AsyncGit {
|
|
|
553
614
|
worktreePrune(opts = {}) {
|
|
554
615
|
return this.backend.execute(this.cwd, { kind: 'worktreePrune' }, opts);
|
|
555
616
|
}
|
|
617
|
+
/** `git submodule update --init --recursive --checkout`, refusing `file` and `ext` URLs. See `submoduleUpdate` in verbs.ts. */
|
|
618
|
+
submoduleUpdate(opts = {}) {
|
|
619
|
+
return this.backend.execute(this.cwd, { kind: 'submoduleUpdate' }, opts);
|
|
620
|
+
}
|
|
556
621
|
/** `git remote add <name> <url>`. */
|
|
557
622
|
remoteAdd(name, url, opts = {}) {
|
|
558
623
|
return this.backend.execute(this.cwd, { kind: 'remoteAdd', name, url }, opts);
|
package/dist/backend.d.ts
CHANGED
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
*/
|
|
20
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 StatusEntriesOptions, 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 DiffAddedFileOptions, type DiffTextOptions, type DiffTreeOptions, type FetchManyOptions, 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
|
/**
|
|
@@ -145,6 +145,11 @@ export type GitRequest = {
|
|
|
145
145
|
} & HashObjectOptions) | {
|
|
146
146
|
kind: 'mktree';
|
|
147
147
|
entries: readonly MktreeEntry[];
|
|
148
|
+
} | {
|
|
149
|
+
kind: 'readTree';
|
|
150
|
+
rev: string;
|
|
151
|
+
} | {
|
|
152
|
+
kind: 'writeTree';
|
|
148
153
|
} | ({
|
|
149
154
|
kind: 'lsFiles';
|
|
150
155
|
} & LsFilesOptions) | {
|
|
@@ -181,14 +186,17 @@ export type GitRequest = {
|
|
|
181
186
|
} & GrepOptions) | ({
|
|
182
187
|
kind: 'diffText';
|
|
183
188
|
rev?: string | undefined;
|
|
184
|
-
} & DiffTextOptions) | {
|
|
189
|
+
} & DiffTextOptions) | ({
|
|
185
190
|
kind: 'diffAddedFile';
|
|
186
191
|
relPath: string;
|
|
187
|
-
} | ({
|
|
192
|
+
} & DiffAddedFileOptions) | ({
|
|
188
193
|
kind: 'fetch';
|
|
189
194
|
remote: string;
|
|
190
195
|
refspec?: string | string[] | undefined;
|
|
191
196
|
} & FetchOptions) | ({
|
|
197
|
+
kind: 'fetchMany';
|
|
198
|
+
remotes: readonly string[];
|
|
199
|
+
} & FetchManyOptions) | ({
|
|
192
200
|
kind: 'add';
|
|
193
201
|
paths: string[];
|
|
194
202
|
} & AddOptions) | ({
|
|
@@ -244,6 +252,8 @@ export type GitRequest = {
|
|
|
244
252
|
path: string;
|
|
245
253
|
} | {
|
|
246
254
|
kind: 'worktreePrune';
|
|
255
|
+
} | {
|
|
256
|
+
kind: 'submoduleUpdate';
|
|
247
257
|
} | ({
|
|
248
258
|
kind: 'merge';
|
|
249
259
|
ref: string;
|
|
@@ -340,6 +350,8 @@ export interface GitResults {
|
|
|
340
350
|
commitTree: string;
|
|
341
351
|
hashObject: string;
|
|
342
352
|
mktree: string;
|
|
353
|
+
readTree: void;
|
|
354
|
+
writeTree: string;
|
|
343
355
|
lsFiles: string[];
|
|
344
356
|
lsFilesTagged: TaggedFile[];
|
|
345
357
|
submodules: IndexSubmodule[];
|
|
@@ -357,6 +369,7 @@ export interface GitResults {
|
|
|
357
369
|
diffText: string;
|
|
358
370
|
diffAddedFile: string;
|
|
359
371
|
fetch: void;
|
|
372
|
+
fetchMany: void;
|
|
360
373
|
add: void;
|
|
361
374
|
commit: void;
|
|
362
375
|
configSet: void;
|
|
@@ -374,6 +387,7 @@ export interface GitResults {
|
|
|
374
387
|
worktreeMove: void;
|
|
375
388
|
worktreeUnlock: void;
|
|
376
389
|
worktreePrune: void;
|
|
390
|
+
submoduleUpdate: void;
|
|
377
391
|
merge: MergeOutcome;
|
|
378
392
|
mergeAbort: void;
|
|
379
393
|
rebase: RebaseOutcome;
|
package/dist/backend.js
CHANGED
|
@@ -82,6 +82,10 @@ function toVerb(request) {
|
|
|
82
82
|
return v.hashObject(request.content, request);
|
|
83
83
|
case 'mktree':
|
|
84
84
|
return v.mktree(request.entries);
|
|
85
|
+
case 'readTree':
|
|
86
|
+
return v.readTree(request.rev);
|
|
87
|
+
case 'writeTree':
|
|
88
|
+
return v.writeTree();
|
|
85
89
|
case 'checkIgnore':
|
|
86
90
|
return v.checkIgnore(request.relPaths);
|
|
87
91
|
case 'checkIgnoreVerbose':
|
|
@@ -117,9 +121,11 @@ function toVerb(request) {
|
|
|
117
121
|
case 'diffText':
|
|
118
122
|
return v.diffText(request.rev, request);
|
|
119
123
|
case 'diffAddedFile':
|
|
120
|
-
return v.diffAddedFile(request.relPath);
|
|
124
|
+
return v.diffAddedFile(request.relPath, request);
|
|
121
125
|
case 'fetch':
|
|
122
126
|
return v.fetch(request.remote, request.refspec, request);
|
|
127
|
+
case 'fetchMany':
|
|
128
|
+
return v.fetchMany(request.remotes, request);
|
|
123
129
|
case 'add':
|
|
124
130
|
return v.add(request.paths, request);
|
|
125
131
|
case 'commit':
|
|
@@ -154,6 +160,8 @@ function toVerb(request) {
|
|
|
154
160
|
return v.worktreeUnlock(request.path);
|
|
155
161
|
case 'worktreePrune':
|
|
156
162
|
return v.worktreePrune();
|
|
163
|
+
case 'submoduleUpdate':
|
|
164
|
+
return v.submoduleUpdate();
|
|
157
165
|
case 'merge':
|
|
158
166
|
return v.merge(request.ref, request);
|
|
159
167
|
case 'mergeAbort':
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `git cat-file --batch` reads: many objects, byte-exact, in a few processes.
|
|
3
|
+
*
|
|
4
|
+
* The planner here is a generator that asks its driver to run git and gets
|
|
5
|
+
* the stdout bytes back, so the sync client (`Git.catFileBatch`) and the async
|
|
6
|
+
* one (`AsyncGit.catFileBatch`) share every line of the batching and parsing.
|
|
7
|
+
* Each driver supplies the bytes runner behind `rawBytesChecked`.
|
|
8
|
+
*/
|
|
9
|
+
/** What one name resolved to. `bytes` are git's, never decoded. */
|
|
10
|
+
export type CatFileEntry =
|
|
11
|
+
/** A blob with no NUL in its first 8000 bytes (git's own text test). */
|
|
12
|
+
{
|
|
13
|
+
kind: 'text';
|
|
14
|
+
sha: string;
|
|
15
|
+
size: number;
|
|
16
|
+
bytes: Buffer;
|
|
17
|
+
}
|
|
18
|
+
/** A blob with a NUL in its first 8000 bytes. */
|
|
19
|
+
| {
|
|
20
|
+
kind: 'binary';
|
|
21
|
+
sha: string;
|
|
22
|
+
size: number;
|
|
23
|
+
bytes: Buffer;
|
|
24
|
+
}
|
|
25
|
+
/** A blob larger than `maxBytes`; its content was not read. */
|
|
26
|
+
| {
|
|
27
|
+
kind: 'too-large';
|
|
28
|
+
sha: string;
|
|
29
|
+
size: number;
|
|
30
|
+
}
|
|
31
|
+
/** A tree, commit or tag, such as `rev:dir`. Its content was not read. */
|
|
32
|
+
| {
|
|
33
|
+
kind: 'not-blob';
|
|
34
|
+
type: string;
|
|
35
|
+
sha: string;
|
|
36
|
+
size: number;
|
|
37
|
+
}
|
|
38
|
+
/** No such object, or a short sha that names more than one. */
|
|
39
|
+
| {
|
|
40
|
+
kind: 'missing';
|
|
41
|
+
};
|
|
42
|
+
/** Options for `catFileBatch` and `catFileBatchChunks`. */
|
|
43
|
+
export interface CatFileBatchOptions {
|
|
44
|
+
/**
|
|
45
|
+
* A blob larger than this many bytes comes back as `too-large`, and its
|
|
46
|
+
* content is not read. Default `Infinity`.
|
|
47
|
+
*/
|
|
48
|
+
maxBytes?: number | undefined;
|
|
49
|
+
/**
|
|
50
|
+
* The most blob bytes one git process is asked for; the default is 64 MiB.
|
|
51
|
+
* A blob larger than this still gets a process of its own, so set
|
|
52
|
+
* `maxBytes` to bound it. Memory held at once is about this value.
|
|
53
|
+
*/
|
|
54
|
+
chunkBytes?: number | undefined;
|
|
55
|
+
}
|
|
56
|
+
/** One git run the planner needs. `input` is the object names, one per line. */
|
|
57
|
+
export interface CatFileRun {
|
|
58
|
+
readonly type: 'run';
|
|
59
|
+
readonly argv: string[];
|
|
60
|
+
readonly input: string;
|
|
61
|
+
/** An output cap sized to the answer; `undefined` leaves the runner's default. */
|
|
62
|
+
readonly maxOutputBytes: number | undefined;
|
|
63
|
+
}
|
|
64
|
+
/** A group of finished entries the caller can use now. */
|
|
65
|
+
export interface CatFileChunk {
|
|
66
|
+
readonly type: 'chunk';
|
|
67
|
+
readonly entries: Map<string, CatFileEntry>;
|
|
68
|
+
}
|
|
69
|
+
/** `entries` in the order of `names`, a repeated name once. */
|
|
70
|
+
export declare function inOrder(names: readonly string[], entries: Map<string, CatFileEntry>): Map<string, CatFileEntry>;
|
|
71
|
+
/**
|
|
72
|
+
* Plan the reads of `names`: `--batch-check` for their sizes, then `--batch`
|
|
73
|
+
* for the blobs within `maxBytes`, grouped so a process is asked for about
|
|
74
|
+
* `chunkBytes`. Yields a {@link CatFileRun} for the driver to run, which sends
|
|
75
|
+
* back the stdout bytes, and a {@link CatFileChunk} for each group of finished
|
|
76
|
+
* entries. The first chunk also holds every entry that needed no content read.
|
|
77
|
+
*/
|
|
78
|
+
export declare function planCatFileBatch(names: readonly string[], opts?: CatFileBatchOptions): Generator<CatFileRun | CatFileChunk, void, Buffer>;
|