type-git 0.5.0 → 0.7.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.
Files changed (42) hide show
  1. package/README.md +27 -7
  2. package/dist/adapters/bun/index.cjs +82 -13348
  3. package/dist/adapters/bun/index.d.cts +7 -1
  4. package/dist/adapters/bun/index.d.ts +7 -1
  5. package/dist/adapters/bun/index.js +49 -13275
  6. package/dist/adapters/deno/index.cjs +76 -13344
  7. package/dist/adapters/deno/index.d.cts +7 -1
  8. package/dist/adapters/deno/index.d.ts +7 -1
  9. package/dist/adapters/deno/index.js +44 -13272
  10. package/dist/adapters/node/index.cjs +5 -13617
  11. package/dist/adapters/node/index.d.cts +44 -6
  12. package/dist/adapters/node/index.d.ts +44 -6
  13. package/dist/adapters/node/index.js +8 -13580
  14. package/dist/chunk-5NI3KM5Z.js +4822 -0
  15. package/dist/chunk-IAJF67MB.js +392 -0
  16. package/dist/chunk-MFY7MGIJ.cjs +4822 -0
  17. package/dist/chunk-NBX6BNQF.cjs +5588 -0
  18. package/dist/chunk-X3F6MDXQ.cjs +392 -0
  19. package/dist/chunk-YIWTIIXH.js +5588 -0
  20. package/dist/client.d-Cs32YZX6.d.ts +566 -0
  21. package/dist/client.d-PRQCR2_T.d.cts +566 -0
  22. package/dist/{client-KHa1WMIH.d.cts → git.d-DrhCzWEn.d.cts} +4541 -6876
  23. package/dist/index.cjs +42 -13717
  24. package/dist/index.d.cts +3 -2
  25. package/dist/index.d.ts +3 -2
  26. package/dist/index.js +38 -13649
  27. package/dist/strict/index.cjs +2919 -0
  28. package/dist/strict/index.d.cts +134022 -0
  29. package/dist/strict/index.d.ts +1 -0
  30. package/dist/strict/index.js +2919 -0
  31. package/docs/adapters.md +168 -0
  32. package/docs/migrations/0.7.0.md +152 -0
  33. package/package.json +58 -21
  34. package/dist/adapters/bun/index.cjs.map +0 -1
  35. package/dist/adapters/bun/index.js.map +0 -1
  36. package/dist/adapters/deno/index.cjs.map +0 -1
  37. package/dist/adapters/deno/index.js.map +0 -1
  38. package/dist/adapters/node/index.cjs.map +0 -1
  39. package/dist/adapters/node/index.js.map +0 -1
  40. package/dist/client-KHa1WMIH.d.ts +0 -12041
  41. package/dist/index.cjs.map +0 -1
  42. package/dist/index.js.map +0 -1
@@ -0,0 +1,4822 @@
1
+ // src/core/types.ts
2
+ function nonEmpty(s) {
3
+ if (s === "") {
4
+ throw new GitArgumentError("Empty string is not allowed");
5
+ }
6
+ return s;
7
+ }
8
+ function isNonEmpty(s) {
9
+ return s !== "";
10
+ }
11
+ var GitError = class extends Error {
12
+ constructor(kind, message, context = {}, category = "unknown") {
13
+ super(message);
14
+ this.kind = kind;
15
+ this.context = context;
16
+ this.category = category;
17
+ this.name = "GitError";
18
+ }
19
+ /**
20
+ * Check if the error is retryable (§13.2)
21
+ *
22
+ * Network errors and some LFS errors are typically retryable.
23
+ */
24
+ isRetryable() {
25
+ return this.category === "network" || this.category === "lfs" && this.kind === "NonZeroExit";
26
+ }
27
+ /**
28
+ * Check if authentication is needed (§13.2)
29
+ */
30
+ needsAuthentication() {
31
+ return this.category === "auth";
32
+ }
33
+ };
34
+ var GitArgumentError = class extends Error {
35
+ constructor(message) {
36
+ super(message);
37
+ this.name = "GitArgumentError";
38
+ }
39
+ };
40
+
41
+ // src/internal/command-host.ts
42
+ var COMMAND_HOST = /* @__PURE__ */ Symbol.for("type-git.command-host");
43
+ function registerCommandHost(target, host) {
44
+ Object.defineProperty(target, COMMAND_HOST, { value: host });
45
+ }
46
+ function commandHostOf(target) {
47
+ if (typeof target !== "object" && typeof target !== "function" || target === null) {
48
+ return void 0;
49
+ }
50
+ const host = target[COMMAND_HOST];
51
+ return typeof host === "function" ? host() : void 0;
52
+ }
53
+
54
+ // src/parsers/index.ts
55
+ var GIT_PROGRESS_PERCENT_REGEX = /^(.+?):\s*(\d+)%\s*\((\d+)\/(\d+)\)(?:,\s*(done))?/;
56
+ var GIT_PROGRESS_SIMPLE_REGEX = /^(.+?):\s*(\d+)\/(\d+)/;
57
+ var WHITESPACE_REGEX = /\s+/;
58
+ var BYTES_RATIO_REGEX = /^(\d+)\/(\d+)$/;
59
+ var SIZE_REGEX = /^([\d.]+)\s*(B|KB|MB|GB|TB)?$/i;
60
+ var BITRATE_REGEX = /^([\d.]+)\s*(B|KB|MB|GB)\/s$/i;
61
+ var LFS_DOWNLOAD_REGEX = /downloading|filtering/i;
62
+ var LFS_UPLOAD_REGEX = /uploading/i;
63
+ var LFS_CHECKOUT_REGEX = /checking out/i;
64
+ var LFS_PROGRESS_REGEX = /(\d+)%\s*\((\d+)\/(\d+)\)(?:,\s*([\d.]+\s*(?:B|KB|MB|GB|TB)?)\s*(?:\|\s*([\d.]+\s*(?:B|KB|MB|GB)\/s))?)?/i;
65
+ function parseLines(stdout, options) {
66
+ const { keepEmpty = false, trim = true } = options ?? {};
67
+ const lines = stdout.split("\n");
68
+ return lines.map((line) => trim ? line.trim() : line).filter((line) => keepEmpty || line.length > 0);
69
+ }
70
+ function parseRecords(stdout, delimiter = "\0") {
71
+ if (!stdout) {
72
+ return [];
73
+ }
74
+ const normalized = stdout.endsWith(delimiter) ? stdout.slice(0, -delimiter.length) : stdout;
75
+ return normalized.split(delimiter);
76
+ }
77
+ function parseJson(stdout, options) {
78
+ const { ndjson = false } = options ?? {};
79
+ const trimmed = stdout.trim();
80
+ if (!trimmed) {
81
+ return ndjson ? [] : void 0;
82
+ }
83
+ if (ndjson) {
84
+ return trimmed.split("\n").filter((line) => line.trim()).map((line) => JSON.parse(line));
85
+ }
86
+ return JSON.parse(trimmed);
87
+ }
88
+ function parseKeyValue(stdout, options) {
89
+ const { separator = "=", delimiter = "\n" } = options ?? {};
90
+ const result = /* @__PURE__ */ new Map();
91
+ const lines = delimiter === "\n" ? parseLines(stdout) : parseRecords(stdout, delimiter);
92
+ for (const line of lines) {
93
+ const sepIndex = line.indexOf(separator);
94
+ if (sepIndex > 0) {
95
+ const key = line.slice(0, sepIndex);
96
+ const value = line.slice(sepIndex + separator.length);
97
+ result.set(key, value);
98
+ }
99
+ }
100
+ return result;
101
+ }
102
+ function decodePath(path) {
103
+ if (!path.startsWith('"')) {
104
+ return path;
105
+ }
106
+ if (!path.endsWith('"')) {
107
+ throw new GitError("ParseError", "Unterminated quoted path");
108
+ }
109
+ const bytes = [];
110
+ const encoder = new TextEncoder();
111
+ const escapes = {
112
+ a: "\x07",
113
+ b: "\b",
114
+ f: "\f",
115
+ n: "\n",
116
+ r: "\r",
117
+ t: " ",
118
+ v: "\v",
119
+ '"': '"',
120
+ "\\": "\\"
121
+ };
122
+ const value = path.slice(1, -1);
123
+ for (let i = 0; i < value.length; ) {
124
+ if (value[i] === "\\") {
125
+ const octal = value.slice(i + 1).match(/^[0-7]{1,3}/)?.[0];
126
+ if (octal) {
127
+ bytes.push(Number.parseInt(octal, 8));
128
+ i += octal.length + 1;
129
+ continue;
130
+ }
131
+ const escaped = escapes[value[i + 1] ?? ""];
132
+ if (escaped === void 0) {
133
+ throw new GitError("ParseError", "Invalid quoted path escape");
134
+ }
135
+ bytes.push(...encoder.encode(escaped));
136
+ i += 2;
137
+ } else {
138
+ const char = String.fromCodePoint(value.codePointAt(i));
139
+ bytes.push(...encoder.encode(char));
140
+ i += char.length;
141
+ }
142
+ }
143
+ return new TextDecoder().decode(new Uint8Array(bytes));
144
+ }
145
+ function parsePorcelainV2(stdout) {
146
+ const entries = [];
147
+ const nul = stdout.includes("\0");
148
+ const records = nul ? parseRecords(stdout) : parseLines(stdout, { trim: false });
149
+ for (let i = 0; i < records.length; i++) {
150
+ const line = records[i];
151
+ if (line.startsWith("# ")) {
152
+ continue;
153
+ }
154
+ const kind = line[0];
155
+ if (kind === "?" || kind === "!") {
156
+ if (line[1] !== " " || line.length < 3) {
157
+ throw new GitError("ParseError", "Invalid status path");
158
+ }
159
+ entries.push({
160
+ type: kind === "?" ? "untracked" : "ignored",
161
+ path: nul ? line.slice(2) : decodePath(line.slice(2))
162
+ });
163
+ continue;
164
+ }
165
+ if (kind !== "1" && kind !== "2" && kind !== "u") {
166
+ throw new GitError("ParseError", "Unknown status record");
167
+ }
168
+ const count = kind === "u" ? 10 : kind === "2" ? 9 : 8;
169
+ const parts = line.split(" ");
170
+ if (parts.length <= count || parts[1]?.length !== 2) {
171
+ throw new GitError("ParseError", "Invalid status record");
172
+ }
173
+ let path = parts.slice(count).join(" ");
174
+ let origPath;
175
+ if (kind === "2") {
176
+ if (nul) {
177
+ origPath = records[++i];
178
+ } else {
179
+ const tab = path.indexOf(" ");
180
+ if (tab < 0) {
181
+ throw new GitError("ParseError", "Missing rename source");
182
+ }
183
+ origPath = decodePath(path.slice(tab + 1));
184
+ path = path.slice(0, tab);
185
+ }
186
+ if (origPath === void 0) {
187
+ throw new GitError("ParseError", "Missing rename source");
188
+ }
189
+ }
190
+ if (!nul) {
191
+ path = decodePath(path);
192
+ }
193
+ if (kind === "u") {
194
+ entries.push({
195
+ type: "unmerged",
196
+ xy: parts[1],
197
+ sub: parts[2],
198
+ m1: parts[3],
199
+ m2: parts[4],
200
+ m3: parts[5],
201
+ mW: parts[6],
202
+ h1: parts[7],
203
+ h2: parts[8],
204
+ h3: parts[9],
205
+ path
206
+ });
207
+ } else {
208
+ entries.push({
209
+ type: "changed",
210
+ xy: parts[1],
211
+ sub: parts[2],
212
+ mH: parts[3],
213
+ mI: parts[4],
214
+ mW: parts[5],
215
+ hH: parts[6],
216
+ hI: parts[7],
217
+ path,
218
+ ...origPath !== void 0 ? { origPath } : {}
219
+ });
220
+ }
221
+ }
222
+ return entries;
223
+ }
224
+ function parseGitProgress(line) {
225
+ const match = line.match(GIT_PROGRESS_PERCENT_REGEX);
226
+ if (match) {
227
+ const percent = match[2];
228
+ const current = match[3];
229
+ const total = match[4];
230
+ if (percent === void 0 || current === void 0 || total === void 0) {
231
+ return null;
232
+ }
233
+ return {
234
+ phase: match[1]?.trim() ?? "",
235
+ percent: Number.parseInt(percent, 10),
236
+ current: Number.parseInt(current, 10),
237
+ total: Number.parseInt(total, 10),
238
+ done: match[5] === "done"
239
+ };
240
+ }
241
+ const simpleMatch = line.match(GIT_PROGRESS_SIMPLE_REGEX);
242
+ if (simpleMatch) {
243
+ const currentStr = simpleMatch[2];
244
+ const totalStr = simpleMatch[3];
245
+ if (currentStr === void 0 || totalStr === void 0) {
246
+ return null;
247
+ }
248
+ const current = Number.parseInt(currentStr, 10);
249
+ const total = Number.parseInt(totalStr, 10);
250
+ return {
251
+ phase: simpleMatch[1]?.trim() ?? "",
252
+ current,
253
+ total,
254
+ percent: total > 0 ? Math.round(current / total * 100) : null,
255
+ done: false
256
+ };
257
+ }
258
+ return null;
259
+ }
260
+ function parseLfsProgress(line) {
261
+ const parts = line.trim().split(WHITESPACE_REGEX);
262
+ if (parts.length < 4) {
263
+ return null;
264
+ }
265
+ const directionStr = parts[0];
266
+ if (directionStr !== "download" && directionStr !== "upload" && directionStr !== "checkout") {
267
+ return null;
268
+ }
269
+ const direction = directionStr;
270
+ const oid = parts[1];
271
+ const bytesStr = parts[2];
272
+ const transferredStr = parts[3];
273
+ if (oid === void 0 || bytesStr === void 0 || transferredStr === void 0) {
274
+ return null;
275
+ }
276
+ const bytesMatch = bytesStr.match(BYTES_RATIO_REGEX);
277
+ if (!bytesMatch) {
278
+ return null;
279
+ }
280
+ const bytesSoFar = bytesMatch[1];
281
+ const bytesTotal = bytesMatch[2];
282
+ if (bytesSoFar === void 0 || bytesTotal === void 0) {
283
+ return null;
284
+ }
285
+ return {
286
+ direction,
287
+ oid,
288
+ bytesSoFar: Number.parseInt(bytesSoFar, 10),
289
+ bytesTotal: Number.parseInt(bytesTotal, 10),
290
+ bytesTransferred: Number.parseInt(transferredStr, 10)
291
+ };
292
+ }
293
+ function parseSizeToBytes(sizeStr) {
294
+ const match = sizeStr.match(SIZE_REGEX);
295
+ if (!match) {
296
+ return 0;
297
+ }
298
+ const value = Number.parseFloat(match[1] ?? "0");
299
+ const unit = (match[2] || "B").toUpperCase();
300
+ const multipliers = {
301
+ B: 1,
302
+ KB: 1024,
303
+ MB: 1024 * 1024,
304
+ GB: 1024 * 1024 * 1024,
305
+ TB: 1024 * 1024 * 1024 * 1024
306
+ };
307
+ return Math.round(value * (multipliers[unit] || 1));
308
+ }
309
+ function parseBitrateToBytes(bitrateStr) {
310
+ const match = bitrateStr.match(BITRATE_REGEX);
311
+ if (!match) {
312
+ return null;
313
+ }
314
+ const value = Number.parseFloat(match[1] ?? "0");
315
+ const unit = (match[2] ?? "B").toUpperCase();
316
+ const multipliers = {
317
+ B: 1,
318
+ KB: 1024,
319
+ MB: 1024 * 1024,
320
+ GB: 1024 * 1024 * 1024
321
+ };
322
+ return Math.round(value * (multipliers[unit] || 1));
323
+ }
324
+ function parseLfsStderrProgress(line) {
325
+ let direction;
326
+ if (LFS_DOWNLOAD_REGEX.test(line)) {
327
+ direction = "download";
328
+ } else if (LFS_UPLOAD_REGEX.test(line)) {
329
+ direction = "upload";
330
+ } else if (LFS_CHECKOUT_REGEX.test(line)) {
331
+ direction = "checkout";
332
+ } else {
333
+ return null;
334
+ }
335
+ const progressMatch = line.match(LFS_PROGRESS_REGEX);
336
+ if (!progressMatch) {
337
+ return null;
338
+ }
339
+ const percentStr = progressMatch[1];
340
+ const filesCompletedStr = progressMatch[2];
341
+ const filesTotalStr = progressMatch[3];
342
+ if (percentStr === void 0 || filesCompletedStr === void 0 || filesTotalStr === void 0) {
343
+ return null;
344
+ }
345
+ const percent = Number.parseInt(percentStr, 10);
346
+ const filesCompleted = Number.parseInt(filesCompletedStr, 10);
347
+ const filesTotal = Number.parseInt(filesTotalStr, 10);
348
+ const sizeStr = progressMatch[4];
349
+ const bitrateStr = progressMatch[5];
350
+ const bytesSoFar = sizeStr ? parseSizeToBytes(sizeStr) : 0;
351
+ const bytesTotal = percent > 0 && bytesSoFar > 0 ? Math.round(bytesSoFar / percent * 100) : 0;
352
+ const bitrate = bitrateStr ? parseBitrateToBytes(bitrateStr) : null;
353
+ const done = /,\s*done\.?\s*$/i.test(line);
354
+ return {
355
+ direction,
356
+ percent,
357
+ filesCompleted,
358
+ filesTotal,
359
+ bytesSoFar,
360
+ bytesTotal,
361
+ bitrate,
362
+ done
363
+ };
364
+ }
365
+ function parseLsRemote(stdout) {
366
+ const refs = [];
367
+ const lines = parseLines(stdout);
368
+ for (const line of lines) {
369
+ const [hash, name] = line.split(" ");
370
+ if (hash && name) {
371
+ refs.push({ hash, name });
372
+ }
373
+ }
374
+ return refs;
375
+ }
376
+ var LS_TREE_REGEX = /^(\d+)\s+(blob|tree|commit)\s+([a-f0-9]+)\t([\s\S]+)$/;
377
+ var LS_TREE_LONG_REGEX = /^(\d+)\s+(blob|tree|commit)\s+([a-f0-9]+)\s+(-|\d+)\t([\s\S]+)$/;
378
+ function parseLsTree(stdout, opts) {
379
+ const nul = stdout.includes("\0");
380
+ const records = nul ? parseRecords(stdout) : parseLines(stdout, { trim: false });
381
+ if (opts?.nameOnly) {
382
+ return records.map((path) => nul ? path : decodePath(path));
383
+ }
384
+ if (opts?.objectOnly) {
385
+ return records;
386
+ }
387
+ return records.map((line) => {
388
+ const match = line.match(opts?.long ? LS_TREE_LONG_REGEX : LS_TREE_REGEX);
389
+ if (!match) {
390
+ throw new GitError("ParseError", "Invalid ls-tree record", { stdout: line });
391
+ }
392
+ const path = match[opts?.long ? 5 : 4];
393
+ const size = opts?.long && match[4] !== "-" ? Number(match[4]) : void 0;
394
+ if (size !== void 0 && !Number.isSafeInteger(size)) {
395
+ throw new GitError("ParseError", "Invalid tree object size");
396
+ }
397
+ return {
398
+ mode: match[1],
399
+ type: match[2],
400
+ hash: match[3],
401
+ path: nul ? path : decodePath(path),
402
+ ...size !== void 0 ? { size } : {}
403
+ };
404
+ });
405
+ }
406
+ var GIT_LOG_FORMAT = "%H%x00%h%x00%P%x00%an%x00%ae%x00%at%x00%cn%x00%ce%x00%ct%x00%s%x00%b";
407
+ function parseGitLog(stdout) {
408
+ if (!stdout) {
409
+ return [];
410
+ }
411
+ const fields = parseRecords(stdout);
412
+ if (fields.length % 11 !== 0) {
413
+ throw new GitError("ParseError", "Invalid git log field count");
414
+ }
415
+ const commits = [];
416
+ for (let i = 0; i < fields.length; i += 11) {
417
+ const authorTimestamp = Number(fields[i + 5]);
418
+ const committerTimestamp = Number(fields[i + 8]);
419
+ if (!(fields[i] && Number.isSafeInteger(authorTimestamp) && Number.isSafeInteger(committerTimestamp))) {
420
+ throw new GitError("ParseError", "Invalid git log metadata");
421
+ }
422
+ commits.push({
423
+ hash: fields[i],
424
+ abbrevHash: fields[i + 1],
425
+ parents: fields[i + 2]?.split(" ").filter(Boolean) ?? [],
426
+ authorName: fields[i + 3],
427
+ authorEmail: fields[i + 4],
428
+ authorTimestamp,
429
+ committerName: fields[i + 6],
430
+ committerEmail: fields[i + 7],
431
+ committerTimestamp,
432
+ subject: fields[i + 9],
433
+ body: fields[i + 10]
434
+ });
435
+ }
436
+ return commits;
437
+ }
438
+ function parseWorktreeList(stdout) {
439
+ const worktrees = [];
440
+ const lines = parseLines(stdout, { keepEmpty: true, trim: false });
441
+ let current = null;
442
+ for (const line of lines) {
443
+ if (line.startsWith("worktree ")) {
444
+ if (current?.path && current.head) {
445
+ worktrees.push({
446
+ path: current.path,
447
+ head: current.head,
448
+ branch: current.branch,
449
+ locked: current.locked ?? false,
450
+ prunable: current.prunable ?? false
451
+ });
452
+ }
453
+ current = {
454
+ path: decodePath(line.slice("worktree ".length)),
455
+ locked: false,
456
+ prunable: false
457
+ };
458
+ } else if (line.startsWith("HEAD ") && current) {
459
+ current.head = line.slice("HEAD ".length);
460
+ } else if (line.startsWith("branch ") && current) {
461
+ current.branch = line.slice("branch ".length);
462
+ } else if (line.startsWith("detached") && current) {
463
+ } else if (line.startsWith("locked") && current) {
464
+ current.locked = true;
465
+ } else if (line.startsWith("prunable") && current) {
466
+ current.prunable = true;
467
+ } else if (line === "" && current && current.path && current.head) {
468
+ worktrees.push({
469
+ path: current.path,
470
+ head: current.head,
471
+ branch: current.branch,
472
+ locked: current.locked ?? false,
473
+ prunable: current.prunable ?? false
474
+ });
475
+ current = null;
476
+ }
477
+ }
478
+ if (current?.path && current.head) {
479
+ worktrees.push({
480
+ path: current.path,
481
+ head: current.head,
482
+ branch: current.branch,
483
+ locked: current.locked ?? false,
484
+ prunable: current.prunable ?? false
485
+ });
486
+ }
487
+ return worktrees;
488
+ }
489
+ var ERROR_PATTERNS = [
490
+ // Auth errors
491
+ { pattern: /fatal:\s*Authentication failed/i, category: "auth" },
492
+ { pattern: /fatal:.*could not read Username/i, category: "auth" },
493
+ { pattern: /Permission denied \(publickey\)/i, category: "auth" },
494
+ { pattern: /HTTP\s+401/i, category: "auth" },
495
+ // Network errors
496
+ { pattern: /fatal:\s*Could not resolve host/i, category: "network" },
497
+ { pattern: /fatal:\s*unable to access.*Connection timed out/i, category: "network" },
498
+ { pattern: /fatal:\s*unable to access.*Connection refused/i, category: "network" },
499
+ { pattern: /fatal:\s*Could not read from remote repository/i, category: "network" },
500
+ // Conflict errors
501
+ { pattern: /CONFLICT \(content\)/i, category: "conflict" },
502
+ { pattern: /Automatic merge failed/i, category: "conflict" },
503
+ { pattern: /error:\s*you need to resolve your current index first/i, category: "conflict" },
504
+ // LFS errors
505
+ { pattern: /LFS:.*507 Insufficient Storage/i, category: "lfs" },
506
+ { pattern: /batch response:.*error/i, category: "lfs" },
507
+ { pattern: /smudge filter lfs failed/i, category: "lfs" },
508
+ // Permission errors
509
+ { pattern: /error:\s*cannot lock ref/i, category: "permission" },
510
+ { pattern: /fatal:\s*Unable to create.*Permission denied/i, category: "permission" },
511
+ { pattern: /error:\s*unable to unlink.*Permission denied/i, category: "permission" },
512
+ // Corruption errors
513
+ { pattern: /fatal:\s*bad object/i, category: "corruption" },
514
+ { pattern: /fatal:\s*loose object.*is corrupt/i, category: "corruption" },
515
+ { pattern: /error:\s*object file.*is empty/i, category: "corruption" }
516
+ ];
517
+ function detectErrorCategory(stderr) {
518
+ for (const { pattern, category } of ERROR_PATTERNS) {
519
+ if (pattern.test(stderr)) {
520
+ return category;
521
+ }
522
+ }
523
+ return "unknown";
524
+ }
525
+
526
+ // src/core/env.ts
527
+ var DEFAULT_ENV_ALLOWLIST = [
528
+ // Executable resolution
529
+ "PATH",
530
+ "PATHEXT",
531
+ // User home / identity
532
+ "HOME",
533
+ "USER",
534
+ "LOGNAME",
535
+ // Locale and time
536
+ "LANG",
537
+ "LANGUAGE",
538
+ "LC_ALL",
539
+ "LC_CTYPE",
540
+ "LC_MESSAGES",
541
+ "LC_NUMERIC",
542
+ "LC_TIME",
543
+ "LC_COLLATE",
544
+ "LC_MONETARY",
545
+ "TZ",
546
+ // Temporary directories
547
+ "TMPDIR",
548
+ "TMP",
549
+ "TEMP",
550
+ // Terminal
551
+ "TERM",
552
+ "COLORTERM",
553
+ // SSH agent (required for Git-over-SSH authentication)
554
+ "SSH_AUTH_SOCK",
555
+ "SSH_AGENT_PID",
556
+ // Git transport and TLS configuration that holds data, commonly required for fetch/push to
557
+ // keep working under the default allowlist. Variables that name a program Git runs
558
+ // (GIT_SSH, GIT_SSH_COMMAND, GIT_ASKPASS, SSH_ASKPASS, GIT_PROXY_COMMAND, …) are
559
+ // intentionally NOT inherited by default: whoever controls the parent environment would
560
+ // otherwise choose a command for every fetch or push. Opt into those explicitly via
561
+ // `inheritEnv` or pass them through `env` when needed.
562
+ "GIT_SSH_VARIANT",
563
+ "GIT_SSL_CAINFO",
564
+ "GIT_SSL_CAPATH",
565
+ "GIT_TERMINAL_PROMPT",
566
+ "GIT_CONFIG_NOSYSTEM",
567
+ // HTTP(S) proxy configuration (required for Git network operations behind a proxy)
568
+ "HTTP_PROXY",
569
+ "HTTPS_PROXY",
570
+ "http_proxy",
571
+ "https_proxy",
572
+ "ALL_PROXY",
573
+ "all_proxy",
574
+ "NO_PROXY",
575
+ "no_proxy",
576
+ // Windows essentials
577
+ "USERPROFILE",
578
+ "HOMEDRIVE",
579
+ "HOMEPATH",
580
+ "APPDATA",
581
+ "LOCALAPPDATA",
582
+ "PROGRAMDATA",
583
+ "ALLUSERSPROFILE",
584
+ "PROGRAMFILES",
585
+ "PROGRAMFILES(X86)",
586
+ "PROGRAMW6432",
587
+ "PUBLIC",
588
+ "SYSTEMROOT",
589
+ "SYSTEMDRIVE",
590
+ "WINDIR",
591
+ "COMSPEC",
592
+ "COMPUTERNAME",
593
+ "USERDOMAIN",
594
+ "NUMBER_OF_PROCESSORS",
595
+ "PROCESSOR_ARCHITECTURE"
596
+ ];
597
+ function pickEnv(parentEnv, predicate) {
598
+ const result = {};
599
+ for (const [key, value] of Object.entries(parentEnv)) {
600
+ if (value !== void 0 && predicate(key)) {
601
+ result[key] = value;
602
+ }
603
+ }
604
+ return result;
605
+ }
606
+ function buildAllowlist(inheritEnv) {
607
+ const allow = new Set(inheritEnv === false ? [] : DEFAULT_ENV_ALLOWLIST);
608
+ if (Array.isArray(inheritEnv)) {
609
+ for (const name of inheritEnv) {
610
+ allow.add(name);
611
+ }
612
+ return { allow, remove: void 0 };
613
+ }
614
+ if (inheritEnv === false) {
615
+ return { allow, remove: void 0 };
616
+ }
617
+ for (const name of inheritEnv.add ?? []) {
618
+ allow.add(name);
619
+ }
620
+ const hasRemove = inheritEnv.remove !== void 0 && inheritEnv.remove.length > 0;
621
+ const remove = hasRemove ? new Set(inheritEnv.remove) : void 0;
622
+ return { allow, remove };
623
+ }
624
+ function makeNameMatcher(names, isWindows) {
625
+ if (!isWindows) {
626
+ return (name) => names.has(name);
627
+ }
628
+ const lower = new Set([...names].map((name) => name.toLowerCase()));
629
+ return (name) => lower.has(name.toLowerCase());
630
+ }
631
+ function resolveInheritedEnv(parentEnv, inheritEnv, platform = "") {
632
+ if (inheritEnv === true) {
633
+ return pickEnv(parentEnv, () => true);
634
+ }
635
+ if (typeof inheritEnv === "function") {
636
+ return pickEnv(parentEnv, inheritEnv);
637
+ }
638
+ const { allow, remove } = buildAllowlist(inheritEnv ?? []);
639
+ const isWindows = platform === "win32";
640
+ const isAllowed = makeNameMatcher(allow, isWindows);
641
+ const isRemoved = remove ? makeNameMatcher(remove, isWindows) : () => false;
642
+ return pickEnv(parentEnv, (name) => isAllowed(name) && !isRemoved(name));
643
+ }
644
+
645
+ // src/constraints/ascii.ts
646
+ var ASCII_UPPERCASE = /[A-Z]/g;
647
+ function asciiLower(value) {
648
+ return value.replace(ASCII_UPPERCASE, (character) => character.toLowerCase());
649
+ }
650
+
651
+ // src/constraints/blame-line-range.ts
652
+ function validBlameLineRange(value) {
653
+ if (typeof value !== "string") {
654
+ return false;
655
+ }
656
+ const prefix = /^[ \t\r\n\v\f]*([+-]?)([0-9]+)/;
657
+ const start = prefix.exec(value);
658
+ if (start && (start[1] === "-" || !/[1-9]/.test(start[2]))) {
659
+ return false;
660
+ }
661
+ const rest = start ? value.slice(start[0].length) : value;
662
+ if (!rest.startsWith(",")) {
663
+ return true;
664
+ }
665
+ const end = rest.slice(1);
666
+ const relative = end.startsWith("+") || end.startsWith("-");
667
+ const parsed = prefix.exec(relative ? end.slice(1) : end);
668
+ return !parsed || /[1-9]/.test(parsed[2]) && (relative || parsed[1] !== "-");
669
+ }
670
+
671
+ // src/constraints/compound-decimals.generated.ts
672
+ var COMPOUND_DECIMALS = {
673
+ "shortlog-wrap": {
674
+ kind: "tuple",
675
+ separator: ",",
676
+ decimal: {
677
+ kind: "decimal",
678
+ longBits: 64,
679
+ bits: 32,
680
+ signed: true,
681
+ unsignedLong: true,
682
+ conversion: "checked"
683
+ },
684
+ defaults: [76, 6, 9],
685
+ nonzeroGreaterThan: {
686
+ index: 0,
687
+ others: [1, 2]
688
+ },
689
+ source: "builtin/shortlog.c:parse_uint/parse_wrap_args"
690
+ },
691
+ "show-branch-reflog": {
692
+ kind: "prefix",
693
+ separator: ",",
694
+ decimal: {
695
+ kind: "decimal",
696
+ longBits: 64,
697
+ bits: 32,
698
+ signed: true,
699
+ unsignedLong: true,
700
+ conversion: "cast",
701
+ empty: true
702
+ },
703
+ source: "builtin/show-branch.c:parse_reflog_param"
704
+ },
705
+ "diff-stat": {
706
+ kind: "tuple",
707
+ separator: ",",
708
+ decimal: {
709
+ kind: "decimal",
710
+ longBits: 64,
711
+ bits: 32,
712
+ signed: true,
713
+ unsignedLong: true,
714
+ conversion: "cast",
715
+ empty: true
716
+ },
717
+ defaults: [0, 0, 0],
718
+ nonzeroGreaterThan: {
719
+ index: 0,
720
+ others: []
721
+ },
722
+ source: "Git2.25.1/2.55.0 diff.c:diff_opt_stat stat branch; at most3strtoul(base10) fields, empty fields accepted. Defaults here serve acceptance only; omitted native values retain previous state and rendering remains native. No field-order relation."
723
+ },
724
+ "pack-objects-index-version": {
725
+ kind: "index-version",
726
+ separator: ",",
727
+ decimal: {
728
+ kind: "decimal",
729
+ longBits: 64,
730
+ bits: 32,
731
+ signed: false,
732
+ unsignedLong: true,
733
+ conversion: "cast",
734
+ empty: true
735
+ },
736
+ emptyOffset: false,
737
+ source: "Git 2.25.1/2.55.0 builtin/pack-objects.c:option_parse_index_version; pack.h:pack_idx_option uint32_t fields; decimal strtoul then version<=2, optional base0 strtoul then off32 high-bit clear; errno ignored. A comma requires a nonempty offset."
738
+ },
739
+ "index-pack-index-version": {
740
+ kind: "index-version",
741
+ separator: ",",
742
+ decimal: {
743
+ kind: "decimal",
744
+ longBits: 64,
745
+ bits: 32,
746
+ signed: false,
747
+ unsignedLong: true,
748
+ conversion: "cast",
749
+ empty: true
750
+ },
751
+ emptyOffset: true,
752
+ source: "Git 2.25.1/2.55.0 builtin/index-pack.c:cmd_index_pack --index-version; pack.h:pack_idx_option uint32_t fields; decimal strtoul then version<=2, optional base0 strtoul then off32 high-bit clear; errno ignored. A trailing comma parses an empty offset as zero."
753
+ }
754
+ };
755
+
756
+ // src/constraints/git-integer.ts
757
+ function legacyBareUnit(text, parser, negativeMagnitudes) {
758
+ return !parser.signed && negativeMagnitudes && /^[kKmMgG]$/.test(text);
759
+ }
760
+ function parseGitInteger(value, parser, binaryIntegers = true, negativeMagnitudes = false) {
761
+ if (parser.numberRepresentation !== "argv" && typeof value === "number" && !Number.isSafeInteger(value)) {
762
+ return void 0;
763
+ }
764
+ if (typeof value !== "string" && typeof value !== "number" && typeof value !== "bigint") {
765
+ return void 0;
766
+ }
767
+ const text = String(value);
768
+ if (legacyBareUnit(text, parser, negativeMagnitudes)) {
769
+ return 0n;
770
+ }
771
+ const match = /^[ \t\r\n\v\f]*([+-]?)(0[xX][\da-fA-F]+|0[bB][01]+|0[0-7]*|[1-9]\d*)([kKmMgG]?)$/.exec(text);
772
+ if (!match || match[0] !== text || !parser.signed && match[1] === "-" && !negativeMagnitudes) {
773
+ return void 0;
774
+ }
775
+ const digits = match[2];
776
+ if (!binaryIntegers && /^0[bB]/.test(digits)) {
777
+ return void 0;
778
+ }
779
+ const magnitude = /^0[xXbB]/.test(digits) ? BigInt(digits) : digits.startsWith("0") ? BigInt(`0o${digits}`) : BigInt(digits);
780
+ const power = { "": 0n, k: 10n, m: 20n, g: 30n }[(match[3] ?? "").toLowerCase()];
781
+ if (!parser.signed && magnitude > 18446744073709551615n) {
782
+ return void 0;
783
+ }
784
+ const signed = match[1] === "-" ? -magnitude : magnitude;
785
+ const base = !parser.signed && negativeMagnitudes ? BigInt.asUintN(64, signed) : signed;
786
+ const number = base * (1n << power);
787
+ const limit = 1n << BigInt(parser.bits - (parser.signed ? 1 : 0));
788
+ return number >= (parser.signed ? -limit : 0n) && number < limit ? number : void 0;
789
+ }
790
+ function parseLegacyGitInteger(value, parser, longBits) {
791
+ if (parser.numberRepresentation !== "argv" && typeof value === "number" && !Number.isSafeInteger(value)) {
792
+ return void 0;
793
+ }
794
+ if (!["number", "string", "bigint"].includes(typeof value)) {
795
+ return void 0;
796
+ }
797
+ const text = String(value);
798
+ const match = /^[ \t\r\n\v\f]*[+-]?[0-9]+$/.exec(text);
799
+ if (!match || match[0] !== text) {
800
+ return void 0;
801
+ }
802
+ const number = BigInt(text.trim());
803
+ const minimum = -(1n << BigInt(longBits - 1));
804
+ const maximum = (1n << BigInt(longBits - 1)) - 1n;
805
+ const clamped = number < minimum ? minimum : number > maximum ? maximum : number;
806
+ return parser.signed ? BigInt.asIntN(32, clamped) : BigInt.asUintN(32, clamped);
807
+ }
808
+ function integerState(value) {
809
+ return value >= BigInt(Number.MIN_SAFE_INTEGER) && value <= BigInt(Number.MAX_SAFE_INTEGER) ? Number(value) : value;
810
+ }
811
+
812
+ // src/constraints/git-decimal.ts
813
+ var DECIMAL_CALLBACK_PROBES = {
814
+ "unified-context": ["diff", "--no-index", "--unified=-1", "-h"],
815
+ "revision-count": ["rev-list", "--max-count=1k", "-h"],
816
+ "revision-age": ["rev-list", "--max-age=invalid", "-h"],
817
+ "strip-count": ["apply", "-p", "1k", "-h"],
818
+ "daemon-count": ["daemon", "--max-connections=1k", "-h"],
819
+ "daemon-timeout": ["daemon", "--timeout=1k", "-h"],
820
+ "daemon-init-timeout": ["daemon", "--init-timeout=1k", "-h"]
821
+ };
822
+ function decimalCallbackFamily(callback, result) {
823
+ const strict = {
824
+ "unified-context": /expects a non-negative integer/,
825
+ "revision-age": /not a number of seconds since epoch/,
826
+ "revision-count": /not an integer/,
827
+ "strip-count": /option -p expects a non-negative integer/,
828
+ "daemon-count": /invalid max-connections .*expecting an integer/,
829
+ "daemon-timeout": /invalid timeout .*expecting a non-negative integer/,
830
+ "daemon-init-timeout": /invalid init-timeout .*expecting a non-negative integer/
831
+ }[callback];
832
+ if (result.exitCode === (callback === "unified-context" ? 129 : 128) && strict.test(result.stderr)) {
833
+ return "modern";
834
+ }
835
+ if (result.exitCode === 129 && (result.stdout + result.stderr).includes("usage:") && !/error:|fatal:/.test(result.stderr)) {
836
+ return "legacy";
837
+ }
838
+ return void 0;
839
+ }
840
+ function selectedGitDecimal(parser, callbacks) {
841
+ if (!parser.nativeCallback || callbacks?.[parser.nativeCallback] !== "legacy") {
842
+ return parser;
843
+ }
844
+ const { beforeNonnegative: _before, rejectMinus: _minus, ...rest } = parser;
845
+ return parser.nativeCallback === "unified-context" ? { ...rest, signed: true } : { ...rest, conversion: "atoi", empty: true };
846
+ }
847
+ function parseGitDecimal(value, parser, previous, selectedLongBits = parser.longBits, compoundNegatedOverflow = false) {
848
+ if (value === true && parser.default) {
849
+ return { valid: true, value: parser.default === "previous" ? previous : true };
850
+ }
851
+ if (typeof value === "number" && parser.conversion !== "prefix-cast" && (parser.conversion === "atoi" ? !Number.isFinite(value) || Math.abs(value) > Number.MAX_SAFE_INTEGER : !Number.isSafeInteger(value))) {
852
+ return { valid: false };
853
+ }
854
+ if (typeof value !== "string" && typeof value !== "number" && typeof value !== "bigint") {
855
+ return { valid: false };
856
+ }
857
+ const text = String(value);
858
+ if (text.includes("\0")) {
859
+ return { valid: false };
860
+ }
861
+ if (parser.rejectMinus && text.includes("-")) {
862
+ return { valid: false };
863
+ }
864
+ const match = parser.conversion === "atoi" || parser.conversion === "prefix-cast" ? /^[ \t\r\n\v\f]*([+-]?\d+)/.exec(text) : /^[ \t\r\n\v\f]*([+-]?\d+)$/.exec(text);
865
+ if (parser.conversion !== "atoi" && parser.conversion !== "prefix-cast" && !(text === "" && parser.empty) && (!match || match[0] !== text)) {
866
+ return { valid: false };
867
+ }
868
+ let parsed = match ? BigInt(match[1]) : 0n;
869
+ if (parser.unsignedLong) {
870
+ const maximum = (1n << BigInt(selectedLongBits)) - 1n;
871
+ const magnitude = parsed < 0n ? -parsed : parsed;
872
+ parsed = magnitude > maximum ? parsed < 0n && (compoundNegatedOverflow || parser.negateUnsignedOverflow) ? 1n : maximum : BigInt.asUintN(selectedLongBits, parsed);
873
+ }
874
+ if (parser.beforeNonnegative && parsed < 0n) {
875
+ return { valid: false };
876
+ }
877
+ if (parser.conversion === "checked") {
878
+ const limit = 1n << BigInt(parser.bits - (parser.signed ? 1 : 0));
879
+ if (parsed < (parser.signed ? -limit : 0n) || parsed >= limit) {
880
+ return { valid: false };
881
+ }
882
+ } else {
883
+ if (!parser.unsignedLong) {
884
+ const longLimit = 1n << BigInt(selectedLongBits - 1);
885
+ parsed = parsed < -longLimit ? -longLimit : parsed >= longLimit ? longLimit - 1n : parsed;
886
+ }
887
+ parsed = parser.signed ? BigInt.asIntN(parser.bits, parsed) : BigInt.asUintN(parser.bits, parsed);
888
+ }
889
+ if (parser.positive && parsed <= 0n) {
890
+ return { valid: false };
891
+ }
892
+ if (parser.nonzeroMinimum && parsed !== 0n && parsed < BigInt(parser.nonzeroMinimum)) {
893
+ parsed = BigInt(parser.nonzeroMinimum);
894
+ }
895
+ if (parser.clampNegativeToZero && parsed < 0n) {
896
+ parsed = 0n;
897
+ }
898
+ return { valid: true, value: integerState(parsed) };
899
+ }
900
+
901
+ // src/constraints/compound-decimal.ts
902
+ function isCompoundDecimal(value) {
903
+ return typeof value === "string" && Object.hasOwn(COMPOUND_DECIMALS, value);
904
+ }
905
+ function validCompoundDecimal(parser, value, longBits = 64, compoundNegatedOverflow = false, binaryIntegers = true) {
906
+ const profile = COMPOUND_DECIMALS[parser];
907
+ if (profile.kind === "index-version") {
908
+ if (typeof value !== "string") {
909
+ return false;
910
+ }
911
+ const parts2 = value.split(",");
912
+ if (parts2.length > 2) {
913
+ return false;
914
+ }
915
+ const version = parseGitDecimal(
916
+ parts2[0],
917
+ profile.decimal,
918
+ void 0,
919
+ longBits,
920
+ compoundNegatedOverflow
921
+ );
922
+ if (!version.valid || typeof version.value !== "number" || version.value > 2) {
923
+ return false;
924
+ }
925
+ if (parts2.length === 1) {
926
+ return true;
927
+ }
928
+ const offset = parts2[1];
929
+ if (offset === "") {
930
+ return profile.emptyOffset;
931
+ }
932
+ const match = /^[ \t\r\n\v\f]*([+-]?)(0[xX][\da-fA-F]+|0[bB][01]+|0[0-7]*|[1-9]\d*)$/.exec(
933
+ offset
934
+ );
935
+ if (!match || match[0] !== offset || !binaryIntegers && /^0[bB]/.test(match[2])) {
936
+ return false;
937
+ }
938
+ const digits = match[2];
939
+ const magnitude = BigInt(/^0[0-7]+$/.test(digits) ? `0o${digits}` : digits);
940
+ const parsed = parseGitDecimal(
941
+ `${match[1]}${magnitude}`,
942
+ profile.decimal,
943
+ void 0,
944
+ longBits,
945
+ compoundNegatedOverflow
946
+ );
947
+ return parsed.valid && typeof parsed.value === "number" && parsed.value <= 2147483647;
948
+ }
949
+ if (value === true) {
950
+ return true;
951
+ }
952
+ if (typeof value !== "string") {
953
+ return false;
954
+ }
955
+ if (profile.kind === "prefix") {
956
+ const separator = value.indexOf(profile.separator);
957
+ return parseGitDecimal(
958
+ separator < 0 ? value : value.slice(0, separator),
959
+ profile.decimal,
960
+ void 0,
961
+ longBits,
962
+ compoundNegatedOverflow
963
+ ).valid;
964
+ }
965
+ const parts = value.split(profile.separator);
966
+ if (parts.length > profile.defaults.length) {
967
+ return false;
968
+ }
969
+ const values = [];
970
+ for (const [index, fallback] of profile.defaults.entries()) {
971
+ const part = parts[index] ?? "";
972
+ if (part === "") {
973
+ values.push(fallback);
974
+ continue;
975
+ }
976
+ const parsed = parseGitDecimal(
977
+ part,
978
+ profile.decimal,
979
+ void 0,
980
+ longBits,
981
+ compoundNegatedOverflow
982
+ );
983
+ if (!parsed.valid || typeof parsed.value !== "number") {
984
+ return false;
985
+ }
986
+ values.push(parsed.value);
987
+ }
988
+ const pivot = values[profile.nonzeroGreaterThan.index];
989
+ return pivot === 0 || profile.nonzeroGreaterThan.others.every((index) => pivot > values[index]);
990
+ }
991
+
992
+ // src/constraints/fast-import-unsigned.ts
993
+ function validFastImportUnsigned(parser, value) {
994
+ if (!["number", "string", "bigint"].includes(typeof value)) {
995
+ return false;
996
+ }
997
+ const original = String(value);
998
+ if (!/^[ \t\r\n\v\f]*\+?(?:0[xX][0-9a-fA-F]+|0[bB][01]+|0[0-7]*|[1-9][0-9]*)(?![\s\S])/.test(
999
+ original
1000
+ )) {
1001
+ return false;
1002
+ }
1003
+ if (parser === "fast-import-active-branches") {
1004
+ return true;
1005
+ }
1006
+ const text = original.replace(/^[ \t\r\n\v\f]*\+?/, "");
1007
+ const magnitude = BigInt(/^0[0-7]+$/.test(text) ? `0o${text}` : text);
1008
+ return magnitude <= (parser === "fast-import-depth" ? 8191n : 2147483647n);
1009
+ }
1010
+
1011
+ // src/constraints/boolean-callbacks.generated.ts
1012
+ var BOOLEAN_GRAMMAR = {
1013
+ true: ["true", "yes", "on"],
1014
+ false: ["", "false", "no", "off"],
1015
+ integer: {
1016
+ kind: "integer",
1017
+ signed: true,
1018
+ bits: 32
1019
+ }
1020
+ };
1021
+ var BOOLEAN_CALLBACKS = {
1022
+ "git-bool": {
1023
+ allowTrue: true,
1024
+ names: {},
1025
+ source: "submodule-config.c:parse_update_recurse; submodule.c:option_parse_recurse_submodules_worktree_updater"
1026
+ },
1027
+ "fetch-recurse": {
1028
+ allowTrue: true,
1029
+ names: {
1030
+ "on-demand": "on-demand"
1031
+ },
1032
+ source: "submodule-config.c:parse_fetch_recurse/option_fetch_parse_recurse_submodules"
1033
+ },
1034
+ "push-recurse": {
1035
+ allowTrue: false,
1036
+ names: {
1037
+ "on-demand": "on-demand",
1038
+ check: "check",
1039
+ only: "only"
1040
+ },
1041
+ source: "submodule-config.c:parse_push_recurse; builtin/push.c:option_parse_recurse_submodules",
1042
+ transitions: {
1043
+ "only-is-on-demand": {
1044
+ from: "only",
1045
+ to: "on-demand"
1046
+ }
1047
+ }
1048
+ },
1049
+ "push-signed": {
1050
+ allowTrue: true,
1051
+ names: {
1052
+ "if-asked": "if-asked"
1053
+ },
1054
+ source: "send-pack.c:option_parse_push_signed",
1055
+ caseInsensitive: true
1056
+ },
1057
+ "pull-rebase": {
1058
+ allowTrue: true,
1059
+ names: {
1060
+ merges: "merges",
1061
+ m: "merges",
1062
+ interactive: "interactive",
1063
+ i: "interactive"
1064
+ },
1065
+ source: "rebase.c:rebase_parse_value; builtin/pull.c:parse_opt_rebase"
1066
+ },
1067
+ "log-decorate": {
1068
+ allowTrue: true,
1069
+ names: {
1070
+ short: "short",
1071
+ full: "full",
1072
+ auto: "auto"
1073
+ },
1074
+ source: "builtin/log.c:parse_decoration_style/decorate_callback; auto decoration depends on output configuration"
1075
+ },
1076
+ "fast-export-reencode": {
1077
+ allowTrue: true,
1078
+ names: {
1079
+ abort: "abort"
1080
+ },
1081
+ caseInsensitive: true,
1082
+ source: "builtin/fast-export.c:parse_opt_reencode_mode"
1083
+ },
1084
+ "untracked-files": {
1085
+ allowTrue: true,
1086
+ names: {
1087
+ normal: "normal",
1088
+ all: "all"
1089
+ },
1090
+ source: "builtin/commit.c:parse_untracked_setting_name; evaluated after parse_options by handle_untracked_files_arg; false means no, true means normal"
1091
+ },
1092
+ "diff-color-moved": {
1093
+ allowTrue: true,
1094
+ names: {
1095
+ plain: "plain",
1096
+ blocks: "blocks",
1097
+ zebra: "zebra",
1098
+ default: "default",
1099
+ "dimmed-zebra": "dimmed-zebra",
1100
+ ["dimmed_zebra"]: "dimmed-zebra"
1101
+ },
1102
+ source: "Git 2.25.1/2.55.0 diff.c:parse_color_moved/diff_opt_color_moved; git_parse_maybe_bool before exact names. Reuse selected native boolean/integer source profiles; lexical acceptance only, not configuration-dependent bare-mode state."
1103
+ }
1104
+ };
1105
+
1106
+ // src/constraints/git-boolean.ts
1107
+ function gitBoolean(value, source = "modern", binaryIntegers = true) {
1108
+ if (typeof value === "boolean") {
1109
+ return value;
1110
+ }
1111
+ if (typeof value !== "string") {
1112
+ return void 0;
1113
+ }
1114
+ const text = asciiLower(value);
1115
+ if (BOOLEAN_GRAMMAR.true.includes(text)) {
1116
+ return true;
1117
+ }
1118
+ if (BOOLEAN_GRAMMAR.false.includes(text)) {
1119
+ return false;
1120
+ }
1121
+ if (source === "legacy-units" && /^[kmgKMG]$/.test(value)) {
1122
+ return false;
1123
+ }
1124
+ const integer = parseGitInteger(value, BOOLEAN_GRAMMAR.integer, binaryIntegers);
1125
+ if (source !== "modern" && integer === -2147483648n) {
1126
+ return void 0;
1127
+ }
1128
+ return integer === void 0 ? void 0 : integer !== 0n;
1129
+ }
1130
+ function isBooleanCallback(parser) {
1131
+ return Object.hasOwn(BOOLEAN_CALLBACKS, parser);
1132
+ }
1133
+ function parseBooleanCallback(parser, value, previous, source = "modern", binaryIntegers = true, capabilities = {}) {
1134
+ const profile = BOOLEAN_CALLBACKS[parser];
1135
+ if (typeof value === "string" && profile.transitions && Object.hasOwn(profile.transitions, value)) {
1136
+ if (!(capabilities.onlyIsOnDemand ?? source !== "legacy-units")) {
1137
+ return { valid: false };
1138
+ }
1139
+ const transition = profile.transitions[value];
1140
+ return { valid: true, value: previous === transition.from ? transition.to : previous };
1141
+ }
1142
+ const boolean = gitBoolean(value, source, binaryIntegers);
1143
+ if (boolean !== void 0) {
1144
+ return { valid: !boolean || profile.allowTrue, value: boolean };
1145
+ }
1146
+ if (typeof value !== "string") {
1147
+ return { valid: false };
1148
+ }
1149
+ if ((capabilities.preserve ?? source === "legacy-units") && parser === "pull-rebase" && (value === "preserve" || value === "p")) {
1150
+ return { valid: true, value: "preserve" };
1151
+ }
1152
+ const name = profile.caseInsensitive ? asciiLower(value) : value;
1153
+ return Object.hasOwn(profile.names, name) ? { valid: true, value: profile.names[name] } : { valid: false };
1154
+ }
1155
+
1156
+ // src/constraints/string-callbacks.generated.ts
1157
+ var STRING_CALLBACKS = {
1158
+ "anonymize-map": {
1159
+ kind: "first-separator",
1160
+ separator: ":",
1161
+ allowUnseparated: true,
1162
+ source: "builtin/fast-export.c:parse_opt_anonymize_map; both sides of the first separator must be nonempty"
1163
+ },
1164
+ "fast-import-sign": {
1165
+ kind: "choice",
1166
+ exact: [
1167
+ "abort",
1168
+ "verbatim",
1169
+ "ignore",
1170
+ "warn-verbatim",
1171
+ "warn",
1172
+ "warn-strip",
1173
+ "strip",
1174
+ "abort-if-invalid",
1175
+ "strip-if-invalid",
1176
+ "sign-if-invalid"
1177
+ ],
1178
+ prefixes: ["sign-if-invalid="],
1179
+ source: "gpg-interface.c:parse_sign_mode; builtin/fast-import.c:parse_one_option; a key suffix may be empty"
1180
+ },
1181
+ "column-mode": {
1182
+ kind: "token-list",
1183
+ separators: [" ", ","],
1184
+ exact: ["always", "never", "auto", "plain", "column", "row", "dense", "nodense"],
1185
+ projection: {
1186
+ initial: "always",
1187
+ values: {
1188
+ always: "always",
1189
+ never: "never",
1190
+ auto: "auto"
1191
+ }
1192
+ },
1193
+ source: "column.c:parse_config/parse_option/parseopt_column_callback; enable projection only; auto depends on tty/pager during finalization"
1194
+ },
1195
+ "revision-date-format": {
1196
+ kind: "choice",
1197
+ exact: [
1198
+ "relative",
1199
+ "iso8601-strict",
1200
+ "iso-strict",
1201
+ "iso8601",
1202
+ "iso",
1203
+ "rfc2822",
1204
+ "rfc",
1205
+ "short",
1206
+ "default",
1207
+ "human",
1208
+ "raw",
1209
+ "unix",
1210
+ "relative-local",
1211
+ "iso8601-strict-local",
1212
+ "iso-strict-local",
1213
+ "iso8601-local",
1214
+ "iso-local",
1215
+ "rfc2822-local",
1216
+ "rfc-local",
1217
+ "short-local",
1218
+ "default-local",
1219
+ "human-local",
1220
+ "raw-local",
1221
+ "unix-local",
1222
+ "local"
1223
+ ],
1224
+ prefixes: ["format:", "format-local:", "auto:"],
1225
+ source: "date.c:parse_date_type/parse_date_format; revision.c:parse_long_opt(date). Case-sensitive mode and optional -local suffix; format requires a colon and accepts arbitrary strftime text. auto: suffix validation depends on stdout TTY/pager and remains native-owned, including empty or malformed suffixes."
1226
+ },
1227
+ "diff-output-indicator": {
1228
+ kind: "byte-character",
1229
+ emptyIsNative: true,
1230
+ source: "diff.c:diff_opt_char; nonempty argv accepts exactly one byte. Empty argv reads arg[1] beyond its terminator, so its native behavior remains delegated."
1231
+ },
1232
+ "diff-rename-score": {
1233
+ kind: "rename-score",
1234
+ parts: 1,
1235
+ source: "Git 2.25.1/2.55.0 diff.c:parse_rename_score and diff_opt_find_renames/diff_opt_find_copies; ASCII digits, optional single dot, optional terminal percent; empty/bare accepted. Only lexical acceptance, not the native stored score."
1236
+ },
1237
+ "diff-break-score": {
1238
+ kind: "rename-score",
1239
+ parts: 2,
1240
+ source: "Git 2.25.1/2.55.0 diff.c:diff_opt_break_rewrites; one or two rename-score fields separated by at most one slash; fields may be empty, bare accepted. Raw values stay unchanged."
1241
+ },
1242
+ "diff-filter-letters": {
1243
+ kind: "character-set",
1244
+ characters: "ACDMRTUXBacdmrtuxb*",
1245
+ source: "Git 2.25.1/2.55.0 diff.c:diff_status_letters/prepare_filter_bits/diff_opt_diff_filter; diff.h status constants; empty and repeated letters accepted, ASCII lowercase folds for class membership. Validate text only, not filter-state accumulation or payload selection."
1246
+ },
1247
+ "diff-color-moved-ws": {
1248
+ kind: "resetting-token-list",
1249
+ separator: ",",
1250
+ reset: "no",
1251
+ trimAscii: true,
1252
+ ordinary: ["ignore-space-change", "ignore-space-at-eol", "ignore-all-space"],
1253
+ exclusive: ["allow-indentation-change"],
1254
+ source: "Git 2.25.1/2.55.0 diff.c:parse_color_moved_ws/diff_opt_color_moved_ws; comma splitting with C whitespace trimming. no resets all bits including prior errors; indentation conflict checked after the token loop. Preserve raw argv/diagnostics; do not model rendered colors."
1255
+ },
1256
+ "diff-ws-error-highlight": {
1257
+ kind: "trailing-token-list",
1258
+ separator: ",",
1259
+ exact: ["none", "default", "all", "new", "old", "context"],
1260
+ source: "Git 2.25.1/2.55.0 diff.c:parse_one_token/parse_ws_error_highlight/diff_opt_ws_error_highlight; exact tokens without whitespace trimming; empty full value and one trailing comma accepted, leading/interior empty tokens fail immediately. Preserve raw argv; none resets rendering bits but does not recover earlier callback errors."
1261
+ },
1262
+ "diff-dirstat": {
1263
+ kind: "dirstat-params",
1264
+ separator: ",",
1265
+ allowBare: true,
1266
+ exact: ["changes", "lines", "files", "noncumulative", "cumulative"],
1267
+ source: "Git 2.25.1/2.55.0 diff.c:parse_dirstat_params/parse_dirstat_opt/diff_opt_dirstat; whole empty text/bare defaults accepted, nonempty comma fields must be exact words or ASCII digit-first decimal with at most one dot (trailing dot accepted). No trimming or range clamp. Invalid fields accumulate errors and cannot be repaired by later words; native fatal128. Keep raw argv and native cutoff arithmetic/rendering."
1268
+ }
1269
+ };
1270
+
1271
+ // src/constraints/string-callback.ts
1272
+ function isStringCallback(parser) {
1273
+ return Object.hasOwn(STRING_CALLBACKS, parser);
1274
+ }
1275
+ function parseStringCallback(parser, value) {
1276
+ const profile = STRING_CALLBACKS[parser];
1277
+ if (value === true && (profile.kind === "rename-score" || profile.kind === "dirstat-params")) {
1278
+ return { valid: true, value };
1279
+ }
1280
+ if (typeof value !== "string") {
1281
+ return { valid: false };
1282
+ }
1283
+ if (profile.kind === "dirstat-params") {
1284
+ const valid = value === "" || value.split(profile.separator).every((token) => {
1285
+ if (profile.exact.includes(token)) {
1286
+ return true;
1287
+ }
1288
+ let dot = false;
1289
+ for (let index2 = 0; index2 < token.length; index2++) {
1290
+ const code = token.charCodeAt(index2);
1291
+ if (code >= 48 && code <= 57) {
1292
+ continue;
1293
+ }
1294
+ if (code === 46 && index2 > 0 && !dot) {
1295
+ dot = true;
1296
+ continue;
1297
+ }
1298
+ return false;
1299
+ }
1300
+ return token.length > 0;
1301
+ });
1302
+ return { valid, value };
1303
+ }
1304
+ if (profile.kind === "trailing-token-list") {
1305
+ const tokens = value.split(profile.separator);
1306
+ if (tokens[tokens.length - 1] === "") {
1307
+ tokens.pop();
1308
+ }
1309
+ return { valid: tokens.every((token) => profile.exact.includes(token)), value };
1310
+ }
1311
+ if (profile.kind === "resetting-token-list") {
1312
+ let ordinary = false;
1313
+ let exclusive = false;
1314
+ let invalid = false;
1315
+ for (const raw of value.split(profile.separator)) {
1316
+ let start = 0;
1317
+ let end = raw.length;
1318
+ const whitespace = " \n\r\v\f";
1319
+ while (start < end && whitespace.includes(raw[start])) {
1320
+ start++;
1321
+ }
1322
+ while (end > start && whitespace.includes(raw[end - 1])) {
1323
+ end--;
1324
+ }
1325
+ const token = raw.slice(start, end);
1326
+ if (token === profile.reset) {
1327
+ ordinary = false;
1328
+ exclusive = false;
1329
+ invalid = false;
1330
+ } else if (profile.ordinary.includes(token)) {
1331
+ ordinary = true;
1332
+ } else if (profile.exclusive.includes(token)) {
1333
+ exclusive = true;
1334
+ } else {
1335
+ invalid = true;
1336
+ }
1337
+ }
1338
+ return { valid: !invalid && !(ordinary && exclusive), value };
1339
+ }
1340
+ if (profile.kind === "character-set") {
1341
+ return {
1342
+ valid: [...value].every((character) => profile.characters.includes(character)),
1343
+ value
1344
+ };
1345
+ }
1346
+ if (profile.kind === "rename-score") {
1347
+ const parts = value.split("/");
1348
+ const valid = parts.length <= profile.parts && parts.every((part) => {
1349
+ let dot = false;
1350
+ for (let index2 = 0; index2 < part.length; index2++) {
1351
+ const character = part[index2];
1352
+ if (character !== void 0 && character >= "0" && character <= "9") {
1353
+ continue;
1354
+ }
1355
+ if (character === "." && !dot) {
1356
+ dot = true;
1357
+ continue;
1358
+ }
1359
+ if (character === "%" && index2 === part.length - 1) {
1360
+ return true;
1361
+ }
1362
+ return false;
1363
+ }
1364
+ return true;
1365
+ });
1366
+ return { valid, value };
1367
+ }
1368
+ if (profile.kind === "byte-character") {
1369
+ return { valid: value === "" || value.length === 1 && value.charCodeAt(0) < 128, value };
1370
+ }
1371
+ if (profile.kind === "choice") {
1372
+ return {
1373
+ valid: profile.exact.includes(value) || profile.prefixes.some((prefix) => value.startsWith(prefix)),
1374
+ value
1375
+ };
1376
+ }
1377
+ if (profile.kind === "token-list") {
1378
+ let token = "";
1379
+ let projected = profile.projection.initial;
1380
+ for (const character of [...value, profile.separators[0]]) {
1381
+ if (!profile.separators.includes(character)) {
1382
+ token += character;
1383
+ continue;
1384
+ }
1385
+ if (token) {
1386
+ if (!profile.exact.includes(token)) {
1387
+ return { valid: false };
1388
+ }
1389
+ if (Object.hasOwn(profile.projection.values, token)) {
1390
+ projected = profile.projection.values[token];
1391
+ }
1392
+ token = "";
1393
+ }
1394
+ }
1395
+ return { valid: true, value: projected };
1396
+ }
1397
+ const index = value.indexOf(profile.separator);
1398
+ return {
1399
+ valid: index < 0 ? profile.allowUnseparated && value.length > 0 : index > 0 && index + profile.separator.length < value.length,
1400
+ value
1401
+ };
1402
+ }
1403
+
1404
+ // src/constraints/git-scalars.ts
1405
+ import process from "process";
1406
+
1407
+ // src/constraints/c-abi.ts
1408
+ function nativeCLongBits(platform, architecture) {
1409
+ return platform === "win32" || ["ia32", "arm", "mips", "mipsel", "ppc", "s390"].includes(architecture) ? 32 : 64;
1410
+ }
1411
+ function nativeSizeTBits(architecture) {
1412
+ return ["ia32", "arm", "mips", "mipsel", "ppc", "s390"].includes(architecture) ? 32 : 64;
1413
+ }
1414
+
1415
+ // src/constraints/git-timestamp.ts
1416
+ var TIMESTAMP_CALLBACK_PROBE = DECIMAL_CALLBACK_PROBES["revision-age"];
1417
+ var DECIMAL_TIMESTAMP = /^[ \t\r\n\v\f]*([+-]?)(\d+)$/;
1418
+ var TIMESTAMP_DEFAULT = 18446744073709551615n;
1419
+ function parseGitTimestamp(value, parser) {
1420
+ if (typeof value !== "string" && typeof value !== "number" && typeof value !== "bigint") {
1421
+ return { valid: false };
1422
+ }
1423
+ const text = String(value);
1424
+ if (text.includes("\0")) {
1425
+ return { valid: false };
1426
+ }
1427
+ if (parser.conversion === "atoi") {
1428
+ const parsed2 = parseGitDecimal(text, {
1429
+ kind: "decimal",
1430
+ conversion: "atoi",
1431
+ empty: true,
1432
+ signed: true,
1433
+ bits: 32,
1434
+ longBits: parser.longBits
1435
+ });
1436
+ return parsed2.valid ? { valid: true, value: integerState(BigInt.asUintN(64, BigInt(parsed2.value))) } : { valid: false };
1437
+ }
1438
+ const match = DECIMAL_TIMESTAMP.exec(text);
1439
+ if (!match || match[0] !== text) {
1440
+ return { valid: false };
1441
+ }
1442
+ const magnitude = BigInt(match[2]);
1443
+ if (magnitude > TIMESTAMP_DEFAULT) {
1444
+ return { valid: false };
1445
+ }
1446
+ const parsed = match[1] === "-" ? BigInt.asUintN(64, -magnitude) : magnitude;
1447
+ return { valid: true, value: integerState(parsed) };
1448
+ }
1449
+
1450
+ // src/constraints/object-filter.ts
1451
+ var RESERVED = /[\x00-\x20~`!@#$^&*()[\]{}\\;'",<>?]/;
1452
+ var HIGH_BYTE = /[^\x00-\x7f]/;
1453
+ function unsignedLong(text, longBits, binaryIntegers, negativeMagnitudes) {
1454
+ return parseGitInteger(
1455
+ text,
1456
+ { kind: "integer", signed: false, bits: longBits },
1457
+ binaryIntegers,
1458
+ negativeMagnitudes
1459
+ ) !== void 0;
1460
+ }
1461
+ function decode(text) {
1462
+ return text.replace(/%([\da-fA-F]{2})/g, (encoded, hex) => {
1463
+ const byte = Number.parseInt(hex, 16);
1464
+ return byte === 0 ? encoded : String.fromCharCode(byte);
1465
+ });
1466
+ }
1467
+ function validObjectFilter(value, allowAuto = false, longBits = 64, binaryIntegers = true, negativeMagnitudes = false, unsignedChar = true, combineEmptyComponents = true) {
1468
+ const pending = [{ text: value, auto: allowAuto }];
1469
+ while (pending.length > 0) {
1470
+ const { text, auto } = pending.pop();
1471
+ if (text === "blob:none" || auto && text === "auto" || text.startsWith("sparse:oid=")) {
1472
+ continue;
1473
+ }
1474
+ if (text.startsWith("blob:limit=") || text.startsWith("tree:")) {
1475
+ if (!unsignedLong(
1476
+ text.slice(text.startsWith("tree:") ? 5 : 11),
1477
+ longBits,
1478
+ binaryIntegers,
1479
+ negativeMagnitudes
1480
+ )) {
1481
+ return false;
1482
+ }
1483
+ } else if (text.startsWith("object:type=")) {
1484
+ if (!["commit", "tree", "blob", "tag"].includes(text.slice(12))) {
1485
+ return false;
1486
+ }
1487
+ } else if (text.startsWith("combine:")) {
1488
+ const combined = text.slice(8);
1489
+ if (combined === "") {
1490
+ return false;
1491
+ }
1492
+ for (const child of combined.split("+")) {
1493
+ if (!child) {
1494
+ if (combineEmptyComponents) {
1495
+ continue;
1496
+ }
1497
+ return false;
1498
+ }
1499
+ if (RESERVED.test(child) || !unsignedChar && HIGH_BYTE.test(child)) {
1500
+ return false;
1501
+ }
1502
+ pending.push({ text: decode(child), auto: false });
1503
+ }
1504
+ } else {
1505
+ return false;
1506
+ }
1507
+ }
1508
+ return true;
1509
+ }
1510
+ function objectFilterUsesBinary(value) {
1511
+ const pending = [value];
1512
+ while (pending.length > 0) {
1513
+ const text = pending.pop();
1514
+ if (text.startsWith("blob:limit=") || text.startsWith("tree:")) {
1515
+ if (/^[ \t\r\n\v\f]*[+-]?0[bB]/.test(text.slice(text.startsWith("tree:") ? 5 : 11))) {
1516
+ return true;
1517
+ }
1518
+ } else if (text.startsWith("combine:")) {
1519
+ for (const child of text.slice(8).split("+")) {
1520
+ pending.push(decode(child));
1521
+ }
1522
+ }
1523
+ }
1524
+ return false;
1525
+ }
1526
+ function objectFilterUsesNegativeMagnitude(value) {
1527
+ const pending = [value];
1528
+ while (pending.length > 0) {
1529
+ const text = pending.pop();
1530
+ if (text.startsWith("blob:limit=") || text.startsWith("tree:")) {
1531
+ if (/^(?:[ \t\r\n\v\f]*-|[kKmMgG]$)/.test(text.slice(text.startsWith("tree:") ? 5 : 11))) {
1532
+ return true;
1533
+ }
1534
+ } else if (text.startsWith("combine:")) {
1535
+ for (const child of text.slice(8).split("+")) {
1536
+ pending.push(decode(child));
1537
+ }
1538
+ }
1539
+ }
1540
+ return false;
1541
+ }
1542
+ function objectFilterUsesHighBytes(value) {
1543
+ const pending = [value];
1544
+ while (pending.length > 0) {
1545
+ const text = pending.pop();
1546
+ if (!text.startsWith("combine:")) {
1547
+ continue;
1548
+ }
1549
+ for (const child of text.slice(8).split("+")) {
1550
+ if (HIGH_BYTE.test(child)) {
1551
+ return true;
1552
+ }
1553
+ pending.push(decode(child));
1554
+ }
1555
+ }
1556
+ return false;
1557
+ }
1558
+ function objectFilterUsesEmptyComponent(value) {
1559
+ const pending = [value];
1560
+ while (pending.length > 0) {
1561
+ const text = pending.pop();
1562
+ if (!text.startsWith("combine:")) {
1563
+ continue;
1564
+ }
1565
+ for (const child of text.slice(8).split("+")) {
1566
+ if (!child) {
1567
+ return true;
1568
+ }
1569
+ pending.push(decode(child));
1570
+ }
1571
+ }
1572
+ return false;
1573
+ }
1574
+ var OBJECT_FILTER_EMPTY_PROBE = ["clone", "--filter=combine:blob:none+", "-h"];
1575
+ function objectFilterCombineEmptyComponents(result) {
1576
+ if (result.exitCode === 128 && result.stderr.includes("invalid filter-spec 'blob:none+'")) {
1577
+ return false;
1578
+ }
1579
+ if (result.exitCode === 129 && (result.stdout + result.stderr).includes("usage:") && !/error:|fatal:/.test(result.stderr)) {
1580
+ return true;
1581
+ }
1582
+ return void 0;
1583
+ }
1584
+ var OBJECT_FILTER_CHAR_PROBE = ["clone", "--filter=combine:sparse:oid=\xE9", "-h"];
1585
+ function objectFilterUnsignedChar(result) {
1586
+ if (result.exitCode === 128 && result.stderr.includes("must escape char in sub-filter-spec")) {
1587
+ return false;
1588
+ }
1589
+ if (result.exitCode === 129 && (result.stdout + result.stderr).includes("usage:") && !/error:|fatal:/.test(result.stderr)) {
1590
+ return true;
1591
+ }
1592
+ return void 0;
1593
+ }
1594
+
1595
+ // src/constraints/git-scalars.ts
1596
+ var PYTHON_INTEGER_DEFERRED = /* @__PURE__ */ Symbol("python-integer-deferred");
1597
+ function pythonInteger(value) {
1598
+ if (!["string", "number", "bigint"].includes(typeof value)) {
1599
+ return void 0;
1600
+ }
1601
+ const original = String(value);
1602
+ if (original.includes("\0")) {
1603
+ return void 0;
1604
+ }
1605
+ if ([...original].some((character) => character.charCodeAt(0) > 127)) {
1606
+ return PYTHON_INTEGER_DEFERRED;
1607
+ }
1608
+ let radix = 10;
1609
+ let text = original;
1610
+ if (/^0x/i.test(text)) {
1611
+ radix = 16;
1612
+ } else if (/^0b/i.test(text)) {
1613
+ radix = 2;
1614
+ text = text.slice(2) || "0";
1615
+ } else if (text.startsWith("0")) {
1616
+ radix = 8;
1617
+ }
1618
+ text = text.replace(/^[ \t\r\n\v\f]+|[ \t\r\n\v\f]+$/g, "");
1619
+ const negative = text.startsWith("-");
1620
+ if (/^[+-]/.test(text)) {
1621
+ text = text.slice(1);
1622
+ }
1623
+ const prefix = radix === 16 ? /^0x/i : radix === 8 ? /^0o/i : /^0b/i;
1624
+ if (radix !== 10 && prefix.test(text)) {
1625
+ text = text.slice(2).replace(/^_/, "");
1626
+ }
1627
+ const digit = radix === 16 ? "[0-9a-fA-F]" : radix === 8 ? "[0-7]" : radix === 2 ? "[01]" : "[0-9]";
1628
+ if (!new RegExp(`^${digit}(?:_?${digit})*$`).test(text)) {
1629
+ return void 0;
1630
+ }
1631
+ const digits = text.replaceAll("_", "");
1632
+ const parsed = BigInt(
1633
+ (radix === 16 ? "0x" : radix === 8 ? "0o" : radix === 2 ? "0b" : "") + digits
1634
+ );
1635
+ return negative ? -parsed : parsed;
1636
+ }
1637
+ function validInitialDepth(value, conversionBits = 64) {
1638
+ const match = /^[ \t\r\n\v\f]*([+-]?\d+)/.exec(String(value));
1639
+ if (!match) {
1640
+ return false;
1641
+ }
1642
+ const parsed = BigInt(match[1]);
1643
+ const minimum = -(1n << BigInt(conversionBits - 1));
1644
+ const maximum = (1n << BigInt(conversionBits - 1)) - 1n;
1645
+ const clamped = parsed < minimum ? minimum : parsed > maximum ? maximum : parsed;
1646
+ return BigInt.asIntN(32, clamped) > 0n;
1647
+ }
1648
+ function parseGitScalar(parser, value, previous, cLongBits = nativeCLongBits(process.platform, process.arch), sizeTBits = nativeSizeTBits(process.arch), binaryIntegers = true, integerProfile, negativeMagnitudes = false, decimalCallbacks, unsignedChar = true, booleanSource = "modern", booleanBinaryIntegers = true, booleanCapabilities, compoundNegatedOverflow = false, depthAtoiBits = 64, combineEmptyComponents = true) {
1649
+ if (typeof parser === "object" && parser.kind === "timestamp") {
1650
+ return parseGitTimestamp(value, {
1651
+ ...parser,
1652
+ longBits: cLongBits,
1653
+ conversion: parser.nativeCallback === "revision-age" && decimalCallbacks?.["revision-age"] === "legacy" ? "atoi" : parser.conversion
1654
+ });
1655
+ }
1656
+ if (typeof parser === "object" && parser.kind === "decimal") {
1657
+ return parseGitDecimal(
1658
+ value,
1659
+ selectedGitDecimal(parser, decimalCallbacks),
1660
+ previous,
1661
+ cLongBits,
1662
+ compoundNegatedOverflow
1663
+ );
1664
+ }
1665
+ if (typeof parser === "object") {
1666
+ const bits = parser.nativeWidth === "long" ? cLongBits : parser.nativeWidth === "size_t" ? sizeTBits : parser.bits;
1667
+ const parsed = (integerProfile ?? parser.integerProfile) === "decimal-cast" && parser.bits === 32 && !parser.nativeWidth ? parseLegacyGitInteger(value, parser, cLongBits) : parseGitInteger(
1668
+ value,
1669
+ { ...parser, bits },
1670
+ binaryIntegers,
1671
+ parser.negativeMagnitudes === false ? false : negativeMagnitudes || parser.negativeMagnitudes === true
1672
+ );
1673
+ return parsed === void 0 ? { valid: false } : { valid: true, value: integerState(parsed) };
1674
+ }
1675
+ if (isBooleanCallback(parser)) {
1676
+ return parseBooleanCallback(
1677
+ parser,
1678
+ value,
1679
+ previous,
1680
+ booleanSource,
1681
+ booleanBinaryIntegers,
1682
+ booleanCapabilities
1683
+ );
1684
+ }
1685
+ if (parser === "fast-import-active-branches" || parser === "fast-import-depth" || parser === "fast-import-cat-blob-fd") {
1686
+ return { valid: validFastImportUnsigned(parser, value), value };
1687
+ }
1688
+ if (parser === "perl-int" || parser === "perl-int-gnu") {
1689
+ if (value === true || parser === "perl-int-gnu" && value === "") {
1690
+ return { valid: true, value: 0 };
1691
+ }
1692
+ return {
1693
+ valid: ["number", "string", "bigint"].includes(typeof value) && /^[-+]?_*[0-9][0-9_]*\n?(?![\s\S])/.test(String(value)),
1694
+ value
1695
+ };
1696
+ }
1697
+ if (parser === "python-int") {
1698
+ const parsed = pythonInteger(value);
1699
+ return { valid: parsed !== void 0, value: parsed };
1700
+ }
1701
+ if (parser === "depth-initial") {
1702
+ return { valid: validInitialDepth(value, depthAtoiBits), value };
1703
+ }
1704
+ if (parser === "object-filter" || parser === "object-filter-auto") {
1705
+ return {
1706
+ valid: value === void 0 || typeof value === "string" && validObjectFilter(
1707
+ value,
1708
+ parser === "object-filter-auto",
1709
+ cLongBits,
1710
+ binaryIntegers,
1711
+ negativeMagnitudes,
1712
+ unsignedChar,
1713
+ combineEmptyComponents
1714
+ ),
1715
+ value
1716
+ };
1717
+ }
1718
+ if (parser === "blame-line-range") {
1719
+ return { valid: validBlameLineRange(value), value };
1720
+ }
1721
+ if (isStringCallback(parser)) {
1722
+ return parseStringCallback(parser, value);
1723
+ }
1724
+ if (parser === "shortlog-group") {
1725
+ return {
1726
+ valid: typeof value === "string" && (["author", "committer"].includes(asciiLower(value)) || value.startsWith("trailer:") || value.startsWith("format:") || value.includes("%")),
1727
+ value
1728
+ };
1729
+ }
1730
+ if (isCompoundDecimal(parser)) {
1731
+ return {
1732
+ valid: validCompoundDecimal(
1733
+ parser,
1734
+ value,
1735
+ cLongBits,
1736
+ compoundNegatedOverflow,
1737
+ binaryIntegers
1738
+ ),
1739
+ value
1740
+ };
1741
+ }
1742
+ if (parser === "rev-list-missing") {
1743
+ return {
1744
+ valid: typeof value === "string",
1745
+ value: ["error", "allow-any", "print", "print-info", "allow-promisor"].includes(String(value)) ? value : previous
1746
+ };
1747
+ }
1748
+ if (parser === "abbrev") {
1749
+ if (value === true) {
1750
+ return { valid: true, value };
1751
+ }
1752
+ if (typeof value !== "number" || !Number.isSafeInteger(value)) {
1753
+ return { valid: false };
1754
+ }
1755
+ const converted = (cLongBits === 32 ? Math.min(2147483647, Math.max(-2147483648, value)) : value) | 0;
1756
+ return { valid: true, value: converted !== 0 && converted < 4 ? 4 : converted };
1757
+ }
1758
+ if (parser === "mainline") {
1759
+ const converted = typeof value === "number" && Number.isSafeInteger(value) ? cLongBits === 32 ? Math.min(2147483647, Math.max(-2147483648, value)) : value : 0;
1760
+ const mainline = converted | 0;
1761
+ return { valid: mainline > 0, value: mainline };
1762
+ }
1763
+ if (parser === "unsigned-size") {
1764
+ return {
1765
+ valid: typeof value === "number" && Number.isSafeInteger(value) && value >= 0 && (sizeTBits === 64 || value <= 4294967295),
1766
+ value
1767
+ };
1768
+ }
1769
+ if (parser === "revision-count" || parser === "unsigned-int") {
1770
+ return {
1771
+ valid: typeof value === "number" && Number.isInteger(value) && value >= (parser === "unsigned-int" ? 0 : -2147483648) && value <= (parser === "unsigned-int" ? 4294967295 : 2147483647),
1772
+ value
1773
+ };
1774
+ }
1775
+ if (parser === "config-type") {
1776
+ if (value === void 0) {
1777
+ return { valid: true, value };
1778
+ }
1779
+ return {
1780
+ valid: ["bool", "int", "bool-or-int", "bool-or-str", "path", "expiry-date", "color"].includes(
1781
+ String(value)
1782
+ ) && (previous === void 0 || previous === value),
1783
+ value
1784
+ };
1785
+ }
1786
+ const boolean = gitBoolean(value);
1787
+ return boolean === void 0 ? { valid: false } : { valid: true, value: boolean };
1788
+ }
1789
+
1790
+ // src/constraints/numeric-callbacks.generated.ts
1791
+ var NUMERIC_CALLBACK_PARSERS = {
1792
+ abbrev: {
1793
+ kind: "decimal",
1794
+ longBits: 64,
1795
+ bits: 32,
1796
+ signed: true,
1797
+ conversion: "cast",
1798
+ nonzeroMinimum: 4,
1799
+ default: "unknown"
1800
+ },
1801
+ mainline: {
1802
+ kind: "decimal",
1803
+ longBits: 64,
1804
+ bits: 32,
1805
+ signed: true,
1806
+ conversion: "cast",
1807
+ positive: true
1808
+ },
1809
+ "revision-count": {
1810
+ kind: "decimal",
1811
+ longBits: 64,
1812
+ bits: 32,
1813
+ signed: true,
1814
+ conversion: "checked",
1815
+ nativeCallback: "revision-count"
1816
+ },
1817
+ "grep-context": {
1818
+ kind: "decimal",
1819
+ longBits: 64,
1820
+ bits: 32,
1821
+ signed: false,
1822
+ conversion: "cast",
1823
+ empty: true
1824
+ },
1825
+ "unified-context": {
1826
+ kind: "decimal",
1827
+ longBits: 64,
1828
+ bits: 32,
1829
+ signed: false,
1830
+ conversion: "cast",
1831
+ empty: true,
1832
+ beforeNonnegative: true,
1833
+ default: "previous",
1834
+ nativeCallback: "unified-context"
1835
+ },
1836
+ "diff-max-depth": {
1837
+ kind: "integer",
1838
+ signed: true,
1839
+ bits: 32
1840
+ },
1841
+ "tab-width": {
1842
+ kind: "decimal",
1843
+ longBits: 64,
1844
+ bits: 32,
1845
+ signed: true,
1846
+ conversion: "checked",
1847
+ beforeNonnegative: true
1848
+ },
1849
+ "strip-count": {
1850
+ kind: "decimal",
1851
+ longBits: 64,
1852
+ bits: 32,
1853
+ signed: true,
1854
+ conversion: "checked",
1855
+ beforeNonnegative: true,
1856
+ nativeCallback: "strip-count"
1857
+ },
1858
+ "daemon-count": {
1859
+ kind: "decimal",
1860
+ longBits: 64,
1861
+ bits: 32,
1862
+ signed: true,
1863
+ conversion: "checked",
1864
+ nativeCallback: "daemon-count",
1865
+ clampNegativeToZero: true
1866
+ },
1867
+ "daemon-timeout": {
1868
+ kind: "decimal",
1869
+ longBits: 64,
1870
+ bits: 32,
1871
+ signed: false,
1872
+ conversion: "checked",
1873
+ nativeCallback: "daemon-timeout",
1874
+ rejectMinus: true
1875
+ },
1876
+ "daemon-init-timeout": {
1877
+ kind: "decimal",
1878
+ longBits: 64,
1879
+ bits: 32,
1880
+ signed: false,
1881
+ conversion: "checked",
1882
+ nativeCallback: "daemon-init-timeout",
1883
+ rejectMinus: true
1884
+ },
1885
+ "diff-stat-scalar": {
1886
+ kind: "decimal",
1887
+ longBits: 64,
1888
+ bits: 32,
1889
+ signed: true,
1890
+ unsignedLong: true,
1891
+ conversion: "cast",
1892
+ empty: true
1893
+ },
1894
+ "commit-graph-filter-count": {
1895
+ kind: "decimal",
1896
+ longBits: 64,
1897
+ bits: 32,
1898
+ signed: true,
1899
+ conversion: "cast",
1900
+ empty: true
1901
+ },
1902
+ "range-diff-memory": {
1903
+ kind: "integer",
1904
+ signed: false,
1905
+ bits: 64,
1906
+ nativeWidth: "size_t",
1907
+ negativeMagnitudes: false
1908
+ }
1909
+ };
1910
+
1911
+ // src/constraints/commands.ts
1912
+ var git = (file) => `https://github.com/git/git/blob/v2.48.0/${file}`;
1913
+ var lfs = (command) => `https://github.com/git-lfs/git-lfs/blob/v3.6.1/docs/man/git-lfs-${command}.adoc`;
1914
+ var contract = "docs/design/option-constraints.md";
1915
+ var active = (key) => ({ key, test: "active" });
1916
+ var present = (key) => ({ key, test: "present" });
1917
+ var equal = (key, value) => ({ key, test: "equals", value });
1918
+ var COMMAND_CONSTRAINTS = {
1919
+ lfsMigrateInfo: [
1920
+ {
1921
+ id: "lfsMigrateInfo.everything-includeRef",
1922
+ kind: "forbid",
1923
+ when: [
1924
+ {
1925
+ key: "everything",
1926
+ test: "active"
1927
+ },
1928
+ {
1929
+ key: "includeRef",
1930
+ test: "nonempty"
1931
+ }
1932
+ ],
1933
+ origin: "git",
1934
+ reason: "Everything cannot be combined with explicit reference selection.",
1935
+ source: "https://github.com/git-lfs/git-lfs/blob/v3.8.0/commands/command_migrate.go"
1936
+ },
1937
+ {
1938
+ id: "lfsMigrateInfo.everything-excludeRef",
1939
+ kind: "forbid",
1940
+ when: [
1941
+ {
1942
+ key: "everything",
1943
+ test: "active"
1944
+ },
1945
+ {
1946
+ key: "excludeRef",
1947
+ test: "nonempty"
1948
+ }
1949
+ ],
1950
+ origin: "git",
1951
+ reason: "Everything cannot be combined with explicit reference selection.",
1952
+ source: "https://github.com/git-lfs/git-lfs/blob/v3.8.0/commands/command_migrate.go"
1953
+ },
1954
+ {
1955
+ id: "lfsMigrateInfo.everything-refs",
1956
+ kind: "forbid",
1957
+ when: [
1958
+ {
1959
+ key: "everything",
1960
+ test: "active"
1961
+ },
1962
+ {
1963
+ key: "refs",
1964
+ test: "nonempty"
1965
+ }
1966
+ ],
1967
+ origin: "git",
1968
+ reason: "Everything cannot be combined with explicit reference selection.",
1969
+ source: "https://github.com/git-lfs/git-lfs/blob/v3.8.0/commands/command_migrate.go"
1970
+ },
1971
+ {
1972
+ id: "lfsMigrateInfo.fixup-patterns",
1973
+ kind: "conflicts",
1974
+ when: {
1975
+ key: "fixup",
1976
+ test: "active"
1977
+ },
1978
+ others: [
1979
+ {
1980
+ key: "include",
1981
+ test: "present"
1982
+ },
1983
+ {
1984
+ key: "exclude",
1985
+ test: "present"
1986
+ }
1987
+ ],
1988
+ origin: "git",
1989
+ reason: "Fixup infers patterns from attributes and rejects explicit include/exclude.",
1990
+ source: "https://github.com/git-lfs/git-lfs/blob/v3.8.0/commands/command_migrate_info.go"
1991
+ },
1992
+ {
1993
+ id: "lfsMigrateInfo.fixup-pointers",
1994
+ kind: "conflicts",
1995
+ when: {
1996
+ key: "fixup",
1997
+ test: "active"
1998
+ },
1999
+ others: [
2000
+ {
2001
+ key: "pointers",
2002
+ test: "equals",
2003
+ value: "follow"
2004
+ },
2005
+ {
2006
+ key: "pointers",
2007
+ test: "equals",
2008
+ value: "no-follow"
2009
+ }
2010
+ ],
2011
+ origin: "git",
2012
+ reason: "Fixup accepts only the ignore pointer mode.",
2013
+ source: "https://github.com/git-lfs/git-lfs/blob/v3.8.0/commands/command_migrate_info.go"
2014
+ }
2015
+ ],
2016
+ lfsMigrateImport: [
2017
+ {
2018
+ id: "lfsMigrateImport.above-include",
2019
+ kind: "forbid",
2020
+ when: [
2021
+ { key: "noRewrite", test: "inactive" },
2022
+ { key: "above", test: "bytesPositive" },
2023
+ { key: "include", test: "present" }
2024
+ ],
2025
+ origin: "git",
2026
+ reason: "Positive size thresholds cannot be combined with explicit filters or fixup when rewriting history.",
2027
+ source: "https://github.com/git-lfs/git-lfs/blob/v3.8.0/commands/command_migrate_import.go"
2028
+ },
2029
+ {
2030
+ id: "lfsMigrateImport.above-exclude",
2031
+ kind: "forbid",
2032
+ when: [
2033
+ { key: "noRewrite", test: "inactive" },
2034
+ { key: "above", test: "bytesPositive" },
2035
+ { key: "exclude", test: "present" }
2036
+ ],
2037
+ origin: "git",
2038
+ reason: "Positive size thresholds cannot be combined with explicit filters or fixup when rewriting history.",
2039
+ source: "https://github.com/git-lfs/git-lfs/blob/v3.8.0/commands/command_migrate_import.go"
2040
+ },
2041
+ {
2042
+ id: "lfsMigrateImport.above-fixup",
2043
+ kind: "forbid",
2044
+ when: [
2045
+ { key: "noRewrite", test: "inactive" },
2046
+ { key: "above", test: "bytesPositive" },
2047
+ { key: "fixup", test: "active" }
2048
+ ],
2049
+ origin: "git",
2050
+ reason: "Positive size thresholds cannot be combined with explicit filters or fixup when rewriting history.",
2051
+ source: "https://github.com/git-lfs/git-lfs/blob/v3.8.0/commands/command_migrate_import.go"
2052
+ },
2053
+ {
2054
+ id: "lfsMigrateImport.everything-includeRef",
2055
+ kind: "forbid",
2056
+ when: [
2057
+ {
2058
+ key: "noRewrite",
2059
+ test: "inactive"
2060
+ },
2061
+ {
2062
+ key: "everything",
2063
+ test: "active"
2064
+ },
2065
+ {
2066
+ key: "includeRef",
2067
+ test: "nonempty"
2068
+ }
2069
+ ],
2070
+ origin: "git",
2071
+ reason: "Everything cannot be combined with explicit reference selection.",
2072
+ source: "https://github.com/git-lfs/git-lfs/blob/v3.8.0/commands/command_migrate.go"
2073
+ },
2074
+ {
2075
+ id: "lfsMigrateImport.everything-excludeRef",
2076
+ kind: "forbid",
2077
+ when: [
2078
+ {
2079
+ key: "noRewrite",
2080
+ test: "inactive"
2081
+ },
2082
+ {
2083
+ key: "everything",
2084
+ test: "active"
2085
+ },
2086
+ {
2087
+ key: "excludeRef",
2088
+ test: "nonempty"
2089
+ }
2090
+ ],
2091
+ origin: "git",
2092
+ reason: "Everything cannot be combined with explicit reference selection.",
2093
+ source: "https://github.com/git-lfs/git-lfs/blob/v3.8.0/commands/command_migrate.go"
2094
+ },
2095
+ {
2096
+ id: "lfsMigrateImport.everything-refs",
2097
+ kind: "forbid",
2098
+ when: [
2099
+ {
2100
+ key: "noRewrite",
2101
+ test: "inactive"
2102
+ },
2103
+ {
2104
+ key: "everything",
2105
+ test: "active"
2106
+ },
2107
+ {
2108
+ key: "refs",
2109
+ test: "nonempty"
2110
+ }
2111
+ ],
2112
+ origin: "git",
2113
+ reason: "Everything cannot be combined with explicit reference selection.",
2114
+ source: "https://github.com/git-lfs/git-lfs/blob/v3.8.0/commands/command_migrate.go"
2115
+ },
2116
+ {
2117
+ id: "lfsMigrateImport.unknown-options",
2118
+ kind: "unsupported",
2119
+ keys: ["object", "top", "unit", "pointers"],
2120
+ origin: "git",
2121
+ reason: "These options do not exist for migrate import.",
2122
+ source: "https://github.com/git-lfs/git-lfs/blob/v3.8.0/commands/command_migrate.go"
2123
+ },
2124
+ {
2125
+ id: "lfsMigrateImport.no-rewrite-fixup",
2126
+ kind: "exclusive",
2127
+ keys: ["noRewrite", "fixup"],
2128
+ origin: "git",
2129
+ reason: "No-rewrite and fixup cannot be combined.",
2130
+ source: "https://github.com/git-lfs/git-lfs/blob/v3.8.0/commands/command_migrate_import.go"
2131
+ },
2132
+ {
2133
+ id: "lfsMigrateImport.files",
2134
+ kind: "requires",
2135
+ when: {
2136
+ key: "noRewrite",
2137
+ test: "active"
2138
+ },
2139
+ required: [
2140
+ {
2141
+ key: "files",
2142
+ test: "nonempty"
2143
+ }
2144
+ ],
2145
+ origin: "git",
2146
+ reason: "No-rewrite requires one or more positional files.",
2147
+ source: "https://github.com/git-lfs/git-lfs/blob/v3.8.0/commands/command_migrate_import.go"
2148
+ },
2149
+ {
2150
+ id: "lfsMigrateImport.file-mode",
2151
+ kind: "requires",
2152
+ when: {
2153
+ key: "files",
2154
+ test: "nonempty"
2155
+ },
2156
+ required: [
2157
+ {
2158
+ key: "noRewrite",
2159
+ test: "active"
2160
+ }
2161
+ ],
2162
+ origin: "type-git",
2163
+ reason: "The files property denotes no-rewrite paths; use refs to select history.",
2164
+ source: "https://github.com/git-lfs/git-lfs/blob/v3.8.0/commands/command_migrate_import.go"
2165
+ },
2166
+ {
2167
+ id: "lfsMigrateImport.refs-mode",
2168
+ kind: "conflicts",
2169
+ when: {
2170
+ key: "noRewrite",
2171
+ test: "active"
2172
+ },
2173
+ others: [
2174
+ {
2175
+ key: "refs",
2176
+ test: "nonempty"
2177
+ }
2178
+ ],
2179
+ origin: "type-git",
2180
+ reason: "No-rewrite operands are files; use the files property in this mode.",
2181
+ source: "https://github.com/git-lfs/git-lfs/blob/v3.8.0/commands/command_migrate_import.go"
2182
+ },
2183
+ {
2184
+ id: "lfsMigrateImport.fixup-patterns",
2185
+ kind: "conflicts",
2186
+ when: {
2187
+ key: "fixup",
2188
+ test: "active"
2189
+ },
2190
+ others: [
2191
+ {
2192
+ key: "include",
2193
+ test: "present"
2194
+ },
2195
+ {
2196
+ key: "exclude",
2197
+ test: "present"
2198
+ }
2199
+ ],
2200
+ origin: "git",
2201
+ reason: "Fixup infers patterns from attributes and rejects explicit include/exclude.",
2202
+ source: "https://github.com/git-lfs/git-lfs/blob/v3.8.0/commands/command_migrate_import.go"
2203
+ }
2204
+ ],
2205
+ lfsMigrateExport: [
2206
+ {
2207
+ id: "lfsMigrateExport.everything-includeRef",
2208
+ kind: "forbid",
2209
+ when: [
2210
+ {
2211
+ key: "everything",
2212
+ test: "active"
2213
+ },
2214
+ {
2215
+ key: "includeRef",
2216
+ test: "nonempty"
2217
+ }
2218
+ ],
2219
+ origin: "git",
2220
+ reason: "Everything cannot be combined with explicit reference selection.",
2221
+ source: "https://github.com/git-lfs/git-lfs/blob/v3.8.0/commands/command_migrate.go"
2222
+ },
2223
+ {
2224
+ id: "lfsMigrateExport.everything-excludeRef",
2225
+ kind: "forbid",
2226
+ when: [
2227
+ {
2228
+ key: "everything",
2229
+ test: "active"
2230
+ },
2231
+ {
2232
+ key: "excludeRef",
2233
+ test: "nonempty"
2234
+ }
2235
+ ],
2236
+ origin: "git",
2237
+ reason: "Everything cannot be combined with explicit reference selection.",
2238
+ source: "https://github.com/git-lfs/git-lfs/blob/v3.8.0/commands/command_migrate.go"
2239
+ },
2240
+ {
2241
+ id: "lfsMigrateExport.everything-refs",
2242
+ kind: "forbid",
2243
+ when: [
2244
+ {
2245
+ key: "everything",
2246
+ test: "active"
2247
+ },
2248
+ {
2249
+ key: "refs",
2250
+ test: "nonempty"
2251
+ }
2252
+ ],
2253
+ origin: "git",
2254
+ reason: "Everything cannot be combined with explicit reference selection.",
2255
+ source: "https://github.com/git-lfs/git-lfs/blob/v3.8.0/commands/command_migrate.go"
2256
+ },
2257
+ {
2258
+ id: "lfsMigrateExport.include",
2259
+ kind: "required",
2260
+ required: [
2261
+ {
2262
+ key: "include",
2263
+ test: "nonblank"
2264
+ }
2265
+ ],
2266
+ origin: "git",
2267
+ reason: "Export requires at least one inclusion pattern.",
2268
+ source: "https://github.com/git-lfs/git-lfs/blob/v3.8.0/commands/command_migrate_export.go"
2269
+ },
2270
+ {
2271
+ id: "lfsMigrateExport.unknown-options",
2272
+ kind: "unsupported",
2273
+ keys: ["above", "top", "unit", "pointers", "fixup"],
2274
+ origin: "git",
2275
+ reason: "These options do not exist for migrate export.",
2276
+ source: "https://github.com/git-lfs/git-lfs/blob/v3.8.0/commands/command_migrate.go"
2277
+ }
2278
+ ],
2279
+ reset: [
2280
+ {
2281
+ id: "reset.intent-to-add-mode",
2282
+ kind: "conflicts",
2283
+ when: active("intentToAdd"),
2284
+ others: [
2285
+ equal("mode", "soft"),
2286
+ equal("mode", "hard"),
2287
+ equal("mode", "merge"),
2288
+ equal("mode", "keep")
2289
+ ],
2290
+ origin: "git",
2291
+ reason: "Intent-to-add requires mixed reset (the default mode).",
2292
+ source: "https://github.com/git/git/blob/v2.55.0/builtin/reset.c"
2293
+ }
2294
+ ],
2295
+ stashPush: [
2296
+ {
2297
+ id: "stashPush.staged",
2298
+ kind: "conflicts",
2299
+ when: active("staged"),
2300
+ others: [active("includeUntracked"), active("all"), present("pathspecFromFile")],
2301
+ origin: "git",
2302
+ reason: "Staged-only stash rejects untracked files, all files, and pathspec files.",
2303
+ source: "https://github.com/git/git/blob/v2.55.0/builtin/stash.c"
2304
+ },
2305
+ {
2306
+ id: "stashPush.pathspec",
2307
+ kind: "conflicts",
2308
+ when: present("pathspecFromFile"),
2309
+ others: [{ key: "paths", test: "nonempty" }],
2310
+ origin: "git",
2311
+ reason: "Pathspec files cannot be combined with command-line pathspecs.",
2312
+ source: "https://github.com/git/git/blob/v2.55.0/builtin/stash.c"
2313
+ }
2314
+ ],
2315
+ tagCreate: [
2316
+ {
2317
+ id: "tagCreate.message-file",
2318
+ kind: "exclusive",
2319
+ keys: ["message", "file"],
2320
+ origin: "git",
2321
+ reason: "Tag messages cannot come from both -m and -F.",
2322
+ source: "https://github.com/git/git/blob/v2.55.0/builtin/tag.c"
2323
+ }
2324
+ ],
2325
+ submoduleUpdate: [
2326
+ {
2327
+ id: "submoduleUpdate.filter-grammar",
2328
+ kind: "scalar",
2329
+ key: "filter",
2330
+ parser: "object-filter",
2331
+ origin: "git",
2332
+ reason: "The object filter must use a supported Git filter grammar.",
2333
+ source: "https://github.com/git/git/blob/v2.55.0/list-objects-filter-options.c"
2334
+ },
2335
+ {
2336
+ id: "submoduleUpdate.filter-init",
2337
+ kind: "requires",
2338
+ when: present("filter"),
2339
+ required: [active("init")],
2340
+ origin: "git",
2341
+ reason: "Submodule update filtering requires initialization.",
2342
+ source: "https://github.com/git/git/blob/v2.55.0/builtin/submodule--helper.c"
2343
+ }
2344
+ ],
2345
+ remoteAdd: [
2346
+ {
2347
+ id: "remoteAdd.push-mirror-track",
2348
+ kind: "conflicts",
2349
+ when: equal("mirror", "push"),
2350
+ others: [present("track")],
2351
+ origin: "git",
2352
+ reason: "Tracking branches is only supported for fetch mirrors.",
2353
+ source: "https://github.com/git/git/blob/v2.55.0/builtin/remote.c"
2354
+ }
2355
+ ],
2356
+ lfsCheckout: [
2357
+ {
2358
+ id: "lfsCheckout.stage",
2359
+ kind: "exclusive",
2360
+ keys: ["base", "ours", "theirs"],
2361
+ origin: "git",
2362
+ reason: "Select at most one conflict stage.",
2363
+ source: "https://github.com/git-lfs/git-lfs/blob/v3.8.0/commands/command_checkout.go"
2364
+ },
2365
+ {
2366
+ id: "lfsCheckout.destination-stage",
2367
+ kind: "requiresAny",
2368
+ when: { key: "to", test: "nonempty" },
2369
+ choices: [active("base"), active("ours"), active("theirs")],
2370
+ origin: "git",
2371
+ reason: "A conflict destination requires a conflict stage.",
2372
+ source: "https://github.com/git-lfs/git-lfs/blob/v3.8.0/commands/command_checkout.go"
2373
+ },
2374
+ {
2375
+ id: "lfsCheckout.base-destination",
2376
+ kind: "requires",
2377
+ when: active("base"),
2378
+ required: [{ key: "to", test: "nonempty" }],
2379
+ origin: "git",
2380
+ reason: "A conflict stage requires a nonempty destination.",
2381
+ source: "https://github.com/git-lfs/git-lfs/blob/v3.8.0/commands/command_checkout.go"
2382
+ },
2383
+ {
2384
+ id: "lfsCheckout.ours-destination",
2385
+ kind: "requires",
2386
+ when: active("ours"),
2387
+ required: [{ key: "to", test: "nonempty" }],
2388
+ origin: "git",
2389
+ reason: "A conflict stage requires a nonempty destination.",
2390
+ source: "https://github.com/git-lfs/git-lfs/blob/v3.8.0/commands/command_checkout.go"
2391
+ },
2392
+ {
2393
+ id: "lfsCheckout.theirs-destination",
2394
+ kind: "requires",
2395
+ when: active("theirs"),
2396
+ required: [{ key: "to", test: "nonempty" }],
2397
+ origin: "git",
2398
+ reason: "A conflict stage requires a nonempty destination.",
2399
+ source: "https://github.com/git-lfs/git-lfs/blob/v3.8.0/commands/command_checkout.go"
2400
+ },
2401
+ {
2402
+ id: "lfsCheckout.unknown-options",
2403
+ kind: "unsupported",
2404
+ keys: ["include", "exclude"],
2405
+ origin: "git",
2406
+ reason: "LFS checkout has no include/exclude options; use positional patterns.",
2407
+ source: "https://github.com/git-lfs/git-lfs/blob/v3.8.0/commands/command_checkout.go"
2408
+ }
2409
+ ],
2410
+ lfsLocks: [
2411
+ {
2412
+ id: "lfsLocks.verify-limit",
2413
+ kind: "range",
2414
+ key: "limit",
2415
+ min: 0,
2416
+ when: active("verify"),
2417
+ origin: "git",
2418
+ reason: "Lock verification allocates a result slice with this capacity and fails for negative limits.",
2419
+ source: "https://github.com/git-lfs/git-lfs/blob/v3.8.0/locking/locks.go"
2420
+ },
2421
+ {
2422
+ id: "lfsLocks.limit-integer",
2423
+ kind: "integer",
2424
+ key: "limit",
2425
+ min: Number.MIN_SAFE_INTEGER,
2426
+ origin: "type-git",
2427
+ reason: "Numeric CLI options use safe integers to prevent truncation and precision loss.",
2428
+ source: contract
2429
+ },
2430
+ {
2431
+ id: "lfsLocks.cached",
2432
+ kind: "conflicts",
2433
+ when: active("cached"),
2434
+ others: [
2435
+ active("local"),
2436
+ { key: "limit", test: "positive" },
2437
+ { key: "id", test: "nonempty" },
2438
+ { key: "path", test: "nonempty" }
2439
+ ],
2440
+ origin: "git",
2441
+ reason: "Cached locks reject positive limits, filters, and local mode.",
2442
+ source: "https://github.com/git-lfs/git-lfs/blob/v3.8.0/commands/command_locks.go"
2443
+ },
2444
+ {
2445
+ id: "lfsLocks.verify",
2446
+ kind: "conflicts",
2447
+ when: active("verify"),
2448
+ others: [active("local"), { key: "id", test: "nonempty" }, { key: "path", test: "nonempty" }],
2449
+ origin: "git",
2450
+ reason: "Lock verification rejects filters and local mode.",
2451
+ source: "https://github.com/git-lfs/git-lfs/blob/v3.8.0/commands/command_locks.go"
2452
+ }
2453
+ ],
2454
+ clone: [
2455
+ {
2456
+ id: "clone.filter-grammar",
2457
+ kind: "scalar",
2458
+ key: "filter",
2459
+ parser: "object-filter-auto",
2460
+ origin: "git",
2461
+ reason: "The object filter must use a supported Git filter grammar.",
2462
+ source: "https://github.com/git/git/blob/v2.55.0/list-objects-filter-options.c"
2463
+ },
2464
+ {
2465
+ id: "clone.bare-separateGitDir",
2466
+ kind: "exclusive",
2467
+ keys: ["bare", "separateGitDir"],
2468
+ origin: "git",
2469
+ reason: "Git rejects these simultaneous modes or operands.",
2470
+ source: git("builtin/clone.c")
2471
+ },
2472
+ {
2473
+ id: "clone.mirror-separateGitDir",
2474
+ kind: "exclusive",
2475
+ keys: ["mirror", "separateGitDir"],
2476
+ origin: "git",
2477
+ reason: "Git rejects these simultaneous modes or operands.",
2478
+ source: git("builtin/clone.c")
2479
+ },
2480
+ {
2481
+ id: "clone.submodule-filter",
2482
+ kind: "requires",
2483
+ when: active("alsoFilterSubmodules"),
2484
+ required: [active("filter"), active("recurseSubmodules")],
2485
+ origin: "git",
2486
+ reason: "Explicit submodule filtering requires a filter and recursive submodule initialization.",
2487
+ source: git("builtin/clone.c")
2488
+ },
2489
+ {
2490
+ id: "clone.depth",
2491
+ kind: "integer",
2492
+ key: "depth",
2493
+ min: Number.MIN_SAFE_INTEGER,
2494
+ origin: "type-git",
2495
+ reason: "Numeric options use safe integers to avoid fractional truncation or loss of precision.",
2496
+ source: contract
2497
+ },
2498
+ {
2499
+ id: "clone.depth-range",
2500
+ kind: "scalar",
2501
+ key: "depth",
2502
+ parser: "depth-initial",
2503
+ origin: "git",
2504
+ reason: "The final depth must be positive after Git converts it with atoi.",
2505
+ source: "https://github.com/git/git/blob/v2.55.0/builtin/clone.c"
2506
+ },
2507
+ {
2508
+ id: "clone.jobs",
2509
+ kind: "integer",
2510
+ key: "jobs",
2511
+ min: Number.MIN_SAFE_INTEGER,
2512
+ origin: "type-git",
2513
+ reason: "Numeric options use safe integers to avoid fractional truncation or loss of precision.",
2514
+ source: contract
2515
+ }
2516
+ ],
2517
+ init: [
2518
+ {
2519
+ id: "init.bare-separateGitDir",
2520
+ kind: "exclusive",
2521
+ keys: ["bare", "separateGitDir"],
2522
+ origin: "git",
2523
+ reason: "Git rejects these simultaneous modes or operands.",
2524
+ source: git("builtin/init-db.c")
2525
+ }
2526
+ ],
2527
+ lsRemote: [
2528
+ {
2529
+ id: "lsRemote.unsupported",
2530
+ kind: "unsupported",
2531
+ keys: ["getUrl", "symref"],
2532
+ origin: "type-git",
2533
+ reason: "The ref-list result cannot represent URL-only output or symbolic-ref records.",
2534
+ source: contract
2535
+ }
2536
+ ],
2537
+ lsTree: [
2538
+ {
2539
+ id: "lsTree.nameOnly-objectOnly-long",
2540
+ kind: "exclusive",
2541
+ keys: ["nameOnly", "objectOnly", "long"],
2542
+ origin: "git",
2543
+ reason: "Git rejects these simultaneous modes or operands.",
2544
+ source: git("builtin/ls-tree.c")
2545
+ },
2546
+ {
2547
+ id: "lsTree.abbrev",
2548
+ kind: "integer",
2549
+ key: "abbrev",
2550
+ allowBoolean: true,
2551
+ min: Number.MIN_SAFE_INTEGER,
2552
+ origin: "type-git",
2553
+ reason: "Numeric options use safe integers to avoid fractional truncation or loss of precision.",
2554
+ source: contract
2555
+ }
2556
+ ],
2557
+ status: [
2558
+ {
2559
+ id: "status.unsupported",
2560
+ kind: "unsupported",
2561
+ keys: ["verbose"],
2562
+ origin: "type-git",
2563
+ reason: "The status result contains porcelain entries, not verbose patch output.",
2564
+ source: contract
2565
+ },
2566
+ {
2567
+ id: "status.porcelain",
2568
+ kind: "value",
2569
+ key: "porcelain",
2570
+ allowed: [2],
2571
+ origin: "type-git",
2572
+ reason: "The typed status parser reads porcelain v2.",
2573
+ source: contract
2574
+ },
2575
+ {
2576
+ id: "status.nul",
2577
+ kind: "value",
2578
+ key: "nullTerminated",
2579
+ allowed: [true],
2580
+ origin: "type-git",
2581
+ reason: "Structured paths use NUL delimiters to preserve all filenames.",
2582
+ source: contract
2583
+ }
2584
+ ],
2585
+ log: [
2586
+ {
2587
+ id: "log.unsupported",
2588
+ kind: "unsupported",
2589
+ keys: [
2590
+ "source",
2591
+ "decorate",
2592
+ "decorateRefs",
2593
+ "decorateRefsExclude",
2594
+ "stat",
2595
+ "shortstat",
2596
+ "nameOnly",
2597
+ "nameStatus"
2598
+ ],
2599
+ origin: "type-git",
2600
+ reason: "The commit result has no fields for decorations, patches, or file statistics.",
2601
+ source: contract
2602
+ },
2603
+ {
2604
+ id: "log.maxCount",
2605
+ kind: "integer",
2606
+ key: "maxCount",
2607
+ min: Number.MIN_SAFE_INTEGER,
2608
+ origin: "type-git",
2609
+ reason: "Numeric options use safe integers to avoid fractional truncation or loss of precision.",
2610
+ source: contract
2611
+ },
2612
+ {
2613
+ id: "log.skip",
2614
+ kind: "integer",
2615
+ key: "skip",
2616
+ min: Number.MIN_SAFE_INTEGER,
2617
+ origin: "type-git",
2618
+ reason: "Numeric options use safe integers to avoid fractional truncation or loss of precision.",
2619
+ source: contract
2620
+ }
2621
+ ],
2622
+ show: [
2623
+ {
2624
+ id: "show.nameOnly-nameStatus",
2625
+ kind: "exclusive",
2626
+ keys: ["nameOnly", "nameStatus"],
2627
+ origin: "git",
2628
+ reason: "Git rejects simultaneous name-only and name-status output.",
2629
+ source: "https://github.com/git/git/blob/v2.55.0/diff.c"
2630
+ },
2631
+ {
2632
+ id: "show.quiet-nameOnly",
2633
+ kind: "forbid",
2634
+ when: [active("quiet"), active("nameOnly")],
2635
+ origin: "git",
2636
+ reason: "The first-pass --quiet suppresses output before --name-only is parsed, so diff_setup_done (diff.c) rejects both. Git 2.55.0 accepts the pair when --stat clears the suppression, but Git 2.25 still rejects it, so --stat does not lift this rule.",
2637
+ source: "https://github.com/git/git/blob/v2.25.0/builtin/log.c"
2638
+ },
2639
+ {
2640
+ id: "show.quiet-nameStatus",
2641
+ kind: "forbid",
2642
+ when: [active("quiet"), active("nameStatus")],
2643
+ origin: "git",
2644
+ reason: "The first-pass --quiet suppresses output before --name-status is parsed, so diff_setup_done (diff.c) rejects both. Git 2.55.0 accepts the pair when --stat clears the suppression, but Git 2.25 still rejects it, so --stat does not lift this rule.",
2645
+ source: "https://github.com/git/git/blob/v2.25.0/builtin/log.c"
2646
+ }
2647
+ ],
2648
+ fetch: [
2649
+ {
2650
+ id: "fetch.depth-unshallow",
2651
+ kind: "exclusive",
2652
+ keys: ["depth", "unshallow"],
2653
+ origin: "git",
2654
+ reason: "Unshallow cannot use an explicit depth.",
2655
+ source: git("builtin/fetch.c")
2656
+ },
2657
+ {
2658
+ id: "fetch.deepen-depth",
2659
+ kind: "forbid",
2660
+ when: [{ key: "deepen", test: "nonzero" }, present("depth")],
2661
+ origin: "git",
2662
+ reason: "A nonzero deepen value cannot be combined with depth.",
2663
+ source: git("builtin/fetch.c")
2664
+ },
2665
+ {
2666
+ id: "fetch.deepen-unshallow",
2667
+ kind: "forbid",
2668
+ when: [{ key: "deepen", test: "nonzero" }, active("unshallow")],
2669
+ origin: "git",
2670
+ reason: "A nonzero deepen value cannot be combined with unshallow.",
2671
+ source: git("builtin/fetch.c")
2672
+ },
2673
+ {
2674
+ id: "fetch.all-remote",
2675
+ kind: "exclusive",
2676
+ keys: ["all", "remote"],
2677
+ origin: "git",
2678
+ reason: "Git rejects these simultaneous modes or operands.",
2679
+ source: git("builtin/fetch.c")
2680
+ },
2681
+ {
2682
+ id: "fetch.all-refspec",
2683
+ kind: "exclusive",
2684
+ keys: ["all", "refspec"],
2685
+ origin: "git",
2686
+ reason: "Git rejects these simultaneous modes or operands.",
2687
+ source: git("builtin/fetch.c")
2688
+ },
2689
+ {
2690
+ id: "fetch.unsupported",
2691
+ kind: "unsupported",
2692
+ keys: ["multiple"],
2693
+ origin: "type-git",
2694
+ reason: "The single-remote API has no multiple-remote operand list.",
2695
+ source: contract
2696
+ },
2697
+ {
2698
+ id: "fetch.depth",
2699
+ kind: "integer",
2700
+ key: "depth",
2701
+ min: Number.MIN_SAFE_INTEGER,
2702
+ origin: "type-git",
2703
+ reason: "Numeric options use safe integers to avoid fractional truncation or loss of precision.",
2704
+ source: contract
2705
+ },
2706
+ {
2707
+ id: "fetch.depth-range",
2708
+ kind: "scalar",
2709
+ key: "depth",
2710
+ parser: "depth-initial",
2711
+ origin: "git",
2712
+ reason: "The final depth must be positive after Git converts it with atoi.",
2713
+ source: "https://github.com/git/git/blob/v2.55.0/builtin/fetch.c"
2714
+ },
2715
+ {
2716
+ id: "fetch.jobs",
2717
+ kind: "integer",
2718
+ key: "jobs",
2719
+ min: Number.MIN_SAFE_INTEGER,
2720
+ origin: "type-git",
2721
+ reason: "Numeric options use safe integers to avoid fractional truncation or loss of precision.",
2722
+ source: contract
2723
+ },
2724
+ {
2725
+ id: "fetch.deepen",
2726
+ kind: "integer",
2727
+ key: "deepen",
2728
+ min: Number.MIN_SAFE_INTEGER,
2729
+ origin: "type-git",
2730
+ reason: "Numeric options use safe integers to avoid fractional truncation or loss of precision.",
2731
+ source: contract
2732
+ },
2733
+ {
2734
+ id: "fetch.deepen-range",
2735
+ kind: "range",
2736
+ key: "deepen",
2737
+ min: 0,
2738
+ origin: "git",
2739
+ reason: "Git rejects values below 0 for deepen.",
2740
+ source: git("builtin/fetch.c")
2741
+ }
2742
+ ],
2743
+ push: [
2744
+ {
2745
+ id: "push.all-mirror-refspec",
2746
+ kind: "exclusive",
2747
+ keys: ["all", "mirror", "refspec"],
2748
+ origin: "git",
2749
+ reason: "Git rejects these simultaneous modes or operands.",
2750
+ source: git("builtin/push.c")
2751
+ },
2752
+ {
2753
+ id: "push.all-tags",
2754
+ kind: "exclusive",
2755
+ keys: ["all", "tags"],
2756
+ origin: "git",
2757
+ reason: "Git rejects these simultaneous modes or operands.",
2758
+ source: git("builtin/push.c")
2759
+ },
2760
+ {
2761
+ id: "push.branches-mirror-refspec",
2762
+ kind: "exclusive",
2763
+ keys: ["branches", "mirror", "refspec"],
2764
+ origin: "git",
2765
+ reason: "Git rejects these simultaneous modes or operands.",
2766
+ source: git("builtin/push.c")
2767
+ },
2768
+ {
2769
+ id: "push.branches-tags",
2770
+ kind: "exclusive",
2771
+ keys: ["branches", "tags"],
2772
+ origin: "git",
2773
+ reason: "Git rejects these simultaneous modes or operands.",
2774
+ source: git("builtin/push.c")
2775
+ },
2776
+ {
2777
+ id: "push.mirror-tags",
2778
+ kind: "exclusive",
2779
+ keys: ["mirror", "tags"],
2780
+ origin: "git",
2781
+ reason: "Git rejects these simultaneous modes or operands.",
2782
+ source: git("builtin/push.c")
2783
+ },
2784
+ {
2785
+ id: "push.delete-all",
2786
+ kind: "exclusive",
2787
+ keys: ["deleteRefs", "all"],
2788
+ origin: "git",
2789
+ reason: "Delete mode cannot be combined with bulk push modes.",
2790
+ source: git("builtin/push.c")
2791
+ },
2792
+ {
2793
+ id: "push.delete-branches",
2794
+ kind: "exclusive",
2795
+ keys: ["deleteRefs", "branches"],
2796
+ origin: "git",
2797
+ reason: "Delete mode cannot be combined with bulk push modes.",
2798
+ source: git("builtin/push.c")
2799
+ },
2800
+ {
2801
+ id: "push.delete-mirror",
2802
+ kind: "exclusive",
2803
+ keys: ["deleteRefs", "mirror"],
2804
+ origin: "git",
2805
+ reason: "Delete mode cannot be combined with bulk push modes.",
2806
+ source: git("builtin/push.c")
2807
+ },
2808
+ {
2809
+ id: "push.delete-tags",
2810
+ kind: "exclusive",
2811
+ keys: ["deleteRefs", "tags"],
2812
+ origin: "git",
2813
+ reason: "Delete mode cannot be combined with bulk push modes.",
2814
+ source: git("builtin/push.c")
2815
+ },
2816
+ {
2817
+ id: "push.delete-refs",
2818
+ kind: "requires",
2819
+ when: active("deleteRefs"),
2820
+ required: [active("refspec")],
2821
+ origin: "git",
2822
+ reason: "Deletion requires explicit refs.",
2823
+ source: git("builtin/push.c")
2824
+ }
2825
+ ],
2826
+ add: [
2827
+ {
2828
+ id: "add.all-update",
2829
+ kind: "exclusive",
2830
+ keys: ["all", "update"],
2831
+ // The emitted --ignore-removal follows --all and resets Git's shared mode variable.
2832
+ guard: [{ key: "ignoreRemoval", test: "inactive" }],
2833
+ origin: "git",
2834
+ reason: "Git rejects these simultaneous modes or operands.",
2835
+ source: git("builtin/add.c")
2836
+ },
2837
+ {
2838
+ id: "add.all-ignoreRemoval",
2839
+ kind: "exclusive",
2840
+ keys: ["all", "ignoreRemoval"],
2841
+ origin: "type-git",
2842
+ reason: "The emitted --ignore-removal follows --all and silently resets the same Git mode to --no-all.",
2843
+ source: "https://github.com/git/git/blob/v2.55.0/builtin/add.c"
2844
+ },
2845
+ {
2846
+ id: "add.ignoreMissing-dryRun",
2847
+ kind: "requires",
2848
+ when: active("ignoreMissing"),
2849
+ required: [active("dryRun")],
2850
+ origin: "git",
2851
+ reason: "Ignoring missing paths requires dry-run.",
2852
+ source: "https://github.com/git/git/blob/v2.55.0/builtin/add.c"
2853
+ },
2854
+ {
2855
+ id: "add.chmod",
2856
+ kind: "value",
2857
+ key: "chmod",
2858
+ allowed: ["+x", "-x"],
2859
+ origin: "git",
2860
+ reason: "The executable bit must be +x or -x.",
2861
+ source: "https://github.com/git/git/blob/v2.55.0/builtin/add.c"
2862
+ },
2863
+ {
2864
+ id: "add.unsupported",
2865
+ kind: "unsupported",
2866
+ keys: ["interactive", "patch"],
2867
+ origin: "type-git",
2868
+ reason: "Interactive patch selection requires a terminal protocol absent from this API.",
2869
+ source: contract
2870
+ }
2871
+ ],
2872
+ checkoutBranch: [
2873
+ {
2874
+ id: "checkoutBranch.createBranch-forceCreateBranch-detach-orphan",
2875
+ kind: "exclusive",
2876
+ keys: ["createBranch", "forceCreateBranch", "detach", "orphan"],
2877
+ origin: "git",
2878
+ reason: "Git rejects these simultaneous modes or operands.",
2879
+ source: git("builtin/checkout.c")
2880
+ }
2881
+ ],
2882
+ checkoutPath: [
2883
+ {
2884
+ id: "checkoutPath.source-ours",
2885
+ kind: "exclusive",
2886
+ keys: ["source", "ours"],
2887
+ origin: "git",
2888
+ reason: "Git rejects these simultaneous modes or operands.",
2889
+ source: git("builtin/checkout.c")
2890
+ },
2891
+ {
2892
+ id: "checkoutPath.source-theirs",
2893
+ kind: "exclusive",
2894
+ keys: ["source", "theirs"],
2895
+ origin: "git",
2896
+ reason: "Git rejects these simultaneous modes or operands.",
2897
+ source: git("builtin/checkout.c")
2898
+ }
2899
+ ],
2900
+ commit: [
2901
+ {
2902
+ id: "commit.message-file-reuseMessage",
2903
+ kind: "exclusive",
2904
+ keys: ["message", "file", "reuseMessage"],
2905
+ origin: "git",
2906
+ reason: "Git rejects these simultaneous modes or operands.",
2907
+ source: git("builtin/commit.c")
2908
+ },
2909
+ {
2910
+ id: "commit.fixup-squash",
2911
+ kind: "exclusive",
2912
+ keys: ["fixup", "squash"],
2913
+ origin: "git",
2914
+ reason: "Git rejects these simultaneous modes or operands.",
2915
+ source: git("builtin/commit.c")
2916
+ },
2917
+ {
2918
+ id: "commit.include-only-all",
2919
+ kind: "exclusive",
2920
+ keys: ["include", "only", "all"],
2921
+ origin: "git",
2922
+ reason: "Git rejects these simultaneous modes or operands.",
2923
+ source: git("builtin/commit.c")
2924
+ },
2925
+ {
2926
+ id: "commit.unsupported",
2927
+ kind: "unsupported",
2928
+ keys: ["dryRun", "reeditMessage"],
2929
+ origin: "type-git",
2930
+ reason: "The commit result requires a completed commit; editor interaction is not supported.",
2931
+ source: contract
2932
+ },
2933
+ {
2934
+ id: "commit.fixup-message-source",
2935
+ kind: "exclusive",
2936
+ keys: ["reuseMessage", "file", "fixup"],
2937
+ origin: "git",
2938
+ reason: "Git rejects combining these message sources.",
2939
+ source: git("builtin/commit.c")
2940
+ },
2941
+ {
2942
+ id: "commit.author-reset",
2943
+ kind: "exclusive",
2944
+ keys: ["author", "resetAuthor"],
2945
+ origin: "git",
2946
+ reason: "An explicit author cannot be combined with resetting authorship.",
2947
+ source: git("builtin/commit.c")
2948
+ },
2949
+ {
2950
+ id: "commit.all-pathspec-file",
2951
+ kind: "exclusive",
2952
+ keys: ["all", "pathspecFromFile"],
2953
+ origin: "git",
2954
+ reason: "Commit --all cannot use a pathspec file.",
2955
+ source: git("builtin/commit.c")
2956
+ },
2957
+ // repo.commit emits no path operands and skips an empty pathspecFromFile or fixup.
2958
+ {
2959
+ id: "commit.include-paths",
2960
+ kind: "requires",
2961
+ when: active("include"),
2962
+ required: [{ key: "pathspecFromFile", test: "nonempty" }],
2963
+ origin: "git",
2964
+ reason: "Include mode needs a pathspec file because repo.commit emits no paths.",
2965
+ source: "https://github.com/git/git/blob/v2.55.0/builtin/commit.c"
2966
+ }
2967
+ ],
2968
+ diff: [
2969
+ {
2970
+ id: "diff.nameOnly-nameStatus",
2971
+ kind: "exclusive",
2972
+ keys: ["nameOnly", "nameStatus"],
2973
+ origin: "git",
2974
+ reason: "Git rejects simultaneous name-only and name-status output.",
2975
+ source: git("diff.c")
2976
+ },
2977
+ {
2978
+ id: "diff.unsupported",
2979
+ kind: "unsupported",
2980
+ keys: ["noIndex"],
2981
+ origin: "type-git",
2982
+ reason: "The repository diff API has no pair of filesystem operands for --no-index.",
2983
+ source: contract
2984
+ },
2985
+ {
2986
+ id: "diff.nul",
2987
+ kind: "value",
2988
+ key: "nullTerminated",
2989
+ allowed: [true],
2990
+ origin: "type-git",
2991
+ reason: "Structured paths use NUL delimiters to preserve all filenames.",
2992
+ source: contract
2993
+ },
2994
+ {
2995
+ id: "diff.context",
2996
+ kind: "integer",
2997
+ key: "context",
2998
+ min: Number.MIN_SAFE_INTEGER,
2999
+ origin: "type-git",
3000
+ reason: "Numeric options use safe integers to avoid fractional truncation or loss of precision.",
3001
+ source: contract
3002
+ },
3003
+ {
3004
+ id: "diff.context-range",
3005
+ kind: "range",
3006
+ key: "context",
3007
+ min: 0,
3008
+ origin: "git",
3009
+ reason: "Git rejects values below 0 for context.",
3010
+ source: git("diff.c")
3011
+ },
3012
+ {
3013
+ id: "diff.renameLimit",
3014
+ kind: "integer",
3015
+ key: "renameLimit",
3016
+ min: Number.MIN_SAFE_INTEGER,
3017
+ origin: "type-git",
3018
+ reason: "Numeric options use safe integers to avoid fractional truncation or loss of precision.",
3019
+ source: contract
3020
+ },
3021
+ {
3022
+ id: "diff.abbrev",
3023
+ kind: "integer",
3024
+ key: "abbrev",
3025
+ min: Number.MIN_SAFE_INTEGER,
3026
+ origin: "type-git",
3027
+ reason: "Numeric options use safe integers to avoid fractional truncation or loss of precision.",
3028
+ source: contract
3029
+ }
3030
+ ],
3031
+ merge: [
3032
+ {
3033
+ id: "merge.abort-continue-quit",
3034
+ kind: "exclusive",
3035
+ keys: ["abort", "continue", "quit"],
3036
+ origin: "git",
3037
+ reason: "Git rejects these simultaneous modes or operands.",
3038
+ source: git("builtin/merge.c")
3039
+ },
3040
+ {
3041
+ id: "merge.abort-options",
3042
+ kind: "conflicts",
3043
+ when: active("abort"),
3044
+ others: [
3045
+ active("message"),
3046
+ present("ff"),
3047
+ active("squash"),
3048
+ active("noCommit"),
3049
+ active("strategy"),
3050
+ active("strategyOption"),
3051
+ active("noVerify"),
3052
+ active("noDiffstat"),
3053
+ active("stat"),
3054
+ active("compactSummary"),
3055
+ active("log"),
3056
+ active("cleanup"),
3057
+ present("rerereAutoupdate"),
3058
+ active("verifySignatures"),
3059
+ active("verbose"),
3060
+ active("quiet"),
3061
+ active("allowUnrelatedHistories"),
3062
+ active("gpgSign"),
3063
+ present("autostash"),
3064
+ present("overwriteIgnore"),
3065
+ active("signoff"),
3066
+ active("intoName")
3067
+ ],
3068
+ origin: "git",
3069
+ reason: "Merge control operations accept no additional command arguments.",
3070
+ source: git("builtin/merge.c")
3071
+ },
3072
+ {
3073
+ id: "merge.continue-options",
3074
+ kind: "conflicts",
3075
+ when: active("continue"),
3076
+ others: [
3077
+ active("message"),
3078
+ present("ff"),
3079
+ active("squash"),
3080
+ active("noCommit"),
3081
+ active("strategy"),
3082
+ active("strategyOption"),
3083
+ active("noVerify"),
3084
+ active("noDiffstat"),
3085
+ active("stat"),
3086
+ active("compactSummary"),
3087
+ active("log"),
3088
+ active("cleanup"),
3089
+ present("rerereAutoupdate"),
3090
+ active("verifySignatures"),
3091
+ active("verbose"),
3092
+ active("quiet"),
3093
+ active("allowUnrelatedHistories"),
3094
+ active("gpgSign"),
3095
+ present("autostash"),
3096
+ present("overwriteIgnore"),
3097
+ active("signoff"),
3098
+ active("intoName")
3099
+ ],
3100
+ origin: "git",
3101
+ reason: "Merge control operations accept no additional command arguments.",
3102
+ source: git("builtin/merge.c")
3103
+ },
3104
+ {
3105
+ id: "merge.quit-options",
3106
+ kind: "conflicts",
3107
+ when: active("quit"),
3108
+ others: [
3109
+ active("message"),
3110
+ present("ff"),
3111
+ active("squash"),
3112
+ active("noCommit"),
3113
+ active("strategy"),
3114
+ active("strategyOption"),
3115
+ active("noVerify"),
3116
+ active("noDiffstat"),
3117
+ active("stat"),
3118
+ active("compactSummary"),
3119
+ active("log"),
3120
+ active("cleanup"),
3121
+ present("rerereAutoupdate"),
3122
+ active("verifySignatures"),
3123
+ active("verbose"),
3124
+ active("quiet"),
3125
+ active("allowUnrelatedHistories"),
3126
+ active("gpgSign"),
3127
+ present("autostash"),
3128
+ present("overwriteIgnore"),
3129
+ active("signoff"),
3130
+ active("intoName")
3131
+ ],
3132
+ origin: "git",
3133
+ reason: "Merge control operations accept no additional command arguments.",
3134
+ source: git("builtin/merge.c")
3135
+ },
3136
+ {
3137
+ id: "merge.squash-no-ff-no",
3138
+ kind: "forbid",
3139
+ when: [active("squash"), equal("ff", "no")],
3140
+ origin: "git",
3141
+ reason: "Squashing is incompatible with explicitly disabling fast-forward.",
3142
+ source: git("builtin/merge.c")
3143
+ },
3144
+ {
3145
+ id: "merge.squash-no-ff-false",
3146
+ kind: "forbid",
3147
+ when: [active("squash"), equal("ff", false)],
3148
+ origin: "git",
3149
+ reason: "Squashing is incompatible with explicitly disabling fast-forward.",
3150
+ source: git("builtin/merge.c")
3151
+ }
3152
+ ],
3153
+ pull: [
3154
+ {
3155
+ id: "pull.depth-unshallow",
3156
+ kind: "exclusive",
3157
+ keys: ["depth", "unshallow"],
3158
+ origin: "git",
3159
+ reason: "Unshallow cannot use an explicit depth.",
3160
+ source: git("builtin/fetch.c")
3161
+ },
3162
+ {
3163
+ id: "pull.deepen-depth",
3164
+ kind: "forbid",
3165
+ when: [{ key: "deepen", test: "nonzero" }, present("depth")],
3166
+ origin: "git",
3167
+ reason: "A nonzero deepen value cannot be combined with depth.",
3168
+ source: git("builtin/fetch.c")
3169
+ },
3170
+ {
3171
+ id: "pull.deepen-unshallow",
3172
+ kind: "forbid",
3173
+ when: [{ key: "deepen", test: "nonzero" }, active("unshallow")],
3174
+ origin: "git",
3175
+ reason: "A nonzero deepen value cannot be combined with unshallow.",
3176
+ source: git("builtin/fetch.c")
3177
+ },
3178
+ {
3179
+ id: "pull.depth",
3180
+ kind: "integer",
3181
+ key: "depth",
3182
+ min: Number.MIN_SAFE_INTEGER,
3183
+ origin: "type-git",
3184
+ reason: "Numeric options use safe integers to avoid fractional truncation or loss of precision.",
3185
+ source: contract
3186
+ },
3187
+ {
3188
+ id: "pull.depth-range",
3189
+ kind: "range",
3190
+ key: "depth",
3191
+ min: 1,
3192
+ origin: "git",
3193
+ reason: "Git rejects values below 1 for depth.",
3194
+ source: git("builtin/pull.c")
3195
+ },
3196
+ {
3197
+ id: "pull.jobs",
3198
+ kind: "integer",
3199
+ key: "jobs",
3200
+ min: Number.MIN_SAFE_INTEGER,
3201
+ origin: "type-git",
3202
+ reason: "Numeric options use safe integers to avoid fractional truncation or loss of precision.",
3203
+ source: contract
3204
+ },
3205
+ {
3206
+ id: "pull.deepen",
3207
+ kind: "integer",
3208
+ key: "deepen",
3209
+ min: Number.MIN_SAFE_INTEGER,
3210
+ origin: "type-git",
3211
+ reason: "Numeric options use safe integers to avoid fractional truncation or loss of precision.",
3212
+ source: contract
3213
+ },
3214
+ {
3215
+ id: "pull.deepen-range",
3216
+ kind: "range",
3217
+ key: "deepen",
3218
+ min: 0,
3219
+ origin: "git",
3220
+ reason: "Git rejects values below 0 for deepen.",
3221
+ source: git("builtin/pull.c")
3222
+ }
3223
+ ],
3224
+ switch: [
3225
+ {
3226
+ id: "switch.create-forceCreate-detach-orphan",
3227
+ kind: "exclusive",
3228
+ keys: ["create", "forceCreate", "detach", "orphan"],
3229
+ origin: "git",
3230
+ reason: "Git rejects these simultaneous modes or operands.",
3231
+ source: git("builtin/checkout.c")
3232
+ },
3233
+ {
3234
+ id: "switch.discard-merge",
3235
+ kind: "exclusive",
3236
+ keys: ["discard", "merge"],
3237
+ origin: "git",
3238
+ reason: "Git rejects these simultaneous modes or operands.",
3239
+ source: git("builtin/checkout.c")
3240
+ },
3241
+ {
3242
+ id: "switch.force-merge",
3243
+ kind: "exclusive",
3244
+ keys: ["force", "merge"],
3245
+ origin: "git",
3246
+ reason: "Git rejects these simultaneous modes or operands.",
3247
+ source: git("builtin/checkout.c")
3248
+ }
3249
+ ],
3250
+ cherryPick: [
3251
+ {
3252
+ id: "cherryPick.abort-continue-skip",
3253
+ kind: "exclusive",
3254
+ keys: ["abort", "continue", "skip"],
3255
+ origin: "git",
3256
+ reason: "Git rejects these simultaneous modes or operands.",
3257
+ source: git("builtin/revert.c")
3258
+ },
3259
+ {
3260
+ id: "cherryPick.unsupported",
3261
+ kind: "unsupported",
3262
+ keys: ["noVerify"],
3263
+ origin: "git",
3264
+ reason: "These options are absent from the command syntax.",
3265
+ source: git("builtin/revert.c")
3266
+ },
3267
+ {
3268
+ id: "cherryPick.mainline",
3269
+ kind: "integer",
3270
+ key: "mainline",
3271
+ min: Number.MIN_SAFE_INTEGER,
3272
+ origin: "type-git",
3273
+ reason: "Numeric options use safe integers to avoid fractional truncation or loss of precision.",
3274
+ source: contract
3275
+ },
3276
+ {
3277
+ id: "cherryPick.mainline-range",
3278
+ kind: "scalar",
3279
+ key: "mainline",
3280
+ parser: NUMERIC_CALLBACK_PARSERS.mainline,
3281
+ origin: "git",
3282
+ reason: "Git requires a positive mainline after decimal strtol conversion and narrowing to int.",
3283
+ source: "https://github.com/git/git/blob/v2.55.0/builtin/revert.c"
3284
+ },
3285
+ {
3286
+ id: "cherryPick.abort-options",
3287
+ kind: "conflicts",
3288
+ when: active("abort"),
3289
+ others: [
3290
+ active("noCommit"),
3291
+ active("signoff"),
3292
+ active("mainline"),
3293
+ active("strategy"),
3294
+ active("strategyOption"),
3295
+ active("appendCommitName"),
3296
+ active("ff"),
3297
+ active("empty"),
3298
+ present("rerereAutoupdate")
3299
+ ],
3300
+ origin: "git",
3301
+ reason: "The sequencer rejects this option with a control operation.",
3302
+ source: git("builtin/revert.c")
3303
+ },
3304
+ {
3305
+ id: "cherryPick.continue-options",
3306
+ kind: "conflicts",
3307
+ when: active("continue"),
3308
+ others: [
3309
+ active("noCommit"),
3310
+ active("signoff"),
3311
+ active("mainline"),
3312
+ active("strategy"),
3313
+ active("strategyOption"),
3314
+ active("appendCommitName"),
3315
+ active("ff"),
3316
+ active("empty"),
3317
+ present("rerereAutoupdate")
3318
+ ],
3319
+ origin: "git",
3320
+ reason: "The sequencer rejects this option with a control operation.",
3321
+ source: git("builtin/revert.c")
3322
+ },
3323
+ {
3324
+ id: "cherryPick.skip-options",
3325
+ kind: "conflicts",
3326
+ when: active("skip"),
3327
+ others: [
3328
+ active("noCommit"),
3329
+ active("signoff"),
3330
+ active("mainline"),
3331
+ active("strategy"),
3332
+ active("strategyOption"),
3333
+ active("appendCommitName"),
3334
+ active("ff"),
3335
+ active("empty"),
3336
+ present("rerereAutoupdate")
3337
+ ],
3338
+ origin: "git",
3339
+ reason: "The sequencer rejects this option with a control operation.",
3340
+ source: git("builtin/revert.c")
3341
+ },
3342
+ {
3343
+ id: "cherryPick.ff-signoff",
3344
+ kind: "exclusive",
3345
+ keys: ["ff", "signoff"],
3346
+ origin: "git",
3347
+ reason: "Fast-forward cherry-picks reject this commit modification option.",
3348
+ source: git("builtin/revert.c")
3349
+ },
3350
+ {
3351
+ id: "cherryPick.ff-noCommit",
3352
+ kind: "exclusive",
3353
+ keys: ["ff", "noCommit"],
3354
+ origin: "git",
3355
+ reason: "Fast-forward cherry-picks reject this commit modification option.",
3356
+ source: git("builtin/revert.c")
3357
+ },
3358
+ {
3359
+ id: "cherryPick.ff-appendCommitName",
3360
+ kind: "exclusive",
3361
+ keys: ["ff", "appendCommitName"],
3362
+ origin: "git",
3363
+ reason: "Fast-forward cherry-picks reject this commit modification option.",
3364
+ source: git("builtin/revert.c")
3365
+ },
3366
+ {
3367
+ id: "cherryPick.ff-edit",
3368
+ kind: "exclusive",
3369
+ keys: ["ff", "edit"],
3370
+ origin: "git",
3371
+ reason: "Fast-forward cherry-picks reject this commit modification option.",
3372
+ source: git("builtin/revert.c")
3373
+ }
3374
+ ],
3375
+ revert: [
3376
+ {
3377
+ id: "revert.abort-continue-skip",
3378
+ kind: "exclusive",
3379
+ keys: ["abort", "continue", "skip"],
3380
+ origin: "git",
3381
+ reason: "Git rejects these simultaneous modes or operands.",
3382
+ source: git("builtin/revert.c")
3383
+ },
3384
+ {
3385
+ id: "revert.unsupported",
3386
+ kind: "unsupported",
3387
+ keys: ["noVerify"],
3388
+ origin: "git",
3389
+ reason: "These options are absent from the command syntax.",
3390
+ source: git("builtin/revert.c")
3391
+ },
3392
+ {
3393
+ id: "revert.mainline",
3394
+ kind: "integer",
3395
+ key: "mainline",
3396
+ min: Number.MIN_SAFE_INTEGER,
3397
+ origin: "type-git",
3398
+ reason: "Numeric options use safe integers to avoid fractional truncation or loss of precision.",
3399
+ source: contract
3400
+ },
3401
+ {
3402
+ id: "revert.mainline-range",
3403
+ kind: "scalar",
3404
+ key: "mainline",
3405
+ parser: NUMERIC_CALLBACK_PARSERS.mainline,
3406
+ origin: "git",
3407
+ reason: "Git requires a positive mainline after decimal strtol conversion and narrowing to int.",
3408
+ source: "https://github.com/git/git/blob/v2.55.0/builtin/revert.c"
3409
+ },
3410
+ {
3411
+ id: "revert.abort-options",
3412
+ kind: "conflicts",
3413
+ when: active("abort"),
3414
+ others: [
3415
+ active("noCommit"),
3416
+ active("signoff"),
3417
+ active("mainline"),
3418
+ active("strategy"),
3419
+ active("strategyOption"),
3420
+ present("rerereAutoupdate")
3421
+ ],
3422
+ origin: "git",
3423
+ reason: "The sequencer rejects this option with a control operation.",
3424
+ source: git("builtin/revert.c")
3425
+ },
3426
+ {
3427
+ id: "revert.continue-options",
3428
+ kind: "conflicts",
3429
+ when: active("continue"),
3430
+ others: [
3431
+ active("noCommit"),
3432
+ active("signoff"),
3433
+ active("mainline"),
3434
+ active("strategy"),
3435
+ active("strategyOption"),
3436
+ present("rerereAutoupdate")
3437
+ ],
3438
+ origin: "git",
3439
+ reason: "The sequencer rejects this option with a control operation.",
3440
+ source: git("builtin/revert.c")
3441
+ },
3442
+ {
3443
+ id: "revert.skip-options",
3444
+ kind: "conflicts",
3445
+ when: active("skip"),
3446
+ others: [
3447
+ active("noCommit"),
3448
+ active("signoff"),
3449
+ active("mainline"),
3450
+ active("strategy"),
3451
+ active("strategyOption"),
3452
+ present("rerereAutoupdate")
3453
+ ],
3454
+ origin: "git",
3455
+ reason: "The sequencer rejects this option with a control operation.",
3456
+ source: git("builtin/revert.c")
3457
+ }
3458
+ ],
3459
+ rebase: [
3460
+ {
3461
+ id: "rebase.abort-continue-skip",
3462
+ kind: "exclusive",
3463
+ keys: ["abort", "continue", "skip"],
3464
+ origin: "git",
3465
+ reason: "Git rejects these simultaneous modes or operands.",
3466
+ source: git("builtin/rebase.c")
3467
+ },
3468
+ {
3469
+ id: "rebase.keepBase-onto",
3470
+ kind: "exclusive",
3471
+ keys: ["keepBase", "onto"],
3472
+ origin: "git",
3473
+ reason: "Git rejects these simultaneous modes or operands.",
3474
+ source: git("builtin/rebase.c")
3475
+ },
3476
+ {
3477
+ id: "rebase.keepBase-root",
3478
+ kind: "exclusive",
3479
+ keys: ["keepBase", "root"],
3480
+ origin: "git",
3481
+ reason: "Git rejects these simultaneous modes or operands.",
3482
+ source: git("builtin/rebase.c")
3483
+ },
3484
+ {
3485
+ id: "rebase.apply-rebaseMerges",
3486
+ kind: "exclusive",
3487
+ keys: ["apply", "rebaseMerges"],
3488
+ origin: "git",
3489
+ reason: "Git rejects these simultaneous modes or operands.",
3490
+ source: git("builtin/rebase.c")
3491
+ },
3492
+ {
3493
+ id: "rebase.apply-strategy",
3494
+ kind: "exclusive",
3495
+ keys: ["apply", "strategy"],
3496
+ origin: "git",
3497
+ reason: "Git rejects these simultaneous modes or operands.",
3498
+ source: git("builtin/rebase.c")
3499
+ },
3500
+ {
3501
+ id: "rebase.apply-exec",
3502
+ kind: "exclusive",
3503
+ keys: ["apply", "exec"],
3504
+ origin: "git",
3505
+ reason: "Git rejects these simultaneous modes or operands.",
3506
+ source: git("builtin/rebase.c")
3507
+ },
3508
+ {
3509
+ id: "rebase.unsupported",
3510
+ kind: "unsupported",
3511
+ keys: ["interactive"],
3512
+ origin: "type-git",
3513
+ reason: "Interactive todo editing requires an editor protocol absent from this API.",
3514
+ source: contract
3515
+ },
3516
+ {
3517
+ id: "rebase.root-forkPoint",
3518
+ kind: "exclusive",
3519
+ keys: ["root", "forkPoint"],
3520
+ origin: "git",
3521
+ reason: "Root rebases cannot use fork-point detection.",
3522
+ source: git("builtin/rebase.c")
3523
+ }
3524
+ ],
3525
+ restore: [
3526
+ {
3527
+ id: "restore.staged-conflict",
3528
+ kind: "conflicts",
3529
+ when: active("staged"),
3530
+ others: [active("ours"), active("theirs"), active("merge"), active("conflict")],
3531
+ origin: "git",
3532
+ reason: "Git rejects index-stage and conflict recreation modes with --staged.",
3533
+ source: git("builtin/checkout.c")
3534
+ },
3535
+ {
3536
+ id: "restore.source-ours",
3537
+ kind: "exclusive",
3538
+ keys: ["source", "ours"],
3539
+ origin: "git",
3540
+ reason: "Git rejects these simultaneous modes or operands.",
3541
+ source: git("builtin/checkout.c")
3542
+ },
3543
+ {
3544
+ id: "restore.source-theirs",
3545
+ kind: "exclusive",
3546
+ keys: ["source", "theirs"],
3547
+ origin: "git",
3548
+ reason: "Git rejects these simultaneous modes or operands.",
3549
+ source: git("builtin/checkout.c")
3550
+ },
3551
+ {
3552
+ id: "restore.source-merge",
3553
+ kind: "exclusive",
3554
+ keys: ["source", "merge"],
3555
+ origin: "git",
3556
+ reason: "Git rejects these simultaneous modes or operands.",
3557
+ source: git("builtin/checkout.c")
3558
+ },
3559
+ {
3560
+ id: "restore.source-conflict",
3561
+ kind: "exclusive",
3562
+ keys: ["source", "conflict"],
3563
+ origin: "git",
3564
+ reason: "Git rejects these simultaneous modes or operands.",
3565
+ source: git("builtin/checkout.c")
3566
+ }
3567
+ ],
3568
+ clean: [
3569
+ {
3570
+ id: "clean.ignored-onlyIgnored",
3571
+ kind: "exclusive",
3572
+ keys: ["ignored", "onlyIgnored"],
3573
+ origin: "git",
3574
+ reason: "Git rejects these simultaneous modes or operands.",
3575
+ source: git("builtin/clean.c")
3576
+ }
3577
+ ],
3578
+ worktreeAdd: [
3579
+ {
3580
+ id: "worktreeAdd.branch-detach",
3581
+ kind: "exclusive",
3582
+ keys: ["branch", "detach"],
3583
+ origin: "git",
3584
+ reason: "Git rejects these simultaneous modes or operands.",
3585
+ source: git("builtin/worktree.c")
3586
+ },
3587
+ {
3588
+ id: "worktreeAdd.orphan-detach",
3589
+ kind: "exclusive",
3590
+ keys: ["orphan", "detach"],
3591
+ origin: "git",
3592
+ reason: "Git rejects these simultaneous modes or operands.",
3593
+ source: git("builtin/worktree.c")
3594
+ },
3595
+ {
3596
+ id: "worktreeAdd.orphan-track",
3597
+ kind: "exclusive",
3598
+ keys: ["orphan", "track"],
3599
+ origin: "git",
3600
+ reason: "An orphan worktree cannot track another branch.",
3601
+ source: git("builtin/worktree.c")
3602
+ },
3603
+ {
3604
+ id: "worktreeAdd.orphan-commitish",
3605
+ kind: "exclusive",
3606
+ keys: ["orphan", "commitish"],
3607
+ origin: "git",
3608
+ reason: "An orphan worktree cannot take a commit-ish.",
3609
+ source: git("builtin/worktree.c")
3610
+ },
3611
+ {
3612
+ id: "worktreeAdd.orphan-no-checkout",
3613
+ kind: "forbid",
3614
+ when: [active("orphan"), equal("checkout", false)],
3615
+ origin: "git",
3616
+ reason: "An orphan worktree cannot disable checkout.",
3617
+ source: git("builtin/worktree.c")
3618
+ }
3619
+ ],
3620
+ remoteSetHead: [
3621
+ {
3622
+ id: "remoteSetHead.auto-delete",
3623
+ kind: "exclusive",
3624
+ keys: ["auto", "delete"],
3625
+ origin: "git",
3626
+ reason: "Git rejects these simultaneous modes or operands.",
3627
+ source: git("builtin/remote.c")
3628
+ }
3629
+ ],
3630
+ configGet: [
3631
+ {
3632
+ id: "configGet.all-default",
3633
+ kind: "exclusive",
3634
+ keys: ["all", "default"],
3635
+ origin: "git",
3636
+ reason: "Git rejects these simultaneous modes or operands.",
3637
+ source: git("builtin/config.c")
3638
+ }
3639
+ ],
3640
+ configList: [
3641
+ {
3642
+ id: "configList.unsupported",
3643
+ kind: "unsupported",
3644
+ keys: ["nameOnly"],
3645
+ origin: "type-git",
3646
+ reason: "Config entries require values; names-only output does not provide them.",
3647
+ source: contract
3648
+ }
3649
+ ],
3650
+ lfsPull: [
3651
+ {
3652
+ id: "lfsPull.unsupported",
3653
+ kind: "unsupported",
3654
+ keys: ["ref"],
3655
+ origin: "git",
3656
+ reason: "These options are absent from the command syntax.",
3657
+ source: lfs("pull")
3658
+ }
3659
+ ],
3660
+ lfsPush: [
3661
+ {
3662
+ id: "lfsPush.ref-objectId",
3663
+ kind: "exclusive",
3664
+ keys: ["ref", "objectId"],
3665
+ origin: "git",
3666
+ reason: "Git rejects these simultaneous modes or operands.",
3667
+ source: lfs("push")
3668
+ }
3669
+ ],
3670
+ lfsFetch: [
3671
+ {
3672
+ id: "lfsFetch.all-include",
3673
+ kind: "exclusive",
3674
+ keys: ["all", "include"],
3675
+ origin: "git",
3676
+ reason: "Git rejects these simultaneous modes or operands.",
3677
+ source: lfs("fetch")
3678
+ },
3679
+ {
3680
+ id: "lfsFetch.all-exclude",
3681
+ kind: "exclusive",
3682
+ keys: ["all", "exclude"],
3683
+ origin: "git",
3684
+ reason: "Git rejects these simultaneous modes or operands.",
3685
+ source: lfs("fetch")
3686
+ },
3687
+ {
3688
+ id: "lfsFetch.all-recent",
3689
+ kind: "exclusive",
3690
+ keys: ["all", "recent"],
3691
+ origin: "git",
3692
+ reason: "Git rejects these simultaneous modes or operands.",
3693
+ source: lfs("fetch")
3694
+ }
3695
+ ],
3696
+ lfsStatus: [
3697
+ {
3698
+ id: "lfsStatus.unsupported",
3699
+ kind: "unsupported",
3700
+ keys: ["porcelain"],
3701
+ origin: "type-git",
3702
+ reason: "LFS status metadata is parsed from JSON.",
3703
+ source: contract
3704
+ },
3705
+ {
3706
+ id: "lfsStatus.json",
3707
+ kind: "value",
3708
+ key: "json",
3709
+ allowed: [true],
3710
+ origin: "type-git",
3711
+ reason: "Structured LFS metadata is parsed from JSON.",
3712
+ source: contract
3713
+ }
3714
+ ],
3715
+ lfsLsFiles: [
3716
+ {
3717
+ id: "lfsLsFiles.unsupported",
3718
+ kind: "unsupported",
3719
+ keys: ["debug", "nameOnly"],
3720
+ origin: "type-git",
3721
+ reason: "LFS file metadata requires JSON records with object IDs and sizes.",
3722
+ source: contract
3723
+ },
3724
+ {
3725
+ id: "lfsLsFiles.json",
3726
+ kind: "value",
3727
+ key: "json",
3728
+ allowed: [true],
3729
+ origin: "type-git",
3730
+ reason: "Structured LFS metadata is parsed from JSON.",
3731
+ source: contract
3732
+ }
3733
+ ]
3734
+ };
3735
+
3736
+ // src/constraints/inputs.ts
3737
+ var INPUT_CONSTRAINTS = {
3738
+ lfsCheckout: [
3739
+ {
3740
+ id: "lfsCheckout.conflict-path",
3741
+ kind: "arity",
3742
+ key: "patterns",
3743
+ min: 1,
3744
+ max: 1,
3745
+ when: { key: "to", test: "nonempty" },
3746
+ origin: "git",
3747
+ reason: "Conflict checkout requires exactly one object path.",
3748
+ source: "https://github.com/git-lfs/git-lfs/blob/v3.8.0/commands/command_checkout.go"
3749
+ }
3750
+ ],
3751
+ // repo.commit emits no paths. These stay runtime checks: modeling them in CommitOpts
3752
+ // multiplies the compiler's work on every caller of the option type.
3753
+ commitPaths: [
3754
+ {
3755
+ id: "commit.only-paths",
3756
+ kind: "requiresAny",
3757
+ when: { key: "only", test: "active" },
3758
+ choices: [
3759
+ { key: "pathspecFromFile", test: "nonempty" },
3760
+ { key: "allowEmpty", test: "active" },
3761
+ { key: "amend", test: "active" },
3762
+ { key: "fixup", test: "startsWith", value: "amend:" }
3763
+ ],
3764
+ origin: "git",
3765
+ // Git 2.32+ also refuses amend with a plain fixup, but older Git accepts it.
3766
+ reason: "Only mode without paths requires allowEmpty, amend or an amend: fixup.",
3767
+ source: "https://github.com/git/git/blob/v2.55.0/builtin/commit.c"
3768
+ },
3769
+ {
3770
+ id: "commit.reword-content",
3771
+ kind: "conflicts",
3772
+ when: { key: "fixup", test: "startsWith", value: "reword:" },
3773
+ others: [
3774
+ { key: "include", test: "active" },
3775
+ { key: "only", test: "active" },
3776
+ { key: "all", test: "active" }
3777
+ ],
3778
+ origin: "git",
3779
+ reason: "A reword: fixup cannot include changed files.",
3780
+ source: "https://github.com/git/git/blob/v2.55.0/builtin/commit.c"
3781
+ }
3782
+ ],
3783
+ pathspec: [
3784
+ {
3785
+ id: "pathspec.file-operands",
3786
+ kind: "arity",
3787
+ key: "paths",
3788
+ min: 0,
3789
+ max: 0,
3790
+ // The convenience APIs emit --pathspec-from-file only for a non-empty value.
3791
+ when: { key: "pathspecFromFile", test: "nonempty" },
3792
+ origin: "git",
3793
+ reason: "Pathspec files cannot be combined with command-line pathspecs.",
3794
+ source: "https://github.com/git/git/blob/v2.55.0/builtin/add.c"
3795
+ },
3796
+ {
3797
+ id: "pathspec.empty-pathspec",
3798
+ kind: "forbid",
3799
+ when: [{ key: "paths", test: "includes", valueKey: "emptyPathspec" }],
3800
+ origin: "git",
3801
+ reason: "parse_pathspec rejects an empty pathspec; add, rm, path checkout and restore all pass their paths to it.",
3802
+ source: "https://github.com/git/git/blob/v2.55.0/pathspec.c#L638-L642"
3803
+ }
3804
+ ],
3805
+ switchTarget: [
3806
+ {
3807
+ id: "switch.empty-branch",
3808
+ kind: "forbid",
3809
+ when: [{ key: "branch", test: "equals", value: "" }],
3810
+ origin: "git",
3811
+ reason: "An empty switch target is never a valid reference or branch name, with or without create, force-create or orphan.",
3812
+ source: "https://github.com/git/git/blob/v2.55.0/builtin/checkout.c"
3813
+ }
3814
+ ]
3815
+ };
3816
+
3817
+ // src/constraints/scalars.ts
3818
+ function lfsBytes(value) {
3819
+ if (typeof value !== "string" && typeof value !== "number") {
3820
+ return void 0;
3821
+ }
3822
+ const match = /^([0-9.,]*)(.*)$/s.exec(String(value));
3823
+ if (!match) {
3824
+ return void 0;
3825
+ }
3826
+ const digits = match[1].replaceAll(",", "");
3827
+ if (digits !== "" && !/^(?:\d+(?:\.\d*)?|\.\d+)$/.test(digits)) {
3828
+ return void 0;
3829
+ }
3830
+ const unit = match[2].trim().toLowerCase();
3831
+ const multiplier = {
3832
+ "": 1,
3833
+ b: 1,
3834
+ kb: 1e3,
3835
+ mb: 1e3 ** 2,
3836
+ gb: 1e3 ** 3,
3837
+ tb: 1e3 ** 4,
3838
+ pb: 1e3 ** 5,
3839
+ kib: 1024,
3840
+ mib: 1024 ** 2,
3841
+ gib: 1024 ** 3,
3842
+ tib: 1024 ** 4,
3843
+ pib: 1024 ** 5
3844
+ };
3845
+ if (!(unit in multiplier)) {
3846
+ return void 0;
3847
+ }
3848
+ const bytes = Number(digits) * multiplier[unit];
3849
+ return Number.isFinite(bytes) && bytes < 2 ** 64 ? Math.trunc(bytes) : void 0;
3850
+ }
3851
+
3852
+ // src/constraints/model.ts
3853
+ function matches(predicate, options) {
3854
+ const value = options[predicate.key];
3855
+ switch (predicate.test) {
3856
+ case "optionValuesNonempty":
3857
+ return Array.isArray(value) && value.every(
3858
+ (token) => !Array.isArray(token) || token[0] !== predicate.value || typeof token[1] === "string" && token[1].length > 0
3859
+ );
3860
+ case "lengthEquals":
3861
+ return Array.isArray(value) && value.length === predicate.value;
3862
+ case "equalsKey":
3863
+ return value === options[predicate.valueKey];
3864
+ case "includes":
3865
+ return Array.isArray(value) && value.includes(options[predicate.valueKey]);
3866
+ case "gitDisabled":
3867
+ return gitBoolean(value) === false;
3868
+ case "gitEnabled":
3869
+ return gitBoolean(value) === true || value === "on-demand";
3870
+ case "inactive":
3871
+ return value === void 0 || value === false;
3872
+ case "active":
3873
+ return value !== void 0 && value !== false;
3874
+ case "nonzero":
3875
+ return value !== void 0 && value !== false && value !== 0 && value !== 0n;
3876
+ case "nonblank":
3877
+ return (typeof value === "string" ? value : Array.isArray(value) ? value.join(",") : "").trim().length > 0;
3878
+ case "nonempty":
3879
+ return (typeof value === "string" || Array.isArray(value)) && value.length > 0;
3880
+ case "bytesPositive":
3881
+ return (lfsBytes(value) ?? 0) > 0;
3882
+ case "timestampNotDefault":
3883
+ return (typeof value === "number" || typeof value === "bigint") && value !== TIMESTAMP_DEFAULT;
3884
+ case "positive":
3885
+ return (typeof value === "number" || typeof value === "bigint") && value > 0;
3886
+ case "present":
3887
+ return value !== void 0;
3888
+ case "equals":
3889
+ return value === predicate.value;
3890
+ case "notEquals":
3891
+ return value !== predicate.value;
3892
+ case "startsWith":
3893
+ return typeof value === "string" && value.startsWith(predicate.value);
3894
+ }
3895
+ }
3896
+ function violations(rules, options, scalarContext) {
3897
+ return rules.filter((rule) => violates(rule, options, scalarContext));
3898
+ }
3899
+ function violates(rule, options, scalarContext) {
3900
+ if (rule.nativeEmptyPickaxe && scalarContext?.emptyPickaxeRejected === false) {
3901
+ return false;
3902
+ }
3903
+ if (rule.nativeWhatchangedOptIn && scalarContext?.whatchangedOptInRequired === false) {
3904
+ return false;
3905
+ }
3906
+ if (rule.nativePackRedundantOptIn && scalarContext?.packRedundantOptInRequired === false) {
3907
+ return false;
3908
+ }
3909
+ if (rule.guard && !rule.guard.every((p) => matches(p, options))) {
3910
+ return false;
3911
+ }
3912
+ switch (rule.kind) {
3913
+ case "arity": {
3914
+ if (rule.when && !conditions(rule.when).every((p) => matches(p, options))) {
3915
+ return false;
3916
+ }
3917
+ const value = options[rule.key];
3918
+ const count = value === void 0 ? 0 : Array.isArray(value) ? value.length : 1;
3919
+ return count < rule.min || rule.max !== void 0 && count > rule.max;
3920
+ }
3921
+ case "required":
3922
+ return !rule.required.every((p) => matches(p, options));
3923
+ case "exclusive":
3924
+ return rule.keys.filter((key) => matches({ key, test: "active" }, options)).length > 1;
3925
+ case "exclusiveGroups":
3926
+ return rule.groups.filter((group) => group.some((p) => matches(p, options))).length > 1;
3927
+ case "requiresAny":
3928
+ return matches(rule.when, options) && !rule.choices.some((p) => matches(p, options));
3929
+ case "requires":
3930
+ return matches(rule.when, options) && !rule.required.every((p) => matches(p, options));
3931
+ case "conflicts":
3932
+ return matches(rule.when, options) && rule.others.some((p) => matches(p, options));
3933
+ case "forbid":
3934
+ return rule.when.every((p) => matches(p, options));
3935
+ case "unsupported":
3936
+ return rule.keys.some((key) => options[key] !== void 0);
3937
+ case "eachInteger": {
3938
+ const items = options[rule.key];
3939
+ return items !== void 0 && (!Array.isArray(items) || items.some(
3940
+ (item) => item !== PYTHON_INTEGER_DEFERRED && (typeof item === "bigint" ? item < BigInt(rule.min) : !Number.isInteger(item) || item < rule.min)
3941
+ ));
3942
+ }
3943
+ case "elements": {
3944
+ const items = options[rule.key];
3945
+ return items !== void 0 && (!Array.isArray(items) || items.some((item) => !rule.allowed.includes(item)));
3946
+ }
3947
+ case "eachScalar": {
3948
+ const items = options[rule.key];
3949
+ return items !== void 0 && (!Array.isArray(items) || items.some(
3950
+ (item) => item === void 0 || // The guard has already been evaluated against the complete list.
3951
+ violates({ ...rule, kind: "scalar", guard: [] }, { [rule.key]: item }, scalarContext)
3952
+ ));
3953
+ }
3954
+ case "scalar":
3955
+ return options[rule.key] !== void 0 && !parseGitScalar(
3956
+ rule.parser,
3957
+ options[rule.key],
3958
+ void 0,
3959
+ scalarContext?.longBits,
3960
+ scalarContext?.sizeTBits,
3961
+ scalarContext?.binaryIntegers,
3962
+ scalarContext?.integerProfile,
3963
+ scalarContext?.negativeMagnitudes,
3964
+ scalarContext?.decimalCallbacks,
3965
+ scalarContext?.unsignedChar,
3966
+ scalarContext?.booleanSource,
3967
+ scalarContext?.booleanBinaryIntegers,
3968
+ scalarContext?.booleanCapabilities,
3969
+ scalarContext?.compoundNegatedOverflow,
3970
+ scalarContext?.depthAtoiBits,
3971
+ scalarContext?.combineEmptyComponents
3972
+ ).valid;
3973
+ case "value":
3974
+ return options[rule.key] !== void 0 && !rule.allowed.some((v) => v === options[rule.key]);
3975
+ case "range":
3976
+ return (!rule.when || matches(rule.when, options)) && typeof options[rule.key] === "number" && (options[rule.key] < rule.min || rule.max !== void 0 && options[rule.key] > rule.max);
3977
+ case "integer": {
3978
+ const value = options[rule.key];
3979
+ return value !== void 0 && !(rule.allowBoolean && typeof value === "boolean") && (!Number.isSafeInteger(value) || value < rule.min);
3980
+ }
3981
+ }
3982
+ }
3983
+ function conditions(when) {
3984
+ return when === void 0 ? [] : Array.isArray(when) ? when : [when];
3985
+ }
3986
+
3987
+ // src/core/option-rules.ts
3988
+ function validateOptions(name, options, scalarContext) {
3989
+ const errors = violations(
3990
+ COMMAND_CONSTRAINTS[name],
3991
+ options ?? {},
3992
+ scalarContext
3993
+ );
3994
+ if (errors.length > 0) {
3995
+ throw new GitArgumentError(`${name}: ${errors.map((r) => `[${r.id}] ${r.reason}`).join("; ")}`);
3996
+ }
3997
+ }
3998
+ var REV_PARSE_QUERY_KEYS = [
3999
+ "gitDir",
4000
+ "absoluteGitDir",
4001
+ "gitCommonDir",
4002
+ "showToplevel",
4003
+ "showCdup",
4004
+ "showPrefix",
4005
+ "showSuperprojectWorkingTree",
4006
+ "sharedIndexPath",
4007
+ "gitPath",
4008
+ "resolveGitDir",
4009
+ "isInsideGitDir",
4010
+ "isInsideWorkTree",
4011
+ "isBareRepository",
4012
+ "isShallowRepository",
4013
+ "all",
4014
+ "branches",
4015
+ "tags",
4016
+ "remotes",
4017
+ "glob",
4018
+ "disambiguate",
4019
+ "showObjectFormat",
4020
+ "showRefFormat",
4021
+ "localEnvVars"
4022
+ ];
4023
+ function validateRevParseQuery(query) {
4024
+ const values = query;
4025
+ const selected = REV_PARSE_QUERY_KEYS.filter((key) => values[key] !== void 0);
4026
+ if (selected.length !== 1 || values[selected[0]] !== true && typeof values[selected[0]] !== "string") {
4027
+ throw new GitArgumentError("revParse: specify exactly one query");
4028
+ }
4029
+ }
4030
+ function validateRevParseRefOpts(opts = {}) {
4031
+ if (opts.quiet && !opts.verify) {
4032
+ throw new GitArgumentError("revParse: quiet requires verify");
4033
+ }
4034
+ }
4035
+ function validatePathInput(name, paths, opts) {
4036
+ validateInput(
4037
+ "pathspec",
4038
+ {
4039
+ paths: Array.isArray(paths) ? paths : [paths],
4040
+ pathspecFromFile: opts?.pathspecFromFile,
4041
+ emptyPathspec: ""
4042
+ },
4043
+ name
4044
+ );
4045
+ }
4046
+ function validateInput(name, input, command = name) {
4047
+ const errors = violations(INPUT_CONSTRAINTS[name], input);
4048
+ if (errors.length > 0) {
4049
+ throw new GitArgumentError(
4050
+ `${command}: ${errors.map((r) => `[${r.id}] ${r.reason}`).join("; ")}`
4051
+ );
4052
+ }
4053
+ }
4054
+
4055
+ // src/runner/cli-runner.ts
4056
+ import process2 from "process";
4057
+ var FATAL_ERROR_PATTERN = /fatal:\s*(.+)/i;
4058
+ var ERROR_PATTERN = /error:\s*(.+)/i;
4059
+ var LINE_SEPARATOR_PATTERN = /\r|\n/;
4060
+ var GIT_TRACE_PATTERN = /^\d{2}:\d{2}:\d{2}\.\d+\s+(?:trace:|[A-Za-z0-9_.-]+\.c:)/;
4061
+ var TRACE_ENV_PATTERN = /^(?:GIT_TRACE\w*|GIT_CURL_VERBOSE)$/i;
4062
+ function stripTraceEnv(env) {
4063
+ for (const key of Object.keys(env)) {
4064
+ if (TRACE_ENV_PATTERN.test(key)) {
4065
+ delete env[key];
4066
+ }
4067
+ }
4068
+ }
4069
+ function toLfsProgress(info) {
4070
+ if (!info) {
4071
+ return null;
4072
+ }
4073
+ return {
4074
+ direction: info.direction,
4075
+ bytesSoFar: info.bytesSoFar,
4076
+ bytesTotal: info.bytesTotal,
4077
+ bitrate: info.bitrate ?? void 0,
4078
+ filesCompleted: info.filesCompleted,
4079
+ filesTotal: info.filesTotal,
4080
+ percent: info.percent
4081
+ };
4082
+ }
4083
+ function toGitProgress(info, message) {
4084
+ if (!info) {
4085
+ return null;
4086
+ }
4087
+ return {
4088
+ phase: info.phase,
4089
+ current: info.current,
4090
+ total: info.total,
4091
+ percent: info.percent,
4092
+ message
4093
+ };
4094
+ }
4095
+ function processProgressLine(line, onProgress, onLfsProgress) {
4096
+ const trimmed = line.trim();
4097
+ if (!trimmed) {
4098
+ return;
4099
+ }
4100
+ if (onLfsProgress) {
4101
+ const lfsProgress = toLfsProgress(parseLfsStderrProgress(trimmed));
4102
+ if (lfsProgress) {
4103
+ onLfsProgress(lfsProgress);
4104
+ return;
4105
+ }
4106
+ }
4107
+ if (onProgress) {
4108
+ const gitProgress = toGitProgress(parseGitProgress(trimmed), trimmed);
4109
+ if (gitProgress) {
4110
+ onProgress(gitProgress);
4111
+ }
4112
+ }
4113
+ }
4114
+ function validateEnv(env) {
4115
+ if (env === void 0) {
4116
+ return;
4117
+ }
4118
+ if (env === null || typeof env !== "object" || Array.isArray(env)) {
4119
+ throw new GitArgumentError("env must be an object of string values");
4120
+ }
4121
+ for (const [name, value] of Object.entries(env)) {
4122
+ if (name === "" || name === "__proto__" || name.includes("=") || name.includes("\0")) {
4123
+ throw new GitArgumentError(
4124
+ `env name must be non-empty, not __proto__, and contain neither '=' nor NUL: ${JSON.stringify(name)}`
4125
+ );
4126
+ }
4127
+ if (typeof value !== "string" || value.includes("\0")) {
4128
+ throw new GitArgumentError(`env value for ${name} must be a string without NUL`);
4129
+ }
4130
+ }
4131
+ }
4132
+ function applyEnvOverride(env, override) {
4133
+ const isWindows = process2.platform === "win32";
4134
+ for (const [name, value] of Object.entries(override)) {
4135
+ if (isWindows) {
4136
+ const lower = name.toLowerCase();
4137
+ for (const key of Object.keys(env)) {
4138
+ if (key !== name && key.toLowerCase() === lower) {
4139
+ delete env[key];
4140
+ }
4141
+ }
4142
+ }
4143
+ env[name] = value;
4144
+ }
4145
+ }
4146
+ function validateIO(opts) {
4147
+ validateEnv(opts?.env);
4148
+ if (opts?.stdout !== void 0 && opts.stdout !== "text" && opts.stdout !== "bytes") {
4149
+ throw new GitArgumentError("stdout must be text or bytes");
4150
+ }
4151
+ const input = opts?.stdin;
4152
+ if (input !== void 0 && typeof input !== "string" && !(ArrayBuffer.isView(input) && Object.prototype.toString.call(input) === "[object Uint8Array]")) {
4153
+ throw new GitArgumentError("stdin must be a string or Uint8Array");
4154
+ }
4155
+ }
4156
+ var internalsOf;
4157
+ function cliRunnerInternals(runner) {
4158
+ return internalsOf(runner);
4159
+ }
4160
+ var CliRunner = class _CliRunner {
4161
+ static {
4162
+ internalsOf = (runner) => ({
4163
+ exec: runner.exec,
4164
+ fs: runner.fs,
4165
+ run: runner.run.bind(runner),
4166
+ runBytes: runner.runBytes.bind(runner),
4167
+ runCompanion: runner.runCompanion.bind(runner),
4168
+ runCompanionBytes: runner.runCompanionBytes.bind(runner),
4169
+ probe: runner.probe.bind(runner),
4170
+ runRepositoryProbe: runner.runRepositoryProbe.bind(runner),
4171
+ observeDepthAtoi: runner.observeDepthAtoi.bind(runner)
4172
+ });
4173
+ }
4174
+ exec;
4175
+ fs;
4176
+ gitBinary;
4177
+ companionBinaries;
4178
+ baseEnv;
4179
+ inheritEnv;
4180
+ pathPrefix;
4181
+ home;
4182
+ credential;
4183
+ audit;
4184
+ constructor(adapters, options) {
4185
+ this.exec = adapters.exec;
4186
+ this.fs = adapters.fs;
4187
+ this.gitBinary = options?.gitBinary ?? "git";
4188
+ this.companionBinaries = {
4189
+ scalar: options?.companionBinaries?.scalar ?? "scalar",
4190
+ gitk: options?.companionBinaries?.gitk ?? "gitk",
4191
+ gitweb: options?.companionBinaries?.gitweb ?? "gitweb.cgi"
4192
+ };
4193
+ this.baseEnv = options?.env ?? {};
4194
+ this.inheritEnv = options?.inheritEnv;
4195
+ this.pathPrefix = options?.pathPrefix ?? [];
4196
+ this.home = options?.home;
4197
+ this.credential = options?.credential;
4198
+ this.audit = options?.audit;
4199
+ }
4200
+ /**
4201
+ * Create a new CliRunner with additional options merged
4202
+ *
4203
+ * Used to create a runner for a specific repository with custom environment
4204
+ */
4205
+ withOptions(options) {
4206
+ const mergedEnv = { ...this.baseEnv, ...options.env };
4207
+ const mergedPathPrefix = [...this.pathPrefix, ...options.pathPrefix ?? []];
4208
+ const inheritEnv = options.inheritEnv ?? this.inheritEnv;
4209
+ const home = options.home ?? this.home;
4210
+ const credential = options.credential ?? this.credential;
4211
+ const audit = options.audit ?? this.audit;
4212
+ return new _CliRunner(
4213
+ {
4214
+ exec: this.exec,
4215
+ fs: this.fs
4216
+ },
4217
+ {
4218
+ gitBinary: options.gitBinary ?? this.gitBinary,
4219
+ companionBinaries: {
4220
+ scalar: options.companionBinaries?.scalar ?? this.companionBinaries.scalar,
4221
+ gitk: options.companionBinaries?.gitk ?? this.companionBinaries.gitk,
4222
+ gitweb: options.companionBinaries?.gitweb ?? this.companionBinaries.gitweb
4223
+ },
4224
+ env: mergedEnv,
4225
+ inheritEnv,
4226
+ pathPrefix: mergedPathPrefix,
4227
+ home,
4228
+ credential,
4229
+ audit
4230
+ }
4231
+ );
4232
+ }
4233
+ /**
4234
+ * Build command argv based on execution context
4235
+ */
4236
+ buildArgv(context, args) {
4237
+ const argv = [this.gitBinary];
4238
+ if (this.credential?.helper) {
4239
+ argv.push("-c", `credential.helper=${this.credential.helper}`);
4240
+ }
4241
+ switch (context.type) {
4242
+ case "global":
4243
+ break;
4244
+ case "worktree":
4245
+ argv.push("-C", context.workdir);
4246
+ break;
4247
+ case "bare":
4248
+ argv.push("--git-dir", context.gitDir);
4249
+ break;
4250
+ }
4251
+ argv.push(...args);
4252
+ return argv;
4253
+ }
4254
+ /**
4255
+ * Build the effective environment for command execution
4256
+ *
4257
+ * Seeds the environment from the inherited (allowlisted) parent variables, then layers
4258
+ * the configured `env`, home directory, and PATH prefix overrides on top. The parent
4259
+ * process environment is never forwarded wholesale unless `inheritEnv: true` is set
4260
+ * (environment variable traversal prevention).
4261
+ */
4262
+ buildEnv(executable, internal = false) {
4263
+ let inheritEnv = this.inheritEnv;
4264
+ if (executable === "gitk" && inheritEnv !== true && inheritEnv !== false && typeof inheritEnv !== "function") {
4265
+ const displayVariables = ["DISPLAY", "XAUTHORITY"];
4266
+ inheritEnv = Array.isArray(inheritEnv) ? [...inheritEnv, ...displayVariables] : { ...inheritEnv, add: [...inheritEnv?.add ?? [], ...displayVariables] };
4267
+ }
4268
+ const env = {
4269
+ ...resolveInheritedEnv(process2.env, inheritEnv, process2.platform),
4270
+ ...this.baseEnv
4271
+ };
4272
+ if (this.home) {
4273
+ env.HOME = this.home;
4274
+ env.USERPROFILE = this.home;
4275
+ }
4276
+ const allPathPrefixes = [...this.pathPrefix];
4277
+ if (this.credential?.helperPath) {
4278
+ const helperDir = this.extractDirectory(this.credential.helperPath);
4279
+ if (helperDir) {
4280
+ allPathPrefixes.unshift(helperDir);
4281
+ }
4282
+ }
4283
+ if (allPathPrefixes.length > 0) {
4284
+ const isWindows = process2.platform === "win32";
4285
+ const separator = isWindows ? ";" : ":";
4286
+ const pathKey = isWindows ? Object.keys(env).find((key) => key.toLowerCase() === "path") ?? "PATH" : "PATH";
4287
+ const currentPath = env[pathKey] ?? "";
4288
+ env[pathKey] = [...allPathPrefixes, currentPath].join(separator);
4289
+ }
4290
+ if (this.audit?.onTrace && !internal) {
4291
+ if (env.GIT_TRACE === void 0) {
4292
+ env.GIT_TRACE = "1";
4293
+ } else if (!env.GIT_TRACE || env.GIT_TRACE === "0") {
4294
+ console.warn(
4295
+ "type-git: onTrace callback provided but GIT_TRACE is disabled. Trace events will not be emitted."
4296
+ );
4297
+ }
4298
+ }
4299
+ return env;
4300
+ }
4301
+ /**
4302
+ * Extract directory from a file path
4303
+ */
4304
+ extractDirectory(filePath) {
4305
+ const separator = filePath.includes("/") ? "/" : "\\";
4306
+ const lastIndex = filePath.lastIndexOf(separator);
4307
+ if (lastIndex > 0) {
4308
+ return filePath.substring(0, lastIndex);
4309
+ }
4310
+ return void 0;
4311
+ }
4312
+ /**
4313
+ * Run a Git command
4314
+ */
4315
+ /** Resolve environment-dependent filter constraints before convenience execution. */
4316
+ async validateFilterOptions(context, name, options, opts) {
4317
+ await this.validateNativeOptions(context, name, options, opts);
4318
+ }
4319
+ /** Resolve mainline narrowing against the executable used by the convenience call. */
4320
+ async validateMainlineOptions(context, name, options, opts) {
4321
+ await this.validateNativeOptions(context, name, options, opts);
4322
+ }
4323
+ /**
4324
+ * Run a probe of a builtin that requires a repository (RUN_SETUP).
4325
+ *
4326
+ * Global contexts carry no repository, so such probes would otherwise discover one from the
4327
+ * process working directory: outside a repository Git dies before parsing options, and inside
4328
+ * an unrelated one its configuration leaks in. Run them against a throwaway empty repository.
4329
+ */
4330
+ async runRepositoryProbe(context, args, opts) {
4331
+ if (context.type !== "global") {
4332
+ return await this.probe(context, args, opts);
4333
+ }
4334
+ if (opts.signal?.aborted) {
4335
+ return { stdout: "", stderr: "", exitCode: -1, aborted: true };
4336
+ }
4337
+ const directory = this.fs.createTempDirectory ? await this.fs.createTempDirectory("type-git-probe-") : void 0;
4338
+ const file = directory === void 0 ? await this.fs.createTempFile("type-git-probe-") : "";
4339
+ const gitDir = directory ?? `${file}-repo`;
4340
+ try {
4341
+ const init = await this.probe(context, ["init", "--bare", "--quiet", gitDir], opts);
4342
+ if (init.aborted || init.exitCode !== 0) {
4343
+ return init;
4344
+ }
4345
+ return await this.probe({ type: "bare", gitDir }, args, opts);
4346
+ } finally {
4347
+ await this.fs.deleteDirectory(gitDir);
4348
+ if (directory === void 0) {
4349
+ await this.fs.deleteFile(file);
4350
+ }
4351
+ }
4352
+ }
4353
+ /** Observe atoi using an existing file so clone stops before transport or destination creation. */
4354
+ async observeDepthAtoi(context, opts) {
4355
+ if (!this.fs.writeFile) {
4356
+ return { bits: void 0, result: void 0 };
4357
+ }
4358
+ const destination = await this.fs.createTempFile("type-git-depth-profile-");
4359
+ try {
4360
+ await this.fs.writeFile(destination, "");
4361
+ const result = await this.probe(
4362
+ context,
4363
+ ["clone", "--depth=2147483648", "type-git-depth-profile:invalid", destination],
4364
+ {
4365
+ ...opts?.env ? { env: opts.env } : {},
4366
+ ...opts?.signal ? { signal: opts.signal } : {}
4367
+ }
4368
+ );
4369
+ let bits;
4370
+ if (!result.aborted && result.exitCode === 128) {
4371
+ if (result.stderr.trim() === "fatal: depth 2147483648 is not a positive number") {
4372
+ bits = 64;
4373
+ } else if (result.stderr.trim() === `fatal: destination path '${destination}' already exists and is not an empty directory.`) {
4374
+ bits = 32;
4375
+ }
4376
+ }
4377
+ return { bits, result };
4378
+ } finally {
4379
+ await this.fs.deleteFile(destination);
4380
+ }
4381
+ }
4382
+ /** Resolve depth and other native constraints for a convenience fetch call. */
4383
+ async validateFetchOptions(context, options, opts) {
4384
+ await this.validateNativeOptions(context, "fetch", options, opts);
4385
+ }
4386
+ /** Check universally invalid input first, then only the native dimensions that affect validity. */
4387
+ async validateNativeOptions(context, name, options, opts) {
4388
+ validateIO(opts);
4389
+ const depth = name === "clone" || name === "fetch" ? options?.depth : void 0;
4390
+ const depthValid = [32, 64].filter(
4391
+ (bits) => depth === void 0 || validInitialDepth(depth, bits)
4392
+ );
4393
+ let depthAtoiBits = depthValid[0] ?? 64;
4394
+ const valid = [];
4395
+ let firstError;
4396
+ for (const longBits2 of [32, 64]) {
4397
+ for (const negativeMagnitudes2 of [false, true]) {
4398
+ for (const unsignedChar2 of [false, true]) {
4399
+ try {
4400
+ validateOptions(name, options, {
4401
+ longBits: longBits2,
4402
+ negativeMagnitudes: negativeMagnitudes2,
4403
+ unsignedChar: unsignedChar2,
4404
+ depthAtoiBits
4405
+ });
4406
+ valid.push({ longBits: longBits2, negativeMagnitudes: negativeMagnitudes2, unsignedChar: unsignedChar2, depthAtoiBits });
4407
+ } catch (error) {
4408
+ if (!(error instanceof GitArgumentError)) {
4409
+ throw error;
4410
+ }
4411
+ firstError ??= error;
4412
+ }
4413
+ }
4414
+ }
4415
+ }
4416
+ if (valid.length === 0) {
4417
+ throw firstError;
4418
+ }
4419
+ if (depth !== void 0 && depthValid.length === 1) {
4420
+ const observed = await this.observeDepthAtoi(context, opts);
4421
+ if (observed.result?.aborted) {
4422
+ throw this.mapError(observed.result, context, this.buildArgv(context, ["clone"]));
4423
+ }
4424
+ if (observed.bits !== void 0) {
4425
+ depthAtoiBits = observed.bits;
4426
+ validateOptions(name, options, { ...valid[0], depthAtoiBits });
4427
+ }
4428
+ }
4429
+ const probeOptions = {
4430
+ ...opts?.env ? { env: opts.env } : {},
4431
+ ...opts?.signal ? { signal: opts.signal } : {}
4432
+ };
4433
+ const filter = options?.filter;
4434
+ if (typeof filter === "string" && objectFilterUsesEmptyComponent(filter)) {
4435
+ const args = [...OBJECT_FILTER_EMPTY_PROBE];
4436
+ const probe = await this.probe(context, args, probeOptions);
4437
+ if (probe.aborted) {
4438
+ throw this.mapError(probe, context, this.buildArgv(context, args));
4439
+ }
4440
+ if (objectFilterCombineEmptyComponents(probe) === false) {
4441
+ validateOptions(name, options, { ...valid[0], depthAtoiBits, combineEmptyComponents: false });
4442
+ }
4443
+ }
4444
+ if (valid.length === 8) {
4445
+ return;
4446
+ }
4447
+ let unsignedChar = true;
4448
+ const charDependent = [32, 64].some(
4449
+ (candidateLongBits) => [false, true].some(
4450
+ (negative) => valid.some(
4451
+ (e) => e.longBits === candidateLongBits && e.negativeMagnitudes === negative && e.unsignedChar === false
4452
+ ) !== valid.some(
4453
+ (e) => e.longBits === candidateLongBits && e.negativeMagnitudes === negative && e.unsignedChar === true
4454
+ )
4455
+ )
4456
+ );
4457
+ if (charDependent) {
4458
+ const args = [...OBJECT_FILTER_CHAR_PROBE];
4459
+ const probe = await this.probe(context, args, probeOptions);
4460
+ if (probe.aborted) {
4461
+ throw this.mapError(probe, context, this.buildArgv(context, args));
4462
+ }
4463
+ const observed = objectFilterUnsignedChar(probe);
4464
+ if (observed === void 0) {
4465
+ return;
4466
+ }
4467
+ unsignedChar = observed;
4468
+ }
4469
+ const charValid = valid.filter((e) => e.unsignedChar === unsignedChar);
4470
+ let negativeMagnitudes = false;
4471
+ const signDependent = [32, 64].some(
4472
+ (candidateLongBits) => charValid.some(
4473
+ (e) => e.longBits === candidateLongBits && e.negativeMagnitudes === false
4474
+ ) !== charValid.some((e) => e.longBits === candidateLongBits && e.negativeMagnitudes === true)
4475
+ );
4476
+ if (signDependent) {
4477
+ const args = ["pack-objects", "--max-pack-size=-0", "-h"];
4478
+ const sign = await this.runRepositoryProbe(context, args, probeOptions);
4479
+ if (sign.aborted) {
4480
+ throw this.mapError(sign, context, this.buildArgv(context, args));
4481
+ }
4482
+ if (sign.exitCode === 129 && /expects .*non-negative|not in range/.test(sign.stderr)) {
4483
+ negativeMagnitudes = false;
4484
+ } else if (sign.exitCode === 129 && (sign.stdout + sign.stderr).includes("usage:") && !/error:|fatal:/.test(sign.stderr)) {
4485
+ negativeMagnitudes = true;
4486
+ } else {
4487
+ return;
4488
+ }
4489
+ }
4490
+ const selected = charValid.filter((e) => e.negativeMagnitudes === negativeMagnitudes);
4491
+ if (selected.length === 0) {
4492
+ validateOptions(name, options, {
4493
+ longBits: 64,
4494
+ negativeMagnitudes,
4495
+ unsignedChar,
4496
+ depthAtoiBits
4497
+ });
4498
+ throw firstError;
4499
+ }
4500
+ let longBits = selected[0].longBits;
4501
+ if (selected.length !== 2) {
4502
+ const args = ["version", "--build-options"];
4503
+ const widths = await this.probe(context, args, probeOptions);
4504
+ if (widths.aborted) {
4505
+ throw this.mapError(widths, context, this.buildArgv(context, args));
4506
+ }
4507
+ const bytes = /^sizeof-long: ([48])\r?$/m.exec(widths.stdout)?.[1];
4508
+ if (widths.exitCode !== 0 || !bytes) {
4509
+ if (name === "cherryPick" || name === "revert") {
4510
+ return;
4511
+ }
4512
+ throw new GitArgumentError(
4513
+ "Cannot determine integer widths of the selected Git executable"
4514
+ );
4515
+ }
4516
+ longBits = bytes === "4" ? 32 : 64;
4517
+ }
4518
+ validateOptions(name, options, { longBits, negativeMagnitudes, unsignedChar, depthAtoiBits });
4519
+ }
4520
+ /** Text execution remains independent of extra command output-mode options. */
4521
+ async run(context, args, opts) {
4522
+ return await this.execute(context, args, opts, false);
4523
+ }
4524
+ /**
4525
+ * Run an internal capability probe.
4526
+ *
4527
+ * Probes classify Git's own diagnostics, so tracing is stripped from their environment
4528
+ * (including GIT_TRACE* variables configured by the caller) and they never reach the
4529
+ * user's audit or trace callbacks.
4530
+ */
4531
+ async probe(context, args, opts) {
4532
+ return await this.execute(context, args, opts, false, void 0, true);
4533
+ }
4534
+ async runBytes(context, args, opts) {
4535
+ return await this.execute(context, args, opts, true);
4536
+ }
4537
+ /** Run a standalone upstream program through the shared text execution path. */
4538
+ async runCompanion(context, executable, args, opts) {
4539
+ return await this.execute(context, args, opts, false, executable);
4540
+ }
4541
+ /** Capture standalone program output without text decoding. */
4542
+ async runCompanionBytes(context, executable, args, opts) {
4543
+ return await this.execute(context, args, opts, true, executable);
4544
+ }
4545
+ /** Validate per-call options, then spawn one Git or companion process and collect its result. */
4546
+ async execute(context, args, opts, binary, executable, internal = false) {
4547
+ validateIO({ stdin: opts?.stdin, env: opts?.env });
4548
+ const argv = executable ? [this.companionBinaries[executable], ...args] : this.buildArgv(context, args);
4549
+ const { signal, onProgress, onLfsProgress, env: envOverride } = opts ?? {};
4550
+ if (signal?.aborted) {
4551
+ return {
4552
+ stdout: binary ? new Uint8Array(0) : "",
4553
+ stderr: "",
4554
+ exitCode: -1,
4555
+ aborted: true
4556
+ };
4557
+ }
4558
+ const env = this.buildEnv(executable, internal);
4559
+ if (envOverride) {
4560
+ applyEnvOverride(env, envOverride);
4561
+ }
4562
+ if (internal) {
4563
+ stripTraceEnv(env);
4564
+ }
4565
+ const audit = internal ? void 0 : this.audit;
4566
+ if (executable && this.credential?.helper) {
4567
+ const quote = (value) => `'${value.replace(/['!]/g, "'\\$&'")}'`;
4568
+ const parameter = quote(`credential.helper=${this.credential.helper}`);
4569
+ env.GIT_CONFIG_PARAMETERS = env.GIT_CONFIG_PARAMETERS ? `${env.GIT_CONFIG_PARAMETERS} ${parameter}` : parameter;
4570
+ }
4571
+ if (onLfsProgress) {
4572
+ env.GIT_LFS_FORCE_PROGRESS = "1";
4573
+ }
4574
+ const startTimestamp = Date.now();
4575
+ if (audit?.onAudit) {
4576
+ audit.onAudit({
4577
+ type: "start",
4578
+ timestamp: startTimestamp,
4579
+ argv,
4580
+ context
4581
+ });
4582
+ }
4583
+ let stderrBuffer = "";
4584
+ const needsStderrStreaming = onProgress || onLfsProgress || audit?.onTrace;
4585
+ let result;
4586
+ try {
4587
+ const spawnProcess = binary ? this.exec.spawnBytes : this.exec.spawn;
4588
+ if (!spawnProcess) {
4589
+ throw new GitError(
4590
+ "CapabilityMissing",
4591
+ "The selected execution adapter does not support binary stdout"
4592
+ );
4593
+ }
4594
+ result = await spawnProcess.call(
4595
+ this.exec,
4596
+ {
4597
+ argv,
4598
+ stdin: opts?.stdin,
4599
+ env,
4600
+ // The env above is already fully resolved (including any inherited variables),
4601
+ // so the adapter must not merge the parent environment on top of it.
4602
+ inheritEnv: false,
4603
+ cwd: context.type === "worktree" ? context.workdir : executable && context.type === "bare" ? context.gitDir : void 0,
4604
+ signal
4605
+ },
4606
+ needsStderrStreaming ? {
4607
+ onStderr: (chunk) => {
4608
+ stderrBuffer += chunk;
4609
+ const lines = stderrBuffer.split(LINE_SEPARATOR_PATTERN);
4610
+ stderrBuffer = lines.pop() ?? "";
4611
+ for (const line of lines) {
4612
+ this.processStderrLine(line, onProgress, onLfsProgress, audit?.onTrace);
4613
+ }
4614
+ }
4615
+ } : void 0
4616
+ );
4617
+ if (stderrBuffer.trim() && needsStderrStreaming) {
4618
+ this.processStderrLine(stderrBuffer, onProgress, onLfsProgress, audit?.onTrace);
4619
+ }
4620
+ } catch (error) {
4621
+ if (audit?.onAudit) {
4622
+ const endTimestamp = Date.now();
4623
+ audit.onAudit({
4624
+ type: "end",
4625
+ timestamp: endTimestamp,
4626
+ argv,
4627
+ context,
4628
+ stdout: "",
4629
+ stderr: error instanceof Error ? error.message : String(error),
4630
+ exitCode: -1,
4631
+ aborted: signal?.aborted ?? false,
4632
+ duration: endTimestamp - startTimestamp
4633
+ });
4634
+ }
4635
+ if (error instanceof GitError) {
4636
+ throw error;
4637
+ }
4638
+ throw new GitError(
4639
+ signal?.aborted ? "Aborted" : "SpawnFailed",
4640
+ error instanceof Error ? error.message : String(error),
4641
+ {
4642
+ argv,
4643
+ ...context.type === "worktree" ? { workdir: context.workdir } : context.type === "bare" ? { gitDir: context.gitDir } : {}
4644
+ }
4645
+ );
4646
+ }
4647
+ if (audit?.onAudit) {
4648
+ const endTimestamp = Date.now();
4649
+ audit.onAudit({
4650
+ type: "end",
4651
+ timestamp: endTimestamp,
4652
+ argv,
4653
+ context,
4654
+ stdout: typeof result.stdout === "string" ? result.stdout : "",
4655
+ ...typeof result.stdout === "string" ? {} : { stdoutBytes: new Uint8Array(result.stdout) },
4656
+ stderr: result.stderr,
4657
+ exitCode: result.exitCode,
4658
+ ...result.signal ? { signal: result.signal } : {},
4659
+ aborted: result.aborted,
4660
+ duration: endTimestamp - startTimestamp
4661
+ });
4662
+ }
4663
+ return {
4664
+ stdout: result.stdout,
4665
+ stderr: result.stderr,
4666
+ exitCode: result.exitCode,
4667
+ ...result.signal ? { signal: result.signal } : {},
4668
+ aborted: result.aborted
4669
+ };
4670
+ }
4671
+ /**
4672
+ * Process a single line from stderr for progress and trace callbacks
4673
+ */
4674
+ processStderrLine(line, onProgress, onLfsProgress, onTrace) {
4675
+ const trimmed = line.trim();
4676
+ if (!trimmed) {
4677
+ return;
4678
+ }
4679
+ if (onTrace && GIT_TRACE_PATTERN.test(trimmed)) {
4680
+ onTrace({
4681
+ timestamp: Date.now(),
4682
+ line: trimmed
4683
+ });
4684
+ return;
4685
+ }
4686
+ processProgressLine(line, onProgress, onLfsProgress);
4687
+ }
4688
+ /**
4689
+ * Map Git result to GitError if needed
4690
+ */
4691
+ mapError(result, context, argv) {
4692
+ if (result.aborted) {
4693
+ return new GitError("Aborted", "Command was aborted", {
4694
+ argv,
4695
+ exitCode: result.exitCode,
4696
+ ...result.signal ? { signal: result.signal } : {},
4697
+ stdout: result.stdout,
4698
+ stderr: result.stderr,
4699
+ ...context.type === "worktree" && { workdir: context.workdir },
4700
+ ...context.type === "bare" && { gitDir: context.gitDir }
4701
+ });
4702
+ }
4703
+ if (result.exitCode !== 0) {
4704
+ const kind = this.classifyError(result);
4705
+ const message = this.extractErrorMessage(result);
4706
+ const category = detectErrorCategory(result.stderr);
4707
+ return new GitError(
4708
+ kind,
4709
+ message,
4710
+ {
4711
+ argv,
4712
+ exitCode: result.exitCode,
4713
+ ...result.signal ? { signal: result.signal } : {},
4714
+ stdout: result.stdout,
4715
+ stderr: result.stderr,
4716
+ ...context.type === "worktree" && { workdir: context.workdir },
4717
+ ...context.type === "bare" && { gitDir: context.gitDir }
4718
+ },
4719
+ category
4720
+ );
4721
+ }
4722
+ return null;
4723
+ }
4724
+ /**
4725
+ * Classify error type based on stderr content
4726
+ */
4727
+ classifyError(result) {
4728
+ const stderr = result.stderr.toLowerCase();
4729
+ if (result.signal) {
4730
+ return "NonZeroExit";
4731
+ }
4732
+ if (result.exitCode === -1 || stderr.includes("command not found")) {
4733
+ return "SpawnFailed";
4734
+ }
4735
+ return "NonZeroExit";
4736
+ }
4737
+ /**
4738
+ * Extract user-friendly error message from stderr
4739
+ */
4740
+ extractErrorMessage(result) {
4741
+ const stderr = result.stderr.trim();
4742
+ const fatalMatch = stderr.match(FATAL_ERROR_PATTERN);
4743
+ const fatalMessage = fatalMatch?.[1];
4744
+ if (fatalMessage) {
4745
+ return fatalMessage;
4746
+ }
4747
+ const errorMatch = stderr.match(ERROR_PATTERN);
4748
+ const errorMessage = errorMatch?.[1];
4749
+ if (errorMessage) {
4750
+ return errorMessage;
4751
+ }
4752
+ const firstLine = stderr.split("\n")[0];
4753
+ return firstLine || `Git exited with code ${result.exitCode}`;
4754
+ }
4755
+ /**
4756
+ * Run a command and throw on error
4757
+ */
4758
+ checkResult(context, args, result) {
4759
+ const error = this.mapError(result, context, this.buildArgv(context, args));
4760
+ if (error) {
4761
+ throw error;
4762
+ }
4763
+ }
4764
+ async runOrThrow(context, args, opts) {
4765
+ const result = await this.run(context, args, opts);
4766
+ const error = this.mapError(result, context, this.buildArgv(context, args));
4767
+ if (error) {
4768
+ throw error;
4769
+ }
4770
+ return result;
4771
+ }
4772
+ };
4773
+
4774
+ export {
4775
+ nonEmpty,
4776
+ isNonEmpty,
4777
+ GitError,
4778
+ GitArgumentError,
4779
+ asciiLower,
4780
+ DECIMAL_CALLBACK_PROBES,
4781
+ decimalCallbackFamily,
4782
+ isCompoundDecimal,
4783
+ isBooleanCallback,
4784
+ nativeCLongBits,
4785
+ nativeSizeTBits,
4786
+ objectFilterUsesBinary,
4787
+ objectFilterUsesNegativeMagnitude,
4788
+ objectFilterUsesHighBytes,
4789
+ objectFilterUsesEmptyComponent,
4790
+ OBJECT_FILTER_EMPTY_PROBE,
4791
+ objectFilterCombineEmptyComponents,
4792
+ OBJECT_FILTER_CHAR_PROBE,
4793
+ objectFilterUnsignedChar,
4794
+ parseGitScalar,
4795
+ matches,
4796
+ violations,
4797
+ validateOptions,
4798
+ validateRevParseQuery,
4799
+ validateRevParseRefOpts,
4800
+ validatePathInput,
4801
+ validateInput,
4802
+ registerCommandHost,
4803
+ commandHostOf,
4804
+ parseLines,
4805
+ parseRecords,
4806
+ parseJson,
4807
+ parseKeyValue,
4808
+ parsePorcelainV2,
4809
+ parseGitProgress,
4810
+ parseLfsProgress,
4811
+ parseLsRemote,
4812
+ parseLsTree,
4813
+ GIT_LOG_FORMAT,
4814
+ parseGitLog,
4815
+ parseWorktreeList,
4816
+ detectErrorCategory,
4817
+ DEFAULT_ENV_ALLOWLIST,
4818
+ resolveInheritedEnv,
4819
+ validateIO,
4820
+ cliRunnerInternals,
4821
+ CliRunner
4822
+ };