@osdlc/typed-git 0.8.2 → 0.11.1

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/dist/verbs.d.ts CHANGED
@@ -13,6 +13,7 @@
13
13
  * `GitVerb` and `gate` are internal: the package entries do not export them.
14
14
  */
15
15
  import { type CommandResult } from '@osdlc/command-seam';
16
+ import type { GitFeature } from './features.ts';
16
17
  /**
17
18
  * One git invocation: what to run, which exits are answers, and how to read
18
19
  * what came back.
@@ -46,6 +47,20 @@ export interface GitVerb<T> {
46
47
  * so every failure names the command that ran.
47
48
  */
48
49
  parse(result: CommandResult, argv: string[]): T;
50
+ /**
51
+ * The git feature this argv needs, from the table in `./features.ts`. The
52
+ * client probes the git version (once per runner) before it runs a verb
53
+ * that sets this, and runs {@link GitVerb.fallback} or throws the
54
+ * `unsupported-git` failure when the git is too old. A verb without it
55
+ * never probes.
56
+ */
57
+ needs?: GitFeature | undefined;
58
+ /**
59
+ * The verb to run instead on a git older than `needs` requires. It is used
60
+ * only when the feature's table entry has a `fallback`, so a verb cannot
61
+ * fall back where the table says no fallback exists.
62
+ */
63
+ fallback?: GitVerb<T> | undefined;
49
64
  }
50
65
  /**
51
66
  * Turn one git result into a value or a thrown failure: a `FailureError`
@@ -111,7 +126,9 @@ export interface Worktree {
111
126
  locked: boolean;
112
127
  /**
113
128
  * The reason given to `git worktree lock --reason`, or null when none was.
114
- * Verbatim porcelain: git C-quotes a reason holding a newline or other
129
+ * On git 2.36 or later it is the reason as written, newlines and all (read
130
+ * from `worktree list --porcelain -z`). On older git it is the newline
131
+ * porcelain's text: git C-quotes a reason holding a newline or other
115
132
  * special characters, and the quotes stay.
116
133
  */
117
134
  lockReason: string | null;
@@ -152,6 +169,17 @@ export declare function splitLines(out: string): string[];
152
169
  * absence from breakage.
153
170
  */
154
171
  export declare function showAtRev(rev: string, relPath: string): GitVerb<string | null>;
172
+ /**
173
+ * A file's content at a rev (`git show <rev>:<relPath>`), and a throw when it
174
+ * is not there.
175
+ *
176
+ * The same argv as {@link showAtRev}, with `absent: []`. Use it when a missing
177
+ * file is an error: a path that is not in that tree throws the classified
178
+ * failure, as does a rev that does not resolve or a broken repository, rather
179
+ * than all three reading as `null`. It has no `soft` form, because it has no
180
+ * absence value.
181
+ */
182
+ export declare function showAtRevChecked(rev: string, relPath: string): GitVerb<string>;
155
183
  /**
156
184
  * Trimmed `git rev-parse <args>` output, for a query no other verb covers.
157
185
  *
@@ -272,9 +300,20 @@ export interface StatusEntry {
272
300
  * tree; throws outside a repository.
273
301
  */
274
302
  export declare function statusEntries(): GitVerb<StatusEntry[]>;
275
- /** Local branch shortnames matching `pattern` (all when omitted). */
303
+ /**
304
+ * Local branch names matching `pattern` (all when omitted). The name is
305
+ * `refs/heads/` stripped, never `%(refname:short)`, which answers
306
+ * `heads/<name>` when a tag shares the name.
307
+ */
276
308
  export declare function branches(pattern?: string | undefined): GitVerb<string[]>;
277
- /** `git worktree list --porcelain`, parsed. Throws outside a repository. */
309
+ /**
310
+ * `git worktree list --porcelain -z`, parsed. Throws outside a repository.
311
+ *
312
+ * `-z` (git 2.36) ends each line with NUL, so a path or lock reason holding
313
+ * a newline reads as written. On an older git the client runs the
314
+ * newline-split form instead (the `worktree list -z` row in `./features.ts`),
315
+ * which breaks on such a path and C-quotes such a reason.
316
+ */
278
317
  export declare function worktrees(): GitVerb<Worktree[]>;
279
318
  /**
280
319
  * Merge base of two revs, or null when the two histories are unrelated
@@ -513,6 +552,20 @@ export interface DiffCheckOptions {
513
552
  * code (2 on current git), so they are an answer, not a failure.
514
553
  */
515
554
  export declare function diffCheck(opts?: DiffCheckOptions): GitVerb<DiffCheckResult>;
555
+ /**
556
+ * True iff the index differs from HEAD (`git diff --cached --quiet`): is there
557
+ * anything staged to commit?
558
+ *
559
+ * A boolean carried by the exit code. `absent: [1]` — measured: nothing staged
560
+ * → 0 (`false`); something staged → 1 (`true`). Anything else throws. Outside
561
+ * a repository `git diff` exits 129, so a non-repository is a failure, not
562
+ * "nothing staged".
563
+ *
564
+ * On an unborn HEAD (no commits yet) git compares the index against the empty
565
+ * tree: an empty index is `false`, and any staged file is `true`. It does not
566
+ * throw.
567
+ */
568
+ export declare function hasStagedChanges(): GitVerb<boolean>;
516
569
  /** Options for {@link diffNameStatus}. */
517
570
  export interface DiffNameStatusOptions {
518
571
  /** `--cached` — diff the index against HEAD rather than the worktree. */
@@ -742,6 +795,39 @@ export interface AheadBehind {
742
795
  /** Commits on `base` that are not on `tip`. */
743
796
  behind: number;
744
797
  }
798
+ /** One line of `git cherry`: a commit on the head side and whether the upstream has its patch. */
799
+ export interface CherryEntry {
800
+ /** The full sha of the commit that is on the head side only. */
801
+ sha: string;
802
+ /** True for `-`: a commit on the upstream side has the same patch id. False for `+`. */
803
+ equivalent: boolean;
804
+ }
805
+ /**
806
+ * Which commits `head` has that `upstream` lacks, and for each one whether
807
+ * `upstream` carries a commit with the same patch id (`git cherry`). Oldest
808
+ * first. Merge commits are not listed.
809
+ *
810
+ * `absent: []`: an unresolvable rev exits 128 and throws. Empty output is a
811
+ * real answer (`head` has nothing `upstream` lacks), so a caller that needs at
812
+ * least one commit checks the length. A line that is not `+ <sha>` or
813
+ * `- <sha>` throws rather than reading as an entry or being skipped.
814
+ */
815
+ export declare function cherry(upstream: string, head?: string): GitVerb<CherryEntry[]>;
816
+ /** Options for {@link commitTree}. */
817
+ export interface CommitTreeOptions {
818
+ /** Parent commits, in order (`-p`). None makes a root commit. */
819
+ parents?: string[] | undefined;
820
+ /** The commit message (`-m`). */
821
+ message: string;
822
+ }
823
+ /**
824
+ * Write a commit object for `tree` and print its sha (`git commit-tree`).
825
+ *
826
+ * It writes an object and no ref, and leaves the index and working tree alone.
827
+ * git needs an author and committer identity; without one it exits 128 and
828
+ * this throws. `absent: []`, and a reply that is not a sha throws.
829
+ */
830
+ export declare function commitTree(tree: string, opts: CommitTreeOptions): GitVerb<string>;
745
831
  /**
746
832
  * How far `tip` has diverged from `base`
747
833
  * (`git rev-list --left-right --count base...tip`).
@@ -851,6 +937,16 @@ export interface CommitFlags {
851
937
  noVerify?: boolean | undefined;
852
938
  /** `--signoff` — append a `Signed-off-by` trailer. */
853
939
  signoff?: boolean | undefined;
940
+ /**
941
+ * `-- <paths…>` — commit only these paths, as `git commit <paths>` does:
942
+ * their current working-tree content is committed, and anything else
943
+ * staged stays staged and out of the commit. Each path must be known to
944
+ * git (tracked, or staged), or git refuses.
945
+ *
946
+ * An empty array throws a `TypeError`: git would read `commit --` as no
947
+ * paths and commit everything staged.
948
+ */
949
+ paths?: string[] | undefined;
854
950
  }
855
951
  /**
856
952
  * Options for {@link commit}. The message comes from exactly one source, and
@@ -985,8 +1081,19 @@ export interface ForceLease {
985
1081
  * an intended pin into the wrong check. Absence is only ever `expect: null`.
986
1082
  */
987
1083
  export declare function forceWithLeaseArg(lease: ForceLease): string;
1084
+ /** Options for {@link push}. */
1085
+ export interface PushOptions {
1086
+ /** `--force-with-lease`: `true` for the bare flag, a {@link ForceLease} to pin it. */
1087
+ forceWithLease?: boolean | ForceLease | undefined;
1088
+ /**
1089
+ * `--delete` — delete `refspec` on the remote rather than pushing to it.
1090
+ * Combines with `forceWithLease`, so a pinned lease deletes the remote ref
1091
+ * only while it still holds the expected sha.
1092
+ */
1093
+ delete?: boolean | undefined;
1094
+ }
988
1095
  /**
989
- * Push a refspec.
1096
+ * Push a refspec, or delete it on the remote with `{ delete: true }`.
990
1097
  *
991
1098
  * `forceWithLease` takes a {@link ForceLease} for the pinned form, or `true`
992
1099
  * for the bare `--force-with-lease`. `true` is the unsafe form. It trusts
@@ -994,9 +1101,7 @@ export declare function forceWithLeaseArg(lease: ForceLease): string;
994
1101
  * bring that up to date. The lease then blocks nothing, and a concurrent push
995
1102
  * is overwritten. Pin the lease whenever the expected remote sha is known.
996
1103
  */
997
- export declare function push(remote: string, refspec: string, opts?: {
998
- forceWithLease?: boolean | ForceLease | undefined;
999
- }): GitVerb<void>;
1104
+ export declare function push(remote: string, refspec: string, opts?: PushOptions): GitVerb<void>;
1000
1105
  /** Options for {@link pushPorcelain}. */
1001
1106
  export interface PushPorcelainOptions {
1002
1107
  /**
@@ -1117,12 +1222,24 @@ export declare function deleteBranch(name: string, opts?: {
1117
1222
  export declare function deleteRef(ref: string, opts: {
1118
1223
  expected: string;
1119
1224
  }): GitVerb<void>;
1120
- /** `git worktree add [--detach] [-b branch] <path> [startPoint]`. */
1121
- export declare function worktreeAdd(path: string, opts?: {
1225
+ /** Options for {@link worktreeAdd}. */
1226
+ export interface WorktreeAddOptions {
1227
+ /** `-b <branch>` — create this branch at `startPoint`; git refuses if it exists. */
1122
1228
  branch?: string | undefined;
1229
+ /**
1230
+ * `-B` rather than `-b`: create `branch`, or reset an existing one, at
1231
+ * `startPoint`. git still refuses a branch checked out in another
1232
+ * worktree. Without `branch` it throws a `TypeError`. The same shape as
1233
+ * {@link CheckoutOptions.resetBranch}.
1234
+ */
1235
+ resetBranch?: boolean | undefined;
1236
+ /** The commit the new worktree (and branch) starts at; HEAD when omitted. */
1123
1237
  startPoint?: string | undefined;
1238
+ /** `--detach` — check out `startPoint` with no branch. */
1124
1239
  detach?: boolean | undefined;
1125
- }): GitVerb<void>;
1240
+ }
1241
+ /** `git worktree add [--detach] [-b|-B branch] <path> [startPoint]`. */
1242
+ export declare function worktreeAdd(path: string, opts?: WorktreeAddOptions): GitVerb<void>;
1126
1243
  /** `git worktree remove [--force] <path>`. */
1127
1244
  export declare function worktreeRemove(path: string, opts?: {
1128
1245
  force?: boolean | undefined;
@@ -1140,6 +1257,72 @@ export declare function worktreeUnlock(path: string): GitVerb<void>;
1140
1257
  export declare function worktreePrune(): GitVerb<void>;
1141
1258
  /** `git remote add <name> <url>`. */
1142
1259
  export declare function remoteAdd(name: string, url: string): GitVerb<void>;
1260
+ /**
1261
+ * What {@link remoteSetHead} does to `refs/remotes/<remote>/HEAD`: point it
1262
+ * at `branch`, ask the remote which branch its HEAD names (`auto`), or delete
1263
+ * it. Exactly one; the types refuse a mix, and so does the verb at run time.
1264
+ */
1265
+ export type RemoteSetHeadOptions = {
1266
+ branch: string;
1267
+ auto?: undefined;
1268
+ delete?: undefined;
1269
+ } | {
1270
+ auto: true;
1271
+ branch?: undefined;
1272
+ delete?: undefined;
1273
+ } | {
1274
+ delete: true;
1275
+ branch?: undefined;
1276
+ auto?: undefined;
1277
+ };
1278
+ /**
1279
+ * `git remote set-head <remote> <branch> | --auto | --delete`: set or remove
1280
+ * the local `refs/remotes/<remote>/HEAD`, which {@link symbolicRef} reads.
1281
+ *
1282
+ * `absent: []`. A `branch` with no remote-tracking ref `<remote>/<branch>`
1283
+ * exits 1 and throws, and so does an unknown remote with `branch`. `auto` asks
1284
+ * the remote, so an unknown or unreachable one exits 128, and a remote whose
1285
+ * HEAD cannot be determined exits 1; both throw. `delete`
1286
+ * when the ref is not set exits 0 (measured on git 2.34).
1287
+ */
1288
+ export declare function remoteSetHead(remote: string, opts: RemoteSetHeadOptions): GitVerb<void>;
1289
+ /** Options for {@link remoteSetBranches}. */
1290
+ export interface RemoteSetBranchesOptions {
1291
+ /** `--add` — add to the tracked branches rather than replacing them. */
1292
+ add?: boolean | undefined;
1293
+ }
1294
+ /**
1295
+ * `git remote set-branches [--add] <remote> <branch…>`: the branches a fetch
1296
+ * of `remote` tracks, written as its `remote.<remote>.fetch` refspecs. A
1297
+ * branch may be a glob.
1298
+ *
1299
+ * An empty `branches` throws a `TypeError`: git would exit 0 and clear every
1300
+ * fetch refspec of the remote. `absent: []` — an unknown remote exits 2 and throws.
1301
+ */
1302
+ export declare function remoteSetBranches(remote: string, branches: string[], opts?: RemoteSetBranchesOptions): GitVerb<void>;
1303
+ /** Options for {@link gc}. */
1304
+ export interface GcOptions {
1305
+ /**
1306
+ * `--auto` — do nothing unless git's thresholds say housekeeping is due.
1307
+ * With git's default `gc.autoDetach=true`, the work then runs in the
1308
+ * background after this call returns. A caller about to delete or reuse the
1309
+ * repository sets `env: { GIT_CONFIG_PARAMETERS: "'gc.autoDetach=false'" }`
1310
+ * or omits `auto`.
1311
+ */
1312
+ auto?: boolean | undefined;
1313
+ /** `--aggressive` — optimize harder, at much more time. */
1314
+ aggressive?: boolean | undefined;
1315
+ /**
1316
+ * `--prune=<date>` for a date string such as `'now'` or `'2.weeks.ago'`,
1317
+ * or `--no-prune` for `false`. Omitted means git's `gc.pruneExpire`. An
1318
+ * empty string throws a `TypeError`.
1319
+ */
1320
+ prune?: string | false | undefined;
1321
+ /** `--quiet` — suppress the progress report. */
1322
+ quiet?: boolean | undefined;
1323
+ }
1324
+ /** `git gc [--auto] [--aggressive] [--prune=<date> | --no-prune] [--quiet]`. */
1325
+ export declare function gc(opts?: GcOptions): GitVerb<void>;
1143
1326
  /** How an integration attempt ended. */
1144
1327
  export type IntegrationOutcome<Extra> = ({
1145
1328
  status: 'clean';
@@ -1265,6 +1448,10 @@ export interface MergeTreeOptions {
1265
1448
  *
1266
1449
  * A name git cannot merge exits 1 exactly like a conflict, so again only
1267
1450
  * stdout separates an answer from a refusal.
1451
+ *
1452
+ * Needs git 2.38, or 2.40 with `mergeBase` (the `merge-tree` rows in
1453
+ * `./features.ts`). There is no fallback: on an older git it throws the
1454
+ * `unsupported-git` failure without running git.
1268
1455
  */
1269
1456
  export declare function mergeTree(ours: string, theirs: string, opts?: MergeTreeOptions): GitVerb<MergeTreeOutcome>;
1270
1457
  /** One `git ls-files -u` row — the same path appears once per present stage. */