@osdlc/typed-git 0.8.2 → 0.11.1
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 +62 -0
- package/README.md +123 -18
- package/dist/async.d.ts +32 -12
- package/dist/async.js +62 -13
- package/dist/backend.d.ts +53 -11
- package/dist/backend.js +44 -7
- package/dist/checkout-root.d.ts +2 -1
- package/dist/checkout-root.js +7 -1
- package/dist/client.d.ts +3 -1
- package/dist/client.js +2 -0
- package/dist/failure.d.ts +18 -4
- package/dist/failure.js +10 -17
- package/dist/features.d.ts +91 -0
- package/dist/features.js +98 -0
- package/dist/git-url.d.ts +27 -0
- package/dist/git-url.js +55 -1
- package/dist/git-version.d.ts +90 -0
- package/dist/git-version.js +225 -0
- package/dist/index.d.ts +4 -3
- package/dist/index.js +4 -3
- package/dist/outcome.d.ts +7 -2
- package/dist/outcome.js +9 -45
- package/dist/remote-url.d.ts +2 -2
- package/dist/remote-url.js +7 -3
- package/dist/soft.d.ts +2 -0
- package/dist/soft.js +2 -0
- package/dist/sync.d.ts +67 -16
- package/dist/sync.js +115 -10
- package/dist/verbs.d.ts +197 -10
- package/dist/verbs.js +255 -62
- package/package.json +2 -2
package/dist/git-url.js
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
// oxlint-disable-next-line typescript/triple-slash-reference
|
|
11
11
|
/// <reference path="./hosted-git-info.d.ts" />
|
|
12
12
|
import hostedGitInfo from 'hosted-git-info';
|
|
13
|
+
import { parseRemoteUrl } from "./remote-url.js";
|
|
13
14
|
/** Parse `ref`, or null when it doesn't match a known git host. */
|
|
14
15
|
export function parseGitUrl(ref) {
|
|
15
16
|
const info = hostedGitInfo.fromUrl(ref);
|
|
@@ -27,6 +28,44 @@ export function parseGitUrl(ref) {
|
|
|
27
28
|
export function gitSshUrl(ref) {
|
|
28
29
|
return hostedGitInfo.fromUrl(ref)?.ssh() ?? null;
|
|
29
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* `{host, owner, repo}` from a git remote reference, or null when it names no
|
|
33
|
+
* project (a local path, a single path segment).
|
|
34
|
+
*
|
|
35
|
+
* It reads a known host (GitHub, GitLab, Bitbucket, Sourcehut) with
|
|
36
|
+
* {@link parseGitUrl} first, so `owner/repo` and `github:owner/repo`
|
|
37
|
+
* shorthand read as GitHub and a GitLab nested group stays whole in `owner`
|
|
38
|
+
* (`group/sub`). Any other clone URL, such as a GitHub Enterprise or a
|
|
39
|
+
* self-hosted Forgejo remote, is read host-agnostically by `parseRemoteUrl`:
|
|
40
|
+
* `host/owner/repo`, scp-style or `scheme://`, where `owner` is the second to
|
|
41
|
+
* last path segment.
|
|
42
|
+
*
|
|
43
|
+
* `ssh.github.com` (GitHub's SSH over port 443) and `www.github.com` read as
|
|
44
|
+
* `github.com`.
|
|
45
|
+
*
|
|
46
|
+
* Use it to read a remote into the repository it names. To decide which forge
|
|
47
|
+
* a host is, compare `host`, never the URL text: `notgithub.com` is not
|
|
48
|
+
* GitHub, and neither is a path that mentions `github.com`.
|
|
49
|
+
*/
|
|
50
|
+
export function parseRemoteRepo(url) {
|
|
51
|
+
const info = parseGitUrl(url);
|
|
52
|
+
if (info !== null && info.user && info.project) {
|
|
53
|
+
return { host: canonicalHost(info.domain), owner: info.user, repo: info.project };
|
|
54
|
+
}
|
|
55
|
+
const remote = parseRemoteUrl(url);
|
|
56
|
+
if (remote === null)
|
|
57
|
+
return null;
|
|
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;
|
|
68
|
+
}
|
|
30
69
|
const SSH_INPUT = /^(?:ssh:\/\/|[A-Za-z0-9._-]+@)/;
|
|
31
70
|
const HTTP_INPUT = /^https?:\/\//i;
|
|
32
71
|
/**
|
|
@@ -47,7 +86,7 @@ export function parseRepoRef(input, protocol = 'https') {
|
|
|
47
86
|
const text = input.trim();
|
|
48
87
|
if (text === '')
|
|
49
88
|
return null;
|
|
50
|
-
const info = parseGitUrl(text) ??
|
|
89
|
+
const info = parseGitUrl(text) ?? parseWebPage(text);
|
|
51
90
|
if (info === null || !info.user || !info.project)
|
|
52
91
|
return null;
|
|
53
92
|
const { domain: host, user: owner, project: repo } = info;
|
|
@@ -59,6 +98,21 @@ export function parseRepoRef(input, protocol = 'https') {
|
|
|
59
98
|
const cloneUrl = kind === 'ssh' ? `git@${host}:${owner}/${repo}.git` : `https://${host}/${owner}/${repo}.git`;
|
|
60
99
|
return { host, owner, repo, cloneUrl, committish: info.committish };
|
|
61
100
|
}
|
|
101
|
+
/**
|
|
102
|
+
* A web page under a project, read as the project. A GitLab page
|
|
103
|
+
* (`https://host/group/sub/repo/-/…`) is first cut at its `/-/`, which keeps a
|
|
104
|
+
* nested group whole. When that names no project (a GitHub path can hold a `-`
|
|
105
|
+
* segment too), the page is cut to its first two path segments instead.
|
|
106
|
+
*/
|
|
107
|
+
function parseWebPage(text) {
|
|
108
|
+
const gitlab = /^(https?:\/\/[^/?#]+(?:\/[^/?#]+){2,}?)\/-(?:[/?#].*)?$/i.exec(text);
|
|
109
|
+
if (gitlab !== null) {
|
|
110
|
+
const info = parseGitUrl(gitlab[1]);
|
|
111
|
+
if (info !== null && info.user && info.project)
|
|
112
|
+
return info;
|
|
113
|
+
}
|
|
114
|
+
return parseGitUrl(trimWebPath(text));
|
|
115
|
+
}
|
|
62
116
|
/** `https://host/a/b/anything…` → `https://host/a/b`; other inputs unchanged. */
|
|
63
117
|
function trimWebPath(text) {
|
|
64
118
|
const m = /^(https?:\/\/[^/?#]+\/[^/?#]+\/[^/?#]+)(?:[/?#].*)?$/i.exec(text);
|
|
@@ -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;
|
|
@@ -0,0 +1,225 @@
|
|
|
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 { tmpdir } from 'node:os';
|
|
17
|
+
import { CommandFailed, } from '@osdlc/command-seam';
|
|
18
|
+
import { gate } from "./verbs.js";
|
|
19
|
+
const VERSION_LINE = /^git version (\d+)\.(\d+)(?:\.(\d+))?\S*(?:\s.*)?$/;
|
|
20
|
+
/**
|
|
21
|
+
* The version in one `git --version` output, or `null` when it is not one.
|
|
22
|
+
* Only the first line is read, so trailing build details do not matter.
|
|
23
|
+
*/
|
|
24
|
+
export function parseGitVersion(output) {
|
|
25
|
+
const line = output.trim().split(/\r?\n/, 1)[0]?.trim() ?? '';
|
|
26
|
+
const m = VERSION_LINE.exec(line);
|
|
27
|
+
if (m === null)
|
|
28
|
+
return null;
|
|
29
|
+
return {
|
|
30
|
+
major: Number(m[1]),
|
|
31
|
+
minor: Number(m[2]),
|
|
32
|
+
patch: m[3] === undefined ? 0 : Number(m[3]),
|
|
33
|
+
text: line.slice('git version '.length),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
/** Negative when `a` is older than `b`, zero when they are the same release, positive when newer. */
|
|
37
|
+
export function compareGitVersions(a, b) {
|
|
38
|
+
return a.major - b.major || a.minor - b.minor || a.patch - b.patch;
|
|
39
|
+
}
|
|
40
|
+
/** `2.34.1` — the numbers only, without a vendor suffix. */
|
|
41
|
+
export function formatGitVersion(v) {
|
|
42
|
+
return `${v.major}.${v.minor}.${v.patch}`;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* `git --version`, parsed. Output that is not a version line is a failure,
|
|
46
|
+
* not a guess: the parse raises a `CommandFailed`, which `gate` classifies.
|
|
47
|
+
*/
|
|
48
|
+
export function versionVerb() {
|
|
49
|
+
return {
|
|
50
|
+
argv: ['--version'],
|
|
51
|
+
absent: [],
|
|
52
|
+
// `git version` is not translated today. The C locale keeps it that way.
|
|
53
|
+
env: { LC_ALL: 'C' },
|
|
54
|
+
parse(r, ranArgv) {
|
|
55
|
+
const version = parseGitVersion(r.stdout);
|
|
56
|
+
if (version === null) {
|
|
57
|
+
// Exit 0 with no version line has no git error to show, so say what
|
|
58
|
+
// was wrong in the failure's own words.
|
|
59
|
+
const first = r.stdout.trim().split(/\r?\n/, 1)[0] ?? '';
|
|
60
|
+
const said = first === '' ? 'nothing' : JSON.stringify(first);
|
|
61
|
+
throw new CommandFailed(ranArgv, {
|
|
62
|
+
...r,
|
|
63
|
+
stderr: r.stderr.trim() === '' ? `git --version printed ${said}, not a version` : r.stderr,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
return version;
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* The time limit on the `git --version` probe itself. In the async client the
|
|
72
|
+
* probe is shared between concurrent callers, so no caller's own timeout or
|
|
73
|
+
* signal applies to it; each caller races its own against it instead.
|
|
74
|
+
*/
|
|
75
|
+
export const PROBE_TIMEOUT_MS = 15_000;
|
|
76
|
+
/**
|
|
77
|
+
* Where the probe runs: the OS temp directory, which always exists. The
|
|
78
|
+
* answer is cached per runner and `PATH`, not per directory, so a caller's
|
|
79
|
+
* cwd must not decide it, and a missing cwd must not fail it for others. The
|
|
80
|
+
* verb that asked still runs in its own cwd, and reports a bad one itself.
|
|
81
|
+
*/
|
|
82
|
+
function probeCwd() {
|
|
83
|
+
return tmpdir();
|
|
84
|
+
}
|
|
85
|
+
/** The probe's run options: the caller's environment, the C locale, the fixed cwd and time limit. */
|
|
86
|
+
function probeOptions(env, verb, timeoutMs) {
|
|
87
|
+
return { cwd: probeCwd(), env: { ...env, ...verb.env }, timeoutMs };
|
|
88
|
+
}
|
|
89
|
+
/** `env[name]` from the environment the runner sees, without case on Windows (`Path`). */
|
|
90
|
+
function effective(env, name) {
|
|
91
|
+
const merged = { ...process.env, ...env };
|
|
92
|
+
if (process.platform !== 'win32')
|
|
93
|
+
return merged[name];
|
|
94
|
+
// The last matching key wins, as a later spread would.
|
|
95
|
+
let value;
|
|
96
|
+
for (const [key, v] of Object.entries(merged))
|
|
97
|
+
if (key.toUpperCase() === name)
|
|
98
|
+
value = v;
|
|
99
|
+
return value;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* The cache key within one runner: the effective `PATH` (and `PATHEXT` on
|
|
103
|
+
* Windows), the call's `env` over the process's. An absolute-path-only runner
|
|
104
|
+
* looks `git` up on that `PATH`, so one runner can run two gits.
|
|
105
|
+
*/
|
|
106
|
+
function pathKey(env) {
|
|
107
|
+
const path = effective(env, 'PATH') ?? '\u0000unset';
|
|
108
|
+
return process.platform === 'win32' ? `${path}\u0000${effective(env, 'PATHEXT') ?? ''}` : path;
|
|
109
|
+
}
|
|
110
|
+
/** Per runner, per `PATH`: the version once known. */
|
|
111
|
+
const known = new WeakMap();
|
|
112
|
+
/** Per async runner, per `PATH`: the probe in flight, shared by concurrent callers. */
|
|
113
|
+
const inFlight = new WeakMap();
|
|
114
|
+
function knownFor(runner, key) {
|
|
115
|
+
return known.get(runner)?.get(key);
|
|
116
|
+
}
|
|
117
|
+
function remember(runner, key, version) {
|
|
118
|
+
let byPath = known.get(runner);
|
|
119
|
+
if (byPath === undefined)
|
|
120
|
+
known.set(runner, (byPath = new Map()));
|
|
121
|
+
byPath.set(key, version);
|
|
122
|
+
return version;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* The version of the git `runner` runs, for the call's `PATH`: probed on the
|
|
126
|
+
* first call, then cached. A failed probe is not cached. The probe runs under
|
|
127
|
+
* the call's `timeoutMs`, or {@link PROBE_TIMEOUT_MS} when it has none, so the
|
|
128
|
+
* first gated call can take up to the probe's time plus its own `timeoutMs`.
|
|
129
|
+
*/
|
|
130
|
+
export function probeGitVersion(runner, call) {
|
|
131
|
+
const key = pathKey(call.env);
|
|
132
|
+
const cached = knownFor(runner, key);
|
|
133
|
+
if (cached !== undefined)
|
|
134
|
+
return cached;
|
|
135
|
+
const verb = versionVerb();
|
|
136
|
+
const timeoutMs = Math.min(call.timeoutMs ?? PROBE_TIMEOUT_MS, PROBE_TIMEOUT_MS);
|
|
137
|
+
const result = runner.run(verb.argv, probeOptions(call.env, verb, timeoutMs));
|
|
138
|
+
return remember(runner, key, gate(verb, result, call.report));
|
|
139
|
+
}
|
|
140
|
+
/** A result standing in for a probe this caller stopped waiting for. */
|
|
141
|
+
function stopped(reason) {
|
|
142
|
+
return {
|
|
143
|
+
exitCode: 1,
|
|
144
|
+
stdout: '',
|
|
145
|
+
stderr: '',
|
|
146
|
+
neverExited: true,
|
|
147
|
+
reason,
|
|
148
|
+
error: reason === 'abort'
|
|
149
|
+
? 'The operation was aborted'
|
|
150
|
+
: 'timed out waiting for the git --version probe',
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
/** `probe`, or a stand-in result when the caller's own timeout or signal ends first. */
|
|
154
|
+
function race(probe, timeoutMs, signal) {
|
|
155
|
+
if (signal?.aborted === true)
|
|
156
|
+
return Promise.resolve(stopped('abort'));
|
|
157
|
+
const usable = typeof timeoutMs === 'number' && Number.isFinite(timeoutMs) && timeoutMs > 0
|
|
158
|
+
? Math.min(timeoutMs, 2 ** 31 - 1)
|
|
159
|
+
: undefined;
|
|
160
|
+
if (usable === undefined && signal === undefined)
|
|
161
|
+
return probe;
|
|
162
|
+
return new Promise((resolve, reject) => {
|
|
163
|
+
const timer = usable === undefined ? undefined : setTimeout(() => done(stopped('timeout')), usable);
|
|
164
|
+
const onAbort = () => done(stopped('abort'));
|
|
165
|
+
function done(result) {
|
|
166
|
+
if (timer !== undefined)
|
|
167
|
+
clearTimeout(timer);
|
|
168
|
+
signal?.removeEventListener('abort', onAbort);
|
|
169
|
+
resolve(result);
|
|
170
|
+
}
|
|
171
|
+
signal?.addEventListener('abort', onAbort, { once: true });
|
|
172
|
+
probe.then(done, (error) => {
|
|
173
|
+
if (timer !== undefined)
|
|
174
|
+
clearTimeout(timer);
|
|
175
|
+
signal?.removeEventListener('abort', onAbort);
|
|
176
|
+
reject(error);
|
|
177
|
+
});
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* {@link probeGitVersion} for an async runner. Concurrent first calls with
|
|
182
|
+
* the same `PATH` share one probe, which runs with no caller's signal and a
|
|
183
|
+
* fixed {@link PROBE_TIMEOUT_MS} limit. Each caller waits for it under its own
|
|
184
|
+
* `timeoutMs` and `signal`, so a caller that gives up rejects alone and the
|
|
185
|
+
* probe goes on for the others. Each caller reads the shared result itself,
|
|
186
|
+
* so a failure names that caller's verb. A failed probe is not cached.
|
|
187
|
+
*/
|
|
188
|
+
export async function probeGitVersionAsync(runner, call) {
|
|
189
|
+
const key = pathKey(call.env);
|
|
190
|
+
const cached = knownFor(runner, key);
|
|
191
|
+
if (cached !== undefined)
|
|
192
|
+
return cached;
|
|
193
|
+
const verb = versionVerb();
|
|
194
|
+
let byPath = inFlight.get(runner);
|
|
195
|
+
if (byPath === undefined)
|
|
196
|
+
inFlight.set(runner, (byPath = new Map()));
|
|
197
|
+
let probe = byPath.get(key);
|
|
198
|
+
if (probe === undefined) {
|
|
199
|
+
const started = runner.run(verb.argv, probeOptions(call.env, verb, PROBE_TIMEOUT_MS));
|
|
200
|
+
probe = started;
|
|
201
|
+
byPath.set(key, started);
|
|
202
|
+
const settle = () => {
|
|
203
|
+
if (byPath.get(key) === started)
|
|
204
|
+
byPath.delete(key);
|
|
205
|
+
};
|
|
206
|
+
started.then(settle, settle);
|
|
207
|
+
}
|
|
208
|
+
const result = await race(probe, call.timeoutMs, call.signal);
|
|
209
|
+
return knownFor(runner, key) ?? remember(runner, key, gate(verb, result, call.report));
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* The `gitVersion` client option, parsed: `'2.55.0'`, or `git --version`'s
|
|
213
|
+
* whole line (`'git version 2.39.3 (Apple Git-146)'`). `undefined` when the
|
|
214
|
+
* option is not set. Anything else throws a `RangeError`, at construction.
|
|
215
|
+
*/
|
|
216
|
+
export function pinnedGitVersion(value) {
|
|
217
|
+
if (value === undefined)
|
|
218
|
+
return undefined;
|
|
219
|
+
const text = value.trim();
|
|
220
|
+
const version = parseGitVersion(text.startsWith('git version ') ? text : `git version ${text}`);
|
|
221
|
+
if (version === null) {
|
|
222
|
+
throw new RangeError(`gitVersion must be a git version such as '2.55.0'; got '${value}'`);
|
|
223
|
+
}
|
|
224
|
+
return version;
|
|
225
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -24,14 +24,15 @@
|
|
|
24
24
|
*
|
|
25
25
|
* The verb table in `./verbs.ts` is the single definition of every argv,
|
|
26
26
|
* every absence code and every parser, so the two clients cannot drift apart.
|
|
27
|
-
* The
|
|
28
|
-
* `
|
|
27
|
+
* The exceptions are helpers that compose other verbs (`remoteOwnerRepo`,
|
|
28
|
+
* `hasHistory`, `mainCheckout`, `isDirty`, `branchExists`, `refs`,
|
|
29
|
+
* `logLines`). Each client writes them, so a change must be made in both.
|
|
29
30
|
*
|
|
30
31
|
* Subpath exports: `./client` is everything here except the git-reference
|
|
31
32
|
* parsers and the checkout walks (and so without `hosted-git-info` on the
|
|
32
33
|
* module graph); `./testing` is the temp-repo fixture builder.
|
|
33
34
|
*/
|
|
34
35
|
export * from './client.ts';
|
|
35
|
-
export { parseGitUrl, gitSshUrl, parseRepoRef, type GitHostInfo, type RepoRef, type CloneProtocol, } from './git-url.ts';
|
|
36
|
+
export { parseGitUrl, gitSshUrl, parseRemoteRepo, parseRepoRef, type GitHostInfo, type RemoteRepo, type RepoRef, type CloneProtocol, } from './git-url.ts';
|
|
36
37
|
export { checkoutRoot, discoverCheckouts, scanForCheckouts, DEFAULT_MAX_DEPTH, DEFAULT_WARN_AFTER, } from './checkout-root.ts';
|
|
37
38
|
export type { CheckoutScan, DiscoverCheckoutsOptions } from './checkout-root.ts';
|
package/dist/index.js
CHANGED
|
@@ -24,13 +24,14 @@
|
|
|
24
24
|
*
|
|
25
25
|
* The verb table in `./verbs.ts` is the single definition of every argv,
|
|
26
26
|
* every absence code and every parser, so the two clients cannot drift apart.
|
|
27
|
-
* The
|
|
28
|
-
* `
|
|
27
|
+
* The exceptions are helpers that compose other verbs (`remoteOwnerRepo`,
|
|
28
|
+
* `hasHistory`, `mainCheckout`, `isDirty`, `branchExists`, `refs`,
|
|
29
|
+
* `logLines`). Each client writes them, so a change must be made in both.
|
|
29
30
|
*
|
|
30
31
|
* Subpath exports: `./client` is everything here except the git-reference
|
|
31
32
|
* parsers and the checkout walks (and so without `hosted-git-info` on the
|
|
32
33
|
* module graph); `./testing` is the temp-repo fixture builder.
|
|
33
34
|
*/
|
|
34
35
|
export * from "./client.js";
|
|
35
|
-
export { parseGitUrl, gitSshUrl, parseRepoRef, } from "./git-url.js";
|
|
36
|
+
export { parseGitUrl, gitSshUrl, parseRemoteRepo, parseRepoRef, } from "./git-url.js";
|
|
36
37
|
export { checkoutRoot, discoverCheckouts, scanForCheckouts, DEFAULT_MAX_DEPTH, DEFAULT_WARN_AFTER, } from "./checkout-root.js";
|
package/dist/outcome.d.ts
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
* is `{ ok: true, value: null }`, because absence is an answer, not a
|
|
18
18
|
* failure.
|
|
19
19
|
*/
|
|
20
|
-
import {
|
|
20
|
+
import type { Result } from '@osdlc/result';
|
|
21
21
|
import { type GitFailure } from './failure.ts';
|
|
22
22
|
/**
|
|
23
23
|
* The methods `try` mirrors: everything except `raw`, `rawChecked`, `at`,
|
|
@@ -35,7 +35,12 @@ export type TriedSync<C> = {
|
|
|
35
35
|
export type TriedAsync<C> = {
|
|
36
36
|
[K in keyof Triable<C>]: Triable<C>[K] extends (...a: infer A) => Promise<infer R> ? (...a: A) => Promise<Result<R, GitFailure>> : never;
|
|
37
37
|
};
|
|
38
|
-
/**
|
|
38
|
+
/**
|
|
39
|
+
* Wrap a synchronous client so every method returns a `Result<T, GitFailure>`.
|
|
40
|
+
* The proxy is command-seam's `tryMethods`: it mirrors whatever the client
|
|
41
|
+
* has, with no per-verb entry to keep in step, and runs each method on the
|
|
42
|
+
* client itself, so private state stays reachable.
|
|
43
|
+
*/
|
|
39
44
|
export declare function triedSync<C extends object>(client: C): TriedSync<C>;
|
|
40
45
|
/** Wrap an awaitable client so every method promises a `Result<T, GitFailure>`. */
|
|
41
46
|
export declare function triedAsync<C extends object>(client: C): TriedAsync<C>;
|
package/dist/outcome.js
CHANGED
|
@@ -17,56 +17,20 @@
|
|
|
17
17
|
* is `{ ok: true, value: null }`, because absence is an answer, not a
|
|
18
18
|
* failure.
|
|
19
19
|
*/
|
|
20
|
-
import {
|
|
20
|
+
import { methodFacade, tryMethods, tryMethodsAsync } from '@osdlc/command-seam';
|
|
21
21
|
import { thrownGitFailure } from "./failure.js";
|
|
22
|
-
/** A thrown git failure becomes an `err`; anything else is thrown again. */
|
|
23
|
-
function asFailure(error) {
|
|
24
|
-
const failure = thrownGitFailure(error);
|
|
25
|
-
if (failure !== null)
|
|
26
|
-
return err(failure);
|
|
27
|
-
throw error;
|
|
28
|
-
}
|
|
29
22
|
/**
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
* per-verb entry to keep in step
|
|
33
|
-
* client itself,
|
|
23
|
+
* Wrap a synchronous client so every method returns a `Result<T, GitFailure>`.
|
|
24
|
+
* The proxy is command-seam's `tryMethods`: it mirrors whatever the client
|
|
25
|
+
* has, with no per-verb entry to keep in step, and runs each method on the
|
|
26
|
+
* client itself, so private state stays reachable.
|
|
34
27
|
*/
|
|
35
|
-
function facade(client, wrap) {
|
|
36
|
-
return new Proxy(client, {
|
|
37
|
-
get(target, prop) {
|
|
38
|
-
// Read from the target, not the proxy: a getter (`try` itself) must run
|
|
39
|
-
// against the real client rather than recursing through the proxy.
|
|
40
|
-
const value = Reflect.get(target, prop);
|
|
41
|
-
if (typeof value !== 'function')
|
|
42
|
-
return value;
|
|
43
|
-
const method = value;
|
|
44
|
-
const name = String(prop);
|
|
45
|
-
return (...args) => wrap(() => method.apply(target, args), name);
|
|
46
|
-
},
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
/** Wrap a synchronous client so every method returns a `Result<T, GitFailure>`. */
|
|
50
28
|
export function triedSync(client) {
|
|
51
|
-
return
|
|
52
|
-
try {
|
|
53
|
-
return ok(call());
|
|
54
|
-
}
|
|
55
|
-
catch (error) {
|
|
56
|
-
return asFailure(error);
|
|
57
|
-
}
|
|
58
|
-
});
|
|
29
|
+
return tryMethods(client, thrownGitFailure);
|
|
59
30
|
}
|
|
60
31
|
/** Wrap an awaitable client so every method promises a `Result<T, GitFailure>`. */
|
|
61
32
|
export function triedAsync(client) {
|
|
62
|
-
return
|
|
63
|
-
try {
|
|
64
|
-
return ok(await call());
|
|
65
|
-
}
|
|
66
|
-
catch (error) {
|
|
67
|
-
return asFailure(error);
|
|
68
|
-
}
|
|
69
|
-
});
|
|
33
|
+
return tryMethodsAsync(client, thrownGitFailure);
|
|
70
34
|
}
|
|
71
35
|
function fallbackFor(table, name) {
|
|
72
36
|
const kind = table[name];
|
|
@@ -77,7 +41,7 @@ function fallbackFor(table, name) {
|
|
|
77
41
|
}
|
|
78
42
|
/** Wrap a synchronous client so a failed call returns the verb's absence value. */
|
|
79
43
|
export function softSync(client, table) {
|
|
80
|
-
return
|
|
44
|
+
return methodFacade(client, (call, name) => {
|
|
81
45
|
try {
|
|
82
46
|
return call();
|
|
83
47
|
}
|
|
@@ -90,7 +54,7 @@ export function softSync(client, table) {
|
|
|
90
54
|
}
|
|
91
55
|
/** Wrap an awaitable client so a failed call resolves to the verb's absence value. */
|
|
92
56
|
export function softAsync(client, table) {
|
|
93
|
-
return
|
|
57
|
+
return methodFacade(client, async (call, name) => {
|
|
94
58
|
try {
|
|
95
59
|
return await call();
|
|
96
60
|
}
|
package/dist/remote-url.d.ts
CHANGED
|
@@ -20,8 +20,8 @@ export interface RemoteCoordinate {
|
|
|
20
20
|
* Parses `git@host:owner/repo.git` (scp-style) and
|
|
21
21
|
* `scheme://[user@]host[:port]/owner/repo[.git]`. The last two path segments
|
|
22
22
|
* are the owner and repo, so a nested group (`group/sub/repo`) answers
|
|
23
|
-
* `owner: "sub"`. Returns null for anything else (a local path
|
|
24
|
-
* path segment).
|
|
23
|
+
* `owner: "sub"`. Returns null for anything else (a local path or a
|
|
24
|
+
* `file://` URL, a single path segment).
|
|
25
25
|
*
|
|
26
26
|
* Only an `http(s)://` port is read. An `ssh://` port is dropped, so `port` is
|
|
27
27
|
* null for `ssh://git@host:2222/owner/repo.git`.
|
package/dist/remote-url.js
CHANGED
|
@@ -12,14 +12,17 @@
|
|
|
12
12
|
* Parses `git@host:owner/repo.git` (scp-style) and
|
|
13
13
|
* `scheme://[user@]host[:port]/owner/repo[.git]`. The last two path segments
|
|
14
14
|
* are the owner and repo, so a nested group (`group/sub/repo`) answers
|
|
15
|
-
* `owner: "sub"`. Returns null for anything else (a local path
|
|
16
|
-
* path segment).
|
|
15
|
+
* `owner: "sub"`. Returns null for anything else (a local path or a
|
|
16
|
+
* `file://` URL, a single path segment).
|
|
17
17
|
*
|
|
18
18
|
* Only an `http(s)://` port is read. An `ssh://` port is dropped, so `port` is
|
|
19
19
|
* null for `ssh://git@host:2222/owner/repo.git`.
|
|
20
20
|
*/
|
|
21
21
|
export function parseRemoteUrl(url) {
|
|
22
22
|
const trimmed = url.trim();
|
|
23
|
+
// `file://localhost/srv/git/a/b.git` is a local path, not a forge coordinate.
|
|
24
|
+
if (/^file:/i.test(trimmed))
|
|
25
|
+
return null;
|
|
23
26
|
const scp = /^[\w.-]+@([^:/]+):(.+)$/.exec(trimmed);
|
|
24
27
|
const uri = /^[a-z][a-z0-9+.-]*:\/\/(?:[^@/]+@)?([^/:]+)(?::(\d+))?\/(.+)$/i.exec(trimmed);
|
|
25
28
|
const match = scp ?? uri;
|
|
@@ -30,7 +33,8 @@ export function parseRemoteUrl(url) {
|
|
|
30
33
|
const isHttp = match === uri && /^https?:/i.test(trimmed);
|
|
31
34
|
const port = isHttp && match[2] !== undefined ? Number(match[2]) : null;
|
|
32
35
|
const rest = match === uri ? match[3] : match[2];
|
|
33
|
-
|
|
36
|
+
// Trim the slashes first, so `repo.git/` loses its `.git` too.
|
|
37
|
+
const path = rest.replace(/^\/+|\/+$/g, '').replace(/\.git$/, '');
|
|
34
38
|
const parts = path.split('/').filter((p) => p !== '');
|
|
35
39
|
if (parts.length < 2)
|
|
36
40
|
return null;
|
package/dist/soft.d.ts
CHANGED
|
@@ -22,6 +22,7 @@ export declare const SOFT_TABLE: {
|
|
|
22
22
|
readonly statusPorcelain: "empty";
|
|
23
23
|
readonly statusEntries: "empty";
|
|
24
24
|
readonly isDirty: "false";
|
|
25
|
+
readonly hasStagedChanges: "false";
|
|
25
26
|
readonly branches: "empty";
|
|
26
27
|
readonly branchExists: "false";
|
|
27
28
|
readonly worktrees: "empty";
|
|
@@ -44,6 +45,7 @@ export declare const SOFT_TABLE: {
|
|
|
44
45
|
readonly diffTreeNumstat: "empty";
|
|
45
46
|
readonly grep: "empty";
|
|
46
47
|
readonly isAncestor: "false";
|
|
48
|
+
readonly cherry: "empty";
|
|
47
49
|
readonly remotes: "empty";
|
|
48
50
|
readonly remote: "empty";
|
|
49
51
|
readonly remoteGetUrl: "null";
|
package/dist/soft.js
CHANGED
|
@@ -22,6 +22,7 @@ export const SOFT_TABLE = {
|
|
|
22
22
|
statusPorcelain: 'empty',
|
|
23
23
|
statusEntries: 'empty',
|
|
24
24
|
isDirty: 'false',
|
|
25
|
+
hasStagedChanges: 'false',
|
|
25
26
|
branches: 'empty',
|
|
26
27
|
branchExists: 'false',
|
|
27
28
|
worktrees: 'empty',
|
|
@@ -44,6 +45,7 @@ export const SOFT_TABLE = {
|
|
|
44
45
|
diffTreeNumstat: 'empty',
|
|
45
46
|
grep: 'empty',
|
|
46
47
|
isAncestor: 'false',
|
|
48
|
+
cherry: 'empty',
|
|
47
49
|
remotes: 'empty',
|
|
48
50
|
remote: 'empty',
|
|
49
51
|
remoteGetUrl: 'null',
|