type-git 0.3.0-beta.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -17
- package/dist/adapters/bun/index.cjs +6332 -0
- package/dist/adapters/bun/index.cjs.map +1 -1
- package/dist/adapters/bun/index.d.cts +11 -6
- package/dist/adapters/bun/index.d.ts +11 -6
- package/dist/adapters/bun/index.js +6321 -0
- package/dist/adapters/bun/index.js.map +1 -1
- package/dist/adapters/deno/index.cjs +6332 -0
- package/dist/adapters/deno/index.cjs.map +1 -1
- package/dist/adapters/deno/index.d.cts +11 -6
- package/dist/adapters/deno/index.d.ts +11 -6
- package/dist/adapters/deno/index.js +6321 -0
- package/dist/adapters/deno/index.js.map +1 -1
- package/dist/adapters/node/index.cjs +1212 -1085
- package/dist/adapters/node/index.cjs.map +1 -1
- package/dist/adapters/node/index.d.cts +8 -4268
- package/dist/adapters/node/index.d.ts +8 -4268
- package/dist/adapters/node/index.js +1212 -1085
- package/dist/adapters/node/index.js.map +1 -1
- package/dist/client-DAAbUvgo.d.cts +5291 -0
- package/dist/client-DAAbUvgo.d.ts +5291 -0
- package/dist/index.cjs +1199 -1088
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1199 -1088
- package/dist/index.js.map +1 -1
- package/docs/migrations/0.4.0.md +93 -0
- package/package.json +4 -3
- package/dist/adapters-CZ8wj9Kr.d.cts +0 -850
- package/dist/adapters-CZ8wj9Kr.d.ts +0 -850
package/dist/index.cjs
CHANGED
|
@@ -101,6 +101,267 @@ var GitArgumentError = class extends Error {
|
|
|
101
101
|
}
|
|
102
102
|
};
|
|
103
103
|
|
|
104
|
+
// src/core/option-rules.ts
|
|
105
|
+
var OPTION_RULES = {
|
|
106
|
+
clone: {
|
|
107
|
+
exclusive: [
|
|
108
|
+
["ipv4", "ipv6"],
|
|
109
|
+
["depth", "shallowSince"],
|
|
110
|
+
["depth", "shallowExclude"],
|
|
111
|
+
["bare", "separateGitDir"],
|
|
112
|
+
["mirror", "separateGitDir"]
|
|
113
|
+
],
|
|
114
|
+
unsupported: []
|
|
115
|
+
},
|
|
116
|
+
init: { exclusive: [["bare", "separateGitDir"]], unsupported: [] },
|
|
117
|
+
lsRemote: { exclusive: [], unsupported: ["getUrl", "symref"] },
|
|
118
|
+
lsTree: { exclusive: [["nameOnly", "objectOnly", "long"]], unsupported: [] },
|
|
119
|
+
status: { exclusive: [["noRenames", "findRenames"]], unsupported: ["verbose"] },
|
|
120
|
+
log: {
|
|
121
|
+
exclusive: [
|
|
122
|
+
["merges", "noMerges"],
|
|
123
|
+
["since", "after"],
|
|
124
|
+
["until", "before"]
|
|
125
|
+
],
|
|
126
|
+
unsupported: [
|
|
127
|
+
"source",
|
|
128
|
+
"decorate",
|
|
129
|
+
"decorateRefs",
|
|
130
|
+
"decorateRefsExclude",
|
|
131
|
+
"stat",
|
|
132
|
+
"shortstat",
|
|
133
|
+
"nameOnly",
|
|
134
|
+
"nameStatus"
|
|
135
|
+
]
|
|
136
|
+
},
|
|
137
|
+
fetch: {
|
|
138
|
+
exclusive: [
|
|
139
|
+
["ipv4", "ipv6"],
|
|
140
|
+
["tags", "noTags"],
|
|
141
|
+
["depth", "deepen", "unshallow"],
|
|
142
|
+
["depth", "shallowSince"],
|
|
143
|
+
["depth", "shallowExclude"],
|
|
144
|
+
["all", "remote"],
|
|
145
|
+
["all", "refspec"]
|
|
146
|
+
],
|
|
147
|
+
unsupported: ["multiple"]
|
|
148
|
+
},
|
|
149
|
+
push: {
|
|
150
|
+
exclusive: [
|
|
151
|
+
["ipv4", "ipv6"],
|
|
152
|
+
["force", "forceWithLease"],
|
|
153
|
+
["all", "mirror", "refspec"],
|
|
154
|
+
["all", "tags"],
|
|
155
|
+
["branches", "mirror", "refspec"],
|
|
156
|
+
["branches", "tags"],
|
|
157
|
+
["mirror", "tags"],
|
|
158
|
+
["remote", "repo"]
|
|
159
|
+
],
|
|
160
|
+
unsupported: []
|
|
161
|
+
},
|
|
162
|
+
add: { exclusive: [["all", "update"]], unsupported: ["interactive", "patch"] },
|
|
163
|
+
checkoutBranch: {
|
|
164
|
+
exclusive: [["createBranch", "forceCreateBranch", "detach", "orphan"]],
|
|
165
|
+
unsupported: []
|
|
166
|
+
},
|
|
167
|
+
checkoutPath: {
|
|
168
|
+
exclusive: [
|
|
169
|
+
["ours", "theirs"],
|
|
170
|
+
["source", "ours"],
|
|
171
|
+
["source", "theirs"]
|
|
172
|
+
],
|
|
173
|
+
unsupported: []
|
|
174
|
+
},
|
|
175
|
+
commit: {
|
|
176
|
+
exclusive: [
|
|
177
|
+
["message", "file", "reuseMessage"],
|
|
178
|
+
["fixup", "squash"],
|
|
179
|
+
["include", "only", "all"],
|
|
180
|
+
["gpgSign", "noGpgSign"]
|
|
181
|
+
],
|
|
182
|
+
unsupported: ["dryRun", "reeditMessage"]
|
|
183
|
+
},
|
|
184
|
+
diff: {
|
|
185
|
+
exclusive: [
|
|
186
|
+
["nameOnly", "nameStatus", "stat", "numstat", "patchWithRaw", "patchWithStat"],
|
|
187
|
+
["nameOnly", "patch"],
|
|
188
|
+
["nameStatus", "patch"],
|
|
189
|
+
["nameOnly", "wordDiff"],
|
|
190
|
+
["nameStatus", "wordDiff"],
|
|
191
|
+
["nameOnly", "context"],
|
|
192
|
+
["nameStatus", "context"]
|
|
193
|
+
],
|
|
194
|
+
unsupported: ["noIndex"]
|
|
195
|
+
},
|
|
196
|
+
merge: {
|
|
197
|
+
controls: ["abort", "continue", "quit"],
|
|
198
|
+
exclusive: [
|
|
199
|
+
["abort", "continue", "quit"],
|
|
200
|
+
["noDiffstat", "stat"]
|
|
201
|
+
],
|
|
202
|
+
unsupported: []
|
|
203
|
+
},
|
|
204
|
+
pull: {
|
|
205
|
+
exclusive: [
|
|
206
|
+
["ipv4", "ipv6"],
|
|
207
|
+
["noStat", "stat"],
|
|
208
|
+
["depth", "deepen", "unshallow"],
|
|
209
|
+
["depth", "shallowSince"],
|
|
210
|
+
["depth", "shallowExclude"]
|
|
211
|
+
],
|
|
212
|
+
unsupported: []
|
|
213
|
+
},
|
|
214
|
+
switch: {
|
|
215
|
+
exclusive: [
|
|
216
|
+
["create", "forceCreate", "detach", "orphan"],
|
|
217
|
+
["discard", "merge"],
|
|
218
|
+
["force", "merge"]
|
|
219
|
+
],
|
|
220
|
+
unsupported: []
|
|
221
|
+
},
|
|
222
|
+
cherryPick: {
|
|
223
|
+
controls: ["abort", "continue", "skip"],
|
|
224
|
+
exclusive: [["abort", "continue", "skip"]],
|
|
225
|
+
unsupported: ["noVerify"]
|
|
226
|
+
},
|
|
227
|
+
revert: {
|
|
228
|
+
controls: ["abort", "continue", "skip"],
|
|
229
|
+
exclusive: [["abort", "continue", "skip"]],
|
|
230
|
+
unsupported: ["noVerify"]
|
|
231
|
+
},
|
|
232
|
+
rebase: {
|
|
233
|
+
controls: ["abort", "continue", "skip"],
|
|
234
|
+
exclusive: [
|
|
235
|
+
["abort", "continue", "skip"],
|
|
236
|
+
["keepBase", "onto"],
|
|
237
|
+
["keepBase", "root"],
|
|
238
|
+
["apply", "rebaseMerges"],
|
|
239
|
+
["apply", "strategy"],
|
|
240
|
+
["apply", "exec"]
|
|
241
|
+
],
|
|
242
|
+
unsupported: ["interactive"]
|
|
243
|
+
},
|
|
244
|
+
restore: {
|
|
245
|
+
exclusive: [
|
|
246
|
+
["ours", "theirs"],
|
|
247
|
+
["source", "ours"],
|
|
248
|
+
["source", "theirs"],
|
|
249
|
+
["source", "merge"],
|
|
250
|
+
["source", "conflict"]
|
|
251
|
+
],
|
|
252
|
+
unsupported: []
|
|
253
|
+
},
|
|
254
|
+
clean: { exclusive: [["ignored", "onlyIgnored"]], unsupported: [] },
|
|
255
|
+
worktreeAdd: {
|
|
256
|
+
exclusive: [
|
|
257
|
+
["branch", "detach"],
|
|
258
|
+
["orphan", "detach"]
|
|
259
|
+
],
|
|
260
|
+
unsupported: []
|
|
261
|
+
},
|
|
262
|
+
remoteSetHead: { exclusive: [["auto", "delete"]], unsupported: [] },
|
|
263
|
+
configGet: { exclusive: [["all", "default"]], unsupported: [] },
|
|
264
|
+
configList: { exclusive: [], unsupported: ["nameOnly"] },
|
|
265
|
+
lfsPull: { exclusive: [], unsupported: ["ref"] },
|
|
266
|
+
lfsPush: { exclusive: [["ref", "objectId"]], unsupported: [] },
|
|
267
|
+
lfsFetch: {
|
|
268
|
+
exclusive: [
|
|
269
|
+
["all", "include"],
|
|
270
|
+
["all", "exclude"],
|
|
271
|
+
["all", "recent"]
|
|
272
|
+
],
|
|
273
|
+
unsupported: []
|
|
274
|
+
},
|
|
275
|
+
lfsStatus: { exclusive: [], unsupported: ["porcelain"] },
|
|
276
|
+
lfsLsFiles: { exclusive: [], unsupported: ["debug", "nameOnly"] }
|
|
277
|
+
};
|
|
278
|
+
function validateOptions(name, options) {
|
|
279
|
+
if (!options) {
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
const values = options;
|
|
283
|
+
const rule = OPTION_RULES[name];
|
|
284
|
+
if ((name === "lfsStatus" || name === "lfsLsFiles") && values.json !== void 0 && values.json !== true) {
|
|
285
|
+
throw new GitArgumentError(`${name}: the typed API uses JSON`);
|
|
286
|
+
}
|
|
287
|
+
if (name === "status" && values.porcelain !== void 0 && values.porcelain !== 2) {
|
|
288
|
+
throw new GitArgumentError("status: the typed API uses porcelain v2");
|
|
289
|
+
}
|
|
290
|
+
if ((name === "status" || name === "diff") && values.nullTerminated !== void 0 && values.nullTerminated !== true) {
|
|
291
|
+
throw new GitArgumentError(`${name}: the typed API uses NUL-delimited paths`);
|
|
292
|
+
}
|
|
293
|
+
for (const key of rule.unsupported) {
|
|
294
|
+
if (values[key] !== void 0) {
|
|
295
|
+
throw new GitArgumentError(
|
|
296
|
+
`${name}: ${key} is not supported by the typed API; use raw() for this output or operation`
|
|
297
|
+
);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
if (rule.controls?.some((key) => values[key] === true)) {
|
|
301
|
+
const ignored = Object.keys(values).filter(
|
|
302
|
+
(key) => !(rule.controls?.includes(key) || ["signal", "onProgress", "onLfsProgress"].includes(key)) && values[key] !== void 0 && values[key] !== false
|
|
303
|
+
);
|
|
304
|
+
if (ignored.length > 0) {
|
|
305
|
+
throw new GitArgumentError(`${name}: control operations cannot take ${ignored.join(", ")}`);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
for (const group of rule.exclusive) {
|
|
309
|
+
const active = group.filter((key) => values[key] !== void 0 && values[key] !== false);
|
|
310
|
+
if (active.length > 1) {
|
|
311
|
+
throw new GitArgumentError(`${name}: ${active.join(", ")} cannot be used together`);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
for (const key of ["depth", "deepen", "jobs", "mainline"]) {
|
|
315
|
+
const value = values[key];
|
|
316
|
+
if (value !== void 0 && (!Number.isSafeInteger(value) || value < 1)) {
|
|
317
|
+
throw new GitArgumentError(`${name}: ${key} must be a positive safe integer`);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
for (const key of ["maxCount", "skip", "context", "renameLimit", "abbrev"]) {
|
|
321
|
+
const value = values[key];
|
|
322
|
+
if (value !== void 0 && typeof value !== "boolean" && (!Number.isSafeInteger(value) || value < 0)) {
|
|
323
|
+
throw new GitArgumentError(`${name}: ${key} must be a non-negative safe integer`);
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
var REV_PARSE_QUERY_KEYS = [
|
|
328
|
+
"gitDir",
|
|
329
|
+
"absoluteGitDir",
|
|
330
|
+
"gitCommonDir",
|
|
331
|
+
"showToplevel",
|
|
332
|
+
"showCdup",
|
|
333
|
+
"showPrefix",
|
|
334
|
+
"showSuperprojectWorkingTree",
|
|
335
|
+
"sharedIndexPath",
|
|
336
|
+
"gitPath",
|
|
337
|
+
"resolveGitDir",
|
|
338
|
+
"isInsideGitDir",
|
|
339
|
+
"isInsideWorkTree",
|
|
340
|
+
"isBareRepository",
|
|
341
|
+
"isShallowRepository",
|
|
342
|
+
"all",
|
|
343
|
+
"branches",
|
|
344
|
+
"tags",
|
|
345
|
+
"remotes",
|
|
346
|
+
"glob",
|
|
347
|
+
"disambiguate",
|
|
348
|
+
"showObjectFormat",
|
|
349
|
+
"showRefFormat",
|
|
350
|
+
"localEnvVars"
|
|
351
|
+
];
|
|
352
|
+
function validateRevParseQuery(query) {
|
|
353
|
+
const values = query;
|
|
354
|
+
const selected = REV_PARSE_QUERY_KEYS.filter((key) => values[key] !== void 0);
|
|
355
|
+
if (selected.length !== 1 || values[selected[0]] !== true && typeof values[selected[0]] !== "string") {
|
|
356
|
+
throw new GitArgumentError("revParse: specify exactly one query");
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
function validatePathInput(name, paths, opts) {
|
|
360
|
+
if (opts?.pathspecFromFile !== void 0 && (typeof paths === "string" || paths.length > 0)) {
|
|
361
|
+
throw new GitArgumentError(`${name}: pass an empty path list when using pathspecFromFile`);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
|
|
104
365
|
// src/parsers/index.ts
|
|
105
366
|
var GIT_PROGRESS_PERCENT_REGEX = /^(.+?):\s*(\d+)%\s*\((\d+)\/(\d+)\)(?:,\s*(done))?/;
|
|
106
367
|
var GIT_PROGRESS_SIMPLE_REGEX = /^(.+?):\s*(\d+)\/(\d+)/;
|
|
@@ -112,13 +373,6 @@ var LFS_DOWNLOAD_REGEX = /downloading|filtering/i;
|
|
|
112
373
|
var LFS_UPLOAD_REGEX = /uploading/i;
|
|
113
374
|
var LFS_CHECKOUT_REGEX = /checking out/i;
|
|
114
375
|
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;
|
|
115
|
-
function at(arr, index, context) {
|
|
116
|
-
const value = arr[index];
|
|
117
|
-
if (value === void 0) {
|
|
118
|
-
throw new Error(`Parse error: expected element at index ${index} in ${context}`);
|
|
119
|
-
}
|
|
120
|
-
return value;
|
|
121
|
-
}
|
|
122
376
|
function parseLines(stdout, options) {
|
|
123
377
|
const { keepEmpty = false, trim = true } = options ?? {};
|
|
124
378
|
const lines = stdout.split("\n");
|
|
@@ -129,9 +383,6 @@ function parseRecords(stdout, delimiter = "\0") {
|
|
|
129
383
|
return [];
|
|
130
384
|
}
|
|
131
385
|
const normalized = stdout.endsWith(delimiter) ? stdout.slice(0, -delimiter.length) : stdout;
|
|
132
|
-
if (!normalized) {
|
|
133
|
-
return [];
|
|
134
|
-
}
|
|
135
386
|
return normalized.split(delimiter);
|
|
136
387
|
}
|
|
137
388
|
function parseJson(stdout, options) {
|
|
@@ -159,65 +410,123 @@ function parseKeyValue(stdout, options) {
|
|
|
159
410
|
}
|
|
160
411
|
return result;
|
|
161
412
|
}
|
|
413
|
+
function decodePath(path) {
|
|
414
|
+
if (!path.startsWith('"')) {
|
|
415
|
+
return path;
|
|
416
|
+
}
|
|
417
|
+
if (!path.endsWith('"')) {
|
|
418
|
+
throw new GitError("ParseError", "Unterminated quoted path");
|
|
419
|
+
}
|
|
420
|
+
const bytes = [];
|
|
421
|
+
const encoder = new TextEncoder();
|
|
422
|
+
const escapes = {
|
|
423
|
+
a: "\x07",
|
|
424
|
+
b: "\b",
|
|
425
|
+
f: "\f",
|
|
426
|
+
n: "\n",
|
|
427
|
+
r: "\r",
|
|
428
|
+
t: " ",
|
|
429
|
+
v: "\v",
|
|
430
|
+
'"': '"',
|
|
431
|
+
"\\": "\\"
|
|
432
|
+
};
|
|
433
|
+
const value = path.slice(1, -1);
|
|
434
|
+
for (let i = 0; i < value.length; ) {
|
|
435
|
+
if (value[i] === "\\") {
|
|
436
|
+
const octal = value.slice(i + 1).match(/^[0-7]{1,3}/)?.[0];
|
|
437
|
+
if (octal) {
|
|
438
|
+
bytes.push(Number.parseInt(octal, 8));
|
|
439
|
+
i += octal.length + 1;
|
|
440
|
+
continue;
|
|
441
|
+
}
|
|
442
|
+
const escaped = escapes[value[i + 1] ?? ""];
|
|
443
|
+
if (escaped === void 0) {
|
|
444
|
+
throw new GitError("ParseError", "Invalid quoted path escape");
|
|
445
|
+
}
|
|
446
|
+
bytes.push(...encoder.encode(escaped));
|
|
447
|
+
i += 2;
|
|
448
|
+
} else {
|
|
449
|
+
const char = String.fromCodePoint(value.codePointAt(i));
|
|
450
|
+
bytes.push(...encoder.encode(char));
|
|
451
|
+
i += char.length;
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
return new TextDecoder().decode(new Uint8Array(bytes));
|
|
455
|
+
}
|
|
162
456
|
function parsePorcelainV2(stdout) {
|
|
163
457
|
const entries = [];
|
|
164
|
-
const
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
hH: at(parts, 6, "porcelain-v2 ordinary"),
|
|
177
|
-
hI: at(parts, 7, "porcelain-v2 ordinary"),
|
|
178
|
-
path: pathPart
|
|
179
|
-
});
|
|
180
|
-
} else if (line.startsWith("2 ")) {
|
|
181
|
-
const parts = line.split(" ");
|
|
182
|
-
const pathPart = parts.slice(9).join(" ");
|
|
183
|
-
const pathParts = pathPart.split(" ");
|
|
458
|
+
const nul = stdout.includes("\0");
|
|
459
|
+
const records = nul ? parseRecords(stdout) : parseLines(stdout, { trim: false });
|
|
460
|
+
for (let i = 0; i < records.length; i++) {
|
|
461
|
+
const line = records[i];
|
|
462
|
+
if (line.startsWith("# ")) {
|
|
463
|
+
continue;
|
|
464
|
+
}
|
|
465
|
+
const kind = line[0];
|
|
466
|
+
if (kind === "?" || kind === "!") {
|
|
467
|
+
if (line[1] !== " " || line.length < 3) {
|
|
468
|
+
throw new GitError("ParseError", "Invalid status path");
|
|
469
|
+
}
|
|
184
470
|
entries.push({
|
|
185
|
-
type: "
|
|
186
|
-
|
|
187
|
-
sub: at(parts, 2, "porcelain-v2 renamed"),
|
|
188
|
-
mH: at(parts, 3, "porcelain-v2 renamed"),
|
|
189
|
-
mI: at(parts, 4, "porcelain-v2 renamed"),
|
|
190
|
-
mW: at(parts, 5, "porcelain-v2 renamed"),
|
|
191
|
-
hH: at(parts, 6, "porcelain-v2 renamed"),
|
|
192
|
-
hI: at(parts, 7, "porcelain-v2 renamed"),
|
|
193
|
-
path: at(pathParts, 0, "porcelain-v2 renamed path"),
|
|
194
|
-
origPath: pathParts[1]
|
|
471
|
+
type: kind === "?" ? "untracked" : "ignored",
|
|
472
|
+
path: nul ? line.slice(2) : decodePath(line.slice(2))
|
|
195
473
|
});
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
474
|
+
continue;
|
|
475
|
+
}
|
|
476
|
+
if (kind !== "1" && kind !== "2" && kind !== "u") {
|
|
477
|
+
throw new GitError("ParseError", "Unknown status record");
|
|
478
|
+
}
|
|
479
|
+
const count = kind === "u" ? 10 : kind === "2" ? 9 : 8;
|
|
480
|
+
const parts = line.split(" ");
|
|
481
|
+
if (parts.length <= count || parts[1]?.length !== 2) {
|
|
482
|
+
throw new GitError("ParseError", "Invalid status record");
|
|
483
|
+
}
|
|
484
|
+
let path = parts.slice(count).join(" ");
|
|
485
|
+
let origPath;
|
|
486
|
+
if (kind === "2") {
|
|
487
|
+
if (nul) {
|
|
488
|
+
origPath = records[++i];
|
|
489
|
+
} else {
|
|
490
|
+
const tab = path.indexOf(" ");
|
|
491
|
+
if (tab < 0) {
|
|
492
|
+
throw new GitError("ParseError", "Missing rename source");
|
|
493
|
+
}
|
|
494
|
+
origPath = decodePath(path.slice(tab + 1));
|
|
495
|
+
path = path.slice(0, tab);
|
|
496
|
+
}
|
|
497
|
+
if (origPath === void 0) {
|
|
498
|
+
throw new GitError("ParseError", "Missing rename source");
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
if (!nul) {
|
|
502
|
+
path = decodePath(path);
|
|
503
|
+
}
|
|
504
|
+
if (kind === "u") {
|
|
199
505
|
entries.push({
|
|
200
506
|
type: "unmerged",
|
|
201
|
-
xy:
|
|
202
|
-
sub:
|
|
203
|
-
m1:
|
|
204
|
-
m2:
|
|
205
|
-
m3:
|
|
206
|
-
mW:
|
|
207
|
-
h1:
|
|
208
|
-
h2:
|
|
209
|
-
h3:
|
|
210
|
-
path
|
|
507
|
+
xy: parts[1],
|
|
508
|
+
sub: parts[2],
|
|
509
|
+
m1: parts[3],
|
|
510
|
+
m2: parts[4],
|
|
511
|
+
m3: parts[5],
|
|
512
|
+
mW: parts[6],
|
|
513
|
+
h1: parts[7],
|
|
514
|
+
h2: parts[8],
|
|
515
|
+
h3: parts[9],
|
|
516
|
+
path
|
|
211
517
|
});
|
|
212
|
-
} else
|
|
213
|
-
entries.push({
|
|
214
|
-
type: "untracked",
|
|
215
|
-
path: line.slice(2)
|
|
216
|
-
});
|
|
217
|
-
} else if (line.startsWith("! ")) {
|
|
518
|
+
} else {
|
|
218
519
|
entries.push({
|
|
219
|
-
type: "
|
|
220
|
-
|
|
520
|
+
type: "changed",
|
|
521
|
+
xy: parts[1],
|
|
522
|
+
sub: parts[2],
|
|
523
|
+
mH: parts[3],
|
|
524
|
+
mI: parts[4],
|
|
525
|
+
mW: parts[5],
|
|
526
|
+
hH: parts[6],
|
|
527
|
+
hI: parts[7],
|
|
528
|
+
path,
|
|
529
|
+
...origPath !== void 0 ? { origPath } : {}
|
|
221
530
|
});
|
|
222
531
|
}
|
|
223
532
|
}
|
|
@@ -375,109 +684,71 @@ function parseLsRemote(stdout) {
|
|
|
375
684
|
}
|
|
376
685
|
return refs;
|
|
377
686
|
}
|
|
378
|
-
var LS_TREE_REGEX = /^(\d+)\s+(blob|tree|commit)\s+([a-f0-9]+)\t(
|
|
379
|
-
var LS_TREE_LONG_REGEX = /^(\d+)\s+(blob|tree|commit)\s+([a-f0-9]+)\s+(-|\d+)\t(
|
|
687
|
+
var LS_TREE_REGEX = /^(\d+)\s+(blob|tree|commit)\s+([a-f0-9]+)\t([\s\S]+)$/;
|
|
688
|
+
var LS_TREE_LONG_REGEX = /^(\d+)\s+(blob|tree|commit)\s+([a-f0-9]+)\s+(-|\d+)\t([\s\S]+)$/;
|
|
380
689
|
function parseLsTree(stdout, opts) {
|
|
381
|
-
const
|
|
382
|
-
const
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
if (opts?.objectOnly) {
|
|
394
|
-
entries.push({
|
|
395
|
-
mode: "",
|
|
396
|
-
type: "blob",
|
|
397
|
-
hash: line,
|
|
398
|
-
path: ""
|
|
399
|
-
});
|
|
400
|
-
continue;
|
|
401
|
-
}
|
|
402
|
-
if (opts?.long) {
|
|
403
|
-
const longMatch = line.match(LS_TREE_LONG_REGEX);
|
|
404
|
-
if (longMatch) {
|
|
405
|
-
const mode = longMatch[1];
|
|
406
|
-
const type = longMatch[2];
|
|
407
|
-
const hash = longMatch[3];
|
|
408
|
-
const sizeStr = longMatch[4];
|
|
409
|
-
const path = longMatch[5];
|
|
410
|
-
if (mode && type && hash && path) {
|
|
411
|
-
entries.push({
|
|
412
|
-
mode,
|
|
413
|
-
type,
|
|
414
|
-
hash,
|
|
415
|
-
path,
|
|
416
|
-
size: sizeStr === "-" || !sizeStr ? void 0 : Number.parseInt(sizeStr, 10)
|
|
417
|
-
});
|
|
418
|
-
}
|
|
419
|
-
continue;
|
|
420
|
-
}
|
|
690
|
+
const nul = stdout.includes("\0");
|
|
691
|
+
const records = nul ? parseRecords(stdout) : parseLines(stdout, { trim: false });
|
|
692
|
+
if (opts?.nameOnly) {
|
|
693
|
+
return records.map((path) => nul ? path : decodePath(path));
|
|
694
|
+
}
|
|
695
|
+
if (opts?.objectOnly) {
|
|
696
|
+
return records;
|
|
697
|
+
}
|
|
698
|
+
return records.map((line) => {
|
|
699
|
+
const match = line.match(opts?.long ? LS_TREE_LONG_REGEX : LS_TREE_REGEX);
|
|
700
|
+
if (!match) {
|
|
701
|
+
throw new GitError("ParseError", "Invalid ls-tree record", { stdout: line });
|
|
421
702
|
}
|
|
422
|
-
const
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
const hash = match[3];
|
|
427
|
-
const path = match[4];
|
|
428
|
-
if (mode && type && hash && path) {
|
|
429
|
-
entries.push({
|
|
430
|
-
mode,
|
|
431
|
-
type,
|
|
432
|
-
hash,
|
|
433
|
-
path
|
|
434
|
-
});
|
|
435
|
-
}
|
|
703
|
+
const path = match[opts?.long ? 5 : 4];
|
|
704
|
+
const size = opts?.long && match[4] !== "-" ? Number(match[4]) : void 0;
|
|
705
|
+
if (size !== void 0 && !Number.isSafeInteger(size)) {
|
|
706
|
+
throw new GitError("ParseError", "Invalid tree object size");
|
|
436
707
|
}
|
|
437
|
-
|
|
438
|
-
|
|
708
|
+
return {
|
|
709
|
+
mode: match[1],
|
|
710
|
+
type: match[2],
|
|
711
|
+
hash: match[3],
|
|
712
|
+
path: nul ? path : decodePath(path),
|
|
713
|
+
...size !== void 0 ? { size } : {}
|
|
714
|
+
};
|
|
715
|
+
});
|
|
439
716
|
}
|
|
440
|
-
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
|
|
717
|
+
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";
|
|
441
718
|
function parseGitLog(stdout) {
|
|
719
|
+
if (!stdout) {
|
|
720
|
+
return [];
|
|
721
|
+
}
|
|
722
|
+
const fields = parseRecords(stdout);
|
|
723
|
+
if (fields.length % 11 !== 0) {
|
|
724
|
+
throw new GitError("ParseError", "Invalid git log field count");
|
|
725
|
+
}
|
|
442
726
|
const commits = [];
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
const
|
|
446
|
-
if (fields.
|
|
447
|
-
|
|
448
|
-
}
|
|
449
|
-
const hash = fields[0]?.trim();
|
|
450
|
-
const abbrevHash = fields[1];
|
|
451
|
-
const parentsStr = fields[2];
|
|
452
|
-
const authorName = fields[3];
|
|
453
|
-
const authorEmail = fields[4];
|
|
454
|
-
const authorTimestampStr = fields[5];
|
|
455
|
-
const committerName = fields[6];
|
|
456
|
-
const committerEmail = fields[7];
|
|
457
|
-
const committerTimestampStr = fields[8];
|
|
458
|
-
const subject = fields[9];
|
|
459
|
-
if (hash === void 0 || abbrevHash === void 0 || authorName === void 0 || authorEmail === void 0 || authorTimestampStr === void 0 || committerName === void 0 || committerEmail === void 0 || committerTimestampStr === void 0 || subject === void 0) {
|
|
460
|
-
continue;
|
|
727
|
+
for (let i = 0; i < fields.length; i += 11) {
|
|
728
|
+
const authorTimestamp = Number(fields[i + 5]);
|
|
729
|
+
const committerTimestamp = Number(fields[i + 8]);
|
|
730
|
+
if (!(fields[i] && Number.isSafeInteger(authorTimestamp) && Number.isSafeInteger(committerTimestamp))) {
|
|
731
|
+
throw new GitError("ParseError", "Invalid git log metadata");
|
|
461
732
|
}
|
|
462
733
|
commits.push({
|
|
463
|
-
hash,
|
|
464
|
-
abbrevHash,
|
|
465
|
-
parents:
|
|
466
|
-
authorName,
|
|
467
|
-
authorEmail,
|
|
468
|
-
authorTimestamp
|
|
469
|
-
committerName,
|
|
470
|
-
committerEmail,
|
|
471
|
-
committerTimestamp
|
|
472
|
-
subject,
|
|
473
|
-
body: fields[10]
|
|
734
|
+
hash: fields[i],
|
|
735
|
+
abbrevHash: fields[i + 1],
|
|
736
|
+
parents: fields[i + 2]?.split(" ").filter(Boolean) ?? [],
|
|
737
|
+
authorName: fields[i + 3],
|
|
738
|
+
authorEmail: fields[i + 4],
|
|
739
|
+
authorTimestamp,
|
|
740
|
+
committerName: fields[i + 6],
|
|
741
|
+
committerEmail: fields[i + 7],
|
|
742
|
+
committerTimestamp,
|
|
743
|
+
subject: fields[i + 9],
|
|
744
|
+
body: fields[i + 10]
|
|
474
745
|
});
|
|
475
746
|
}
|
|
476
747
|
return commits;
|
|
477
748
|
}
|
|
478
749
|
function parseWorktreeList(stdout) {
|
|
479
750
|
const worktrees = [];
|
|
480
|
-
const lines = parseLines(stdout, { keepEmpty: true });
|
|
751
|
+
const lines = parseLines(stdout, { keepEmpty: true, trim: false });
|
|
481
752
|
let current = null;
|
|
482
753
|
for (const line of lines) {
|
|
483
754
|
if (line.startsWith("worktree ")) {
|
|
@@ -491,7 +762,7 @@ function parseWorktreeList(stdout) {
|
|
|
491
762
|
});
|
|
492
763
|
}
|
|
493
764
|
current = {
|
|
494
|
-
path: line.slice("worktree ".length),
|
|
765
|
+
path: decodePath(line.slice("worktree ".length)),
|
|
495
766
|
locked: false,
|
|
496
767
|
prunable: false
|
|
497
768
|
};
|
|
@@ -563,6 +834,132 @@ function detectErrorCategory(stderr) {
|
|
|
563
834
|
return "unknown";
|
|
564
835
|
}
|
|
565
836
|
|
|
837
|
+
// src/internal/config.ts
|
|
838
|
+
var CONFIG_ENUMS = {
|
|
839
|
+
"core.autocrlf": ["true", "false", "input"],
|
|
840
|
+
"core.filemode": ["true", "false"],
|
|
841
|
+
"core.ignorecase": ["true", "false"],
|
|
842
|
+
"core.bare": ["true", "false"],
|
|
843
|
+
"core.logallrefupdates": ["true", "false", "always"],
|
|
844
|
+
"core.quotepath": ["true", "false"],
|
|
845
|
+
"commit.gpgsign": ["true", "false"],
|
|
846
|
+
"tag.gpgsign": ["true", "false"],
|
|
847
|
+
"tag.forcesignannotated": ["true", "false"],
|
|
848
|
+
"push.default": ["nothing", "current", "upstream", "tracking", "simple", "matching"],
|
|
849
|
+
"push.followTags": ["true", "false"],
|
|
850
|
+
"push.autoSetupRemote": ["true", "false"],
|
|
851
|
+
"push.gpgSign": ["true", "false", "if-asked"],
|
|
852
|
+
"pull.rebase": ["true", "false", "merges", "interactive"],
|
|
853
|
+
"pull.ff": ["true", "false", "only"],
|
|
854
|
+
"fetch.prune": ["true", "false"],
|
|
855
|
+
"fetch.pruneTags": ["true", "false"],
|
|
856
|
+
"merge.ff": ["true", "false", "only"],
|
|
857
|
+
"merge.conflictstyle": ["merge", "diff3", "zdiff3"],
|
|
858
|
+
"rebase.autoStash": ["true", "false"],
|
|
859
|
+
"rebase.autoSquash": ["true", "false"],
|
|
860
|
+
"rebase.updateRefs": ["true", "false"],
|
|
861
|
+
"diff.algorithm": ["default", "minimal", "patience", "histogram"],
|
|
862
|
+
"diff.colorMoved": ["no", "default", "plain", "blocks", "zebra", "dimmed-zebra"],
|
|
863
|
+
"color.ui": ["auto", "always", "never", "true", "false"],
|
|
864
|
+
"gpg.format": ["openpgp", "x509", "ssh"],
|
|
865
|
+
"http.sslVerify": ["true", "false"]
|
|
866
|
+
};
|
|
867
|
+
function configValue(key, value, implicit = false) {
|
|
868
|
+
const allowed = CONFIG_ENUMS[key];
|
|
869
|
+
if (!allowed) {
|
|
870
|
+
return value;
|
|
871
|
+
}
|
|
872
|
+
let normalized = value.toLowerCase();
|
|
873
|
+
if (allowed.includes("true") && allowed.includes("false")) {
|
|
874
|
+
if (normalized === "") {
|
|
875
|
+
normalized = implicit ? "true" : "false";
|
|
876
|
+
}
|
|
877
|
+
if (/^[+-]?\d+[kmg]?$/i.test(normalized)) {
|
|
878
|
+
normalized = Number.parseInt(normalized, 10) === 0 ? "false" : "true";
|
|
879
|
+
}
|
|
880
|
+
if (["yes", "on", "1"].includes(normalized)) {
|
|
881
|
+
normalized = "true";
|
|
882
|
+
}
|
|
883
|
+
if (["no", "off", "0"].includes(normalized)) {
|
|
884
|
+
normalized = "false";
|
|
885
|
+
}
|
|
886
|
+
}
|
|
887
|
+
if (!allowed.includes(normalized)) {
|
|
888
|
+
throw new GitError("ParseError", `Invalid value for ${key}: expected ${allowed.join(" | ")}`);
|
|
889
|
+
}
|
|
890
|
+
return normalized;
|
|
891
|
+
}
|
|
892
|
+
async function readConfig(runner, context, key, opts) {
|
|
893
|
+
validateOptions("configGet", opts);
|
|
894
|
+
const args = ["config", ...context.type === "global" ? ["--global"] : [], "--null"];
|
|
895
|
+
if (opts?.type) {
|
|
896
|
+
args.push(`--type=${opts.type}`);
|
|
897
|
+
}
|
|
898
|
+
if (opts?.default !== void 0) {
|
|
899
|
+
args.push("--default", opts.default);
|
|
900
|
+
}
|
|
901
|
+
args.push(opts?.all ? "--get-all" : "--get", key);
|
|
902
|
+
const result = await runner.run(context, args, opts);
|
|
903
|
+
if (result.exitCode === 1 && !result.aborted) {
|
|
904
|
+
return opts?.all ? [] : void 0;
|
|
905
|
+
}
|
|
906
|
+
runner.checkResult(context, args, result);
|
|
907
|
+
const values = parseRecords(result.stdout);
|
|
908
|
+
return opts?.all ? values : values[0];
|
|
909
|
+
}
|
|
910
|
+
async function listConfig(runner, context, opts) {
|
|
911
|
+
validateOptions("configList", opts);
|
|
912
|
+
const args = ["config", ...context.type === "global" ? ["--global"] : [], "--null", "--list"];
|
|
913
|
+
if (opts?.showOrigin) {
|
|
914
|
+
args.push("--show-origin");
|
|
915
|
+
}
|
|
916
|
+
if (opts?.showScope) {
|
|
917
|
+
args.push("--show-scope");
|
|
918
|
+
}
|
|
919
|
+
if (opts?.includes !== void 0) {
|
|
920
|
+
args.push(opts.includes ? "--includes" : "--no-includes");
|
|
921
|
+
}
|
|
922
|
+
const result = await runner.runOrThrow(context, args, opts);
|
|
923
|
+
const records = parseRecords(result.stdout);
|
|
924
|
+
const entries = [];
|
|
925
|
+
for (let i = 0; i < records.length; ) {
|
|
926
|
+
const scope = opts?.showScope ? records[i++] : void 0;
|
|
927
|
+
const origin = opts?.showOrigin ? records[i++] : void 0;
|
|
928
|
+
const entry = records[i++];
|
|
929
|
+
if (entry === void 0) {
|
|
930
|
+
throw new GitError("ParseError", "Incomplete config record");
|
|
931
|
+
}
|
|
932
|
+
const separator = entry.indexOf("\n");
|
|
933
|
+
entries.push({
|
|
934
|
+
key: separator < 0 ? entry : entry.slice(0, separator),
|
|
935
|
+
value: separator < 0 ? "" : entry.slice(separator + 1),
|
|
936
|
+
...scope !== void 0 ? { scope } : {},
|
|
937
|
+
...origin !== void 0 ? { origin } : {}
|
|
938
|
+
});
|
|
939
|
+
}
|
|
940
|
+
return entries;
|
|
941
|
+
}
|
|
942
|
+
async function readTypedConfig(runner, context, key, opts, all = false) {
|
|
943
|
+
const pattern = `^${key.toLowerCase().replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}$`;
|
|
944
|
+
const args = [
|
|
945
|
+
"config",
|
|
946
|
+
...context.type === "global" ? ["--global"] : [],
|
|
947
|
+
"--null",
|
|
948
|
+
"--get-regexp",
|
|
949
|
+
pattern
|
|
950
|
+
];
|
|
951
|
+
const result = await runner.run(context, args, opts);
|
|
952
|
+
if (result.exitCode === 1 && !result.aborted) {
|
|
953
|
+
return [];
|
|
954
|
+
}
|
|
955
|
+
runner.checkResult(context, args, result);
|
|
956
|
+
const records = parseRecords(result.stdout);
|
|
957
|
+
return (all ? records : records.slice(-1)).map((record2) => {
|
|
958
|
+
const separator = record2.indexOf("\n");
|
|
959
|
+
return configValue(key, separator < 0 ? "" : record2.slice(separator + 1), separator < 0);
|
|
960
|
+
});
|
|
961
|
+
}
|
|
962
|
+
|
|
566
963
|
// src/runner/cli-runner.ts
|
|
567
964
|
var import_node_process = __toESM(require("process"), 1);
|
|
568
965
|
|
|
@@ -873,6 +1270,9 @@ var CliRunner = class _CliRunner {
|
|
|
873
1270
|
async run(context, args, opts) {
|
|
874
1271
|
const argv = this.buildArgv(context, args);
|
|
875
1272
|
const { signal, onProgress, onLfsProgress, env: envOverride } = opts ?? {};
|
|
1273
|
+
if (signal?.aborted) {
|
|
1274
|
+
return { stdout: "", stderr: "", exitCode: -1, aborted: true };
|
|
1275
|
+
}
|
|
876
1276
|
const env = this.buildEnv();
|
|
877
1277
|
if (envOverride) {
|
|
878
1278
|
Object.assign(env, envOverride);
|
|
@@ -933,7 +1333,17 @@ var CliRunner = class _CliRunner {
|
|
|
933
1333
|
duration: endTimestamp - startTimestamp
|
|
934
1334
|
});
|
|
935
1335
|
}
|
|
936
|
-
|
|
1336
|
+
if (error instanceof GitError) {
|
|
1337
|
+
throw error;
|
|
1338
|
+
}
|
|
1339
|
+
throw new GitError(
|
|
1340
|
+
signal?.aborted ? "Aborted" : "SpawnFailed",
|
|
1341
|
+
error instanceof Error ? error.message : String(error),
|
|
1342
|
+
{
|
|
1343
|
+
argv,
|
|
1344
|
+
...context.type === "worktree" ? { workdir: context.workdir } : context.type === "bare" ? { gitDir: context.gitDir } : {}
|
|
1345
|
+
}
|
|
1346
|
+
);
|
|
937
1347
|
}
|
|
938
1348
|
if (this.audit?.onAudit) {
|
|
939
1349
|
const endTimestamp = Date.now();
|
|
@@ -1038,6 +1448,12 @@ var CliRunner = class _CliRunner {
|
|
|
1038
1448
|
/**
|
|
1039
1449
|
* Run a command and throw on error
|
|
1040
1450
|
*/
|
|
1451
|
+
checkResult(context, args, result) {
|
|
1452
|
+
const error = this.mapError(result, context, this.buildArgv(context, args));
|
|
1453
|
+
if (error) {
|
|
1454
|
+
throw error;
|
|
1455
|
+
}
|
|
1456
|
+
}
|
|
1041
1457
|
async runOrThrow(context, args, opts) {
|
|
1042
1458
|
const result = await this.run(context, args, opts);
|
|
1043
1459
|
const error = this.mapError(result, context, this.buildArgv(context, args));
|
|
@@ -1048,6 +1464,230 @@ var CliRunner = class _CliRunner {
|
|
|
1048
1464
|
}
|
|
1049
1465
|
};
|
|
1050
1466
|
|
|
1467
|
+
// src/internal/transport.ts
|
|
1468
|
+
async function fetch(runner, context, opts) {
|
|
1469
|
+
validateOptions("fetch", opts);
|
|
1470
|
+
const args = ["fetch"];
|
|
1471
|
+
if (opts?.onProgress) {
|
|
1472
|
+
args.push("--progress");
|
|
1473
|
+
}
|
|
1474
|
+
if (opts?.verbose) {
|
|
1475
|
+
args.push("--verbose");
|
|
1476
|
+
}
|
|
1477
|
+
if (opts?.quiet) {
|
|
1478
|
+
args.push("--quiet");
|
|
1479
|
+
}
|
|
1480
|
+
if (opts?.all) {
|
|
1481
|
+
args.push("--all");
|
|
1482
|
+
}
|
|
1483
|
+
if (opts?.setUpstream) {
|
|
1484
|
+
args.push("--set-upstream");
|
|
1485
|
+
}
|
|
1486
|
+
if (opts?.append) {
|
|
1487
|
+
args.push("--append");
|
|
1488
|
+
}
|
|
1489
|
+
if (opts?.atomic) {
|
|
1490
|
+
args.push("--atomic");
|
|
1491
|
+
}
|
|
1492
|
+
if (opts?.force) {
|
|
1493
|
+
args.push("--force");
|
|
1494
|
+
}
|
|
1495
|
+
if (opts?.prune) {
|
|
1496
|
+
args.push("--prune");
|
|
1497
|
+
}
|
|
1498
|
+
if (opts?.pruneTags) {
|
|
1499
|
+
args.push("--prune-tags");
|
|
1500
|
+
}
|
|
1501
|
+
if (opts?.tags) {
|
|
1502
|
+
args.push("--tags");
|
|
1503
|
+
} else if (opts?.noTags) {
|
|
1504
|
+
args.push("--no-tags");
|
|
1505
|
+
}
|
|
1506
|
+
if (opts?.jobs !== void 0) {
|
|
1507
|
+
args.push(`--jobs=${opts.jobs}`);
|
|
1508
|
+
}
|
|
1509
|
+
if (opts?.prefetch) {
|
|
1510
|
+
args.push("--prefetch");
|
|
1511
|
+
}
|
|
1512
|
+
if (opts?.recurseSubmodules !== void 0) {
|
|
1513
|
+
if (opts.recurseSubmodules === true || opts.recurseSubmodules === "yes") {
|
|
1514
|
+
args.push("--recurse-submodules=yes");
|
|
1515
|
+
} else if (opts.recurseSubmodules === "on-demand") {
|
|
1516
|
+
args.push("--recurse-submodules=on-demand");
|
|
1517
|
+
} else if (opts.recurseSubmodules === "no" || opts.recurseSubmodules === false) {
|
|
1518
|
+
args.push("--recurse-submodules=no");
|
|
1519
|
+
}
|
|
1520
|
+
}
|
|
1521
|
+
if (opts?.dryRun) {
|
|
1522
|
+
args.push("--dry-run");
|
|
1523
|
+
}
|
|
1524
|
+
if (opts?.writeFetchHead === false) {
|
|
1525
|
+
args.push("--no-write-fetch-head");
|
|
1526
|
+
}
|
|
1527
|
+
if (opts?.keep) {
|
|
1528
|
+
args.push("--keep");
|
|
1529
|
+
}
|
|
1530
|
+
if (opts?.updateHeadOk) {
|
|
1531
|
+
args.push("--update-head-ok");
|
|
1532
|
+
}
|
|
1533
|
+
if (opts?.depth !== void 0) {
|
|
1534
|
+
args.push(`--depth=${opts.depth}`);
|
|
1535
|
+
}
|
|
1536
|
+
if (opts?.shallowSince) {
|
|
1537
|
+
const since = opts.shallowSince instanceof Date ? opts.shallowSince.toISOString() : opts.shallowSince;
|
|
1538
|
+
args.push(`--shallow-since=${since}`);
|
|
1539
|
+
}
|
|
1540
|
+
if (opts?.shallowExclude) {
|
|
1541
|
+
const excludes = Array.isArray(opts.shallowExclude) ? opts.shallowExclude : [opts.shallowExclude];
|
|
1542
|
+
for (const exclude of excludes) {
|
|
1543
|
+
args.push(`--shallow-exclude=${exclude}`);
|
|
1544
|
+
}
|
|
1545
|
+
}
|
|
1546
|
+
if (opts?.deepen !== void 0) {
|
|
1547
|
+
args.push(`--deepen=${opts.deepen}`);
|
|
1548
|
+
}
|
|
1549
|
+
if (opts?.unshallow) {
|
|
1550
|
+
args.push("--unshallow");
|
|
1551
|
+
}
|
|
1552
|
+
if (opts?.refetch) {
|
|
1553
|
+
args.push("--refetch");
|
|
1554
|
+
}
|
|
1555
|
+
if (opts?.updateShallow) {
|
|
1556
|
+
args.push("--update-shallow");
|
|
1557
|
+
}
|
|
1558
|
+
if (opts?.refmap) {
|
|
1559
|
+
args.push(`--refmap=${opts.refmap}`);
|
|
1560
|
+
}
|
|
1561
|
+
if (opts?.ipv4) {
|
|
1562
|
+
args.push("--ipv4");
|
|
1563
|
+
}
|
|
1564
|
+
if (opts?.ipv6) {
|
|
1565
|
+
args.push("--ipv6");
|
|
1566
|
+
}
|
|
1567
|
+
if (opts?.filter) {
|
|
1568
|
+
args.push(`--filter=${opts.filter}`);
|
|
1569
|
+
}
|
|
1570
|
+
if (opts?.showForcedUpdates === false) {
|
|
1571
|
+
args.push("--no-show-forced-updates");
|
|
1572
|
+
}
|
|
1573
|
+
if (opts?.writeCommitGraph) {
|
|
1574
|
+
args.push("--write-commit-graph");
|
|
1575
|
+
}
|
|
1576
|
+
if (opts?.remote) {
|
|
1577
|
+
args.push(opts.remote);
|
|
1578
|
+
}
|
|
1579
|
+
if (opts?.refspec) {
|
|
1580
|
+
const refspecs = Array.isArray(opts.refspec) ? opts.refspec : [opts.refspec];
|
|
1581
|
+
args.push(...refspecs);
|
|
1582
|
+
}
|
|
1583
|
+
await runner.runOrThrow(context, args, {
|
|
1584
|
+
signal: opts?.signal,
|
|
1585
|
+
onProgress: opts?.onProgress
|
|
1586
|
+
});
|
|
1587
|
+
}
|
|
1588
|
+
async function push(runner, context, opts) {
|
|
1589
|
+
validateOptions("push", opts);
|
|
1590
|
+
const args = ["push"];
|
|
1591
|
+
if (opts?.onProgress || opts?.onLfsProgress) {
|
|
1592
|
+
args.push("--progress");
|
|
1593
|
+
}
|
|
1594
|
+
if (opts?.verbose) {
|
|
1595
|
+
args.push("--verbose");
|
|
1596
|
+
}
|
|
1597
|
+
if (opts?.quiet) {
|
|
1598
|
+
args.push("--quiet");
|
|
1599
|
+
}
|
|
1600
|
+
if (opts?.repo) {
|
|
1601
|
+
args.push(`--repo=${opts.repo}`);
|
|
1602
|
+
}
|
|
1603
|
+
if (opts?.all) {
|
|
1604
|
+
args.push("--all");
|
|
1605
|
+
} else if (opts?.branches) {
|
|
1606
|
+
args.push("--branches");
|
|
1607
|
+
}
|
|
1608
|
+
if (opts?.mirror) {
|
|
1609
|
+
args.push("--mirror");
|
|
1610
|
+
}
|
|
1611
|
+
if (opts?.deleteRefs) {
|
|
1612
|
+
args.push("--delete");
|
|
1613
|
+
}
|
|
1614
|
+
if (opts?.force) {
|
|
1615
|
+
args.push("--force");
|
|
1616
|
+
} else if (opts?.forceWithLease !== void 0 && opts.forceWithLease !== false) {
|
|
1617
|
+
if (opts.forceWithLease === true) {
|
|
1618
|
+
args.push("--force-with-lease");
|
|
1619
|
+
} else {
|
|
1620
|
+
const leaseOpts = opts.forceWithLease;
|
|
1621
|
+
if (leaseOpts.expect !== void 0) {
|
|
1622
|
+
args.push(`--force-with-lease=${leaseOpts.refname}:${leaseOpts.expect}`);
|
|
1623
|
+
} else {
|
|
1624
|
+
args.push(`--force-with-lease=${leaseOpts.refname}`);
|
|
1625
|
+
}
|
|
1626
|
+
}
|
|
1627
|
+
}
|
|
1628
|
+
if (opts?.forceIfIncludes) {
|
|
1629
|
+
args.push("--force-if-includes");
|
|
1630
|
+
}
|
|
1631
|
+
if (opts?.dryRun) {
|
|
1632
|
+
args.push("--dry-run");
|
|
1633
|
+
}
|
|
1634
|
+
if (opts?.recurseSubmodules) {
|
|
1635
|
+
args.push(`--recurse-submodules=${opts.recurseSubmodules}`);
|
|
1636
|
+
}
|
|
1637
|
+
if (opts?.thin === false) {
|
|
1638
|
+
args.push("--no-thin");
|
|
1639
|
+
}
|
|
1640
|
+
if (opts?.prune) {
|
|
1641
|
+
args.push("--prune");
|
|
1642
|
+
}
|
|
1643
|
+
if (opts?.tags) {
|
|
1644
|
+
args.push("--tags");
|
|
1645
|
+
}
|
|
1646
|
+
if (opts?.followTags) {
|
|
1647
|
+
args.push("--follow-tags");
|
|
1648
|
+
}
|
|
1649
|
+
if (opts?.atomic) {
|
|
1650
|
+
args.push("--atomic");
|
|
1651
|
+
}
|
|
1652
|
+
if (opts?.pushOption) {
|
|
1653
|
+
const pushOptions = Array.isArray(opts.pushOption) ? opts.pushOption : [opts.pushOption];
|
|
1654
|
+
for (const opt of pushOptions) {
|
|
1655
|
+
args.push("--push-option", opt);
|
|
1656
|
+
}
|
|
1657
|
+
}
|
|
1658
|
+
if (opts?.setUpstream) {
|
|
1659
|
+
args.push("--set-upstream");
|
|
1660
|
+
}
|
|
1661
|
+
if (opts?.noVerify) {
|
|
1662
|
+
args.push("--no-verify");
|
|
1663
|
+
}
|
|
1664
|
+
if (opts?.signed !== void 0) {
|
|
1665
|
+
if (opts.signed === true) {
|
|
1666
|
+
args.push("--signed");
|
|
1667
|
+
} else if (opts.signed === "if-asked") {
|
|
1668
|
+
args.push("--signed=if-asked");
|
|
1669
|
+
}
|
|
1670
|
+
}
|
|
1671
|
+
if (opts?.ipv4) {
|
|
1672
|
+
args.push("--ipv4");
|
|
1673
|
+
}
|
|
1674
|
+
if (opts?.ipv6) {
|
|
1675
|
+
args.push("--ipv6");
|
|
1676
|
+
}
|
|
1677
|
+
if (opts?.remote) {
|
|
1678
|
+
args.push(opts.remote);
|
|
1679
|
+
}
|
|
1680
|
+
if (opts?.refspec) {
|
|
1681
|
+
const refspecs = Array.isArray(opts.refspec) ? opts.refspec : [opts.refspec];
|
|
1682
|
+
args.push(...refspecs);
|
|
1683
|
+
}
|
|
1684
|
+
await runner.runOrThrow(context, args, {
|
|
1685
|
+
signal: opts?.signal,
|
|
1686
|
+
onProgress: opts?.onProgress,
|
|
1687
|
+
onLfsProgress: opts?.onLfsProgress
|
|
1688
|
+
});
|
|
1689
|
+
}
|
|
1690
|
+
|
|
1051
1691
|
// src/impl/bare-repo-impl.ts
|
|
1052
1692
|
var REMOTE_LINE_PATTERN = /^(\S+)\t(.+?)\s+\((fetch|push)\)$/;
|
|
1053
1693
|
var PRUNED_REF_PATTERN = /\* \[pruned\] (.+)/;
|
|
@@ -1240,6 +1880,7 @@ function isListQuery(opts) {
|
|
|
1240
1880
|
return "glob" in opts && !!opts.glob || "disambiguate" in opts && !!opts.disambiguate || "localEnvVars" in opts && !!opts.localEnvVars;
|
|
1241
1881
|
}
|
|
1242
1882
|
var BareRepoImpl = class {
|
|
1883
|
+
kind = "bare";
|
|
1243
1884
|
gitDir;
|
|
1244
1885
|
runner;
|
|
1245
1886
|
remote;
|
|
@@ -1305,6 +1946,7 @@ var BareRepoImpl = class {
|
|
|
1305
1946
|
* List references in a remote repository
|
|
1306
1947
|
*/
|
|
1307
1948
|
async lsRemote(remote, opts) {
|
|
1949
|
+
validateOptions("lsRemote", opts);
|
|
1308
1950
|
const args = ["ls-remote"];
|
|
1309
1951
|
if (opts?.heads) {
|
|
1310
1952
|
args.push("--heads");
|
|
@@ -1315,15 +1957,9 @@ var BareRepoImpl = class {
|
|
|
1315
1957
|
if (opts?.refsOnly) {
|
|
1316
1958
|
args.push("--refs");
|
|
1317
1959
|
}
|
|
1318
|
-
if (opts?.getUrl) {
|
|
1319
|
-
args.push("--get-url");
|
|
1320
|
-
}
|
|
1321
1960
|
if (opts?.sort) {
|
|
1322
1961
|
args.push("--sort", opts.sort);
|
|
1323
1962
|
}
|
|
1324
|
-
if (opts?.symref) {
|
|
1325
|
-
args.push("--symref");
|
|
1326
|
-
}
|
|
1327
1963
|
args.push(remote);
|
|
1328
1964
|
if (opts?.refs && opts.refs.length > 0) {
|
|
1329
1965
|
args.push(...opts.refs);
|
|
@@ -1335,11 +1971,9 @@ var BareRepoImpl = class {
|
|
|
1335
1971
|
const refs = parseLsRemote(result.stdout);
|
|
1336
1972
|
return { refs };
|
|
1337
1973
|
}
|
|
1338
|
-
/**
|
|
1339
|
-
* List contents of a tree object
|
|
1340
|
-
*/
|
|
1341
1974
|
async lsTree(treeish, opts) {
|
|
1342
|
-
|
|
1975
|
+
validateOptions("lsTree", opts);
|
|
1976
|
+
const args = ["ls-tree", "-z"];
|
|
1343
1977
|
if (opts?.recursive) {
|
|
1344
1978
|
args.push("-r");
|
|
1345
1979
|
}
|
|
@@ -1352,12 +1986,6 @@ var BareRepoImpl = class {
|
|
|
1352
1986
|
if (opts?.long) {
|
|
1353
1987
|
args.push("--long");
|
|
1354
1988
|
}
|
|
1355
|
-
if (opts?.nameOnly) {
|
|
1356
|
-
args.push("--name-only");
|
|
1357
|
-
}
|
|
1358
|
-
if (opts?.objectOnly) {
|
|
1359
|
-
args.push("--object-only");
|
|
1360
|
-
}
|
|
1361
1989
|
if (opts?.fullName) {
|
|
1362
1990
|
args.push("--full-name");
|
|
1363
1991
|
}
|
|
@@ -1378,11 +2006,14 @@ var BareRepoImpl = class {
|
|
|
1378
2006
|
const result = await this.runner.runOrThrow(this.context, args, {
|
|
1379
2007
|
signal: opts?.signal
|
|
1380
2008
|
});
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
2009
|
+
const entries = parseLsTree(result.stdout, { long: opts?.long });
|
|
2010
|
+
if (opts?.nameOnly) {
|
|
2011
|
+
return entries.map((entry) => entry.path);
|
|
2012
|
+
}
|
|
2013
|
+
if (opts?.objectOnly) {
|
|
2014
|
+
return entries.map((entry) => entry.hash);
|
|
2015
|
+
}
|
|
2016
|
+
return entries;
|
|
1386
2017
|
}
|
|
1387
2018
|
async revParse(refOrOpts, opts) {
|
|
1388
2019
|
const args = ["rev-parse"];
|
|
@@ -1394,11 +2025,12 @@ var BareRepoImpl = class {
|
|
|
1394
2025
|
});
|
|
1395
2026
|
return result2.stdout.trim();
|
|
1396
2027
|
}
|
|
2028
|
+
validateRevParseQuery(refOrOpts);
|
|
2029
|
+
if ("pathFormat" in refOrOpts && refOrOpts.pathFormat) {
|
|
2030
|
+
args.push(`--path-format=${refOrOpts.pathFormat}`);
|
|
2031
|
+
}
|
|
1397
2032
|
const queryOpts = refOrOpts;
|
|
1398
2033
|
tryAddPathQuery(args, queryOpts) || tryAddBooleanQuery(args, queryOpts) || tryAddListQuery(args, queryOpts) || tryAddOtherQuery(args, queryOpts);
|
|
1399
|
-
if ("pathFormat" in queryOpts && queryOpts.pathFormat) {
|
|
1400
|
-
args.push(`--path-format=${queryOpts.pathFormat}`);
|
|
1401
|
-
}
|
|
1402
2034
|
const result = await this.runner.runOrThrow(this.context, args, {
|
|
1403
2035
|
signal: refOrOpts.signal
|
|
1404
2036
|
});
|
|
@@ -1415,60 +2047,13 @@ var BareRepoImpl = class {
|
|
|
1415
2047
|
* Fetch from remote
|
|
1416
2048
|
*/
|
|
1417
2049
|
async fetch(opts) {
|
|
1418
|
-
|
|
1419
|
-
if (opts?.onProgress) {
|
|
1420
|
-
args.push("--progress");
|
|
1421
|
-
}
|
|
1422
|
-
if (opts?.prune) {
|
|
1423
|
-
args.push("--prune");
|
|
1424
|
-
}
|
|
1425
|
-
if (opts?.tags) {
|
|
1426
|
-
args.push("--tags");
|
|
1427
|
-
}
|
|
1428
|
-
if (opts?.depth !== void 0) {
|
|
1429
|
-
args.push(`--depth=${opts.depth}`);
|
|
1430
|
-
}
|
|
1431
|
-
if (opts?.remote) {
|
|
1432
|
-
args.push(opts.remote);
|
|
1433
|
-
}
|
|
1434
|
-
if (opts?.refspec) {
|
|
1435
|
-
const refspecs = Array.isArray(opts.refspec) ? opts.refspec : [opts.refspec];
|
|
1436
|
-
args.push(...refspecs);
|
|
1437
|
-
}
|
|
1438
|
-
await this.runner.runOrThrow(this.context, args, {
|
|
1439
|
-
signal: opts?.signal,
|
|
1440
|
-
onProgress: opts?.onProgress
|
|
1441
|
-
});
|
|
2050
|
+
return fetch(this.runner, this.context, opts);
|
|
1442
2051
|
}
|
|
1443
2052
|
/**
|
|
1444
2053
|
* Push to remote
|
|
1445
2054
|
*/
|
|
1446
2055
|
async push(opts) {
|
|
1447
|
-
|
|
1448
|
-
if (opts?.onProgress || opts?.onLfsProgress) {
|
|
1449
|
-
args.push("--progress");
|
|
1450
|
-
}
|
|
1451
|
-
if (opts?.force) {
|
|
1452
|
-
args.push("--force");
|
|
1453
|
-
}
|
|
1454
|
-
if (opts?.tags) {
|
|
1455
|
-
args.push("--tags");
|
|
1456
|
-
}
|
|
1457
|
-
if (opts?.setUpstream) {
|
|
1458
|
-
args.push("--set-upstream");
|
|
1459
|
-
}
|
|
1460
|
-
if (opts?.remote) {
|
|
1461
|
-
args.push(opts.remote);
|
|
1462
|
-
}
|
|
1463
|
-
if (opts?.refspec) {
|
|
1464
|
-
const refspecs = Array.isArray(opts.refspec) ? opts.refspec : [opts.refspec];
|
|
1465
|
-
args.push(...refspecs);
|
|
1466
|
-
}
|
|
1467
|
-
await this.runner.runOrThrow(this.context, args, {
|
|
1468
|
-
signal: opts?.signal,
|
|
1469
|
-
onProgress: opts?.onProgress,
|
|
1470
|
-
onLfsProgress: opts?.onLfsProgress
|
|
1471
|
-
});
|
|
2056
|
+
return push(this.runner, this.context, opts);
|
|
1472
2057
|
}
|
|
1473
2058
|
// ==========================================================================
|
|
1474
2059
|
// Remote Operations
|
|
@@ -1534,6 +2119,7 @@ var BareRepoImpl = class {
|
|
|
1534
2119
|
});
|
|
1535
2120
|
}
|
|
1536
2121
|
async remoteSetHead(remote, branch, opts) {
|
|
2122
|
+
validateOptions("remoteSetHead", opts);
|
|
1537
2123
|
const args = ["remote", "set-head"];
|
|
1538
2124
|
if (opts?.auto) {
|
|
1539
2125
|
args.push("--auto");
|
|
@@ -1607,25 +2193,14 @@ var BareRepoImpl = class {
|
|
|
1607
2193
|
* Get a typed config value
|
|
1608
2194
|
*/
|
|
1609
2195
|
async configGet(key, opts) {
|
|
1610
|
-
const
|
|
1611
|
-
|
|
1612
|
-
});
|
|
1613
|
-
if (result.exitCode !== 0) {
|
|
1614
|
-
return void 0;
|
|
1615
|
-
}
|
|
1616
|
-
return result.stdout.trim();
|
|
2196
|
+
const values = await readTypedConfig(this.runner, this.context, key, opts);
|
|
2197
|
+
return values.at(-1);
|
|
1617
2198
|
}
|
|
1618
2199
|
/**
|
|
1619
2200
|
* Get all values for a typed multi-valued config key
|
|
1620
2201
|
*/
|
|
1621
2202
|
async configGetAll(key, opts) {
|
|
1622
|
-
|
|
1623
|
-
signal: opts?.signal
|
|
1624
|
-
});
|
|
1625
|
-
if (result.exitCode !== 0) {
|
|
1626
|
-
return [];
|
|
1627
|
-
}
|
|
1628
|
-
return parseLines(result.stdout);
|
|
2203
|
+
return readTypedConfig(this.runner, this.context, key, opts, true);
|
|
1629
2204
|
}
|
|
1630
2205
|
/**
|
|
1631
2206
|
* Set a typed config value
|
|
@@ -1651,27 +2226,8 @@ var BareRepoImpl = class {
|
|
|
1651
2226
|
signal: opts?.signal
|
|
1652
2227
|
});
|
|
1653
2228
|
}
|
|
1654
|
-
/**
|
|
1655
|
-
* Get a raw config value (for arbitrary keys)
|
|
1656
|
-
*/
|
|
1657
2229
|
async configGetRaw(key, opts) {
|
|
1658
|
-
|
|
1659
|
-
if (opts?.all) {
|
|
1660
|
-
args.push("--get-all");
|
|
1661
|
-
} else {
|
|
1662
|
-
args.push("--get");
|
|
1663
|
-
}
|
|
1664
|
-
args.push(key);
|
|
1665
|
-
const result = await this.runner.run(this.context, args, {
|
|
1666
|
-
signal: opts?.signal
|
|
1667
|
-
});
|
|
1668
|
-
if (result.exitCode !== 0) {
|
|
1669
|
-
return void 0;
|
|
1670
|
-
}
|
|
1671
|
-
if (opts?.all) {
|
|
1672
|
-
return parseLines(result.stdout);
|
|
1673
|
-
}
|
|
1674
|
-
return result.stdout.trim();
|
|
2230
|
+
return readConfig(this.runner, this.context, key, opts);
|
|
1675
2231
|
}
|
|
1676
2232
|
/**
|
|
1677
2233
|
* Set a raw config value (for arbitrary keys)
|
|
@@ -1698,47 +2254,7 @@ var BareRepoImpl = class {
|
|
|
1698
2254
|
* List all config values
|
|
1699
2255
|
*/
|
|
1700
2256
|
async configList(opts) {
|
|
1701
|
-
|
|
1702
|
-
if (opts?.showOrigin) {
|
|
1703
|
-
args.push("--show-origin");
|
|
1704
|
-
}
|
|
1705
|
-
if (opts?.showScope) {
|
|
1706
|
-
args.push("--show-scope");
|
|
1707
|
-
}
|
|
1708
|
-
if (opts?.includes) {
|
|
1709
|
-
args.push("--includes");
|
|
1710
|
-
}
|
|
1711
|
-
if (opts?.nameOnly) {
|
|
1712
|
-
args.push("--name-only");
|
|
1713
|
-
}
|
|
1714
|
-
const result = await this.runner.runOrThrow(this.context, args, {
|
|
1715
|
-
signal: opts?.signal
|
|
1716
|
-
});
|
|
1717
|
-
const entries = [];
|
|
1718
|
-
for (const line of parseLines(result.stdout)) {
|
|
1719
|
-
let keyValue = line;
|
|
1720
|
-
if (opts?.showOrigin || opts?.showScope) {
|
|
1721
|
-
const tabIndex = line.lastIndexOf(" ");
|
|
1722
|
-
if (tabIndex !== -1) {
|
|
1723
|
-
keyValue = line.slice(tabIndex + 1);
|
|
1724
|
-
}
|
|
1725
|
-
}
|
|
1726
|
-
if (opts?.nameOnly) {
|
|
1727
|
-
entries.push({
|
|
1728
|
-
key: keyValue,
|
|
1729
|
-
value: ""
|
|
1730
|
-
});
|
|
1731
|
-
} else {
|
|
1732
|
-
const eqIndex = keyValue.indexOf("=");
|
|
1733
|
-
if (eqIndex !== -1) {
|
|
1734
|
-
entries.push({
|
|
1735
|
-
key: keyValue.slice(0, eqIndex),
|
|
1736
|
-
value: keyValue.slice(eqIndex + 1)
|
|
1737
|
-
});
|
|
1738
|
-
}
|
|
1739
|
-
}
|
|
1740
|
-
}
|
|
1741
|
-
return entries;
|
|
2257
|
+
return listConfig(this.runner, this.context, opts);
|
|
1742
2258
|
}
|
|
1743
2259
|
async configRenameSection(oldName, newName, opts) {
|
|
1744
2260
|
await this.runner.runOrThrow(this.context, ["config", "--rename-section", oldName, newName], {
|
|
@@ -1752,6 +2268,58 @@ var BareRepoImpl = class {
|
|
|
1752
2268
|
}
|
|
1753
2269
|
};
|
|
1754
2270
|
|
|
2271
|
+
// src/internal/lfs-output.ts
|
|
2272
|
+
function record(value) {
|
|
2273
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
2274
|
+
}
|
|
2275
|
+
function data(stdout) {
|
|
2276
|
+
try {
|
|
2277
|
+
const value = JSON.parse(stdout);
|
|
2278
|
+
if (record(value)) {
|
|
2279
|
+
return value;
|
|
2280
|
+
}
|
|
2281
|
+
} catch {
|
|
2282
|
+
}
|
|
2283
|
+
throw new GitError("ParseError", "Invalid Git LFS JSON", { stdout });
|
|
2284
|
+
}
|
|
2285
|
+
function validSize(value) {
|
|
2286
|
+
return typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
|
|
2287
|
+
}
|
|
2288
|
+
function parseLfsStatusJson(stdout) {
|
|
2289
|
+
const files = data(stdout).files;
|
|
2290
|
+
if (!record(files)) {
|
|
2291
|
+
throw new GitError("ParseError", "Missing Git LFS status files");
|
|
2292
|
+
}
|
|
2293
|
+
return {
|
|
2294
|
+
files: Object.entries(files).map(([name, value]) => {
|
|
2295
|
+
if (!record(value) || typeof value.status !== "string" || value.size !== void 0 && !validSize(value.size)) {
|
|
2296
|
+
throw new GitError("ParseError", "Invalid Git LFS status entry");
|
|
2297
|
+
}
|
|
2298
|
+
return { name, status: value.status, ...validSize(value.size) ? { size: value.size } : {} };
|
|
2299
|
+
})
|
|
2300
|
+
};
|
|
2301
|
+
}
|
|
2302
|
+
function parseLfsFilesJson(stdout) {
|
|
2303
|
+
const files = data(stdout).files;
|
|
2304
|
+
if (files === null) {
|
|
2305
|
+
return [];
|
|
2306
|
+
}
|
|
2307
|
+
if (!Array.isArray(files)) {
|
|
2308
|
+
throw new GitError("ParseError", "Missing Git LFS file list");
|
|
2309
|
+
}
|
|
2310
|
+
return files.map((value) => {
|
|
2311
|
+
if (!record(value) || typeof value.name !== "string" || typeof value.oid !== "string" || !/^[a-f0-9]{64}$/.test(value.oid) || typeof value.checkout !== "boolean" || !validSize(value.size)) {
|
|
2312
|
+
throw new GitError("ParseError", "Invalid Git LFS file entry");
|
|
2313
|
+
}
|
|
2314
|
+
return {
|
|
2315
|
+
path: value.name,
|
|
2316
|
+
oid: value.oid,
|
|
2317
|
+
size: value.size,
|
|
2318
|
+
status: value.checkout ? "checked-out" : "not-checked-out"
|
|
2319
|
+
};
|
|
2320
|
+
});
|
|
2321
|
+
}
|
|
2322
|
+
|
|
1755
2323
|
// src/internal/concurrency.ts
|
|
1756
2324
|
async function runWithConcurrency(items, run, options) {
|
|
1757
2325
|
const { concurrency, warmupCount = 0 } = options;
|
|
@@ -1800,6 +2368,7 @@ var PRE_UPLOAD_DEFAULT_BATCH_SIZE = 200;
|
|
|
1800
2368
|
var PRE_UPLOAD_DEFAULT_CONCURRENCY = 4;
|
|
1801
2369
|
var PRE_UPLOAD_WARMUP_BATCH_COUNT = 1;
|
|
1802
2370
|
var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
2371
|
+
kind = "worktree";
|
|
1803
2372
|
workdir;
|
|
1804
2373
|
runner;
|
|
1805
2374
|
_lfsMode = "enabled";
|
|
@@ -1947,6 +2516,7 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
1947
2516
|
* List references in a remote repository
|
|
1948
2517
|
*/
|
|
1949
2518
|
async lsRemote(remote, opts) {
|
|
2519
|
+
validateOptions("lsRemote", opts);
|
|
1950
2520
|
const args = ["ls-remote"];
|
|
1951
2521
|
if (opts?.heads) {
|
|
1952
2522
|
args.push("--heads");
|
|
@@ -1957,15 +2527,9 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
1957
2527
|
if (opts?.refsOnly) {
|
|
1958
2528
|
args.push("--refs");
|
|
1959
2529
|
}
|
|
1960
|
-
if (opts?.getUrl) {
|
|
1961
|
-
args.push("--get-url");
|
|
1962
|
-
}
|
|
1963
2530
|
if (opts?.sort) {
|
|
1964
2531
|
args.push("--sort", opts.sort);
|
|
1965
2532
|
}
|
|
1966
|
-
if (opts?.symref) {
|
|
1967
|
-
args.push("--symref");
|
|
1968
|
-
}
|
|
1969
2533
|
args.push(remote);
|
|
1970
2534
|
if (opts?.refs && opts.refs.length > 0) {
|
|
1971
2535
|
args.push(...opts.refs);
|
|
@@ -1977,11 +2541,9 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
1977
2541
|
const refs = parseLsRemote(result.stdout);
|
|
1978
2542
|
return { refs };
|
|
1979
2543
|
}
|
|
1980
|
-
/**
|
|
1981
|
-
* List contents of a tree object
|
|
1982
|
-
*/
|
|
1983
2544
|
async lsTree(treeish, opts) {
|
|
1984
|
-
|
|
2545
|
+
validateOptions("lsTree", opts);
|
|
2546
|
+
const args = ["ls-tree", "-z"];
|
|
1985
2547
|
if (opts?.recursive) {
|
|
1986
2548
|
args.push("-r");
|
|
1987
2549
|
}
|
|
@@ -1994,12 +2556,6 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
1994
2556
|
if (opts?.long) {
|
|
1995
2557
|
args.push("--long");
|
|
1996
2558
|
}
|
|
1997
|
-
if (opts?.nameOnly) {
|
|
1998
|
-
args.push("--name-only");
|
|
1999
|
-
}
|
|
2000
|
-
if (opts?.objectOnly) {
|
|
2001
|
-
args.push("--object-only");
|
|
2002
|
-
}
|
|
2003
2559
|
if (opts?.fullName) {
|
|
2004
2560
|
args.push("--full-name");
|
|
2005
2561
|
}
|
|
@@ -2020,20 +2576,21 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
2020
2576
|
const result = await this.runner.runOrThrow(this.context, args, {
|
|
2021
2577
|
signal: opts?.signal
|
|
2022
2578
|
});
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2579
|
+
const entries = parseLsTree(result.stdout, { long: opts?.long });
|
|
2580
|
+
if (opts?.nameOnly) {
|
|
2581
|
+
return entries.map((entry) => entry.path);
|
|
2582
|
+
}
|
|
2583
|
+
if (opts?.objectOnly) {
|
|
2584
|
+
return entries.map((entry) => entry.hash);
|
|
2585
|
+
}
|
|
2586
|
+
return entries;
|
|
2028
2587
|
}
|
|
2029
2588
|
/**
|
|
2030
2589
|
* Get repository status
|
|
2031
2590
|
*/
|
|
2032
2591
|
async status(opts) {
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
args.push("--verbose");
|
|
2036
|
-
}
|
|
2592
|
+
validateOptions("status", opts);
|
|
2593
|
+
const args = ["status", "--porcelain=v2", "-z"];
|
|
2037
2594
|
if (opts?.untracked) {
|
|
2038
2595
|
switch (opts.untracked) {
|
|
2039
2596
|
case "no":
|
|
@@ -2054,9 +2611,6 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
2054
2611
|
if (opts?.aheadBehind === false) {
|
|
2055
2612
|
args.push("--no-ahead-behind");
|
|
2056
2613
|
}
|
|
2057
|
-
if (opts?.nullTerminated) {
|
|
2058
|
-
args.push("-z");
|
|
2059
|
-
}
|
|
2060
2614
|
if (opts?.ignored) {
|
|
2061
2615
|
switch (opts.ignored) {
|
|
2062
2616
|
case "traditional":
|
|
@@ -2088,81 +2642,60 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
2088
2642
|
return this.parseStatus(result.stdout);
|
|
2089
2643
|
}
|
|
2090
2644
|
parseStatus(stdout) {
|
|
2091
|
-
const
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
let behind;
|
|
2097
|
-
for (const line of lines) {
|
|
2098
|
-
if (line.startsWith("# branch.head ")) {
|
|
2099
|
-
branch = line.slice("# branch.head ".length);
|
|
2100
|
-
} else if (line.startsWith("# branch.upstream ")) {
|
|
2101
|
-
upstream = line.slice("# branch.upstream ".length);
|
|
2102
|
-
} else if (line.startsWith("# branch.ab ")) {
|
|
2103
|
-
const match = line.match(/# branch\.ab \+(\d+) -(\d+)/);
|
|
2104
|
-
const aheadStr = match?.[1];
|
|
2105
|
-
const behindStr = match?.[2];
|
|
2106
|
-
if (aheadStr !== void 0 && behindStr !== void 0) {
|
|
2107
|
-
ahead = Number.parseInt(aheadStr, 10);
|
|
2108
|
-
behind = Number.parseInt(behindStr, 10);
|
|
2109
|
-
}
|
|
2110
|
-
} else if (line.startsWith("1 ") || line.startsWith("2 ")) {
|
|
2111
|
-
const parsed = parsePorcelainV2(line);
|
|
2112
|
-
const entry = parsed[0];
|
|
2113
|
-
if (entry?.type === "changed") {
|
|
2114
|
-
const indexStatus = entry.xy[0];
|
|
2115
|
-
const workdirStatus = entry.xy[1];
|
|
2116
|
-
if (indexStatus !== void 0 && workdirStatus !== void 0) {
|
|
2117
|
-
entries.push({
|
|
2118
|
-
path: entry.path,
|
|
2119
|
-
index: indexStatus,
|
|
2120
|
-
workdir: workdirStatus,
|
|
2121
|
-
originalPath: entry.origPath
|
|
2122
|
-
});
|
|
2123
|
-
}
|
|
2124
|
-
}
|
|
2125
|
-
} else if (line.startsWith("u ")) {
|
|
2126
|
-
const parsed = parsePorcelainV2(line);
|
|
2127
|
-
const entry = parsed[0];
|
|
2128
|
-
if (entry?.type === "unmerged") {
|
|
2129
|
-
const indexStatus = entry.xy[0];
|
|
2130
|
-
const workdirStatus = entry.xy[1];
|
|
2131
|
-
if (indexStatus !== void 0 && workdirStatus !== void 0) {
|
|
2132
|
-
entries.push({
|
|
2133
|
-
path: entry.path,
|
|
2134
|
-
index: indexStatus,
|
|
2135
|
-
workdir: workdirStatus
|
|
2136
|
-
});
|
|
2137
|
-
}
|
|
2645
|
+
const result = {
|
|
2646
|
+
entries: parsePorcelainV2(stdout).map((entry) => {
|
|
2647
|
+
if (entry.type === "untracked" || entry.type === "ignored") {
|
|
2648
|
+
const status = entry.type === "untracked" ? "?" : "!";
|
|
2649
|
+
return { path: entry.path, index: status, workdir: status };
|
|
2138
2650
|
}
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
}
|
|
2145
|
-
}
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2651
|
+
return {
|
|
2652
|
+
path: entry.path,
|
|
2653
|
+
index: entry.xy[0],
|
|
2654
|
+
workdir: entry.xy[1],
|
|
2655
|
+
..."origPath" in entry && entry.origPath !== void 0 ? { originalPath: entry.origPath } : {}
|
|
2656
|
+
};
|
|
2657
|
+
})
|
|
2658
|
+
};
|
|
2659
|
+
const records = stdout.includes("\0") ? parseRecords(stdout) : parseLines(stdout, { trim: false });
|
|
2660
|
+
for (let i = 0; i < records.length; i++) {
|
|
2661
|
+
const line = records[i];
|
|
2662
|
+
if (line.startsWith("2 ") && stdout.includes("\0")) {
|
|
2663
|
+
i++;
|
|
2664
|
+
continue;
|
|
2665
|
+
}
|
|
2666
|
+
if (line.startsWith("# branch.head ")) {
|
|
2667
|
+
result.branch = line.slice(14);
|
|
2668
|
+
}
|
|
2669
|
+
if (line.startsWith("# branch.upstream ")) {
|
|
2670
|
+
result.upstream = line.slice(18);
|
|
2671
|
+
}
|
|
2672
|
+
const ab = line.match(/^# branch\.ab \+(\d+) -(\d+)$/);
|
|
2673
|
+
if (ab) {
|
|
2674
|
+
result.ahead = Number(ab[1]);
|
|
2675
|
+
result.behind = Number(ab[2]);
|
|
2676
|
+
}
|
|
2677
|
+
if (line.startsWith("# stash ")) {
|
|
2678
|
+
result.stash = Number(line.slice(8));
|
|
2151
2679
|
}
|
|
2152
2680
|
}
|
|
2153
|
-
return
|
|
2154
|
-
entries,
|
|
2155
|
-
branch,
|
|
2156
|
-
upstream,
|
|
2157
|
-
ahead,
|
|
2158
|
-
behind
|
|
2159
|
-
};
|
|
2681
|
+
return result;
|
|
2160
2682
|
}
|
|
2161
2683
|
/**
|
|
2162
2684
|
* Get commit log
|
|
2163
2685
|
*/
|
|
2164
2686
|
async log(opts) {
|
|
2165
|
-
|
|
2687
|
+
validateOptions("log", opts);
|
|
2688
|
+
const format = opts?.useMailmap ? GIT_LOG_FORMAT.replace("%an", "%aN").replace("%ae", "%aE").replace("%cn", "%cN").replace("%ce", "%cE") : GIT_LOG_FORMAT;
|
|
2689
|
+
const args = [
|
|
2690
|
+
"log",
|
|
2691
|
+
"-z",
|
|
2692
|
+
"--no-patch",
|
|
2693
|
+
"--no-notes",
|
|
2694
|
+
"--no-show-signature",
|
|
2695
|
+
"--no-color",
|
|
2696
|
+
"--encoding=UTF-8",
|
|
2697
|
+
`--format=${format}`
|
|
2698
|
+
];
|
|
2166
2699
|
if (opts?.maxCount !== void 0) {
|
|
2167
2700
|
args.push(`-n${opts.maxCount}`);
|
|
2168
2701
|
}
|
|
@@ -2195,33 +2728,9 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
2195
2728
|
if (opts?.firstParent) {
|
|
2196
2729
|
args.push("--first-parent");
|
|
2197
2730
|
}
|
|
2198
|
-
if (opts?.source) {
|
|
2199
|
-
args.push("--source");
|
|
2200
|
-
}
|
|
2201
2731
|
if (opts?.useMailmap) {
|
|
2202
2732
|
args.push("--use-mailmap");
|
|
2203
2733
|
}
|
|
2204
|
-
if (opts?.decorateRefs) {
|
|
2205
|
-
args.push(`--decorate-refs=${opts.decorateRefs}`);
|
|
2206
|
-
}
|
|
2207
|
-
if (opts?.decorateRefsExclude) {
|
|
2208
|
-
args.push(`--decorate-refs-exclude=${opts.decorateRefsExclude}`);
|
|
2209
|
-
}
|
|
2210
|
-
if (opts?.decorate) {
|
|
2211
|
-
args.push(`--decorate=${opts.decorate}`);
|
|
2212
|
-
}
|
|
2213
|
-
if (opts?.stat) {
|
|
2214
|
-
args.push("--stat");
|
|
2215
|
-
}
|
|
2216
|
-
if (opts?.shortstat) {
|
|
2217
|
-
args.push("--shortstat");
|
|
2218
|
-
}
|
|
2219
|
-
if (opts?.nameOnly) {
|
|
2220
|
-
args.push("--name-only");
|
|
2221
|
-
}
|
|
2222
|
-
if (opts?.nameStatus) {
|
|
2223
|
-
args.push("--name-status");
|
|
2224
|
-
}
|
|
2225
2734
|
if (opts?.merges) {
|
|
2226
2735
|
args.push("--merges");
|
|
2227
2736
|
}
|
|
@@ -2263,230 +2772,13 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
2263
2772
|
* Fetch from remote
|
|
2264
2773
|
*/
|
|
2265
2774
|
async fetch(opts) {
|
|
2266
|
-
|
|
2267
|
-
if (opts?.onProgress) {
|
|
2268
|
-
args.push("--progress");
|
|
2269
|
-
}
|
|
2270
|
-
if (opts?.verbose) {
|
|
2271
|
-
args.push("--verbose");
|
|
2272
|
-
}
|
|
2273
|
-
if (opts?.quiet) {
|
|
2274
|
-
args.push("--quiet");
|
|
2275
|
-
}
|
|
2276
|
-
if (opts?.all) {
|
|
2277
|
-
args.push("--all");
|
|
2278
|
-
}
|
|
2279
|
-
if (opts?.setUpstream) {
|
|
2280
|
-
args.push("--set-upstream");
|
|
2281
|
-
}
|
|
2282
|
-
if (opts?.append) {
|
|
2283
|
-
args.push("--append");
|
|
2284
|
-
}
|
|
2285
|
-
if (opts?.atomic) {
|
|
2286
|
-
args.push("--atomic");
|
|
2287
|
-
}
|
|
2288
|
-
if (opts?.force) {
|
|
2289
|
-
args.push("--force");
|
|
2290
|
-
}
|
|
2291
|
-
if (opts?.multiple) {
|
|
2292
|
-
args.push("--multiple");
|
|
2293
|
-
}
|
|
2294
|
-
if (opts?.prune) {
|
|
2295
|
-
args.push("--prune");
|
|
2296
|
-
}
|
|
2297
|
-
if (opts?.pruneTags) {
|
|
2298
|
-
args.push("--prune-tags");
|
|
2299
|
-
}
|
|
2300
|
-
if (opts?.tags) {
|
|
2301
|
-
args.push("--tags");
|
|
2302
|
-
} else if (opts?.noTags) {
|
|
2303
|
-
args.push("--no-tags");
|
|
2304
|
-
}
|
|
2305
|
-
if (opts?.jobs !== void 0) {
|
|
2306
|
-
args.push(`--jobs=${opts.jobs}`);
|
|
2307
|
-
}
|
|
2308
|
-
if (opts?.prefetch) {
|
|
2309
|
-
args.push("--prefetch");
|
|
2310
|
-
}
|
|
2311
|
-
if (opts?.recurseSubmodules !== void 0) {
|
|
2312
|
-
if (opts.recurseSubmodules === true || opts.recurseSubmodules === "yes") {
|
|
2313
|
-
args.push("--recurse-submodules=yes");
|
|
2314
|
-
} else if (opts.recurseSubmodules === "on-demand") {
|
|
2315
|
-
args.push("--recurse-submodules=on-demand");
|
|
2316
|
-
} else if (opts.recurseSubmodules === "no" || opts.recurseSubmodules === false) {
|
|
2317
|
-
args.push("--recurse-submodules=no");
|
|
2318
|
-
}
|
|
2319
|
-
}
|
|
2320
|
-
if (opts?.dryRun) {
|
|
2321
|
-
args.push("--dry-run");
|
|
2322
|
-
}
|
|
2323
|
-
if (opts?.writeFetchHead === false) {
|
|
2324
|
-
args.push("--no-write-fetch-head");
|
|
2325
|
-
}
|
|
2326
|
-
if (opts?.keep) {
|
|
2327
|
-
args.push("--keep");
|
|
2328
|
-
}
|
|
2329
|
-
if (opts?.updateHeadOk) {
|
|
2330
|
-
args.push("--update-head-ok");
|
|
2331
|
-
}
|
|
2332
|
-
if (opts?.depth !== void 0) {
|
|
2333
|
-
args.push(`--depth=${opts.depth}`);
|
|
2334
|
-
}
|
|
2335
|
-
if (opts?.shallowSince) {
|
|
2336
|
-
const since = opts.shallowSince instanceof Date ? opts.shallowSince.toISOString() : opts.shallowSince;
|
|
2337
|
-
args.push(`--shallow-since=${since}`);
|
|
2338
|
-
}
|
|
2339
|
-
if (opts?.shallowExclude) {
|
|
2340
|
-
const excludes = Array.isArray(opts.shallowExclude) ? opts.shallowExclude : [opts.shallowExclude];
|
|
2341
|
-
for (const exclude of excludes) {
|
|
2342
|
-
args.push(`--shallow-exclude=${exclude}`);
|
|
2343
|
-
}
|
|
2344
|
-
}
|
|
2345
|
-
if (opts?.deepen !== void 0) {
|
|
2346
|
-
args.push(`--deepen=${opts.deepen}`);
|
|
2347
|
-
}
|
|
2348
|
-
if (opts?.unshallow) {
|
|
2349
|
-
args.push("--unshallow");
|
|
2350
|
-
}
|
|
2351
|
-
if (opts?.refetch) {
|
|
2352
|
-
args.push("--refetch");
|
|
2353
|
-
}
|
|
2354
|
-
if (opts?.updateShallow) {
|
|
2355
|
-
args.push("--update-shallow");
|
|
2356
|
-
}
|
|
2357
|
-
if (opts?.refmap) {
|
|
2358
|
-
args.push(`--refmap=${opts.refmap}`);
|
|
2359
|
-
}
|
|
2360
|
-
if (opts?.ipv4) {
|
|
2361
|
-
args.push("--ipv4");
|
|
2362
|
-
}
|
|
2363
|
-
if (opts?.ipv6) {
|
|
2364
|
-
args.push("--ipv6");
|
|
2365
|
-
}
|
|
2366
|
-
if (opts?.filter) {
|
|
2367
|
-
args.push(`--filter=${opts.filter}`);
|
|
2368
|
-
}
|
|
2369
|
-
if (opts?.showForcedUpdates === false) {
|
|
2370
|
-
args.push("--no-show-forced-updates");
|
|
2371
|
-
}
|
|
2372
|
-
if (opts?.writeCommitGraph) {
|
|
2373
|
-
args.push("--write-commit-graph");
|
|
2374
|
-
}
|
|
2375
|
-
if (opts?.remote) {
|
|
2376
|
-
args.push(opts.remote);
|
|
2377
|
-
}
|
|
2378
|
-
if (opts?.refspec) {
|
|
2379
|
-
const refspecs = Array.isArray(opts.refspec) ? opts.refspec : [opts.refspec];
|
|
2380
|
-
args.push(...refspecs);
|
|
2381
|
-
}
|
|
2382
|
-
await this.runner.runOrThrow(this.context, args, {
|
|
2383
|
-
signal: opts?.signal,
|
|
2384
|
-
onProgress: opts?.onProgress
|
|
2385
|
-
});
|
|
2775
|
+
return fetch(this.runner, this.context, opts);
|
|
2386
2776
|
}
|
|
2387
2777
|
/**
|
|
2388
2778
|
* Push to remote
|
|
2389
2779
|
*/
|
|
2390
2780
|
async push(opts) {
|
|
2391
|
-
|
|
2392
|
-
if (opts?.onProgress || opts?.onLfsProgress) {
|
|
2393
|
-
args.push("--progress");
|
|
2394
|
-
}
|
|
2395
|
-
if (opts?.verbose) {
|
|
2396
|
-
args.push("--verbose");
|
|
2397
|
-
}
|
|
2398
|
-
if (opts?.quiet) {
|
|
2399
|
-
args.push("--quiet");
|
|
2400
|
-
}
|
|
2401
|
-
if (opts?.repo) {
|
|
2402
|
-
args.push(`--repo=${opts.repo}`);
|
|
2403
|
-
}
|
|
2404
|
-
if (opts?.all) {
|
|
2405
|
-
args.push("--all");
|
|
2406
|
-
} else if (opts?.branches) {
|
|
2407
|
-
args.push("--branches");
|
|
2408
|
-
}
|
|
2409
|
-
if (opts?.mirror) {
|
|
2410
|
-
args.push("--mirror");
|
|
2411
|
-
}
|
|
2412
|
-
if (opts?.deleteRefs) {
|
|
2413
|
-
args.push("--delete");
|
|
2414
|
-
}
|
|
2415
|
-
if (opts?.force) {
|
|
2416
|
-
args.push("--force");
|
|
2417
|
-
} else if (opts?.forceWithLease !== void 0 && opts.forceWithLease !== false) {
|
|
2418
|
-
if (opts.forceWithLease === true) {
|
|
2419
|
-
args.push("--force-with-lease");
|
|
2420
|
-
} else {
|
|
2421
|
-
const leaseOpts = opts.forceWithLease;
|
|
2422
|
-
if (leaseOpts.expect !== void 0) {
|
|
2423
|
-
args.push(`--force-with-lease=${leaseOpts.refname}:${leaseOpts.expect}`);
|
|
2424
|
-
} else {
|
|
2425
|
-
args.push(`--force-with-lease=${leaseOpts.refname}`);
|
|
2426
|
-
}
|
|
2427
|
-
}
|
|
2428
|
-
}
|
|
2429
|
-
if (opts?.forceIfIncludes) {
|
|
2430
|
-
args.push("--force-if-includes");
|
|
2431
|
-
}
|
|
2432
|
-
if (opts?.dryRun) {
|
|
2433
|
-
args.push("--dry-run");
|
|
2434
|
-
}
|
|
2435
|
-
if (opts?.recurseSubmodules) {
|
|
2436
|
-
args.push(`--recurse-submodules=${opts.recurseSubmodules}`);
|
|
2437
|
-
}
|
|
2438
|
-
if (opts?.thin === false) {
|
|
2439
|
-
args.push("--no-thin");
|
|
2440
|
-
}
|
|
2441
|
-
if (opts?.prune) {
|
|
2442
|
-
args.push("--prune");
|
|
2443
|
-
}
|
|
2444
|
-
if (opts?.tags) {
|
|
2445
|
-
args.push("--tags");
|
|
2446
|
-
}
|
|
2447
|
-
if (opts?.followTags) {
|
|
2448
|
-
args.push("--follow-tags");
|
|
2449
|
-
}
|
|
2450
|
-
if (opts?.atomic) {
|
|
2451
|
-
args.push("--atomic");
|
|
2452
|
-
}
|
|
2453
|
-
if (opts?.pushOption) {
|
|
2454
|
-
const pushOptions = Array.isArray(opts.pushOption) ? opts.pushOption : [opts.pushOption];
|
|
2455
|
-
for (const opt of pushOptions) {
|
|
2456
|
-
args.push("--push-option", opt);
|
|
2457
|
-
}
|
|
2458
|
-
}
|
|
2459
|
-
if (opts?.setUpstream) {
|
|
2460
|
-
args.push("--set-upstream");
|
|
2461
|
-
}
|
|
2462
|
-
if (opts?.noVerify) {
|
|
2463
|
-
args.push("--no-verify");
|
|
2464
|
-
}
|
|
2465
|
-
if (opts?.signed !== void 0) {
|
|
2466
|
-
if (opts.signed === true) {
|
|
2467
|
-
args.push("--signed");
|
|
2468
|
-
} else if (opts.signed === "if-asked") {
|
|
2469
|
-
args.push("--signed=if-asked");
|
|
2470
|
-
}
|
|
2471
|
-
}
|
|
2472
|
-
if (opts?.ipv4) {
|
|
2473
|
-
args.push("--ipv4");
|
|
2474
|
-
}
|
|
2475
|
-
if (opts?.ipv6) {
|
|
2476
|
-
args.push("--ipv6");
|
|
2477
|
-
}
|
|
2478
|
-
if (opts?.remote) {
|
|
2479
|
-
args.push(opts.remote);
|
|
2480
|
-
}
|
|
2481
|
-
if (opts?.refspec) {
|
|
2482
|
-
const refspecs = Array.isArray(opts.refspec) ? opts.refspec : [opts.refspec];
|
|
2483
|
-
args.push(...refspecs);
|
|
2484
|
-
}
|
|
2485
|
-
await this.runner.runOrThrow(this.context, args, {
|
|
2486
|
-
signal: opts?.signal,
|
|
2487
|
-
onProgress: opts?.onProgress,
|
|
2488
|
-
onLfsProgress: opts?.onLfsProgress
|
|
2489
|
-
});
|
|
2781
|
+
return push(this.runner, this.context, opts);
|
|
2490
2782
|
}
|
|
2491
2783
|
/**
|
|
2492
2784
|
* Configure LFS mode for this repository
|
|
@@ -2521,6 +2813,7 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
2521
2813
|
// LFS Operations
|
|
2522
2814
|
// ==========================================================================
|
|
2523
2815
|
async lfsPull(opts) {
|
|
2816
|
+
validateOptions("lfsPull", opts);
|
|
2524
2817
|
if (this._lfsMode === "disabled") {
|
|
2525
2818
|
return;
|
|
2526
2819
|
}
|
|
@@ -2528,13 +2821,10 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
2528
2821
|
if (opts?.remote) {
|
|
2529
2822
|
args.push(opts.remote);
|
|
2530
2823
|
}
|
|
2531
|
-
if (opts?.
|
|
2532
|
-
args.push(opts.ref);
|
|
2533
|
-
}
|
|
2534
|
-
if (opts?.include && opts.include.length > 0) {
|
|
2824
|
+
if (opts?.include !== void 0) {
|
|
2535
2825
|
args.push("--include", opts.include.join(","));
|
|
2536
2826
|
}
|
|
2537
|
-
if (opts?.exclude
|
|
2827
|
+
if (opts?.exclude !== void 0) {
|
|
2538
2828
|
args.push("--exclude", opts.exclude.join(","));
|
|
2539
2829
|
}
|
|
2540
2830
|
await this.runner.runOrThrow(this.context, args, {
|
|
@@ -2544,6 +2834,7 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
2544
2834
|
});
|
|
2545
2835
|
}
|
|
2546
2836
|
async lfsPush(opts) {
|
|
2837
|
+
validateOptions("lfsPush", opts);
|
|
2547
2838
|
if (this._lfsMode === "disabled") {
|
|
2548
2839
|
return;
|
|
2549
2840
|
}
|
|
@@ -2577,33 +2868,9 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
2577
2868
|
});
|
|
2578
2869
|
}
|
|
2579
2870
|
async lfsStatus(opts) {
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
}
|
|
2584
|
-
if (opts?.porcelain) {
|
|
2585
|
-
args.push("--porcelain");
|
|
2586
|
-
}
|
|
2587
|
-
const result = await this.runner.runOrThrow(this.context, args, {
|
|
2588
|
-
signal: opts?.signal
|
|
2589
|
-
});
|
|
2590
|
-
const files = [];
|
|
2591
|
-
if (opts?.json) {
|
|
2592
|
-
try {
|
|
2593
|
-
const json = JSON.parse(result.stdout);
|
|
2594
|
-
if (json.files) {
|
|
2595
|
-
for (const [name, info] of Object.entries(json.files)) {
|
|
2596
|
-
files.push({
|
|
2597
|
-
name,
|
|
2598
|
-
size: info.size ?? 0,
|
|
2599
|
-
status: "unknown"
|
|
2600
|
-
});
|
|
2601
|
-
}
|
|
2602
|
-
}
|
|
2603
|
-
} catch {
|
|
2604
|
-
}
|
|
2605
|
-
}
|
|
2606
|
-
return { files };
|
|
2871
|
+
validateOptions("lfsStatus", opts);
|
|
2872
|
+
const result = await this.runner.runOrThrow(this.context, ["lfs", "status", "--json"], opts);
|
|
2873
|
+
return parseLfsStatusJson(result.stdout);
|
|
2607
2874
|
}
|
|
2608
2875
|
/**
|
|
2609
2876
|
* Pre-upload LFS objects before commit/push (2-phase commit pattern)
|
|
@@ -2831,12 +3098,19 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
2831
3098
|
});
|
|
2832
3099
|
}
|
|
2833
3100
|
async lfsFetch(opts) {
|
|
3101
|
+
validateOptions("lfsFetch", opts);
|
|
2834
3102
|
if (this._lfsMode === "disabled") {
|
|
2835
3103
|
return;
|
|
2836
3104
|
}
|
|
2837
3105
|
const args = ["lfs", "fetch"];
|
|
2838
|
-
if (opts?.
|
|
2839
|
-
args.push("--
|
|
3106
|
+
if (opts?.dryRun) {
|
|
3107
|
+
args.push("--dry-run");
|
|
3108
|
+
}
|
|
3109
|
+
if (opts?.refetch) {
|
|
3110
|
+
args.push("--refetch");
|
|
3111
|
+
}
|
|
3112
|
+
if (opts?.json) {
|
|
3113
|
+
args.push("--json");
|
|
2840
3114
|
}
|
|
2841
3115
|
if (opts?.all) {
|
|
2842
3116
|
args.push("--all");
|
|
@@ -2849,18 +3123,14 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
2849
3123
|
}
|
|
2850
3124
|
if (opts?.include) {
|
|
2851
3125
|
const patterns = Array.isArray(opts.include) ? opts.include : [opts.include];
|
|
2852
|
-
|
|
2853
|
-
args.push("--include", pattern);
|
|
2854
|
-
}
|
|
3126
|
+
args.push("--include", patterns.join(","));
|
|
2855
3127
|
}
|
|
2856
3128
|
if (opts?.exclude) {
|
|
2857
3129
|
const patterns = Array.isArray(opts.exclude) ? opts.exclude : [opts.exclude];
|
|
2858
|
-
|
|
2859
|
-
args.push("--exclude", pattern);
|
|
2860
|
-
}
|
|
3130
|
+
args.push("--exclude", patterns.join(","));
|
|
2861
3131
|
}
|
|
2862
|
-
if (opts?.remote) {
|
|
2863
|
-
args.push(opts.remote);
|
|
3132
|
+
if (opts?.remote || opts?.refs) {
|
|
3133
|
+
args.push(opts.remote ?? "origin");
|
|
2864
3134
|
}
|
|
2865
3135
|
if (opts?.refs) {
|
|
2866
3136
|
const refList = Array.isArray(opts.refs) ? opts.refs : [opts.refs];
|
|
@@ -2901,19 +3171,17 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
2901
3171
|
});
|
|
2902
3172
|
}
|
|
2903
3173
|
async lfsLsFiles(opts) {
|
|
3174
|
+
validateOptions("lfsLsFiles", opts);
|
|
2904
3175
|
if (this._lfsMode === "disabled") {
|
|
2905
3176
|
return [];
|
|
2906
3177
|
}
|
|
2907
|
-
const args = ["lfs", "ls-files"];
|
|
3178
|
+
const args = ["lfs", "ls-files", "--json"];
|
|
2908
3179
|
if (opts?.long) {
|
|
2909
3180
|
args.push("--long");
|
|
2910
3181
|
}
|
|
2911
3182
|
if (opts?.size) {
|
|
2912
3183
|
args.push("--size");
|
|
2913
3184
|
}
|
|
2914
|
-
if (opts?.debug) {
|
|
2915
|
-
args.push("--debug");
|
|
2916
|
-
}
|
|
2917
3185
|
if (opts?.all) {
|
|
2918
3186
|
args.push("--all");
|
|
2919
3187
|
}
|
|
@@ -2922,15 +3190,11 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
2922
3190
|
}
|
|
2923
3191
|
if (opts?.include) {
|
|
2924
3192
|
const patterns = Array.isArray(opts.include) ? opts.include : [opts.include];
|
|
2925
|
-
|
|
2926
|
-
args.push("--include", pattern);
|
|
2927
|
-
}
|
|
3193
|
+
args.push("--include", patterns.join(","));
|
|
2928
3194
|
}
|
|
2929
3195
|
if (opts?.exclude) {
|
|
2930
3196
|
const patterns = Array.isArray(opts.exclude) ? opts.exclude : [opts.exclude];
|
|
2931
|
-
|
|
2932
|
-
args.push("--exclude", pattern);
|
|
2933
|
-
}
|
|
3197
|
+
args.push("--exclude", patterns.join(","));
|
|
2934
3198
|
}
|
|
2935
3199
|
if (opts?.ref) {
|
|
2936
3200
|
args.push(opts.ref);
|
|
@@ -2938,19 +3202,7 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
2938
3202
|
const result = await this.runner.runOrThrow(this.context, args, {
|
|
2939
3203
|
signal: opts?.signal
|
|
2940
3204
|
});
|
|
2941
|
-
|
|
2942
|
-
for (const line of parseLines(result.stdout)) {
|
|
2943
|
-
const match = line.match(/^([0-9a-f]+)\s+([-*])\s+(.+?)(?:\s+\((\d+)\s*(?:B|bytes)?\))?$/);
|
|
2944
|
-
if (match) {
|
|
2945
|
-
entries.push({
|
|
2946
|
-
oid: match[1],
|
|
2947
|
-
path: match[3],
|
|
2948
|
-
size: match[4] ? Number.parseInt(match[4], 10) : void 0,
|
|
2949
|
-
status: match[2] === "*" ? "checked-out" : "not-checked-out"
|
|
2950
|
-
});
|
|
2951
|
-
}
|
|
2952
|
-
}
|
|
2953
|
-
return entries;
|
|
3205
|
+
return parseLfsFilesJson(result.stdout);
|
|
2954
3206
|
}
|
|
2955
3207
|
async lfsTrack(patterns, opts) {
|
|
2956
3208
|
const args = ["lfs", "track"];
|
|
@@ -3015,12 +3267,12 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
3015
3267
|
const result = await this.runner.runOrThrow(this.context, args, {
|
|
3016
3268
|
signal: opts?.signal
|
|
3017
3269
|
});
|
|
3018
|
-
const
|
|
3270
|
+
const data2 = JSON.parse(result.stdout);
|
|
3019
3271
|
return {
|
|
3020
|
-
id:
|
|
3021
|
-
path:
|
|
3022
|
-
owner: { name:
|
|
3023
|
-
lockedAt: new Date(
|
|
3272
|
+
id: data2.id,
|
|
3273
|
+
path: data2.path,
|
|
3274
|
+
owner: { name: data2.owner.name },
|
|
3275
|
+
lockedAt: new Date(data2.locked_at)
|
|
3024
3276
|
};
|
|
3025
3277
|
}
|
|
3026
3278
|
async lfsUnlock(pathOrId, opts) {
|
|
@@ -3068,8 +3320,8 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
3068
3320
|
const result = await this.runner.runOrThrow(this.context, args, {
|
|
3069
3321
|
signal: opts?.signal
|
|
3070
3322
|
});
|
|
3071
|
-
const
|
|
3072
|
-
return
|
|
3323
|
+
const data2 = JSON.parse(result.stdout);
|
|
3324
|
+
return data2.map((lock) => ({
|
|
3073
3325
|
id: lock.id,
|
|
3074
3326
|
path: lock.path,
|
|
3075
3327
|
owner: { name: lock.owner.name },
|
|
@@ -3286,6 +3538,7 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
3286
3538
|
return parseWorktreeList(result.stdout);
|
|
3287
3539
|
}
|
|
3288
3540
|
async worktreeAdd(path, opts) {
|
|
3541
|
+
validateOptions("worktreeAdd", opts);
|
|
3289
3542
|
const args = ["worktree", "add"];
|
|
3290
3543
|
if (opts?.detach) {
|
|
3291
3544
|
args.push("--detach");
|
|
@@ -3381,10 +3634,9 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
3381
3634
|
signal: opts?.signal
|
|
3382
3635
|
});
|
|
3383
3636
|
}
|
|
3384
|
-
// ==========================================================================
|
|
3385
|
-
// High-level API - add
|
|
3386
|
-
// ==========================================================================
|
|
3387
3637
|
async add(paths, opts) {
|
|
3638
|
+
validatePathInput("add", paths, opts);
|
|
3639
|
+
validateOptions("add", opts);
|
|
3388
3640
|
const args = ["add"];
|
|
3389
3641
|
if (opts?.verbose) {
|
|
3390
3642
|
args.push("--verbose");
|
|
@@ -3500,12 +3752,12 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
3500
3752
|
return branches;
|
|
3501
3753
|
}
|
|
3502
3754
|
async branchCurrent(opts) {
|
|
3503
|
-
const
|
|
3504
|
-
|
|
3505
|
-
|
|
3506
|
-
if (result.exitCode !== 0) {
|
|
3755
|
+
const args = ["symbolic-ref", "--quiet", "--short", "HEAD"];
|
|
3756
|
+
const result = await this.runner.run(this.context, args, opts);
|
|
3757
|
+
if (result.exitCode === 1 && !result.aborted) {
|
|
3507
3758
|
return null;
|
|
3508
3759
|
}
|
|
3760
|
+
this.runner.checkResult(this.context, args, result);
|
|
3509
3761
|
return result.stdout.trim();
|
|
3510
3762
|
}
|
|
3511
3763
|
async branchCreate(name, opts) {
|
|
@@ -3555,9 +3807,11 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
3555
3807
|
}
|
|
3556
3808
|
// Implementation
|
|
3557
3809
|
async checkout(targetOrPaths, opts) {
|
|
3810
|
+
validateOptions(Array.isArray(targetOrPaths) ? "checkoutPath" : "checkoutBranch", opts);
|
|
3558
3811
|
const args = ["checkout"];
|
|
3559
3812
|
const isPathMode = Array.isArray(targetOrPaths);
|
|
3560
3813
|
if (isPathMode) {
|
|
3814
|
+
validatePathInput("checkout", targetOrPaths, opts);
|
|
3561
3815
|
const pathOpts = opts;
|
|
3562
3816
|
if (pathOpts?.force) {
|
|
3563
3817
|
args.push("--force");
|
|
@@ -3639,6 +3893,7 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
3639
3893
|
// High-level API - commit
|
|
3640
3894
|
// ==========================================================================
|
|
3641
3895
|
async commit(opts) {
|
|
3896
|
+
validateOptions("commit", opts);
|
|
3642
3897
|
const args = ["commit"];
|
|
3643
3898
|
if (opts?.message) {
|
|
3644
3899
|
args.push("-m", opts.message);
|
|
@@ -3659,9 +3914,6 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
3659
3914
|
const date = opts.date instanceof Date ? opts.date.toISOString() : opts.date;
|
|
3660
3915
|
args.push("--date", date);
|
|
3661
3916
|
}
|
|
3662
|
-
if (opts?.dryRun) {
|
|
3663
|
-
args.push("--dry-run");
|
|
3664
|
-
}
|
|
3665
3917
|
if (opts?.noVerify) {
|
|
3666
3918
|
args.push("--no-verify");
|
|
3667
3919
|
}
|
|
@@ -3679,9 +3931,6 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
3679
3931
|
if (opts?.file) {
|
|
3680
3932
|
args.push("--file", opts.file);
|
|
3681
3933
|
}
|
|
3682
|
-
if (opts?.reeditMessage) {
|
|
3683
|
-
args.push("--reedit-message", opts.reeditMessage);
|
|
3684
|
-
}
|
|
3685
3934
|
if (opts?.reuseMessage) {
|
|
3686
3935
|
args.push("--reuse-message", opts.reuseMessage);
|
|
3687
3936
|
}
|
|
@@ -3724,10 +3973,9 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
3724
3973
|
if (opts?.allowEmptyMessage) {
|
|
3725
3974
|
args.push("--allow-empty-message");
|
|
3726
3975
|
}
|
|
3727
|
-
|
|
3976
|
+
await this.runner.runOrThrow(this.context, args, {
|
|
3728
3977
|
signal: opts?.signal
|
|
3729
3978
|
});
|
|
3730
|
-
const output = result.stdout;
|
|
3731
3979
|
let hash = "";
|
|
3732
3980
|
let branch = "";
|
|
3733
3981
|
let summary = "";
|
|
@@ -3738,17 +3986,29 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
3738
3986
|
signal: opts?.signal
|
|
3739
3987
|
});
|
|
3740
3988
|
hash = hashResult.stdout.trim();
|
|
3741
|
-
|
|
3742
|
-
|
|
3743
|
-
|
|
3744
|
-
|
|
3745
|
-
|
|
3746
|
-
/(\d+) files? changed(?:, (\d+) insertions?\(\+\))?(?:, (\d+) deletions?\(-\))?/
|
|
3989
|
+
branch = await this.branchCurrent(opts) ?? "HEAD";
|
|
3990
|
+
const stats = await this.runner.runOrThrow(
|
|
3991
|
+
this.context,
|
|
3992
|
+
["diff-tree", "--root", "--no-commit-id", "--numstat", "-r", "-z", "-M", hash],
|
|
3993
|
+
opts
|
|
3747
3994
|
);
|
|
3748
|
-
|
|
3749
|
-
|
|
3750
|
-
|
|
3751
|
-
|
|
3995
|
+
const records = parseRecords(stats.stdout);
|
|
3996
|
+
for (let i = 0; i < records.length; i++) {
|
|
3997
|
+
const record2 = records[i];
|
|
3998
|
+
const match = record2.match(/^(\d+|-)\t(\d+|-)\t([\s\S]*)$/);
|
|
3999
|
+
if (!match) {
|
|
4000
|
+
throw new GitError("ParseError", "Invalid commit numstat record");
|
|
4001
|
+
}
|
|
4002
|
+
filesChanged++;
|
|
4003
|
+
if (match[1] !== "-") {
|
|
4004
|
+
insertions += Number(match[1]);
|
|
4005
|
+
}
|
|
4006
|
+
if (match[2] !== "-") {
|
|
4007
|
+
deletions += Number(match[2]);
|
|
4008
|
+
}
|
|
4009
|
+
if (match[3] === "") {
|
|
4010
|
+
i += 2;
|
|
4011
|
+
}
|
|
3752
4012
|
}
|
|
3753
4013
|
const logResult = await this.runner.runOrThrow(this.context, ["log", "-1", "--format=%s"], {
|
|
3754
4014
|
signal: opts?.signal
|
|
@@ -3763,11 +4023,12 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
3763
4023
|
deletions
|
|
3764
4024
|
};
|
|
3765
4025
|
}
|
|
3766
|
-
// ==========================================================================
|
|
3767
|
-
// High-level API - diff
|
|
3768
|
-
// ==========================================================================
|
|
3769
4026
|
async diff(target, opts) {
|
|
3770
|
-
|
|
4027
|
+
validateOptions("diff", opts);
|
|
4028
|
+
const args = ["diff", "--no-ext-diff", "--no-textconv", "--no-color"];
|
|
4029
|
+
if (opts?.nameOnly || opts?.nameStatus) {
|
|
4030
|
+
args.push("-z");
|
|
4031
|
+
}
|
|
3771
4032
|
if (opts?.staged) {
|
|
3772
4033
|
args.push("--staged");
|
|
3773
4034
|
}
|
|
@@ -3845,10 +4106,7 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
3845
4106
|
args.push("--text");
|
|
3846
4107
|
}
|
|
3847
4108
|
if (opts?.mergeBase) {
|
|
3848
|
-
args.push(
|
|
3849
|
-
}
|
|
3850
|
-
if (opts?.noIndex) {
|
|
3851
|
-
args.push("--no-index");
|
|
4109
|
+
args.push("--merge-base");
|
|
3852
4110
|
}
|
|
3853
4111
|
if (opts?.wordDiff) {
|
|
3854
4112
|
args.push(`--word-diff=${opts.wordDiff}`);
|
|
@@ -3862,30 +4120,28 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
3862
4120
|
const result = await this.runner.runOrThrow(this.context, args, {
|
|
3863
4121
|
signal: opts?.signal
|
|
3864
4122
|
});
|
|
4123
|
+
if (opts?.nameOnly) {
|
|
4124
|
+
return parseRecords(result.stdout);
|
|
4125
|
+
}
|
|
3865
4126
|
if (opts?.nameStatus) {
|
|
4127
|
+
const records = parseRecords(result.stdout);
|
|
3866
4128
|
const files = [];
|
|
3867
|
-
for (
|
|
3868
|
-
const
|
|
3869
|
-
|
|
3870
|
-
|
|
3871
|
-
const newPath = match?.[3];
|
|
3872
|
-
if (status !== void 0 && pathOrOld !== void 0) {
|
|
3873
|
-
const entry = {
|
|
3874
|
-
status,
|
|
3875
|
-
path: newPath ?? pathOrOld
|
|
3876
|
-
};
|
|
3877
|
-
if (newPath !== void 0) {
|
|
3878
|
-
entry.oldPath = pathOrOld;
|
|
3879
|
-
}
|
|
3880
|
-
files.push(entry);
|
|
4129
|
+
for (let i = 0; i < records.length; ) {
|
|
4130
|
+
const code = records[i++];
|
|
4131
|
+
if (!/^[AMDRTCUXB][0-9]*$/.test(code)) {
|
|
4132
|
+
throw new GitError("ParseError", "Invalid diff status");
|
|
3881
4133
|
}
|
|
3882
|
-
|
|
3883
|
-
|
|
3884
|
-
|
|
3885
|
-
|
|
3886
|
-
|
|
3887
|
-
|
|
3888
|
-
files.push({
|
|
4134
|
+
const oldPath = records[i++];
|
|
4135
|
+
const renamed = code[0] === "R" || code[0] === "C";
|
|
4136
|
+
const path = renamed ? records[i++] : oldPath;
|
|
4137
|
+
if (oldPath === void 0 || path === void 0) {
|
|
4138
|
+
throw new GitError("ParseError", "Missing diff path");
|
|
4139
|
+
}
|
|
4140
|
+
files.push({
|
|
4141
|
+
status: code[0],
|
|
4142
|
+
path,
|
|
4143
|
+
...renamed ? { oldPath, similarity: Number(code.slice(1)) } : {}
|
|
4144
|
+
});
|
|
3889
4145
|
}
|
|
3890
4146
|
return { files };
|
|
3891
4147
|
}
|
|
@@ -3895,6 +4151,7 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
3895
4151
|
// High-level API - merge
|
|
3896
4152
|
// ==========================================================================
|
|
3897
4153
|
async merge(branch, opts) {
|
|
4154
|
+
validateOptions("merge", opts);
|
|
3898
4155
|
if (opts?.abort) {
|
|
3899
4156
|
await this.runner.runOrThrow(this.context, ["merge", "--abort"], {
|
|
3900
4157
|
signal: opts?.signal
|
|
@@ -3908,6 +4165,10 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
3908
4165
|
const hash = (await this.runner.runOrThrow(this.context, ["rev-parse", "HEAD"])).stdout.trim();
|
|
3909
4166
|
return { success: true, hash };
|
|
3910
4167
|
}
|
|
4168
|
+
if (opts?.quit) {
|
|
4169
|
+
await this.runner.runOrThrow(this.context, ["merge", "--quit"], opts);
|
|
4170
|
+
return { success: true };
|
|
4171
|
+
}
|
|
3911
4172
|
const args = ["merge"];
|
|
3912
4173
|
if (opts?.message) {
|
|
3913
4174
|
args.push("-m", opts.message);
|
|
@@ -3992,17 +4253,20 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
3992
4253
|
signal: opts?.signal,
|
|
3993
4254
|
env: this.lfsModeEnv()
|
|
3994
4255
|
});
|
|
4256
|
+
if (result.aborted) {
|
|
4257
|
+
this.runner.checkResult(this.context, args, result);
|
|
4258
|
+
}
|
|
3995
4259
|
if (result.exitCode !== 0) {
|
|
3996
|
-
const statusResult = await this.runner.runOrThrow(
|
|
3997
|
-
|
|
3998
|
-
|
|
3999
|
-
|
|
4000
|
-
|
|
4001
|
-
).
|
|
4002
|
-
|
|
4003
|
-
|
|
4004
|
-
|
|
4005
|
-
};
|
|
4260
|
+
const statusResult = await this.runner.runOrThrow(
|
|
4261
|
+
this.context,
|
|
4262
|
+
["status", "--porcelain=v2", "-z"],
|
|
4263
|
+
{ signal: opts?.signal }
|
|
4264
|
+
);
|
|
4265
|
+
const conflicts = parsePorcelainV2(statusResult.stdout).filter((entry) => entry.type === "unmerged").map((entry) => entry.path);
|
|
4266
|
+
if (conflicts.length === 0) {
|
|
4267
|
+
this.runner.checkResult(this.context, args, result);
|
|
4268
|
+
}
|
|
4269
|
+
return { success: false, conflicts };
|
|
4006
4270
|
}
|
|
4007
4271
|
const hashResult = await this.runner.runOrThrow(this.context, ["rev-parse", "HEAD"], {
|
|
4008
4272
|
signal: opts?.signal
|
|
@@ -4018,6 +4282,7 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
4018
4282
|
// High-level API - pull
|
|
4019
4283
|
// ==========================================================================
|
|
4020
4284
|
async pull(opts) {
|
|
4285
|
+
validateOptions("pull", opts);
|
|
4021
4286
|
const args = ["pull"];
|
|
4022
4287
|
if (opts?.onProgress || opts?.onLfsProgress) {
|
|
4023
4288
|
args.push("--progress");
|
|
@@ -4203,10 +4468,8 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
4203
4468
|
env: this.lfsModeEnv()
|
|
4204
4469
|
});
|
|
4205
4470
|
}
|
|
4206
|
-
// ==========================================================================
|
|
4207
|
-
// High-level API - rm
|
|
4208
|
-
// ==========================================================================
|
|
4209
4471
|
async rm(paths, opts) {
|
|
4472
|
+
validatePathInput("rm", paths, opts);
|
|
4210
4473
|
const args = ["rm"];
|
|
4211
4474
|
if (opts?.force) {
|
|
4212
4475
|
args.push("--force");
|
|
@@ -4242,38 +4505,29 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
4242
4505
|
// High-level API - Stash Operations
|
|
4243
4506
|
// ==========================================================================
|
|
4244
4507
|
async stashList(opts) {
|
|
4245
|
-
const result = await this.runner.runOrThrow(
|
|
4246
|
-
|
|
4247
|
-
|
|
4248
|
-
|
|
4249
|
-
|
|
4250
|
-
|
|
4251
|
-
|
|
4252
|
-
|
|
4253
|
-
const message = match?.[3];
|
|
4254
|
-
if (indexStr !== void 0 && message !== void 0) {
|
|
4255
|
-
const wipMatch = branchOrContext?.match(/^WIP on (.+)$/);
|
|
4256
|
-
entries.push({
|
|
4257
|
-
index: Number.parseInt(indexStr, 10),
|
|
4258
|
-
message,
|
|
4259
|
-
branch: wipMatch?.[1] ?? branchOrContext,
|
|
4260
|
-
commit: ""
|
|
4261
|
-
// We'd need another command to get the commit hash
|
|
4262
|
-
});
|
|
4263
|
-
}
|
|
4508
|
+
const result = await this.runner.runOrThrow(
|
|
4509
|
+
this.context,
|
|
4510
|
+
["stash", "list", "-z", "--format=%gd%x00%H%x00%gs"],
|
|
4511
|
+
opts
|
|
4512
|
+
);
|
|
4513
|
+
const fields = parseRecords(result.stdout);
|
|
4514
|
+
if (fields.length % 3 !== 0) {
|
|
4515
|
+
throw new GitError("ParseError", "Invalid stash record");
|
|
4264
4516
|
}
|
|
4265
|
-
|
|
4266
|
-
|
|
4267
|
-
|
|
4268
|
-
|
|
4269
|
-
|
|
4270
|
-
["rev-parse", `stash@{${entry.index}}`],
|
|
4271
|
-
{ signal: opts?.signal }
|
|
4272
|
-
);
|
|
4273
|
-
entry.commit = hashResult.stdout.trim();
|
|
4274
|
-
} catch {
|
|
4275
|
-
}
|
|
4517
|
+
const entries = [];
|
|
4518
|
+
for (let i = 0; i < fields.length; i += 3) {
|
|
4519
|
+
const index = fields[i]?.match(/^stash@\{(\d+)\}$/)?.[1];
|
|
4520
|
+
if (index === void 0 || !fields[i + 1]) {
|
|
4521
|
+
throw new GitError("ParseError", "Invalid stash metadata");
|
|
4276
4522
|
}
|
|
4523
|
+
const subject = fields[i + 2];
|
|
4524
|
+
const context = subject.match(/^(?:WIP on|On) (.*?): ([\s\S]*)$/);
|
|
4525
|
+
entries.push({
|
|
4526
|
+
index: Number(index),
|
|
4527
|
+
commit: fields[i + 1],
|
|
4528
|
+
message: context?.[2] ?? subject,
|
|
4529
|
+
...context ? { branch: context[1] } : {}
|
|
4530
|
+
});
|
|
4277
4531
|
}
|
|
4278
4532
|
return entries;
|
|
4279
4533
|
}
|
|
@@ -4349,6 +4603,7 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
4349
4603
|
// High-level API - switch
|
|
4350
4604
|
// ==========================================================================
|
|
4351
4605
|
async switch(branch, opts) {
|
|
4606
|
+
validateOptions("switch", opts);
|
|
4352
4607
|
const args = ["switch"];
|
|
4353
4608
|
if (opts?.create) {
|
|
4354
4609
|
args.push("-c");
|
|
@@ -4548,6 +4803,7 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
4548
4803
|
// Medium Priority - cherry-pick
|
|
4549
4804
|
// ==========================================================================
|
|
4550
4805
|
async cherryPick(commits, opts) {
|
|
4806
|
+
validateOptions("cherryPick", opts);
|
|
4551
4807
|
if (opts?.abort) {
|
|
4552
4808
|
await this.runner.runOrThrow(this.context, ["cherry-pick", "--abort"], {
|
|
4553
4809
|
signal: opts?.signal
|
|
@@ -4582,9 +4838,6 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
4582
4838
|
if (opts?.strategy) {
|
|
4583
4839
|
args.push("-s", opts.strategy);
|
|
4584
4840
|
}
|
|
4585
|
-
if (opts?.noVerify) {
|
|
4586
|
-
args.push("--no-verify");
|
|
4587
|
-
}
|
|
4588
4841
|
if (opts?.cleanup) {
|
|
4589
4842
|
args.push("--cleanup", opts.cleanup);
|
|
4590
4843
|
}
|
|
@@ -4629,6 +4882,7 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
4629
4882
|
// Medium Priority - clean
|
|
4630
4883
|
// ==========================================================================
|
|
4631
4884
|
async clean(opts) {
|
|
4885
|
+
validateOptions("clean", opts);
|
|
4632
4886
|
const args = ["clean"];
|
|
4633
4887
|
if (opts?.force) {
|
|
4634
4888
|
args.push("-f");
|
|
@@ -4698,6 +4952,7 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
4698
4952
|
// Medium Priority - rebase
|
|
4699
4953
|
// ==========================================================================
|
|
4700
4954
|
async rebase(opts) {
|
|
4955
|
+
validateOptions("rebase", opts);
|
|
4701
4956
|
if (opts?.abort) {
|
|
4702
4957
|
await this.runner.runOrThrow(this.context, ["rebase", "--abort"], {
|
|
4703
4958
|
signal: opts?.signal
|
|
@@ -4828,10 +5083,9 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
4828
5083
|
env: this.lfsModeEnv()
|
|
4829
5084
|
});
|
|
4830
5085
|
}
|
|
4831
|
-
// ==========================================================================
|
|
4832
|
-
// Medium Priority - restore
|
|
4833
|
-
// ==========================================================================
|
|
4834
5086
|
async restore(paths, opts) {
|
|
5087
|
+
validatePathInput("restore", paths, opts);
|
|
5088
|
+
validateOptions("restore", opts);
|
|
4835
5089
|
const args = ["restore"];
|
|
4836
5090
|
if (opts?.staged) {
|
|
4837
5091
|
args.push("--staged");
|
|
@@ -4891,6 +5145,7 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
4891
5145
|
// Medium Priority - revert
|
|
4892
5146
|
// ==========================================================================
|
|
4893
5147
|
async revert(commits, opts) {
|
|
5148
|
+
validateOptions("revert", opts);
|
|
4894
5149
|
if (opts?.abort) {
|
|
4895
5150
|
await this.runner.runOrThrow(this.context, ["revert", "--abort"], {
|
|
4896
5151
|
signal: opts?.signal
|
|
@@ -4919,9 +5174,6 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
4919
5174
|
if (opts?.mainline !== void 0) {
|
|
4920
5175
|
args.push("-m", opts.mainline.toString());
|
|
4921
5176
|
}
|
|
4922
|
-
if (opts?.noVerify) {
|
|
4923
|
-
args.push("--no-verify");
|
|
4924
|
-
}
|
|
4925
5177
|
if (opts?.cleanup) {
|
|
4926
5178
|
args.push("--cleanup", opts.cleanup);
|
|
4927
5179
|
}
|
|
@@ -5033,6 +5285,10 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
5033
5285
|
});
|
|
5034
5286
|
return result2.stdout.trim();
|
|
5035
5287
|
}
|
|
5288
|
+
validateRevParseQuery(refOrOpts);
|
|
5289
|
+
if ("pathFormat" in refOrOpts && refOrOpts.pathFormat) {
|
|
5290
|
+
args.push(`--path-format=${refOrOpts.pathFormat}`);
|
|
5291
|
+
}
|
|
5036
5292
|
const queryOpts = refOrOpts;
|
|
5037
5293
|
if ("gitDir" in queryOpts && queryOpts.gitDir) {
|
|
5038
5294
|
args.push("--git-dir");
|
|
@@ -5127,9 +5383,6 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
5127
5383
|
} else if ("localEnvVars" in queryOpts && queryOpts.localEnvVars) {
|
|
5128
5384
|
args.push("--local-env-vars");
|
|
5129
5385
|
}
|
|
5130
|
-
if ("pathFormat" in queryOpts && queryOpts.pathFormat) {
|
|
5131
|
-
args.push(`--path-format=${queryOpts.pathFormat}`);
|
|
5132
|
-
}
|
|
5133
5386
|
const result = await this.runner.runOrThrow(this.context, args, {
|
|
5134
5387
|
signal: queryOpts.signal
|
|
5135
5388
|
});
|
|
@@ -5469,6 +5722,7 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
5469
5722
|
});
|
|
5470
5723
|
}
|
|
5471
5724
|
async remoteSetHead(remote, branch, opts) {
|
|
5725
|
+
validateOptions("remoteSetHead", opts);
|
|
5472
5726
|
const args = ["remote", "set-head"];
|
|
5473
5727
|
if (opts?.auto) {
|
|
5474
5728
|
args.push("--auto");
|
|
@@ -5542,25 +5796,14 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
5542
5796
|
* Get a typed config value
|
|
5543
5797
|
*/
|
|
5544
5798
|
async configGet(key, opts) {
|
|
5545
|
-
const
|
|
5546
|
-
|
|
5547
|
-
|
|
5548
|
-
|
|
5549
|
-
|
|
5550
|
-
|
|
5551
|
-
|
|
5552
|
-
|
|
5553
|
-
/**
|
|
5554
|
-
* Get all values for a typed multi-valued config key
|
|
5555
|
-
*/
|
|
5556
|
-
async configGetAll(key, opts) {
|
|
5557
|
-
const result = await this.runner.run(this.context, ["config", "--get-all", key], {
|
|
5558
|
-
signal: opts?.signal
|
|
5559
|
-
});
|
|
5560
|
-
if (result.exitCode !== 0) {
|
|
5561
|
-
return [];
|
|
5562
|
-
}
|
|
5563
|
-
return parseLines(result.stdout);
|
|
5799
|
+
const values = await readTypedConfig(this.runner, this.context, key, opts);
|
|
5800
|
+
return values.at(-1);
|
|
5801
|
+
}
|
|
5802
|
+
/**
|
|
5803
|
+
* Get all values for a typed multi-valued config key
|
|
5804
|
+
*/
|
|
5805
|
+
async configGetAll(key, opts) {
|
|
5806
|
+
return readTypedConfig(this.runner, this.context, key, opts, true);
|
|
5564
5807
|
}
|
|
5565
5808
|
/**
|
|
5566
5809
|
* Set a typed config value
|
|
@@ -5586,33 +5829,8 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
5586
5829
|
signal: opts?.signal
|
|
5587
5830
|
});
|
|
5588
5831
|
}
|
|
5589
|
-
/**
|
|
5590
|
-
* Get a raw config value (for arbitrary keys)
|
|
5591
|
-
*/
|
|
5592
5832
|
async configGetRaw(key, opts) {
|
|
5593
|
-
|
|
5594
|
-
if (opts?.type) {
|
|
5595
|
-
args.push(`--type=${opts.type}`);
|
|
5596
|
-
}
|
|
5597
|
-
if (opts?.default !== void 0) {
|
|
5598
|
-
args.push("--default", opts.default);
|
|
5599
|
-
}
|
|
5600
|
-
if (opts?.all) {
|
|
5601
|
-
args.push("--get-all");
|
|
5602
|
-
} else {
|
|
5603
|
-
args.push("--get");
|
|
5604
|
-
}
|
|
5605
|
-
args.push(key);
|
|
5606
|
-
const result = await this.runner.run(this.context, args, {
|
|
5607
|
-
signal: opts?.signal
|
|
5608
|
-
});
|
|
5609
|
-
if (result.exitCode !== 0) {
|
|
5610
|
-
return void 0;
|
|
5611
|
-
}
|
|
5612
|
-
if (opts?.all) {
|
|
5613
|
-
return parseLines(result.stdout);
|
|
5614
|
-
}
|
|
5615
|
-
return result.stdout.trim();
|
|
5833
|
+
return readConfig(this.runner, this.context, key, opts);
|
|
5616
5834
|
}
|
|
5617
5835
|
/**
|
|
5618
5836
|
* Set a raw config value (for arbitrary keys)
|
|
@@ -5639,47 +5857,7 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
5639
5857
|
* List all config values
|
|
5640
5858
|
*/
|
|
5641
5859
|
async configList(opts) {
|
|
5642
|
-
|
|
5643
|
-
if (opts?.showOrigin) {
|
|
5644
|
-
args.push("--show-origin");
|
|
5645
|
-
}
|
|
5646
|
-
if (opts?.showScope) {
|
|
5647
|
-
args.push("--show-scope");
|
|
5648
|
-
}
|
|
5649
|
-
if (opts?.includes) {
|
|
5650
|
-
args.push("--includes");
|
|
5651
|
-
}
|
|
5652
|
-
if (opts?.nameOnly) {
|
|
5653
|
-
args.push("--name-only");
|
|
5654
|
-
}
|
|
5655
|
-
const result = await this.runner.runOrThrow(this.context, args, {
|
|
5656
|
-
signal: opts?.signal
|
|
5657
|
-
});
|
|
5658
|
-
const entries = [];
|
|
5659
|
-
for (const line of parseLines(result.stdout)) {
|
|
5660
|
-
let keyValue = line;
|
|
5661
|
-
if (opts?.showOrigin || opts?.showScope) {
|
|
5662
|
-
const tabIndex = line.lastIndexOf(" ");
|
|
5663
|
-
if (tabIndex !== -1) {
|
|
5664
|
-
keyValue = line.slice(tabIndex + 1);
|
|
5665
|
-
}
|
|
5666
|
-
}
|
|
5667
|
-
if (opts?.nameOnly) {
|
|
5668
|
-
entries.push({
|
|
5669
|
-
key: keyValue,
|
|
5670
|
-
value: ""
|
|
5671
|
-
});
|
|
5672
|
-
} else {
|
|
5673
|
-
const eqIndex = keyValue.indexOf("=");
|
|
5674
|
-
if (eqIndex !== -1) {
|
|
5675
|
-
entries.push({
|
|
5676
|
-
key: keyValue.slice(0, eqIndex),
|
|
5677
|
-
value: keyValue.slice(eqIndex + 1)
|
|
5678
|
-
});
|
|
5679
|
-
}
|
|
5680
|
-
}
|
|
5681
|
-
}
|
|
5682
|
-
return entries;
|
|
5860
|
+
return listConfig(this.runner, this.context, opts);
|
|
5683
5861
|
}
|
|
5684
5862
|
async configRenameSection(oldName, newName, opts) {
|
|
5685
5863
|
await this.runner.runOrThrow(this.context, ["config", "--rename-section", oldName, newName], {
|
|
@@ -5896,11 +6074,14 @@ var GitImpl = class {
|
|
|
5896
6074
|
return new WorktreeRepoImpl(repoRunner, path, opts);
|
|
5897
6075
|
}
|
|
5898
6076
|
async clone(url, path, opts) {
|
|
6077
|
+
validateOptions("clone", opts);
|
|
5899
6078
|
const args = buildCloneArgs(opts);
|
|
5900
6079
|
if (opts?.onProgress || opts?.onLfsProgress) {
|
|
5901
6080
|
args.push("--progress");
|
|
5902
6081
|
}
|
|
5903
6082
|
args.push(url, path);
|
|
6083
|
+
const destinationExisted = await this.adapters.fs.exists(path);
|
|
6084
|
+
const alreadyAborted = opts?.signal?.aborted;
|
|
5904
6085
|
try {
|
|
5905
6086
|
await this.runner.runOrThrow({ type: "global" }, args, {
|
|
5906
6087
|
signal: opts?.signal,
|
|
@@ -5908,7 +6089,7 @@ var GitImpl = class {
|
|
|
5908
6089
|
onLfsProgress: opts?.onLfsProgress
|
|
5909
6090
|
});
|
|
5910
6091
|
} catch (error) {
|
|
5911
|
-
if (error instanceof GitError && error.kind === "Aborted" && opts?.cleanupOnAbort !== false) {
|
|
6092
|
+
if (error instanceof GitError && error.kind === "Aborted" && opts?.cleanupOnAbort !== false && !destinationExisted && !alreadyAborted) {
|
|
5912
6093
|
await this.adapters.fs.deleteDirectory(path);
|
|
5913
6094
|
}
|
|
5914
6095
|
throw error;
|
|
@@ -5919,6 +6100,7 @@ var GitImpl = class {
|
|
|
5919
6100
|
return new WorktreeRepoImpl(this.runner, path);
|
|
5920
6101
|
}
|
|
5921
6102
|
async init(path, opts) {
|
|
6103
|
+
validateOptions("init", opts);
|
|
5922
6104
|
const args = ["init"];
|
|
5923
6105
|
if (opts?.quiet) {
|
|
5924
6106
|
args.push("--quiet");
|
|
@@ -5950,6 +6132,8 @@ var GitImpl = class {
|
|
|
5950
6132
|
args.push("--separate-git-dir", opts.separateGitDir);
|
|
5951
6133
|
}
|
|
5952
6134
|
args.push(path);
|
|
6135
|
+
const destinationExisted = await this.adapters.fs.exists(path);
|
|
6136
|
+
const alreadyAborted = opts?.signal?.aborted;
|
|
5953
6137
|
try {
|
|
5954
6138
|
await this.runner.runOrThrow({ type: "global" }, args, {
|
|
5955
6139
|
signal: opts?.signal,
|
|
@@ -5966,7 +6150,7 @@ var GitImpl = class {
|
|
|
5966
6150
|
);
|
|
5967
6151
|
}
|
|
5968
6152
|
} catch (error) {
|
|
5969
|
-
if (error instanceof GitError && error.kind === "Aborted" && opts?.cleanupOnAbort !== false) {
|
|
6153
|
+
if (error instanceof GitError && error.kind === "Aborted" && opts?.cleanupOnAbort !== false && !destinationExisted && !alreadyAborted) {
|
|
5970
6154
|
await this.adapters.fs.deleteDirectory(path);
|
|
5971
6155
|
}
|
|
5972
6156
|
throw error;
|
|
@@ -5980,6 +6164,7 @@ var GitImpl = class {
|
|
|
5980
6164
|
* List references in a remote repository
|
|
5981
6165
|
*/
|
|
5982
6166
|
async lsRemote(url, opts) {
|
|
6167
|
+
validateOptions("lsRemote", opts);
|
|
5983
6168
|
const args = ["ls-remote"];
|
|
5984
6169
|
if (opts?.heads) {
|
|
5985
6170
|
args.push("--heads");
|
|
@@ -5990,15 +6175,9 @@ var GitImpl = class {
|
|
|
5990
6175
|
if (opts?.refs) {
|
|
5991
6176
|
args.push("--refs");
|
|
5992
6177
|
}
|
|
5993
|
-
if (opts?.getUrl) {
|
|
5994
|
-
args.push("--get-url");
|
|
5995
|
-
}
|
|
5996
6178
|
if (opts?.sort) {
|
|
5997
6179
|
args.push("--sort", opts.sort);
|
|
5998
6180
|
}
|
|
5999
|
-
if (opts?.symref) {
|
|
6000
|
-
args.push("--symref");
|
|
6001
|
-
}
|
|
6002
6181
|
args.push(url);
|
|
6003
6182
|
const result = await this.runner.runOrThrow({ type: "global" }, args, {
|
|
6004
6183
|
signal: opts?.signal,
|
|
@@ -6042,27 +6221,14 @@ var GitImpl = class {
|
|
|
6042
6221
|
* Get a typed global config value
|
|
6043
6222
|
*/
|
|
6044
6223
|
async configGet(key, opts) {
|
|
6045
|
-
const
|
|
6046
|
-
|
|
6047
|
-
});
|
|
6048
|
-
if (result.exitCode !== 0) {
|
|
6049
|
-
return void 0;
|
|
6050
|
-
}
|
|
6051
|
-
return result.stdout.trim();
|
|
6224
|
+
const values = await readTypedConfig(this.runner, { type: "global" }, key, opts);
|
|
6225
|
+
return values.at(-1);
|
|
6052
6226
|
}
|
|
6053
6227
|
/**
|
|
6054
6228
|
* Get all values for a typed multi-valued global config key
|
|
6055
6229
|
*/
|
|
6056
6230
|
async configGetAll(key, opts) {
|
|
6057
|
-
|
|
6058
|
-
{ type: "global" },
|
|
6059
|
-
["config", "--global", "--get-all", key],
|
|
6060
|
-
{ signal: opts?.signal }
|
|
6061
|
-
);
|
|
6062
|
-
if (result.exitCode !== 0) {
|
|
6063
|
-
return [];
|
|
6064
|
-
}
|
|
6065
|
-
return parseLines(result.stdout);
|
|
6231
|
+
return readTypedConfig(this.runner, { type: "global" }, key, opts, true);
|
|
6066
6232
|
}
|
|
6067
6233
|
/**
|
|
6068
6234
|
* Set a typed global config value
|
|
@@ -6090,27 +6256,8 @@ var GitImpl = class {
|
|
|
6090
6256
|
signal: opts?.signal
|
|
6091
6257
|
});
|
|
6092
6258
|
}
|
|
6093
|
-
/**
|
|
6094
|
-
* Get a raw global config value (for arbitrary keys)
|
|
6095
|
-
*/
|
|
6096
6259
|
async configGetRaw(key, opts) {
|
|
6097
|
-
|
|
6098
|
-
if (opts?.all) {
|
|
6099
|
-
args.push("--get-all");
|
|
6100
|
-
} else {
|
|
6101
|
-
args.push("--get");
|
|
6102
|
-
}
|
|
6103
|
-
args.push(key);
|
|
6104
|
-
const result = await this.runner.run({ type: "global" }, args, {
|
|
6105
|
-
signal: opts?.signal
|
|
6106
|
-
});
|
|
6107
|
-
if (result.exitCode !== 0) {
|
|
6108
|
-
return void 0;
|
|
6109
|
-
}
|
|
6110
|
-
if (opts?.all) {
|
|
6111
|
-
return parseLines(result.stdout);
|
|
6112
|
-
}
|
|
6113
|
-
return result.stdout.trim();
|
|
6260
|
+
return readConfig(this.runner, { type: "global" }, key, opts);
|
|
6114
6261
|
}
|
|
6115
6262
|
/**
|
|
6116
6263
|
* Set a raw global config value (for arbitrary keys)
|
|
@@ -6137,34 +6284,7 @@ var GitImpl = class {
|
|
|
6137
6284
|
* List all global config values
|
|
6138
6285
|
*/
|
|
6139
6286
|
async configList(opts) {
|
|
6140
|
-
|
|
6141
|
-
if (opts?.showOrigin) {
|
|
6142
|
-
args.push("--show-origin");
|
|
6143
|
-
}
|
|
6144
|
-
if (opts?.showScope) {
|
|
6145
|
-
args.push("--show-scope");
|
|
6146
|
-
}
|
|
6147
|
-
const result = await this.runner.runOrThrow({ type: "global" }, args, {
|
|
6148
|
-
signal: opts?.signal
|
|
6149
|
-
});
|
|
6150
|
-
const entries = [];
|
|
6151
|
-
for (const line of parseLines(result.stdout)) {
|
|
6152
|
-
let keyValue = line;
|
|
6153
|
-
if (opts?.showOrigin || opts?.showScope) {
|
|
6154
|
-
const tabIndex = line.lastIndexOf(" ");
|
|
6155
|
-
if (tabIndex !== -1) {
|
|
6156
|
-
keyValue = line.slice(tabIndex + 1);
|
|
6157
|
-
}
|
|
6158
|
-
}
|
|
6159
|
-
const eqIndex = keyValue.indexOf("=");
|
|
6160
|
-
if (eqIndex !== -1) {
|
|
6161
|
-
entries.push({
|
|
6162
|
-
key: keyValue.slice(0, eqIndex),
|
|
6163
|
-
value: keyValue.slice(eqIndex + 1)
|
|
6164
|
-
});
|
|
6165
|
-
}
|
|
6166
|
-
}
|
|
6167
|
-
return entries;
|
|
6287
|
+
return listConfig(this.runner, { type: "global" }, opts);
|
|
6168
6288
|
}
|
|
6169
6289
|
// ==========================================================================
|
|
6170
6290
|
// Global LFS Operations
|
|
@@ -6237,6 +6357,89 @@ async function createGit(options) {
|
|
|
6237
6357
|
return git;
|
|
6238
6358
|
}
|
|
6239
6359
|
|
|
6360
|
+
// src/internal/client.ts
|
|
6361
|
+
var GitClient = class {
|
|
6362
|
+
constructor(git) {
|
|
6363
|
+
this.git = git;
|
|
6364
|
+
}
|
|
6365
|
+
get open() {
|
|
6366
|
+
return this.git.open.bind(this.git);
|
|
6367
|
+
}
|
|
6368
|
+
/**
|
|
6369
|
+
* Open an existing bare repository
|
|
6370
|
+
*
|
|
6371
|
+
* Throws GitError if the repository is not bare.
|
|
6372
|
+
*
|
|
6373
|
+
* @throws GitError with kind 'NotBareRepo' if the repository is not bare
|
|
6374
|
+
*/
|
|
6375
|
+
get openBare() {
|
|
6376
|
+
return this.git.openBare.bind(this.git);
|
|
6377
|
+
}
|
|
6378
|
+
/**
|
|
6379
|
+
* Open an existing repository without type guarantee
|
|
6380
|
+
*
|
|
6381
|
+
* Returns either WorktreeRepo or BareRepo depending on the repository type.
|
|
6382
|
+
* Use this when you don't know the repository type at compile time.
|
|
6383
|
+
*/
|
|
6384
|
+
get openRaw() {
|
|
6385
|
+
return this.git.openRaw.bind(this.git);
|
|
6386
|
+
}
|
|
6387
|
+
clone(url, path, opts) {
|
|
6388
|
+
return this.git.clone(url, path, opts);
|
|
6389
|
+
}
|
|
6390
|
+
init(path, opts) {
|
|
6391
|
+
return this.git.init(path, opts);
|
|
6392
|
+
}
|
|
6393
|
+
/**
|
|
6394
|
+
* List references in a remote repository
|
|
6395
|
+
*/
|
|
6396
|
+
get lsRemote() {
|
|
6397
|
+
return this.git.lsRemote.bind(this.git);
|
|
6398
|
+
}
|
|
6399
|
+
/**
|
|
6400
|
+
* Get git version
|
|
6401
|
+
*/
|
|
6402
|
+
get version() {
|
|
6403
|
+
return this.git.version.bind(this.git);
|
|
6404
|
+
}
|
|
6405
|
+
/**
|
|
6406
|
+
* Execute a raw git command (repository-agnostic)
|
|
6407
|
+
*/
|
|
6408
|
+
get raw() {
|
|
6409
|
+
return this.git.raw.bind(this.git);
|
|
6410
|
+
}
|
|
6411
|
+
/**
|
|
6412
|
+
* Global config operations
|
|
6413
|
+
*
|
|
6414
|
+
* Operates on ~/.gitconfig (user-level configuration).
|
|
6415
|
+
* For repository-level config, use repo.config instead.
|
|
6416
|
+
*/
|
|
6417
|
+
get config() {
|
|
6418
|
+
return this.git.config;
|
|
6419
|
+
}
|
|
6420
|
+
/**
|
|
6421
|
+
* Global LFS operations
|
|
6422
|
+
*
|
|
6423
|
+
* Operates on ~/.gitconfig (user-level) or /etc/gitconfig (system-level).
|
|
6424
|
+
* For repository-level LFS operations, use repo.lfs instead.
|
|
6425
|
+
*
|
|
6426
|
+
* @example
|
|
6427
|
+
* ```typescript
|
|
6428
|
+
* // Install LFS globally
|
|
6429
|
+
* await git.lfs.install();
|
|
6430
|
+
*
|
|
6431
|
+
* // Install system-wide
|
|
6432
|
+
* await git.lfs.install({ system: true });
|
|
6433
|
+
*
|
|
6434
|
+
* // Get LFS version
|
|
6435
|
+
* const version = await git.lfs.version();
|
|
6436
|
+
* ```
|
|
6437
|
+
*/
|
|
6438
|
+
get lfs() {
|
|
6439
|
+
return this.git.lfs;
|
|
6440
|
+
}
|
|
6441
|
+
};
|
|
6442
|
+
|
|
6240
6443
|
// src/adapters/node/exec.ts
|
|
6241
6444
|
var import_node_child_process = require("child_process");
|
|
6242
6445
|
function resolveChildEnv(env, inheritEnv) {
|
|
@@ -6248,7 +6451,7 @@ function resolveChildEnv(env, inheritEnv) {
|
|
|
6248
6451
|
async function* streamToAsyncIterable(stream) {
|
|
6249
6452
|
let buffer = "";
|
|
6250
6453
|
for await (const chunk of stream) {
|
|
6251
|
-
buffer += chunk
|
|
6454
|
+
buffer += chunk;
|
|
6252
6455
|
const lines = buffer.split("\n");
|
|
6253
6456
|
buffer = lines.pop() ?? "";
|
|
6254
6457
|
for (const line of lines) {
|
|
@@ -6277,12 +6480,17 @@ var NodeExecAdapter = class {
|
|
|
6277
6480
|
throw new Error("argv must not be empty");
|
|
6278
6481
|
}
|
|
6279
6482
|
const args = argv.slice(1);
|
|
6483
|
+
if (signal?.aborted) {
|
|
6484
|
+
return Promise.resolve({ stdout: "", stderr: "", exitCode: -1, aborted: true });
|
|
6485
|
+
}
|
|
6280
6486
|
return new Promise((resolve, reject) => {
|
|
6281
6487
|
const child = (0, import_node_child_process.spawn)(command, args, {
|
|
6282
6488
|
cwd,
|
|
6283
6489
|
env: resolveChildEnv(env, inheritEnv),
|
|
6284
6490
|
stdio: [options.stdin === void 0 ? "ignore" : "pipe", "pipe", "pipe"]
|
|
6285
6491
|
});
|
|
6492
|
+
child.stdout?.setEncoding("utf8");
|
|
6493
|
+
child.stderr?.setEncoding("utf8");
|
|
6286
6494
|
let stdout = "";
|
|
6287
6495
|
let stderr = "";
|
|
6288
6496
|
let aborted = false;
|
|
@@ -6300,12 +6508,12 @@ var NodeExecAdapter = class {
|
|
|
6300
6508
|
}
|
|
6301
6509
|
}
|
|
6302
6510
|
child.stdout?.on("data", (chunk) => {
|
|
6303
|
-
const text = chunk
|
|
6511
|
+
const text = chunk;
|
|
6304
6512
|
stdout += text;
|
|
6305
6513
|
handlers?.onStdout?.(text);
|
|
6306
6514
|
});
|
|
6307
6515
|
child.stderr?.on("data", (chunk) => {
|
|
6308
|
-
const text = chunk
|
|
6516
|
+
const text = chunk;
|
|
6309
6517
|
stderr += text;
|
|
6310
6518
|
handlers?.onStderr?.(text);
|
|
6311
6519
|
});
|
|
@@ -6320,6 +6528,7 @@ var NodeExecAdapter = class {
|
|
|
6320
6528
|
reject(error);
|
|
6321
6529
|
});
|
|
6322
6530
|
child.on("close", (code, sig) => {
|
|
6531
|
+
signal?.removeEventListener("abort", abortHandler);
|
|
6323
6532
|
if (sig) {
|
|
6324
6533
|
exitSignal = sig;
|
|
6325
6534
|
}
|
|
@@ -6360,13 +6569,15 @@ var NodeExecAdapter = class {
|
|
|
6360
6569
|
}
|
|
6361
6570
|
}
|
|
6362
6571
|
const waitPromise = new Promise((resolve, reject) => {
|
|
6572
|
+
child.stdout?.setEncoding("utf8");
|
|
6573
|
+
child.stderr?.setEncoding("utf8");
|
|
6363
6574
|
let stdout = "";
|
|
6364
6575
|
let stderr = "";
|
|
6365
6576
|
child.stdout?.on("data", (chunk) => {
|
|
6366
|
-
stdout += chunk
|
|
6577
|
+
stdout += chunk;
|
|
6367
6578
|
});
|
|
6368
6579
|
child.stderr?.on("data", (chunk) => {
|
|
6369
|
-
stderr += chunk
|
|
6580
|
+
stderr += chunk;
|
|
6370
6581
|
});
|
|
6371
6582
|
child.stdin?.on("error", (error) => {
|
|
6372
6583
|
if (error.code !== "EPIPE" && error.code !== "EOF") {
|
|
@@ -6633,114 +6844,14 @@ function createNodeAdapters() {
|
|
|
6633
6844
|
fs: new NodeFsAdapter()
|
|
6634
6845
|
};
|
|
6635
6846
|
}
|
|
6636
|
-
var TypeGit = class _TypeGit {
|
|
6637
|
-
|
|
6638
|
-
|
|
6639
|
-
* Create a TypeGit instance with Git version check
|
|
6640
|
-
*
|
|
6641
|
-
* @param createOpts - Options including skipVersionCheck
|
|
6642
|
-
* @returns TypeGit instance
|
|
6643
|
-
* @throws GitError with kind 'UnsupportedGitVersion' if Git version is below minimum
|
|
6644
|
-
*/
|
|
6645
|
-
static async create(createOpts) {
|
|
6646
|
-
const gitInstance = await createGit({
|
|
6647
|
-
...createOpts,
|
|
6648
|
-
adapters: createNodeAdapters()
|
|
6649
|
-
});
|
|
6650
|
-
return new _TypeGit(gitInstance);
|
|
6847
|
+
var TypeGit = class _TypeGit extends GitClient {
|
|
6848
|
+
static async create(options) {
|
|
6849
|
+
return new _TypeGit(await createGit({ ...options, adapters: createNodeAdapters() }));
|
|
6651
6850
|
}
|
|
6652
6851
|
constructor(optionsOrGit) {
|
|
6653
|
-
|
|
6654
|
-
|
|
6655
|
-
|
|
6656
|
-
this.git = createGitSync({
|
|
6657
|
-
...optionsOrGit,
|
|
6658
|
-
adapters: createNodeAdapters()
|
|
6659
|
-
});
|
|
6660
|
-
}
|
|
6661
|
-
}
|
|
6662
|
-
/**
|
|
6663
|
-
* Open an existing worktree repository
|
|
6664
|
-
*
|
|
6665
|
-
* This is the most common use case. Throws GitError if the repository is bare.
|
|
6666
|
-
*
|
|
6667
|
-
* @throws GitError with kind 'NotWorktreeRepo' if the repository is bare
|
|
6668
|
-
*/
|
|
6669
|
-
get open() {
|
|
6670
|
-
return this.git.open.bind(this.git);
|
|
6671
|
-
}
|
|
6672
|
-
/**
|
|
6673
|
-
* Open an existing bare repository
|
|
6674
|
-
*
|
|
6675
|
-
* Throws GitError if the repository is not bare.
|
|
6676
|
-
*
|
|
6677
|
-
* @throws GitError with kind 'NotBareRepo' if the repository is not bare
|
|
6678
|
-
*/
|
|
6679
|
-
get openBare() {
|
|
6680
|
-
return this.git.openBare.bind(this.git);
|
|
6681
|
-
}
|
|
6682
|
-
/**
|
|
6683
|
-
* Open an existing repository without type guarantee
|
|
6684
|
-
*
|
|
6685
|
-
* Returns either WorktreeRepo or BareRepo depending on the repository type.
|
|
6686
|
-
* Use this when you don't know the repository type at compile time.
|
|
6687
|
-
*/
|
|
6688
|
-
get openRaw() {
|
|
6689
|
-
return this.git.openRaw.bind(this.git);
|
|
6690
|
-
}
|
|
6691
|
-
clone(url, path, opts) {
|
|
6692
|
-
return this.git.clone(url, path, opts);
|
|
6693
|
-
}
|
|
6694
|
-
init(path, opts) {
|
|
6695
|
-
return this.git.init(path, opts);
|
|
6696
|
-
}
|
|
6697
|
-
/**
|
|
6698
|
-
* List references in a remote repository
|
|
6699
|
-
*/
|
|
6700
|
-
get lsRemote() {
|
|
6701
|
-
return this.git.lsRemote.bind(this.git);
|
|
6702
|
-
}
|
|
6703
|
-
/**
|
|
6704
|
-
* Get git version
|
|
6705
|
-
*/
|
|
6706
|
-
get version() {
|
|
6707
|
-
return this.git.version.bind(this.git);
|
|
6708
|
-
}
|
|
6709
|
-
/**
|
|
6710
|
-
* Execute a raw git command (repository-agnostic)
|
|
6711
|
-
*/
|
|
6712
|
-
get raw() {
|
|
6713
|
-
return this.git.raw.bind(this.git);
|
|
6714
|
-
}
|
|
6715
|
-
/**
|
|
6716
|
-
* Global config operations
|
|
6717
|
-
*
|
|
6718
|
-
* Operates on ~/.gitconfig (user-level configuration).
|
|
6719
|
-
* For repository-level config, use repo.config instead.
|
|
6720
|
-
*/
|
|
6721
|
-
get config() {
|
|
6722
|
-
return this.git.config;
|
|
6723
|
-
}
|
|
6724
|
-
/**
|
|
6725
|
-
* Global LFS operations
|
|
6726
|
-
*
|
|
6727
|
-
* Operates on ~/.gitconfig (user-level) or /etc/gitconfig (system-level).
|
|
6728
|
-
* For repository-level LFS operations, use repo.lfs instead.
|
|
6729
|
-
*
|
|
6730
|
-
* @example
|
|
6731
|
-
* ```typescript
|
|
6732
|
-
* // Install LFS globally
|
|
6733
|
-
* await git.lfs.install();
|
|
6734
|
-
*
|
|
6735
|
-
* // Install system-wide
|
|
6736
|
-
* await git.lfs.install({ system: true });
|
|
6737
|
-
*
|
|
6738
|
-
* // Get LFS version
|
|
6739
|
-
* const version = await git.lfs.version();
|
|
6740
|
-
* ```
|
|
6741
|
-
*/
|
|
6742
|
-
get lfs() {
|
|
6743
|
-
return this.git.lfs;
|
|
6852
|
+
super(
|
|
6853
|
+
optionsOrGit && "open" in optionsOrGit ? optionsOrGit : createGitSync({ ...optionsOrGit, adapters: createNodeAdapters() })
|
|
6854
|
+
);
|
|
6744
6855
|
}
|
|
6745
6856
|
};
|
|
6746
6857
|
// Annotate the CommonJS export names for ESM import in node:
|