@osdlc/typed-git 0.5.0 → 0.5.3
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 +83 -36
- package/LICENSE-APACHE +202 -0
- package/README.md +133 -30
- package/async.ts +109 -32
- package/backend.ts +57 -12
- package/client.ts +18 -8
- package/dist/async.d.ts +59 -23
- package/dist/async.d.ts.map +1 -1
- package/dist/async.js +87 -29
- package/dist/backend.d.ts +50 -9
- package/dist/backend.d.ts.map +1 -1
- package/dist/backend.js +25 -3
- package/dist/client.d.ts +10 -7
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +10 -7
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/outcome.d.ts +6 -1
- package/dist/outcome.d.ts.map +1 -1
- package/dist/remote-url.d.ts +3 -0
- package/dist/remote-url.d.ts.map +1 -1
- package/dist/remote-url.js +3 -0
- package/dist/soft.d.ts +7 -1
- package/dist/soft.d.ts.map +1 -1
- package/dist/soft.js +7 -1
- package/dist/sync.d.ts +74 -24
- package/dist/sync.d.ts.map +1 -1
- package/dist/sync.js +99 -28
- package/dist/testing.d.ts +54 -26
- package/dist/testing.d.ts.map +1 -1
- package/dist/testing.js +11 -4
- package/dist/verbs.d.ts +163 -41
- package/dist/verbs.d.ts.map +1 -1
- package/dist/verbs.js +342 -83
- package/index.ts +2 -2
- package/outcome.ts +13 -5
- package/package.json +11 -6
- package/remote-url.ts +3 -0
- package/soft.ts +7 -1
- package/sync.ts +114 -31
- package/testing.ts +64 -32
- package/verbs.ts +427 -103
- /package/{LICENSE → LICENSE-MIT} +0 -0
package/index.ts
CHANGED
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
* `parseRemoteUrl` written in each client.
|
|
28
28
|
*
|
|
29
29
|
* Subpath exports: `./client` is everything here except the git-reference
|
|
30
|
-
* parsers (and so without `hosted-git-info` on the
|
|
31
|
-
* is the temp-repo fixture builder.
|
|
30
|
+
* parsers and the checkout walks (and so without `hosted-git-info` on the
|
|
31
|
+
* module graph); `./testing` is the temp-repo fixture builder.
|
|
32
32
|
*/
|
|
33
33
|
|
|
34
34
|
export * from './client.ts'
|
package/outcome.ts
CHANGED
|
@@ -115,14 +115,22 @@ type SoftKind<R> = R extends readonly unknown[]
|
|
|
115
115
|
|
|
116
116
|
type Unwrap<R> = R extends Promise<infer U> ? U : R
|
|
117
117
|
|
|
118
|
+
/**
|
|
119
|
+
* Methods left out of the soft door although their return type has an absence
|
|
120
|
+
* value. `configRemoveSection` is a mutation, and no mutation has a soft form.
|
|
121
|
+
*/
|
|
122
|
+
type NoSoftForm = 'configRemoveSection'
|
|
123
|
+
|
|
118
124
|
/** The client methods that have an absence value, each mapped to its {@link SoftKind}. */
|
|
119
125
|
export type SoftKinds<C> = {
|
|
120
126
|
[
|
|
121
|
-
K in keyof Triable<C> as
|
|
122
|
-
?
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
127
|
+
K in keyof Triable<C> as K extends NoSoftForm
|
|
128
|
+
? never
|
|
129
|
+
: Triable<C>[K] extends (...a: never[]) => infer R
|
|
130
|
+
? [SoftKind<Unwrap<R>>] extends [never]
|
|
131
|
+
? never
|
|
132
|
+
: K
|
|
133
|
+
: never
|
|
126
134
|
]: Triable<C>[K] extends (...a: never[]) => infer R ? SoftKind<Unwrap<R>> : never
|
|
127
135
|
}
|
|
128
136
|
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@osdlc/typed-git",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.3",
|
|
4
4
|
"description": "A typed git client for TypeScript, sync and awaitable. Each verb declares what absence means for it; every other failure throws. git.try.* inspects, raw() bypasses — over an injectable backend that drives the git CLI or any other implementation.",
|
|
5
|
-
"license": "MIT",
|
|
5
|
+
"license": "MIT OR Apache-2.0",
|
|
6
|
+
"author": "sksizer",
|
|
6
7
|
"repository": {
|
|
7
8
|
"type": "git",
|
|
8
9
|
"url": "git+https://github.com/osdlc/osdlc.git",
|
|
@@ -23,6 +24,9 @@
|
|
|
23
24
|
},
|
|
24
25
|
"type": "module",
|
|
25
26
|
"sideEffects": false,
|
|
27
|
+
"engines": {
|
|
28
|
+
"node": "^22.22.2 || ^24.15.0 || >=26.0.0"
|
|
29
|
+
},
|
|
26
30
|
"exports": {
|
|
27
31
|
".": {
|
|
28
32
|
"bun": "./index.ts",
|
|
@@ -57,13 +61,14 @@
|
|
|
57
61
|
"hosted-git-info.d.ts",
|
|
58
62
|
"README.md",
|
|
59
63
|
"CHANGELOG.md",
|
|
60
|
-
"LICENSE",
|
|
64
|
+
"LICENSE-MIT",
|
|
65
|
+
"LICENSE-APACHE",
|
|
61
66
|
"SECURITY.md",
|
|
62
67
|
"CONTRIBUTING.md"
|
|
63
68
|
],
|
|
64
69
|
"dependencies": {
|
|
65
70
|
"hosted-git-info": "^10.1.1",
|
|
66
|
-
"@osdlc/command-seam": "^0.
|
|
71
|
+
"@osdlc/command-seam": "^0.8.0"
|
|
67
72
|
},
|
|
68
73
|
"devDependencies": {
|
|
69
74
|
"@types/bun": "^1.1.14",
|
|
@@ -71,8 +76,8 @@
|
|
|
71
76
|
"oxlint": "^1.65.0",
|
|
72
77
|
"prettier": "3.9.6",
|
|
73
78
|
"typescript": "~6.0.3",
|
|
74
|
-
"@osdlc/tsconfig": "^0.
|
|
75
|
-
"@osdlc/prettier-config": "^0.
|
|
79
|
+
"@osdlc/tsconfig": "^0.4.0",
|
|
80
|
+
"@osdlc/prettier-config": "^0.3.0"
|
|
76
81
|
},
|
|
77
82
|
"scripts": {
|
|
78
83
|
"build": "tsc -p tsconfig.build.json",
|
package/remote-url.ts
CHANGED
|
@@ -24,6 +24,9 @@ export interface RemoteCoordinate {
|
|
|
24
24
|
* are the owner and repo, so a nested group (`group/sub/repo`) answers
|
|
25
25
|
* `owner: "sub"`. Returns null for anything else (a local path, a single
|
|
26
26
|
* path segment).
|
|
27
|
+
*
|
|
28
|
+
* Only an `http(s)://` port is read. An `ssh://` port is dropped, so `port` is
|
|
29
|
+
* null for `ssh://git@host:2222/owner/repo.git`.
|
|
27
30
|
*/
|
|
28
31
|
export function parseRemoteUrl(url: string): RemoteCoordinate | null {
|
|
29
32
|
const trimmed = url.trim()
|
package/soft.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* Typed against `Git` and `AsyncGit` both, so adding a list-, nullable- or
|
|
6
6
|
* boolean-returning verb to either client is a compile error here until it
|
|
7
7
|
* is declared, and the two clients cannot grow different soft doors.
|
|
8
|
+
* Mutations have no soft form, so `configRemoveSection` is not here.
|
|
8
9
|
*/
|
|
9
10
|
|
|
10
11
|
import type { AsyncGit } from './async.ts'
|
|
@@ -19,6 +20,7 @@ export const SOFT_TABLE = {
|
|
|
19
20
|
headRef: 'null',
|
|
20
21
|
topLevel: 'null',
|
|
21
22
|
gitCommonDir: 'null',
|
|
23
|
+
gitDir: 'null',
|
|
22
24
|
symbolicRef: 'null',
|
|
23
25
|
mainCheckout: 'null',
|
|
24
26
|
currentBranch: 'null',
|
|
@@ -31,6 +33,8 @@ export const SOFT_TABLE = {
|
|
|
31
33
|
mergeBase: 'null',
|
|
32
34
|
logSubject: 'null',
|
|
33
35
|
configGet: 'null',
|
|
36
|
+
configGetAll: 'empty',
|
|
37
|
+
configGetBool: 'null',
|
|
34
38
|
objectExists: 'false',
|
|
35
39
|
lsRemote: 'empty',
|
|
36
40
|
lsFiles: 'empty',
|
|
@@ -45,10 +49,12 @@ export const SOFT_TABLE = {
|
|
|
45
49
|
diffTreeNumstat: 'empty',
|
|
46
50
|
grep: 'empty',
|
|
47
51
|
isAncestor: 'false',
|
|
52
|
+
remotes: 'empty',
|
|
48
53
|
remote: 'empty',
|
|
49
54
|
remoteGetUrl: 'null',
|
|
55
|
+
remoteGetUrls: 'empty',
|
|
56
|
+
remoteHead: 'null',
|
|
50
57
|
remoteOwnerRepo: 'null',
|
|
51
|
-
configRemoveSection: 'false',
|
|
52
58
|
lsFilesUnmerged: 'empty',
|
|
53
59
|
checkIgnoreVerbose: 'empty',
|
|
54
60
|
} as const satisfies SoftTableFor<Git> & SoftTableFor<AsyncGit>
|
package/sync.ts
CHANGED
|
@@ -19,7 +19,6 @@
|
|
|
19
19
|
import { dirname } from 'node:path'
|
|
20
20
|
|
|
21
21
|
import {
|
|
22
|
-
runChecked,
|
|
23
22
|
resolveRunner,
|
|
24
23
|
type CommandResult,
|
|
25
24
|
type CommandRunner,
|
|
@@ -36,10 +35,12 @@ import {
|
|
|
36
35
|
parseRefRows,
|
|
37
36
|
repoPrefix,
|
|
38
37
|
splitLines,
|
|
38
|
+
splitTrailingOptions,
|
|
39
39
|
type AddOptions,
|
|
40
40
|
type AheadBehind,
|
|
41
41
|
type CommitOptions,
|
|
42
42
|
type CheckoutOptions,
|
|
43
|
+
type ConfigGetOptions,
|
|
43
44
|
type CloneOptions,
|
|
44
45
|
type ConflictSide,
|
|
45
46
|
type MergeOptions,
|
|
@@ -48,6 +49,7 @@ import {
|
|
|
48
49
|
type MergeTreeOutcome,
|
|
49
50
|
type RebaseOptions,
|
|
50
51
|
type RebaseOutcome,
|
|
52
|
+
type RemoteGetUrlOptions,
|
|
51
53
|
type TaggedFile,
|
|
52
54
|
type UnmergedEntry,
|
|
53
55
|
type ConfigSetOptions,
|
|
@@ -55,6 +57,7 @@ import {
|
|
|
55
57
|
type DiffNameOnlyOptions,
|
|
56
58
|
type DiffStatOptions,
|
|
57
59
|
type DiffNameStatusOptions,
|
|
60
|
+
type DiffTextOptions,
|
|
58
61
|
type DiffTreeOptions,
|
|
59
62
|
type FetchOptions,
|
|
60
63
|
type ForEachRefOptions,
|
|
@@ -95,13 +98,20 @@ export interface GitSyncCallOptions {
|
|
|
95
98
|
timeoutMs?: number | undefined
|
|
96
99
|
/** Entries merged over the parent environment for this call only. */
|
|
97
100
|
env?: Record<string, string> | undefined
|
|
101
|
+
/**
|
|
102
|
+
* Cap on each output stream, in bytes; 256 MB when omitted. Past it the
|
|
103
|
+
* runner kills the child and the call throws `CommandFailed`. command-seam's
|
|
104
|
+
* Bun test capture path (the Bun runtime with `NODE_ENV=test`) does not
|
|
105
|
+
* apply it.
|
|
106
|
+
*/
|
|
107
|
+
maxOutputBytes?: number | undefined
|
|
98
108
|
}
|
|
99
109
|
|
|
100
110
|
/** A typed git client bound to one working directory. */
|
|
101
111
|
export class Git {
|
|
102
112
|
readonly cwd: string
|
|
103
113
|
private readonly runner: CommandRunner
|
|
104
|
-
private readonly
|
|
114
|
+
private readonly boundGitDir: string | undefined
|
|
105
115
|
private readonly workTree: string | undefined
|
|
106
116
|
private readonly env: Record<string, string> | undefined
|
|
107
117
|
private tried: TriedSync<Git> | undefined
|
|
@@ -126,7 +136,8 @@ export class Git {
|
|
|
126
136
|
* default runner spawns `git`; tests pass a fake `CommandRunner`.
|
|
127
137
|
*
|
|
128
138
|
* Neither client has a default timeout. This client kills a child whose
|
|
129
|
-
* output on one stream passes 256 MB; `AsyncGit` has no output cap.
|
|
139
|
+
* output on one stream passes 256 MB; `AsyncGit` has no output cap. The
|
|
140
|
+
* `maxOutputBytes` call option sets the cap per call on both.
|
|
130
141
|
*/
|
|
131
142
|
constructor(
|
|
132
143
|
cwd: string,
|
|
@@ -139,7 +150,7 @@ export class Git {
|
|
|
139
150
|
) {
|
|
140
151
|
this.cwd = cwd
|
|
141
152
|
this.runner = resolveRunner('git', opts.runner)
|
|
142
|
-
this.
|
|
153
|
+
this.boundGitDir = opts.gitDir
|
|
143
154
|
this.workTree = opts.workTree
|
|
144
155
|
this.env = opts.env
|
|
145
156
|
}
|
|
@@ -151,7 +162,7 @@ export class Git {
|
|
|
151
162
|
at(cwd: string): Git {
|
|
152
163
|
return new Git(cwd, {
|
|
153
164
|
runner: this.runner,
|
|
154
|
-
gitDir: this.
|
|
165
|
+
gitDir: this.boundGitDir,
|
|
155
166
|
workTree: this.workTree,
|
|
156
167
|
env: this.env,
|
|
157
168
|
})
|
|
@@ -195,7 +206,8 @@ export class Git {
|
|
|
195
206
|
}
|
|
196
207
|
|
|
197
208
|
/**
|
|
198
|
-
* Checked passthrough — throws `CommandFailed` on a non-zero exit
|
|
209
|
+
* Checked passthrough — throws `CommandFailed` on a non-zero exit, and on
|
|
210
|
+
* output cut short at the output cap or a timeout, as every verb does.
|
|
199
211
|
*
|
|
200
212
|
* `CommandFailed.message` interpolates stderr only, and several git commands
|
|
201
213
|
* write the sentence that explains the failure to stdout instead — a
|
|
@@ -206,18 +218,23 @@ export class Git {
|
|
|
206
218
|
argv: string[],
|
|
207
219
|
opts: GitSyncCallOptions & { input?: string | undefined } = {},
|
|
208
220
|
): CommandResult {
|
|
209
|
-
|
|
221
|
+
// Through the gate, like `AsyncGit.rawChecked`: the seam's `runChecked`
|
|
222
|
+
// checks the exit code only, so it would pass cut-short output.
|
|
223
|
+
const verb: GitVerb<CommandResult> = { argv, absent: [], parse: (r) => r }
|
|
224
|
+
if (opts.input !== undefined) verb.input = opts.input
|
|
225
|
+
return this.exec(verb, opts)
|
|
210
226
|
}
|
|
211
227
|
|
|
212
228
|
/** The verb's argv behind this client's repository binding. */
|
|
213
229
|
private argv(argv: string[]): string[] {
|
|
214
|
-
const prefix = repoPrefix(this.
|
|
230
|
+
const prefix = repoPrefix(this.boundGitDir, this.workTree)
|
|
215
231
|
return prefix.length === 0 ? argv : [...prefix, ...argv]
|
|
216
232
|
}
|
|
217
233
|
|
|
218
234
|
private runOpts(opts: GitSyncCallOptions & { input?: string | undefined }): CommandRunOptions {
|
|
219
235
|
const run: CommandRunOptions = { cwd: this.cwd }
|
|
220
236
|
if (opts.timeoutMs !== undefined) run.timeoutMs = opts.timeoutMs
|
|
237
|
+
if (opts.maxOutputBytes !== undefined) run.maxOutputBytes = opts.maxOutputBytes
|
|
221
238
|
// Per-call entries win over the client's.
|
|
222
239
|
const env = mergeEnv(this.env, opts.env)
|
|
223
240
|
if (env !== undefined) run.env = env
|
|
@@ -229,6 +246,8 @@ export class Git {
|
|
|
229
246
|
private exec<T>(verb: GitVerb<T>, opts: GitSyncCallOptions = {}): T {
|
|
230
247
|
const run = this.runOpts(opts)
|
|
231
248
|
if (verb.input !== undefined) run.input = verb.input
|
|
249
|
+
// The verb's own entries (the C locale) win over the client's and the call's.
|
|
250
|
+
if (verb.env !== undefined) run.env = { ...run.env, ...verb.env }
|
|
232
251
|
// The prefixed argv is what ran, so it is what a `CommandFailed` reports.
|
|
233
252
|
const argv = this.argv(verb.argv)
|
|
234
253
|
return gate(verb, this.runner.run(argv, run), argv)
|
|
@@ -244,10 +263,15 @@ export class Git {
|
|
|
244
263
|
/**
|
|
245
264
|
* Trimmed `git rev-parse <args>` output — the escape hatch for a query no
|
|
246
265
|
* dedicated verb covers. See `revParse` in `verbs.ts`; for a ref, prefer
|
|
247
|
-
* {@link Git.resolveRef}.
|
|
266
|
+
* {@link Git.resolveRef}.
|
|
267
|
+
*
|
|
268
|
+
* Variadic. Call options go last, as an object:
|
|
269
|
+
* `revParse('--show-toplevel', { timeoutMs: 5000 })`. The args are flags by
|
|
270
|
+
* design, so a value that starts with `-` is not refused here.
|
|
248
271
|
*/
|
|
249
|
-
revParse(...args: string[]): string | null {
|
|
250
|
-
|
|
272
|
+
revParse(...args: string[] | [...string[], GitSyncCallOptions]): string | null {
|
|
273
|
+
const [argv, opts] = splitTrailingOptions<GitSyncCallOptions>(args)
|
|
274
|
+
return this.exec(v.revParse(...argv), opts)
|
|
251
275
|
}
|
|
252
276
|
|
|
253
277
|
/**
|
|
@@ -291,6 +315,15 @@ export class Git {
|
|
|
291
315
|
return this.exec(v.gitCommonDir(), opts)
|
|
292
316
|
}
|
|
293
317
|
|
|
318
|
+
/**
|
|
319
|
+
* This worktree's own `.git` dir as an absolute path, or null outside a repo
|
|
320
|
+
* — see `gitDir` in `verbs.ts`. Not the constructor's `gitDir` option, which
|
|
321
|
+
* binds the client to a repository.
|
|
322
|
+
*/
|
|
323
|
+
gitDir(opts: GitSyncCallOptions = {}): string | null {
|
|
324
|
+
return this.exec(v.gitDir(), opts)
|
|
325
|
+
}
|
|
326
|
+
|
|
294
327
|
/**
|
|
295
328
|
* What a symbolic ref points at (full refname), or null when it is not one —
|
|
296
329
|
* see `symbolicRef` in `verbs.ts`.
|
|
@@ -360,9 +393,22 @@ export class Git {
|
|
|
360
393
|
return this.exec(v.logSubject(ref), opts)
|
|
361
394
|
}
|
|
362
395
|
|
|
363
|
-
/** `git config --get <key>`, or null when unset. */
|
|
364
|
-
configGet(key: string, opts: GitSyncCallOptions = {}): string | null {
|
|
365
|
-
return this.exec(v.configGet(key), opts)
|
|
396
|
+
/** `git config --get <key>`, or null when unset. `scope` reads one file only. */
|
|
397
|
+
configGet(key: string, opts: GitSyncCallOptions & ConfigGetOptions = {}): string | null {
|
|
398
|
+
return this.exec(v.configGet(key, opts), opts)
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
/** Every value of a multi-valued key, verbatim; `[]` when unset. */
|
|
402
|
+
configGetAll(key: string, opts: GitSyncCallOptions & ConfigGetOptions = {}): string[] {
|
|
403
|
+
return this.exec(v.configGetAll(key, opts), opts)
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
/**
|
|
407
|
+
* A key read as a boolean by git, or null when unset. A value git cannot
|
|
408
|
+
* read as a boolean throws.
|
|
409
|
+
*/
|
|
410
|
+
configGetBool(key: string, opts: GitSyncCallOptions & ConfigGetOptions = {}): boolean | null {
|
|
411
|
+
return this.exec(v.configGetBool(key, opts), opts)
|
|
366
412
|
}
|
|
367
413
|
|
|
368
414
|
/** True iff `rev` resolves to an object (`cat-file -e`). */
|
|
@@ -414,14 +460,20 @@ export class Git {
|
|
|
414
460
|
return this.exec(v.lsFilesTagged(), opts)
|
|
415
461
|
}
|
|
416
462
|
|
|
417
|
-
/**
|
|
418
|
-
|
|
419
|
-
|
|
463
|
+
/**
|
|
464
|
+
* The unified diff; `""` when nothing differs. A bad rev, or a cwd outside a
|
|
465
|
+
* repository, throws. See `diffText` in `verbs.ts`.
|
|
466
|
+
*/
|
|
467
|
+
diffText(rev?: string | undefined, opts: GitSyncCallOptions & DiffTextOptions = {}): string {
|
|
468
|
+
return this.exec(v.diffText(rev, opts), opts)
|
|
420
469
|
}
|
|
421
470
|
|
|
422
|
-
/**
|
|
423
|
-
|
|
424
|
-
|
|
471
|
+
/**
|
|
472
|
+
* One untracked file rendered as an all-added diff. A path git cannot read
|
|
473
|
+
* throws. See `diffAddedFile` in `verbs.ts`.
|
|
474
|
+
*/
|
|
475
|
+
diffAddedFile(relPath: string, opts: GitSyncCallOptions = {}): string {
|
|
476
|
+
return this.exec(v.diffAddedFile(relPath), opts)
|
|
425
477
|
}
|
|
426
478
|
|
|
427
479
|
/** `for-each-ref` rows, one line each, in the caller's format. */
|
|
@@ -523,13 +575,39 @@ export class Git {
|
|
|
523
575
|
}
|
|
524
576
|
|
|
525
577
|
/** Configured remote names (`git remote`); `[]` when there are none. */
|
|
526
|
-
|
|
578
|
+
remotes(opts: GitSyncCallOptions = {}): string[] {
|
|
527
579
|
return this.exec(v.remote(), opts)
|
|
528
580
|
}
|
|
529
581
|
|
|
530
|
-
/**
|
|
531
|
-
|
|
532
|
-
|
|
582
|
+
/**
|
|
583
|
+
* The same as {@link Git.remotes}.
|
|
584
|
+
*
|
|
585
|
+
* @deprecated Use `remotes()`. The name `remote()` reads as one remote, but
|
|
586
|
+
* it returns every remote name. It will be removed at 1.0.
|
|
587
|
+
*/
|
|
588
|
+
remote(opts: GitSyncCallOptions = {}): string[] {
|
|
589
|
+
return this.remotes(opts)
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
/**
|
|
593
|
+
* A remote's fetch URL (push URL with `push`), or null when no remote by
|
|
594
|
+
* that name exists.
|
|
595
|
+
*/
|
|
596
|
+
remoteGetUrl(name: string, opts: GitSyncCallOptions & RemoteGetUrlOptions = {}): string | null {
|
|
597
|
+
return this.exec(v.remoteGetUrl(name, opts), opts)
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
/** Every URL a remote has (push URLs with `push`); `[]` for an unknown remote. */
|
|
601
|
+
remoteGetUrls(name: string, opts: GitSyncCallOptions & RemoteGetUrlOptions = {}): string[] {
|
|
602
|
+
return this.exec(v.remoteGetUrls(name, opts), opts)
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
/**
|
|
606
|
+
* The full refname the remote's HEAD points at, asked over the network; null
|
|
607
|
+
* when the remote names none. See `remoteHead` in `verbs.ts`.
|
|
608
|
+
*/
|
|
609
|
+
remoteHead(remote: string, opts: GitSyncCallOptions = {}): string | null {
|
|
610
|
+
return this.exec(v.remoteHead(remote), opts)
|
|
533
611
|
}
|
|
534
612
|
|
|
535
613
|
/**
|
|
@@ -595,11 +673,11 @@ export class Git {
|
|
|
595
673
|
}
|
|
596
674
|
|
|
597
675
|
/**
|
|
598
|
-
* Push a refspec.
|
|
599
|
-
*
|
|
600
|
-
*
|
|
676
|
+
* Push a refspec. A {@link ForceLease} pins `--force-with-lease`, which means
|
|
677
|
+
* "nobody has touched this since I looked". `{forceWithLease: true}` adds the
|
|
678
|
+
* bare flag, which is the unsafe form: it compares against the
|
|
601
679
|
* remote-tracking ref, which a fetch in this same process may have just
|
|
602
|
-
* updated.
|
|
680
|
+
* updated. See `push` in `verbs.ts`.
|
|
603
681
|
*/
|
|
604
682
|
push(
|
|
605
683
|
remote: string,
|
|
@@ -627,7 +705,10 @@ export class Git {
|
|
|
627
705
|
this.exec(v.deleteBranch(name, opts), opts)
|
|
628
706
|
}
|
|
629
707
|
|
|
630
|
-
/**
|
|
708
|
+
/**
|
|
709
|
+
* Remove config section `name`; false when it was absent. See
|
|
710
|
+
* `configRemoveSection` in `verbs.ts`.
|
|
711
|
+
*/
|
|
631
712
|
configRemoveSection(name: string, opts: GitSyncCallOptions = {}): boolean {
|
|
632
713
|
return this.exec(v.configRemoveSection(name), opts)
|
|
633
714
|
}
|
|
@@ -730,10 +811,12 @@ export class Git {
|
|
|
730
811
|
}
|
|
731
812
|
|
|
732
813
|
/**
|
|
733
|
-
* Resolve conflicted `paths` to one side wholesale.
|
|
734
|
-
* for a path that is not
|
|
814
|
+
* Resolve conflicted `paths` to one side wholesale. An empty list returns
|
|
815
|
+
* without running git. Silently does nothing for a path that is not
|
|
816
|
+
* conflicted — see `checkoutSide` in `verbs.ts`.
|
|
735
817
|
*/
|
|
736
818
|
checkoutSide(side: ConflictSide, paths: string[], opts: GitSyncCallOptions = {}): void {
|
|
819
|
+
if (paths.length === 0) return
|
|
737
820
|
this.exec(v.checkoutSide(side, paths), opts)
|
|
738
821
|
}
|
|
739
822
|
|
package/testing.ts
CHANGED
|
@@ -17,10 +17,15 @@ import { Git } from './sync.ts'
|
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
19
|
* A fixed author and committer identity, supplied through the environment
|
|
20
|
-
* rather than written into the repo config
|
|
21
|
-
* the
|
|
22
|
-
*
|
|
23
|
-
*
|
|
20
|
+
* rather than written into the repo config. The dates are pinned because they
|
|
21
|
+
* are the two inputs to a commit object that would otherwise move every run.
|
|
22
|
+
*
|
|
23
|
+
* Only identity is isolated. A fixture also turns off `commit.gpgsign` in its
|
|
24
|
+
* own repo config. The rest of the developer's global and system config still
|
|
25
|
+
* applies: `core.hooksPath`, `commit.template`, `init.templateDir`,
|
|
26
|
+
* `core.autocrlf` and the like. A suite that must not see them sets
|
|
27
|
+
* `GIT_CONFIG_GLOBAL` and `GIT_CONFIG_NOSYSTEM` itself, for example through
|
|
28
|
+
* the `identity` option.
|
|
24
29
|
*/
|
|
25
30
|
export const IDENTITY: Readonly<Record<string, string>> = Object.freeze({
|
|
26
31
|
GIT_AUTHOR_NAME: 'Fixture',
|
|
@@ -158,6 +163,29 @@ export function makeGitFixture(opts: MakeGitFixtureOptions = {}): GitFixture {
|
|
|
158
163
|
return fixtureAt(dir, at)
|
|
159
164
|
}
|
|
160
165
|
|
|
166
|
+
/** Options for {@link makeOriginAndCheckout}. */
|
|
167
|
+
export interface MakeOriginAndCheckoutOptions {
|
|
168
|
+
/** Initial branch name; `main` when omitted. */
|
|
169
|
+
initialBranch?: string | undefined
|
|
170
|
+
/** Files in the origin's first commit; a `README.md` when omitted. */
|
|
171
|
+
files?: Record<string, string> | undefined
|
|
172
|
+
/**
|
|
173
|
+
* Make both repositories under this parent instead of `os.tmpdir()`.
|
|
174
|
+
* `cleanup()` removes the two repositories, not `parent`.
|
|
175
|
+
*/
|
|
176
|
+
parent?: string | undefined
|
|
177
|
+
/** Override the pinned {@link IDENTITY} wholesale. */
|
|
178
|
+
identity?: Record<string, string> | undefined
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/** What {@link makeOriginAndCheckout} returns. */
|
|
182
|
+
export interface OriginAndCheckout {
|
|
183
|
+
origin: GitFixture
|
|
184
|
+
checkout: GitFixture
|
|
185
|
+
/** Remove the checkout and the origin. */
|
|
186
|
+
cleanup(): void
|
|
187
|
+
}
|
|
188
|
+
|
|
161
189
|
/**
|
|
162
190
|
* An origin repository with one commit, plus a clone of it — the shape a test
|
|
163
191
|
* of fetch/push/worktree behaviour needs.
|
|
@@ -165,14 +193,7 @@ export function makeGitFixture(opts: MakeGitFixtureOptions = {}): GitFixture {
|
|
|
165
193
|
* Reach for {@link makeBareAndWorker} instead when the second repo must have
|
|
166
194
|
* its own history rather than the origin's.
|
|
167
195
|
*/
|
|
168
|
-
export function makeOriginAndCheckout(
|
|
169
|
-
opts: {
|
|
170
|
-
initialBranch?: string | undefined
|
|
171
|
-
files?: Record<string, string> | undefined
|
|
172
|
-
parent?: string | undefined
|
|
173
|
-
identity?: Record<string, string> | undefined
|
|
174
|
-
} = {},
|
|
175
|
-
): { origin: GitFixture; checkout: GitFixture; cleanup(): void } {
|
|
196
|
+
export function makeOriginAndCheckout(opts: MakeOriginAndCheckoutOptions = {}): OriginAndCheckout {
|
|
176
197
|
const branch = opts.initialBranch ?? 'main'
|
|
177
198
|
const origin = makeGitFixture({
|
|
178
199
|
prefix: 'typed-git-origin-',
|
|
@@ -197,6 +218,34 @@ export function makeOriginAndCheckout(
|
|
|
197
218
|
}
|
|
198
219
|
}
|
|
199
220
|
|
|
221
|
+
/** Options for {@link makeBareAndWorker}. */
|
|
222
|
+
export interface MakeBareAndWorkerOptions {
|
|
223
|
+
/** Name the worker knows the store by; `origin` when omitted. */
|
|
224
|
+
remoteName?: string | undefined
|
|
225
|
+
/**
|
|
226
|
+
* Shared parent for both; a fresh temp directory when omitted.
|
|
227
|
+
*
|
|
228
|
+
* Warning: `cleanup()` removes this whole directory, also when you pass it,
|
|
229
|
+
* with everything else in it. Do not point it at anything you want to keep.
|
|
230
|
+
*/
|
|
231
|
+
parent?: string | undefined
|
|
232
|
+
/** Initial branch name; `main` when omitted. */
|
|
233
|
+
initialBranch?: string | undefined
|
|
234
|
+
/** Override the pinned {@link IDENTITY} wholesale. */
|
|
235
|
+
identity?: Record<string, string> | undefined
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/** What {@link makeBareAndWorker} returns. */
|
|
239
|
+
export interface BareAndWorker {
|
|
240
|
+
bare: GitFixture
|
|
241
|
+
worker: GitFixture
|
|
242
|
+
remoteName: string
|
|
243
|
+
/** The directory both repositories live in. */
|
|
244
|
+
parent: string
|
|
245
|
+
/** Remove `parent` and everything in it, also a `parent` the caller passed. */
|
|
246
|
+
cleanup(): void
|
|
247
|
+
}
|
|
248
|
+
|
|
200
249
|
/**
|
|
201
250
|
* A bare store plus an independently-inited worker that names it as a remote.
|
|
202
251
|
*
|
|
@@ -205,27 +254,10 @@ export function makeOriginAndCheckout(
|
|
|
205
254
|
* genuine publish into an empty store.
|
|
206
255
|
*
|
|
207
256
|
* Both repositories land under one parent, so a suite deletes one directory.
|
|
257
|
+
* `cleanup()` deletes that whole parent, also one the caller passed in; see
|
|
258
|
+
* {@link MakeBareAndWorkerOptions.parent}.
|
|
208
259
|
*/
|
|
209
|
-
export function makeBareAndWorker(
|
|
210
|
-
opts: {
|
|
211
|
-
/** Name the worker knows the store by; `origin` when omitted. */
|
|
212
|
-
remoteName?: string | undefined
|
|
213
|
-
/**
|
|
214
|
-
* Shared parent for both; a fresh temp directory when omitted. `cleanup()`
|
|
215
|
-
* removes this whole directory, so do not point it at anything you want to
|
|
216
|
-
* keep.
|
|
217
|
-
*/
|
|
218
|
-
parent?: string | undefined
|
|
219
|
-
initialBranch?: string | undefined
|
|
220
|
-
identity?: Record<string, string> | undefined
|
|
221
|
-
} = {},
|
|
222
|
-
): {
|
|
223
|
-
bare: GitFixture
|
|
224
|
-
worker: GitFixture
|
|
225
|
-
remoteName: string
|
|
226
|
-
parent: string
|
|
227
|
-
cleanup(): void
|
|
228
|
-
} {
|
|
260
|
+
export function makeBareAndWorker(opts: MakeBareAndWorkerOptions = {}): BareAndWorker {
|
|
229
261
|
const parent =
|
|
230
262
|
opts.parent === undefined
|
|
231
263
|
? mkdtempSync(join(tmpdir(), 'typed-git-pair-'))
|