@osdlc/typed-git 0.5.2 → 0.6.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 +36 -1
- package/CONTRIBUTING.md +3 -4
- package/LICENSE-APACHE +1 -1
- package/README.md +40 -16
- package/dist/async.d.ts +3 -4
- package/dist/async.js +3 -3
- package/dist/backend.d.ts +1 -2
- package/dist/checkout-root.d.ts +0 -1
- package/dist/client.d.ts +2 -2
- package/dist/client.js +1 -0
- package/dist/failure.d.ts +64 -0
- package/dist/failure.js +126 -0
- package/dist/git-url.d.ts +0 -1
- package/dist/index.d.ts +1 -2
- package/dist/index.js +1 -1
- package/dist/outcome.d.ts +13 -18
- package/dist/outcome.js +21 -16
- package/dist/remote-url.d.ts +0 -1
- package/dist/soft.d.ts +0 -1
- package/dist/sync.d.ts +5 -5
- package/dist/sync.js +4 -3
- package/dist/testing.d.ts +0 -1
- package/dist/verbs.d.ts +5 -7
- package/dist/verbs.js +18 -11
- package/package.json +10 -23
- package/async.ts +0 -753
- package/backend.ts +0 -574
- package/checkout-root.ts +0 -164
- package/client.ts +0 -102
- package/dist/async.d.ts.map +0 -1
- package/dist/backend.d.ts.map +0 -1
- package/dist/checkout-root.d.ts.map +0 -1
- package/dist/client.d.ts.map +0 -1
- package/dist/git-url.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/outcome.d.ts.map +0 -1
- package/dist/remote-url.d.ts.map +0 -1
- package/dist/soft.d.ts.map +0 -1
- package/dist/sync.d.ts.map +0 -1
- package/dist/testing.d.ts.map +0 -1
- package/dist/verbs.d.ts.map +0 -1
- package/git-url.ts +0 -102
- package/hosted-git-info.d.ts +0 -24
- package/index.ts +0 -52
- package/outcome.ts +0 -191
- package/remote-url.ts +0 -46
- package/soft.ts +0 -60
- package/sync.ts +0 -827
- package/testing.ts +0 -291
- package/verbs.ts +0 -2300
package/testing.ts
DELETED
|
@@ -1,291 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `@osdlc/typed-git/testing` — throwaway git repositories for tests.
|
|
3
|
-
*
|
|
4
|
-
* A separate subpath, not part of the package entry: production code should
|
|
5
|
-
* not be able to reach `mkdtemp` through a git client.
|
|
6
|
-
*
|
|
7
|
-
* Deliberately general. Conventions that belong to one consuming project — a
|
|
8
|
-
* particular directory layout, its own ref namespace — go in that project's
|
|
9
|
-
* own wrapper around these helpers, not here.
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'
|
|
13
|
-
import { tmpdir } from 'node:os'
|
|
14
|
-
import { dirname, join, resolve } from 'node:path'
|
|
15
|
-
|
|
16
|
-
import { Git } from './sync.ts'
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* A fixed author and committer identity, supplied through the environment
|
|
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.
|
|
29
|
-
*/
|
|
30
|
-
export const IDENTITY: Readonly<Record<string, string>> = Object.freeze({
|
|
31
|
-
GIT_AUTHOR_NAME: 'Fixture',
|
|
32
|
-
GIT_AUTHOR_EMAIL: 'fixture@example.invalid',
|
|
33
|
-
GIT_AUTHOR_DATE: '2020-01-01T00:00:00+0000',
|
|
34
|
-
GIT_COMMITTER_NAME: 'Fixture',
|
|
35
|
-
GIT_COMMITTER_EMAIL: 'fixture@example.invalid',
|
|
36
|
-
GIT_COMMITTER_DATE: '2020-01-01T00:00:00+0000',
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
/** Per-commit overrides, for a suite that needs commits at distinct times. */
|
|
40
|
-
export interface FixtureCommitOptions {
|
|
41
|
-
/**
|
|
42
|
-
* Both `GIT_AUTHOR_DATE` and `GIT_COMMITTER_DATE` for this commit. Set it
|
|
43
|
-
* rather than the two variables by hand: a commit whose two dates disagree
|
|
44
|
-
* has a different sha from one where they match.
|
|
45
|
-
*/
|
|
46
|
-
date?: string | undefined
|
|
47
|
-
/** Further environment entries for this commit only, over `date`. */
|
|
48
|
-
env?: Record<string, string> | undefined
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/** A temp repository and the client bound to it. */
|
|
52
|
-
export interface GitFixture {
|
|
53
|
-
/** Absolute path of the repository's working tree (or of a bare store). */
|
|
54
|
-
readonly dir: string
|
|
55
|
-
/**
|
|
56
|
-
* A client rooted at {@link GitFixture.dir}, carrying the fixture identity
|
|
57
|
-
* as its client-level `env` — so every call through it, a suite's own
|
|
58
|
-
* included, runs under the pinned identity.
|
|
59
|
-
*/
|
|
60
|
-
readonly git: Git
|
|
61
|
-
/** Write files (paths relative to `dir`), stage everything, and commit. */
|
|
62
|
-
commit(message: string, files?: Record<string, string>, opts?: FixtureCommitOptions): string
|
|
63
|
-
/** Remove the temp directory. Idempotent. */
|
|
64
|
-
cleanup(): void
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/** Shared knobs for choosing where a fixture lands and who authors it. */
|
|
68
|
-
interface FixtureLocation {
|
|
69
|
-
/**
|
|
70
|
-
* Use this exact directory rather than making one. `cleanup()` still removes
|
|
71
|
-
* it, so do not point it at anything you want to keep.
|
|
72
|
-
*/
|
|
73
|
-
dir?: string | undefined
|
|
74
|
-
/**
|
|
75
|
-
* Make the temp directory under this parent instead of `os.tmpdir()`, so two
|
|
76
|
-
* related repositories share one parent — a store and its worker, an origin
|
|
77
|
-
* and its clone.
|
|
78
|
-
*/
|
|
79
|
-
parent?: string | undefined
|
|
80
|
-
/** Prefix for the generated directory name. */
|
|
81
|
-
prefix?: string | undefined
|
|
82
|
-
/** Override the pinned {@link IDENTITY} wholesale. */
|
|
83
|
-
identity?: Record<string, string> | undefined
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/** Make (or adopt) the directory a fixture will live in. */
|
|
87
|
-
function fixtureDir(opts: FixtureLocation, fallbackPrefix: string): string {
|
|
88
|
-
if (opts.dir !== undefined) {
|
|
89
|
-
mkdirSync(opts.dir, { recursive: true })
|
|
90
|
-
return resolve(opts.dir)
|
|
91
|
-
}
|
|
92
|
-
const parent = opts.parent === undefined ? tmpdir() : resolve(opts.parent)
|
|
93
|
-
mkdirSync(parent, { recursive: true })
|
|
94
|
-
return mkdtempSync(join(parent, opts.prefix ?? fallbackPrefix))
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* Wrap an existing directory that already holds a repository.
|
|
99
|
-
*
|
|
100
|
-
* The identity is bound as the client's `env` rather than threaded onto each
|
|
101
|
-
* call, so every call the fixture makes runs under it — the internal
|
|
102
|
-
* `rev-parse` in `commit()` included.
|
|
103
|
-
*/
|
|
104
|
-
function fixtureAt(
|
|
105
|
-
dir: string,
|
|
106
|
-
opts: { identity?: Record<string, string> | undefined; bare?: boolean | undefined } = {},
|
|
107
|
-
): GitFixture {
|
|
108
|
-
const identity = opts.identity ?? IDENTITY
|
|
109
|
-
const git = new Git(dir, { env: { ...identity } })
|
|
110
|
-
// A developer with `commit.gpgsign = true` globally would otherwise fail
|
|
111
|
-
// every fixture commit, on their machine only. A bare store has no commits
|
|
112
|
-
// made in it, so there is nothing to sign.
|
|
113
|
-
if (opts.bare !== true) git.configSet('commit.gpgsign', 'false')
|
|
114
|
-
return {
|
|
115
|
-
dir,
|
|
116
|
-
git,
|
|
117
|
-
commit(message, files = {}, commitOpts = {}) {
|
|
118
|
-
for (const [rel, content] of Object.entries(files)) {
|
|
119
|
-
const path = join(dir, rel)
|
|
120
|
-
mkdirSync(dirname(path), { recursive: true })
|
|
121
|
-
writeFileSync(path, content)
|
|
122
|
-
}
|
|
123
|
-
const env: Record<string, string> = {}
|
|
124
|
-
if (commitOpts.date !== undefined) {
|
|
125
|
-
env['GIT_AUTHOR_DATE'] = commitOpts.date
|
|
126
|
-
env['GIT_COMMITTER_DATE'] = commitOpts.date
|
|
127
|
-
}
|
|
128
|
-
Object.assign(env, commitOpts.env ?? {})
|
|
129
|
-
const call = Object.keys(env).length === 0 ? {} : { env }
|
|
130
|
-
git.add(['.'], { all: true, ...call })
|
|
131
|
-
git.commit({ message, allowEmpty: true, ...call })
|
|
132
|
-
const head = git.revParse('HEAD')
|
|
133
|
-
if (head === null) throw new Error('fixture commit produced no HEAD')
|
|
134
|
-
return head
|
|
135
|
-
},
|
|
136
|
-
cleanup() {
|
|
137
|
-
rmSync(dir, { recursive: true, force: true })
|
|
138
|
-
},
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
/** Options for {@link makeGitFixture}. */
|
|
143
|
-
export interface MakeGitFixtureOptions extends FixtureLocation {
|
|
144
|
-
/** Initial branch name; `main` when omitted. */
|
|
145
|
-
initialBranch?: string | undefined
|
|
146
|
-
/** Make a bare store rather than a working tree. */
|
|
147
|
-
bare?: boolean | undefined
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
/** Create an initialized repository, by default under the OS temp directory. */
|
|
151
|
-
export function makeGitFixture(opts: MakeGitFixtureOptions = {}): GitFixture {
|
|
152
|
-
const dir = fixtureDir(opts, 'typed-git-fixture-')
|
|
153
|
-
const initOpts: { quiet: true; initialBranch: string; bare?: boolean } = {
|
|
154
|
-
quiet: true,
|
|
155
|
-
initialBranch: opts.initialBranch ?? 'main',
|
|
156
|
-
}
|
|
157
|
-
if (opts.bare === true) initOpts.bare = true
|
|
158
|
-
new Git(dir).init(undefined, initOpts)
|
|
159
|
-
const at: { identity?: Record<string, string> | undefined; bare?: boolean } = {
|
|
160
|
-
identity: opts.identity,
|
|
161
|
-
}
|
|
162
|
-
if (opts.bare === true) at.bare = true
|
|
163
|
-
return fixtureAt(dir, at)
|
|
164
|
-
}
|
|
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
|
-
|
|
189
|
-
/**
|
|
190
|
-
* An origin repository with one commit, plus a clone of it — the shape a test
|
|
191
|
-
* of fetch/push/worktree behaviour needs.
|
|
192
|
-
*
|
|
193
|
-
* Reach for {@link makeBareAndWorker} instead when the second repo must have
|
|
194
|
-
* its own history rather than the origin's.
|
|
195
|
-
*/
|
|
196
|
-
export function makeOriginAndCheckout(opts: MakeOriginAndCheckoutOptions = {}): OriginAndCheckout {
|
|
197
|
-
const branch = opts.initialBranch ?? 'main'
|
|
198
|
-
const origin = makeGitFixture({
|
|
199
|
-
prefix: 'typed-git-origin-',
|
|
200
|
-
initialBranch: branch,
|
|
201
|
-
parent: opts.parent,
|
|
202
|
-
identity: opts.identity,
|
|
203
|
-
})
|
|
204
|
-
origin.commit('initial', opts.files ?? { 'README.md': 'fixture\n' })
|
|
205
|
-
|
|
206
|
-
const dir = fixtureDir({ parent: opts.parent }, 'typed-git-checkout-')
|
|
207
|
-
// `Git.clone` runs from `cwd` (see sync.ts) — `dir` isn't a repository yet, so this call makes it the checkout below.
|
|
208
|
-
new Git(dir).clone(origin.dir, '.', { quiet: true, branch })
|
|
209
|
-
const checkout = fixtureAt(dir, { identity: opts.identity })
|
|
210
|
-
|
|
211
|
-
return {
|
|
212
|
-
origin,
|
|
213
|
-
checkout,
|
|
214
|
-
cleanup() {
|
|
215
|
-
checkout.cleanup()
|
|
216
|
-
origin.cleanup()
|
|
217
|
-
},
|
|
218
|
-
}
|
|
219
|
-
}
|
|
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
|
-
|
|
249
|
-
/**
|
|
250
|
-
* A bare store plus an independently-inited worker that names it as a remote.
|
|
251
|
-
*
|
|
252
|
-
* Not a clone: the worker is `git init`ed on its own and given a remote, so it
|
|
253
|
-
* starts with no history and no upstream tracking, and its first push is a
|
|
254
|
-
* genuine publish into an empty store.
|
|
255
|
-
*
|
|
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}.
|
|
259
|
-
*/
|
|
260
|
-
export function makeBareAndWorker(opts: MakeBareAndWorkerOptions = {}): BareAndWorker {
|
|
261
|
-
const parent =
|
|
262
|
-
opts.parent === undefined
|
|
263
|
-
? mkdtempSync(join(tmpdir(), 'typed-git-pair-'))
|
|
264
|
-
: resolve(opts.parent)
|
|
265
|
-
mkdirSync(parent, { recursive: true })
|
|
266
|
-
const remoteName = opts.remoteName ?? 'origin'
|
|
267
|
-
const branch = opts.initialBranch ?? 'main'
|
|
268
|
-
|
|
269
|
-
const bare = makeGitFixture({
|
|
270
|
-
dir: join(parent, 'store.git'),
|
|
271
|
-
bare: true,
|
|
272
|
-
initialBranch: branch,
|
|
273
|
-
identity: opts.identity,
|
|
274
|
-
})
|
|
275
|
-
const worker = makeGitFixture({
|
|
276
|
-
dir: join(parent, 'worker'),
|
|
277
|
-
initialBranch: branch,
|
|
278
|
-
identity: opts.identity,
|
|
279
|
-
})
|
|
280
|
-
worker.git.remoteAdd(remoteName, bare.dir)
|
|
281
|
-
|
|
282
|
-
return {
|
|
283
|
-
bare,
|
|
284
|
-
worker,
|
|
285
|
-
remoteName,
|
|
286
|
-
parent,
|
|
287
|
-
cleanup() {
|
|
288
|
-
rmSync(parent, { recursive: true, force: true })
|
|
289
|
-
},
|
|
290
|
-
}
|
|
291
|
-
}
|