@osdlc/typed-git 0.14.0 → 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +21 -0
- package/README.md +97 -15
- package/dist/async.d.ts +35 -7
- package/dist/async.js +44 -7
- package/dist/backend.d.ts +37 -11
- package/dist/backend.js +33 -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 +54 -9
- package/dist/sync.js +68 -9
- package/dist/verbs.d.ts +139 -8
- package/dist/verbs.js +249 -20
- package/package.json +1 -1
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 InitOptions, type IntegrationOutcome, type LogOptions, type IgnoreMatch, type LsFilesOptions, type LsRemoteOptions, type LsTreeOptions, type MergeOptions, type MergeOutcome, type MergeTreeOptions, type MergeTreeOutcome, 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 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 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
|
|
@@ -350,6 +383,13 @@ export declare class Git {
|
|
|
350
383
|
cherry(upstream: string, head?: string, opts?: GitSyncCallOptions): CherryEntry[];
|
|
351
384
|
/** Write a commit for `tree` and return its sha; no ref moves. Needs a git identity. */
|
|
352
385
|
commitTree(tree: string, commitOpts: CommitTreeOptions, opts?: GitSyncCallOptions): string;
|
|
386
|
+
/**
|
|
387
|
+
* The blob sha of `content`; `{ write: true }` also writes the blob. See
|
|
388
|
+
* `hashObject` in `verbs.ts`.
|
|
389
|
+
*/
|
|
390
|
+
hashObject(content: string, opts?: GitSyncCallOptions & HashObjectOptions): string;
|
|
391
|
+
/** Write a tree of `entries` and return its sha; no ref moves. See `mktree` in `verbs.ts`. */
|
|
392
|
+
mktree(entries: readonly MktreeEntry[], opts?: GitSyncCallOptions): string;
|
|
353
393
|
/** Configured remote names (`git remote`); `[]` when there are none. */
|
|
354
394
|
remotes(opts?: GitSyncCallOptions): string[];
|
|
355
395
|
/**
|
|
@@ -428,6 +468,11 @@ export declare class Git {
|
|
|
428
468
|
deleteRef(ref: string, opts: GitSyncCallOptions & {
|
|
429
469
|
expected: string;
|
|
430
470
|
}): void;
|
|
471
|
+
/**
|
|
472
|
+
* Point `ref` at `sha` only while it holds `oldSha` (`null`: only while it
|
|
473
|
+
* does not exist). See `updateRef` in `verbs.ts`.
|
|
474
|
+
*/
|
|
475
|
+
updateRef(ref: string, sha: string, opts: GitSyncCallOptions & UpdateRefOptions): void;
|
|
431
476
|
/**
|
|
432
477
|
* `git worktree add [--detach] [-b|-B branch] <path> [startPoint]`.
|
|
433
478
|
* `resetBranch` picks `-B`: create `branch`, or reset it if it exists.
|
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
|
|
@@ -513,6 +554,17 @@ export class Git {
|
|
|
513
554
|
commitTree(tree, commitOpts, opts = {}) {
|
|
514
555
|
return this.exec(v.commitTree(tree, commitOpts), opts);
|
|
515
556
|
}
|
|
557
|
+
/**
|
|
558
|
+
* The blob sha of `content`; `{ write: true }` also writes the blob. See
|
|
559
|
+
* `hashObject` in `verbs.ts`.
|
|
560
|
+
*/
|
|
561
|
+
hashObject(content, opts = {}) {
|
|
562
|
+
return this.exec(v.hashObject(content, opts), opts);
|
|
563
|
+
}
|
|
564
|
+
/** Write a tree of `entries` and return its sha; no ref moves. See `mktree` in `verbs.ts`. */
|
|
565
|
+
mktree(entries, opts = {}) {
|
|
566
|
+
return this.exec(v.mktree(entries), opts);
|
|
567
|
+
}
|
|
516
568
|
/** Configured remote names (`git remote`); `[]` when there are none. */
|
|
517
569
|
remotes(opts = {}) {
|
|
518
570
|
return this.exec(v.remote(), opts);
|
|
@@ -625,6 +677,13 @@ export class Git {
|
|
|
625
677
|
deleteRef(ref, opts) {
|
|
626
678
|
this.exec(v.deleteRef(ref, opts), opts);
|
|
627
679
|
}
|
|
680
|
+
/**
|
|
681
|
+
* Point `ref` at `sha` only while it holds `oldSha` (`null`: only while it
|
|
682
|
+
* does not exist). See `updateRef` in `verbs.ts`.
|
|
683
|
+
*/
|
|
684
|
+
updateRef(ref, sha, opts) {
|
|
685
|
+
this.exec(v.updateRef(ref, sha, opts), opts);
|
|
686
|
+
}
|
|
628
687
|
/**
|
|
629
688
|
* `git worktree add [--detach] [-b|-B branch] <path> [startPoint]`.
|
|
630
689
|
* `resetBranch` picks `-B`: create `branch`, or reset it if it exists.
|
package/dist/verbs.d.ts
CHANGED
|
@@ -87,6 +87,22 @@ export interface GitVerb<T> {
|
|
|
87
87
|
* timeout, so a parse would read cut-short output as the whole answer.
|
|
88
88
|
*/
|
|
89
89
|
export declare function gate<T>(verb: GitVerb<T>, result: CommandResult, argv?: string[]): T;
|
|
90
|
+
/**
|
|
91
|
+
* Gate for a bytes runner's result: returns it, or throws a `FailureError`
|
|
92
|
+
* with the classified `GitFailure` on a non-zero exit, `neverExited` or
|
|
93
|
+
* `outputIncomplete`. The `CommandFailed` cause holds stdout decoded as UTF-8.
|
|
94
|
+
*/
|
|
95
|
+
export declare function gateBytes(result: CommandResult<Buffer>, argv: string[]): CommandResult<Buffer>;
|
|
96
|
+
/**
|
|
97
|
+
* The bytes runner a client runs `rawBytes` on: the `bytesRunner` passed,
|
|
98
|
+
* else the default spawn, but only when no `runner` was passed either.
|
|
99
|
+
* `undefined` means the client throws `UnsupportedRequest` from its bytes
|
|
100
|
+
* calls. See the `Git` constructor.
|
|
101
|
+
*/
|
|
102
|
+
export declare function bytesRunnerFor<B>(opts: {
|
|
103
|
+
runner?: unknown;
|
|
104
|
+
bytesRunner?: B | undefined;
|
|
105
|
+
}, spawnDefault: () => B): B | undefined;
|
|
90
106
|
/**
|
|
91
107
|
* A client-level environment bag under a per-call one, or `undefined` when
|
|
92
108
|
* neither is set (so the runner inherits the parent environment untouched
|
|
@@ -292,14 +308,26 @@ export interface StatusEntry {
|
|
|
292
308
|
/** The path; for a rename or copy, the destination. */
|
|
293
309
|
path: string;
|
|
294
310
|
}
|
|
311
|
+
/** Options for {@link statusEntries}. */
|
|
312
|
+
export interface StatusEntriesOptions {
|
|
313
|
+
/**
|
|
314
|
+
* `--ignored`: report ignored files too, as entries whose `x` and `y` are
|
|
315
|
+
* both `'!'`. This verb always passes `--untracked-files=all`, so each
|
|
316
|
+
* ignored file is its own entry, inside an ignored directory too.
|
|
317
|
+
*/
|
|
318
|
+
ignored?: boolean | undefined;
|
|
319
|
+
}
|
|
295
320
|
/**
|
|
296
321
|
* Every changed or untracked file as a {@link StatusEntry}
|
|
297
|
-
* (`git status --porcelain -z --untracked-files=all`
|
|
298
|
-
* are expanded to their files. Paths are
|
|
299
|
-
* or copy yields one entry (its source
|
|
300
|
-
* tree; throws outside a repository.
|
|
322
|
+
* (`git status --porcelain -z --untracked-files=all`, plus `--ignored` with
|
|
323
|
+
* `ignored`). Untracked directories are expanded to their files. Paths are
|
|
324
|
+
* verbatim, never quoted, and a rename or copy yields one entry (its source
|
|
325
|
+
* path is dropped). Empty on a clean tree; throws outside a repository.
|
|
326
|
+
*
|
|
327
|
+
* Paths are decoded as UTF-8, so a name that is not valid UTF-8 comes back
|
|
328
|
+
* with U+FFFD in it. Read such names through `rawBytesChecked`.
|
|
301
329
|
*/
|
|
302
|
-
export declare function statusEntries(): GitVerb<StatusEntry[]>;
|
|
330
|
+
export declare function statusEntries(opts?: StatusEntriesOptions): GitVerb<StatusEntry[]>;
|
|
303
331
|
/**
|
|
304
332
|
* Local branch names matching `pattern` (all when omitted). The name is
|
|
305
333
|
* `refs/heads/` stripped, never `%(refname:short)`, which answers
|
|
@@ -717,13 +745,24 @@ export interface DiffTreeOptions {
|
|
|
717
745
|
export interface DiffTextOptions {
|
|
718
746
|
/** `--cached` — diff the index against `rev` (or HEAD) rather than the worktree. */
|
|
719
747
|
staged?: boolean | undefined;
|
|
748
|
+
/**
|
|
749
|
+
* `--binary`: write a binary file's change as a `GIT binary patch` that
|
|
750
|
+
* `git apply` can replay, instead of the one line `Binary files … differ`.
|
|
751
|
+
* The patch is ASCII (base85), so the decode to a string keeps it intact.
|
|
752
|
+
*/
|
|
753
|
+
binary?: boolean | undefined;
|
|
720
754
|
/** Pathspecs, passed after `--`. */
|
|
721
755
|
paths?: string[] | undefined;
|
|
722
756
|
}
|
|
723
757
|
/**
|
|
724
|
-
* The unified diff text (`git diff [--cached] [rev] [-- paths]`),
|
|
725
|
-
* rev and staged shape {@link diffNameOnly} selects paths for.
|
|
726
|
-
* nothing differs.
|
|
758
|
+
* The unified diff text (`git diff [--cached] [--binary] [rev] [-- paths]`),
|
|
759
|
+
* for the same rev and staged shape {@link diffNameOnly} selects paths for.
|
|
760
|
+
* Empty when nothing differs.
|
|
761
|
+
*
|
|
762
|
+
* The text is decoded as UTF-8. A text file whose lines are not valid UTF-8
|
|
763
|
+
* comes back with U+FFFD in them, and the patch no longer applies. For a
|
|
764
|
+
* patch that must replay byte for byte, run the same argv through
|
|
765
|
+
* `rawBytesChecked`.
|
|
727
766
|
*
|
|
728
767
|
* `absent: []`. A rev that does not resolve exits 128, and outside a
|
|
729
768
|
* repository `git diff` exits 129. Both throw, so "git failed" never reads as
|
|
@@ -850,6 +889,68 @@ export interface CommitTreeOptions {
|
|
|
850
889
|
* this throws. `absent: []`, and a reply that is not a sha throws.
|
|
851
890
|
*/
|
|
852
891
|
export declare function commitTree(tree: string, opts: CommitTreeOptions): GitVerb<string>;
|
|
892
|
+
/** Options for {@link hashObject}. */
|
|
893
|
+
export interface HashObjectOptions {
|
|
894
|
+
/**
|
|
895
|
+
* `-w`: also write the blob into the object store; without it only the sha is computed.
|
|
896
|
+
*/
|
|
897
|
+
write?: boolean | undefined;
|
|
898
|
+
}
|
|
899
|
+
/**
|
|
900
|
+
* The blob sha of `content`, and with `{ write: true }` the blob itself
|
|
901
|
+
* written to the object store (`git hash-object [-w] --stdin`).
|
|
902
|
+
*
|
|
903
|
+
* `content` goes to git on stdin as UTF-8, so the blob holds exactly those
|
|
904
|
+
* bytes: input from stdin skips the clean filters and line-ending
|
|
905
|
+
* conversion that `.gitattributes` would apply to a file. A string cannot
|
|
906
|
+
* carry arbitrary bytes, so binary content is not supported.
|
|
907
|
+
*
|
|
908
|
+
* `absent: []`, and a reply that is not a sha throws.
|
|
909
|
+
*/
|
|
910
|
+
export declare function hashObject(content: string, opts?: HashObjectOptions): GitVerb<string>;
|
|
911
|
+
/**
|
|
912
|
+
* One entry of a tree written by {@link mktree}: a name in that tree, not a
|
|
913
|
+
* path through it. A row of {@link lsTree} without `recursive` has this shape,
|
|
914
|
+
* so `mktree(lsTree(rev))` writes the same tree back.
|
|
915
|
+
*/
|
|
916
|
+
export interface MktreeEntry {
|
|
917
|
+
/**
|
|
918
|
+
* `100644` (file), `100755` (executable), `120000` (symlink), `040000`
|
|
919
|
+
* (tree) or `160000` (submodule commit). Any other mode throws.
|
|
920
|
+
*/
|
|
921
|
+
mode: string;
|
|
922
|
+
/**
|
|
923
|
+
* The object type. Each mode has one, so it may be left out; when given,
|
|
924
|
+
* it must be the mode's type.
|
|
925
|
+
*/
|
|
926
|
+
type?: 'blob' | 'tree' | 'commit' | undefined;
|
|
927
|
+
/** The full sha of an object already in the store. */
|
|
928
|
+
sha: string;
|
|
929
|
+
/**
|
|
930
|
+
* The entry's name: no `/`, no NUL, not empty, `.`, `..`, or a name git
|
|
931
|
+
* reads as `.git` (see {@link mktree}).
|
|
932
|
+
*/
|
|
933
|
+
path: string;
|
|
934
|
+
}
|
|
935
|
+
/**
|
|
936
|
+
* Write a tree object holding `entries` and return its sha (`git mktree -z`).
|
|
937
|
+
* No entries writes the empty tree.
|
|
938
|
+
*
|
|
939
|
+
* The entries go to git on stdin, NUL-terminated, so a name may hold spaces,
|
|
940
|
+
* tabs or newlines; git sorts them into tree order itself.
|
|
941
|
+
*
|
|
942
|
+
* Throws a `TypeError` before git runs for a duplicate, empty, `.`, `..`,
|
|
943
|
+
* `/`- or NUL-bearing name, a name git reads as `.git`, a `.gitmodules` that
|
|
944
|
+
* is not a file, an unknown mode, a sha that is not a full sha, and a type
|
|
945
|
+
* that does not match the mode. `git mktree` writes most of these, but
|
|
946
|
+
* `git fsck --strict` reports them. D-03 lists the NTFS and HFS+ spellings.
|
|
947
|
+
*
|
|
948
|
+
* Every sha must name an object already in the store, of the entry's type,
|
|
949
|
+
* except a submodule (`160000`) commit, which git does not check; otherwise
|
|
950
|
+
* git exits 128 and this throws. `absent: []`, and a reply that is not a
|
|
951
|
+
* sha throws.
|
|
952
|
+
*/
|
|
953
|
+
export declare function mktree(entries: readonly MktreeEntry[]): GitVerb<string>;
|
|
853
954
|
/**
|
|
854
955
|
* How far `tip` has diverged from `base`
|
|
855
956
|
* (`git rev-list --left-right --count base...tip`).
|
|
@@ -1257,6 +1358,36 @@ export declare function deleteBranch(name: string, opts?: {
|
|
|
1257
1358
|
export declare function deleteRef(ref: string, opts: {
|
|
1258
1359
|
expected: string;
|
|
1259
1360
|
}): GitVerb<void>;
|
|
1361
|
+
/** Options for {@link updateRef}. */
|
|
1362
|
+
export interface UpdateRefOptions {
|
|
1363
|
+
/**
|
|
1364
|
+
* The sha `ref` must hold now, or `null` when `ref` must not exist yet.
|
|
1365
|
+
* Required: git checks it and moves the ref in one step, so a commit
|
|
1366
|
+
* another writer put on the ref after the caller looked is never lost.
|
|
1367
|
+
* It must be a full sha: a ref name here would resolve at the moment of
|
|
1368
|
+
* the check and always match.
|
|
1369
|
+
*/
|
|
1370
|
+
oldSha: string | null;
|
|
1371
|
+
/** `-m <reason>` — the message the reflog records for this update. */
|
|
1372
|
+
reason?: string | undefined;
|
|
1373
|
+
}
|
|
1374
|
+
/**
|
|
1375
|
+
* `git update-ref [-m <reason>] <ref> <sha> <oldSha>`: point `ref` at `sha`,
|
|
1376
|
+
* only while `ref` still holds `oldSha` (`null`: only while it does not
|
|
1377
|
+
* exist). It writes no object and leaves the index and working tree alone.
|
|
1378
|
+
*
|
|
1379
|
+
* `ref` must be `HEAD` or a full name under `refs/`. git does not expand a
|
|
1380
|
+
* short name here: `update-ref main` would write a new top-level ref named
|
|
1381
|
+
* `main` beside `refs/heads/main`, so a name that is neither throws a
|
|
1382
|
+
* `TypeError` before git runs. `HEAD` on a branch moves that branch.
|
|
1383
|
+
*
|
|
1384
|
+
* When `ref` is not where `oldSha` says, git exits 128 and this throws,
|
|
1385
|
+
* like any other failure: `reference already exists`, `is at <sha> but
|
|
1386
|
+
* expected <oldSha>`, or `unable to resolve reference`. Re-read the ref with
|
|
1387
|
+
* `resolveRef` to decide whether to retry. git also refuses a `sha` that
|
|
1388
|
+
* names no object, a non-commit on a branch, and a malformed ref name.
|
|
1389
|
+
*/
|
|
1390
|
+
export declare function updateRef(ref: string, sha: string, opts: UpdateRefOptions): GitVerb<void>;
|
|
1260
1391
|
/** Options for {@link worktreeAdd}. */
|
|
1261
1392
|
export interface WorktreeAddOptions {
|
|
1262
1393
|
/** `-b <branch>` — create this branch at `startPoint`; git refuses if it exists. */
|