@osdlc/typed-git 0.10.0 → 0.12.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 +37 -0
- package/README.md +167 -24
- package/dist/async.d.ts +21 -11
- package/dist/async.js +25 -12
- package/dist/backend.d.ts +30 -9
- package/dist/backend.js +33 -6
- package/dist/client.d.ts +3 -1
- package/dist/client.js +3 -1
- package/dist/failure.d.ts +18 -4
- package/dist/failure.js +4 -0
- package/dist/features.d.ts +91 -0
- package/dist/features.js +98 -0
- package/dist/git-url.d.ts +3 -0
- package/dist/git-url.js +14 -2
- package/dist/git-version.d.ts +90 -0
- package/dist/git-version.js +225 -0
- package/dist/soft.d.ts +1 -0
- package/dist/soft.js +1 -0
- package/dist/sync.d.ts +41 -17
- package/dist/sync.js +69 -19
- package/dist/verbs.d.ts +114 -40
- package/dist/verbs.js +201 -72
- package/package.json +1 -1
package/dist/backend.js
CHANGED
|
@@ -18,6 +18,8 @@
|
|
|
18
18
|
* `cliBackend` and `AsyncGit` are stable.
|
|
19
19
|
*/
|
|
20
20
|
import { spawnRunnerAsync, } from '@osdlc/command-seam';
|
|
21
|
+
import { versionedVerb } from "./features.js";
|
|
22
|
+
import { pinnedGitVersion, probeGitVersionAsync, versionVerb, } from "./git-version.js";
|
|
21
23
|
import * as v from "./verbs.js";
|
|
22
24
|
import { gate, mergeEnv, repoPrefix, } from "./verbs.js";
|
|
23
25
|
/** Thrown by a backend asked for an operation it cannot perform. */
|
|
@@ -32,6 +34,8 @@ export class UnsupportedRequest extends Error {
|
|
|
32
34
|
/** Translate a request into the CLI verb that performs it. */
|
|
33
35
|
function toVerb(request) {
|
|
34
36
|
switch (request.kind) {
|
|
37
|
+
case 'version':
|
|
38
|
+
return versionVerb();
|
|
35
39
|
case 'showAtRev':
|
|
36
40
|
return v.showAtRev(request.rev, request.relPath);
|
|
37
41
|
case 'showAtRevChecked':
|
|
@@ -78,6 +82,10 @@ function toVerb(request) {
|
|
|
78
82
|
return v.isAncestor(request.a, request.b);
|
|
79
83
|
case 'aheadBehind':
|
|
80
84
|
return v.aheadBehind(request.base, request.tip);
|
|
85
|
+
case 'cherry':
|
|
86
|
+
return v.cherry(request.upstream, request.head);
|
|
87
|
+
case 'commitTree':
|
|
88
|
+
return v.commitTree(request.tree, request);
|
|
81
89
|
case 'checkIgnore':
|
|
82
90
|
return v.checkIgnore(request.relPaths);
|
|
83
91
|
case 'checkIgnoreVerbose':
|
|
@@ -128,8 +136,6 @@ function toVerb(request) {
|
|
|
128
136
|
return v.clone(request.url, request.dest, request);
|
|
129
137
|
case 'push':
|
|
130
138
|
return v.push(request.remote, request.refspec, request);
|
|
131
|
-
case 'pushPorcelain':
|
|
132
|
-
return v.pushPorcelain(request.remote, request.refspec, request);
|
|
133
139
|
case 'resetHard':
|
|
134
140
|
return v.resetHard(request.rev);
|
|
135
141
|
case 'clean':
|
|
@@ -205,10 +211,21 @@ function toVerb(request) {
|
|
|
205
211
|
*/
|
|
206
212
|
export function cliBackend(opts = {}) {
|
|
207
213
|
const runner = opts.runner ?? spawnRunnerAsync('git', { absolutePathOnly: true });
|
|
214
|
+
const pinned = pinnedGitVersion(opts.gitVersion);
|
|
215
|
+
// A failed probe names `report`: the gated verb's argv, so a missing git
|
|
216
|
+
// reads `git worktree: …` rather than `git --version: …`.
|
|
217
|
+
const versionOf = (run, report) => pinned === undefined
|
|
218
|
+
? probeGitVersionAsync(runner, {
|
|
219
|
+
env: run.env,
|
|
220
|
+
timeoutMs: run.timeoutMs,
|
|
221
|
+
signal: run.signal,
|
|
222
|
+
report,
|
|
223
|
+
})
|
|
224
|
+
: Promise.resolve(pinned);
|
|
208
225
|
const prefix = repoPrefix(opts.gitDir, opts.workTree);
|
|
209
226
|
return {
|
|
210
227
|
async execute(cwd, request, callOpts = {}) {
|
|
211
|
-
const
|
|
228
|
+
const gated = toVerb(request);
|
|
212
229
|
const runOpts = { cwd };
|
|
213
230
|
if (callOpts.timeoutMs !== undefined)
|
|
214
231
|
runOpts.timeoutMs = callOpts.timeoutMs;
|
|
@@ -220,6 +237,17 @@ export function cliBackend(opts = {}) {
|
|
|
220
237
|
const env = mergeEnv(opts.env, callOpts.env);
|
|
221
238
|
if (env !== undefined)
|
|
222
239
|
runOpts.env = env;
|
|
240
|
+
const req = request;
|
|
241
|
+
// `version` is answered from the per-runner cache, like the probe a
|
|
242
|
+
// version-gated verb makes.
|
|
243
|
+
if (req.kind === 'version') {
|
|
244
|
+
return (await versionOf(runOpts, ['--version']));
|
|
245
|
+
}
|
|
246
|
+
// A verb that needs a git feature runs in the form this git supports,
|
|
247
|
+
// or rejects as `unsupported-git`. Others never probe.
|
|
248
|
+
const verb = gated.needs === undefined
|
|
249
|
+
? gated
|
|
250
|
+
: versionedVerb(gated, await versionOf(runOpts, [...prefix, ...gated.argv]), prefix);
|
|
223
251
|
if (verb.input !== undefined)
|
|
224
252
|
runOpts.input = verb.input;
|
|
225
253
|
// The verb's own entries (the C locale) win over the backend's and the call's.
|
|
@@ -230,10 +258,9 @@ export function cliBackend(opts = {}) {
|
|
|
230
258
|
// Unchecked `raw` is the only request that skips `gate`: it returns the
|
|
231
259
|
// result at any exit code. Everything else goes through the same `gate`
|
|
232
260
|
// the sync client uses.
|
|
233
|
-
const
|
|
234
|
-
const gated = req.kind !== 'raw' || req.checked === true;
|
|
261
|
+
const checked = req.kind !== 'raw' || req.checked === true;
|
|
235
262
|
// The prefixed argv is what ran, so it is what a `CommandFailed` reports.
|
|
236
|
-
const value =
|
|
263
|
+
const value = checked ? gate(verb, result, argv) : verb.parse(result, argv);
|
|
237
264
|
// `GitResults` restates the verb table's return types for callers. The
|
|
238
265
|
// two are kept in step by hand, and this cast is where they meet.
|
|
239
266
|
return value;
|
package/dist/client.d.ts
CHANGED
|
@@ -20,5 +20,7 @@ export { parseRemoteUrl, type RemoteCoordinate } from './remote-url.ts';
|
|
|
20
20
|
export { cliBackend, partialBackend, UnsupportedRequest, type GitBackend, type GitCallOptions, type GitRequest, type GitRequestKind, type GitResults, } from './backend.ts';
|
|
21
21
|
export { classifyGitFailure, describeGitFailure, type GitFailure, type GitFailureKind, } from './failure.ts';
|
|
22
22
|
export { type Soft, type TriedAsync, type TriedSync } from './outcome.ts';
|
|
23
|
-
export {
|
|
23
|
+
export { GIT_FEATURES, GIT_FLOOR, gitSupports, type GitFeature, type GitFeatureSpec, type GitRelease, type UnsupportedGit, } from './features.ts';
|
|
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 TaggedFile, type TreeEntry, type UnmergedEntry, type Worktree, type WorktreeAddOptions, type WorktreeMoveOptions, } from './verbs.ts';
|
|
24
26
|
export { asAsync, CommandFailed, runChecked, runCheckedAsync, spawnRunner, spawnRunnerAsync, type AsyncCommandRunner, type AsyncCommandRunOptions, type CommandResult, type CommandRunner, type CommandRunOptions, } from '@osdlc/command-seam';
|
package/dist/client.js
CHANGED
|
@@ -20,7 +20,9 @@ export { parseRemoteUrl } from "./remote-url.js";
|
|
|
20
20
|
export { cliBackend, partialBackend, UnsupportedRequest, } from "./backend.js";
|
|
21
21
|
export { classifyGitFailure, describeGitFailure, } from "./failure.js";
|
|
22
22
|
export {} from "./outcome.js";
|
|
23
|
-
export {
|
|
23
|
+
export { GIT_FEATURES, GIT_FLOOR, gitSupports, } from "./features.js";
|
|
24
|
+
export { compareGitVersions, parseGitVersion } from "./git-version.js";
|
|
25
|
+
export { forceWithLeaseArg, parseRefRows, PUSH_REJECTIONS, REF_FORMAT, } from "./verbs.js";
|
|
24
26
|
// The command-seam exports are re-exported so a caller wiring a runner or catching
|
|
25
27
|
// a failure needs one import, not two. `@osdlc/command-seam` is the package
|
|
26
28
|
// that owns these; it is usable on its own, without a git client.
|
package/dist/failure.d.ts
CHANGED
|
@@ -7,9 +7,14 @@
|
|
|
7
7
|
* non-English locale git translates its messages. Those keep command-seam's
|
|
8
8
|
* kind, so an unrecognised failure is still an `exit` with git's first stderr
|
|
9
9
|
* line as its message, never a wrong git kind.
|
|
10
|
+
*
|
|
11
|
+
* One kind is not read from git's output: `unsupported-git`, which a client
|
|
12
|
+
* reports before it runs a verb the local git is too old for (see
|
|
13
|
+
* `./features.ts`).
|
|
10
14
|
*/
|
|
11
15
|
import { type CommandFailed, type CommandFailureKind } from '@osdlc/command-seam';
|
|
12
16
|
import { type Failure } from '@osdlc/result';
|
|
17
|
+
import type { UnsupportedGit } from './features.ts';
|
|
13
18
|
/**
|
|
14
19
|
* Why a git call failed:
|
|
15
20
|
*
|
|
@@ -29,9 +34,13 @@ import { type Failure } from '@osdlc/result';
|
|
|
29
34
|
* - `tls`: the TLS handshake failed ("unable to access … SSL certificate
|
|
30
35
|
* problem"). The host was reached, so this is not `remote-unreachable`, and
|
|
31
36
|
* retrying will not help until the clock, the CA certificates or the remote's
|
|
32
|
-
* certificate is fixed
|
|
37
|
+
* certificate is fixed;
|
|
38
|
+
* - `unsupported-git`: the local git is older than the verb needs ("merge-tree
|
|
39
|
+
* --write-tree needs git 2.38 or later; found 2.34.1"), or older than the
|
|
40
|
+
* 2.34 floor. The verb did not run. `unsupported` says which feature, and
|
|
41
|
+
* which git it needs and found.
|
|
33
42
|
*/
|
|
34
|
-
export type GitFailureKind = CommandFailureKind | 'not-a-repo' | 'no-remote' | 'remote-unreachable' | 'not-authenticated' | 'not-found' | 'tls';
|
|
43
|
+
export type GitFailureKind = CommandFailureKind | 'not-a-repo' | 'no-remote' | 'remote-unreachable' | 'not-authenticated' | 'not-found' | 'tls' | 'unsupported-git';
|
|
35
44
|
/** A failed git call. `message` is one line for a person; `detail` is git's own output. */
|
|
36
45
|
export interface GitFailure extends Failure<GitFailureKind> {
|
|
37
46
|
/** The binary that ran (`git`), when the runner reports one. */
|
|
@@ -42,8 +51,13 @@ export interface GitFailure extends Failure<GitFailureKind> {
|
|
|
42
51
|
exitCode: number | null;
|
|
43
52
|
/** The signal that ended git, when the runner knows it. */
|
|
44
53
|
signal?: NodeJS.Signals | null | undefined;
|
|
45
|
-
/**
|
|
46
|
-
|
|
54
|
+
/**
|
|
55
|
+
* The `CommandFailed` this was classified from. Absent for
|
|
56
|
+
* `unsupported-git`, where the verb never ran.
|
|
57
|
+
*/
|
|
58
|
+
cause?: CommandFailed | undefined;
|
|
59
|
+
/** For `unsupported-git`: the feature, the git it needs, and the git found. */
|
|
60
|
+
unsupported?: UnsupportedGit | undefined;
|
|
47
61
|
}
|
|
48
62
|
/** The git failure for a failed `git` run. */
|
|
49
63
|
export declare function classifyGitFailure(failed: CommandFailed): GitFailure;
|
package/dist/failure.js
CHANGED
|
@@ -7,6 +7,10 @@
|
|
|
7
7
|
* non-English locale git translates its messages. Those keep command-seam's
|
|
8
8
|
* kind, so an unrecognised failure is still an `exit` with git's first stderr
|
|
9
9
|
* line as its message, never a wrong git kind.
|
|
10
|
+
*
|
|
11
|
+
* One kind is not read from git's output: `unsupported-git`, which a client
|
|
12
|
+
* reports before it runs a verb the local git is too old for (see
|
|
13
|
+
* `./features.ts`).
|
|
10
14
|
*/
|
|
11
15
|
import { classifyFailed, isCommandFailed, } from '@osdlc/command-seam';
|
|
12
16
|
import { describe, FailureError, isFailure } from '@osdlc/result';
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The git feature table: the one place that says which git release each
|
|
3
|
+
* version-dependent feature needs, and which of them have a fallback.
|
|
4
|
+
*
|
|
5
|
+
* A verb that uses one of these features names it in `needs` (see `GitVerb`
|
|
6
|
+
* in `./verbs.ts`). Before such a verb runs, the client probes the git version
|
|
7
|
+
* once per runner (`./git-version.ts`) and calls {@link versionedVerb}, which
|
|
8
|
+
* picks the verb's own form, its `fallback` form, or throws the
|
|
9
|
+
* `unsupported-git` failure. No other module compares versions.
|
|
10
|
+
*
|
|
11
|
+
* Every feature at or below {@link GIT_FLOOR} is used without a check. Below
|
|
12
|
+
* the floor itself, every version-gated verb fails as `unsupported-git` with
|
|
13
|
+
* the feature `typed-git`, and no fallback is tried.
|
|
14
|
+
*
|
|
15
|
+
* The README's "Git versions" table is checked against this one by
|
|
16
|
+
* `tests/features.test.ts`.
|
|
17
|
+
*/
|
|
18
|
+
import { type GitFailure } from './failure.ts';
|
|
19
|
+
import { type GitVersion } from './git-version.ts';
|
|
20
|
+
import type { GitVerb } from './verbs.ts';
|
|
21
|
+
/** A `major.minor.patch` release, without the `text` a probed version carries. */
|
|
22
|
+
export type GitRelease = Pick<GitVersion, 'major' | 'minor' | 'patch'>;
|
|
23
|
+
/**
|
|
24
|
+
* The oldest git this package supports: 2.34, the git of Ubuntu 22.04 LTS.
|
|
25
|
+
* Every flag typed-git passes unconditionally is at least this old.
|
|
26
|
+
*/
|
|
27
|
+
export declare const GIT_FLOOR: GitRelease;
|
|
28
|
+
/** One row of {@link GIT_FEATURES}. */
|
|
29
|
+
export interface GitFeatureSpec {
|
|
30
|
+
/** The first git release with the feature. */
|
|
31
|
+
readonly minimum: GitRelease;
|
|
32
|
+
/** The methods that use it. */
|
|
33
|
+
readonly usedBy: readonly string[];
|
|
34
|
+
/**
|
|
35
|
+
* What runs instead on an older git, for a feature whose older form gives
|
|
36
|
+
* the same answer. A feature without one fails as `unsupported-git`.
|
|
37
|
+
*/
|
|
38
|
+
readonly fallback?: string;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Every git feature newer than {@link GIT_FLOOR} that typed-git uses.
|
|
42
|
+
*
|
|
43
|
+
* - `merge-tree --write-tree`: git 2.38 ("git merge-tree" learned a new mode
|
|
44
|
+
* that computes the merge tree, RelNotes/2.38.0). `--name-only` and `-z`
|
|
45
|
+
* arrived with it.
|
|
46
|
+
* - `merge-tree --merge-base`: git 2.40 ("merge-tree" learns a new
|
|
47
|
+
* `--merge-base` option, RelNotes/2.40.0).
|
|
48
|
+
* - `worktree list -z`: git 2.36 (NUL-terminated `--porcelain` output, because
|
|
49
|
+
* paths and lock reasons with unsafe bytes were not C-quoted correctly,
|
|
50
|
+
* RelNotes/2.36.0).
|
|
51
|
+
*/
|
|
52
|
+
export declare const GIT_FEATURES: Readonly<{
|
|
53
|
+
'merge-tree --write-tree': {
|
|
54
|
+
minimum: GitRelease;
|
|
55
|
+
usedBy: string[];
|
|
56
|
+
};
|
|
57
|
+
'merge-tree --merge-base': {
|
|
58
|
+
minimum: GitRelease;
|
|
59
|
+
usedBy: string[];
|
|
60
|
+
};
|
|
61
|
+
'worktree list -z': {
|
|
62
|
+
minimum: GitRelease;
|
|
63
|
+
usedBy: string[];
|
|
64
|
+
fallback: string;
|
|
65
|
+
};
|
|
66
|
+
}>;
|
|
67
|
+
/** A feature in {@link GIT_FEATURES}. */
|
|
68
|
+
export type GitFeature = keyof typeof GIT_FEATURES;
|
|
69
|
+
/** What an `unsupported-git` failure carries: the feature, the git it needs, and the git found. */
|
|
70
|
+
export interface UnsupportedGit {
|
|
71
|
+
/** The feature, or `typed-git` when the git is older than {@link GIT_FLOOR}. */
|
|
72
|
+
feature: GitFeature | 'typed-git';
|
|
73
|
+
/** The first git release that has it. */
|
|
74
|
+
needs: GitRelease;
|
|
75
|
+
/** The git that was found. */
|
|
76
|
+
have: GitVersion;
|
|
77
|
+
}
|
|
78
|
+
/** True when `have` has `feature`. */
|
|
79
|
+
export declare function gitSupports(feature: GitFeature, have: GitRelease): boolean;
|
|
80
|
+
/** The classified failure for a git too old for `feature`. */
|
|
81
|
+
export declare function unsupportedGitFailure(feature: GitFeature | 'typed-git', needs: GitRelease, have: GitVersion, argv: string[]): GitFailure;
|
|
82
|
+
/**
|
|
83
|
+
* The form of `verb` that the git at `have` can run: the verb itself when it
|
|
84
|
+
* needs nothing or `have` has its feature, its `fallback` when the feature has
|
|
85
|
+
* one in the table, otherwise a thrown `unsupported-git` failure. Below
|
|
86
|
+
* {@link GIT_FLOOR} a gated verb always throws.
|
|
87
|
+
*
|
|
88
|
+
* `prefix` is the repository binding the client adds, so the failure names
|
|
89
|
+
* the argv that would have run.
|
|
90
|
+
*/
|
|
91
|
+
export declare function versionedVerb<T>(verb: GitVerb<T>, have: GitVersion, prefix?: readonly string[]): GitVerb<T>;
|
package/dist/features.js
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The git feature table: the one place that says which git release each
|
|
3
|
+
* version-dependent feature needs, and which of them have a fallback.
|
|
4
|
+
*
|
|
5
|
+
* A verb that uses one of these features names it in `needs` (see `GitVerb`
|
|
6
|
+
* in `./verbs.ts`). Before such a verb runs, the client probes the git version
|
|
7
|
+
* once per runner (`./git-version.ts`) and calls {@link versionedVerb}, which
|
|
8
|
+
* picks the verb's own form, its `fallback` form, or throws the
|
|
9
|
+
* `unsupported-git` failure. No other module compares versions.
|
|
10
|
+
*
|
|
11
|
+
* Every feature at or below {@link GIT_FLOOR} is used without a check. Below
|
|
12
|
+
* the floor itself, every version-gated verb fails as `unsupported-git` with
|
|
13
|
+
* the feature `typed-git`, and no fallback is tried.
|
|
14
|
+
*
|
|
15
|
+
* The README's "Git versions" table is checked against this one by
|
|
16
|
+
* `tests/features.test.ts`.
|
|
17
|
+
*/
|
|
18
|
+
import { FailureError } from '@osdlc/result';
|
|
19
|
+
import { describeGitFailure } from "./failure.js";
|
|
20
|
+
import { compareGitVersions, formatGitVersion } from "./git-version.js";
|
|
21
|
+
/**
|
|
22
|
+
* The oldest git this package supports: 2.34, the git of Ubuntu 22.04 LTS.
|
|
23
|
+
* Every flag typed-git passes unconditionally is at least this old.
|
|
24
|
+
*/
|
|
25
|
+
export const GIT_FLOOR = Object.freeze({ major: 2, minor: 34, patch: 0 });
|
|
26
|
+
const release = (major, minor) => Object.freeze({ major, minor, patch: 0 });
|
|
27
|
+
/**
|
|
28
|
+
* Every git feature newer than {@link GIT_FLOOR} that typed-git uses.
|
|
29
|
+
*
|
|
30
|
+
* - `merge-tree --write-tree`: git 2.38 ("git merge-tree" learned a new mode
|
|
31
|
+
* that computes the merge tree, RelNotes/2.38.0). `--name-only` and `-z`
|
|
32
|
+
* arrived with it.
|
|
33
|
+
* - `merge-tree --merge-base`: git 2.40 ("merge-tree" learns a new
|
|
34
|
+
* `--merge-base` option, RelNotes/2.40.0).
|
|
35
|
+
* - `worktree list -z`: git 2.36 (NUL-terminated `--porcelain` output, because
|
|
36
|
+
* paths and lock reasons with unsafe bytes were not C-quoted correctly,
|
|
37
|
+
* RelNotes/2.36.0).
|
|
38
|
+
*/
|
|
39
|
+
export const GIT_FEATURES = Object.freeze({
|
|
40
|
+
'merge-tree --write-tree': { minimum: release(2, 38), usedBy: ['mergeTree'] },
|
|
41
|
+
'merge-tree --merge-base': { minimum: release(2, 40), usedBy: ['mergeTree({ mergeBase })'] },
|
|
42
|
+
'worktree list -z': {
|
|
43
|
+
minimum: release(2, 36),
|
|
44
|
+
usedBy: ['worktrees'],
|
|
45
|
+
fallback: 'newline-split `worktree list --porcelain`: a path with a newline breaks it, and a lock reason comes back C-quoted',
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
/** True when `have` has `feature`. */
|
|
49
|
+
export function gitSupports(feature, have) {
|
|
50
|
+
return compareGitVersions(have, GIT_FEATURES[feature].minimum) >= 0;
|
|
51
|
+
}
|
|
52
|
+
/** `2.38` — a feature minimum as the README and the messages write it. */
|
|
53
|
+
function formatMinimum(v) {
|
|
54
|
+
return v.patch === 0 ? `${v.major}.${v.minor}` : formatGitVersion(v);
|
|
55
|
+
}
|
|
56
|
+
/** The classified failure for a git too old for `feature`. */
|
|
57
|
+
export function unsupportedGitFailure(feature, needs, have, argv) {
|
|
58
|
+
const want = formatMinimum(needs);
|
|
59
|
+
return {
|
|
60
|
+
kind: 'unsupported-git',
|
|
61
|
+
message: `${feature} needs git ${want} or later; found ${formatGitVersion(have)}.`,
|
|
62
|
+
hint: `Upgrade git to ${want} or later from https://git-scm.com.`,
|
|
63
|
+
detail: `git version ${have.text}`,
|
|
64
|
+
argv,
|
|
65
|
+
exitCode: null,
|
|
66
|
+
unsupported: { feature, needs, have },
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
function throwUnsupported(feature, needs, have, argv) {
|
|
70
|
+
const failure = unsupportedGitFailure(feature, needs, have, argv);
|
|
71
|
+
const thrown = new FailureError(failure);
|
|
72
|
+
thrown.message = describeGitFailure(failure);
|
|
73
|
+
throw thrown;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* The form of `verb` that the git at `have` can run: the verb itself when it
|
|
77
|
+
* needs nothing or `have` has its feature, its `fallback` when the feature has
|
|
78
|
+
* one in the table, otherwise a thrown `unsupported-git` failure. Below
|
|
79
|
+
* {@link GIT_FLOOR} a gated verb always throws.
|
|
80
|
+
*
|
|
81
|
+
* `prefix` is the repository binding the client adds, so the failure names
|
|
82
|
+
* the argv that would have run.
|
|
83
|
+
*/
|
|
84
|
+
export function versionedVerb(verb, have, prefix = []) {
|
|
85
|
+
const feature = verb.needs;
|
|
86
|
+
if (feature === undefined)
|
|
87
|
+
return verb;
|
|
88
|
+
const argv = [...prefix, ...verb.argv];
|
|
89
|
+
if (compareGitVersions(have, GIT_FLOOR) < 0)
|
|
90
|
+
throwUnsupported('typed-git', GIT_FLOOR, have, argv);
|
|
91
|
+
if (gitSupports(feature, have))
|
|
92
|
+
return verb;
|
|
93
|
+
const spec = GIT_FEATURES[feature];
|
|
94
|
+
if (spec.fallback !== undefined && verb.fallback !== undefined) {
|
|
95
|
+
return versionedVerb(verb.fallback, have, prefix);
|
|
96
|
+
}
|
|
97
|
+
return throwUnsupported(feature, spec.minimum, have, argv);
|
|
98
|
+
}
|
package/dist/git-url.d.ts
CHANGED
|
@@ -37,6 +37,9 @@ export interface RemoteRepo {
|
|
|
37
37
|
* `host/owner/repo`, scp-style or `scheme://`, where `owner` is the second to
|
|
38
38
|
* last path segment.
|
|
39
39
|
*
|
|
40
|
+
* `ssh.github.com` (GitHub's SSH over port 443) and `www.github.com` read as
|
|
41
|
+
* `github.com`.
|
|
42
|
+
*
|
|
40
43
|
* Use it to read a remote into the repository it names. To decide which forge
|
|
41
44
|
* a host is, compare `host`, never the URL text: `notgithub.com` is not
|
|
42
45
|
* GitHub, and neither is a path that mentions `github.com`.
|
package/dist/git-url.js
CHANGED
|
@@ -40,6 +40,9 @@ export function gitSshUrl(ref) {
|
|
|
40
40
|
* `host/owner/repo`, scp-style or `scheme://`, where `owner` is the second to
|
|
41
41
|
* last path segment.
|
|
42
42
|
*
|
|
43
|
+
* `ssh.github.com` (GitHub's SSH over port 443) and `www.github.com` read as
|
|
44
|
+
* `github.com`.
|
|
45
|
+
*
|
|
43
46
|
* Use it to read a remote into the repository it names. To decide which forge
|
|
44
47
|
* a host is, compare `host`, never the URL text: `notgithub.com` is not
|
|
45
48
|
* GitHub, and neither is a path that mentions `github.com`.
|
|
@@ -47,12 +50,21 @@ export function gitSshUrl(ref) {
|
|
|
47
50
|
export function parseRemoteRepo(url) {
|
|
48
51
|
const info = parseGitUrl(url);
|
|
49
52
|
if (info !== null && info.user && info.project) {
|
|
50
|
-
return { host: info.domain, owner: info.user, repo: info.project };
|
|
53
|
+
return { host: canonicalHost(info.domain), owner: info.user, repo: info.project };
|
|
51
54
|
}
|
|
52
55
|
const remote = parseRemoteUrl(url);
|
|
53
56
|
if (remote === null)
|
|
54
57
|
return null;
|
|
55
|
-
return { host: remote.host
|
|
58
|
+
return { host: canonicalHost(remote.host), owner: remote.owner, repo: remote.repo };
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* GitHub's other names for itself, read as `github.com`: `ssh.github.com` is
|
|
62
|
+
* its SSH-over-443 endpoint, and `www.github.com` redirects.
|
|
63
|
+
*/
|
|
64
|
+
const GITHUB_ALIASES = new Set(['ssh.github.com', 'www.github.com']);
|
|
65
|
+
function canonicalHost(host) {
|
|
66
|
+
const lower = host.toLowerCase();
|
|
67
|
+
return GITHUB_ALIASES.has(lower) ? 'github.com' : lower;
|
|
56
68
|
}
|
|
57
69
|
const SSH_INPUT = /^(?:ssh:\/\/|[A-Za-z0-9._-]+@)/;
|
|
58
70
|
const HTTP_INPUT = /^https?:\/\//i;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The git version: `git --version` parsed, and probed at most once per runner.
|
|
3
|
+
*
|
|
4
|
+
* Only a verb that declares `needs` (see `./features.ts`) asks for it, so a
|
|
5
|
+
* client that never runs such a verb never spawns `git --version`. The answer
|
|
6
|
+
* is cached against the runner object, so every client sharing a runner (a
|
|
7
|
+
* `Git` and its `at()` copies, every `AsyncGit` over one `cliBackend`) probes
|
|
8
|
+
* once between them.
|
|
9
|
+
*
|
|
10
|
+
* The cache key is the runner and the effective `PATH`, because a runner
|
|
11
|
+
* that finds git on `PATH` runs whichever git the call's `PATH` names.
|
|
12
|
+
*
|
|
13
|
+
* A failed probe is not cached: a missing git is reported on each call, as it
|
|
14
|
+
* is for any other verb.
|
|
15
|
+
*/
|
|
16
|
+
import { type AsyncCommandRunner, type CommandRunner, type EnvOverrides } from '@osdlc/command-seam';
|
|
17
|
+
import { type GitVerb } from './verbs.ts';
|
|
18
|
+
/**
|
|
19
|
+
* A git version, read from `git --version`.
|
|
20
|
+
*
|
|
21
|
+
* `major`, `minor` and `patch` are the leading numbers, so they compare as
|
|
22
|
+
* versions. Everything after them is in `text` only. A release candidate
|
|
23
|
+
* (`2.47.0.rc1`) reads as the release it leads to (2.47.0). A vendor build
|
|
24
|
+
* (`2.39.3 (Apple Git-146)`, `2.45.1.windows.1`) reads as the git release it
|
|
25
|
+
* is built from.
|
|
26
|
+
*/
|
|
27
|
+
export interface GitVersion {
|
|
28
|
+
major: number;
|
|
29
|
+
minor: number;
|
|
30
|
+
patch: number;
|
|
31
|
+
/** What git printed after `git version `, trimmed: `2.39.3 (Apple Git-146)`. */
|
|
32
|
+
text: string;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The version in one `git --version` output, or `null` when it is not one.
|
|
36
|
+
* Only the first line is read, so trailing build details do not matter.
|
|
37
|
+
*/
|
|
38
|
+
export declare function parseGitVersion(output: string): GitVersion | null;
|
|
39
|
+
/** Negative when `a` is older than `b`, zero when they are the same release, positive when newer. */
|
|
40
|
+
export declare function compareGitVersions(a: Pick<GitVersion, 'major' | 'minor' | 'patch'>, b: Pick<GitVersion, 'major' | 'minor' | 'patch'>): number;
|
|
41
|
+
/** `2.34.1` — the numbers only, without a vendor suffix. */
|
|
42
|
+
export declare function formatGitVersion(v: Pick<GitVersion, 'major' | 'minor' | 'patch'>): string;
|
|
43
|
+
/**
|
|
44
|
+
* `git --version`, parsed. Output that is not a version line is a failure,
|
|
45
|
+
* not a guess: the parse raises a `CommandFailed`, which `gate` classifies.
|
|
46
|
+
*/
|
|
47
|
+
export declare function versionVerb(): GitVerb<GitVersion>;
|
|
48
|
+
/**
|
|
49
|
+
* The time limit on the `git --version` probe itself. In the async client the
|
|
50
|
+
* probe is shared between concurrent callers, so no caller's own timeout or
|
|
51
|
+
* signal applies to it; each caller races its own against it instead.
|
|
52
|
+
*/
|
|
53
|
+
export declare const PROBE_TIMEOUT_MS = 15000;
|
|
54
|
+
/**
|
|
55
|
+
* What a probe call needs from the call that asked: its environment, its
|
|
56
|
+
* time limit and signal, and the argv a probe failure reports.
|
|
57
|
+
*/
|
|
58
|
+
export interface ProbeCall {
|
|
59
|
+
env?: EnvOverrides | undefined;
|
|
60
|
+
timeoutMs?: number | undefined;
|
|
61
|
+
signal?: AbortSignal | undefined;
|
|
62
|
+
/**
|
|
63
|
+
* The argv the failure names when the probe fails: the gated verb's, with
|
|
64
|
+
* the client's repository flags, so a missing git reads `git worktree: …`
|
|
65
|
+
* rather than `git --version: …`. `['--version']` for `version()` itself.
|
|
66
|
+
*/
|
|
67
|
+
report: string[];
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* The version of the git `runner` runs, for the call's `PATH`: probed on the
|
|
71
|
+
* first call, then cached. A failed probe is not cached. The probe runs under
|
|
72
|
+
* the call's `timeoutMs`, or {@link PROBE_TIMEOUT_MS} when it has none, so the
|
|
73
|
+
* first gated call can take up to the probe's time plus its own `timeoutMs`.
|
|
74
|
+
*/
|
|
75
|
+
export declare function probeGitVersion(runner: CommandRunner, call: ProbeCall): GitVersion;
|
|
76
|
+
/**
|
|
77
|
+
* {@link probeGitVersion} for an async runner. Concurrent first calls with
|
|
78
|
+
* the same `PATH` share one probe, which runs with no caller's signal and a
|
|
79
|
+
* fixed {@link PROBE_TIMEOUT_MS} limit. Each caller waits for it under its own
|
|
80
|
+
* `timeoutMs` and `signal`, so a caller that gives up rejects alone and the
|
|
81
|
+
* probe goes on for the others. Each caller reads the shared result itself,
|
|
82
|
+
* so a failure names that caller's verb. A failed probe is not cached.
|
|
83
|
+
*/
|
|
84
|
+
export declare function probeGitVersionAsync(runner: AsyncCommandRunner, call: ProbeCall): Promise<GitVersion>;
|
|
85
|
+
/**
|
|
86
|
+
* The `gitVersion` client option, parsed: `'2.55.0'`, or `git --version`'s
|
|
87
|
+
* whole line (`'git version 2.39.3 (Apple Git-146)'`). `undefined` when the
|
|
88
|
+
* option is not set. Anything else throws a `RangeError`, at construction.
|
|
89
|
+
*/
|
|
90
|
+
export declare function pinnedGitVersion(value: string | undefined): GitVersion | undefined;
|