@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.
@@ -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/soft.d.ts CHANGED
@@ -45,6 +45,7 @@ export declare const SOFT_TABLE: {
45
45
  readonly diffTreeNumstat: "empty";
46
46
  readonly grep: "empty";
47
47
  readonly isAncestor: "false";
48
+ readonly cherry: "empty";
48
49
  readonly remotes: "empty";
49
50
  readonly remote: "empty";
50
51
  readonly remoteGetUrl: "null";
package/dist/soft.js CHANGED
@@ -45,6 +45,7 @@ export const SOFT_TABLE = {
45
45
  diffTreeNumstat: 'empty',
46
46
  grep: 'empty',
47
47
  isAncestor: 'false',
48
+ cherry: 'empty',
48
49
  remotes: 'empty',
49
50
  remote: 'empty',
50
51
  remoteGetUrl: 'null',
package/dist/sync.d.ts CHANGED
@@ -16,9 +16,10 @@
16
16
  * service's compare-and-swap ref operations. That is not general git.
17
17
  */
18
18
  import { type CommandResult, type CommandRunner } from '@osdlc/command-seam';
19
+ import { type GitVersion } from './git-version.ts';
19
20
  import { type Soft, type TriedSync } from './outcome.ts';
20
21
  import { type RemoteCoordinate } from './remote-url.ts';
21
- import { type AddOptions, type AheadBehind, 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 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 PushPorcelainOptions, 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 CheckoutOptions, type ConfigGetOptions, type CloneOptions, type ConflictSide, type MergeOptions, type MergeOutcome, type MergeTreeOptions, type MergeTreeOutcome, type RebaseOptions, type RebaseOutcome, type RemoteGetUrlOptions, 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
23
  /**
23
24
  * Per-call concerns that are not part of the operation itself.
24
25
  *
@@ -50,6 +51,8 @@ export declare class Git {
50
51
  private readonly boundGitDir;
51
52
  private readonly workTree;
52
53
  private readonly env;
54
+ private readonly gitVersionOption;
55
+ private readonly pinnedVersion;
53
56
  private tried;
54
57
  private softened;
55
58
  /**
@@ -75,16 +78,23 @@ export declare class Git {
75
78
  * Neither client has a default timeout. This client kills a child whose
76
79
  * output on one stream passes 256 MB; `AsyncGit` has no output cap. The
77
80
  * `maxOutputBytes` call option sets the cap per call on both.
81
+ *
82
+ * `gitVersion` pins the git version: `'2.55.0'`, or a whole
83
+ * `git version …` line. Version-gated verbs then use it and never run
84
+ * `git --version`, and {@link Git.version} returns it. Set it with a fake
85
+ * runner, so the fake answers only the verbs under test. An unparsable
86
+ * value throws a `RangeError` here.
78
87
  */
79
88
  constructor(cwd: string, opts?: {
80
89
  runner?: CommandRunner | undefined;
81
90
  gitDir?: string | undefined;
82
91
  workTree?: string | undefined;
83
92
  env?: Record<string, string> | undefined;
93
+ gitVersion?: string | undefined;
84
94
  });
85
95
  /**
86
96
  * The same client in a different directory, with the same runner,
87
- * repository options and client-level `env`.
97
+ * repository options, client-level `env` and `gitVersion`.
88
98
  */
89
99
  at(cwd: string): Git;
90
100
  /**
@@ -127,8 +137,21 @@ export declare class Git {
127
137
  /** The verb's argv, after this client's `--git-dir` / `--work-tree` flags. */
128
138
  private argv;
129
139
  private runOpts;
130
- /** Run one verb from the table and check its result with `gate`. */
140
+ /**
141
+ * Run one verb from the table and check its result with `gate`. A verb that
142
+ * `needs` a git feature first gets the form this runner's git can run (see
143
+ * `versionedVerb` in `features.ts`), which probes the version once.
144
+ */
131
145
  private exec;
146
+ /**
147
+ * The git this client's runner runs, from `git --version`. Probed on the
148
+ * first call (or the first version-gated verb) and cached for the runner,
149
+ * so a client that never asks never spawns it. Throws the classified
150
+ * failure when git cannot run (`not-installed`), and an `exit` failure when
151
+ * the output is not a version line. With the `gitVersion` option it is that
152
+ * version, and nothing runs.
153
+ */
154
+ version(opts?: GitSyncCallOptions): GitVersion;
132
155
  /** A file's content at a rev (`git show <rev>:<relPath>`), null if absent. */
133
156
  showAtRev(rev: string, relPath: string, opts?: GitSyncCallOptions): string | null;
134
157
  /**
@@ -318,6 +341,13 @@ export declare class Git {
318
341
  isAncestor(a: string, b: string, opts?: GitSyncCallOptions): boolean;
319
342
  /** How far `tip` has diverged from `base`. See {@link AheadBehind}. */
320
343
  aheadBehind(base: string, tip: string, opts?: GitSyncCallOptions): AheadBehind;
344
+ /**
345
+ * Commits on `head` (default `HEAD`) that `upstream` lacks, each marked by
346
+ * whether `upstream` has the same patch. See {@link CherryEntry}.
347
+ */
348
+ cherry(upstream: string, head?: string, opts?: GitSyncCallOptions): CherryEntry[];
349
+ /** Write a commit for `tree` and return its sha; no ref moves. Needs a git identity. */
350
+ commitTree(tree: string, commitOpts: CommitTreeOptions, opts?: GitSyncCallOptions): string;
321
351
  /** Configured remote names (`git remote`); `[]` when there are none. */
322
352
  remotes(opts?: GitSyncCallOptions): string[];
323
353
  /**
@@ -370,21 +400,15 @@ export declare class Git {
370
400
  */
371
401
  clone(url: string, dest?: string | undefined, opts?: GitSyncCallOptions & CloneOptions): void;
372
402
  /**
373
- * Push a refspec. A {@link ForceLease} pins `--force-with-lease`, which means
374
- * "push only if the remote ref is still where I saw it". `{forceWithLease: true}` adds the
375
- * bare flag, which is the unsafe form: it compares against the
376
- * remote-tracking ref, which a fetch in this same process may have just
377
- * updated. `{delete: true}` deletes `refspec` on the remote. See `push` in
378
- * `verbs.ts`.
379
- */
380
- push(remote: string, refspec: string, opts?: GitSyncCallOptions & PushOptions): void;
381
- /**
382
- * `git push --porcelain`, read into one result per ref. A rejected ref comes
383
- * back with a typed `rejection` rather than a throw; a failure that reaches
384
- * no ref (an unknown remote, auth, network) still throws. See
385
- * `pushPorcelain` in `verbs.ts`.
403
+ * Push one refspec or several, read into one result per ref. A rejected
404
+ * ref comes back with a typed `rejection` rather than a throw, so check
405
+ * `flag`; a failure that reaches no ref (an unknown remote, auth, network)
406
+ * still throws. A {@link ForceLease} pins `--force-with-lease`, which means
407
+ * "push only if the remote ref is still where I saw it";
408
+ * `{forceWithLease: true}` is the unsafe bare flag. `{delete: true}`
409
+ * deletes each refspec on the remote. See `push` in `verbs.ts`.
386
410
  */
387
- pushPorcelain(remote: string, refspec: string | string[], opts?: GitSyncCallOptions & PushPorcelainOptions): PushReport;
411
+ push(remote: string, refspec: string | readonly string[], opts?: GitSyncCallOptions & PushOptions): PushReport;
388
412
  /** `git clean -f`, plus `-d` with `directories`. Ignored files are kept. */
389
413
  clean(opts?: GitSyncCallOptions & CleanOptions): void;
390
414
  /** `git reset --hard <rev>`. */
package/dist/sync.js CHANGED
@@ -17,6 +17,8 @@
17
17
  */
18
18
  import { basename, dirname, resolve } from 'node:path';
19
19
  import { spawnRunner, } from '@osdlc/command-seam';
20
+ import { versionedVerb } from "./features.js";
21
+ import { pinnedGitVersion, probeGitVersion } from "./git-version.js";
20
22
  import { softSync, triedSync } from "./outcome.js";
21
23
  import { parseRemoteUrl } from "./remote-url.js";
22
24
  import { SOFT_TABLE } from "./soft.js";
@@ -29,6 +31,8 @@ export class Git {
29
31
  boundGitDir;
30
32
  workTree;
31
33
  env;
34
+ gitVersionOption;
35
+ pinnedVersion;
32
36
  tried;
33
37
  softened;
34
38
  /**
@@ -54,9 +58,17 @@ export class Git {
54
58
  * Neither client has a default timeout. This client kills a child whose
55
59
  * output on one stream passes 256 MB; `AsyncGit` has no output cap. The
56
60
  * `maxOutputBytes` call option sets the cap per call on both.
61
+ *
62
+ * `gitVersion` pins the git version: `'2.55.0'`, or a whole
63
+ * `git version …` line. Version-gated verbs then use it and never run
64
+ * `git --version`, and {@link Git.version} returns it. Set it with a fake
65
+ * runner, so the fake answers only the verbs under test. An unparsable
66
+ * value throws a `RangeError` here.
57
67
  */
58
68
  constructor(cwd, opts = {}) {
59
69
  this.cwd = cwd;
70
+ this.gitVersionOption = opts.gitVersion;
71
+ this.pinnedVersion = pinnedGitVersion(opts.gitVersion);
60
72
  this.runner = opts.runner ?? spawnRunner('git', { absolutePathOnly: true });
61
73
  this.boundGitDir = opts.gitDir;
62
74
  this.workTree = opts.workTree;
@@ -64,7 +76,7 @@ export class Git {
64
76
  }
65
77
  /**
66
78
  * The same client in a different directory, with the same runner,
67
- * repository options and client-level `env`.
79
+ * repository options, client-level `env` and `gitVersion`.
68
80
  */
69
81
  at(cwd) {
70
82
  return new Git(cwd, {
@@ -72,6 +84,7 @@ export class Git {
72
84
  gitDir: this.boundGitDir,
73
85
  workTree: this.workTree,
74
86
  env: this.env,
87
+ gitVersion: this.gitVersionOption,
75
88
  });
76
89
  }
77
90
  /**
@@ -141,9 +154,25 @@ export class Git {
141
154
  run.input = opts.input;
142
155
  return run;
143
156
  }
144
- /** Run one verb from the table and check its result with `gate`. */
145
- exec(verb, opts = {}) {
157
+ /**
158
+ * Run one verb from the table and check its result with `gate`. A verb that
159
+ * `needs` a git feature first gets the form this runner's git can run (see
160
+ * `versionedVerb` in `features.ts`), which probes the version once.
161
+ */
162
+ exec(gated, opts = {}) {
146
163
  const run = this.runOpts(opts);
164
+ let verb = gated;
165
+ if (gated.needs !== undefined) {
166
+ const prefix = repoPrefix(this.boundGitDir, this.workTree);
167
+ // A failed probe names this verb's argv, not `--version`.
168
+ const have = this.pinnedVersion ??
169
+ probeGitVersion(this.runner, {
170
+ env: run.env,
171
+ timeoutMs: run.timeoutMs,
172
+ report: [...prefix, ...gated.argv],
173
+ });
174
+ verb = versionedVerb(gated, have, prefix);
175
+ }
147
176
  if (verb.input !== undefined)
148
177
  run.input = verb.input;
149
178
  // The verb's own entries (the C locale) win over the client's and the call's.
@@ -154,6 +183,24 @@ export class Git {
154
183
  return gate(verb, this.runner.run(argv, run), argv);
155
184
  }
156
185
  // ── queries ───────────────────────────────────────────────────────────────
186
+ /**
187
+ * The git this client's runner runs, from `git --version`. Probed on the
188
+ * first call (or the first version-gated verb) and cached for the runner,
189
+ * so a client that never asks never spawns it. Throws the classified
190
+ * failure when git cannot run (`not-installed`), and an `exit` failure when
191
+ * the output is not a version line. With the `gitVersion` option it is that
192
+ * version, and nothing runs.
193
+ */
194
+ version(opts = {}) {
195
+ if (this.pinnedVersion !== undefined)
196
+ return this.pinnedVersion;
197
+ const run = this.runOpts(opts);
198
+ return probeGitVersion(this.runner, {
199
+ env: run.env,
200
+ timeoutMs: run.timeoutMs,
201
+ report: ['--version'],
202
+ });
203
+ }
157
204
  /** A file's content at a rev (`git show <rev>:<relPath>`), null if absent. */
158
205
  showAtRev(rev, relPath, opts = {}) {
159
206
  return this.exec(v.showAtRev(rev, relPath), opts);
@@ -451,6 +498,17 @@ export class Git {
451
498
  aheadBehind(base, tip, opts = {}) {
452
499
  return this.exec(v.aheadBehind(base, tip), opts);
453
500
  }
501
+ /**
502
+ * Commits on `head` (default `HEAD`) that `upstream` lacks, each marked by
503
+ * whether `upstream` has the same patch. See {@link CherryEntry}.
504
+ */
505
+ cherry(upstream, head, opts = {}) {
506
+ return this.exec(v.cherry(upstream, head), opts);
507
+ }
508
+ /** Write a commit for `tree` and return its sha; no ref moves. Needs a git identity. */
509
+ commitTree(tree, commitOpts, opts = {}) {
510
+ return this.exec(v.commitTree(tree, commitOpts), opts);
511
+ }
454
512
  /** Configured remote names (`git remote`); `[]` when there are none. */
455
513
  remotes(opts = {}) {
456
514
  return this.exec(v.remote(), opts);
@@ -529,24 +587,16 @@ export class Git {
529
587
  this.exec(v.clone(url, dest, opts), opts);
530
588
  }
531
589
  /**
532
- * Push a refspec. A {@link ForceLease} pins `--force-with-lease`, which means
533
- * "push only if the remote ref is still where I saw it". `{forceWithLease: true}` adds the
534
- * bare flag, which is the unsafe form: it compares against the
535
- * remote-tracking ref, which a fetch in this same process may have just
536
- * updated. `{delete: true}` deletes `refspec` on the remote. See `push` in
537
- * `verbs.ts`.
590
+ * Push one refspec or several, read into one result per ref. A rejected
591
+ * ref comes back with a typed `rejection` rather than a throw, so check
592
+ * `flag`; a failure that reaches no ref (an unknown remote, auth, network)
593
+ * still throws. A {@link ForceLease} pins `--force-with-lease`, which means
594
+ * "push only if the remote ref is still where I saw it";
595
+ * `{forceWithLease: true}` is the unsafe bare flag. `{delete: true}`
596
+ * deletes each refspec on the remote. See `push` in `verbs.ts`.
538
597
  */
539
598
  push(remote, refspec, opts = {}) {
540
- this.exec(v.push(remote, refspec, opts), opts);
541
- }
542
- /**
543
- * `git push --porcelain`, read into one result per ref. A rejected ref comes
544
- * back with a typed `rejection` rather than a throw; a failure that reaches
545
- * no ref (an unknown remote, auth, network) still throws. See
546
- * `pushPorcelain` in `verbs.ts`.
547
- */
548
- pushPorcelain(remote, refspec, opts = {}) {
549
- return this.exec(v.pushPorcelain(remote, refspec, opts), opts);
599
+ return this.exec(v.push(remote, refspec, opts), opts);
550
600
  }
551
601
  /** `git clean -f`, plus `-d` with `directories`. Ignored files are kept. */
552
602
  clean(opts = {}) {