@osdlc/typed-git 0.7.0 → 0.7.2
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 +14 -0
- package/README.md +145 -138
- package/dist/async.d.ts +22 -23
- package/dist/async.js +22 -23
- package/dist/backend.d.ts +26 -28
- package/dist/backend.js +20 -22
- package/dist/checkout-root.d.ts +33 -32
- package/dist/checkout-root.js +28 -27
- package/dist/client.d.ts +4 -4
- package/dist/client.js +5 -5
- package/dist/failure.d.ts +14 -14
- package/dist/failure.js +15 -15
- package/dist/git-url.d.ts +6 -6
- package/dist/git-url.js +6 -6
- package/dist/index.d.ts +19 -18
- package/dist/index.js +19 -18
- package/dist/outcome.d.ts +29 -27
- package/dist/outcome.js +16 -14
- package/dist/remote-url.d.ts +6 -6
- package/dist/remote-url.js +6 -6
- package/dist/soft.d.ts +5 -5
- package/dist/soft.js +5 -5
- package/dist/sync.d.ts +58 -60
- package/dist/sync.js +56 -58
- package/dist/testing.d.ts +12 -12
- package/dist/testing.js +11 -11
- package/dist/verbs.d.ts +38 -40
- package/dist/verbs.js +40 -42
- package/package.json +2 -2
package/dist/async.d.ts
CHANGED
|
@@ -2,14 +2,13 @@
|
|
|
2
2
|
* `AsyncGit` — the awaitable client, bound to one working directory and one
|
|
3
3
|
* {@link GitBackend}.
|
|
4
4
|
*
|
|
5
|
-
* The sync `Git
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* one throws.
|
|
5
|
+
* The same methods as the sync `Git`, returning promises. One difference: a
|
|
6
|
+
* backend does the work, not a runner. The default backend runs the `git`
|
|
7
|
+
* CLI. Any other {@link GitBackend}, such as a pure-JavaScript git, a remote
|
|
8
|
+
* service or a recorded fixture, works with the same client. Each method
|
|
9
|
+
* matches its {@link Git} counterpart and rejects where that one throws.
|
|
11
10
|
*
|
|
12
|
-
*
|
|
11
|
+
* Here the repository is set on the backend:
|
|
13
12
|
* `new AsyncGit(cwd, { backend: cliBackend({ gitDir }) })`, where the sync
|
|
14
13
|
* client takes `gitDir` on its own constructor.
|
|
15
14
|
*/
|
|
@@ -41,7 +40,7 @@ export declare class AsyncGit {
|
|
|
41
40
|
/** The same client rooted at a different directory (same backend). */
|
|
42
41
|
at(cwd: string): AsyncGit;
|
|
43
42
|
/**
|
|
44
|
-
*
|
|
43
|
+
* Every method again, resolving to a `Result<T, GitFailure>` instead of
|
|
45
44
|
* rejecting. A declared absence is `ok: true`; see `./outcome.ts`.
|
|
46
45
|
*
|
|
47
46
|
* The type leaves out `raw`, `rawChecked` and `at`, but at runtime the proxy
|
|
@@ -50,27 +49,27 @@ export declare class AsyncGit {
|
|
|
50
49
|
*/
|
|
51
50
|
get try(): TriedAsync<AsyncGit>;
|
|
52
51
|
/**
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
* `
|
|
57
|
-
*
|
|
52
|
+
* Each verb with an absence value (`null`, `[]` or `false`) resolves to that
|
|
53
|
+
* value when git fails, instead of rejecting. It is for callers that treat
|
|
54
|
+
* "could not ask" the same as "nothing there": `git.soft.resolveRef(x)` is
|
|
55
|
+
* `null` both for a missing ref and for a broken repo. Use `try` when the
|
|
56
|
+
* failure itself matters.
|
|
58
57
|
*
|
|
59
58
|
* As with `try`, the proxy also wraps `raw`, `rawChecked` and `at` at
|
|
60
59
|
* runtime, though the type leaves them out.
|
|
61
60
|
*/
|
|
62
61
|
get soft(): Soft<AsyncGit>;
|
|
63
62
|
/**
|
|
64
|
-
*
|
|
65
|
-
*
|
|
63
|
+
* Runs any git argv without checking the exit code. Only a CLI backend can
|
|
64
|
+
* run this. Others reject with `UnsupportedRequest`.
|
|
66
65
|
*/
|
|
67
66
|
raw(argv: string[], opts?: GitCallOptions & {
|
|
68
67
|
input?: string | undefined;
|
|
69
68
|
}): Promise<CommandResult>;
|
|
70
69
|
/**
|
|
71
|
-
*
|
|
72
|
-
* exit,
|
|
73
|
-
* `e.detail`, which
|
|
70
|
+
* Runs any git argv and rejects with the classified failure on a non-zero
|
|
71
|
+
* exit, or on output cut short at the output cap or a timeout. Report
|
|
72
|
+
* `e.failure.detail`, which holds both streams. See {@link Git.rawChecked}.
|
|
74
73
|
*/
|
|
75
74
|
rawChecked(argv: string[], opts?: GitCallOptions & {
|
|
76
75
|
input?: string | undefined;
|
|
@@ -241,11 +240,11 @@ export declare class AsyncGit {
|
|
|
241
240
|
add(paths: string[], opts?: GitCallOptions & AddOptions): Promise<void>;
|
|
242
241
|
/**
|
|
243
242
|
* Commit with an inline message, a message file or a stdin message (exactly
|
|
244
|
-
* one). A failing hook rejects
|
|
245
|
-
* `e.detail`
|
|
243
|
+
* one). A failing hook rejects. git writes hook output to stdout, which
|
|
244
|
+
* `e.failure.detail` includes.
|
|
246
245
|
*/
|
|
247
246
|
commit(opts: GitCallOptions & CommitOptions): Promise<void>;
|
|
248
|
-
/** `git config <key> <value
|
|
247
|
+
/** `git config <key> <value>`, the write counterpart of {@link AsyncGit.configGet}. */
|
|
249
248
|
configSet(key: string, value: string, opts?: GitCallOptions & ConfigSetOptions): Promise<void>;
|
|
250
249
|
/** `git init [path]`; `path` defaults to this client's `cwd`. */
|
|
251
250
|
init(path?: string | undefined, opts?: GitCallOptions & InitOptions): Promise<void>;
|
|
@@ -308,8 +307,8 @@ export declare class AsyncGit {
|
|
|
308
307
|
rebaseContinue(opts?: GitCallOptions): Promise<RebaseOutcome>;
|
|
309
308
|
/**
|
|
310
309
|
* What merging `theirs` into `ours` would do — no index, no checkout, no
|
|
311
|
-
* worktree.
|
|
312
|
-
* merged `tree` it returns is real
|
|
310
|
+
* worktree. It is the cheap way to ask "would this conflict, and where". The
|
|
311
|
+
* merged `tree` it returns is a real object you can build a commit from.
|
|
313
312
|
*/
|
|
314
313
|
mergeTree(ours: string, theirs: string, opts?: MergeTreeOptions & GitCallOptions): Promise<MergeTreeOutcome>;
|
|
315
314
|
/** `git ls-files -u`, parsed — the stage detail behind each conflict. */
|
package/dist/async.js
CHANGED
|
@@ -2,14 +2,13 @@
|
|
|
2
2
|
* `AsyncGit` — the awaitable client, bound to one working directory and one
|
|
3
3
|
* {@link GitBackend}.
|
|
4
4
|
*
|
|
5
|
-
* The sync `Git
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* one throws.
|
|
5
|
+
* The same methods as the sync `Git`, returning promises. One difference: a
|
|
6
|
+
* backend does the work, not a runner. The default backend runs the `git`
|
|
7
|
+
* CLI. Any other {@link GitBackend}, such as a pure-JavaScript git, a remote
|
|
8
|
+
* service or a recorded fixture, works with the same client. Each method
|
|
9
|
+
* matches its {@link Git} counterpart and rejects where that one throws.
|
|
11
10
|
*
|
|
12
|
-
*
|
|
11
|
+
* Here the repository is set on the backend:
|
|
13
12
|
* `new AsyncGit(cwd, { backend: cliBackend({ gitDir }) })`, where the sync
|
|
14
13
|
* client takes `gitDir` on its own constructor.
|
|
15
14
|
*/
|
|
@@ -57,7 +56,7 @@ export class AsyncGit {
|
|
|
57
56
|
return new AsyncGit(cwd, { backend: this.backend });
|
|
58
57
|
}
|
|
59
58
|
/**
|
|
60
|
-
*
|
|
59
|
+
* Every method again, resolving to a `Result<T, GitFailure>` instead of
|
|
61
60
|
* rejecting. A declared absence is `ok: true`; see `./outcome.ts`.
|
|
62
61
|
*
|
|
63
62
|
* The type leaves out `raw`, `rawChecked` and `at`, but at runtime the proxy
|
|
@@ -68,11 +67,11 @@ export class AsyncGit {
|
|
|
68
67
|
return (this.tried ??= triedAsync(this));
|
|
69
68
|
}
|
|
70
69
|
/**
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
* `
|
|
75
|
-
*
|
|
70
|
+
* Each verb with an absence value (`null`, `[]` or `false`) resolves to that
|
|
71
|
+
* value when git fails, instead of rejecting. It is for callers that treat
|
|
72
|
+
* "could not ask" the same as "nothing there": `git.soft.resolveRef(x)` is
|
|
73
|
+
* `null` both for a missing ref and for a broken repo. Use `try` when the
|
|
74
|
+
* failure itself matters.
|
|
76
75
|
*
|
|
77
76
|
* As with `try`, the proxy also wraps `raw`, `rawChecked` and `at` at
|
|
78
77
|
* runtime, though the type leaves them out.
|
|
@@ -83,16 +82,16 @@ export class AsyncGit {
|
|
|
83
82
|
}
|
|
84
83
|
// ── escape hatch ──────────────────────────────────────────────────────────
|
|
85
84
|
/**
|
|
86
|
-
*
|
|
87
|
-
*
|
|
85
|
+
* Runs any git argv without checking the exit code. Only a CLI backend can
|
|
86
|
+
* run this. Others reject with `UnsupportedRequest`.
|
|
88
87
|
*/
|
|
89
88
|
raw(argv, opts = {}) {
|
|
90
89
|
return this.backend.execute(this.cwd, { kind: 'raw', argv, input: opts.input }, opts);
|
|
91
90
|
}
|
|
92
91
|
/**
|
|
93
|
-
*
|
|
94
|
-
* exit,
|
|
95
|
-
* `e.detail`, which
|
|
92
|
+
* Runs any git argv and rejects with the classified failure on a non-zero
|
|
93
|
+
* exit, or on output cut short at the output cap or a timeout. Report
|
|
94
|
+
* `e.failure.detail`, which holds both streams. See {@link Git.rawChecked}.
|
|
96
95
|
*/
|
|
97
96
|
rawChecked(argv, opts = {}) {
|
|
98
97
|
return this.backend.execute(this.cwd, { kind: 'raw', argv, checked: true, input: opts.input }, opts);
|
|
@@ -397,14 +396,14 @@ export class AsyncGit {
|
|
|
397
396
|
}
|
|
398
397
|
/**
|
|
399
398
|
* Commit with an inline message, a message file or a stdin message (exactly
|
|
400
|
-
* one). A failing hook rejects
|
|
401
|
-
* `e.detail`
|
|
399
|
+
* one). A failing hook rejects. git writes hook output to stdout, which
|
|
400
|
+
* `e.failure.detail` includes.
|
|
402
401
|
*/
|
|
403
402
|
commit(opts) {
|
|
404
403
|
const [call, req] = splitCallOptions(opts);
|
|
405
404
|
return this.backend.execute(this.cwd, { kind: 'commit', ...req }, call);
|
|
406
405
|
}
|
|
407
|
-
/** `git config <key> <value
|
|
406
|
+
/** `git config <key> <value>`, the write counterpart of {@link AsyncGit.configGet}. */
|
|
408
407
|
configSet(key, value, opts = {}) {
|
|
409
408
|
const [call, req] = splitCallOptions(opts);
|
|
410
409
|
return this.backend.execute(this.cwd, { kind: 'configSet', key, value, ...req }, call);
|
|
@@ -507,8 +506,8 @@ export class AsyncGit {
|
|
|
507
506
|
}
|
|
508
507
|
/**
|
|
509
508
|
* What merging `theirs` into `ours` would do — no index, no checkout, no
|
|
510
|
-
* worktree.
|
|
511
|
-
* merged `tree` it returns is real
|
|
509
|
+
* worktree. It is the cheap way to ask "would this conflict, and where". The
|
|
510
|
+
* merged `tree` it returns is a real object you can build a commit from.
|
|
512
511
|
*/
|
|
513
512
|
mergeTree(ours, theirs, opts = {}) {
|
|
514
513
|
const [call, req] = splitCallOptions(opts);
|
package/dist/backend.d.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The backend
|
|
3
|
-
*
|
|
2
|
+
* The backend interface: what `AsyncGit` calls, and what you replace when git
|
|
3
|
+
* should not run as a subprocess.
|
|
4
4
|
*
|
|
5
|
-
* A backend takes a {@link GitRequest}
|
|
6
|
-
* one git operation
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* the
|
|
5
|
+
* A backend takes a {@link GitRequest}, a plain, serializable description of
|
|
6
|
+
* one git operation, and returns its typed result. The request is not argv on
|
|
7
|
+
* purpose. argv is a CLI detail, and a backend built on a pure-JavaScript git
|
|
8
|
+
* has no argv to receive. Describing the operation, not the command line, lets
|
|
9
|
+
* the same client work with either.
|
|
10
10
|
*
|
|
11
|
-
* It also means a request can be logged, queued, or replayed as data. The
|
|
12
|
-
*
|
|
13
|
-
*
|
|
11
|
+
* It also means a request can be logged, queued, or replayed as data. The
|
|
12
|
+
* exception is `raw`, which is argv by definition. A non-CLI backend rejects
|
|
13
|
+
* it with {@link UnsupportedRequest}.
|
|
14
14
|
*
|
|
15
|
-
* The
|
|
15
|
+
* The interface is experimental: `GitBackend`, `GitRequest`, `GitResults` and
|
|
16
16
|
* `partialBackend`. Each new verb adds a request kind, which breaks a backend
|
|
17
17
|
* written as an exhaustive switch. Such a change can land in a minor release.
|
|
18
18
|
* `cliBackend` and `AsyncGit` are stable.
|
|
@@ -22,24 +22,24 @@ import { type AddOptions, type AheadBehind, type CheckoutOptions, type CloneOpti
|
|
|
22
22
|
/** Per-call concerns that are not part of the operation itself. */
|
|
23
23
|
export interface GitCallOptions {
|
|
24
24
|
/**
|
|
25
|
-
*
|
|
26
|
-
* Without it there is no
|
|
25
|
+
* Time limit for the call. A backend that cannot enforce one may ignore it.
|
|
26
|
+
* Without it there is no limit, and the default async runner has no output
|
|
27
27
|
* cap either. An invalid value throws (sync) or rejects (async), as in command-seam:
|
|
28
28
|
* `RangeError` for 0, a negative value or `NaN`; `TypeError` for a
|
|
29
29
|
* non-number.
|
|
30
30
|
*/
|
|
31
31
|
timeoutMs?: number | undefined;
|
|
32
|
-
/**
|
|
32
|
+
/** Cancels the call while it runs, where the backend supports it. */
|
|
33
33
|
signal?: AbortSignal | undefined;
|
|
34
34
|
/**
|
|
35
|
-
* Entries merged over the parent environment for this call only.
|
|
36
|
-
*
|
|
37
|
-
*
|
|
35
|
+
* Entries merged over the parent environment for this call only. It is a
|
|
36
|
+
* call option, not part of the request, like `timeoutMs`: it describes how
|
|
37
|
+
* the command runs, not which operation was asked for.
|
|
38
38
|
*/
|
|
39
39
|
env?: Record<string, string> | undefined;
|
|
40
40
|
/**
|
|
41
41
|
* Cap on each output stream, in bytes. Past it the runner kills the child
|
|
42
|
-
* and the call throws (sync) or rejects (async) with
|
|
42
|
+
* and the call throws (sync) or rejects (async) with the classified failure, so
|
|
43
43
|
* cut-short output is never read as an answer. A backend that cannot
|
|
44
44
|
* enforce it may ignore it. Without it the async runner has no cap and the
|
|
45
45
|
* sync runner caps at 256 MB.
|
|
@@ -369,28 +369,26 @@ export declare class UnsupportedRequest extends Error {
|
|
|
369
369
|
export declare function cliBackend(opts?: {
|
|
370
370
|
runner?: AsyncCommandRunner | undefined;
|
|
371
371
|
/**
|
|
372
|
-
*
|
|
373
|
-
*
|
|
374
|
-
*
|
|
375
|
-
*
|
|
376
|
-
* spawns git.
|
|
372
|
+
* The repository to work on, added to every call as `--git-dir` /
|
|
373
|
+
* `--work-tree`. They are set on the backend, not on `GitRequest`, because
|
|
374
|
+
* they are CLI flags. A backend built on a pure-JavaScript git has no
|
|
375
|
+
* `--git-dir` to receive.
|
|
377
376
|
*/
|
|
378
377
|
gitDir?: string | undefined;
|
|
379
378
|
workTree?: string | undefined;
|
|
380
379
|
/**
|
|
381
380
|
* Entries merged over the parent environment on every call this backend
|
|
382
|
-
* makes, under any per-call `env`.
|
|
383
|
-
* `GIT_SSH_COMMAND` once,
|
|
381
|
+
* makes, under any per-call `env`. Use it to set an identity or a
|
|
382
|
+
* `GIT_SSH_COMMAND` once, instead of passing it on every call.
|
|
384
383
|
*/
|
|
385
384
|
env?: Record<string, string> | undefined;
|
|
386
385
|
}): GitBackend;
|
|
387
386
|
/**
|
|
388
387
|
* Wrap a partial implementation: any request kind the object does not handle
|
|
389
388
|
* rejects with {@link UnsupportedRequest} instead of failing as `undefined`.
|
|
390
|
-
*
|
|
391
|
-
* about the rest.
|
|
389
|
+
* Use it for a backend that covers only some operations.
|
|
392
390
|
*
|
|
393
|
-
* @experimental Part of the backend
|
|
391
|
+
* @experimental Part of the backend interface; see {@link GitBackend}.
|
|
394
392
|
*/
|
|
395
393
|
export declare function partialBackend(name: string, impl: Partial<{
|
|
396
394
|
[K in GitRequestKind]: (cwd: string, request: Extract<GitRequest, {
|
package/dist/backend.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The backend
|
|
3
|
-
*
|
|
2
|
+
* The backend interface: what `AsyncGit` calls, and what you replace when git
|
|
3
|
+
* should not run as a subprocess.
|
|
4
4
|
*
|
|
5
|
-
* A backend takes a {@link GitRequest}
|
|
6
|
-
* one git operation
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* the
|
|
5
|
+
* A backend takes a {@link GitRequest}, a plain, serializable description of
|
|
6
|
+
* one git operation, and returns its typed result. The request is not argv on
|
|
7
|
+
* purpose. argv is a CLI detail, and a backend built on a pure-JavaScript git
|
|
8
|
+
* has no argv to receive. Describing the operation, not the command line, lets
|
|
9
|
+
* the same client work with either.
|
|
10
10
|
*
|
|
11
|
-
* It also means a request can be logged, queued, or replayed as data. The
|
|
12
|
-
*
|
|
13
|
-
*
|
|
11
|
+
* It also means a request can be logged, queued, or replayed as data. The
|
|
12
|
+
* exception is `raw`, which is argv by definition. A non-CLI backend rejects
|
|
13
|
+
* it with {@link UnsupportedRequest}.
|
|
14
14
|
*
|
|
15
|
-
* The
|
|
15
|
+
* The interface is experimental: `GitBackend`, `GitRequest`, `GitResults` and
|
|
16
16
|
* `partialBackend`. Each new verb adds a request kind, which breaks a backend
|
|
17
17
|
* written as an exhaustive switch. Such a change can land in a minor release.
|
|
18
18
|
* `cliBackend` and `AsyncGit` are stable.
|
|
@@ -173,9 +173,8 @@ function toVerb(request) {
|
|
|
173
173
|
case 'raw': {
|
|
174
174
|
const verb = {
|
|
175
175
|
argv: request.argv,
|
|
176
|
-
// Unchecked `raw`
|
|
177
|
-
//
|
|
178
|
-
// absence.
|
|
176
|
+
// Unchecked `raw` skips `gate` (see `execute`), so this only matters
|
|
177
|
+
// for `rawChecked`, where no exit code is an absence.
|
|
179
178
|
absent: [],
|
|
180
179
|
parse: (r) => r,
|
|
181
180
|
};
|
|
@@ -214,15 +213,15 @@ export function cliBackend(opts = {}) {
|
|
|
214
213
|
runOpts.env = { ...runOpts.env, ...verb.env };
|
|
215
214
|
const argv = prefix.length === 0 ? verb.argv : [...prefix, ...verb.argv];
|
|
216
215
|
const result = await runner.run(argv, runOpts);
|
|
217
|
-
// Unchecked `raw` is the
|
|
218
|
-
//
|
|
219
|
-
//
|
|
216
|
+
// Unchecked `raw` is the only request that skips `gate`: it returns the
|
|
217
|
+
// result at any exit code. Everything else goes through the same `gate`
|
|
218
|
+
// the sync client uses.
|
|
220
219
|
const req = request;
|
|
221
220
|
const gated = req.kind !== 'raw' || req.checked === true;
|
|
222
221
|
// The prefixed argv is what ran, so it is what a `CommandFailed` reports.
|
|
223
222
|
const value = gated ? gate(verb, result, argv) : verb.parse(result, argv);
|
|
224
|
-
// `GitResults` restates the verb table's return types for callers
|
|
225
|
-
// two are kept in step by hand,
|
|
223
|
+
// `GitResults` restates the verb table's return types for callers. The
|
|
224
|
+
// two are kept in step by hand, and this cast is where they meet.
|
|
226
225
|
return value;
|
|
227
226
|
},
|
|
228
227
|
};
|
|
@@ -230,10 +229,9 @@ export function cliBackend(opts = {}) {
|
|
|
230
229
|
/**
|
|
231
230
|
* Wrap a partial implementation: any request kind the object does not handle
|
|
232
231
|
* rejects with {@link UnsupportedRequest} instead of failing as `undefined`.
|
|
233
|
-
*
|
|
234
|
-
* about the rest.
|
|
232
|
+
* Use it for a backend that covers only some operations.
|
|
235
233
|
*
|
|
236
|
-
* @experimental Part of the backend
|
|
234
|
+
* @experimental Part of the backend interface; see {@link GitBackend}.
|
|
237
235
|
*/
|
|
238
236
|
export function partialBackend(name, impl) {
|
|
239
237
|
return {
|
package/dist/checkout-root.d.ts
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Locate the git checkout containing a path, and find the checkouts inside a
|
|
3
|
-
* directory
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* that run before it would be safe to spawn one.
|
|
3
|
+
* directory, by reading the filesystem only, with no git process. Every other
|
|
4
|
+
* query in this package runs git (see `Git#topLevel()`, `git rev-parse
|
|
5
|
+
* --show-toplevel`). These exist for callers that must not depend on a git
|
|
6
|
+
* binary being present, or that run before it would be safe to spawn one.
|
|
7
7
|
*/
|
|
8
8
|
/**
|
|
9
9
|
* The git checkout containing `path` — the nearest ancestor (`path` itself
|
|
10
10
|
* included) carrying a `.git` entry, or null when none does.
|
|
11
11
|
*
|
|
12
12
|
* `.git` is a directory in a main checkout and a file (`gitdir: <path>`) in a
|
|
13
|
-
* linked worktree
|
|
14
|
-
* which is what
|
|
13
|
+
* linked worktree. `existsSync` matches either without telling them apart,
|
|
14
|
+
* which is what callers want.
|
|
15
15
|
*
|
|
16
|
-
* `path` may be a file or a directory
|
|
17
|
-
* stat'ed,
|
|
16
|
+
* `path` may be a file or a directory. A file, or anything that cannot be
|
|
17
|
+
* stat'ed (for example, it does not exist yet), starts the walk from its parent.
|
|
18
18
|
* Returns null on a miss rather than throwing: "no checkout here" is an
|
|
19
19
|
* answer, not a failure, matching this package's query contract.
|
|
20
20
|
*/
|
|
21
21
|
export declare function checkoutRoot(path: string): string | null;
|
|
22
22
|
/** How far below the search root {@link discoverCheckouts} looks by default. */
|
|
23
23
|
export declare const DEFAULT_MAX_DEPTH = 3;
|
|
24
|
-
/** Directories read before the walk
|
|
24
|
+
/** Directories read before the walk warns that the tree is very large. */
|
|
25
25
|
export declare const DEFAULT_WARN_AFTER = 10000;
|
|
26
26
|
export interface DiscoverCheckoutsOptions {
|
|
27
27
|
/**
|
|
@@ -35,17 +35,17 @@ export interface DiscoverCheckoutsOptions {
|
|
|
35
35
|
*/
|
|
36
36
|
warnAfter?: number | undefined;
|
|
37
37
|
/**
|
|
38
|
-
*
|
|
39
|
-
* line on stderr: a walk
|
|
40
|
-
*
|
|
41
|
-
*
|
|
38
|
+
* Called once, during the walk, when the search root turns out to be very
|
|
39
|
+
* large. Defaults to a line on stderr: a slow walk should say why while it
|
|
40
|
+
* is still running, not in a summary afterwards. A host with its own output
|
|
41
|
+
* passes its own function. `() => {}` silences it.
|
|
42
42
|
*/
|
|
43
43
|
onWarn?: ((message: string) => void) | undefined;
|
|
44
44
|
}
|
|
45
45
|
export interface CheckoutScan {
|
|
46
46
|
/** The checkouts found, sorted, as absolute paths. */
|
|
47
47
|
checkouts: string[];
|
|
48
|
-
/** Directories read, the search root included.
|
|
48
|
+
/** Directories read, the search root included. */
|
|
49
49
|
directoriesScanned: number;
|
|
50
50
|
/**
|
|
51
51
|
* Directories left unopened because `maxDepth` stopped the walk there. A
|
|
@@ -54,35 +54,36 @@ export interface CheckoutScan {
|
|
|
54
54
|
depthLimited: number;
|
|
55
55
|
}
|
|
56
56
|
/**
|
|
57
|
-
* The checkouts under `dir`, with what the walk
|
|
57
|
+
* The checkouts under `dir`, with counts of what the walk read.
|
|
58
58
|
*
|
|
59
59
|
* The walk descends through directories that are not checkouts and stops at
|
|
60
60
|
* the ones that are, because people group repositories: `~/Developer` holds
|
|
61
61
|
* an owner directory per GitHub org, or a folder per client, and the
|
|
62
|
-
* checkouts sit a level or two inside. Stopping at a checkout
|
|
63
|
-
*
|
|
64
|
-
*
|
|
62
|
+
* checkouts sit a level or two inside. Stopping at a checkout keeps this
|
|
63
|
+
* fast: a repository's own `node_modules`, `vendor` and nested worktrees are
|
|
64
|
+
* below it, so they are never entered.
|
|
65
65
|
*
|
|
66
|
-
* Two
|
|
67
|
-
*
|
|
68
|
-
* entered. The depth
|
|
69
|
-
* ordinary files
|
|
70
|
-
* stop the
|
|
71
|
-
* one a person sees: past that many directories the walk
|
|
72
|
-
*
|
|
66
|
+
* Two limits keep a bad search root from turning into a walk of the whole
|
|
67
|
+
* disk: children whose names start with a dot are skipped, and nothing
|
|
68
|
+
* deeper than `maxDepth` is entered. The depth limit matters most, since a
|
|
69
|
+
* directory of ordinary files, such as a documents folder or a media
|
|
70
|
+
* library, has no checkout to stop the walk. `warnAfter` is a third check,
|
|
71
|
+
* and the only one a person sees: past that many directories the walk warns
|
|
72
|
+
* and keeps going, because the usual cause is a search root pointed at the
|
|
73
|
+
* wrong place.
|
|
73
74
|
*
|
|
74
|
-
* Like {@link checkoutRoot},
|
|
75
|
-
* the cost is a `readdir` per directory entered and a `stat` per
|
|
76
|
-
* linked worktree answers as a checkout here, since both carry a
|
|
77
|
-
* entry
|
|
78
|
-
* through `Git#mainCheckout()` and de-duplicates.
|
|
75
|
+
* Like {@link checkoutRoot}, it reads the filesystem only. No git process
|
|
76
|
+
* runs, so the cost is a `readdir` per directory entered and a `stat` per
|
|
77
|
+
* child. A linked worktree answers as a checkout here, since both carry a
|
|
78
|
+
* `.git` entry. A caller that wants one row per repository resolves each
|
|
79
|
+
* result through `Git#mainCheckout()` and de-duplicates.
|
|
79
80
|
*
|
|
80
81
|
* An unreadable directory contributes nothing rather than throwing, matching
|
|
81
82
|
* this module's contract that absence is an answer.
|
|
82
83
|
*/
|
|
83
84
|
export declare function scanForCheckouts(dir: string, opts?: DiscoverCheckoutsOptions): CheckoutScan;
|
|
84
85
|
/**
|
|
85
|
-
* The checkouts under `dir`, sorted, as absolute paths
|
|
86
|
-
* scanForCheckouts}
|
|
86
|
+
* The checkouts under `dir`, sorted, as absolute paths. {@link
|
|
87
|
+
* scanForCheckouts} without the counts.
|
|
87
88
|
*/
|
|
88
89
|
export declare function discoverCheckouts(dir: string, opts?: DiscoverCheckoutsOptions): string[];
|
package/dist/checkout-root.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Locate the git checkout containing a path, and find the checkouts inside a
|
|
3
|
-
* directory
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* that run before it would be safe to spawn one.
|
|
3
|
+
* directory, by reading the filesystem only, with no git process. Every other
|
|
4
|
+
* query in this package runs git (see `Git#topLevel()`, `git rev-parse
|
|
5
|
+
* --show-toplevel`). These exist for callers that must not depend on a git
|
|
6
|
+
* binary being present, or that run before it would be safe to spawn one.
|
|
7
7
|
*/
|
|
8
8
|
import { existsSync, readdirSync, statSync } from 'node:fs';
|
|
9
9
|
import { dirname, resolve } from 'node:path';
|
|
@@ -21,11 +21,11 @@ function isDir(p) {
|
|
|
21
21
|
* included) carrying a `.git` entry, or null when none does.
|
|
22
22
|
*
|
|
23
23
|
* `.git` is a directory in a main checkout and a file (`gitdir: <path>`) in a
|
|
24
|
-
* linked worktree
|
|
25
|
-
* which is what
|
|
24
|
+
* linked worktree. `existsSync` matches either without telling them apart,
|
|
25
|
+
* which is what callers want.
|
|
26
26
|
*
|
|
27
|
-
* `path` may be a file or a directory
|
|
28
|
-
* stat'ed,
|
|
27
|
+
* `path` may be a file or a directory. A file, or anything that cannot be
|
|
28
|
+
* stat'ed (for example, it does not exist yet), starts the walk from its parent.
|
|
29
29
|
* Returns null on a miss rather than throwing: "no checkout here" is an
|
|
30
30
|
* answer, not a failure, matching this package's query contract.
|
|
31
31
|
*/
|
|
@@ -44,31 +44,32 @@ export function checkoutRoot(path) {
|
|
|
44
44
|
}
|
|
45
45
|
/** How far below the search root {@link discoverCheckouts} looks by default. */
|
|
46
46
|
export const DEFAULT_MAX_DEPTH = 3;
|
|
47
|
-
/** Directories read before the walk
|
|
47
|
+
/** Directories read before the walk warns that the tree is very large. */
|
|
48
48
|
export const DEFAULT_WARN_AFTER = 10_000;
|
|
49
49
|
/**
|
|
50
|
-
* The checkouts under `dir`, with what the walk
|
|
50
|
+
* The checkouts under `dir`, with counts of what the walk read.
|
|
51
51
|
*
|
|
52
52
|
* The walk descends through directories that are not checkouts and stops at
|
|
53
53
|
* the ones that are, because people group repositories: `~/Developer` holds
|
|
54
54
|
* an owner directory per GitHub org, or a folder per client, and the
|
|
55
|
-
* checkouts sit a level or two inside. Stopping at a checkout
|
|
56
|
-
*
|
|
57
|
-
*
|
|
55
|
+
* checkouts sit a level or two inside. Stopping at a checkout keeps this
|
|
56
|
+
* fast: a repository's own `node_modules`, `vendor` and nested worktrees are
|
|
57
|
+
* below it, so they are never entered.
|
|
58
58
|
*
|
|
59
|
-
* Two
|
|
60
|
-
*
|
|
61
|
-
* entered. The depth
|
|
62
|
-
* ordinary files
|
|
63
|
-
* stop the
|
|
64
|
-
* one a person sees: past that many directories the walk
|
|
65
|
-
*
|
|
59
|
+
* Two limits keep a bad search root from turning into a walk of the whole
|
|
60
|
+
* disk: children whose names start with a dot are skipped, and nothing
|
|
61
|
+
* deeper than `maxDepth` is entered. The depth limit matters most, since a
|
|
62
|
+
* directory of ordinary files, such as a documents folder or a media
|
|
63
|
+
* library, has no checkout to stop the walk. `warnAfter` is a third check,
|
|
64
|
+
* and the only one a person sees: past that many directories the walk warns
|
|
65
|
+
* and keeps going, because the usual cause is a search root pointed at the
|
|
66
|
+
* wrong place.
|
|
66
67
|
*
|
|
67
|
-
* Like {@link checkoutRoot},
|
|
68
|
-
* the cost is a `readdir` per directory entered and a `stat` per
|
|
69
|
-
* linked worktree answers as a checkout here, since both carry a
|
|
70
|
-
* entry
|
|
71
|
-
* through `Git#mainCheckout()` and de-duplicates.
|
|
68
|
+
* Like {@link checkoutRoot}, it reads the filesystem only. No git process
|
|
69
|
+
* runs, so the cost is a `readdir` per directory entered and a `stat` per
|
|
70
|
+
* child. A linked worktree answers as a checkout here, since both carry a
|
|
71
|
+
* `.git` entry. A caller that wants one row per repository resolves each
|
|
72
|
+
* result through `Git#mainCheckout()` and de-duplicates.
|
|
72
73
|
*
|
|
73
74
|
* An unreadable directory contributes nothing rather than throwing, matching
|
|
74
75
|
* this module's contract that absence is an answer.
|
|
@@ -119,8 +120,8 @@ export function scanForCheckouts(dir, opts = {}) {
|
|
|
119
120
|
return { checkouts: checkouts.sort(), directoriesScanned, depthLimited };
|
|
120
121
|
}
|
|
121
122
|
/**
|
|
122
|
-
* The checkouts under `dir`, sorted, as absolute paths
|
|
123
|
-
* scanForCheckouts}
|
|
123
|
+
* The checkouts under `dir`, sorted, as absolute paths. {@link
|
|
124
|
+
* scanForCheckouts} without the counts.
|
|
124
125
|
*/
|
|
125
126
|
export function discoverCheckouts(dir, opts = {}) {
|
|
126
127
|
return scanForCheckouts(dir, opts).checkouts;
|
package/dist/client.d.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `@osdlc/typed-git/client
|
|
3
|
-
* git-reference parsers and the checkout walks.
|
|
2
|
+
* `@osdlc/typed-git/client`: the git clients, their backend and runner
|
|
3
|
+
* types, without the git-reference parsers and the checkout walks.
|
|
4
4
|
*
|
|
5
5
|
* The package entry minus two groups. The first is `parseGitUrl`,
|
|
6
6
|
* `gitSshUrl`, `parseRepoRef` and their types, which pull in
|
|
7
7
|
* `hosted-git-info`. The second is the checkout walks: `checkoutRoot`,
|
|
8
8
|
* `discoverCheckouts`, `scanForCheckouts`, their types and their defaults. A
|
|
9
|
-
* consumer that only
|
|
9
|
+
* consumer that only runs git, such as a runner discovery pass or a check script,
|
|
10
10
|
* imports from here and keeps `hosted-git-info` off its module graph. It stays
|
|
11
11
|
* in `dependencies` either way, so this is a bundle saving, not an install
|
|
12
12
|
* one.
|
|
13
13
|
*
|
|
14
14
|
* The package entry is defined as this module plus the URL exports, so there
|
|
15
|
-
* is one
|
|
15
|
+
* is one list of exports rather than two to keep in step.
|
|
16
16
|
*/
|
|
17
17
|
export { Git, type GitSyncCallOptions } from './sync.ts';
|
|
18
18
|
export { AsyncGit } from './async.ts';
|