type-git 0.3.0-alpha.3 → 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 +43 -12
- 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 +6 -4
- package/dist/adapters-CZ8wj9Kr.d.cts +0 -850
- package/dist/adapters-CZ8wj9Kr.d.ts +0 -850
|
@@ -61,6 +61,273 @@ var GitError = class extends Error {
|
|
|
61
61
|
return this.category === "auth";
|
|
62
62
|
}
|
|
63
63
|
};
|
|
64
|
+
var GitArgumentError = class extends Error {
|
|
65
|
+
constructor(message) {
|
|
66
|
+
super(message);
|
|
67
|
+
this.name = "GitArgumentError";
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
// src/core/option-rules.ts
|
|
72
|
+
var OPTION_RULES = {
|
|
73
|
+
clone: {
|
|
74
|
+
exclusive: [
|
|
75
|
+
["ipv4", "ipv6"],
|
|
76
|
+
["depth", "shallowSince"],
|
|
77
|
+
["depth", "shallowExclude"],
|
|
78
|
+
["bare", "separateGitDir"],
|
|
79
|
+
["mirror", "separateGitDir"]
|
|
80
|
+
],
|
|
81
|
+
unsupported: []
|
|
82
|
+
},
|
|
83
|
+
init: { exclusive: [["bare", "separateGitDir"]], unsupported: [] },
|
|
84
|
+
lsRemote: { exclusive: [], unsupported: ["getUrl", "symref"] },
|
|
85
|
+
lsTree: { exclusive: [["nameOnly", "objectOnly", "long"]], unsupported: [] },
|
|
86
|
+
status: { exclusive: [["noRenames", "findRenames"]], unsupported: ["verbose"] },
|
|
87
|
+
log: {
|
|
88
|
+
exclusive: [
|
|
89
|
+
["merges", "noMerges"],
|
|
90
|
+
["since", "after"],
|
|
91
|
+
["until", "before"]
|
|
92
|
+
],
|
|
93
|
+
unsupported: [
|
|
94
|
+
"source",
|
|
95
|
+
"decorate",
|
|
96
|
+
"decorateRefs",
|
|
97
|
+
"decorateRefsExclude",
|
|
98
|
+
"stat",
|
|
99
|
+
"shortstat",
|
|
100
|
+
"nameOnly",
|
|
101
|
+
"nameStatus"
|
|
102
|
+
]
|
|
103
|
+
},
|
|
104
|
+
fetch: {
|
|
105
|
+
exclusive: [
|
|
106
|
+
["ipv4", "ipv6"],
|
|
107
|
+
["tags", "noTags"],
|
|
108
|
+
["depth", "deepen", "unshallow"],
|
|
109
|
+
["depth", "shallowSince"],
|
|
110
|
+
["depth", "shallowExclude"],
|
|
111
|
+
["all", "remote"],
|
|
112
|
+
["all", "refspec"]
|
|
113
|
+
],
|
|
114
|
+
unsupported: ["multiple"]
|
|
115
|
+
},
|
|
116
|
+
push: {
|
|
117
|
+
exclusive: [
|
|
118
|
+
["ipv4", "ipv6"],
|
|
119
|
+
["force", "forceWithLease"],
|
|
120
|
+
["all", "mirror", "refspec"],
|
|
121
|
+
["all", "tags"],
|
|
122
|
+
["branches", "mirror", "refspec"],
|
|
123
|
+
["branches", "tags"],
|
|
124
|
+
["mirror", "tags"],
|
|
125
|
+
["remote", "repo"]
|
|
126
|
+
],
|
|
127
|
+
unsupported: []
|
|
128
|
+
},
|
|
129
|
+
add: { exclusive: [["all", "update"]], unsupported: ["interactive", "patch"] },
|
|
130
|
+
checkoutBranch: {
|
|
131
|
+
exclusive: [["createBranch", "forceCreateBranch", "detach", "orphan"]],
|
|
132
|
+
unsupported: []
|
|
133
|
+
},
|
|
134
|
+
checkoutPath: {
|
|
135
|
+
exclusive: [
|
|
136
|
+
["ours", "theirs"],
|
|
137
|
+
["source", "ours"],
|
|
138
|
+
["source", "theirs"]
|
|
139
|
+
],
|
|
140
|
+
unsupported: []
|
|
141
|
+
},
|
|
142
|
+
commit: {
|
|
143
|
+
exclusive: [
|
|
144
|
+
["message", "file", "reuseMessage"],
|
|
145
|
+
["fixup", "squash"],
|
|
146
|
+
["include", "only", "all"],
|
|
147
|
+
["gpgSign", "noGpgSign"]
|
|
148
|
+
],
|
|
149
|
+
unsupported: ["dryRun", "reeditMessage"]
|
|
150
|
+
},
|
|
151
|
+
diff: {
|
|
152
|
+
exclusive: [
|
|
153
|
+
["nameOnly", "nameStatus", "stat", "numstat", "patchWithRaw", "patchWithStat"],
|
|
154
|
+
["nameOnly", "patch"],
|
|
155
|
+
["nameStatus", "patch"],
|
|
156
|
+
["nameOnly", "wordDiff"],
|
|
157
|
+
["nameStatus", "wordDiff"],
|
|
158
|
+
["nameOnly", "context"],
|
|
159
|
+
["nameStatus", "context"]
|
|
160
|
+
],
|
|
161
|
+
unsupported: ["noIndex"]
|
|
162
|
+
},
|
|
163
|
+
merge: {
|
|
164
|
+
controls: ["abort", "continue", "quit"],
|
|
165
|
+
exclusive: [
|
|
166
|
+
["abort", "continue", "quit"],
|
|
167
|
+
["noDiffstat", "stat"]
|
|
168
|
+
],
|
|
169
|
+
unsupported: []
|
|
170
|
+
},
|
|
171
|
+
pull: {
|
|
172
|
+
exclusive: [
|
|
173
|
+
["ipv4", "ipv6"],
|
|
174
|
+
["noStat", "stat"],
|
|
175
|
+
["depth", "deepen", "unshallow"],
|
|
176
|
+
["depth", "shallowSince"],
|
|
177
|
+
["depth", "shallowExclude"]
|
|
178
|
+
],
|
|
179
|
+
unsupported: []
|
|
180
|
+
},
|
|
181
|
+
switch: {
|
|
182
|
+
exclusive: [
|
|
183
|
+
["create", "forceCreate", "detach", "orphan"],
|
|
184
|
+
["discard", "merge"],
|
|
185
|
+
["force", "merge"]
|
|
186
|
+
],
|
|
187
|
+
unsupported: []
|
|
188
|
+
},
|
|
189
|
+
cherryPick: {
|
|
190
|
+
controls: ["abort", "continue", "skip"],
|
|
191
|
+
exclusive: [["abort", "continue", "skip"]],
|
|
192
|
+
unsupported: ["noVerify"]
|
|
193
|
+
},
|
|
194
|
+
revert: {
|
|
195
|
+
controls: ["abort", "continue", "skip"],
|
|
196
|
+
exclusive: [["abort", "continue", "skip"]],
|
|
197
|
+
unsupported: ["noVerify"]
|
|
198
|
+
},
|
|
199
|
+
rebase: {
|
|
200
|
+
controls: ["abort", "continue", "skip"],
|
|
201
|
+
exclusive: [
|
|
202
|
+
["abort", "continue", "skip"],
|
|
203
|
+
["keepBase", "onto"],
|
|
204
|
+
["keepBase", "root"],
|
|
205
|
+
["apply", "rebaseMerges"],
|
|
206
|
+
["apply", "strategy"],
|
|
207
|
+
["apply", "exec"]
|
|
208
|
+
],
|
|
209
|
+
unsupported: ["interactive"]
|
|
210
|
+
},
|
|
211
|
+
restore: {
|
|
212
|
+
exclusive: [
|
|
213
|
+
["ours", "theirs"],
|
|
214
|
+
["source", "ours"],
|
|
215
|
+
["source", "theirs"],
|
|
216
|
+
["source", "merge"],
|
|
217
|
+
["source", "conflict"]
|
|
218
|
+
],
|
|
219
|
+
unsupported: []
|
|
220
|
+
},
|
|
221
|
+
clean: { exclusive: [["ignored", "onlyIgnored"]], unsupported: [] },
|
|
222
|
+
worktreeAdd: {
|
|
223
|
+
exclusive: [
|
|
224
|
+
["branch", "detach"],
|
|
225
|
+
["orphan", "detach"]
|
|
226
|
+
],
|
|
227
|
+
unsupported: []
|
|
228
|
+
},
|
|
229
|
+
remoteSetHead: { exclusive: [["auto", "delete"]], unsupported: [] },
|
|
230
|
+
configGet: { exclusive: [["all", "default"]], unsupported: [] },
|
|
231
|
+
configList: { exclusive: [], unsupported: ["nameOnly"] },
|
|
232
|
+
lfsPull: { exclusive: [], unsupported: ["ref"] },
|
|
233
|
+
lfsPush: { exclusive: [["ref", "objectId"]], unsupported: [] },
|
|
234
|
+
lfsFetch: {
|
|
235
|
+
exclusive: [
|
|
236
|
+
["all", "include"],
|
|
237
|
+
["all", "exclude"],
|
|
238
|
+
["all", "recent"]
|
|
239
|
+
],
|
|
240
|
+
unsupported: []
|
|
241
|
+
},
|
|
242
|
+
lfsStatus: { exclusive: [], unsupported: ["porcelain"] },
|
|
243
|
+
lfsLsFiles: { exclusive: [], unsupported: ["debug", "nameOnly"] }
|
|
244
|
+
};
|
|
245
|
+
function validateOptions(name, options) {
|
|
246
|
+
if (!options) {
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
const values = options;
|
|
250
|
+
const rule = OPTION_RULES[name];
|
|
251
|
+
if ((name === "lfsStatus" || name === "lfsLsFiles") && values.json !== void 0 && values.json !== true) {
|
|
252
|
+
throw new GitArgumentError(`${name}: the typed API uses JSON`);
|
|
253
|
+
}
|
|
254
|
+
if (name === "status" && values.porcelain !== void 0 && values.porcelain !== 2) {
|
|
255
|
+
throw new GitArgumentError("status: the typed API uses porcelain v2");
|
|
256
|
+
}
|
|
257
|
+
if ((name === "status" || name === "diff") && values.nullTerminated !== void 0 && values.nullTerminated !== true) {
|
|
258
|
+
throw new GitArgumentError(`${name}: the typed API uses NUL-delimited paths`);
|
|
259
|
+
}
|
|
260
|
+
for (const key of rule.unsupported) {
|
|
261
|
+
if (values[key] !== void 0) {
|
|
262
|
+
throw new GitArgumentError(
|
|
263
|
+
`${name}: ${key} is not supported by the typed API; use raw() for this output or operation`
|
|
264
|
+
);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
if (rule.controls?.some((key) => values[key] === true)) {
|
|
268
|
+
const ignored = Object.keys(values).filter(
|
|
269
|
+
(key) => !(rule.controls?.includes(key) || ["signal", "onProgress", "onLfsProgress"].includes(key)) && values[key] !== void 0 && values[key] !== false
|
|
270
|
+
);
|
|
271
|
+
if (ignored.length > 0) {
|
|
272
|
+
throw new GitArgumentError(`${name}: control operations cannot take ${ignored.join(", ")}`);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
for (const group of rule.exclusive) {
|
|
276
|
+
const active = group.filter((key) => values[key] !== void 0 && values[key] !== false);
|
|
277
|
+
if (active.length > 1) {
|
|
278
|
+
throw new GitArgumentError(`${name}: ${active.join(", ")} cannot be used together`);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
for (const key of ["depth", "deepen", "jobs", "mainline"]) {
|
|
282
|
+
const value = values[key];
|
|
283
|
+
if (value !== void 0 && (!Number.isSafeInteger(value) || value < 1)) {
|
|
284
|
+
throw new GitArgumentError(`${name}: ${key} must be a positive safe integer`);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
for (const key of ["maxCount", "skip", "context", "renameLimit", "abbrev"]) {
|
|
288
|
+
const value = values[key];
|
|
289
|
+
if (value !== void 0 && typeof value !== "boolean" && (!Number.isSafeInteger(value) || value < 0)) {
|
|
290
|
+
throw new GitArgumentError(`${name}: ${key} must be a non-negative safe integer`);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
var REV_PARSE_QUERY_KEYS = [
|
|
295
|
+
"gitDir",
|
|
296
|
+
"absoluteGitDir",
|
|
297
|
+
"gitCommonDir",
|
|
298
|
+
"showToplevel",
|
|
299
|
+
"showCdup",
|
|
300
|
+
"showPrefix",
|
|
301
|
+
"showSuperprojectWorkingTree",
|
|
302
|
+
"sharedIndexPath",
|
|
303
|
+
"gitPath",
|
|
304
|
+
"resolveGitDir",
|
|
305
|
+
"isInsideGitDir",
|
|
306
|
+
"isInsideWorkTree",
|
|
307
|
+
"isBareRepository",
|
|
308
|
+
"isShallowRepository",
|
|
309
|
+
"all",
|
|
310
|
+
"branches",
|
|
311
|
+
"tags",
|
|
312
|
+
"remotes",
|
|
313
|
+
"glob",
|
|
314
|
+
"disambiguate",
|
|
315
|
+
"showObjectFormat",
|
|
316
|
+
"showRefFormat",
|
|
317
|
+
"localEnvVars"
|
|
318
|
+
];
|
|
319
|
+
function validateRevParseQuery(query) {
|
|
320
|
+
const values = query;
|
|
321
|
+
const selected = REV_PARSE_QUERY_KEYS.filter((key) => values[key] !== void 0);
|
|
322
|
+
if (selected.length !== 1 || values[selected[0]] !== true && typeof values[selected[0]] !== "string") {
|
|
323
|
+
throw new GitArgumentError("revParse: specify exactly one query");
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
function validatePathInput(name, paths, opts) {
|
|
327
|
+
if (opts?.pathspecFromFile !== void 0 && (typeof paths === "string" || paths.length > 0)) {
|
|
328
|
+
throw new GitArgumentError(`${name}: pass an empty path list when using pathspecFromFile`);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
64
331
|
|
|
65
332
|
// src/parsers/index.ts
|
|
66
333
|
var GIT_PROGRESS_PERCENT_REGEX = /^(.+?):\s*(\d+)%\s*\((\d+)\/(\d+)\)(?:,\s*(done))?/;
|
|
@@ -71,77 +338,135 @@ var LFS_DOWNLOAD_REGEX = /downloading|filtering/i;
|
|
|
71
338
|
var LFS_UPLOAD_REGEX = /uploading/i;
|
|
72
339
|
var LFS_CHECKOUT_REGEX = /checking out/i;
|
|
73
340
|
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;
|
|
74
|
-
function at(arr, index, context) {
|
|
75
|
-
const value = arr[index];
|
|
76
|
-
if (value === void 0) {
|
|
77
|
-
throw new Error(`Parse error: expected element at index ${index} in ${context}`);
|
|
78
|
-
}
|
|
79
|
-
return value;
|
|
80
|
-
}
|
|
81
341
|
function parseLines(stdout, options) {
|
|
82
342
|
const { keepEmpty = false, trim = true } = options ?? {};
|
|
83
343
|
const lines = stdout.split("\n");
|
|
84
344
|
return lines.map((line) => trim ? line.trim() : line).filter((line) => keepEmpty || line.length > 0);
|
|
85
345
|
}
|
|
346
|
+
function parseRecords(stdout, delimiter = "\0") {
|
|
347
|
+
if (!stdout) {
|
|
348
|
+
return [];
|
|
349
|
+
}
|
|
350
|
+
const normalized = stdout.endsWith(delimiter) ? stdout.slice(0, -delimiter.length) : stdout;
|
|
351
|
+
return normalized.split(delimiter);
|
|
352
|
+
}
|
|
353
|
+
function decodePath(path) {
|
|
354
|
+
if (!path.startsWith('"')) {
|
|
355
|
+
return path;
|
|
356
|
+
}
|
|
357
|
+
if (!path.endsWith('"')) {
|
|
358
|
+
throw new GitError("ParseError", "Unterminated quoted path");
|
|
359
|
+
}
|
|
360
|
+
const bytes = [];
|
|
361
|
+
const encoder = new TextEncoder();
|
|
362
|
+
const escapes = {
|
|
363
|
+
a: "\x07",
|
|
364
|
+
b: "\b",
|
|
365
|
+
f: "\f",
|
|
366
|
+
n: "\n",
|
|
367
|
+
r: "\r",
|
|
368
|
+
t: " ",
|
|
369
|
+
v: "\v",
|
|
370
|
+
'"': '"',
|
|
371
|
+
"\\": "\\"
|
|
372
|
+
};
|
|
373
|
+
const value = path.slice(1, -1);
|
|
374
|
+
for (let i = 0; i < value.length; ) {
|
|
375
|
+
if (value[i] === "\\") {
|
|
376
|
+
const octal = value.slice(i + 1).match(/^[0-7]{1,3}/)?.[0];
|
|
377
|
+
if (octal) {
|
|
378
|
+
bytes.push(Number.parseInt(octal, 8));
|
|
379
|
+
i += octal.length + 1;
|
|
380
|
+
continue;
|
|
381
|
+
}
|
|
382
|
+
const escaped = escapes[value[i + 1] ?? ""];
|
|
383
|
+
if (escaped === void 0) {
|
|
384
|
+
throw new GitError("ParseError", "Invalid quoted path escape");
|
|
385
|
+
}
|
|
386
|
+
bytes.push(...encoder.encode(escaped));
|
|
387
|
+
i += 2;
|
|
388
|
+
} else {
|
|
389
|
+
const char = String.fromCodePoint(value.codePointAt(i));
|
|
390
|
+
bytes.push(...encoder.encode(char));
|
|
391
|
+
i += char.length;
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
return new TextDecoder().decode(new Uint8Array(bytes));
|
|
395
|
+
}
|
|
86
396
|
function parsePorcelainV2(stdout) {
|
|
87
397
|
const entries = [];
|
|
88
|
-
const
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
hH: at(parts, 6, "porcelain-v2 ordinary"),
|
|
101
|
-
hI: at(parts, 7, "porcelain-v2 ordinary"),
|
|
102
|
-
path: pathPart
|
|
103
|
-
});
|
|
104
|
-
} else if (line.startsWith("2 ")) {
|
|
105
|
-
const parts = line.split(" ");
|
|
106
|
-
const pathPart = parts.slice(9).join(" ");
|
|
107
|
-
const pathParts = pathPart.split(" ");
|
|
398
|
+
const nul = stdout.includes("\0");
|
|
399
|
+
const records = nul ? parseRecords(stdout) : parseLines(stdout, { trim: false });
|
|
400
|
+
for (let i = 0; i < records.length; i++) {
|
|
401
|
+
const line = records[i];
|
|
402
|
+
if (line.startsWith("# ")) {
|
|
403
|
+
continue;
|
|
404
|
+
}
|
|
405
|
+
const kind = line[0];
|
|
406
|
+
if (kind === "?" || kind === "!") {
|
|
407
|
+
if (line[1] !== " " || line.length < 3) {
|
|
408
|
+
throw new GitError("ParseError", "Invalid status path");
|
|
409
|
+
}
|
|
108
410
|
entries.push({
|
|
109
|
-
type: "
|
|
110
|
-
|
|
111
|
-
sub: at(parts, 2, "porcelain-v2 renamed"),
|
|
112
|
-
mH: at(parts, 3, "porcelain-v2 renamed"),
|
|
113
|
-
mI: at(parts, 4, "porcelain-v2 renamed"),
|
|
114
|
-
mW: at(parts, 5, "porcelain-v2 renamed"),
|
|
115
|
-
hH: at(parts, 6, "porcelain-v2 renamed"),
|
|
116
|
-
hI: at(parts, 7, "porcelain-v2 renamed"),
|
|
117
|
-
path: at(pathParts, 0, "porcelain-v2 renamed path"),
|
|
118
|
-
origPath: pathParts[1]
|
|
411
|
+
type: kind === "?" ? "untracked" : "ignored",
|
|
412
|
+
path: nul ? line.slice(2) : decodePath(line.slice(2))
|
|
119
413
|
});
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
414
|
+
continue;
|
|
415
|
+
}
|
|
416
|
+
if (kind !== "1" && kind !== "2" && kind !== "u") {
|
|
417
|
+
throw new GitError("ParseError", "Unknown status record");
|
|
418
|
+
}
|
|
419
|
+
const count = kind === "u" ? 10 : kind === "2" ? 9 : 8;
|
|
420
|
+
const parts = line.split(" ");
|
|
421
|
+
if (parts.length <= count || parts[1]?.length !== 2) {
|
|
422
|
+
throw new GitError("ParseError", "Invalid status record");
|
|
423
|
+
}
|
|
424
|
+
let path = parts.slice(count).join(" ");
|
|
425
|
+
let origPath;
|
|
426
|
+
if (kind === "2") {
|
|
427
|
+
if (nul) {
|
|
428
|
+
origPath = records[++i];
|
|
429
|
+
} else {
|
|
430
|
+
const tab = path.indexOf(" ");
|
|
431
|
+
if (tab < 0) {
|
|
432
|
+
throw new GitError("ParseError", "Missing rename source");
|
|
433
|
+
}
|
|
434
|
+
origPath = decodePath(path.slice(tab + 1));
|
|
435
|
+
path = path.slice(0, tab);
|
|
436
|
+
}
|
|
437
|
+
if (origPath === void 0) {
|
|
438
|
+
throw new GitError("ParseError", "Missing rename source");
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
if (!nul) {
|
|
442
|
+
path = decodePath(path);
|
|
443
|
+
}
|
|
444
|
+
if (kind === "u") {
|
|
123
445
|
entries.push({
|
|
124
446
|
type: "unmerged",
|
|
125
|
-
xy:
|
|
126
|
-
sub:
|
|
127
|
-
m1:
|
|
128
|
-
m2:
|
|
129
|
-
m3:
|
|
130
|
-
mW:
|
|
131
|
-
h1:
|
|
132
|
-
h2:
|
|
133
|
-
h3:
|
|
134
|
-
path
|
|
135
|
-
});
|
|
136
|
-
} else if (line.startsWith("? ")) {
|
|
137
|
-
entries.push({
|
|
138
|
-
type: "untracked",
|
|
139
|
-
path: line.slice(2)
|
|
447
|
+
xy: parts[1],
|
|
448
|
+
sub: parts[2],
|
|
449
|
+
m1: parts[3],
|
|
450
|
+
m2: parts[4],
|
|
451
|
+
m3: parts[5],
|
|
452
|
+
mW: parts[6],
|
|
453
|
+
h1: parts[7],
|
|
454
|
+
h2: parts[8],
|
|
455
|
+
h3: parts[9],
|
|
456
|
+
path
|
|
140
457
|
});
|
|
141
|
-
} else
|
|
458
|
+
} else {
|
|
142
459
|
entries.push({
|
|
143
|
-
type: "
|
|
144
|
-
|
|
460
|
+
type: "changed",
|
|
461
|
+
xy: parts[1],
|
|
462
|
+
sub: parts[2],
|
|
463
|
+
mH: parts[3],
|
|
464
|
+
mI: parts[4],
|
|
465
|
+
mW: parts[5],
|
|
466
|
+
hH: parts[6],
|
|
467
|
+
hI: parts[7],
|
|
468
|
+
path,
|
|
469
|
+
...origPath !== void 0 ? { origPath } : {}
|
|
145
470
|
});
|
|
146
471
|
}
|
|
147
472
|
}
|
|
@@ -266,109 +591,71 @@ function parseLsRemote(stdout) {
|
|
|
266
591
|
}
|
|
267
592
|
return refs;
|
|
268
593
|
}
|
|
269
|
-
var LS_TREE_REGEX = /^(\d+)\s+(blob|tree|commit)\s+([a-f0-9]+)\t(
|
|
270
|
-
var LS_TREE_LONG_REGEX = /^(\d+)\s+(blob|tree|commit)\s+([a-f0-9]+)\s+(-|\d+)\t(
|
|
594
|
+
var LS_TREE_REGEX = /^(\d+)\s+(blob|tree|commit)\s+([a-f0-9]+)\t([\s\S]+)$/;
|
|
595
|
+
var LS_TREE_LONG_REGEX = /^(\d+)\s+(blob|tree|commit)\s+([a-f0-9]+)\s+(-|\d+)\t([\s\S]+)$/;
|
|
271
596
|
function parseLsTree(stdout, opts) {
|
|
272
|
-
const
|
|
273
|
-
const
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
if (opts?.objectOnly) {
|
|
285
|
-
entries.push({
|
|
286
|
-
mode: "",
|
|
287
|
-
type: "blob",
|
|
288
|
-
hash: line,
|
|
289
|
-
path: ""
|
|
290
|
-
});
|
|
291
|
-
continue;
|
|
292
|
-
}
|
|
293
|
-
if (opts?.long) {
|
|
294
|
-
const longMatch = line.match(LS_TREE_LONG_REGEX);
|
|
295
|
-
if (longMatch) {
|
|
296
|
-
const mode = longMatch[1];
|
|
297
|
-
const type = longMatch[2];
|
|
298
|
-
const hash = longMatch[3];
|
|
299
|
-
const sizeStr = longMatch[4];
|
|
300
|
-
const path = longMatch[5];
|
|
301
|
-
if (mode && type && hash && path) {
|
|
302
|
-
entries.push({
|
|
303
|
-
mode,
|
|
304
|
-
type,
|
|
305
|
-
hash,
|
|
306
|
-
path,
|
|
307
|
-
size: sizeStr === "-" || !sizeStr ? void 0 : Number.parseInt(sizeStr, 10)
|
|
308
|
-
});
|
|
309
|
-
}
|
|
310
|
-
continue;
|
|
311
|
-
}
|
|
597
|
+
const nul = stdout.includes("\0");
|
|
598
|
+
const records = nul ? parseRecords(stdout) : parseLines(stdout, { trim: false });
|
|
599
|
+
if (opts?.nameOnly) {
|
|
600
|
+
return records.map((path) => nul ? path : decodePath(path));
|
|
601
|
+
}
|
|
602
|
+
if (opts?.objectOnly) {
|
|
603
|
+
return records;
|
|
604
|
+
}
|
|
605
|
+
return records.map((line) => {
|
|
606
|
+
const match = line.match(opts?.long ? LS_TREE_LONG_REGEX : LS_TREE_REGEX);
|
|
607
|
+
if (!match) {
|
|
608
|
+
throw new GitError("ParseError", "Invalid ls-tree record", { stdout: line });
|
|
312
609
|
}
|
|
313
|
-
const
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
const hash = match[3];
|
|
318
|
-
const path = match[4];
|
|
319
|
-
if (mode && type && hash && path) {
|
|
320
|
-
entries.push({
|
|
321
|
-
mode,
|
|
322
|
-
type,
|
|
323
|
-
hash,
|
|
324
|
-
path
|
|
325
|
-
});
|
|
326
|
-
}
|
|
610
|
+
const path = match[opts?.long ? 5 : 4];
|
|
611
|
+
const size = opts?.long && match[4] !== "-" ? Number(match[4]) : void 0;
|
|
612
|
+
if (size !== void 0 && !Number.isSafeInteger(size)) {
|
|
613
|
+
throw new GitError("ParseError", "Invalid tree object size");
|
|
327
614
|
}
|
|
328
|
-
|
|
329
|
-
|
|
615
|
+
return {
|
|
616
|
+
mode: match[1],
|
|
617
|
+
type: match[2],
|
|
618
|
+
hash: match[3],
|
|
619
|
+
path: nul ? path : decodePath(path),
|
|
620
|
+
...size !== void 0 ? { size } : {}
|
|
621
|
+
};
|
|
622
|
+
});
|
|
330
623
|
}
|
|
331
|
-
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
|
|
624
|
+
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";
|
|
332
625
|
function parseGitLog(stdout) {
|
|
626
|
+
if (!stdout) {
|
|
627
|
+
return [];
|
|
628
|
+
}
|
|
629
|
+
const fields = parseRecords(stdout);
|
|
630
|
+
if (fields.length % 11 !== 0) {
|
|
631
|
+
throw new GitError("ParseError", "Invalid git log field count");
|
|
632
|
+
}
|
|
333
633
|
const commits = [];
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
const
|
|
337
|
-
if (fields.
|
|
338
|
-
|
|
339
|
-
}
|
|
340
|
-
const hash = fields[0]?.trim();
|
|
341
|
-
const abbrevHash = fields[1];
|
|
342
|
-
const parentsStr = fields[2];
|
|
343
|
-
const authorName = fields[3];
|
|
344
|
-
const authorEmail = fields[4];
|
|
345
|
-
const authorTimestampStr = fields[5];
|
|
346
|
-
const committerName = fields[6];
|
|
347
|
-
const committerEmail = fields[7];
|
|
348
|
-
const committerTimestampStr = fields[8];
|
|
349
|
-
const subject = fields[9];
|
|
350
|
-
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) {
|
|
351
|
-
continue;
|
|
634
|
+
for (let i = 0; i < fields.length; i += 11) {
|
|
635
|
+
const authorTimestamp = Number(fields[i + 5]);
|
|
636
|
+
const committerTimestamp = Number(fields[i + 8]);
|
|
637
|
+
if (!(fields[i] && Number.isSafeInteger(authorTimestamp) && Number.isSafeInteger(committerTimestamp))) {
|
|
638
|
+
throw new GitError("ParseError", "Invalid git log metadata");
|
|
352
639
|
}
|
|
353
640
|
commits.push({
|
|
354
|
-
hash,
|
|
355
|
-
abbrevHash,
|
|
356
|
-
parents:
|
|
357
|
-
authorName,
|
|
358
|
-
authorEmail,
|
|
359
|
-
authorTimestamp
|
|
360
|
-
committerName,
|
|
361
|
-
committerEmail,
|
|
362
|
-
committerTimestamp
|
|
363
|
-
subject,
|
|
364
|
-
body: fields[10]
|
|
641
|
+
hash: fields[i],
|
|
642
|
+
abbrevHash: fields[i + 1],
|
|
643
|
+
parents: fields[i + 2]?.split(" ").filter(Boolean) ?? [],
|
|
644
|
+
authorName: fields[i + 3],
|
|
645
|
+
authorEmail: fields[i + 4],
|
|
646
|
+
authorTimestamp,
|
|
647
|
+
committerName: fields[i + 6],
|
|
648
|
+
committerEmail: fields[i + 7],
|
|
649
|
+
committerTimestamp,
|
|
650
|
+
subject: fields[i + 9],
|
|
651
|
+
body: fields[i + 10]
|
|
365
652
|
});
|
|
366
653
|
}
|
|
367
654
|
return commits;
|
|
368
655
|
}
|
|
369
656
|
function parseWorktreeList(stdout) {
|
|
370
657
|
const worktrees = [];
|
|
371
|
-
const lines = parseLines(stdout, { keepEmpty: true });
|
|
658
|
+
const lines = parseLines(stdout, { keepEmpty: true, trim: false });
|
|
372
659
|
let current = null;
|
|
373
660
|
for (const line of lines) {
|
|
374
661
|
if (line.startsWith("worktree ")) {
|
|
@@ -382,7 +669,7 @@ function parseWorktreeList(stdout) {
|
|
|
382
669
|
});
|
|
383
670
|
}
|
|
384
671
|
current = {
|
|
385
|
-
path: line.slice("worktree ".length),
|
|
672
|
+
path: decodePath(line.slice("worktree ".length)),
|
|
386
673
|
locked: false,
|
|
387
674
|
prunable: false
|
|
388
675
|
};
|
|
@@ -454,6 +741,132 @@ function detectErrorCategory(stderr) {
|
|
|
454
741
|
return "unknown";
|
|
455
742
|
}
|
|
456
743
|
|
|
744
|
+
// src/internal/config.ts
|
|
745
|
+
var CONFIG_ENUMS = {
|
|
746
|
+
"core.autocrlf": ["true", "false", "input"],
|
|
747
|
+
"core.filemode": ["true", "false"],
|
|
748
|
+
"core.ignorecase": ["true", "false"],
|
|
749
|
+
"core.bare": ["true", "false"],
|
|
750
|
+
"core.logallrefupdates": ["true", "false", "always"],
|
|
751
|
+
"core.quotepath": ["true", "false"],
|
|
752
|
+
"commit.gpgsign": ["true", "false"],
|
|
753
|
+
"tag.gpgsign": ["true", "false"],
|
|
754
|
+
"tag.forcesignannotated": ["true", "false"],
|
|
755
|
+
"push.default": ["nothing", "current", "upstream", "tracking", "simple", "matching"],
|
|
756
|
+
"push.followTags": ["true", "false"],
|
|
757
|
+
"push.autoSetupRemote": ["true", "false"],
|
|
758
|
+
"push.gpgSign": ["true", "false", "if-asked"],
|
|
759
|
+
"pull.rebase": ["true", "false", "merges", "interactive"],
|
|
760
|
+
"pull.ff": ["true", "false", "only"],
|
|
761
|
+
"fetch.prune": ["true", "false"],
|
|
762
|
+
"fetch.pruneTags": ["true", "false"],
|
|
763
|
+
"merge.ff": ["true", "false", "only"],
|
|
764
|
+
"merge.conflictstyle": ["merge", "diff3", "zdiff3"],
|
|
765
|
+
"rebase.autoStash": ["true", "false"],
|
|
766
|
+
"rebase.autoSquash": ["true", "false"],
|
|
767
|
+
"rebase.updateRefs": ["true", "false"],
|
|
768
|
+
"diff.algorithm": ["default", "minimal", "patience", "histogram"],
|
|
769
|
+
"diff.colorMoved": ["no", "default", "plain", "blocks", "zebra", "dimmed-zebra"],
|
|
770
|
+
"color.ui": ["auto", "always", "never", "true", "false"],
|
|
771
|
+
"gpg.format": ["openpgp", "x509", "ssh"],
|
|
772
|
+
"http.sslVerify": ["true", "false"]
|
|
773
|
+
};
|
|
774
|
+
function configValue(key, value, implicit = false) {
|
|
775
|
+
const allowed = CONFIG_ENUMS[key];
|
|
776
|
+
if (!allowed) {
|
|
777
|
+
return value;
|
|
778
|
+
}
|
|
779
|
+
let normalized = value.toLowerCase();
|
|
780
|
+
if (allowed.includes("true") && allowed.includes("false")) {
|
|
781
|
+
if (normalized === "") {
|
|
782
|
+
normalized = implicit ? "true" : "false";
|
|
783
|
+
}
|
|
784
|
+
if (/^[+-]?\d+[kmg]?$/i.test(normalized)) {
|
|
785
|
+
normalized = Number.parseInt(normalized, 10) === 0 ? "false" : "true";
|
|
786
|
+
}
|
|
787
|
+
if (["yes", "on", "1"].includes(normalized)) {
|
|
788
|
+
normalized = "true";
|
|
789
|
+
}
|
|
790
|
+
if (["no", "off", "0"].includes(normalized)) {
|
|
791
|
+
normalized = "false";
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
if (!allowed.includes(normalized)) {
|
|
795
|
+
throw new GitError("ParseError", `Invalid value for ${key}: expected ${allowed.join(" | ")}`);
|
|
796
|
+
}
|
|
797
|
+
return normalized;
|
|
798
|
+
}
|
|
799
|
+
async function readConfig(runner, context, key, opts) {
|
|
800
|
+
validateOptions("configGet", opts);
|
|
801
|
+
const args = ["config", ...context.type === "global" ? ["--global"] : [], "--null"];
|
|
802
|
+
if (opts?.type) {
|
|
803
|
+
args.push(`--type=${opts.type}`);
|
|
804
|
+
}
|
|
805
|
+
if (opts?.default !== void 0) {
|
|
806
|
+
args.push("--default", opts.default);
|
|
807
|
+
}
|
|
808
|
+
args.push(opts?.all ? "--get-all" : "--get", key);
|
|
809
|
+
const result = await runner.run(context, args, opts);
|
|
810
|
+
if (result.exitCode === 1 && !result.aborted) {
|
|
811
|
+
return opts?.all ? [] : void 0;
|
|
812
|
+
}
|
|
813
|
+
runner.checkResult(context, args, result);
|
|
814
|
+
const values = parseRecords(result.stdout);
|
|
815
|
+
return opts?.all ? values : values[0];
|
|
816
|
+
}
|
|
817
|
+
async function listConfig(runner, context, opts) {
|
|
818
|
+
validateOptions("configList", opts);
|
|
819
|
+
const args = ["config", ...context.type === "global" ? ["--global"] : [], "--null", "--list"];
|
|
820
|
+
if (opts?.showOrigin) {
|
|
821
|
+
args.push("--show-origin");
|
|
822
|
+
}
|
|
823
|
+
if (opts?.showScope) {
|
|
824
|
+
args.push("--show-scope");
|
|
825
|
+
}
|
|
826
|
+
if (opts?.includes !== void 0) {
|
|
827
|
+
args.push(opts.includes ? "--includes" : "--no-includes");
|
|
828
|
+
}
|
|
829
|
+
const result = await runner.runOrThrow(context, args, opts);
|
|
830
|
+
const records = parseRecords(result.stdout);
|
|
831
|
+
const entries = [];
|
|
832
|
+
for (let i = 0; i < records.length; ) {
|
|
833
|
+
const scope = opts?.showScope ? records[i++] : void 0;
|
|
834
|
+
const origin = opts?.showOrigin ? records[i++] : void 0;
|
|
835
|
+
const entry = records[i++];
|
|
836
|
+
if (entry === void 0) {
|
|
837
|
+
throw new GitError("ParseError", "Incomplete config record");
|
|
838
|
+
}
|
|
839
|
+
const separator = entry.indexOf("\n");
|
|
840
|
+
entries.push({
|
|
841
|
+
key: separator < 0 ? entry : entry.slice(0, separator),
|
|
842
|
+
value: separator < 0 ? "" : entry.slice(separator + 1),
|
|
843
|
+
...scope !== void 0 ? { scope } : {},
|
|
844
|
+
...origin !== void 0 ? { origin } : {}
|
|
845
|
+
});
|
|
846
|
+
}
|
|
847
|
+
return entries;
|
|
848
|
+
}
|
|
849
|
+
async function readTypedConfig(runner, context, key, opts, all = false) {
|
|
850
|
+
const pattern = `^${key.toLowerCase().replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}$`;
|
|
851
|
+
const args = [
|
|
852
|
+
"config",
|
|
853
|
+
...context.type === "global" ? ["--global"] : [],
|
|
854
|
+
"--null",
|
|
855
|
+
"--get-regexp",
|
|
856
|
+
pattern
|
|
857
|
+
];
|
|
858
|
+
const result = await runner.run(context, args, opts);
|
|
859
|
+
if (result.exitCode === 1 && !result.aborted) {
|
|
860
|
+
return [];
|
|
861
|
+
}
|
|
862
|
+
runner.checkResult(context, args, result);
|
|
863
|
+
const records = parseRecords(result.stdout);
|
|
864
|
+
return (all ? records : records.slice(-1)).map((record2) => {
|
|
865
|
+
const separator = record2.indexOf("\n");
|
|
866
|
+
return configValue(key, separator < 0 ? "" : record2.slice(separator + 1), separator < 0);
|
|
867
|
+
});
|
|
868
|
+
}
|
|
869
|
+
|
|
457
870
|
// src/runner/cli-runner.ts
|
|
458
871
|
var import_node_process = __toESM(require("process"), 1);
|
|
459
872
|
|
|
@@ -764,6 +1177,9 @@ var CliRunner = class _CliRunner {
|
|
|
764
1177
|
async run(context, args, opts) {
|
|
765
1178
|
const argv = this.buildArgv(context, args);
|
|
766
1179
|
const { signal, onProgress, onLfsProgress, env: envOverride } = opts ?? {};
|
|
1180
|
+
if (signal?.aborted) {
|
|
1181
|
+
return { stdout: "", stderr: "", exitCode: -1, aborted: true };
|
|
1182
|
+
}
|
|
767
1183
|
const env = this.buildEnv();
|
|
768
1184
|
if (envOverride) {
|
|
769
1185
|
Object.assign(env, envOverride);
|
|
@@ -824,7 +1240,17 @@ var CliRunner = class _CliRunner {
|
|
|
824
1240
|
duration: endTimestamp - startTimestamp
|
|
825
1241
|
});
|
|
826
1242
|
}
|
|
827
|
-
|
|
1243
|
+
if (error instanceof GitError) {
|
|
1244
|
+
throw error;
|
|
1245
|
+
}
|
|
1246
|
+
throw new GitError(
|
|
1247
|
+
signal?.aborted ? "Aborted" : "SpawnFailed",
|
|
1248
|
+
error instanceof Error ? error.message : String(error),
|
|
1249
|
+
{
|
|
1250
|
+
argv,
|
|
1251
|
+
...context.type === "worktree" ? { workdir: context.workdir } : context.type === "bare" ? { gitDir: context.gitDir } : {}
|
|
1252
|
+
}
|
|
1253
|
+
);
|
|
828
1254
|
}
|
|
829
1255
|
if (this.audit?.onAudit) {
|
|
830
1256
|
const endTimestamp = Date.now();
|
|
@@ -929,6 +1355,12 @@ var CliRunner = class _CliRunner {
|
|
|
929
1355
|
/**
|
|
930
1356
|
* Run a command and throw on error
|
|
931
1357
|
*/
|
|
1358
|
+
checkResult(context, args, result) {
|
|
1359
|
+
const error = this.mapError(result, context, this.buildArgv(context, args));
|
|
1360
|
+
if (error) {
|
|
1361
|
+
throw error;
|
|
1362
|
+
}
|
|
1363
|
+
}
|
|
932
1364
|
async runOrThrow(context, args, opts) {
|
|
933
1365
|
const result = await this.run(context, args, opts);
|
|
934
1366
|
const error = this.mapError(result, context, this.buildArgv(context, args));
|
|
@@ -939,6 +1371,230 @@ var CliRunner = class _CliRunner {
|
|
|
939
1371
|
}
|
|
940
1372
|
};
|
|
941
1373
|
|
|
1374
|
+
// src/internal/transport.ts
|
|
1375
|
+
async function fetch(runner, context, opts) {
|
|
1376
|
+
validateOptions("fetch", opts);
|
|
1377
|
+
const args = ["fetch"];
|
|
1378
|
+
if (opts?.onProgress) {
|
|
1379
|
+
args.push("--progress");
|
|
1380
|
+
}
|
|
1381
|
+
if (opts?.verbose) {
|
|
1382
|
+
args.push("--verbose");
|
|
1383
|
+
}
|
|
1384
|
+
if (opts?.quiet) {
|
|
1385
|
+
args.push("--quiet");
|
|
1386
|
+
}
|
|
1387
|
+
if (opts?.all) {
|
|
1388
|
+
args.push("--all");
|
|
1389
|
+
}
|
|
1390
|
+
if (opts?.setUpstream) {
|
|
1391
|
+
args.push("--set-upstream");
|
|
1392
|
+
}
|
|
1393
|
+
if (opts?.append) {
|
|
1394
|
+
args.push("--append");
|
|
1395
|
+
}
|
|
1396
|
+
if (opts?.atomic) {
|
|
1397
|
+
args.push("--atomic");
|
|
1398
|
+
}
|
|
1399
|
+
if (opts?.force) {
|
|
1400
|
+
args.push("--force");
|
|
1401
|
+
}
|
|
1402
|
+
if (opts?.prune) {
|
|
1403
|
+
args.push("--prune");
|
|
1404
|
+
}
|
|
1405
|
+
if (opts?.pruneTags) {
|
|
1406
|
+
args.push("--prune-tags");
|
|
1407
|
+
}
|
|
1408
|
+
if (opts?.tags) {
|
|
1409
|
+
args.push("--tags");
|
|
1410
|
+
} else if (opts?.noTags) {
|
|
1411
|
+
args.push("--no-tags");
|
|
1412
|
+
}
|
|
1413
|
+
if (opts?.jobs !== void 0) {
|
|
1414
|
+
args.push(`--jobs=${opts.jobs}`);
|
|
1415
|
+
}
|
|
1416
|
+
if (opts?.prefetch) {
|
|
1417
|
+
args.push("--prefetch");
|
|
1418
|
+
}
|
|
1419
|
+
if (opts?.recurseSubmodules !== void 0) {
|
|
1420
|
+
if (opts.recurseSubmodules === true || opts.recurseSubmodules === "yes") {
|
|
1421
|
+
args.push("--recurse-submodules=yes");
|
|
1422
|
+
} else if (opts.recurseSubmodules === "on-demand") {
|
|
1423
|
+
args.push("--recurse-submodules=on-demand");
|
|
1424
|
+
} else if (opts.recurseSubmodules === "no" || opts.recurseSubmodules === false) {
|
|
1425
|
+
args.push("--recurse-submodules=no");
|
|
1426
|
+
}
|
|
1427
|
+
}
|
|
1428
|
+
if (opts?.dryRun) {
|
|
1429
|
+
args.push("--dry-run");
|
|
1430
|
+
}
|
|
1431
|
+
if (opts?.writeFetchHead === false) {
|
|
1432
|
+
args.push("--no-write-fetch-head");
|
|
1433
|
+
}
|
|
1434
|
+
if (opts?.keep) {
|
|
1435
|
+
args.push("--keep");
|
|
1436
|
+
}
|
|
1437
|
+
if (opts?.updateHeadOk) {
|
|
1438
|
+
args.push("--update-head-ok");
|
|
1439
|
+
}
|
|
1440
|
+
if (opts?.depth !== void 0) {
|
|
1441
|
+
args.push(`--depth=${opts.depth}`);
|
|
1442
|
+
}
|
|
1443
|
+
if (opts?.shallowSince) {
|
|
1444
|
+
const since = opts.shallowSince instanceof Date ? opts.shallowSince.toISOString() : opts.shallowSince;
|
|
1445
|
+
args.push(`--shallow-since=${since}`);
|
|
1446
|
+
}
|
|
1447
|
+
if (opts?.shallowExclude) {
|
|
1448
|
+
const excludes = Array.isArray(opts.shallowExclude) ? opts.shallowExclude : [opts.shallowExclude];
|
|
1449
|
+
for (const exclude of excludes) {
|
|
1450
|
+
args.push(`--shallow-exclude=${exclude}`);
|
|
1451
|
+
}
|
|
1452
|
+
}
|
|
1453
|
+
if (opts?.deepen !== void 0) {
|
|
1454
|
+
args.push(`--deepen=${opts.deepen}`);
|
|
1455
|
+
}
|
|
1456
|
+
if (opts?.unshallow) {
|
|
1457
|
+
args.push("--unshallow");
|
|
1458
|
+
}
|
|
1459
|
+
if (opts?.refetch) {
|
|
1460
|
+
args.push("--refetch");
|
|
1461
|
+
}
|
|
1462
|
+
if (opts?.updateShallow) {
|
|
1463
|
+
args.push("--update-shallow");
|
|
1464
|
+
}
|
|
1465
|
+
if (opts?.refmap) {
|
|
1466
|
+
args.push(`--refmap=${opts.refmap}`);
|
|
1467
|
+
}
|
|
1468
|
+
if (opts?.ipv4) {
|
|
1469
|
+
args.push("--ipv4");
|
|
1470
|
+
}
|
|
1471
|
+
if (opts?.ipv6) {
|
|
1472
|
+
args.push("--ipv6");
|
|
1473
|
+
}
|
|
1474
|
+
if (opts?.filter) {
|
|
1475
|
+
args.push(`--filter=${opts.filter}`);
|
|
1476
|
+
}
|
|
1477
|
+
if (opts?.showForcedUpdates === false) {
|
|
1478
|
+
args.push("--no-show-forced-updates");
|
|
1479
|
+
}
|
|
1480
|
+
if (opts?.writeCommitGraph) {
|
|
1481
|
+
args.push("--write-commit-graph");
|
|
1482
|
+
}
|
|
1483
|
+
if (opts?.remote) {
|
|
1484
|
+
args.push(opts.remote);
|
|
1485
|
+
}
|
|
1486
|
+
if (opts?.refspec) {
|
|
1487
|
+
const refspecs = Array.isArray(opts.refspec) ? opts.refspec : [opts.refspec];
|
|
1488
|
+
args.push(...refspecs);
|
|
1489
|
+
}
|
|
1490
|
+
await runner.runOrThrow(context, args, {
|
|
1491
|
+
signal: opts?.signal,
|
|
1492
|
+
onProgress: opts?.onProgress
|
|
1493
|
+
});
|
|
1494
|
+
}
|
|
1495
|
+
async function push(runner, context, opts) {
|
|
1496
|
+
validateOptions("push", opts);
|
|
1497
|
+
const args = ["push"];
|
|
1498
|
+
if (opts?.onProgress || opts?.onLfsProgress) {
|
|
1499
|
+
args.push("--progress");
|
|
1500
|
+
}
|
|
1501
|
+
if (opts?.verbose) {
|
|
1502
|
+
args.push("--verbose");
|
|
1503
|
+
}
|
|
1504
|
+
if (opts?.quiet) {
|
|
1505
|
+
args.push("--quiet");
|
|
1506
|
+
}
|
|
1507
|
+
if (opts?.repo) {
|
|
1508
|
+
args.push(`--repo=${opts.repo}`);
|
|
1509
|
+
}
|
|
1510
|
+
if (opts?.all) {
|
|
1511
|
+
args.push("--all");
|
|
1512
|
+
} else if (opts?.branches) {
|
|
1513
|
+
args.push("--branches");
|
|
1514
|
+
}
|
|
1515
|
+
if (opts?.mirror) {
|
|
1516
|
+
args.push("--mirror");
|
|
1517
|
+
}
|
|
1518
|
+
if (opts?.deleteRefs) {
|
|
1519
|
+
args.push("--delete");
|
|
1520
|
+
}
|
|
1521
|
+
if (opts?.force) {
|
|
1522
|
+
args.push("--force");
|
|
1523
|
+
} else if (opts?.forceWithLease !== void 0 && opts.forceWithLease !== false) {
|
|
1524
|
+
if (opts.forceWithLease === true) {
|
|
1525
|
+
args.push("--force-with-lease");
|
|
1526
|
+
} else {
|
|
1527
|
+
const leaseOpts = opts.forceWithLease;
|
|
1528
|
+
if (leaseOpts.expect !== void 0) {
|
|
1529
|
+
args.push(`--force-with-lease=${leaseOpts.refname}:${leaseOpts.expect}`);
|
|
1530
|
+
} else {
|
|
1531
|
+
args.push(`--force-with-lease=${leaseOpts.refname}`);
|
|
1532
|
+
}
|
|
1533
|
+
}
|
|
1534
|
+
}
|
|
1535
|
+
if (opts?.forceIfIncludes) {
|
|
1536
|
+
args.push("--force-if-includes");
|
|
1537
|
+
}
|
|
1538
|
+
if (opts?.dryRun) {
|
|
1539
|
+
args.push("--dry-run");
|
|
1540
|
+
}
|
|
1541
|
+
if (opts?.recurseSubmodules) {
|
|
1542
|
+
args.push(`--recurse-submodules=${opts.recurseSubmodules}`);
|
|
1543
|
+
}
|
|
1544
|
+
if (opts?.thin === false) {
|
|
1545
|
+
args.push("--no-thin");
|
|
1546
|
+
}
|
|
1547
|
+
if (opts?.prune) {
|
|
1548
|
+
args.push("--prune");
|
|
1549
|
+
}
|
|
1550
|
+
if (opts?.tags) {
|
|
1551
|
+
args.push("--tags");
|
|
1552
|
+
}
|
|
1553
|
+
if (opts?.followTags) {
|
|
1554
|
+
args.push("--follow-tags");
|
|
1555
|
+
}
|
|
1556
|
+
if (opts?.atomic) {
|
|
1557
|
+
args.push("--atomic");
|
|
1558
|
+
}
|
|
1559
|
+
if (opts?.pushOption) {
|
|
1560
|
+
const pushOptions = Array.isArray(opts.pushOption) ? opts.pushOption : [opts.pushOption];
|
|
1561
|
+
for (const opt of pushOptions) {
|
|
1562
|
+
args.push("--push-option", opt);
|
|
1563
|
+
}
|
|
1564
|
+
}
|
|
1565
|
+
if (opts?.setUpstream) {
|
|
1566
|
+
args.push("--set-upstream");
|
|
1567
|
+
}
|
|
1568
|
+
if (opts?.noVerify) {
|
|
1569
|
+
args.push("--no-verify");
|
|
1570
|
+
}
|
|
1571
|
+
if (opts?.signed !== void 0) {
|
|
1572
|
+
if (opts.signed === true) {
|
|
1573
|
+
args.push("--signed");
|
|
1574
|
+
} else if (opts.signed === "if-asked") {
|
|
1575
|
+
args.push("--signed=if-asked");
|
|
1576
|
+
}
|
|
1577
|
+
}
|
|
1578
|
+
if (opts?.ipv4) {
|
|
1579
|
+
args.push("--ipv4");
|
|
1580
|
+
}
|
|
1581
|
+
if (opts?.ipv6) {
|
|
1582
|
+
args.push("--ipv6");
|
|
1583
|
+
}
|
|
1584
|
+
if (opts?.remote) {
|
|
1585
|
+
args.push(opts.remote);
|
|
1586
|
+
}
|
|
1587
|
+
if (opts?.refspec) {
|
|
1588
|
+
const refspecs = Array.isArray(opts.refspec) ? opts.refspec : [opts.refspec];
|
|
1589
|
+
args.push(...refspecs);
|
|
1590
|
+
}
|
|
1591
|
+
await runner.runOrThrow(context, args, {
|
|
1592
|
+
signal: opts?.signal,
|
|
1593
|
+
onProgress: opts?.onProgress,
|
|
1594
|
+
onLfsProgress: opts?.onLfsProgress
|
|
1595
|
+
});
|
|
1596
|
+
}
|
|
1597
|
+
|
|
942
1598
|
// src/impl/bare-repo-impl.ts
|
|
943
1599
|
var REMOTE_LINE_PATTERN = /^(\S+)\t(.+?)\s+\((fetch|push)\)$/;
|
|
944
1600
|
var PRUNED_REF_PATTERN = /\* \[pruned\] (.+)/;
|
|
@@ -1131,6 +1787,7 @@ function isListQuery(opts) {
|
|
|
1131
1787
|
return "glob" in opts && !!opts.glob || "disambiguate" in opts && !!opts.disambiguate || "localEnvVars" in opts && !!opts.localEnvVars;
|
|
1132
1788
|
}
|
|
1133
1789
|
var BareRepoImpl = class {
|
|
1790
|
+
kind = "bare";
|
|
1134
1791
|
gitDir;
|
|
1135
1792
|
runner;
|
|
1136
1793
|
remote;
|
|
@@ -1196,6 +1853,7 @@ var BareRepoImpl = class {
|
|
|
1196
1853
|
* List references in a remote repository
|
|
1197
1854
|
*/
|
|
1198
1855
|
async lsRemote(remote, opts) {
|
|
1856
|
+
validateOptions("lsRemote", opts);
|
|
1199
1857
|
const args = ["ls-remote"];
|
|
1200
1858
|
if (opts?.heads) {
|
|
1201
1859
|
args.push("--heads");
|
|
@@ -1206,15 +1864,9 @@ var BareRepoImpl = class {
|
|
|
1206
1864
|
if (opts?.refsOnly) {
|
|
1207
1865
|
args.push("--refs");
|
|
1208
1866
|
}
|
|
1209
|
-
if (opts?.getUrl) {
|
|
1210
|
-
args.push("--get-url");
|
|
1211
|
-
}
|
|
1212
1867
|
if (opts?.sort) {
|
|
1213
1868
|
args.push("--sort", opts.sort);
|
|
1214
1869
|
}
|
|
1215
|
-
if (opts?.symref) {
|
|
1216
|
-
args.push("--symref");
|
|
1217
|
-
}
|
|
1218
1870
|
args.push(remote);
|
|
1219
1871
|
if (opts?.refs && opts.refs.length > 0) {
|
|
1220
1872
|
args.push(...opts.refs);
|
|
@@ -1226,11 +1878,9 @@ var BareRepoImpl = class {
|
|
|
1226
1878
|
const refs = parseLsRemote(result.stdout);
|
|
1227
1879
|
return { refs };
|
|
1228
1880
|
}
|
|
1229
|
-
/**
|
|
1230
|
-
* List contents of a tree object
|
|
1231
|
-
*/
|
|
1232
1881
|
async lsTree(treeish, opts) {
|
|
1233
|
-
|
|
1882
|
+
validateOptions("lsTree", opts);
|
|
1883
|
+
const args = ["ls-tree", "-z"];
|
|
1234
1884
|
if (opts?.recursive) {
|
|
1235
1885
|
args.push("-r");
|
|
1236
1886
|
}
|
|
@@ -1243,12 +1893,6 @@ var BareRepoImpl = class {
|
|
|
1243
1893
|
if (opts?.long) {
|
|
1244
1894
|
args.push("--long");
|
|
1245
1895
|
}
|
|
1246
|
-
if (opts?.nameOnly) {
|
|
1247
|
-
args.push("--name-only");
|
|
1248
|
-
}
|
|
1249
|
-
if (opts?.objectOnly) {
|
|
1250
|
-
args.push("--object-only");
|
|
1251
|
-
}
|
|
1252
1896
|
if (opts?.fullName) {
|
|
1253
1897
|
args.push("--full-name");
|
|
1254
1898
|
}
|
|
@@ -1269,11 +1913,14 @@ var BareRepoImpl = class {
|
|
|
1269
1913
|
const result = await this.runner.runOrThrow(this.context, args, {
|
|
1270
1914
|
signal: opts?.signal
|
|
1271
1915
|
});
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1916
|
+
const entries = parseLsTree(result.stdout, { long: opts?.long });
|
|
1917
|
+
if (opts?.nameOnly) {
|
|
1918
|
+
return entries.map((entry) => entry.path);
|
|
1919
|
+
}
|
|
1920
|
+
if (opts?.objectOnly) {
|
|
1921
|
+
return entries.map((entry) => entry.hash);
|
|
1922
|
+
}
|
|
1923
|
+
return entries;
|
|
1277
1924
|
}
|
|
1278
1925
|
async revParse(refOrOpts, opts) {
|
|
1279
1926
|
const args = ["rev-parse"];
|
|
@@ -1285,11 +1932,12 @@ var BareRepoImpl = class {
|
|
|
1285
1932
|
});
|
|
1286
1933
|
return result2.stdout.trim();
|
|
1287
1934
|
}
|
|
1935
|
+
validateRevParseQuery(refOrOpts);
|
|
1936
|
+
if ("pathFormat" in refOrOpts && refOrOpts.pathFormat) {
|
|
1937
|
+
args.push(`--path-format=${refOrOpts.pathFormat}`);
|
|
1938
|
+
}
|
|
1288
1939
|
const queryOpts = refOrOpts;
|
|
1289
1940
|
tryAddPathQuery(args, queryOpts) || tryAddBooleanQuery(args, queryOpts) || tryAddListQuery(args, queryOpts) || tryAddOtherQuery(args, queryOpts);
|
|
1290
|
-
if ("pathFormat" in queryOpts && queryOpts.pathFormat) {
|
|
1291
|
-
args.push(`--path-format=${queryOpts.pathFormat}`);
|
|
1292
|
-
}
|
|
1293
1941
|
const result = await this.runner.runOrThrow(this.context, args, {
|
|
1294
1942
|
signal: refOrOpts.signal
|
|
1295
1943
|
});
|
|
@@ -1306,60 +1954,13 @@ var BareRepoImpl = class {
|
|
|
1306
1954
|
* Fetch from remote
|
|
1307
1955
|
*/
|
|
1308
1956
|
async fetch(opts) {
|
|
1309
|
-
|
|
1310
|
-
if (opts?.onProgress) {
|
|
1311
|
-
args.push("--progress");
|
|
1312
|
-
}
|
|
1313
|
-
if (opts?.prune) {
|
|
1314
|
-
args.push("--prune");
|
|
1315
|
-
}
|
|
1316
|
-
if (opts?.tags) {
|
|
1317
|
-
args.push("--tags");
|
|
1318
|
-
}
|
|
1319
|
-
if (opts?.depth !== void 0) {
|
|
1320
|
-
args.push(`--depth=${opts.depth}`);
|
|
1321
|
-
}
|
|
1322
|
-
if (opts?.remote) {
|
|
1323
|
-
args.push(opts.remote);
|
|
1324
|
-
}
|
|
1325
|
-
if (opts?.refspec) {
|
|
1326
|
-
const refspecs = Array.isArray(opts.refspec) ? opts.refspec : [opts.refspec];
|
|
1327
|
-
args.push(...refspecs);
|
|
1328
|
-
}
|
|
1329
|
-
await this.runner.runOrThrow(this.context, args, {
|
|
1330
|
-
signal: opts?.signal,
|
|
1331
|
-
onProgress: opts?.onProgress
|
|
1332
|
-
});
|
|
1957
|
+
return fetch(this.runner, this.context, opts);
|
|
1333
1958
|
}
|
|
1334
1959
|
/**
|
|
1335
1960
|
* Push to remote
|
|
1336
1961
|
*/
|
|
1337
1962
|
async push(opts) {
|
|
1338
|
-
|
|
1339
|
-
if (opts?.onProgress || opts?.onLfsProgress) {
|
|
1340
|
-
args.push("--progress");
|
|
1341
|
-
}
|
|
1342
|
-
if (opts?.force) {
|
|
1343
|
-
args.push("--force");
|
|
1344
|
-
}
|
|
1345
|
-
if (opts?.tags) {
|
|
1346
|
-
args.push("--tags");
|
|
1347
|
-
}
|
|
1348
|
-
if (opts?.setUpstream) {
|
|
1349
|
-
args.push("--set-upstream");
|
|
1350
|
-
}
|
|
1351
|
-
if (opts?.remote) {
|
|
1352
|
-
args.push(opts.remote);
|
|
1353
|
-
}
|
|
1354
|
-
if (opts?.refspec) {
|
|
1355
|
-
const refspecs = Array.isArray(opts.refspec) ? opts.refspec : [opts.refspec];
|
|
1356
|
-
args.push(...refspecs);
|
|
1357
|
-
}
|
|
1358
|
-
await this.runner.runOrThrow(this.context, args, {
|
|
1359
|
-
signal: opts?.signal,
|
|
1360
|
-
onProgress: opts?.onProgress,
|
|
1361
|
-
onLfsProgress: opts?.onLfsProgress
|
|
1362
|
-
});
|
|
1963
|
+
return push(this.runner, this.context, opts);
|
|
1363
1964
|
}
|
|
1364
1965
|
// ==========================================================================
|
|
1365
1966
|
// Remote Operations
|
|
@@ -1425,6 +2026,7 @@ var BareRepoImpl = class {
|
|
|
1425
2026
|
});
|
|
1426
2027
|
}
|
|
1427
2028
|
async remoteSetHead(remote, branch, opts) {
|
|
2029
|
+
validateOptions("remoteSetHead", opts);
|
|
1428
2030
|
const args = ["remote", "set-head"];
|
|
1429
2031
|
if (opts?.auto) {
|
|
1430
2032
|
args.push("--auto");
|
|
@@ -1498,25 +2100,14 @@ var BareRepoImpl = class {
|
|
|
1498
2100
|
* Get a typed config value
|
|
1499
2101
|
*/
|
|
1500
2102
|
async configGet(key, opts) {
|
|
1501
|
-
const
|
|
1502
|
-
|
|
1503
|
-
});
|
|
1504
|
-
if (result.exitCode !== 0) {
|
|
1505
|
-
return void 0;
|
|
1506
|
-
}
|
|
1507
|
-
return result.stdout.trim();
|
|
2103
|
+
const values = await readTypedConfig(this.runner, this.context, key, opts);
|
|
2104
|
+
return values.at(-1);
|
|
1508
2105
|
}
|
|
1509
2106
|
/**
|
|
1510
2107
|
* Get all values for a typed multi-valued config key
|
|
1511
2108
|
*/
|
|
1512
2109
|
async configGetAll(key, opts) {
|
|
1513
|
-
|
|
1514
|
-
signal: opts?.signal
|
|
1515
|
-
});
|
|
1516
|
-
if (result.exitCode !== 0) {
|
|
1517
|
-
return [];
|
|
1518
|
-
}
|
|
1519
|
-
return parseLines(result.stdout);
|
|
2110
|
+
return readTypedConfig(this.runner, this.context, key, opts, true);
|
|
1520
2111
|
}
|
|
1521
2112
|
/**
|
|
1522
2113
|
* Set a typed config value
|
|
@@ -1542,27 +2133,8 @@ var BareRepoImpl = class {
|
|
|
1542
2133
|
signal: opts?.signal
|
|
1543
2134
|
});
|
|
1544
2135
|
}
|
|
1545
|
-
/**
|
|
1546
|
-
* Get a raw config value (for arbitrary keys)
|
|
1547
|
-
*/
|
|
1548
2136
|
async configGetRaw(key, opts) {
|
|
1549
|
-
|
|
1550
|
-
if (opts?.all) {
|
|
1551
|
-
args.push("--get-all");
|
|
1552
|
-
} else {
|
|
1553
|
-
args.push("--get");
|
|
1554
|
-
}
|
|
1555
|
-
args.push(key);
|
|
1556
|
-
const result = await this.runner.run(this.context, args, {
|
|
1557
|
-
signal: opts?.signal
|
|
1558
|
-
});
|
|
1559
|
-
if (result.exitCode !== 0) {
|
|
1560
|
-
return void 0;
|
|
1561
|
-
}
|
|
1562
|
-
if (opts?.all) {
|
|
1563
|
-
return parseLines(result.stdout);
|
|
1564
|
-
}
|
|
1565
|
-
return result.stdout.trim();
|
|
2137
|
+
return readConfig(this.runner, this.context, key, opts);
|
|
1566
2138
|
}
|
|
1567
2139
|
/**
|
|
1568
2140
|
* Set a raw config value (for arbitrary keys)
|
|
@@ -1589,47 +2161,7 @@ var BareRepoImpl = class {
|
|
|
1589
2161
|
* List all config values
|
|
1590
2162
|
*/
|
|
1591
2163
|
async configList(opts) {
|
|
1592
|
-
|
|
1593
|
-
if (opts?.showOrigin) {
|
|
1594
|
-
args.push("--show-origin");
|
|
1595
|
-
}
|
|
1596
|
-
if (opts?.showScope) {
|
|
1597
|
-
args.push("--show-scope");
|
|
1598
|
-
}
|
|
1599
|
-
if (opts?.includes) {
|
|
1600
|
-
args.push("--includes");
|
|
1601
|
-
}
|
|
1602
|
-
if (opts?.nameOnly) {
|
|
1603
|
-
args.push("--name-only");
|
|
1604
|
-
}
|
|
1605
|
-
const result = await this.runner.runOrThrow(this.context, args, {
|
|
1606
|
-
signal: opts?.signal
|
|
1607
|
-
});
|
|
1608
|
-
const entries = [];
|
|
1609
|
-
for (const line of parseLines(result.stdout)) {
|
|
1610
|
-
let keyValue = line;
|
|
1611
|
-
if (opts?.showOrigin || opts?.showScope) {
|
|
1612
|
-
const tabIndex = line.lastIndexOf(" ");
|
|
1613
|
-
if (tabIndex !== -1) {
|
|
1614
|
-
keyValue = line.slice(tabIndex + 1);
|
|
1615
|
-
}
|
|
1616
|
-
}
|
|
1617
|
-
if (opts?.nameOnly) {
|
|
1618
|
-
entries.push({
|
|
1619
|
-
key: keyValue,
|
|
1620
|
-
value: ""
|
|
1621
|
-
});
|
|
1622
|
-
} else {
|
|
1623
|
-
const eqIndex = keyValue.indexOf("=");
|
|
1624
|
-
if (eqIndex !== -1) {
|
|
1625
|
-
entries.push({
|
|
1626
|
-
key: keyValue.slice(0, eqIndex),
|
|
1627
|
-
value: keyValue.slice(eqIndex + 1)
|
|
1628
|
-
});
|
|
1629
|
-
}
|
|
1630
|
-
}
|
|
1631
|
-
}
|
|
1632
|
-
return entries;
|
|
2164
|
+
return listConfig(this.runner, this.context, opts);
|
|
1633
2165
|
}
|
|
1634
2166
|
async configRenameSection(oldName, newName, opts) {
|
|
1635
2167
|
await this.runner.runOrThrow(this.context, ["config", "--rename-section", oldName, newName], {
|
|
@@ -1643,6 +2175,58 @@ var BareRepoImpl = class {
|
|
|
1643
2175
|
}
|
|
1644
2176
|
};
|
|
1645
2177
|
|
|
2178
|
+
// src/internal/lfs-output.ts
|
|
2179
|
+
function record(value) {
|
|
2180
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
2181
|
+
}
|
|
2182
|
+
function data(stdout) {
|
|
2183
|
+
try {
|
|
2184
|
+
const value = JSON.parse(stdout);
|
|
2185
|
+
if (record(value)) {
|
|
2186
|
+
return value;
|
|
2187
|
+
}
|
|
2188
|
+
} catch {
|
|
2189
|
+
}
|
|
2190
|
+
throw new GitError("ParseError", "Invalid Git LFS JSON", { stdout });
|
|
2191
|
+
}
|
|
2192
|
+
function validSize(value) {
|
|
2193
|
+
return typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
|
|
2194
|
+
}
|
|
2195
|
+
function parseLfsStatusJson(stdout) {
|
|
2196
|
+
const files = data(stdout).files;
|
|
2197
|
+
if (!record(files)) {
|
|
2198
|
+
throw new GitError("ParseError", "Missing Git LFS status files");
|
|
2199
|
+
}
|
|
2200
|
+
return {
|
|
2201
|
+
files: Object.entries(files).map(([name, value]) => {
|
|
2202
|
+
if (!record(value) || typeof value.status !== "string" || value.size !== void 0 && !validSize(value.size)) {
|
|
2203
|
+
throw new GitError("ParseError", "Invalid Git LFS status entry");
|
|
2204
|
+
}
|
|
2205
|
+
return { name, status: value.status, ...validSize(value.size) ? { size: value.size } : {} };
|
|
2206
|
+
})
|
|
2207
|
+
};
|
|
2208
|
+
}
|
|
2209
|
+
function parseLfsFilesJson(stdout) {
|
|
2210
|
+
const files = data(stdout).files;
|
|
2211
|
+
if (files === null) {
|
|
2212
|
+
return [];
|
|
2213
|
+
}
|
|
2214
|
+
if (!Array.isArray(files)) {
|
|
2215
|
+
throw new GitError("ParseError", "Missing Git LFS file list");
|
|
2216
|
+
}
|
|
2217
|
+
return files.map((value) => {
|
|
2218
|
+
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)) {
|
|
2219
|
+
throw new GitError("ParseError", "Invalid Git LFS file entry");
|
|
2220
|
+
}
|
|
2221
|
+
return {
|
|
2222
|
+
path: value.name,
|
|
2223
|
+
oid: value.oid,
|
|
2224
|
+
size: value.size,
|
|
2225
|
+
status: value.checkout ? "checked-out" : "not-checked-out"
|
|
2226
|
+
};
|
|
2227
|
+
});
|
|
2228
|
+
}
|
|
2229
|
+
|
|
1646
2230
|
// src/internal/concurrency.ts
|
|
1647
2231
|
async function runWithConcurrency(items, run, options) {
|
|
1648
2232
|
const { concurrency, warmupCount = 0 } = options;
|
|
@@ -1691,6 +2275,7 @@ var PRE_UPLOAD_DEFAULT_BATCH_SIZE = 200;
|
|
|
1691
2275
|
var PRE_UPLOAD_DEFAULT_CONCURRENCY = 4;
|
|
1692
2276
|
var PRE_UPLOAD_WARMUP_BATCH_COUNT = 1;
|
|
1693
2277
|
var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
2278
|
+
kind = "worktree";
|
|
1694
2279
|
workdir;
|
|
1695
2280
|
runner;
|
|
1696
2281
|
_lfsMode = "enabled";
|
|
@@ -1838,6 +2423,7 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
1838
2423
|
* List references in a remote repository
|
|
1839
2424
|
*/
|
|
1840
2425
|
async lsRemote(remote, opts) {
|
|
2426
|
+
validateOptions("lsRemote", opts);
|
|
1841
2427
|
const args = ["ls-remote"];
|
|
1842
2428
|
if (opts?.heads) {
|
|
1843
2429
|
args.push("--heads");
|
|
@@ -1848,15 +2434,9 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
1848
2434
|
if (opts?.refsOnly) {
|
|
1849
2435
|
args.push("--refs");
|
|
1850
2436
|
}
|
|
1851
|
-
if (opts?.getUrl) {
|
|
1852
|
-
args.push("--get-url");
|
|
1853
|
-
}
|
|
1854
2437
|
if (opts?.sort) {
|
|
1855
2438
|
args.push("--sort", opts.sort);
|
|
1856
2439
|
}
|
|
1857
|
-
if (opts?.symref) {
|
|
1858
|
-
args.push("--symref");
|
|
1859
|
-
}
|
|
1860
2440
|
args.push(remote);
|
|
1861
2441
|
if (opts?.refs && opts.refs.length > 0) {
|
|
1862
2442
|
args.push(...opts.refs);
|
|
@@ -1868,11 +2448,9 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
1868
2448
|
const refs = parseLsRemote(result.stdout);
|
|
1869
2449
|
return { refs };
|
|
1870
2450
|
}
|
|
1871
|
-
/**
|
|
1872
|
-
* List contents of a tree object
|
|
1873
|
-
*/
|
|
1874
2451
|
async lsTree(treeish, opts) {
|
|
1875
|
-
|
|
2452
|
+
validateOptions("lsTree", opts);
|
|
2453
|
+
const args = ["ls-tree", "-z"];
|
|
1876
2454
|
if (opts?.recursive) {
|
|
1877
2455
|
args.push("-r");
|
|
1878
2456
|
}
|
|
@@ -1885,12 +2463,6 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
1885
2463
|
if (opts?.long) {
|
|
1886
2464
|
args.push("--long");
|
|
1887
2465
|
}
|
|
1888
|
-
if (opts?.nameOnly) {
|
|
1889
|
-
args.push("--name-only");
|
|
1890
|
-
}
|
|
1891
|
-
if (opts?.objectOnly) {
|
|
1892
|
-
args.push("--object-only");
|
|
1893
|
-
}
|
|
1894
2466
|
if (opts?.fullName) {
|
|
1895
2467
|
args.push("--full-name");
|
|
1896
2468
|
}
|
|
@@ -1911,20 +2483,21 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
1911
2483
|
const result = await this.runner.runOrThrow(this.context, args, {
|
|
1912
2484
|
signal: opts?.signal
|
|
1913
2485
|
});
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
2486
|
+
const entries = parseLsTree(result.stdout, { long: opts?.long });
|
|
2487
|
+
if (opts?.nameOnly) {
|
|
2488
|
+
return entries.map((entry) => entry.path);
|
|
2489
|
+
}
|
|
2490
|
+
if (opts?.objectOnly) {
|
|
2491
|
+
return entries.map((entry) => entry.hash);
|
|
2492
|
+
}
|
|
2493
|
+
return entries;
|
|
1919
2494
|
}
|
|
1920
2495
|
/**
|
|
1921
2496
|
* Get repository status
|
|
1922
2497
|
*/
|
|
1923
2498
|
async status(opts) {
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
args.push("--verbose");
|
|
1927
|
-
}
|
|
2499
|
+
validateOptions("status", opts);
|
|
2500
|
+
const args = ["status", "--porcelain=v2", "-z"];
|
|
1928
2501
|
if (opts?.untracked) {
|
|
1929
2502
|
switch (opts.untracked) {
|
|
1930
2503
|
case "no":
|
|
@@ -1945,9 +2518,6 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
1945
2518
|
if (opts?.aheadBehind === false) {
|
|
1946
2519
|
args.push("--no-ahead-behind");
|
|
1947
2520
|
}
|
|
1948
|
-
if (opts?.nullTerminated) {
|
|
1949
|
-
args.push("-z");
|
|
1950
|
-
}
|
|
1951
2521
|
if (opts?.ignored) {
|
|
1952
2522
|
switch (opts.ignored) {
|
|
1953
2523
|
case "traditional":
|
|
@@ -1979,81 +2549,60 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
1979
2549
|
return this.parseStatus(result.stdout);
|
|
1980
2550
|
}
|
|
1981
2551
|
parseStatus(stdout) {
|
|
1982
|
-
const
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
let behind;
|
|
1988
|
-
for (const line of lines) {
|
|
1989
|
-
if (line.startsWith("# branch.head ")) {
|
|
1990
|
-
branch = line.slice("# branch.head ".length);
|
|
1991
|
-
} else if (line.startsWith("# branch.upstream ")) {
|
|
1992
|
-
upstream = line.slice("# branch.upstream ".length);
|
|
1993
|
-
} else if (line.startsWith("# branch.ab ")) {
|
|
1994
|
-
const match = line.match(/# branch\.ab \+(\d+) -(\d+)/);
|
|
1995
|
-
const aheadStr = match?.[1];
|
|
1996
|
-
const behindStr = match?.[2];
|
|
1997
|
-
if (aheadStr !== void 0 && behindStr !== void 0) {
|
|
1998
|
-
ahead = Number.parseInt(aheadStr, 10);
|
|
1999
|
-
behind = Number.parseInt(behindStr, 10);
|
|
2552
|
+
const result = {
|
|
2553
|
+
entries: parsePorcelainV2(stdout).map((entry) => {
|
|
2554
|
+
if (entry.type === "untracked" || entry.type === "ignored") {
|
|
2555
|
+
const status = entry.type === "untracked" ? "?" : "!";
|
|
2556
|
+
return { path: entry.path, index: status, workdir: status };
|
|
2000
2557
|
}
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
}
|
|
2030
|
-
} else if (line.startsWith("? ")) {
|
|
2031
|
-
entries.push({
|
|
2032
|
-
path: line.slice(2),
|
|
2033
|
-
index: "?",
|
|
2034
|
-
workdir: "?"
|
|
2035
|
-
});
|
|
2036
|
-
} else if (line.startsWith("! ")) {
|
|
2037
|
-
entries.push({
|
|
2038
|
-
path: line.slice(2),
|
|
2039
|
-
index: "!",
|
|
2040
|
-
workdir: "!"
|
|
2041
|
-
});
|
|
2558
|
+
return {
|
|
2559
|
+
path: entry.path,
|
|
2560
|
+
index: entry.xy[0],
|
|
2561
|
+
workdir: entry.xy[1],
|
|
2562
|
+
..."origPath" in entry && entry.origPath !== void 0 ? { originalPath: entry.origPath } : {}
|
|
2563
|
+
};
|
|
2564
|
+
})
|
|
2565
|
+
};
|
|
2566
|
+
const records = stdout.includes("\0") ? parseRecords(stdout) : parseLines(stdout, { trim: false });
|
|
2567
|
+
for (let i = 0; i < records.length; i++) {
|
|
2568
|
+
const line = records[i];
|
|
2569
|
+
if (line.startsWith("2 ") && stdout.includes("\0")) {
|
|
2570
|
+
i++;
|
|
2571
|
+
continue;
|
|
2572
|
+
}
|
|
2573
|
+
if (line.startsWith("# branch.head ")) {
|
|
2574
|
+
result.branch = line.slice(14);
|
|
2575
|
+
}
|
|
2576
|
+
if (line.startsWith("# branch.upstream ")) {
|
|
2577
|
+
result.upstream = line.slice(18);
|
|
2578
|
+
}
|
|
2579
|
+
const ab = line.match(/^# branch\.ab \+(\d+) -(\d+)$/);
|
|
2580
|
+
if (ab) {
|
|
2581
|
+
result.ahead = Number(ab[1]);
|
|
2582
|
+
result.behind = Number(ab[2]);
|
|
2583
|
+
}
|
|
2584
|
+
if (line.startsWith("# stash ")) {
|
|
2585
|
+
result.stash = Number(line.slice(8));
|
|
2042
2586
|
}
|
|
2043
2587
|
}
|
|
2044
|
-
return
|
|
2045
|
-
entries,
|
|
2046
|
-
branch,
|
|
2047
|
-
upstream,
|
|
2048
|
-
ahead,
|
|
2049
|
-
behind
|
|
2050
|
-
};
|
|
2588
|
+
return result;
|
|
2051
2589
|
}
|
|
2052
2590
|
/**
|
|
2053
2591
|
* Get commit log
|
|
2054
2592
|
*/
|
|
2055
2593
|
async log(opts) {
|
|
2056
|
-
|
|
2594
|
+
validateOptions("log", opts);
|
|
2595
|
+
const format = opts?.useMailmap ? GIT_LOG_FORMAT.replace("%an", "%aN").replace("%ae", "%aE").replace("%cn", "%cN").replace("%ce", "%cE") : GIT_LOG_FORMAT;
|
|
2596
|
+
const args = [
|
|
2597
|
+
"log",
|
|
2598
|
+
"-z",
|
|
2599
|
+
"--no-patch",
|
|
2600
|
+
"--no-notes",
|
|
2601
|
+
"--no-show-signature",
|
|
2602
|
+
"--no-color",
|
|
2603
|
+
"--encoding=UTF-8",
|
|
2604
|
+
`--format=${format}`
|
|
2605
|
+
];
|
|
2057
2606
|
if (opts?.maxCount !== void 0) {
|
|
2058
2607
|
args.push(`-n${opts.maxCount}`);
|
|
2059
2608
|
}
|
|
@@ -2086,33 +2635,9 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
2086
2635
|
if (opts?.firstParent) {
|
|
2087
2636
|
args.push("--first-parent");
|
|
2088
2637
|
}
|
|
2089
|
-
if (opts?.source) {
|
|
2090
|
-
args.push("--source");
|
|
2091
|
-
}
|
|
2092
2638
|
if (opts?.useMailmap) {
|
|
2093
2639
|
args.push("--use-mailmap");
|
|
2094
2640
|
}
|
|
2095
|
-
if (opts?.decorateRefs) {
|
|
2096
|
-
args.push(`--decorate-refs=${opts.decorateRefs}`);
|
|
2097
|
-
}
|
|
2098
|
-
if (opts?.decorateRefsExclude) {
|
|
2099
|
-
args.push(`--decorate-refs-exclude=${opts.decorateRefsExclude}`);
|
|
2100
|
-
}
|
|
2101
|
-
if (opts?.decorate) {
|
|
2102
|
-
args.push(`--decorate=${opts.decorate}`);
|
|
2103
|
-
}
|
|
2104
|
-
if (opts?.stat) {
|
|
2105
|
-
args.push("--stat");
|
|
2106
|
-
}
|
|
2107
|
-
if (opts?.shortstat) {
|
|
2108
|
-
args.push("--shortstat");
|
|
2109
|
-
}
|
|
2110
|
-
if (opts?.nameOnly) {
|
|
2111
|
-
args.push("--name-only");
|
|
2112
|
-
}
|
|
2113
|
-
if (opts?.nameStatus) {
|
|
2114
|
-
args.push("--name-status");
|
|
2115
|
-
}
|
|
2116
2641
|
if (opts?.merges) {
|
|
2117
2642
|
args.push("--merges");
|
|
2118
2643
|
}
|
|
@@ -2154,230 +2679,13 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
2154
2679
|
* Fetch from remote
|
|
2155
2680
|
*/
|
|
2156
2681
|
async fetch(opts) {
|
|
2157
|
-
|
|
2158
|
-
if (opts?.onProgress) {
|
|
2159
|
-
args.push("--progress");
|
|
2160
|
-
}
|
|
2161
|
-
if (opts?.verbose) {
|
|
2162
|
-
args.push("--verbose");
|
|
2163
|
-
}
|
|
2164
|
-
if (opts?.quiet) {
|
|
2165
|
-
args.push("--quiet");
|
|
2166
|
-
}
|
|
2167
|
-
if (opts?.all) {
|
|
2168
|
-
args.push("--all");
|
|
2169
|
-
}
|
|
2170
|
-
if (opts?.setUpstream) {
|
|
2171
|
-
args.push("--set-upstream");
|
|
2172
|
-
}
|
|
2173
|
-
if (opts?.append) {
|
|
2174
|
-
args.push("--append");
|
|
2175
|
-
}
|
|
2176
|
-
if (opts?.atomic) {
|
|
2177
|
-
args.push("--atomic");
|
|
2178
|
-
}
|
|
2179
|
-
if (opts?.force) {
|
|
2180
|
-
args.push("--force");
|
|
2181
|
-
}
|
|
2182
|
-
if (opts?.multiple) {
|
|
2183
|
-
args.push("--multiple");
|
|
2184
|
-
}
|
|
2185
|
-
if (opts?.prune) {
|
|
2186
|
-
args.push("--prune");
|
|
2187
|
-
}
|
|
2188
|
-
if (opts?.pruneTags) {
|
|
2189
|
-
args.push("--prune-tags");
|
|
2190
|
-
}
|
|
2191
|
-
if (opts?.tags) {
|
|
2192
|
-
args.push("--tags");
|
|
2193
|
-
} else if (opts?.noTags) {
|
|
2194
|
-
args.push("--no-tags");
|
|
2195
|
-
}
|
|
2196
|
-
if (opts?.jobs !== void 0) {
|
|
2197
|
-
args.push(`--jobs=${opts.jobs}`);
|
|
2198
|
-
}
|
|
2199
|
-
if (opts?.prefetch) {
|
|
2200
|
-
args.push("--prefetch");
|
|
2201
|
-
}
|
|
2202
|
-
if (opts?.recurseSubmodules !== void 0) {
|
|
2203
|
-
if (opts.recurseSubmodules === true || opts.recurseSubmodules === "yes") {
|
|
2204
|
-
args.push("--recurse-submodules=yes");
|
|
2205
|
-
} else if (opts.recurseSubmodules === "on-demand") {
|
|
2206
|
-
args.push("--recurse-submodules=on-demand");
|
|
2207
|
-
} else if (opts.recurseSubmodules === "no" || opts.recurseSubmodules === false) {
|
|
2208
|
-
args.push("--recurse-submodules=no");
|
|
2209
|
-
}
|
|
2210
|
-
}
|
|
2211
|
-
if (opts?.dryRun) {
|
|
2212
|
-
args.push("--dry-run");
|
|
2213
|
-
}
|
|
2214
|
-
if (opts?.writeFetchHead === false) {
|
|
2215
|
-
args.push("--no-write-fetch-head");
|
|
2216
|
-
}
|
|
2217
|
-
if (opts?.keep) {
|
|
2218
|
-
args.push("--keep");
|
|
2219
|
-
}
|
|
2220
|
-
if (opts?.updateHeadOk) {
|
|
2221
|
-
args.push("--update-head-ok");
|
|
2222
|
-
}
|
|
2223
|
-
if (opts?.depth !== void 0) {
|
|
2224
|
-
args.push(`--depth=${opts.depth}`);
|
|
2225
|
-
}
|
|
2226
|
-
if (opts?.shallowSince) {
|
|
2227
|
-
const since = opts.shallowSince instanceof Date ? opts.shallowSince.toISOString() : opts.shallowSince;
|
|
2228
|
-
args.push(`--shallow-since=${since}`);
|
|
2229
|
-
}
|
|
2230
|
-
if (opts?.shallowExclude) {
|
|
2231
|
-
const excludes = Array.isArray(opts.shallowExclude) ? opts.shallowExclude : [opts.shallowExclude];
|
|
2232
|
-
for (const exclude of excludes) {
|
|
2233
|
-
args.push(`--shallow-exclude=${exclude}`);
|
|
2234
|
-
}
|
|
2235
|
-
}
|
|
2236
|
-
if (opts?.deepen !== void 0) {
|
|
2237
|
-
args.push(`--deepen=${opts.deepen}`);
|
|
2238
|
-
}
|
|
2239
|
-
if (opts?.unshallow) {
|
|
2240
|
-
args.push("--unshallow");
|
|
2241
|
-
}
|
|
2242
|
-
if (opts?.refetch) {
|
|
2243
|
-
args.push("--refetch");
|
|
2244
|
-
}
|
|
2245
|
-
if (opts?.updateShallow) {
|
|
2246
|
-
args.push("--update-shallow");
|
|
2247
|
-
}
|
|
2248
|
-
if (opts?.refmap) {
|
|
2249
|
-
args.push(`--refmap=${opts.refmap}`);
|
|
2250
|
-
}
|
|
2251
|
-
if (opts?.ipv4) {
|
|
2252
|
-
args.push("--ipv4");
|
|
2253
|
-
}
|
|
2254
|
-
if (opts?.ipv6) {
|
|
2255
|
-
args.push("--ipv6");
|
|
2256
|
-
}
|
|
2257
|
-
if (opts?.filter) {
|
|
2258
|
-
args.push(`--filter=${opts.filter}`);
|
|
2259
|
-
}
|
|
2260
|
-
if (opts?.showForcedUpdates === false) {
|
|
2261
|
-
args.push("--no-show-forced-updates");
|
|
2262
|
-
}
|
|
2263
|
-
if (opts?.writeCommitGraph) {
|
|
2264
|
-
args.push("--write-commit-graph");
|
|
2265
|
-
}
|
|
2266
|
-
if (opts?.remote) {
|
|
2267
|
-
args.push(opts.remote);
|
|
2268
|
-
}
|
|
2269
|
-
if (opts?.refspec) {
|
|
2270
|
-
const refspecs = Array.isArray(opts.refspec) ? opts.refspec : [opts.refspec];
|
|
2271
|
-
args.push(...refspecs);
|
|
2272
|
-
}
|
|
2273
|
-
await this.runner.runOrThrow(this.context, args, {
|
|
2274
|
-
signal: opts?.signal,
|
|
2275
|
-
onProgress: opts?.onProgress
|
|
2276
|
-
});
|
|
2682
|
+
return fetch(this.runner, this.context, opts);
|
|
2277
2683
|
}
|
|
2278
2684
|
/**
|
|
2279
2685
|
* Push to remote
|
|
2280
2686
|
*/
|
|
2281
2687
|
async push(opts) {
|
|
2282
|
-
|
|
2283
|
-
if (opts?.onProgress || opts?.onLfsProgress) {
|
|
2284
|
-
args.push("--progress");
|
|
2285
|
-
}
|
|
2286
|
-
if (opts?.verbose) {
|
|
2287
|
-
args.push("--verbose");
|
|
2288
|
-
}
|
|
2289
|
-
if (opts?.quiet) {
|
|
2290
|
-
args.push("--quiet");
|
|
2291
|
-
}
|
|
2292
|
-
if (opts?.repo) {
|
|
2293
|
-
args.push(`--repo=${opts.repo}`);
|
|
2294
|
-
}
|
|
2295
|
-
if (opts?.all) {
|
|
2296
|
-
args.push("--all");
|
|
2297
|
-
} else if (opts?.branches) {
|
|
2298
|
-
args.push("--branches");
|
|
2299
|
-
}
|
|
2300
|
-
if (opts?.mirror) {
|
|
2301
|
-
args.push("--mirror");
|
|
2302
|
-
}
|
|
2303
|
-
if (opts?.deleteRefs) {
|
|
2304
|
-
args.push("--delete");
|
|
2305
|
-
}
|
|
2306
|
-
if (opts?.force) {
|
|
2307
|
-
args.push("--force");
|
|
2308
|
-
} else if (opts?.forceWithLease !== void 0 && opts.forceWithLease !== false) {
|
|
2309
|
-
if (opts.forceWithLease === true) {
|
|
2310
|
-
args.push("--force-with-lease");
|
|
2311
|
-
} else {
|
|
2312
|
-
const leaseOpts = opts.forceWithLease;
|
|
2313
|
-
if (leaseOpts.expect !== void 0) {
|
|
2314
|
-
args.push(`--force-with-lease=${leaseOpts.refname}:${leaseOpts.expect}`);
|
|
2315
|
-
} else {
|
|
2316
|
-
args.push(`--force-with-lease=${leaseOpts.refname}`);
|
|
2317
|
-
}
|
|
2318
|
-
}
|
|
2319
|
-
}
|
|
2320
|
-
if (opts?.forceIfIncludes) {
|
|
2321
|
-
args.push("--force-if-includes");
|
|
2322
|
-
}
|
|
2323
|
-
if (opts?.dryRun) {
|
|
2324
|
-
args.push("--dry-run");
|
|
2325
|
-
}
|
|
2326
|
-
if (opts?.recurseSubmodules) {
|
|
2327
|
-
args.push(`--recurse-submodules=${opts.recurseSubmodules}`);
|
|
2328
|
-
}
|
|
2329
|
-
if (opts?.thin === false) {
|
|
2330
|
-
args.push("--no-thin");
|
|
2331
|
-
}
|
|
2332
|
-
if (opts?.prune) {
|
|
2333
|
-
args.push("--prune");
|
|
2334
|
-
}
|
|
2335
|
-
if (opts?.tags) {
|
|
2336
|
-
args.push("--tags");
|
|
2337
|
-
}
|
|
2338
|
-
if (opts?.followTags) {
|
|
2339
|
-
args.push("--follow-tags");
|
|
2340
|
-
}
|
|
2341
|
-
if (opts?.atomic) {
|
|
2342
|
-
args.push("--atomic");
|
|
2343
|
-
}
|
|
2344
|
-
if (opts?.pushOption) {
|
|
2345
|
-
const pushOptions = Array.isArray(opts.pushOption) ? opts.pushOption : [opts.pushOption];
|
|
2346
|
-
for (const opt of pushOptions) {
|
|
2347
|
-
args.push("--push-option", opt);
|
|
2348
|
-
}
|
|
2349
|
-
}
|
|
2350
|
-
if (opts?.setUpstream) {
|
|
2351
|
-
args.push("--set-upstream");
|
|
2352
|
-
}
|
|
2353
|
-
if (opts?.noVerify) {
|
|
2354
|
-
args.push("--no-verify");
|
|
2355
|
-
}
|
|
2356
|
-
if (opts?.signed !== void 0) {
|
|
2357
|
-
if (opts.signed === true) {
|
|
2358
|
-
args.push("--signed");
|
|
2359
|
-
} else if (opts.signed === "if-asked") {
|
|
2360
|
-
args.push("--signed=if-asked");
|
|
2361
|
-
}
|
|
2362
|
-
}
|
|
2363
|
-
if (opts?.ipv4) {
|
|
2364
|
-
args.push("--ipv4");
|
|
2365
|
-
}
|
|
2366
|
-
if (opts?.ipv6) {
|
|
2367
|
-
args.push("--ipv6");
|
|
2368
|
-
}
|
|
2369
|
-
if (opts?.remote) {
|
|
2370
|
-
args.push(opts.remote);
|
|
2371
|
-
}
|
|
2372
|
-
if (opts?.refspec) {
|
|
2373
|
-
const refspecs = Array.isArray(opts.refspec) ? opts.refspec : [opts.refspec];
|
|
2374
|
-
args.push(...refspecs);
|
|
2375
|
-
}
|
|
2376
|
-
await this.runner.runOrThrow(this.context, args, {
|
|
2377
|
-
signal: opts?.signal,
|
|
2378
|
-
onProgress: opts?.onProgress,
|
|
2379
|
-
onLfsProgress: opts?.onLfsProgress
|
|
2380
|
-
});
|
|
2688
|
+
return push(this.runner, this.context, opts);
|
|
2381
2689
|
}
|
|
2382
2690
|
/**
|
|
2383
2691
|
* Configure LFS mode for this repository
|
|
@@ -2412,6 +2720,7 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
2412
2720
|
// LFS Operations
|
|
2413
2721
|
// ==========================================================================
|
|
2414
2722
|
async lfsPull(opts) {
|
|
2723
|
+
validateOptions("lfsPull", opts);
|
|
2415
2724
|
if (this._lfsMode === "disabled") {
|
|
2416
2725
|
return;
|
|
2417
2726
|
}
|
|
@@ -2419,13 +2728,10 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
2419
2728
|
if (opts?.remote) {
|
|
2420
2729
|
args.push(opts.remote);
|
|
2421
2730
|
}
|
|
2422
|
-
if (opts?.
|
|
2423
|
-
args.push(opts.ref);
|
|
2424
|
-
}
|
|
2425
|
-
if (opts?.include && opts.include.length > 0) {
|
|
2731
|
+
if (opts?.include !== void 0) {
|
|
2426
2732
|
args.push("--include", opts.include.join(","));
|
|
2427
2733
|
}
|
|
2428
|
-
if (opts?.exclude
|
|
2734
|
+
if (opts?.exclude !== void 0) {
|
|
2429
2735
|
args.push("--exclude", opts.exclude.join(","));
|
|
2430
2736
|
}
|
|
2431
2737
|
await this.runner.runOrThrow(this.context, args, {
|
|
@@ -2435,6 +2741,7 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
2435
2741
|
});
|
|
2436
2742
|
}
|
|
2437
2743
|
async lfsPush(opts) {
|
|
2744
|
+
validateOptions("lfsPush", opts);
|
|
2438
2745
|
if (this._lfsMode === "disabled") {
|
|
2439
2746
|
return;
|
|
2440
2747
|
}
|
|
@@ -2468,33 +2775,9 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
2468
2775
|
});
|
|
2469
2776
|
}
|
|
2470
2777
|
async lfsStatus(opts) {
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
}
|
|
2475
|
-
if (opts?.porcelain) {
|
|
2476
|
-
args.push("--porcelain");
|
|
2477
|
-
}
|
|
2478
|
-
const result = await this.runner.runOrThrow(this.context, args, {
|
|
2479
|
-
signal: opts?.signal
|
|
2480
|
-
});
|
|
2481
|
-
const files = [];
|
|
2482
|
-
if (opts?.json) {
|
|
2483
|
-
try {
|
|
2484
|
-
const json = JSON.parse(result.stdout);
|
|
2485
|
-
if (json.files) {
|
|
2486
|
-
for (const [name, info] of Object.entries(json.files)) {
|
|
2487
|
-
files.push({
|
|
2488
|
-
name,
|
|
2489
|
-
size: info.size ?? 0,
|
|
2490
|
-
status: "unknown"
|
|
2491
|
-
});
|
|
2492
|
-
}
|
|
2493
|
-
}
|
|
2494
|
-
} catch {
|
|
2495
|
-
}
|
|
2496
|
-
}
|
|
2497
|
-
return { files };
|
|
2778
|
+
validateOptions("lfsStatus", opts);
|
|
2779
|
+
const result = await this.runner.runOrThrow(this.context, ["lfs", "status", "--json"], opts);
|
|
2780
|
+
return parseLfsStatusJson(result.stdout);
|
|
2498
2781
|
}
|
|
2499
2782
|
/**
|
|
2500
2783
|
* Pre-upload LFS objects before commit/push (2-phase commit pattern)
|
|
@@ -2722,12 +3005,19 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
2722
3005
|
});
|
|
2723
3006
|
}
|
|
2724
3007
|
async lfsFetch(opts) {
|
|
3008
|
+
validateOptions("lfsFetch", opts);
|
|
2725
3009
|
if (this._lfsMode === "disabled") {
|
|
2726
3010
|
return;
|
|
2727
3011
|
}
|
|
2728
3012
|
const args = ["lfs", "fetch"];
|
|
2729
|
-
if (opts?.
|
|
2730
|
-
args.push("--
|
|
3013
|
+
if (opts?.dryRun) {
|
|
3014
|
+
args.push("--dry-run");
|
|
3015
|
+
}
|
|
3016
|
+
if (opts?.refetch) {
|
|
3017
|
+
args.push("--refetch");
|
|
3018
|
+
}
|
|
3019
|
+
if (opts?.json) {
|
|
3020
|
+
args.push("--json");
|
|
2731
3021
|
}
|
|
2732
3022
|
if (opts?.all) {
|
|
2733
3023
|
args.push("--all");
|
|
@@ -2740,18 +3030,14 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
2740
3030
|
}
|
|
2741
3031
|
if (opts?.include) {
|
|
2742
3032
|
const patterns = Array.isArray(opts.include) ? opts.include : [opts.include];
|
|
2743
|
-
|
|
2744
|
-
args.push("--include", pattern);
|
|
2745
|
-
}
|
|
3033
|
+
args.push("--include", patterns.join(","));
|
|
2746
3034
|
}
|
|
2747
3035
|
if (opts?.exclude) {
|
|
2748
3036
|
const patterns = Array.isArray(opts.exclude) ? opts.exclude : [opts.exclude];
|
|
2749
|
-
|
|
2750
|
-
args.push("--exclude", pattern);
|
|
2751
|
-
}
|
|
3037
|
+
args.push("--exclude", patterns.join(","));
|
|
2752
3038
|
}
|
|
2753
|
-
if (opts?.remote) {
|
|
2754
|
-
args.push(opts.remote);
|
|
3039
|
+
if (opts?.remote || opts?.refs) {
|
|
3040
|
+
args.push(opts.remote ?? "origin");
|
|
2755
3041
|
}
|
|
2756
3042
|
if (opts?.refs) {
|
|
2757
3043
|
const refList = Array.isArray(opts.refs) ? opts.refs : [opts.refs];
|
|
@@ -2792,19 +3078,17 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
2792
3078
|
});
|
|
2793
3079
|
}
|
|
2794
3080
|
async lfsLsFiles(opts) {
|
|
3081
|
+
validateOptions("lfsLsFiles", opts);
|
|
2795
3082
|
if (this._lfsMode === "disabled") {
|
|
2796
3083
|
return [];
|
|
2797
3084
|
}
|
|
2798
|
-
const args = ["lfs", "ls-files"];
|
|
3085
|
+
const args = ["lfs", "ls-files", "--json"];
|
|
2799
3086
|
if (opts?.long) {
|
|
2800
3087
|
args.push("--long");
|
|
2801
3088
|
}
|
|
2802
3089
|
if (opts?.size) {
|
|
2803
3090
|
args.push("--size");
|
|
2804
3091
|
}
|
|
2805
|
-
if (opts?.debug) {
|
|
2806
|
-
args.push("--debug");
|
|
2807
|
-
}
|
|
2808
3092
|
if (opts?.all) {
|
|
2809
3093
|
args.push("--all");
|
|
2810
3094
|
}
|
|
@@ -2813,15 +3097,11 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
2813
3097
|
}
|
|
2814
3098
|
if (opts?.include) {
|
|
2815
3099
|
const patterns = Array.isArray(opts.include) ? opts.include : [opts.include];
|
|
2816
|
-
|
|
2817
|
-
args.push("--include", pattern);
|
|
2818
|
-
}
|
|
3100
|
+
args.push("--include", patterns.join(","));
|
|
2819
3101
|
}
|
|
2820
3102
|
if (opts?.exclude) {
|
|
2821
3103
|
const patterns = Array.isArray(opts.exclude) ? opts.exclude : [opts.exclude];
|
|
2822
|
-
|
|
2823
|
-
args.push("--exclude", pattern);
|
|
2824
|
-
}
|
|
3104
|
+
args.push("--exclude", patterns.join(","));
|
|
2825
3105
|
}
|
|
2826
3106
|
if (opts?.ref) {
|
|
2827
3107
|
args.push(opts.ref);
|
|
@@ -2829,19 +3109,7 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
2829
3109
|
const result = await this.runner.runOrThrow(this.context, args, {
|
|
2830
3110
|
signal: opts?.signal
|
|
2831
3111
|
});
|
|
2832
|
-
|
|
2833
|
-
for (const line of parseLines(result.stdout)) {
|
|
2834
|
-
const match = line.match(/^([0-9a-f]+)\s+([-*])\s+(.+?)(?:\s+\((\d+)\s*(?:B|bytes)?\))?$/);
|
|
2835
|
-
if (match) {
|
|
2836
|
-
entries.push({
|
|
2837
|
-
oid: match[1],
|
|
2838
|
-
path: match[3],
|
|
2839
|
-
size: match[4] ? Number.parseInt(match[4], 10) : void 0,
|
|
2840
|
-
status: match[2] === "*" ? "checked-out" : "not-checked-out"
|
|
2841
|
-
});
|
|
2842
|
-
}
|
|
2843
|
-
}
|
|
2844
|
-
return entries;
|
|
3112
|
+
return parseLfsFilesJson(result.stdout);
|
|
2845
3113
|
}
|
|
2846
3114
|
async lfsTrack(patterns, opts) {
|
|
2847
3115
|
const args = ["lfs", "track"];
|
|
@@ -2906,12 +3174,12 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
2906
3174
|
const result = await this.runner.runOrThrow(this.context, args, {
|
|
2907
3175
|
signal: opts?.signal
|
|
2908
3176
|
});
|
|
2909
|
-
const
|
|
3177
|
+
const data2 = JSON.parse(result.stdout);
|
|
2910
3178
|
return {
|
|
2911
|
-
id:
|
|
2912
|
-
path:
|
|
2913
|
-
owner: { name:
|
|
2914
|
-
lockedAt: new Date(
|
|
3179
|
+
id: data2.id,
|
|
3180
|
+
path: data2.path,
|
|
3181
|
+
owner: { name: data2.owner.name },
|
|
3182
|
+
lockedAt: new Date(data2.locked_at)
|
|
2915
3183
|
};
|
|
2916
3184
|
}
|
|
2917
3185
|
async lfsUnlock(pathOrId, opts) {
|
|
@@ -2959,8 +3227,8 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
2959
3227
|
const result = await this.runner.runOrThrow(this.context, args, {
|
|
2960
3228
|
signal: opts?.signal
|
|
2961
3229
|
});
|
|
2962
|
-
const
|
|
2963
|
-
return
|
|
3230
|
+
const data2 = JSON.parse(result.stdout);
|
|
3231
|
+
return data2.map((lock) => ({
|
|
2964
3232
|
id: lock.id,
|
|
2965
3233
|
path: lock.path,
|
|
2966
3234
|
owner: { name: lock.owner.name },
|
|
@@ -3177,6 +3445,7 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
3177
3445
|
return parseWorktreeList(result.stdout);
|
|
3178
3446
|
}
|
|
3179
3447
|
async worktreeAdd(path, opts) {
|
|
3448
|
+
validateOptions("worktreeAdd", opts);
|
|
3180
3449
|
const args = ["worktree", "add"];
|
|
3181
3450
|
if (opts?.detach) {
|
|
3182
3451
|
args.push("--detach");
|
|
@@ -3272,10 +3541,9 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
3272
3541
|
signal: opts?.signal
|
|
3273
3542
|
});
|
|
3274
3543
|
}
|
|
3275
|
-
// ==========================================================================
|
|
3276
|
-
// High-level API - add
|
|
3277
|
-
// ==========================================================================
|
|
3278
3544
|
async add(paths, opts) {
|
|
3545
|
+
validatePathInput("add", paths, opts);
|
|
3546
|
+
validateOptions("add", opts);
|
|
3279
3547
|
const args = ["add"];
|
|
3280
3548
|
if (opts?.verbose) {
|
|
3281
3549
|
args.push("--verbose");
|
|
@@ -3391,12 +3659,12 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
3391
3659
|
return branches;
|
|
3392
3660
|
}
|
|
3393
3661
|
async branchCurrent(opts) {
|
|
3394
|
-
const
|
|
3395
|
-
|
|
3396
|
-
|
|
3397
|
-
if (result.exitCode !== 0) {
|
|
3662
|
+
const args = ["symbolic-ref", "--quiet", "--short", "HEAD"];
|
|
3663
|
+
const result = await this.runner.run(this.context, args, opts);
|
|
3664
|
+
if (result.exitCode === 1 && !result.aborted) {
|
|
3398
3665
|
return null;
|
|
3399
3666
|
}
|
|
3667
|
+
this.runner.checkResult(this.context, args, result);
|
|
3400
3668
|
return result.stdout.trim();
|
|
3401
3669
|
}
|
|
3402
3670
|
async branchCreate(name, opts) {
|
|
@@ -3446,9 +3714,11 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
3446
3714
|
}
|
|
3447
3715
|
// Implementation
|
|
3448
3716
|
async checkout(targetOrPaths, opts) {
|
|
3717
|
+
validateOptions(Array.isArray(targetOrPaths) ? "checkoutPath" : "checkoutBranch", opts);
|
|
3449
3718
|
const args = ["checkout"];
|
|
3450
3719
|
const isPathMode = Array.isArray(targetOrPaths);
|
|
3451
3720
|
if (isPathMode) {
|
|
3721
|
+
validatePathInput("checkout", targetOrPaths, opts);
|
|
3452
3722
|
const pathOpts = opts;
|
|
3453
3723
|
if (pathOpts?.force) {
|
|
3454
3724
|
args.push("--force");
|
|
@@ -3530,6 +3800,7 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
3530
3800
|
// High-level API - commit
|
|
3531
3801
|
// ==========================================================================
|
|
3532
3802
|
async commit(opts) {
|
|
3803
|
+
validateOptions("commit", opts);
|
|
3533
3804
|
const args = ["commit"];
|
|
3534
3805
|
if (opts?.message) {
|
|
3535
3806
|
args.push("-m", opts.message);
|
|
@@ -3550,9 +3821,6 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
3550
3821
|
const date = opts.date instanceof Date ? opts.date.toISOString() : opts.date;
|
|
3551
3822
|
args.push("--date", date);
|
|
3552
3823
|
}
|
|
3553
|
-
if (opts?.dryRun) {
|
|
3554
|
-
args.push("--dry-run");
|
|
3555
|
-
}
|
|
3556
3824
|
if (opts?.noVerify) {
|
|
3557
3825
|
args.push("--no-verify");
|
|
3558
3826
|
}
|
|
@@ -3570,9 +3838,6 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
3570
3838
|
if (opts?.file) {
|
|
3571
3839
|
args.push("--file", opts.file);
|
|
3572
3840
|
}
|
|
3573
|
-
if (opts?.reeditMessage) {
|
|
3574
|
-
args.push("--reedit-message", opts.reeditMessage);
|
|
3575
|
-
}
|
|
3576
3841
|
if (opts?.reuseMessage) {
|
|
3577
3842
|
args.push("--reuse-message", opts.reuseMessage);
|
|
3578
3843
|
}
|
|
@@ -3615,10 +3880,9 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
3615
3880
|
if (opts?.allowEmptyMessage) {
|
|
3616
3881
|
args.push("--allow-empty-message");
|
|
3617
3882
|
}
|
|
3618
|
-
|
|
3883
|
+
await this.runner.runOrThrow(this.context, args, {
|
|
3619
3884
|
signal: opts?.signal
|
|
3620
3885
|
});
|
|
3621
|
-
const output = result.stdout;
|
|
3622
3886
|
let hash = "";
|
|
3623
3887
|
let branch = "";
|
|
3624
3888
|
let summary = "";
|
|
@@ -3629,17 +3893,29 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
3629
3893
|
signal: opts?.signal
|
|
3630
3894
|
});
|
|
3631
3895
|
hash = hashResult.stdout.trim();
|
|
3632
|
-
|
|
3633
|
-
|
|
3634
|
-
|
|
3635
|
-
|
|
3636
|
-
|
|
3637
|
-
/(\d+) files? changed(?:, (\d+) insertions?\(\+\))?(?:, (\d+) deletions?\(-\))?/
|
|
3896
|
+
branch = await this.branchCurrent(opts) ?? "HEAD";
|
|
3897
|
+
const stats = await this.runner.runOrThrow(
|
|
3898
|
+
this.context,
|
|
3899
|
+
["diff-tree", "--root", "--no-commit-id", "--numstat", "-r", "-z", "-M", hash],
|
|
3900
|
+
opts
|
|
3638
3901
|
);
|
|
3639
|
-
|
|
3640
|
-
|
|
3641
|
-
|
|
3642
|
-
|
|
3902
|
+
const records = parseRecords(stats.stdout);
|
|
3903
|
+
for (let i = 0; i < records.length; i++) {
|
|
3904
|
+
const record2 = records[i];
|
|
3905
|
+
const match = record2.match(/^(\d+|-)\t(\d+|-)\t([\s\S]*)$/);
|
|
3906
|
+
if (!match) {
|
|
3907
|
+
throw new GitError("ParseError", "Invalid commit numstat record");
|
|
3908
|
+
}
|
|
3909
|
+
filesChanged++;
|
|
3910
|
+
if (match[1] !== "-") {
|
|
3911
|
+
insertions += Number(match[1]);
|
|
3912
|
+
}
|
|
3913
|
+
if (match[2] !== "-") {
|
|
3914
|
+
deletions += Number(match[2]);
|
|
3915
|
+
}
|
|
3916
|
+
if (match[3] === "") {
|
|
3917
|
+
i += 2;
|
|
3918
|
+
}
|
|
3643
3919
|
}
|
|
3644
3920
|
const logResult = await this.runner.runOrThrow(this.context, ["log", "-1", "--format=%s"], {
|
|
3645
3921
|
signal: opts?.signal
|
|
@@ -3654,11 +3930,12 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
3654
3930
|
deletions
|
|
3655
3931
|
};
|
|
3656
3932
|
}
|
|
3657
|
-
// ==========================================================================
|
|
3658
|
-
// High-level API - diff
|
|
3659
|
-
// ==========================================================================
|
|
3660
3933
|
async diff(target, opts) {
|
|
3661
|
-
|
|
3934
|
+
validateOptions("diff", opts);
|
|
3935
|
+
const args = ["diff", "--no-ext-diff", "--no-textconv", "--no-color"];
|
|
3936
|
+
if (opts?.nameOnly || opts?.nameStatus) {
|
|
3937
|
+
args.push("-z");
|
|
3938
|
+
}
|
|
3662
3939
|
if (opts?.staged) {
|
|
3663
3940
|
args.push("--staged");
|
|
3664
3941
|
}
|
|
@@ -3736,10 +4013,7 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
3736
4013
|
args.push("--text");
|
|
3737
4014
|
}
|
|
3738
4015
|
if (opts?.mergeBase) {
|
|
3739
|
-
args.push(
|
|
3740
|
-
}
|
|
3741
|
-
if (opts?.noIndex) {
|
|
3742
|
-
args.push("--no-index");
|
|
4016
|
+
args.push("--merge-base");
|
|
3743
4017
|
}
|
|
3744
4018
|
if (opts?.wordDiff) {
|
|
3745
4019
|
args.push(`--word-diff=${opts.wordDiff}`);
|
|
@@ -3753,30 +4027,28 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
3753
4027
|
const result = await this.runner.runOrThrow(this.context, args, {
|
|
3754
4028
|
signal: opts?.signal
|
|
3755
4029
|
});
|
|
4030
|
+
if (opts?.nameOnly) {
|
|
4031
|
+
return parseRecords(result.stdout);
|
|
4032
|
+
}
|
|
3756
4033
|
if (opts?.nameStatus) {
|
|
4034
|
+
const records = parseRecords(result.stdout);
|
|
3757
4035
|
const files = [];
|
|
3758
|
-
for (
|
|
3759
|
-
const
|
|
3760
|
-
|
|
3761
|
-
|
|
3762
|
-
const newPath = match?.[3];
|
|
3763
|
-
if (status !== void 0 && pathOrOld !== void 0) {
|
|
3764
|
-
const entry = {
|
|
3765
|
-
status,
|
|
3766
|
-
path: newPath ?? pathOrOld
|
|
3767
|
-
};
|
|
3768
|
-
if (newPath !== void 0) {
|
|
3769
|
-
entry.oldPath = pathOrOld;
|
|
3770
|
-
}
|
|
3771
|
-
files.push(entry);
|
|
4036
|
+
for (let i = 0; i < records.length; ) {
|
|
4037
|
+
const code = records[i++];
|
|
4038
|
+
if (!/^[AMDRTCUXB][0-9]*$/.test(code)) {
|
|
4039
|
+
throw new GitError("ParseError", "Invalid diff status");
|
|
3772
4040
|
}
|
|
3773
|
-
|
|
3774
|
-
|
|
3775
|
-
|
|
3776
|
-
|
|
3777
|
-
|
|
3778
|
-
|
|
3779
|
-
files.push({
|
|
4041
|
+
const oldPath = records[i++];
|
|
4042
|
+
const renamed = code[0] === "R" || code[0] === "C";
|
|
4043
|
+
const path = renamed ? records[i++] : oldPath;
|
|
4044
|
+
if (oldPath === void 0 || path === void 0) {
|
|
4045
|
+
throw new GitError("ParseError", "Missing diff path");
|
|
4046
|
+
}
|
|
4047
|
+
files.push({
|
|
4048
|
+
status: code[0],
|
|
4049
|
+
path,
|
|
4050
|
+
...renamed ? { oldPath, similarity: Number(code.slice(1)) } : {}
|
|
4051
|
+
});
|
|
3780
4052
|
}
|
|
3781
4053
|
return { files };
|
|
3782
4054
|
}
|
|
@@ -3786,6 +4058,7 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
3786
4058
|
// High-level API - merge
|
|
3787
4059
|
// ==========================================================================
|
|
3788
4060
|
async merge(branch, opts) {
|
|
4061
|
+
validateOptions("merge", opts);
|
|
3789
4062
|
if (opts?.abort) {
|
|
3790
4063
|
await this.runner.runOrThrow(this.context, ["merge", "--abort"], {
|
|
3791
4064
|
signal: opts?.signal
|
|
@@ -3799,6 +4072,10 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
3799
4072
|
const hash = (await this.runner.runOrThrow(this.context, ["rev-parse", "HEAD"])).stdout.trim();
|
|
3800
4073
|
return { success: true, hash };
|
|
3801
4074
|
}
|
|
4075
|
+
if (opts?.quit) {
|
|
4076
|
+
await this.runner.runOrThrow(this.context, ["merge", "--quit"], opts);
|
|
4077
|
+
return { success: true };
|
|
4078
|
+
}
|
|
3802
4079
|
const args = ["merge"];
|
|
3803
4080
|
if (opts?.message) {
|
|
3804
4081
|
args.push("-m", opts.message);
|
|
@@ -3883,17 +4160,20 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
3883
4160
|
signal: opts?.signal,
|
|
3884
4161
|
env: this.lfsModeEnv()
|
|
3885
4162
|
});
|
|
4163
|
+
if (result.aborted) {
|
|
4164
|
+
this.runner.checkResult(this.context, args, result);
|
|
4165
|
+
}
|
|
3886
4166
|
if (result.exitCode !== 0) {
|
|
3887
|
-
const statusResult = await this.runner.runOrThrow(
|
|
3888
|
-
|
|
3889
|
-
|
|
3890
|
-
|
|
3891
|
-
|
|
3892
|
-
).
|
|
3893
|
-
|
|
3894
|
-
|
|
3895
|
-
|
|
3896
|
-
};
|
|
4167
|
+
const statusResult = await this.runner.runOrThrow(
|
|
4168
|
+
this.context,
|
|
4169
|
+
["status", "--porcelain=v2", "-z"],
|
|
4170
|
+
{ signal: opts?.signal }
|
|
4171
|
+
);
|
|
4172
|
+
const conflicts = parsePorcelainV2(statusResult.stdout).filter((entry) => entry.type === "unmerged").map((entry) => entry.path);
|
|
4173
|
+
if (conflicts.length === 0) {
|
|
4174
|
+
this.runner.checkResult(this.context, args, result);
|
|
4175
|
+
}
|
|
4176
|
+
return { success: false, conflicts };
|
|
3897
4177
|
}
|
|
3898
4178
|
const hashResult = await this.runner.runOrThrow(this.context, ["rev-parse", "HEAD"], {
|
|
3899
4179
|
signal: opts?.signal
|
|
@@ -3909,6 +4189,7 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
3909
4189
|
// High-level API - pull
|
|
3910
4190
|
// ==========================================================================
|
|
3911
4191
|
async pull(opts) {
|
|
4192
|
+
validateOptions("pull", opts);
|
|
3912
4193
|
const args = ["pull"];
|
|
3913
4194
|
if (opts?.onProgress || opts?.onLfsProgress) {
|
|
3914
4195
|
args.push("--progress");
|
|
@@ -4094,10 +4375,8 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
4094
4375
|
env: this.lfsModeEnv()
|
|
4095
4376
|
});
|
|
4096
4377
|
}
|
|
4097
|
-
// ==========================================================================
|
|
4098
|
-
// High-level API - rm
|
|
4099
|
-
// ==========================================================================
|
|
4100
4378
|
async rm(paths, opts) {
|
|
4379
|
+
validatePathInput("rm", paths, opts);
|
|
4101
4380
|
const args = ["rm"];
|
|
4102
4381
|
if (opts?.force) {
|
|
4103
4382
|
args.push("--force");
|
|
@@ -4133,38 +4412,29 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
4133
4412
|
// High-level API - Stash Operations
|
|
4134
4413
|
// ==========================================================================
|
|
4135
4414
|
async stashList(opts) {
|
|
4136
|
-
const result = await this.runner.runOrThrow(
|
|
4137
|
-
|
|
4138
|
-
|
|
4139
|
-
|
|
4140
|
-
|
|
4141
|
-
|
|
4142
|
-
|
|
4143
|
-
|
|
4144
|
-
const message = match?.[3];
|
|
4145
|
-
if (indexStr !== void 0 && message !== void 0) {
|
|
4146
|
-
const wipMatch = branchOrContext?.match(/^WIP on (.+)$/);
|
|
4147
|
-
entries.push({
|
|
4148
|
-
index: Number.parseInt(indexStr, 10),
|
|
4149
|
-
message,
|
|
4150
|
-
branch: wipMatch?.[1] ?? branchOrContext,
|
|
4151
|
-
commit: ""
|
|
4152
|
-
// We'd need another command to get the commit hash
|
|
4153
|
-
});
|
|
4154
|
-
}
|
|
4415
|
+
const result = await this.runner.runOrThrow(
|
|
4416
|
+
this.context,
|
|
4417
|
+
["stash", "list", "-z", "--format=%gd%x00%H%x00%gs"],
|
|
4418
|
+
opts
|
|
4419
|
+
);
|
|
4420
|
+
const fields = parseRecords(result.stdout);
|
|
4421
|
+
if (fields.length % 3 !== 0) {
|
|
4422
|
+
throw new GitError("ParseError", "Invalid stash record");
|
|
4155
4423
|
}
|
|
4156
|
-
|
|
4157
|
-
|
|
4158
|
-
|
|
4159
|
-
|
|
4160
|
-
|
|
4161
|
-
["rev-parse", `stash@{${entry.index}}`],
|
|
4162
|
-
{ signal: opts?.signal }
|
|
4163
|
-
);
|
|
4164
|
-
entry.commit = hashResult.stdout.trim();
|
|
4165
|
-
} catch {
|
|
4166
|
-
}
|
|
4424
|
+
const entries = [];
|
|
4425
|
+
for (let i = 0; i < fields.length; i += 3) {
|
|
4426
|
+
const index = fields[i]?.match(/^stash@\{(\d+)\}$/)?.[1];
|
|
4427
|
+
if (index === void 0 || !fields[i + 1]) {
|
|
4428
|
+
throw new GitError("ParseError", "Invalid stash metadata");
|
|
4167
4429
|
}
|
|
4430
|
+
const subject = fields[i + 2];
|
|
4431
|
+
const context = subject.match(/^(?:WIP on|On) (.*?): ([\s\S]*)$/);
|
|
4432
|
+
entries.push({
|
|
4433
|
+
index: Number(index),
|
|
4434
|
+
commit: fields[i + 1],
|
|
4435
|
+
message: context?.[2] ?? subject,
|
|
4436
|
+
...context ? { branch: context[1] } : {}
|
|
4437
|
+
});
|
|
4168
4438
|
}
|
|
4169
4439
|
return entries;
|
|
4170
4440
|
}
|
|
@@ -4240,6 +4510,7 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
4240
4510
|
// High-level API - switch
|
|
4241
4511
|
// ==========================================================================
|
|
4242
4512
|
async switch(branch, opts) {
|
|
4513
|
+
validateOptions("switch", opts);
|
|
4243
4514
|
const args = ["switch"];
|
|
4244
4515
|
if (opts?.create) {
|
|
4245
4516
|
args.push("-c");
|
|
@@ -4439,6 +4710,7 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
4439
4710
|
// Medium Priority - cherry-pick
|
|
4440
4711
|
// ==========================================================================
|
|
4441
4712
|
async cherryPick(commits, opts) {
|
|
4713
|
+
validateOptions("cherryPick", opts);
|
|
4442
4714
|
if (opts?.abort) {
|
|
4443
4715
|
await this.runner.runOrThrow(this.context, ["cherry-pick", "--abort"], {
|
|
4444
4716
|
signal: opts?.signal
|
|
@@ -4473,9 +4745,6 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
4473
4745
|
if (opts?.strategy) {
|
|
4474
4746
|
args.push("-s", opts.strategy);
|
|
4475
4747
|
}
|
|
4476
|
-
if (opts?.noVerify) {
|
|
4477
|
-
args.push("--no-verify");
|
|
4478
|
-
}
|
|
4479
4748
|
if (opts?.cleanup) {
|
|
4480
4749
|
args.push("--cleanup", opts.cleanup);
|
|
4481
4750
|
}
|
|
@@ -4520,6 +4789,7 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
4520
4789
|
// Medium Priority - clean
|
|
4521
4790
|
// ==========================================================================
|
|
4522
4791
|
async clean(opts) {
|
|
4792
|
+
validateOptions("clean", opts);
|
|
4523
4793
|
const args = ["clean"];
|
|
4524
4794
|
if (opts?.force) {
|
|
4525
4795
|
args.push("-f");
|
|
@@ -4589,6 +4859,7 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
4589
4859
|
// Medium Priority - rebase
|
|
4590
4860
|
// ==========================================================================
|
|
4591
4861
|
async rebase(opts) {
|
|
4862
|
+
validateOptions("rebase", opts);
|
|
4592
4863
|
if (opts?.abort) {
|
|
4593
4864
|
await this.runner.runOrThrow(this.context, ["rebase", "--abort"], {
|
|
4594
4865
|
signal: opts?.signal
|
|
@@ -4719,10 +4990,9 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
4719
4990
|
env: this.lfsModeEnv()
|
|
4720
4991
|
});
|
|
4721
4992
|
}
|
|
4722
|
-
// ==========================================================================
|
|
4723
|
-
// Medium Priority - restore
|
|
4724
|
-
// ==========================================================================
|
|
4725
4993
|
async restore(paths, opts) {
|
|
4994
|
+
validatePathInput("restore", paths, opts);
|
|
4995
|
+
validateOptions("restore", opts);
|
|
4726
4996
|
const args = ["restore"];
|
|
4727
4997
|
if (opts?.staged) {
|
|
4728
4998
|
args.push("--staged");
|
|
@@ -4782,6 +5052,7 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
4782
5052
|
// Medium Priority - revert
|
|
4783
5053
|
// ==========================================================================
|
|
4784
5054
|
async revert(commits, opts) {
|
|
5055
|
+
validateOptions("revert", opts);
|
|
4785
5056
|
if (opts?.abort) {
|
|
4786
5057
|
await this.runner.runOrThrow(this.context, ["revert", "--abort"], {
|
|
4787
5058
|
signal: opts?.signal
|
|
@@ -4810,9 +5081,6 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
4810
5081
|
if (opts?.mainline !== void 0) {
|
|
4811
5082
|
args.push("-m", opts.mainline.toString());
|
|
4812
5083
|
}
|
|
4813
|
-
if (opts?.noVerify) {
|
|
4814
|
-
args.push("--no-verify");
|
|
4815
|
-
}
|
|
4816
5084
|
if (opts?.cleanup) {
|
|
4817
5085
|
args.push("--cleanup", opts.cleanup);
|
|
4818
5086
|
}
|
|
@@ -4924,6 +5192,10 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
4924
5192
|
});
|
|
4925
5193
|
return result2.stdout.trim();
|
|
4926
5194
|
}
|
|
5195
|
+
validateRevParseQuery(refOrOpts);
|
|
5196
|
+
if ("pathFormat" in refOrOpts && refOrOpts.pathFormat) {
|
|
5197
|
+
args.push(`--path-format=${refOrOpts.pathFormat}`);
|
|
5198
|
+
}
|
|
4927
5199
|
const queryOpts = refOrOpts;
|
|
4928
5200
|
if ("gitDir" in queryOpts && queryOpts.gitDir) {
|
|
4929
5201
|
args.push("--git-dir");
|
|
@@ -5018,9 +5290,6 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
5018
5290
|
} else if ("localEnvVars" in queryOpts && queryOpts.localEnvVars) {
|
|
5019
5291
|
args.push("--local-env-vars");
|
|
5020
5292
|
}
|
|
5021
|
-
if ("pathFormat" in queryOpts && queryOpts.pathFormat) {
|
|
5022
|
-
args.push(`--path-format=${queryOpts.pathFormat}`);
|
|
5023
|
-
}
|
|
5024
5293
|
const result = await this.runner.runOrThrow(this.context, args, {
|
|
5025
5294
|
signal: queryOpts.signal
|
|
5026
5295
|
});
|
|
@@ -5360,6 +5629,7 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
5360
5629
|
});
|
|
5361
5630
|
}
|
|
5362
5631
|
async remoteSetHead(remote, branch, opts) {
|
|
5632
|
+
validateOptions("remoteSetHead", opts);
|
|
5363
5633
|
const args = ["remote", "set-head"];
|
|
5364
5634
|
if (opts?.auto) {
|
|
5365
5635
|
args.push("--auto");
|
|
@@ -5433,25 +5703,14 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
5433
5703
|
* Get a typed config value
|
|
5434
5704
|
*/
|
|
5435
5705
|
async configGet(key, opts) {
|
|
5436
|
-
const
|
|
5437
|
-
|
|
5438
|
-
|
|
5439
|
-
|
|
5440
|
-
|
|
5441
|
-
|
|
5442
|
-
|
|
5443
|
-
|
|
5444
|
-
/**
|
|
5445
|
-
* Get all values for a typed multi-valued config key
|
|
5446
|
-
*/
|
|
5447
|
-
async configGetAll(key, opts) {
|
|
5448
|
-
const result = await this.runner.run(this.context, ["config", "--get-all", key], {
|
|
5449
|
-
signal: opts?.signal
|
|
5450
|
-
});
|
|
5451
|
-
if (result.exitCode !== 0) {
|
|
5452
|
-
return [];
|
|
5453
|
-
}
|
|
5454
|
-
return parseLines(result.stdout);
|
|
5706
|
+
const values = await readTypedConfig(this.runner, this.context, key, opts);
|
|
5707
|
+
return values.at(-1);
|
|
5708
|
+
}
|
|
5709
|
+
/**
|
|
5710
|
+
* Get all values for a typed multi-valued config key
|
|
5711
|
+
*/
|
|
5712
|
+
async configGetAll(key, opts) {
|
|
5713
|
+
return readTypedConfig(this.runner, this.context, key, opts, true);
|
|
5455
5714
|
}
|
|
5456
5715
|
/**
|
|
5457
5716
|
* Set a typed config value
|
|
@@ -5477,33 +5736,8 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
5477
5736
|
signal: opts?.signal
|
|
5478
5737
|
});
|
|
5479
5738
|
}
|
|
5480
|
-
/**
|
|
5481
|
-
* Get a raw config value (for arbitrary keys)
|
|
5482
|
-
*/
|
|
5483
5739
|
async configGetRaw(key, opts) {
|
|
5484
|
-
|
|
5485
|
-
if (opts?.type) {
|
|
5486
|
-
args.push(`--type=${opts.type}`);
|
|
5487
|
-
}
|
|
5488
|
-
if (opts?.default !== void 0) {
|
|
5489
|
-
args.push("--default", opts.default);
|
|
5490
|
-
}
|
|
5491
|
-
if (opts?.all) {
|
|
5492
|
-
args.push("--get-all");
|
|
5493
|
-
} else {
|
|
5494
|
-
args.push("--get");
|
|
5495
|
-
}
|
|
5496
|
-
args.push(key);
|
|
5497
|
-
const result = await this.runner.run(this.context, args, {
|
|
5498
|
-
signal: opts?.signal
|
|
5499
|
-
});
|
|
5500
|
-
if (result.exitCode !== 0) {
|
|
5501
|
-
return void 0;
|
|
5502
|
-
}
|
|
5503
|
-
if (opts?.all) {
|
|
5504
|
-
return parseLines(result.stdout);
|
|
5505
|
-
}
|
|
5506
|
-
return result.stdout.trim();
|
|
5740
|
+
return readConfig(this.runner, this.context, key, opts);
|
|
5507
5741
|
}
|
|
5508
5742
|
/**
|
|
5509
5743
|
* Set a raw config value (for arbitrary keys)
|
|
@@ -5530,47 +5764,7 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
5530
5764
|
* List all config values
|
|
5531
5765
|
*/
|
|
5532
5766
|
async configList(opts) {
|
|
5533
|
-
|
|
5534
|
-
if (opts?.showOrigin) {
|
|
5535
|
-
args.push("--show-origin");
|
|
5536
|
-
}
|
|
5537
|
-
if (opts?.showScope) {
|
|
5538
|
-
args.push("--show-scope");
|
|
5539
|
-
}
|
|
5540
|
-
if (opts?.includes) {
|
|
5541
|
-
args.push("--includes");
|
|
5542
|
-
}
|
|
5543
|
-
if (opts?.nameOnly) {
|
|
5544
|
-
args.push("--name-only");
|
|
5545
|
-
}
|
|
5546
|
-
const result = await this.runner.runOrThrow(this.context, args, {
|
|
5547
|
-
signal: opts?.signal
|
|
5548
|
-
});
|
|
5549
|
-
const entries = [];
|
|
5550
|
-
for (const line of parseLines(result.stdout)) {
|
|
5551
|
-
let keyValue = line;
|
|
5552
|
-
if (opts?.showOrigin || opts?.showScope) {
|
|
5553
|
-
const tabIndex = line.lastIndexOf(" ");
|
|
5554
|
-
if (tabIndex !== -1) {
|
|
5555
|
-
keyValue = line.slice(tabIndex + 1);
|
|
5556
|
-
}
|
|
5557
|
-
}
|
|
5558
|
-
if (opts?.nameOnly) {
|
|
5559
|
-
entries.push({
|
|
5560
|
-
key: keyValue,
|
|
5561
|
-
value: ""
|
|
5562
|
-
});
|
|
5563
|
-
} else {
|
|
5564
|
-
const eqIndex = keyValue.indexOf("=");
|
|
5565
|
-
if (eqIndex !== -1) {
|
|
5566
|
-
entries.push({
|
|
5567
|
-
key: keyValue.slice(0, eqIndex),
|
|
5568
|
-
value: keyValue.slice(eqIndex + 1)
|
|
5569
|
-
});
|
|
5570
|
-
}
|
|
5571
|
-
}
|
|
5572
|
-
}
|
|
5573
|
-
return entries;
|
|
5767
|
+
return listConfig(this.runner, this.context, opts);
|
|
5574
5768
|
}
|
|
5575
5769
|
async configRenameSection(oldName, newName, opts) {
|
|
5576
5770
|
await this.runner.runOrThrow(this.context, ["config", "--rename-section", oldName, newName], {
|
|
@@ -5787,11 +5981,14 @@ var GitImpl = class {
|
|
|
5787
5981
|
return new WorktreeRepoImpl(repoRunner, path, opts);
|
|
5788
5982
|
}
|
|
5789
5983
|
async clone(url, path, opts) {
|
|
5984
|
+
validateOptions("clone", opts);
|
|
5790
5985
|
const args = buildCloneArgs(opts);
|
|
5791
5986
|
if (opts?.onProgress || opts?.onLfsProgress) {
|
|
5792
5987
|
args.push("--progress");
|
|
5793
5988
|
}
|
|
5794
5989
|
args.push(url, path);
|
|
5990
|
+
const destinationExisted = await this.adapters.fs.exists(path);
|
|
5991
|
+
const alreadyAborted = opts?.signal?.aborted;
|
|
5795
5992
|
try {
|
|
5796
5993
|
await this.runner.runOrThrow({ type: "global" }, args, {
|
|
5797
5994
|
signal: opts?.signal,
|
|
@@ -5799,7 +5996,7 @@ var GitImpl = class {
|
|
|
5799
5996
|
onLfsProgress: opts?.onLfsProgress
|
|
5800
5997
|
});
|
|
5801
5998
|
} catch (error) {
|
|
5802
|
-
if (error instanceof GitError && error.kind === "Aborted" && opts?.cleanupOnAbort !== false) {
|
|
5999
|
+
if (error instanceof GitError && error.kind === "Aborted" && opts?.cleanupOnAbort !== false && !destinationExisted && !alreadyAborted) {
|
|
5803
6000
|
await this.adapters.fs.deleteDirectory(path);
|
|
5804
6001
|
}
|
|
5805
6002
|
throw error;
|
|
@@ -5810,6 +6007,7 @@ var GitImpl = class {
|
|
|
5810
6007
|
return new WorktreeRepoImpl(this.runner, path);
|
|
5811
6008
|
}
|
|
5812
6009
|
async init(path, opts) {
|
|
6010
|
+
validateOptions("init", opts);
|
|
5813
6011
|
const args = ["init"];
|
|
5814
6012
|
if (opts?.quiet) {
|
|
5815
6013
|
args.push("--quiet");
|
|
@@ -5841,6 +6039,8 @@ var GitImpl = class {
|
|
|
5841
6039
|
args.push("--separate-git-dir", opts.separateGitDir);
|
|
5842
6040
|
}
|
|
5843
6041
|
args.push(path);
|
|
6042
|
+
const destinationExisted = await this.adapters.fs.exists(path);
|
|
6043
|
+
const alreadyAborted = opts?.signal?.aborted;
|
|
5844
6044
|
try {
|
|
5845
6045
|
await this.runner.runOrThrow({ type: "global" }, args, {
|
|
5846
6046
|
signal: opts?.signal,
|
|
@@ -5857,7 +6057,7 @@ var GitImpl = class {
|
|
|
5857
6057
|
);
|
|
5858
6058
|
}
|
|
5859
6059
|
} catch (error) {
|
|
5860
|
-
if (error instanceof GitError && error.kind === "Aborted" && opts?.cleanupOnAbort !== false) {
|
|
6060
|
+
if (error instanceof GitError && error.kind === "Aborted" && opts?.cleanupOnAbort !== false && !destinationExisted && !alreadyAborted) {
|
|
5861
6061
|
await this.adapters.fs.deleteDirectory(path);
|
|
5862
6062
|
}
|
|
5863
6063
|
throw error;
|
|
@@ -5871,6 +6071,7 @@ var GitImpl = class {
|
|
|
5871
6071
|
* List references in a remote repository
|
|
5872
6072
|
*/
|
|
5873
6073
|
async lsRemote(url, opts) {
|
|
6074
|
+
validateOptions("lsRemote", opts);
|
|
5874
6075
|
const args = ["ls-remote"];
|
|
5875
6076
|
if (opts?.heads) {
|
|
5876
6077
|
args.push("--heads");
|
|
@@ -5881,15 +6082,9 @@ var GitImpl = class {
|
|
|
5881
6082
|
if (opts?.refs) {
|
|
5882
6083
|
args.push("--refs");
|
|
5883
6084
|
}
|
|
5884
|
-
if (opts?.getUrl) {
|
|
5885
|
-
args.push("--get-url");
|
|
5886
|
-
}
|
|
5887
6085
|
if (opts?.sort) {
|
|
5888
6086
|
args.push("--sort", opts.sort);
|
|
5889
6087
|
}
|
|
5890
|
-
if (opts?.symref) {
|
|
5891
|
-
args.push("--symref");
|
|
5892
|
-
}
|
|
5893
6088
|
args.push(url);
|
|
5894
6089
|
const result = await this.runner.runOrThrow({ type: "global" }, args, {
|
|
5895
6090
|
signal: opts?.signal,
|
|
@@ -5933,27 +6128,14 @@ var GitImpl = class {
|
|
|
5933
6128
|
* Get a typed global config value
|
|
5934
6129
|
*/
|
|
5935
6130
|
async configGet(key, opts) {
|
|
5936
|
-
const
|
|
5937
|
-
|
|
5938
|
-
});
|
|
5939
|
-
if (result.exitCode !== 0) {
|
|
5940
|
-
return void 0;
|
|
5941
|
-
}
|
|
5942
|
-
return result.stdout.trim();
|
|
6131
|
+
const values = await readTypedConfig(this.runner, { type: "global" }, key, opts);
|
|
6132
|
+
return values.at(-1);
|
|
5943
6133
|
}
|
|
5944
6134
|
/**
|
|
5945
6135
|
* Get all values for a typed multi-valued global config key
|
|
5946
6136
|
*/
|
|
5947
6137
|
async configGetAll(key, opts) {
|
|
5948
|
-
|
|
5949
|
-
{ type: "global" },
|
|
5950
|
-
["config", "--global", "--get-all", key],
|
|
5951
|
-
{ signal: opts?.signal }
|
|
5952
|
-
);
|
|
5953
|
-
if (result.exitCode !== 0) {
|
|
5954
|
-
return [];
|
|
5955
|
-
}
|
|
5956
|
-
return parseLines(result.stdout);
|
|
6138
|
+
return readTypedConfig(this.runner, { type: "global" }, key, opts, true);
|
|
5957
6139
|
}
|
|
5958
6140
|
/**
|
|
5959
6141
|
* Set a typed global config value
|
|
@@ -5981,27 +6163,8 @@ var GitImpl = class {
|
|
|
5981
6163
|
signal: opts?.signal
|
|
5982
6164
|
});
|
|
5983
6165
|
}
|
|
5984
|
-
/**
|
|
5985
|
-
* Get a raw global config value (for arbitrary keys)
|
|
5986
|
-
*/
|
|
5987
6166
|
async configGetRaw(key, opts) {
|
|
5988
|
-
|
|
5989
|
-
if (opts?.all) {
|
|
5990
|
-
args.push("--get-all");
|
|
5991
|
-
} else {
|
|
5992
|
-
args.push("--get");
|
|
5993
|
-
}
|
|
5994
|
-
args.push(key);
|
|
5995
|
-
const result = await this.runner.run({ type: "global" }, args, {
|
|
5996
|
-
signal: opts?.signal
|
|
5997
|
-
});
|
|
5998
|
-
if (result.exitCode !== 0) {
|
|
5999
|
-
return void 0;
|
|
6000
|
-
}
|
|
6001
|
-
if (opts?.all) {
|
|
6002
|
-
return parseLines(result.stdout);
|
|
6003
|
-
}
|
|
6004
|
-
return result.stdout.trim();
|
|
6167
|
+
return readConfig(this.runner, { type: "global" }, key, opts);
|
|
6005
6168
|
}
|
|
6006
6169
|
/**
|
|
6007
6170
|
* Set a raw global config value (for arbitrary keys)
|
|
@@ -6028,34 +6191,7 @@ var GitImpl = class {
|
|
|
6028
6191
|
* List all global config values
|
|
6029
6192
|
*/
|
|
6030
6193
|
async configList(opts) {
|
|
6031
|
-
|
|
6032
|
-
if (opts?.showOrigin) {
|
|
6033
|
-
args.push("--show-origin");
|
|
6034
|
-
}
|
|
6035
|
-
if (opts?.showScope) {
|
|
6036
|
-
args.push("--show-scope");
|
|
6037
|
-
}
|
|
6038
|
-
const result = await this.runner.runOrThrow({ type: "global" }, args, {
|
|
6039
|
-
signal: opts?.signal
|
|
6040
|
-
});
|
|
6041
|
-
const entries = [];
|
|
6042
|
-
for (const line of parseLines(result.stdout)) {
|
|
6043
|
-
let keyValue = line;
|
|
6044
|
-
if (opts?.showOrigin || opts?.showScope) {
|
|
6045
|
-
const tabIndex = line.lastIndexOf(" ");
|
|
6046
|
-
if (tabIndex !== -1) {
|
|
6047
|
-
keyValue = line.slice(tabIndex + 1);
|
|
6048
|
-
}
|
|
6049
|
-
}
|
|
6050
|
-
const eqIndex = keyValue.indexOf("=");
|
|
6051
|
-
if (eqIndex !== -1) {
|
|
6052
|
-
entries.push({
|
|
6053
|
-
key: keyValue.slice(0, eqIndex),
|
|
6054
|
-
value: keyValue.slice(eqIndex + 1)
|
|
6055
|
-
});
|
|
6056
|
-
}
|
|
6057
|
-
}
|
|
6058
|
-
return entries;
|
|
6194
|
+
return listConfig(this.runner, { type: "global" }, opts);
|
|
6059
6195
|
}
|
|
6060
6196
|
// ==========================================================================
|
|
6061
6197
|
// Global LFS Operations
|
|
@@ -6128,6 +6264,89 @@ async function createGit(options) {
|
|
|
6128
6264
|
return git;
|
|
6129
6265
|
}
|
|
6130
6266
|
|
|
6267
|
+
// src/internal/client.ts
|
|
6268
|
+
var GitClient = class {
|
|
6269
|
+
constructor(git) {
|
|
6270
|
+
this.git = git;
|
|
6271
|
+
}
|
|
6272
|
+
get open() {
|
|
6273
|
+
return this.git.open.bind(this.git);
|
|
6274
|
+
}
|
|
6275
|
+
/**
|
|
6276
|
+
* Open an existing bare repository
|
|
6277
|
+
*
|
|
6278
|
+
* Throws GitError if the repository is not bare.
|
|
6279
|
+
*
|
|
6280
|
+
* @throws GitError with kind 'NotBareRepo' if the repository is not bare
|
|
6281
|
+
*/
|
|
6282
|
+
get openBare() {
|
|
6283
|
+
return this.git.openBare.bind(this.git);
|
|
6284
|
+
}
|
|
6285
|
+
/**
|
|
6286
|
+
* Open an existing repository without type guarantee
|
|
6287
|
+
*
|
|
6288
|
+
* Returns either WorktreeRepo or BareRepo depending on the repository type.
|
|
6289
|
+
* Use this when you don't know the repository type at compile time.
|
|
6290
|
+
*/
|
|
6291
|
+
get openRaw() {
|
|
6292
|
+
return this.git.openRaw.bind(this.git);
|
|
6293
|
+
}
|
|
6294
|
+
clone(url, path, opts) {
|
|
6295
|
+
return this.git.clone(url, path, opts);
|
|
6296
|
+
}
|
|
6297
|
+
init(path, opts) {
|
|
6298
|
+
return this.git.init(path, opts);
|
|
6299
|
+
}
|
|
6300
|
+
/**
|
|
6301
|
+
* List references in a remote repository
|
|
6302
|
+
*/
|
|
6303
|
+
get lsRemote() {
|
|
6304
|
+
return this.git.lsRemote.bind(this.git);
|
|
6305
|
+
}
|
|
6306
|
+
/**
|
|
6307
|
+
* Get git version
|
|
6308
|
+
*/
|
|
6309
|
+
get version() {
|
|
6310
|
+
return this.git.version.bind(this.git);
|
|
6311
|
+
}
|
|
6312
|
+
/**
|
|
6313
|
+
* Execute a raw git command (repository-agnostic)
|
|
6314
|
+
*/
|
|
6315
|
+
get raw() {
|
|
6316
|
+
return this.git.raw.bind(this.git);
|
|
6317
|
+
}
|
|
6318
|
+
/**
|
|
6319
|
+
* Global config operations
|
|
6320
|
+
*
|
|
6321
|
+
* Operates on ~/.gitconfig (user-level configuration).
|
|
6322
|
+
* For repository-level config, use repo.config instead.
|
|
6323
|
+
*/
|
|
6324
|
+
get config() {
|
|
6325
|
+
return this.git.config;
|
|
6326
|
+
}
|
|
6327
|
+
/**
|
|
6328
|
+
* Global LFS operations
|
|
6329
|
+
*
|
|
6330
|
+
* Operates on ~/.gitconfig (user-level) or /etc/gitconfig (system-level).
|
|
6331
|
+
* For repository-level LFS operations, use repo.lfs instead.
|
|
6332
|
+
*
|
|
6333
|
+
* @example
|
|
6334
|
+
* ```typescript
|
|
6335
|
+
* // Install LFS globally
|
|
6336
|
+
* await git.lfs.install();
|
|
6337
|
+
*
|
|
6338
|
+
* // Install system-wide
|
|
6339
|
+
* await git.lfs.install({ system: true });
|
|
6340
|
+
*
|
|
6341
|
+
* // Get LFS version
|
|
6342
|
+
* const version = await git.lfs.version();
|
|
6343
|
+
* ```
|
|
6344
|
+
*/
|
|
6345
|
+
get lfs() {
|
|
6346
|
+
return this.git.lfs;
|
|
6347
|
+
}
|
|
6348
|
+
};
|
|
6349
|
+
|
|
6131
6350
|
// src/adapters/node/exec.ts
|
|
6132
6351
|
var import_node_child_process = require("child_process");
|
|
6133
6352
|
function resolveChildEnv(env, inheritEnv) {
|
|
@@ -6139,7 +6358,7 @@ function resolveChildEnv(env, inheritEnv) {
|
|
|
6139
6358
|
async function* streamToAsyncIterable(stream) {
|
|
6140
6359
|
let buffer = "";
|
|
6141
6360
|
for await (const chunk of stream) {
|
|
6142
|
-
buffer += chunk
|
|
6361
|
+
buffer += chunk;
|
|
6143
6362
|
const lines = buffer.split("\n");
|
|
6144
6363
|
buffer = lines.pop() ?? "";
|
|
6145
6364
|
for (const line of lines) {
|
|
@@ -6168,12 +6387,17 @@ var NodeExecAdapter = class {
|
|
|
6168
6387
|
throw new Error("argv must not be empty");
|
|
6169
6388
|
}
|
|
6170
6389
|
const args = argv.slice(1);
|
|
6390
|
+
if (signal?.aborted) {
|
|
6391
|
+
return Promise.resolve({ stdout: "", stderr: "", exitCode: -1, aborted: true });
|
|
6392
|
+
}
|
|
6171
6393
|
return new Promise((resolve, reject) => {
|
|
6172
6394
|
const child = (0, import_node_child_process.spawn)(command, args, {
|
|
6173
6395
|
cwd,
|
|
6174
6396
|
env: resolveChildEnv(env, inheritEnv),
|
|
6175
6397
|
stdio: [options.stdin === void 0 ? "ignore" : "pipe", "pipe", "pipe"]
|
|
6176
6398
|
});
|
|
6399
|
+
child.stdout?.setEncoding("utf8");
|
|
6400
|
+
child.stderr?.setEncoding("utf8");
|
|
6177
6401
|
let stdout = "";
|
|
6178
6402
|
let stderr = "";
|
|
6179
6403
|
let aborted = false;
|
|
@@ -6191,12 +6415,12 @@ var NodeExecAdapter = class {
|
|
|
6191
6415
|
}
|
|
6192
6416
|
}
|
|
6193
6417
|
child.stdout?.on("data", (chunk) => {
|
|
6194
|
-
const text = chunk
|
|
6418
|
+
const text = chunk;
|
|
6195
6419
|
stdout += text;
|
|
6196
6420
|
handlers?.onStdout?.(text);
|
|
6197
6421
|
});
|
|
6198
6422
|
child.stderr?.on("data", (chunk) => {
|
|
6199
|
-
const text = chunk
|
|
6423
|
+
const text = chunk;
|
|
6200
6424
|
stderr += text;
|
|
6201
6425
|
handlers?.onStderr?.(text);
|
|
6202
6426
|
});
|
|
@@ -6211,6 +6435,7 @@ var NodeExecAdapter = class {
|
|
|
6211
6435
|
reject(error);
|
|
6212
6436
|
});
|
|
6213
6437
|
child.on("close", (code, sig) => {
|
|
6438
|
+
signal?.removeEventListener("abort", abortHandler);
|
|
6214
6439
|
if (sig) {
|
|
6215
6440
|
exitSignal = sig;
|
|
6216
6441
|
}
|
|
@@ -6251,13 +6476,15 @@ var NodeExecAdapter = class {
|
|
|
6251
6476
|
}
|
|
6252
6477
|
}
|
|
6253
6478
|
const waitPromise = new Promise((resolve, reject) => {
|
|
6479
|
+
child.stdout?.setEncoding("utf8");
|
|
6480
|
+
child.stderr?.setEncoding("utf8");
|
|
6254
6481
|
let stdout = "";
|
|
6255
6482
|
let stderr = "";
|
|
6256
6483
|
child.stdout?.on("data", (chunk) => {
|
|
6257
|
-
stdout += chunk
|
|
6484
|
+
stdout += chunk;
|
|
6258
6485
|
});
|
|
6259
6486
|
child.stderr?.on("data", (chunk) => {
|
|
6260
|
-
stderr += chunk
|
|
6487
|
+
stderr += chunk;
|
|
6261
6488
|
});
|
|
6262
6489
|
child.stdin?.on("error", (error) => {
|
|
6263
6490
|
if (error.code !== "EPIPE" && error.code !== "EOF") {
|
|
@@ -6524,114 +6751,14 @@ function createNodeAdapters() {
|
|
|
6524
6751
|
fs: new NodeFsAdapter()
|
|
6525
6752
|
};
|
|
6526
6753
|
}
|
|
6527
|
-
var TypeGit = class _TypeGit {
|
|
6528
|
-
|
|
6529
|
-
|
|
6530
|
-
* Create a TypeGit instance with Git version check
|
|
6531
|
-
*
|
|
6532
|
-
* @param createOpts - Options including skipVersionCheck
|
|
6533
|
-
* @returns TypeGit instance
|
|
6534
|
-
* @throws GitError with kind 'UnsupportedGitVersion' if Git version is below minimum
|
|
6535
|
-
*/
|
|
6536
|
-
static async create(createOpts) {
|
|
6537
|
-
const gitInstance = await createGit({
|
|
6538
|
-
...createOpts,
|
|
6539
|
-
adapters: createNodeAdapters()
|
|
6540
|
-
});
|
|
6541
|
-
return new _TypeGit(gitInstance);
|
|
6754
|
+
var TypeGit = class _TypeGit extends GitClient {
|
|
6755
|
+
static async create(options) {
|
|
6756
|
+
return new _TypeGit(await createGit({ ...options, adapters: createNodeAdapters() }));
|
|
6542
6757
|
}
|
|
6543
6758
|
constructor(optionsOrGit) {
|
|
6544
|
-
|
|
6545
|
-
|
|
6546
|
-
|
|
6547
|
-
this.git = createGitSync({
|
|
6548
|
-
...optionsOrGit,
|
|
6549
|
-
adapters: createNodeAdapters()
|
|
6550
|
-
});
|
|
6551
|
-
}
|
|
6552
|
-
}
|
|
6553
|
-
/**
|
|
6554
|
-
* Open an existing worktree repository
|
|
6555
|
-
*
|
|
6556
|
-
* This is the most common use case. Throws GitError if the repository is bare.
|
|
6557
|
-
*
|
|
6558
|
-
* @throws GitError with kind 'NotWorktreeRepo' if the repository is bare
|
|
6559
|
-
*/
|
|
6560
|
-
get open() {
|
|
6561
|
-
return this.git.open.bind(this.git);
|
|
6562
|
-
}
|
|
6563
|
-
/**
|
|
6564
|
-
* Open an existing bare repository
|
|
6565
|
-
*
|
|
6566
|
-
* Throws GitError if the repository is not bare.
|
|
6567
|
-
*
|
|
6568
|
-
* @throws GitError with kind 'NotBareRepo' if the repository is not bare
|
|
6569
|
-
*/
|
|
6570
|
-
get openBare() {
|
|
6571
|
-
return this.git.openBare.bind(this.git);
|
|
6572
|
-
}
|
|
6573
|
-
/**
|
|
6574
|
-
* Open an existing repository without type guarantee
|
|
6575
|
-
*
|
|
6576
|
-
* Returns either WorktreeRepo or BareRepo depending on the repository type.
|
|
6577
|
-
* Use this when you don't know the repository type at compile time.
|
|
6578
|
-
*/
|
|
6579
|
-
get openRaw() {
|
|
6580
|
-
return this.git.openRaw.bind(this.git);
|
|
6581
|
-
}
|
|
6582
|
-
clone(url, path, opts) {
|
|
6583
|
-
return this.git.clone(url, path, opts);
|
|
6584
|
-
}
|
|
6585
|
-
init(path, opts) {
|
|
6586
|
-
return this.git.init(path, opts);
|
|
6587
|
-
}
|
|
6588
|
-
/**
|
|
6589
|
-
* List references in a remote repository
|
|
6590
|
-
*/
|
|
6591
|
-
get lsRemote() {
|
|
6592
|
-
return this.git.lsRemote.bind(this.git);
|
|
6593
|
-
}
|
|
6594
|
-
/**
|
|
6595
|
-
* Get git version
|
|
6596
|
-
*/
|
|
6597
|
-
get version() {
|
|
6598
|
-
return this.git.version.bind(this.git);
|
|
6599
|
-
}
|
|
6600
|
-
/**
|
|
6601
|
-
* Execute a raw git command (repository-agnostic)
|
|
6602
|
-
*/
|
|
6603
|
-
get raw() {
|
|
6604
|
-
return this.git.raw.bind(this.git);
|
|
6605
|
-
}
|
|
6606
|
-
/**
|
|
6607
|
-
* Global config operations
|
|
6608
|
-
*
|
|
6609
|
-
* Operates on ~/.gitconfig (user-level configuration).
|
|
6610
|
-
* For repository-level config, use repo.config instead.
|
|
6611
|
-
*/
|
|
6612
|
-
get config() {
|
|
6613
|
-
return this.git.config;
|
|
6614
|
-
}
|
|
6615
|
-
/**
|
|
6616
|
-
* Global LFS operations
|
|
6617
|
-
*
|
|
6618
|
-
* Operates on ~/.gitconfig (user-level) or /etc/gitconfig (system-level).
|
|
6619
|
-
* For repository-level LFS operations, use repo.lfs instead.
|
|
6620
|
-
*
|
|
6621
|
-
* @example
|
|
6622
|
-
* ```typescript
|
|
6623
|
-
* // Install LFS globally
|
|
6624
|
-
* await git.lfs.install();
|
|
6625
|
-
*
|
|
6626
|
-
* // Install system-wide
|
|
6627
|
-
* await git.lfs.install({ system: true });
|
|
6628
|
-
*
|
|
6629
|
-
* // Get LFS version
|
|
6630
|
-
* const version = await git.lfs.version();
|
|
6631
|
-
* ```
|
|
6632
|
-
*/
|
|
6633
|
-
get lfs() {
|
|
6634
|
-
return this.git.lfs;
|
|
6759
|
+
super(
|
|
6760
|
+
optionsOrGit && "open" in optionsOrGit ? optionsOrGit : createGitSync({ ...optionsOrGit, adapters: createNodeAdapters() })
|
|
6761
|
+
);
|
|
6635
6762
|
}
|
|
6636
6763
|
};
|
|
6637
6764
|
// Annotate the CommonJS export names for ESM import in node:
|