@osdlc/typed-git 0.8.2 → 0.10.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 +37 -0
- package/README.md +37 -9
- package/dist/async.d.ts +16 -12
- package/dist/async.js +41 -13
- package/dist/backend.d.ts +27 -11
- package/dist/backend.js +11 -3
- package/dist/checkout-root.d.ts +2 -1
- package/dist/checkout-root.js +7 -1
- package/dist/client.d.ts +1 -1
- package/dist/failure.js +6 -17
- package/dist/git-url.d.ts +24 -0
- package/dist/git-url.js +43 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.js +4 -3
- package/dist/outcome.d.ts +7 -2
- package/dist/outcome.js +9 -45
- package/dist/remote-url.d.ts +2 -2
- package/dist/remote-url.js +7 -3
- package/dist/soft.d.ts +1 -0
- package/dist/soft.js +1 -0
- package/dist/sync.d.ts +35 -14
- package/dist/sync.js +54 -7
- package/dist/verbs.d.ts +134 -8
- package/dist/verbs.js +138 -20
- package/package.json +2 -2
package/dist/verbs.d.ts
CHANGED
|
@@ -152,6 +152,17 @@ export declare function splitLines(out: string): string[];
|
|
|
152
152
|
* absence from breakage.
|
|
153
153
|
*/
|
|
154
154
|
export declare function showAtRev(rev: string, relPath: string): GitVerb<string | null>;
|
|
155
|
+
/**
|
|
156
|
+
* A file's content at a rev (`git show <rev>:<relPath>`), and a throw when it
|
|
157
|
+
* is not there.
|
|
158
|
+
*
|
|
159
|
+
* The same argv as {@link showAtRev}, with `absent: []`. Use it when a missing
|
|
160
|
+
* file is an error: a path that is not in that tree throws the classified
|
|
161
|
+
* failure, as does a rev that does not resolve or a broken repository, rather
|
|
162
|
+
* than all three reading as `null`. It has no `soft` form, because it has no
|
|
163
|
+
* absence value.
|
|
164
|
+
*/
|
|
165
|
+
export declare function showAtRevChecked(rev: string, relPath: string): GitVerb<string>;
|
|
155
166
|
/**
|
|
156
167
|
* Trimmed `git rev-parse <args>` output, for a query no other verb covers.
|
|
157
168
|
*
|
|
@@ -272,7 +283,11 @@ export interface StatusEntry {
|
|
|
272
283
|
* tree; throws outside a repository.
|
|
273
284
|
*/
|
|
274
285
|
export declare function statusEntries(): GitVerb<StatusEntry[]>;
|
|
275
|
-
/**
|
|
286
|
+
/**
|
|
287
|
+
* Local branch names matching `pattern` (all when omitted). The name is
|
|
288
|
+
* `refs/heads/` stripped, never `%(refname:short)`, which answers
|
|
289
|
+
* `heads/<name>` when a tag shares the name.
|
|
290
|
+
*/
|
|
276
291
|
export declare function branches(pattern?: string | undefined): GitVerb<string[]>;
|
|
277
292
|
/** `git worktree list --porcelain`, parsed. Throws outside a repository. */
|
|
278
293
|
export declare function worktrees(): GitVerb<Worktree[]>;
|
|
@@ -513,6 +528,20 @@ export interface DiffCheckOptions {
|
|
|
513
528
|
* code (2 on current git), so they are an answer, not a failure.
|
|
514
529
|
*/
|
|
515
530
|
export declare function diffCheck(opts?: DiffCheckOptions): GitVerb<DiffCheckResult>;
|
|
531
|
+
/**
|
|
532
|
+
* True iff the index differs from HEAD (`git diff --cached --quiet`): is there
|
|
533
|
+
* anything staged to commit?
|
|
534
|
+
*
|
|
535
|
+
* A boolean carried by the exit code. `absent: [1]` — measured: nothing staged
|
|
536
|
+
* → 0 (`false`); something staged → 1 (`true`). Anything else throws. Outside
|
|
537
|
+
* a repository `git diff` exits 129, so a non-repository is a failure, not
|
|
538
|
+
* "nothing staged".
|
|
539
|
+
*
|
|
540
|
+
* On an unborn HEAD (no commits yet) git compares the index against the empty
|
|
541
|
+
* tree: an empty index is `false`, and any staged file is `true`. It does not
|
|
542
|
+
* throw.
|
|
543
|
+
*/
|
|
544
|
+
export declare function hasStagedChanges(): GitVerb<boolean>;
|
|
516
545
|
/** Options for {@link diffNameStatus}. */
|
|
517
546
|
export interface DiffNameStatusOptions {
|
|
518
547
|
/** `--cached` — diff the index against HEAD rather than the worktree. */
|
|
@@ -851,6 +880,16 @@ export interface CommitFlags {
|
|
|
851
880
|
noVerify?: boolean | undefined;
|
|
852
881
|
/** `--signoff` — append a `Signed-off-by` trailer. */
|
|
853
882
|
signoff?: boolean | undefined;
|
|
883
|
+
/**
|
|
884
|
+
* `-- <paths…>` — commit only these paths, as `git commit <paths>` does:
|
|
885
|
+
* their current working-tree content is committed, and anything else
|
|
886
|
+
* staged stays staged and out of the commit. Each path must be known to
|
|
887
|
+
* git (tracked, or staged), or git refuses.
|
|
888
|
+
*
|
|
889
|
+
* An empty array throws a `TypeError`: git would read `commit --` as no
|
|
890
|
+
* paths and commit everything staged.
|
|
891
|
+
*/
|
|
892
|
+
paths?: string[] | undefined;
|
|
854
893
|
}
|
|
855
894
|
/**
|
|
856
895
|
* Options for {@link commit}. The message comes from exactly one source, and
|
|
@@ -985,8 +1024,19 @@ export interface ForceLease {
|
|
|
985
1024
|
* an intended pin into the wrong check. Absence is only ever `expect: null`.
|
|
986
1025
|
*/
|
|
987
1026
|
export declare function forceWithLeaseArg(lease: ForceLease): string;
|
|
1027
|
+
/** Options for {@link push}. */
|
|
1028
|
+
export interface PushOptions {
|
|
1029
|
+
/** `--force-with-lease`: `true` for the bare flag, a {@link ForceLease} to pin it. */
|
|
1030
|
+
forceWithLease?: boolean | ForceLease | undefined;
|
|
1031
|
+
/**
|
|
1032
|
+
* `--delete` — delete `refspec` on the remote rather than pushing to it.
|
|
1033
|
+
* Combines with `forceWithLease`, so a pinned lease deletes the remote ref
|
|
1034
|
+
* only while it still holds the expected sha.
|
|
1035
|
+
*/
|
|
1036
|
+
delete?: boolean | undefined;
|
|
1037
|
+
}
|
|
988
1038
|
/**
|
|
989
|
-
* Push a refspec
|
|
1039
|
+
* Push a refspec, or delete it on the remote with `{ delete: true }`.
|
|
990
1040
|
*
|
|
991
1041
|
* `forceWithLease` takes a {@link ForceLease} for the pinned form, or `true`
|
|
992
1042
|
* for the bare `--force-with-lease`. `true` is the unsafe form. It trusts
|
|
@@ -994,9 +1044,7 @@ export declare function forceWithLeaseArg(lease: ForceLease): string;
|
|
|
994
1044
|
* bring that up to date. The lease then blocks nothing, and a concurrent push
|
|
995
1045
|
* is overwritten. Pin the lease whenever the expected remote sha is known.
|
|
996
1046
|
*/
|
|
997
|
-
export declare function push(remote: string, refspec: string, opts?:
|
|
998
|
-
forceWithLease?: boolean | ForceLease | undefined;
|
|
999
|
-
}): GitVerb<void>;
|
|
1047
|
+
export declare function push(remote: string, refspec: string, opts?: PushOptions): GitVerb<void>;
|
|
1000
1048
|
/** Options for {@link pushPorcelain}. */
|
|
1001
1049
|
export interface PushPorcelainOptions {
|
|
1002
1050
|
/**
|
|
@@ -1117,12 +1165,24 @@ export declare function deleteBranch(name: string, opts?: {
|
|
|
1117
1165
|
export declare function deleteRef(ref: string, opts: {
|
|
1118
1166
|
expected: string;
|
|
1119
1167
|
}): GitVerb<void>;
|
|
1120
|
-
/**
|
|
1121
|
-
export
|
|
1168
|
+
/** Options for {@link worktreeAdd}. */
|
|
1169
|
+
export interface WorktreeAddOptions {
|
|
1170
|
+
/** `-b <branch>` — create this branch at `startPoint`; git refuses if it exists. */
|
|
1122
1171
|
branch?: string | undefined;
|
|
1172
|
+
/**
|
|
1173
|
+
* `-B` rather than `-b`: create `branch`, or reset an existing one, at
|
|
1174
|
+
* `startPoint`. git still refuses a branch checked out in another
|
|
1175
|
+
* worktree. Without `branch` it throws a `TypeError`. The same shape as
|
|
1176
|
+
* {@link CheckoutOptions.resetBranch}.
|
|
1177
|
+
*/
|
|
1178
|
+
resetBranch?: boolean | undefined;
|
|
1179
|
+
/** The commit the new worktree (and branch) starts at; HEAD when omitted. */
|
|
1123
1180
|
startPoint?: string | undefined;
|
|
1181
|
+
/** `--detach` — check out `startPoint` with no branch. */
|
|
1124
1182
|
detach?: boolean | undefined;
|
|
1125
|
-
}
|
|
1183
|
+
}
|
|
1184
|
+
/** `git worktree add [--detach] [-b|-B branch] <path> [startPoint]`. */
|
|
1185
|
+
export declare function worktreeAdd(path: string, opts?: WorktreeAddOptions): GitVerb<void>;
|
|
1126
1186
|
/** `git worktree remove [--force] <path>`. */
|
|
1127
1187
|
export declare function worktreeRemove(path: string, opts?: {
|
|
1128
1188
|
force?: boolean | undefined;
|
|
@@ -1140,6 +1200,72 @@ export declare function worktreeUnlock(path: string): GitVerb<void>;
|
|
|
1140
1200
|
export declare function worktreePrune(): GitVerb<void>;
|
|
1141
1201
|
/** `git remote add <name> <url>`. */
|
|
1142
1202
|
export declare function remoteAdd(name: string, url: string): GitVerb<void>;
|
|
1203
|
+
/**
|
|
1204
|
+
* What {@link remoteSetHead} does to `refs/remotes/<remote>/HEAD`: point it
|
|
1205
|
+
* at `branch`, ask the remote which branch its HEAD names (`auto`), or delete
|
|
1206
|
+
* it. Exactly one; the types refuse a mix, and so does the verb at run time.
|
|
1207
|
+
*/
|
|
1208
|
+
export type RemoteSetHeadOptions = {
|
|
1209
|
+
branch: string;
|
|
1210
|
+
auto?: undefined;
|
|
1211
|
+
delete?: undefined;
|
|
1212
|
+
} | {
|
|
1213
|
+
auto: true;
|
|
1214
|
+
branch?: undefined;
|
|
1215
|
+
delete?: undefined;
|
|
1216
|
+
} | {
|
|
1217
|
+
delete: true;
|
|
1218
|
+
branch?: undefined;
|
|
1219
|
+
auto?: undefined;
|
|
1220
|
+
};
|
|
1221
|
+
/**
|
|
1222
|
+
* `git remote set-head <remote> <branch> | --auto | --delete`: set or remove
|
|
1223
|
+
* the local `refs/remotes/<remote>/HEAD`, which {@link symbolicRef} reads.
|
|
1224
|
+
*
|
|
1225
|
+
* `absent: []`. A `branch` with no remote-tracking ref `<remote>/<branch>`
|
|
1226
|
+
* exits 1 and throws, and so does an unknown remote with `branch`. `auto` asks
|
|
1227
|
+
* the remote, so an unknown or unreachable one exits 128, and a remote whose
|
|
1228
|
+
* HEAD cannot be determined exits 1; both throw. `delete`
|
|
1229
|
+
* when the ref is not set exits 0 (measured on git 2.34).
|
|
1230
|
+
*/
|
|
1231
|
+
export declare function remoteSetHead(remote: string, opts: RemoteSetHeadOptions): GitVerb<void>;
|
|
1232
|
+
/** Options for {@link remoteSetBranches}. */
|
|
1233
|
+
export interface RemoteSetBranchesOptions {
|
|
1234
|
+
/** `--add` — add to the tracked branches rather than replacing them. */
|
|
1235
|
+
add?: boolean | undefined;
|
|
1236
|
+
}
|
|
1237
|
+
/**
|
|
1238
|
+
* `git remote set-branches [--add] <remote> <branch…>`: the branches a fetch
|
|
1239
|
+
* of `remote` tracks, written as its `remote.<remote>.fetch` refspecs. A
|
|
1240
|
+
* branch may be a glob.
|
|
1241
|
+
*
|
|
1242
|
+
* An empty `branches` throws a `TypeError`: git would exit 0 and clear every
|
|
1243
|
+
* fetch refspec of the remote. `absent: []` — an unknown remote exits 2 and throws.
|
|
1244
|
+
*/
|
|
1245
|
+
export declare function remoteSetBranches(remote: string, branches: string[], opts?: RemoteSetBranchesOptions): GitVerb<void>;
|
|
1246
|
+
/** Options for {@link gc}. */
|
|
1247
|
+
export interface GcOptions {
|
|
1248
|
+
/**
|
|
1249
|
+
* `--auto` — do nothing unless git's thresholds say housekeeping is due.
|
|
1250
|
+
* With git's default `gc.autoDetach=true`, the work then runs in the
|
|
1251
|
+
* background after this call returns. A caller about to delete or reuse the
|
|
1252
|
+
* repository sets `env: { GIT_CONFIG_PARAMETERS: "'gc.autoDetach=false'" }`
|
|
1253
|
+
* or omits `auto`.
|
|
1254
|
+
*/
|
|
1255
|
+
auto?: boolean | undefined;
|
|
1256
|
+
/** `--aggressive` — optimize harder, at much more time. */
|
|
1257
|
+
aggressive?: boolean | undefined;
|
|
1258
|
+
/**
|
|
1259
|
+
* `--prune=<date>` for a date string such as `'now'` or `'2.weeks.ago'`,
|
|
1260
|
+
* or `--no-prune` for `false`. Omitted means git's `gc.pruneExpire`. An
|
|
1261
|
+
* empty string throws a `TypeError`.
|
|
1262
|
+
*/
|
|
1263
|
+
prune?: string | false | undefined;
|
|
1264
|
+
/** `--quiet` — suppress the progress report. */
|
|
1265
|
+
quiet?: boolean | undefined;
|
|
1266
|
+
}
|
|
1267
|
+
/** `git gc [--auto] [--aggressive] [--prune=<date> | --no-prune] [--quiet]`. */
|
|
1268
|
+
export declare function gc(opts?: GcOptions): GitVerb<void>;
|
|
1143
1269
|
/** How an integration attempt ended. */
|
|
1144
1270
|
export type IntegrationOutcome<Extra> = ({
|
|
1145
1271
|
status: 'clean';
|
package/dist/verbs.js
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
*
|
|
13
13
|
* `GitVerb` and `gate` are internal: the package entries do not export them.
|
|
14
14
|
*/
|
|
15
|
-
import { CommandFailed } from '@osdlc/command-seam';
|
|
15
|
+
import { CommandFailed, notAnOption, runFailed } from '@osdlc/command-seam';
|
|
16
16
|
import { gitFailureError } from "./failure.js";
|
|
17
17
|
/**
|
|
18
18
|
* Turn one git result into a value or a thrown failure: a `FailureError`
|
|
@@ -40,9 +40,7 @@ import { gitFailureError } from "./failure.js";
|
|
|
40
40
|
*/
|
|
41
41
|
export function gate(verb, result, argv) {
|
|
42
42
|
try {
|
|
43
|
-
if (result.
|
|
44
|
-
result.outputIncomplete ||
|
|
45
|
-
(result.exitCode !== 0 && !verb.absent.includes(result.exitCode))) {
|
|
43
|
+
if (runFailed(result, (r) => verb.absent.includes(r.exitCode))) {
|
|
46
44
|
throw new CommandFailed(argv ?? verb.argv, result);
|
|
47
45
|
}
|
|
48
46
|
return verb.parse(result, argv ?? verb.argv);
|
|
@@ -164,10 +162,8 @@ const NONE = [];
|
|
|
164
162
|
* `-`, and `@{-1}` for the previous branch.
|
|
165
163
|
*/
|
|
166
164
|
function positional(verb, param, value) {
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
}
|
|
170
|
-
return value;
|
|
165
|
+
const message = (v) => `typed-git: ${verb}: ${param} must not start with "-" (got ${JSON.stringify(v)})`;
|
|
166
|
+
return notAnOption(value, (v) => new TypeError(message(v)));
|
|
171
167
|
}
|
|
172
168
|
/**
|
|
173
169
|
* A config key for the `config` reads: {@link positional}, plus a section and
|
|
@@ -217,6 +213,24 @@ export function showAtRev(rev, relPath) {
|
|
|
217
213
|
parse: (r) => (r.exitCode === 0 ? r.stdout : null),
|
|
218
214
|
};
|
|
219
215
|
}
|
|
216
|
+
/**
|
|
217
|
+
* A file's content at a rev (`git show <rev>:<relPath>`), and a throw when it
|
|
218
|
+
* is not there.
|
|
219
|
+
*
|
|
220
|
+
* The same argv as {@link showAtRev}, with `absent: []`. Use it when a missing
|
|
221
|
+
* file is an error: a path that is not in that tree throws the classified
|
|
222
|
+
* failure, as does a rev that does not resolve or a broken repository, rather
|
|
223
|
+
* than all three reading as `null`. It has no `soft` form, because it has no
|
|
224
|
+
* absence value.
|
|
225
|
+
*/
|
|
226
|
+
export function showAtRevChecked(rev, relPath) {
|
|
227
|
+
return {
|
|
228
|
+
argv: ['show', `${positional('showAtRevChecked', 'rev', rev)}:${relPath}`],
|
|
229
|
+
absent: NONE,
|
|
230
|
+
// Verbatim, as for showAtRev.
|
|
231
|
+
parse: (r) => r.stdout,
|
|
232
|
+
};
|
|
233
|
+
}
|
|
220
234
|
/**
|
|
221
235
|
* Trimmed `git rev-parse <args>` output, for a query no other verb covers.
|
|
222
236
|
*
|
|
@@ -374,17 +388,24 @@ export function statusEntries() {
|
|
|
374
388
|
if (f.length < 4)
|
|
375
389
|
continue;
|
|
376
390
|
const x = f[0];
|
|
377
|
-
|
|
378
|
-
|
|
391
|
+
const y = f[1];
|
|
392
|
+
out.push({ x, y, path: f.slice(3) });
|
|
393
|
+
// A rename or copy in either column (a worktree rename of an
|
|
394
|
+
// intent-to-add file sets Y) is followed by its source field.
|
|
395
|
+
if (x === 'R' || x === 'C' || y === 'R' || y === 'C')
|
|
379
396
|
i++;
|
|
380
397
|
}
|
|
381
398
|
return out;
|
|
382
399
|
},
|
|
383
400
|
};
|
|
384
401
|
}
|
|
385
|
-
/**
|
|
402
|
+
/**
|
|
403
|
+
* Local branch names matching `pattern` (all when omitted). The name is
|
|
404
|
+
* `refs/heads/` stripped, never `%(refname:short)`, which answers
|
|
405
|
+
* `heads/<name>` when a tag shares the name.
|
|
406
|
+
*/
|
|
386
407
|
export function branches(pattern) {
|
|
387
|
-
const argv = ['branch', '--list', '--format=%(refname:
|
|
408
|
+
const argv = ['branch', '--list', '--format=%(refname:lstrip=2)'];
|
|
388
409
|
if (pattern !== undefined)
|
|
389
410
|
argv.push(positional('branches', 'pattern', pattern));
|
|
390
411
|
return { argv, absent: NONE, parse: trimmedLines };
|
|
@@ -754,6 +775,26 @@ export function diffCheck(opts = {}) {
|
|
|
754
775
|
parse: (r) => ({ ok: r.exitCode === 0, output: r.stdout }),
|
|
755
776
|
};
|
|
756
777
|
}
|
|
778
|
+
/**
|
|
779
|
+
* True iff the index differs from HEAD (`git diff --cached --quiet`): is there
|
|
780
|
+
* anything staged to commit?
|
|
781
|
+
*
|
|
782
|
+
* A boolean carried by the exit code. `absent: [1]` — measured: nothing staged
|
|
783
|
+
* → 0 (`false`); something staged → 1 (`true`). Anything else throws. Outside
|
|
784
|
+
* a repository `git diff` exits 129, so a non-repository is a failure, not
|
|
785
|
+
* "nothing staged".
|
|
786
|
+
*
|
|
787
|
+
* On an unborn HEAD (no commits yet) git compares the index against the empty
|
|
788
|
+
* tree: an empty index is `false`, and any staged file is `true`. It does not
|
|
789
|
+
* throw.
|
|
790
|
+
*/
|
|
791
|
+
export function hasStagedChanges() {
|
|
792
|
+
return {
|
|
793
|
+
argv: ['diff', '--cached', '--quiet'],
|
|
794
|
+
absent: [1],
|
|
795
|
+
parse: (r) => r.exitCode === 1,
|
|
796
|
+
};
|
|
797
|
+
}
|
|
757
798
|
/**
|
|
758
799
|
* Changed paths with their status (`git diff --name-status -z`).
|
|
759
800
|
*
|
|
@@ -1180,6 +1221,10 @@ export function add(paths, opts = {}) {
|
|
|
1180
1221
|
* which holds both streams, not stderr alone.
|
|
1181
1222
|
*/
|
|
1182
1223
|
export function commit(opts) {
|
|
1224
|
+
if (opts.paths !== undefined && opts.paths.length === 0) {
|
|
1225
|
+
throw new TypeError('typed-git: commit: paths is empty; omit it to commit everything staged');
|
|
1226
|
+
}
|
|
1227
|
+
const pathArgs = opts.paths === undefined ? [] : ['--', ...opts.paths];
|
|
1183
1228
|
const argv = ['commit'];
|
|
1184
1229
|
if (opts.allowEmpty)
|
|
1185
1230
|
argv.push('--allow-empty');
|
|
@@ -1190,7 +1235,7 @@ export function commit(opts) {
|
|
|
1190
1235
|
if (opts.signoff)
|
|
1191
1236
|
argv.push('--signoff');
|
|
1192
1237
|
if (opts.messageStdin !== undefined) {
|
|
1193
|
-
argv.push('-F', '-');
|
|
1238
|
+
argv.push('-F', '-', ...pathArgs);
|
|
1194
1239
|
return { argv, input: opts.messageStdin, absent: NONE, parse: nothing };
|
|
1195
1240
|
}
|
|
1196
1241
|
if (opts.messageFile !== undefined)
|
|
@@ -1200,6 +1245,7 @@ export function commit(opts) {
|
|
|
1200
1245
|
if (opts.body !== undefined)
|
|
1201
1246
|
argv.push('-m', opts.body);
|
|
1202
1247
|
}
|
|
1248
|
+
argv.push(...pathArgs);
|
|
1203
1249
|
return { argv, absent: NONE, parse: nothing };
|
|
1204
1250
|
}
|
|
1205
1251
|
/** `git config <key> <value>` — the write twin of {@link configGet}. */
|
|
@@ -1288,7 +1334,7 @@ export function forceWithLeaseArg(lease) {
|
|
|
1288
1334
|
return `--force-with-lease=${lease.ref}:${lease.expect ?? ''}`;
|
|
1289
1335
|
}
|
|
1290
1336
|
/**
|
|
1291
|
-
* Push a refspec
|
|
1337
|
+
* Push a refspec, or delete it on the remote with `{ delete: true }`.
|
|
1292
1338
|
*
|
|
1293
1339
|
* `forceWithLease` takes a {@link ForceLease} for the pinned form, or `true`
|
|
1294
1340
|
* for the bare `--force-with-lease`. `true` is the unsafe form. It trusts
|
|
@@ -1297,7 +1343,10 @@ export function forceWithLeaseArg(lease) {
|
|
|
1297
1343
|
* is overwritten. Pin the lease whenever the expected remote sha is known.
|
|
1298
1344
|
*/
|
|
1299
1345
|
export function push(remote, refspec, opts = {}) {
|
|
1300
|
-
const argv = ['push'
|
|
1346
|
+
const argv = ['push'];
|
|
1347
|
+
if (opts.delete)
|
|
1348
|
+
argv.push('--delete');
|
|
1349
|
+
argv.push(...forceWithLeaseArgs('push', opts.forceWithLease));
|
|
1301
1350
|
argv.push(positional('push', 'remote', remote), positional('push', 'refspec', refspec));
|
|
1302
1351
|
return { argv, absent: NONE, parse: nothing };
|
|
1303
1352
|
}
|
|
@@ -1489,13 +1538,19 @@ export function deleteRef(ref, opts) {
|
|
|
1489
1538
|
parse: nothing,
|
|
1490
1539
|
};
|
|
1491
1540
|
}
|
|
1492
|
-
/** `git worktree add [--detach] [-b branch] <path> [startPoint]`. */
|
|
1541
|
+
/** `git worktree add [--detach] [-b|-B branch] <path> [startPoint]`. */
|
|
1493
1542
|
export function worktreeAdd(path, opts = {}) {
|
|
1543
|
+
if (opts.resetBranch && opts.branch === undefined) {
|
|
1544
|
+
throw new TypeError('typed-git: worktreeAdd: resetBranch needs a branch');
|
|
1545
|
+
}
|
|
1494
1546
|
const argv = ['worktree', 'add'];
|
|
1495
1547
|
if (opts.detach)
|
|
1496
1548
|
argv.push('--detach');
|
|
1497
|
-
|
|
1498
|
-
|
|
1549
|
+
// Guarded: worktree add hands the name to a child `git branch`, which would
|
|
1550
|
+
// read a leading-dash value such as `-M` as an option.
|
|
1551
|
+
if (opts.branch !== undefined) {
|
|
1552
|
+
argv.push(opts.resetBranch ? '-B' : '-b', positional('worktreeAdd', 'branch', opts.branch));
|
|
1553
|
+
}
|
|
1499
1554
|
argv.push(positional('worktreeAdd', 'path', path));
|
|
1500
1555
|
const start = optionalPositional('worktreeAdd', 'startPoint', opts.startPoint);
|
|
1501
1556
|
if (start !== undefined)
|
|
@@ -1543,6 +1598,68 @@ export function remoteAdd(name, url) {
|
|
|
1543
1598
|
parse: nothing,
|
|
1544
1599
|
};
|
|
1545
1600
|
}
|
|
1601
|
+
/**
|
|
1602
|
+
* `git remote set-head <remote> <branch> | --auto | --delete`: set or remove
|
|
1603
|
+
* the local `refs/remotes/<remote>/HEAD`, which {@link symbolicRef} reads.
|
|
1604
|
+
*
|
|
1605
|
+
* `absent: []`. A `branch` with no remote-tracking ref `<remote>/<branch>`
|
|
1606
|
+
* exits 1 and throws, and so does an unknown remote with `branch`. `auto` asks
|
|
1607
|
+
* the remote, so an unknown or unreachable one exits 128, and a remote whose
|
|
1608
|
+
* HEAD cannot be determined exits 1; both throw. `delete`
|
|
1609
|
+
* when the ref is not set exits 0 (measured on git 2.34).
|
|
1610
|
+
*/
|
|
1611
|
+
export function remoteSetHead(remote, opts) {
|
|
1612
|
+
const given = [opts.branch !== undefined, opts.auto === true, opts.delete === true];
|
|
1613
|
+
if (given.filter(Boolean).length !== 1) {
|
|
1614
|
+
throw new TypeError('typed-git: remoteSetHead: pass exactly one of branch, auto, delete');
|
|
1615
|
+
}
|
|
1616
|
+
const argv = ['remote', 'set-head', positional('remoteSetHead', 'remote', remote)];
|
|
1617
|
+
if (opts.branch !== undefined)
|
|
1618
|
+
argv.push(positional('remoteSetHead', 'branch', opts.branch));
|
|
1619
|
+
else if (opts.auto)
|
|
1620
|
+
argv.push('--auto');
|
|
1621
|
+
else
|
|
1622
|
+
argv.push('--delete');
|
|
1623
|
+
return { argv, absent: NONE, parse: nothing };
|
|
1624
|
+
}
|
|
1625
|
+
/**
|
|
1626
|
+
* `git remote set-branches [--add] <remote> <branch…>`: the branches a fetch
|
|
1627
|
+
* of `remote` tracks, written as its `remote.<remote>.fetch` refspecs. A
|
|
1628
|
+
* branch may be a glob.
|
|
1629
|
+
*
|
|
1630
|
+
* An empty `branches` throws a `TypeError`: git would exit 0 and clear every
|
|
1631
|
+
* fetch refspec of the remote. `absent: []` — an unknown remote exits 2 and throws.
|
|
1632
|
+
*/
|
|
1633
|
+
export function remoteSetBranches(remote, branches, opts = {}) {
|
|
1634
|
+
if (branches.length === 0) {
|
|
1635
|
+
throw new TypeError('typed-git: remoteSetBranches: branches is empty');
|
|
1636
|
+
}
|
|
1637
|
+
const argv = ['remote', 'set-branches'];
|
|
1638
|
+
if (opts.add)
|
|
1639
|
+
argv.push('--add');
|
|
1640
|
+
argv.push(positional('remoteSetBranches', 'remote', remote));
|
|
1641
|
+
for (const b of branches)
|
|
1642
|
+
argv.push(positional('remoteSetBranches', 'branch', b));
|
|
1643
|
+
return { argv, absent: NONE, parse: nothing };
|
|
1644
|
+
}
|
|
1645
|
+
/** `git gc [--auto] [--aggressive] [--prune=<date> | --no-prune] [--quiet]`. */
|
|
1646
|
+
export function gc(opts = {}) {
|
|
1647
|
+
const argv = ['gc'];
|
|
1648
|
+
if (opts.auto)
|
|
1649
|
+
argv.push('--auto');
|
|
1650
|
+
if (opts.aggressive)
|
|
1651
|
+
argv.push('--aggressive');
|
|
1652
|
+
if (opts.prune === false)
|
|
1653
|
+
argv.push('--no-prune');
|
|
1654
|
+
else if (opts.prune !== undefined) {
|
|
1655
|
+
if (opts.prune === '')
|
|
1656
|
+
throw new TypeError('typed-git: gc: prune is empty');
|
|
1657
|
+
argv.push(`--prune=${opts.prune}`);
|
|
1658
|
+
}
|
|
1659
|
+
if (opts.quiet)
|
|
1660
|
+
argv.push('--quiet');
|
|
1661
|
+
return { argv, absent: NONE, parse: nothing };
|
|
1662
|
+
}
|
|
1546
1663
|
/** `CONFLICT (content|add/add|…): Merge conflict in <path>` */
|
|
1547
1664
|
const CONFLICT_MERGE_IN = /^CONFLICT \([^)]*\): Merge conflict in (.+)$/;
|
|
1548
1665
|
/** `CONFLICT (modify/delete): <path> deleted in <x> and modified in <y>…` */
|
|
@@ -1788,8 +1905,9 @@ export function checkout(ref, opts = {}) {
|
|
|
1788
1905
|
const argv = ['checkout'];
|
|
1789
1906
|
if (opts.force)
|
|
1790
1907
|
argv.push('--force');
|
|
1791
|
-
if (opts.branch !== undefined)
|
|
1792
|
-
argv.push(opts.resetBranch ? '-B' : '-b', opts.branch);
|
|
1908
|
+
if (opts.branch !== undefined) {
|
|
1909
|
+
argv.push(opts.resetBranch ? '-B' : '-b', positional('checkout', 'branch', opts.branch));
|
|
1910
|
+
}
|
|
1793
1911
|
argv.push(positional('checkout', 'ref', ref));
|
|
1794
1912
|
return { argv, absent: NONE, parse: nothing };
|
|
1795
1913
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@osdlc/typed-git",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
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
5
|
"license": "MIT OR Apache-2.0",
|
|
6
6
|
"author": "sksizer",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
],
|
|
53
53
|
"dependencies": {
|
|
54
54
|
"hosted-git-info": "^10.1.1",
|
|
55
|
-
"@osdlc/command-seam": "^0.
|
|
55
|
+
"@osdlc/command-seam": "^0.14.0",
|
|
56
56
|
"@osdlc/result": "^0.1.0"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|