type-git 0.3.0-beta.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -17
- package/dist/adapters/bun/index.cjs +6332 -0
- package/dist/adapters/bun/index.cjs.map +1 -1
- package/dist/adapters/bun/index.d.cts +11 -6
- package/dist/adapters/bun/index.d.ts +11 -6
- package/dist/adapters/bun/index.js +6321 -0
- package/dist/adapters/bun/index.js.map +1 -1
- package/dist/adapters/deno/index.cjs +6332 -0
- package/dist/adapters/deno/index.cjs.map +1 -1
- package/dist/adapters/deno/index.d.cts +11 -6
- package/dist/adapters/deno/index.d.ts +11 -6
- package/dist/adapters/deno/index.js +6321 -0
- package/dist/adapters/deno/index.js.map +1 -1
- package/dist/adapters/node/index.cjs +1212 -1085
- package/dist/adapters/node/index.cjs.map +1 -1
- package/dist/adapters/node/index.d.cts +8 -4268
- package/dist/adapters/node/index.d.ts +8 -4268
- package/dist/adapters/node/index.js +1212 -1085
- package/dist/adapters/node/index.js.map +1 -1
- package/dist/client-DAAbUvgo.d.cts +5291 -0
- package/dist/client-DAAbUvgo.d.ts +5291 -0
- package/dist/index.cjs +1199 -1088
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1199 -1088
- package/dist/index.js.map +1 -1
- package/docs/migrations/0.4.0.md +93 -0
- package/package.json +4 -3
- package/dist/adapters-CZ8wj9Kr.d.cts +0 -850
- package/dist/adapters-CZ8wj9Kr.d.ts +0 -850
|
@@ -22,6 +22,273 @@ var GitError = class extends Error {
|
|
|
22
22
|
return this.category === "auth";
|
|
23
23
|
}
|
|
24
24
|
};
|
|
25
|
+
var GitArgumentError = class extends Error {
|
|
26
|
+
constructor(message) {
|
|
27
|
+
super(message);
|
|
28
|
+
this.name = "GitArgumentError";
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
// src/core/option-rules.ts
|
|
33
|
+
var OPTION_RULES = {
|
|
34
|
+
clone: {
|
|
35
|
+
exclusive: [
|
|
36
|
+
["ipv4", "ipv6"],
|
|
37
|
+
["depth", "shallowSince"],
|
|
38
|
+
["depth", "shallowExclude"],
|
|
39
|
+
["bare", "separateGitDir"],
|
|
40
|
+
["mirror", "separateGitDir"]
|
|
41
|
+
],
|
|
42
|
+
unsupported: []
|
|
43
|
+
},
|
|
44
|
+
init: { exclusive: [["bare", "separateGitDir"]], unsupported: [] },
|
|
45
|
+
lsRemote: { exclusive: [], unsupported: ["getUrl", "symref"] },
|
|
46
|
+
lsTree: { exclusive: [["nameOnly", "objectOnly", "long"]], unsupported: [] },
|
|
47
|
+
status: { exclusive: [["noRenames", "findRenames"]], unsupported: ["verbose"] },
|
|
48
|
+
log: {
|
|
49
|
+
exclusive: [
|
|
50
|
+
["merges", "noMerges"],
|
|
51
|
+
["since", "after"],
|
|
52
|
+
["until", "before"]
|
|
53
|
+
],
|
|
54
|
+
unsupported: [
|
|
55
|
+
"source",
|
|
56
|
+
"decorate",
|
|
57
|
+
"decorateRefs",
|
|
58
|
+
"decorateRefsExclude",
|
|
59
|
+
"stat",
|
|
60
|
+
"shortstat",
|
|
61
|
+
"nameOnly",
|
|
62
|
+
"nameStatus"
|
|
63
|
+
]
|
|
64
|
+
},
|
|
65
|
+
fetch: {
|
|
66
|
+
exclusive: [
|
|
67
|
+
["ipv4", "ipv6"],
|
|
68
|
+
["tags", "noTags"],
|
|
69
|
+
["depth", "deepen", "unshallow"],
|
|
70
|
+
["depth", "shallowSince"],
|
|
71
|
+
["depth", "shallowExclude"],
|
|
72
|
+
["all", "remote"],
|
|
73
|
+
["all", "refspec"]
|
|
74
|
+
],
|
|
75
|
+
unsupported: ["multiple"]
|
|
76
|
+
},
|
|
77
|
+
push: {
|
|
78
|
+
exclusive: [
|
|
79
|
+
["ipv4", "ipv6"],
|
|
80
|
+
["force", "forceWithLease"],
|
|
81
|
+
["all", "mirror", "refspec"],
|
|
82
|
+
["all", "tags"],
|
|
83
|
+
["branches", "mirror", "refspec"],
|
|
84
|
+
["branches", "tags"],
|
|
85
|
+
["mirror", "tags"],
|
|
86
|
+
["remote", "repo"]
|
|
87
|
+
],
|
|
88
|
+
unsupported: []
|
|
89
|
+
},
|
|
90
|
+
add: { exclusive: [["all", "update"]], unsupported: ["interactive", "patch"] },
|
|
91
|
+
checkoutBranch: {
|
|
92
|
+
exclusive: [["createBranch", "forceCreateBranch", "detach", "orphan"]],
|
|
93
|
+
unsupported: []
|
|
94
|
+
},
|
|
95
|
+
checkoutPath: {
|
|
96
|
+
exclusive: [
|
|
97
|
+
["ours", "theirs"],
|
|
98
|
+
["source", "ours"],
|
|
99
|
+
["source", "theirs"]
|
|
100
|
+
],
|
|
101
|
+
unsupported: []
|
|
102
|
+
},
|
|
103
|
+
commit: {
|
|
104
|
+
exclusive: [
|
|
105
|
+
["message", "file", "reuseMessage"],
|
|
106
|
+
["fixup", "squash"],
|
|
107
|
+
["include", "only", "all"],
|
|
108
|
+
["gpgSign", "noGpgSign"]
|
|
109
|
+
],
|
|
110
|
+
unsupported: ["dryRun", "reeditMessage"]
|
|
111
|
+
},
|
|
112
|
+
diff: {
|
|
113
|
+
exclusive: [
|
|
114
|
+
["nameOnly", "nameStatus", "stat", "numstat", "patchWithRaw", "patchWithStat"],
|
|
115
|
+
["nameOnly", "patch"],
|
|
116
|
+
["nameStatus", "patch"],
|
|
117
|
+
["nameOnly", "wordDiff"],
|
|
118
|
+
["nameStatus", "wordDiff"],
|
|
119
|
+
["nameOnly", "context"],
|
|
120
|
+
["nameStatus", "context"]
|
|
121
|
+
],
|
|
122
|
+
unsupported: ["noIndex"]
|
|
123
|
+
},
|
|
124
|
+
merge: {
|
|
125
|
+
controls: ["abort", "continue", "quit"],
|
|
126
|
+
exclusive: [
|
|
127
|
+
["abort", "continue", "quit"],
|
|
128
|
+
["noDiffstat", "stat"]
|
|
129
|
+
],
|
|
130
|
+
unsupported: []
|
|
131
|
+
},
|
|
132
|
+
pull: {
|
|
133
|
+
exclusive: [
|
|
134
|
+
["ipv4", "ipv6"],
|
|
135
|
+
["noStat", "stat"],
|
|
136
|
+
["depth", "deepen", "unshallow"],
|
|
137
|
+
["depth", "shallowSince"],
|
|
138
|
+
["depth", "shallowExclude"]
|
|
139
|
+
],
|
|
140
|
+
unsupported: []
|
|
141
|
+
},
|
|
142
|
+
switch: {
|
|
143
|
+
exclusive: [
|
|
144
|
+
["create", "forceCreate", "detach", "orphan"],
|
|
145
|
+
["discard", "merge"],
|
|
146
|
+
["force", "merge"]
|
|
147
|
+
],
|
|
148
|
+
unsupported: []
|
|
149
|
+
},
|
|
150
|
+
cherryPick: {
|
|
151
|
+
controls: ["abort", "continue", "skip"],
|
|
152
|
+
exclusive: [["abort", "continue", "skip"]],
|
|
153
|
+
unsupported: ["noVerify"]
|
|
154
|
+
},
|
|
155
|
+
revert: {
|
|
156
|
+
controls: ["abort", "continue", "skip"],
|
|
157
|
+
exclusive: [["abort", "continue", "skip"]],
|
|
158
|
+
unsupported: ["noVerify"]
|
|
159
|
+
},
|
|
160
|
+
rebase: {
|
|
161
|
+
controls: ["abort", "continue", "skip"],
|
|
162
|
+
exclusive: [
|
|
163
|
+
["abort", "continue", "skip"],
|
|
164
|
+
["keepBase", "onto"],
|
|
165
|
+
["keepBase", "root"],
|
|
166
|
+
["apply", "rebaseMerges"],
|
|
167
|
+
["apply", "strategy"],
|
|
168
|
+
["apply", "exec"]
|
|
169
|
+
],
|
|
170
|
+
unsupported: ["interactive"]
|
|
171
|
+
},
|
|
172
|
+
restore: {
|
|
173
|
+
exclusive: [
|
|
174
|
+
["ours", "theirs"],
|
|
175
|
+
["source", "ours"],
|
|
176
|
+
["source", "theirs"],
|
|
177
|
+
["source", "merge"],
|
|
178
|
+
["source", "conflict"]
|
|
179
|
+
],
|
|
180
|
+
unsupported: []
|
|
181
|
+
},
|
|
182
|
+
clean: { exclusive: [["ignored", "onlyIgnored"]], unsupported: [] },
|
|
183
|
+
worktreeAdd: {
|
|
184
|
+
exclusive: [
|
|
185
|
+
["branch", "detach"],
|
|
186
|
+
["orphan", "detach"]
|
|
187
|
+
],
|
|
188
|
+
unsupported: []
|
|
189
|
+
},
|
|
190
|
+
remoteSetHead: { exclusive: [["auto", "delete"]], unsupported: [] },
|
|
191
|
+
configGet: { exclusive: [["all", "default"]], unsupported: [] },
|
|
192
|
+
configList: { exclusive: [], unsupported: ["nameOnly"] },
|
|
193
|
+
lfsPull: { exclusive: [], unsupported: ["ref"] },
|
|
194
|
+
lfsPush: { exclusive: [["ref", "objectId"]], unsupported: [] },
|
|
195
|
+
lfsFetch: {
|
|
196
|
+
exclusive: [
|
|
197
|
+
["all", "include"],
|
|
198
|
+
["all", "exclude"],
|
|
199
|
+
["all", "recent"]
|
|
200
|
+
],
|
|
201
|
+
unsupported: []
|
|
202
|
+
},
|
|
203
|
+
lfsStatus: { exclusive: [], unsupported: ["porcelain"] },
|
|
204
|
+
lfsLsFiles: { exclusive: [], unsupported: ["debug", "nameOnly"] }
|
|
205
|
+
};
|
|
206
|
+
function validateOptions(name, options) {
|
|
207
|
+
if (!options) {
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
const values = options;
|
|
211
|
+
const rule = OPTION_RULES[name];
|
|
212
|
+
if ((name === "lfsStatus" || name === "lfsLsFiles") && values.json !== void 0 && values.json !== true) {
|
|
213
|
+
throw new GitArgumentError(`${name}: the typed API uses JSON`);
|
|
214
|
+
}
|
|
215
|
+
if (name === "status" && values.porcelain !== void 0 && values.porcelain !== 2) {
|
|
216
|
+
throw new GitArgumentError("status: the typed API uses porcelain v2");
|
|
217
|
+
}
|
|
218
|
+
if ((name === "status" || name === "diff") && values.nullTerminated !== void 0 && values.nullTerminated !== true) {
|
|
219
|
+
throw new GitArgumentError(`${name}: the typed API uses NUL-delimited paths`);
|
|
220
|
+
}
|
|
221
|
+
for (const key of rule.unsupported) {
|
|
222
|
+
if (values[key] !== void 0) {
|
|
223
|
+
throw new GitArgumentError(
|
|
224
|
+
`${name}: ${key} is not supported by the typed API; use raw() for this output or operation`
|
|
225
|
+
);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
if (rule.controls?.some((key) => values[key] === true)) {
|
|
229
|
+
const ignored = Object.keys(values).filter(
|
|
230
|
+
(key) => !(rule.controls?.includes(key) || ["signal", "onProgress", "onLfsProgress"].includes(key)) && values[key] !== void 0 && values[key] !== false
|
|
231
|
+
);
|
|
232
|
+
if (ignored.length > 0) {
|
|
233
|
+
throw new GitArgumentError(`${name}: control operations cannot take ${ignored.join(", ")}`);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
for (const group of rule.exclusive) {
|
|
237
|
+
const active = group.filter((key) => values[key] !== void 0 && values[key] !== false);
|
|
238
|
+
if (active.length > 1) {
|
|
239
|
+
throw new GitArgumentError(`${name}: ${active.join(", ")} cannot be used together`);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
for (const key of ["depth", "deepen", "jobs", "mainline"]) {
|
|
243
|
+
const value = values[key];
|
|
244
|
+
if (value !== void 0 && (!Number.isSafeInteger(value) || value < 1)) {
|
|
245
|
+
throw new GitArgumentError(`${name}: ${key} must be a positive safe integer`);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
for (const key of ["maxCount", "skip", "context", "renameLimit", "abbrev"]) {
|
|
249
|
+
const value = values[key];
|
|
250
|
+
if (value !== void 0 && typeof value !== "boolean" && (!Number.isSafeInteger(value) || value < 0)) {
|
|
251
|
+
throw new GitArgumentError(`${name}: ${key} must be a non-negative safe integer`);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
var REV_PARSE_QUERY_KEYS = [
|
|
256
|
+
"gitDir",
|
|
257
|
+
"absoluteGitDir",
|
|
258
|
+
"gitCommonDir",
|
|
259
|
+
"showToplevel",
|
|
260
|
+
"showCdup",
|
|
261
|
+
"showPrefix",
|
|
262
|
+
"showSuperprojectWorkingTree",
|
|
263
|
+
"sharedIndexPath",
|
|
264
|
+
"gitPath",
|
|
265
|
+
"resolveGitDir",
|
|
266
|
+
"isInsideGitDir",
|
|
267
|
+
"isInsideWorkTree",
|
|
268
|
+
"isBareRepository",
|
|
269
|
+
"isShallowRepository",
|
|
270
|
+
"all",
|
|
271
|
+
"branches",
|
|
272
|
+
"tags",
|
|
273
|
+
"remotes",
|
|
274
|
+
"glob",
|
|
275
|
+
"disambiguate",
|
|
276
|
+
"showObjectFormat",
|
|
277
|
+
"showRefFormat",
|
|
278
|
+
"localEnvVars"
|
|
279
|
+
];
|
|
280
|
+
function validateRevParseQuery(query) {
|
|
281
|
+
const values = query;
|
|
282
|
+
const selected = REV_PARSE_QUERY_KEYS.filter((key) => values[key] !== void 0);
|
|
283
|
+
if (selected.length !== 1 || values[selected[0]] !== true && typeof values[selected[0]] !== "string") {
|
|
284
|
+
throw new GitArgumentError("revParse: specify exactly one query");
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
function validatePathInput(name, paths, opts) {
|
|
288
|
+
if (opts?.pathspecFromFile !== void 0 && (typeof paths === "string" || paths.length > 0)) {
|
|
289
|
+
throw new GitArgumentError(`${name}: pass an empty path list when using pathspecFromFile`);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
25
292
|
|
|
26
293
|
// src/parsers/index.ts
|
|
27
294
|
var GIT_PROGRESS_PERCENT_REGEX = /^(.+?):\s*(\d+)%\s*\((\d+)\/(\d+)\)(?:,\s*(done))?/;
|
|
@@ -32,77 +299,135 @@ var LFS_DOWNLOAD_REGEX = /downloading|filtering/i;
|
|
|
32
299
|
var LFS_UPLOAD_REGEX = /uploading/i;
|
|
33
300
|
var LFS_CHECKOUT_REGEX = /checking out/i;
|
|
34
301
|
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;
|
|
35
|
-
function at(arr, index, context) {
|
|
36
|
-
const value = arr[index];
|
|
37
|
-
if (value === void 0) {
|
|
38
|
-
throw new Error(`Parse error: expected element at index ${index} in ${context}`);
|
|
39
|
-
}
|
|
40
|
-
return value;
|
|
41
|
-
}
|
|
42
302
|
function parseLines(stdout, options) {
|
|
43
303
|
const { keepEmpty = false, trim = true } = options ?? {};
|
|
44
304
|
const lines = stdout.split("\n");
|
|
45
305
|
return lines.map((line) => trim ? line.trim() : line).filter((line) => keepEmpty || line.length > 0);
|
|
46
306
|
}
|
|
307
|
+
function parseRecords(stdout, delimiter = "\0") {
|
|
308
|
+
if (!stdout) {
|
|
309
|
+
return [];
|
|
310
|
+
}
|
|
311
|
+
const normalized = stdout.endsWith(delimiter) ? stdout.slice(0, -delimiter.length) : stdout;
|
|
312
|
+
return normalized.split(delimiter);
|
|
313
|
+
}
|
|
314
|
+
function decodePath(path) {
|
|
315
|
+
if (!path.startsWith('"')) {
|
|
316
|
+
return path;
|
|
317
|
+
}
|
|
318
|
+
if (!path.endsWith('"')) {
|
|
319
|
+
throw new GitError("ParseError", "Unterminated quoted path");
|
|
320
|
+
}
|
|
321
|
+
const bytes = [];
|
|
322
|
+
const encoder = new TextEncoder();
|
|
323
|
+
const escapes = {
|
|
324
|
+
a: "\x07",
|
|
325
|
+
b: "\b",
|
|
326
|
+
f: "\f",
|
|
327
|
+
n: "\n",
|
|
328
|
+
r: "\r",
|
|
329
|
+
t: " ",
|
|
330
|
+
v: "\v",
|
|
331
|
+
'"': '"',
|
|
332
|
+
"\\": "\\"
|
|
333
|
+
};
|
|
334
|
+
const value = path.slice(1, -1);
|
|
335
|
+
for (let i = 0; i < value.length; ) {
|
|
336
|
+
if (value[i] === "\\") {
|
|
337
|
+
const octal = value.slice(i + 1).match(/^[0-7]{1,3}/)?.[0];
|
|
338
|
+
if (octal) {
|
|
339
|
+
bytes.push(Number.parseInt(octal, 8));
|
|
340
|
+
i += octal.length + 1;
|
|
341
|
+
continue;
|
|
342
|
+
}
|
|
343
|
+
const escaped = escapes[value[i + 1] ?? ""];
|
|
344
|
+
if (escaped === void 0) {
|
|
345
|
+
throw new GitError("ParseError", "Invalid quoted path escape");
|
|
346
|
+
}
|
|
347
|
+
bytes.push(...encoder.encode(escaped));
|
|
348
|
+
i += 2;
|
|
349
|
+
} else {
|
|
350
|
+
const char = String.fromCodePoint(value.codePointAt(i));
|
|
351
|
+
bytes.push(...encoder.encode(char));
|
|
352
|
+
i += char.length;
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
return new TextDecoder().decode(new Uint8Array(bytes));
|
|
356
|
+
}
|
|
47
357
|
function parsePorcelainV2(stdout) {
|
|
48
358
|
const entries = [];
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
hH: at(parts, 6, "porcelain-v2 ordinary"),
|
|
62
|
-
hI: at(parts, 7, "porcelain-v2 ordinary"),
|
|
63
|
-
path: pathPart
|
|
64
|
-
});
|
|
65
|
-
} else if (line.startsWith("2 ")) {
|
|
66
|
-
const parts = line.split(" ");
|
|
67
|
-
const pathPart = parts.slice(9).join(" ");
|
|
68
|
-
const pathParts = pathPart.split(" ");
|
|
359
|
+
const nul = stdout.includes("\0");
|
|
360
|
+
const records = nul ? parseRecords(stdout) : parseLines(stdout, { trim: false });
|
|
361
|
+
for (let i = 0; i < records.length; i++) {
|
|
362
|
+
const line = records[i];
|
|
363
|
+
if (line.startsWith("# ")) {
|
|
364
|
+
continue;
|
|
365
|
+
}
|
|
366
|
+
const kind = line[0];
|
|
367
|
+
if (kind === "?" || kind === "!") {
|
|
368
|
+
if (line[1] !== " " || line.length < 3) {
|
|
369
|
+
throw new GitError("ParseError", "Invalid status path");
|
|
370
|
+
}
|
|
69
371
|
entries.push({
|
|
70
|
-
type: "
|
|
71
|
-
|
|
72
|
-
sub: at(parts, 2, "porcelain-v2 renamed"),
|
|
73
|
-
mH: at(parts, 3, "porcelain-v2 renamed"),
|
|
74
|
-
mI: at(parts, 4, "porcelain-v2 renamed"),
|
|
75
|
-
mW: at(parts, 5, "porcelain-v2 renamed"),
|
|
76
|
-
hH: at(parts, 6, "porcelain-v2 renamed"),
|
|
77
|
-
hI: at(parts, 7, "porcelain-v2 renamed"),
|
|
78
|
-
path: at(pathParts, 0, "porcelain-v2 renamed path"),
|
|
79
|
-
origPath: pathParts[1]
|
|
372
|
+
type: kind === "?" ? "untracked" : "ignored",
|
|
373
|
+
path: nul ? line.slice(2) : decodePath(line.slice(2))
|
|
80
374
|
});
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
375
|
+
continue;
|
|
376
|
+
}
|
|
377
|
+
if (kind !== "1" && kind !== "2" && kind !== "u") {
|
|
378
|
+
throw new GitError("ParseError", "Unknown status record");
|
|
379
|
+
}
|
|
380
|
+
const count = kind === "u" ? 10 : kind === "2" ? 9 : 8;
|
|
381
|
+
const parts = line.split(" ");
|
|
382
|
+
if (parts.length <= count || parts[1]?.length !== 2) {
|
|
383
|
+
throw new GitError("ParseError", "Invalid status record");
|
|
384
|
+
}
|
|
385
|
+
let path = parts.slice(count).join(" ");
|
|
386
|
+
let origPath;
|
|
387
|
+
if (kind === "2") {
|
|
388
|
+
if (nul) {
|
|
389
|
+
origPath = records[++i];
|
|
390
|
+
} else {
|
|
391
|
+
const tab = path.indexOf(" ");
|
|
392
|
+
if (tab < 0) {
|
|
393
|
+
throw new GitError("ParseError", "Missing rename source");
|
|
394
|
+
}
|
|
395
|
+
origPath = decodePath(path.slice(tab + 1));
|
|
396
|
+
path = path.slice(0, tab);
|
|
397
|
+
}
|
|
398
|
+
if (origPath === void 0) {
|
|
399
|
+
throw new GitError("ParseError", "Missing rename source");
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
if (!nul) {
|
|
403
|
+
path = decodePath(path);
|
|
404
|
+
}
|
|
405
|
+
if (kind === "u") {
|
|
84
406
|
entries.push({
|
|
85
407
|
type: "unmerged",
|
|
86
|
-
xy:
|
|
87
|
-
sub:
|
|
88
|
-
m1:
|
|
89
|
-
m2:
|
|
90
|
-
m3:
|
|
91
|
-
mW:
|
|
92
|
-
h1:
|
|
93
|
-
h2:
|
|
94
|
-
h3:
|
|
95
|
-
path
|
|
96
|
-
});
|
|
97
|
-
} else if (line.startsWith("? ")) {
|
|
98
|
-
entries.push({
|
|
99
|
-
type: "untracked",
|
|
100
|
-
path: line.slice(2)
|
|
408
|
+
xy: parts[1],
|
|
409
|
+
sub: parts[2],
|
|
410
|
+
m1: parts[3],
|
|
411
|
+
m2: parts[4],
|
|
412
|
+
m3: parts[5],
|
|
413
|
+
mW: parts[6],
|
|
414
|
+
h1: parts[7],
|
|
415
|
+
h2: parts[8],
|
|
416
|
+
h3: parts[9],
|
|
417
|
+
path
|
|
101
418
|
});
|
|
102
|
-
} else
|
|
419
|
+
} else {
|
|
103
420
|
entries.push({
|
|
104
|
-
type: "
|
|
105
|
-
|
|
421
|
+
type: "changed",
|
|
422
|
+
xy: parts[1],
|
|
423
|
+
sub: parts[2],
|
|
424
|
+
mH: parts[3],
|
|
425
|
+
mI: parts[4],
|
|
426
|
+
mW: parts[5],
|
|
427
|
+
hH: parts[6],
|
|
428
|
+
hI: parts[7],
|
|
429
|
+
path,
|
|
430
|
+
...origPath !== void 0 ? { origPath } : {}
|
|
106
431
|
});
|
|
107
432
|
}
|
|
108
433
|
}
|
|
@@ -227,109 +552,71 @@ function parseLsRemote(stdout) {
|
|
|
227
552
|
}
|
|
228
553
|
return refs;
|
|
229
554
|
}
|
|
230
|
-
var LS_TREE_REGEX = /^(\d+)\s+(blob|tree|commit)\s+([a-f0-9]+)\t(
|
|
231
|
-
var LS_TREE_LONG_REGEX = /^(\d+)\s+(blob|tree|commit)\s+([a-f0-9]+)\s+(-|\d+)\t(
|
|
555
|
+
var LS_TREE_REGEX = /^(\d+)\s+(blob|tree|commit)\s+([a-f0-9]+)\t([\s\S]+)$/;
|
|
556
|
+
var LS_TREE_LONG_REGEX = /^(\d+)\s+(blob|tree|commit)\s+([a-f0-9]+)\s+(-|\d+)\t([\s\S]+)$/;
|
|
232
557
|
function parseLsTree(stdout, opts) {
|
|
233
|
-
const
|
|
234
|
-
const
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
if (opts?.objectOnly) {
|
|
246
|
-
entries.push({
|
|
247
|
-
mode: "",
|
|
248
|
-
type: "blob",
|
|
249
|
-
hash: line,
|
|
250
|
-
path: ""
|
|
251
|
-
});
|
|
252
|
-
continue;
|
|
253
|
-
}
|
|
254
|
-
if (opts?.long) {
|
|
255
|
-
const longMatch = line.match(LS_TREE_LONG_REGEX);
|
|
256
|
-
if (longMatch) {
|
|
257
|
-
const mode = longMatch[1];
|
|
258
|
-
const type = longMatch[2];
|
|
259
|
-
const hash = longMatch[3];
|
|
260
|
-
const sizeStr = longMatch[4];
|
|
261
|
-
const path = longMatch[5];
|
|
262
|
-
if (mode && type && hash && path) {
|
|
263
|
-
entries.push({
|
|
264
|
-
mode,
|
|
265
|
-
type,
|
|
266
|
-
hash,
|
|
267
|
-
path,
|
|
268
|
-
size: sizeStr === "-" || !sizeStr ? void 0 : Number.parseInt(sizeStr, 10)
|
|
269
|
-
});
|
|
270
|
-
}
|
|
271
|
-
continue;
|
|
272
|
-
}
|
|
558
|
+
const nul = stdout.includes("\0");
|
|
559
|
+
const records = nul ? parseRecords(stdout) : parseLines(stdout, { trim: false });
|
|
560
|
+
if (opts?.nameOnly) {
|
|
561
|
+
return records.map((path) => nul ? path : decodePath(path));
|
|
562
|
+
}
|
|
563
|
+
if (opts?.objectOnly) {
|
|
564
|
+
return records;
|
|
565
|
+
}
|
|
566
|
+
return records.map((line) => {
|
|
567
|
+
const match = line.match(opts?.long ? LS_TREE_LONG_REGEX : LS_TREE_REGEX);
|
|
568
|
+
if (!match) {
|
|
569
|
+
throw new GitError("ParseError", "Invalid ls-tree record", { stdout: line });
|
|
273
570
|
}
|
|
274
|
-
const
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
const hash = match[3];
|
|
279
|
-
const path = match[4];
|
|
280
|
-
if (mode && type && hash && path) {
|
|
281
|
-
entries.push({
|
|
282
|
-
mode,
|
|
283
|
-
type,
|
|
284
|
-
hash,
|
|
285
|
-
path
|
|
286
|
-
});
|
|
287
|
-
}
|
|
571
|
+
const path = match[opts?.long ? 5 : 4];
|
|
572
|
+
const size = opts?.long && match[4] !== "-" ? Number(match[4]) : void 0;
|
|
573
|
+
if (size !== void 0 && !Number.isSafeInteger(size)) {
|
|
574
|
+
throw new GitError("ParseError", "Invalid tree object size");
|
|
288
575
|
}
|
|
289
|
-
|
|
290
|
-
|
|
576
|
+
return {
|
|
577
|
+
mode: match[1],
|
|
578
|
+
type: match[2],
|
|
579
|
+
hash: match[3],
|
|
580
|
+
path: nul ? path : decodePath(path),
|
|
581
|
+
...size !== void 0 ? { size } : {}
|
|
582
|
+
};
|
|
583
|
+
});
|
|
291
584
|
}
|
|
292
|
-
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
|
|
585
|
+
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";
|
|
293
586
|
function parseGitLog(stdout) {
|
|
587
|
+
if (!stdout) {
|
|
588
|
+
return [];
|
|
589
|
+
}
|
|
590
|
+
const fields = parseRecords(stdout);
|
|
591
|
+
if (fields.length % 11 !== 0) {
|
|
592
|
+
throw new GitError("ParseError", "Invalid git log field count");
|
|
593
|
+
}
|
|
294
594
|
const commits = [];
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
const
|
|
298
|
-
if (fields.
|
|
299
|
-
|
|
300
|
-
}
|
|
301
|
-
const hash = fields[0]?.trim();
|
|
302
|
-
const abbrevHash = fields[1];
|
|
303
|
-
const parentsStr = fields[2];
|
|
304
|
-
const authorName = fields[3];
|
|
305
|
-
const authorEmail = fields[4];
|
|
306
|
-
const authorTimestampStr = fields[5];
|
|
307
|
-
const committerName = fields[6];
|
|
308
|
-
const committerEmail = fields[7];
|
|
309
|
-
const committerTimestampStr = fields[8];
|
|
310
|
-
const subject = fields[9];
|
|
311
|
-
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) {
|
|
312
|
-
continue;
|
|
595
|
+
for (let i = 0; i < fields.length; i += 11) {
|
|
596
|
+
const authorTimestamp = Number(fields[i + 5]);
|
|
597
|
+
const committerTimestamp = Number(fields[i + 8]);
|
|
598
|
+
if (!(fields[i] && Number.isSafeInteger(authorTimestamp) && Number.isSafeInteger(committerTimestamp))) {
|
|
599
|
+
throw new GitError("ParseError", "Invalid git log metadata");
|
|
313
600
|
}
|
|
314
601
|
commits.push({
|
|
315
|
-
hash,
|
|
316
|
-
abbrevHash,
|
|
317
|
-
parents:
|
|
318
|
-
authorName,
|
|
319
|
-
authorEmail,
|
|
320
|
-
authorTimestamp
|
|
321
|
-
committerName,
|
|
322
|
-
committerEmail,
|
|
323
|
-
committerTimestamp
|
|
324
|
-
subject,
|
|
325
|
-
body: fields[10]
|
|
602
|
+
hash: fields[i],
|
|
603
|
+
abbrevHash: fields[i + 1],
|
|
604
|
+
parents: fields[i + 2]?.split(" ").filter(Boolean) ?? [],
|
|
605
|
+
authorName: fields[i + 3],
|
|
606
|
+
authorEmail: fields[i + 4],
|
|
607
|
+
authorTimestamp,
|
|
608
|
+
committerName: fields[i + 6],
|
|
609
|
+
committerEmail: fields[i + 7],
|
|
610
|
+
committerTimestamp,
|
|
611
|
+
subject: fields[i + 9],
|
|
612
|
+
body: fields[i + 10]
|
|
326
613
|
});
|
|
327
614
|
}
|
|
328
615
|
return commits;
|
|
329
616
|
}
|
|
330
617
|
function parseWorktreeList(stdout) {
|
|
331
618
|
const worktrees = [];
|
|
332
|
-
const lines = parseLines(stdout, { keepEmpty: true });
|
|
619
|
+
const lines = parseLines(stdout, { keepEmpty: true, trim: false });
|
|
333
620
|
let current = null;
|
|
334
621
|
for (const line of lines) {
|
|
335
622
|
if (line.startsWith("worktree ")) {
|
|
@@ -343,7 +630,7 @@ function parseWorktreeList(stdout) {
|
|
|
343
630
|
});
|
|
344
631
|
}
|
|
345
632
|
current = {
|
|
346
|
-
path: line.slice("worktree ".length),
|
|
633
|
+
path: decodePath(line.slice("worktree ".length)),
|
|
347
634
|
locked: false,
|
|
348
635
|
prunable: false
|
|
349
636
|
};
|
|
@@ -415,6 +702,132 @@ function detectErrorCategory(stderr) {
|
|
|
415
702
|
return "unknown";
|
|
416
703
|
}
|
|
417
704
|
|
|
705
|
+
// src/internal/config.ts
|
|
706
|
+
var CONFIG_ENUMS = {
|
|
707
|
+
"core.autocrlf": ["true", "false", "input"],
|
|
708
|
+
"core.filemode": ["true", "false"],
|
|
709
|
+
"core.ignorecase": ["true", "false"],
|
|
710
|
+
"core.bare": ["true", "false"],
|
|
711
|
+
"core.logallrefupdates": ["true", "false", "always"],
|
|
712
|
+
"core.quotepath": ["true", "false"],
|
|
713
|
+
"commit.gpgsign": ["true", "false"],
|
|
714
|
+
"tag.gpgsign": ["true", "false"],
|
|
715
|
+
"tag.forcesignannotated": ["true", "false"],
|
|
716
|
+
"push.default": ["nothing", "current", "upstream", "tracking", "simple", "matching"],
|
|
717
|
+
"push.followTags": ["true", "false"],
|
|
718
|
+
"push.autoSetupRemote": ["true", "false"],
|
|
719
|
+
"push.gpgSign": ["true", "false", "if-asked"],
|
|
720
|
+
"pull.rebase": ["true", "false", "merges", "interactive"],
|
|
721
|
+
"pull.ff": ["true", "false", "only"],
|
|
722
|
+
"fetch.prune": ["true", "false"],
|
|
723
|
+
"fetch.pruneTags": ["true", "false"],
|
|
724
|
+
"merge.ff": ["true", "false", "only"],
|
|
725
|
+
"merge.conflictstyle": ["merge", "diff3", "zdiff3"],
|
|
726
|
+
"rebase.autoStash": ["true", "false"],
|
|
727
|
+
"rebase.autoSquash": ["true", "false"],
|
|
728
|
+
"rebase.updateRefs": ["true", "false"],
|
|
729
|
+
"diff.algorithm": ["default", "minimal", "patience", "histogram"],
|
|
730
|
+
"diff.colorMoved": ["no", "default", "plain", "blocks", "zebra", "dimmed-zebra"],
|
|
731
|
+
"color.ui": ["auto", "always", "never", "true", "false"],
|
|
732
|
+
"gpg.format": ["openpgp", "x509", "ssh"],
|
|
733
|
+
"http.sslVerify": ["true", "false"]
|
|
734
|
+
};
|
|
735
|
+
function configValue(key, value, implicit = false) {
|
|
736
|
+
const allowed = CONFIG_ENUMS[key];
|
|
737
|
+
if (!allowed) {
|
|
738
|
+
return value;
|
|
739
|
+
}
|
|
740
|
+
let normalized = value.toLowerCase();
|
|
741
|
+
if (allowed.includes("true") && allowed.includes("false")) {
|
|
742
|
+
if (normalized === "") {
|
|
743
|
+
normalized = implicit ? "true" : "false";
|
|
744
|
+
}
|
|
745
|
+
if (/^[+-]?\d+[kmg]?$/i.test(normalized)) {
|
|
746
|
+
normalized = Number.parseInt(normalized, 10) === 0 ? "false" : "true";
|
|
747
|
+
}
|
|
748
|
+
if (["yes", "on", "1"].includes(normalized)) {
|
|
749
|
+
normalized = "true";
|
|
750
|
+
}
|
|
751
|
+
if (["no", "off", "0"].includes(normalized)) {
|
|
752
|
+
normalized = "false";
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
if (!allowed.includes(normalized)) {
|
|
756
|
+
throw new GitError("ParseError", `Invalid value for ${key}: expected ${allowed.join(" | ")}`);
|
|
757
|
+
}
|
|
758
|
+
return normalized;
|
|
759
|
+
}
|
|
760
|
+
async function readConfig(runner, context, key, opts) {
|
|
761
|
+
validateOptions("configGet", opts);
|
|
762
|
+
const args = ["config", ...context.type === "global" ? ["--global"] : [], "--null"];
|
|
763
|
+
if (opts?.type) {
|
|
764
|
+
args.push(`--type=${opts.type}`);
|
|
765
|
+
}
|
|
766
|
+
if (opts?.default !== void 0) {
|
|
767
|
+
args.push("--default", opts.default);
|
|
768
|
+
}
|
|
769
|
+
args.push(opts?.all ? "--get-all" : "--get", key);
|
|
770
|
+
const result = await runner.run(context, args, opts);
|
|
771
|
+
if (result.exitCode === 1 && !result.aborted) {
|
|
772
|
+
return opts?.all ? [] : void 0;
|
|
773
|
+
}
|
|
774
|
+
runner.checkResult(context, args, result);
|
|
775
|
+
const values = parseRecords(result.stdout);
|
|
776
|
+
return opts?.all ? values : values[0];
|
|
777
|
+
}
|
|
778
|
+
async function listConfig(runner, context, opts) {
|
|
779
|
+
validateOptions("configList", opts);
|
|
780
|
+
const args = ["config", ...context.type === "global" ? ["--global"] : [], "--null", "--list"];
|
|
781
|
+
if (opts?.showOrigin) {
|
|
782
|
+
args.push("--show-origin");
|
|
783
|
+
}
|
|
784
|
+
if (opts?.showScope) {
|
|
785
|
+
args.push("--show-scope");
|
|
786
|
+
}
|
|
787
|
+
if (opts?.includes !== void 0) {
|
|
788
|
+
args.push(opts.includes ? "--includes" : "--no-includes");
|
|
789
|
+
}
|
|
790
|
+
const result = await runner.runOrThrow(context, args, opts);
|
|
791
|
+
const records = parseRecords(result.stdout);
|
|
792
|
+
const entries = [];
|
|
793
|
+
for (let i = 0; i < records.length; ) {
|
|
794
|
+
const scope = opts?.showScope ? records[i++] : void 0;
|
|
795
|
+
const origin = opts?.showOrigin ? records[i++] : void 0;
|
|
796
|
+
const entry = records[i++];
|
|
797
|
+
if (entry === void 0) {
|
|
798
|
+
throw new GitError("ParseError", "Incomplete config record");
|
|
799
|
+
}
|
|
800
|
+
const separator = entry.indexOf("\n");
|
|
801
|
+
entries.push({
|
|
802
|
+
key: separator < 0 ? entry : entry.slice(0, separator),
|
|
803
|
+
value: separator < 0 ? "" : entry.slice(separator + 1),
|
|
804
|
+
...scope !== void 0 ? { scope } : {},
|
|
805
|
+
...origin !== void 0 ? { origin } : {}
|
|
806
|
+
});
|
|
807
|
+
}
|
|
808
|
+
return entries;
|
|
809
|
+
}
|
|
810
|
+
async function readTypedConfig(runner, context, key, opts, all = false) {
|
|
811
|
+
const pattern = `^${key.toLowerCase().replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}$`;
|
|
812
|
+
const args = [
|
|
813
|
+
"config",
|
|
814
|
+
...context.type === "global" ? ["--global"] : [],
|
|
815
|
+
"--null",
|
|
816
|
+
"--get-regexp",
|
|
817
|
+
pattern
|
|
818
|
+
];
|
|
819
|
+
const result = await runner.run(context, args, opts);
|
|
820
|
+
if (result.exitCode === 1 && !result.aborted) {
|
|
821
|
+
return [];
|
|
822
|
+
}
|
|
823
|
+
runner.checkResult(context, args, result);
|
|
824
|
+
const records = parseRecords(result.stdout);
|
|
825
|
+
return (all ? records : records.slice(-1)).map((record2) => {
|
|
826
|
+
const separator = record2.indexOf("\n");
|
|
827
|
+
return configValue(key, separator < 0 ? "" : record2.slice(separator + 1), separator < 0);
|
|
828
|
+
});
|
|
829
|
+
}
|
|
830
|
+
|
|
418
831
|
// src/runner/cli-runner.ts
|
|
419
832
|
import process2 from "process";
|
|
420
833
|
|
|
@@ -725,6 +1138,9 @@ var CliRunner = class _CliRunner {
|
|
|
725
1138
|
async run(context, args, opts) {
|
|
726
1139
|
const argv = this.buildArgv(context, args);
|
|
727
1140
|
const { signal, onProgress, onLfsProgress, env: envOverride } = opts ?? {};
|
|
1141
|
+
if (signal?.aborted) {
|
|
1142
|
+
return { stdout: "", stderr: "", exitCode: -1, aborted: true };
|
|
1143
|
+
}
|
|
728
1144
|
const env = this.buildEnv();
|
|
729
1145
|
if (envOverride) {
|
|
730
1146
|
Object.assign(env, envOverride);
|
|
@@ -785,7 +1201,17 @@ var CliRunner = class _CliRunner {
|
|
|
785
1201
|
duration: endTimestamp - startTimestamp
|
|
786
1202
|
});
|
|
787
1203
|
}
|
|
788
|
-
|
|
1204
|
+
if (error instanceof GitError) {
|
|
1205
|
+
throw error;
|
|
1206
|
+
}
|
|
1207
|
+
throw new GitError(
|
|
1208
|
+
signal?.aborted ? "Aborted" : "SpawnFailed",
|
|
1209
|
+
error instanceof Error ? error.message : String(error),
|
|
1210
|
+
{
|
|
1211
|
+
argv,
|
|
1212
|
+
...context.type === "worktree" ? { workdir: context.workdir } : context.type === "bare" ? { gitDir: context.gitDir } : {}
|
|
1213
|
+
}
|
|
1214
|
+
);
|
|
789
1215
|
}
|
|
790
1216
|
if (this.audit?.onAudit) {
|
|
791
1217
|
const endTimestamp = Date.now();
|
|
@@ -890,6 +1316,12 @@ var CliRunner = class _CliRunner {
|
|
|
890
1316
|
/**
|
|
891
1317
|
* Run a command and throw on error
|
|
892
1318
|
*/
|
|
1319
|
+
checkResult(context, args, result) {
|
|
1320
|
+
const error = this.mapError(result, context, this.buildArgv(context, args));
|
|
1321
|
+
if (error) {
|
|
1322
|
+
throw error;
|
|
1323
|
+
}
|
|
1324
|
+
}
|
|
893
1325
|
async runOrThrow(context, args, opts) {
|
|
894
1326
|
const result = await this.run(context, args, opts);
|
|
895
1327
|
const error = this.mapError(result, context, this.buildArgv(context, args));
|
|
@@ -900,6 +1332,230 @@ var CliRunner = class _CliRunner {
|
|
|
900
1332
|
}
|
|
901
1333
|
};
|
|
902
1334
|
|
|
1335
|
+
// src/internal/transport.ts
|
|
1336
|
+
async function fetch(runner, context, opts) {
|
|
1337
|
+
validateOptions("fetch", opts);
|
|
1338
|
+
const args = ["fetch"];
|
|
1339
|
+
if (opts?.onProgress) {
|
|
1340
|
+
args.push("--progress");
|
|
1341
|
+
}
|
|
1342
|
+
if (opts?.verbose) {
|
|
1343
|
+
args.push("--verbose");
|
|
1344
|
+
}
|
|
1345
|
+
if (opts?.quiet) {
|
|
1346
|
+
args.push("--quiet");
|
|
1347
|
+
}
|
|
1348
|
+
if (opts?.all) {
|
|
1349
|
+
args.push("--all");
|
|
1350
|
+
}
|
|
1351
|
+
if (opts?.setUpstream) {
|
|
1352
|
+
args.push("--set-upstream");
|
|
1353
|
+
}
|
|
1354
|
+
if (opts?.append) {
|
|
1355
|
+
args.push("--append");
|
|
1356
|
+
}
|
|
1357
|
+
if (opts?.atomic) {
|
|
1358
|
+
args.push("--atomic");
|
|
1359
|
+
}
|
|
1360
|
+
if (opts?.force) {
|
|
1361
|
+
args.push("--force");
|
|
1362
|
+
}
|
|
1363
|
+
if (opts?.prune) {
|
|
1364
|
+
args.push("--prune");
|
|
1365
|
+
}
|
|
1366
|
+
if (opts?.pruneTags) {
|
|
1367
|
+
args.push("--prune-tags");
|
|
1368
|
+
}
|
|
1369
|
+
if (opts?.tags) {
|
|
1370
|
+
args.push("--tags");
|
|
1371
|
+
} else if (opts?.noTags) {
|
|
1372
|
+
args.push("--no-tags");
|
|
1373
|
+
}
|
|
1374
|
+
if (opts?.jobs !== void 0) {
|
|
1375
|
+
args.push(`--jobs=${opts.jobs}`);
|
|
1376
|
+
}
|
|
1377
|
+
if (opts?.prefetch) {
|
|
1378
|
+
args.push("--prefetch");
|
|
1379
|
+
}
|
|
1380
|
+
if (opts?.recurseSubmodules !== void 0) {
|
|
1381
|
+
if (opts.recurseSubmodules === true || opts.recurseSubmodules === "yes") {
|
|
1382
|
+
args.push("--recurse-submodules=yes");
|
|
1383
|
+
} else if (opts.recurseSubmodules === "on-demand") {
|
|
1384
|
+
args.push("--recurse-submodules=on-demand");
|
|
1385
|
+
} else if (opts.recurseSubmodules === "no" || opts.recurseSubmodules === false) {
|
|
1386
|
+
args.push("--recurse-submodules=no");
|
|
1387
|
+
}
|
|
1388
|
+
}
|
|
1389
|
+
if (opts?.dryRun) {
|
|
1390
|
+
args.push("--dry-run");
|
|
1391
|
+
}
|
|
1392
|
+
if (opts?.writeFetchHead === false) {
|
|
1393
|
+
args.push("--no-write-fetch-head");
|
|
1394
|
+
}
|
|
1395
|
+
if (opts?.keep) {
|
|
1396
|
+
args.push("--keep");
|
|
1397
|
+
}
|
|
1398
|
+
if (opts?.updateHeadOk) {
|
|
1399
|
+
args.push("--update-head-ok");
|
|
1400
|
+
}
|
|
1401
|
+
if (opts?.depth !== void 0) {
|
|
1402
|
+
args.push(`--depth=${opts.depth}`);
|
|
1403
|
+
}
|
|
1404
|
+
if (opts?.shallowSince) {
|
|
1405
|
+
const since = opts.shallowSince instanceof Date ? opts.shallowSince.toISOString() : opts.shallowSince;
|
|
1406
|
+
args.push(`--shallow-since=${since}`);
|
|
1407
|
+
}
|
|
1408
|
+
if (opts?.shallowExclude) {
|
|
1409
|
+
const excludes = Array.isArray(opts.shallowExclude) ? opts.shallowExclude : [opts.shallowExclude];
|
|
1410
|
+
for (const exclude of excludes) {
|
|
1411
|
+
args.push(`--shallow-exclude=${exclude}`);
|
|
1412
|
+
}
|
|
1413
|
+
}
|
|
1414
|
+
if (opts?.deepen !== void 0) {
|
|
1415
|
+
args.push(`--deepen=${opts.deepen}`);
|
|
1416
|
+
}
|
|
1417
|
+
if (opts?.unshallow) {
|
|
1418
|
+
args.push("--unshallow");
|
|
1419
|
+
}
|
|
1420
|
+
if (opts?.refetch) {
|
|
1421
|
+
args.push("--refetch");
|
|
1422
|
+
}
|
|
1423
|
+
if (opts?.updateShallow) {
|
|
1424
|
+
args.push("--update-shallow");
|
|
1425
|
+
}
|
|
1426
|
+
if (opts?.refmap) {
|
|
1427
|
+
args.push(`--refmap=${opts.refmap}`);
|
|
1428
|
+
}
|
|
1429
|
+
if (opts?.ipv4) {
|
|
1430
|
+
args.push("--ipv4");
|
|
1431
|
+
}
|
|
1432
|
+
if (opts?.ipv6) {
|
|
1433
|
+
args.push("--ipv6");
|
|
1434
|
+
}
|
|
1435
|
+
if (opts?.filter) {
|
|
1436
|
+
args.push(`--filter=${opts.filter}`);
|
|
1437
|
+
}
|
|
1438
|
+
if (opts?.showForcedUpdates === false) {
|
|
1439
|
+
args.push("--no-show-forced-updates");
|
|
1440
|
+
}
|
|
1441
|
+
if (opts?.writeCommitGraph) {
|
|
1442
|
+
args.push("--write-commit-graph");
|
|
1443
|
+
}
|
|
1444
|
+
if (opts?.remote) {
|
|
1445
|
+
args.push(opts.remote);
|
|
1446
|
+
}
|
|
1447
|
+
if (opts?.refspec) {
|
|
1448
|
+
const refspecs = Array.isArray(opts.refspec) ? opts.refspec : [opts.refspec];
|
|
1449
|
+
args.push(...refspecs);
|
|
1450
|
+
}
|
|
1451
|
+
await runner.runOrThrow(context, args, {
|
|
1452
|
+
signal: opts?.signal,
|
|
1453
|
+
onProgress: opts?.onProgress
|
|
1454
|
+
});
|
|
1455
|
+
}
|
|
1456
|
+
async function push(runner, context, opts) {
|
|
1457
|
+
validateOptions("push", opts);
|
|
1458
|
+
const args = ["push"];
|
|
1459
|
+
if (opts?.onProgress || opts?.onLfsProgress) {
|
|
1460
|
+
args.push("--progress");
|
|
1461
|
+
}
|
|
1462
|
+
if (opts?.verbose) {
|
|
1463
|
+
args.push("--verbose");
|
|
1464
|
+
}
|
|
1465
|
+
if (opts?.quiet) {
|
|
1466
|
+
args.push("--quiet");
|
|
1467
|
+
}
|
|
1468
|
+
if (opts?.repo) {
|
|
1469
|
+
args.push(`--repo=${opts.repo}`);
|
|
1470
|
+
}
|
|
1471
|
+
if (opts?.all) {
|
|
1472
|
+
args.push("--all");
|
|
1473
|
+
} else if (opts?.branches) {
|
|
1474
|
+
args.push("--branches");
|
|
1475
|
+
}
|
|
1476
|
+
if (opts?.mirror) {
|
|
1477
|
+
args.push("--mirror");
|
|
1478
|
+
}
|
|
1479
|
+
if (opts?.deleteRefs) {
|
|
1480
|
+
args.push("--delete");
|
|
1481
|
+
}
|
|
1482
|
+
if (opts?.force) {
|
|
1483
|
+
args.push("--force");
|
|
1484
|
+
} else if (opts?.forceWithLease !== void 0 && opts.forceWithLease !== false) {
|
|
1485
|
+
if (opts.forceWithLease === true) {
|
|
1486
|
+
args.push("--force-with-lease");
|
|
1487
|
+
} else {
|
|
1488
|
+
const leaseOpts = opts.forceWithLease;
|
|
1489
|
+
if (leaseOpts.expect !== void 0) {
|
|
1490
|
+
args.push(`--force-with-lease=${leaseOpts.refname}:${leaseOpts.expect}`);
|
|
1491
|
+
} else {
|
|
1492
|
+
args.push(`--force-with-lease=${leaseOpts.refname}`);
|
|
1493
|
+
}
|
|
1494
|
+
}
|
|
1495
|
+
}
|
|
1496
|
+
if (opts?.forceIfIncludes) {
|
|
1497
|
+
args.push("--force-if-includes");
|
|
1498
|
+
}
|
|
1499
|
+
if (opts?.dryRun) {
|
|
1500
|
+
args.push("--dry-run");
|
|
1501
|
+
}
|
|
1502
|
+
if (opts?.recurseSubmodules) {
|
|
1503
|
+
args.push(`--recurse-submodules=${opts.recurseSubmodules}`);
|
|
1504
|
+
}
|
|
1505
|
+
if (opts?.thin === false) {
|
|
1506
|
+
args.push("--no-thin");
|
|
1507
|
+
}
|
|
1508
|
+
if (opts?.prune) {
|
|
1509
|
+
args.push("--prune");
|
|
1510
|
+
}
|
|
1511
|
+
if (opts?.tags) {
|
|
1512
|
+
args.push("--tags");
|
|
1513
|
+
}
|
|
1514
|
+
if (opts?.followTags) {
|
|
1515
|
+
args.push("--follow-tags");
|
|
1516
|
+
}
|
|
1517
|
+
if (opts?.atomic) {
|
|
1518
|
+
args.push("--atomic");
|
|
1519
|
+
}
|
|
1520
|
+
if (opts?.pushOption) {
|
|
1521
|
+
const pushOptions = Array.isArray(opts.pushOption) ? opts.pushOption : [opts.pushOption];
|
|
1522
|
+
for (const opt of pushOptions) {
|
|
1523
|
+
args.push("--push-option", opt);
|
|
1524
|
+
}
|
|
1525
|
+
}
|
|
1526
|
+
if (opts?.setUpstream) {
|
|
1527
|
+
args.push("--set-upstream");
|
|
1528
|
+
}
|
|
1529
|
+
if (opts?.noVerify) {
|
|
1530
|
+
args.push("--no-verify");
|
|
1531
|
+
}
|
|
1532
|
+
if (opts?.signed !== void 0) {
|
|
1533
|
+
if (opts.signed === true) {
|
|
1534
|
+
args.push("--signed");
|
|
1535
|
+
} else if (opts.signed === "if-asked") {
|
|
1536
|
+
args.push("--signed=if-asked");
|
|
1537
|
+
}
|
|
1538
|
+
}
|
|
1539
|
+
if (opts?.ipv4) {
|
|
1540
|
+
args.push("--ipv4");
|
|
1541
|
+
}
|
|
1542
|
+
if (opts?.ipv6) {
|
|
1543
|
+
args.push("--ipv6");
|
|
1544
|
+
}
|
|
1545
|
+
if (opts?.remote) {
|
|
1546
|
+
args.push(opts.remote);
|
|
1547
|
+
}
|
|
1548
|
+
if (opts?.refspec) {
|
|
1549
|
+
const refspecs = Array.isArray(opts.refspec) ? opts.refspec : [opts.refspec];
|
|
1550
|
+
args.push(...refspecs);
|
|
1551
|
+
}
|
|
1552
|
+
await runner.runOrThrow(context, args, {
|
|
1553
|
+
signal: opts?.signal,
|
|
1554
|
+
onProgress: opts?.onProgress,
|
|
1555
|
+
onLfsProgress: opts?.onLfsProgress
|
|
1556
|
+
});
|
|
1557
|
+
}
|
|
1558
|
+
|
|
903
1559
|
// src/impl/bare-repo-impl.ts
|
|
904
1560
|
var REMOTE_LINE_PATTERN = /^(\S+)\t(.+?)\s+\((fetch|push)\)$/;
|
|
905
1561
|
var PRUNED_REF_PATTERN = /\* \[pruned\] (.+)/;
|
|
@@ -1092,6 +1748,7 @@ function isListQuery(opts) {
|
|
|
1092
1748
|
return "glob" in opts && !!opts.glob || "disambiguate" in opts && !!opts.disambiguate || "localEnvVars" in opts && !!opts.localEnvVars;
|
|
1093
1749
|
}
|
|
1094
1750
|
var BareRepoImpl = class {
|
|
1751
|
+
kind = "bare";
|
|
1095
1752
|
gitDir;
|
|
1096
1753
|
runner;
|
|
1097
1754
|
remote;
|
|
@@ -1157,6 +1814,7 @@ var BareRepoImpl = class {
|
|
|
1157
1814
|
* List references in a remote repository
|
|
1158
1815
|
*/
|
|
1159
1816
|
async lsRemote(remote, opts) {
|
|
1817
|
+
validateOptions("lsRemote", opts);
|
|
1160
1818
|
const args = ["ls-remote"];
|
|
1161
1819
|
if (opts?.heads) {
|
|
1162
1820
|
args.push("--heads");
|
|
@@ -1167,15 +1825,9 @@ var BareRepoImpl = class {
|
|
|
1167
1825
|
if (opts?.refsOnly) {
|
|
1168
1826
|
args.push("--refs");
|
|
1169
1827
|
}
|
|
1170
|
-
if (opts?.getUrl) {
|
|
1171
|
-
args.push("--get-url");
|
|
1172
|
-
}
|
|
1173
1828
|
if (opts?.sort) {
|
|
1174
1829
|
args.push("--sort", opts.sort);
|
|
1175
1830
|
}
|
|
1176
|
-
if (opts?.symref) {
|
|
1177
|
-
args.push("--symref");
|
|
1178
|
-
}
|
|
1179
1831
|
args.push(remote);
|
|
1180
1832
|
if (opts?.refs && opts.refs.length > 0) {
|
|
1181
1833
|
args.push(...opts.refs);
|
|
@@ -1187,11 +1839,9 @@ var BareRepoImpl = class {
|
|
|
1187
1839
|
const refs = parseLsRemote(result.stdout);
|
|
1188
1840
|
return { refs };
|
|
1189
1841
|
}
|
|
1190
|
-
/**
|
|
1191
|
-
* List contents of a tree object
|
|
1192
|
-
*/
|
|
1193
1842
|
async lsTree(treeish, opts) {
|
|
1194
|
-
|
|
1843
|
+
validateOptions("lsTree", opts);
|
|
1844
|
+
const args = ["ls-tree", "-z"];
|
|
1195
1845
|
if (opts?.recursive) {
|
|
1196
1846
|
args.push("-r");
|
|
1197
1847
|
}
|
|
@@ -1204,12 +1854,6 @@ var BareRepoImpl = class {
|
|
|
1204
1854
|
if (opts?.long) {
|
|
1205
1855
|
args.push("--long");
|
|
1206
1856
|
}
|
|
1207
|
-
if (opts?.nameOnly) {
|
|
1208
|
-
args.push("--name-only");
|
|
1209
|
-
}
|
|
1210
|
-
if (opts?.objectOnly) {
|
|
1211
|
-
args.push("--object-only");
|
|
1212
|
-
}
|
|
1213
1857
|
if (opts?.fullName) {
|
|
1214
1858
|
args.push("--full-name");
|
|
1215
1859
|
}
|
|
@@ -1230,11 +1874,14 @@ var BareRepoImpl = class {
|
|
|
1230
1874
|
const result = await this.runner.runOrThrow(this.context, args, {
|
|
1231
1875
|
signal: opts?.signal
|
|
1232
1876
|
});
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1877
|
+
const entries = parseLsTree(result.stdout, { long: opts?.long });
|
|
1878
|
+
if (opts?.nameOnly) {
|
|
1879
|
+
return entries.map((entry) => entry.path);
|
|
1880
|
+
}
|
|
1881
|
+
if (opts?.objectOnly) {
|
|
1882
|
+
return entries.map((entry) => entry.hash);
|
|
1883
|
+
}
|
|
1884
|
+
return entries;
|
|
1238
1885
|
}
|
|
1239
1886
|
async revParse(refOrOpts, opts) {
|
|
1240
1887
|
const args = ["rev-parse"];
|
|
@@ -1246,11 +1893,12 @@ var BareRepoImpl = class {
|
|
|
1246
1893
|
});
|
|
1247
1894
|
return result2.stdout.trim();
|
|
1248
1895
|
}
|
|
1896
|
+
validateRevParseQuery(refOrOpts);
|
|
1897
|
+
if ("pathFormat" in refOrOpts && refOrOpts.pathFormat) {
|
|
1898
|
+
args.push(`--path-format=${refOrOpts.pathFormat}`);
|
|
1899
|
+
}
|
|
1249
1900
|
const queryOpts = refOrOpts;
|
|
1250
1901
|
tryAddPathQuery(args, queryOpts) || tryAddBooleanQuery(args, queryOpts) || tryAddListQuery(args, queryOpts) || tryAddOtherQuery(args, queryOpts);
|
|
1251
|
-
if ("pathFormat" in queryOpts && queryOpts.pathFormat) {
|
|
1252
|
-
args.push(`--path-format=${queryOpts.pathFormat}`);
|
|
1253
|
-
}
|
|
1254
1902
|
const result = await this.runner.runOrThrow(this.context, args, {
|
|
1255
1903
|
signal: refOrOpts.signal
|
|
1256
1904
|
});
|
|
@@ -1267,60 +1915,13 @@ var BareRepoImpl = class {
|
|
|
1267
1915
|
* Fetch from remote
|
|
1268
1916
|
*/
|
|
1269
1917
|
async fetch(opts) {
|
|
1270
|
-
|
|
1271
|
-
if (opts?.onProgress) {
|
|
1272
|
-
args.push("--progress");
|
|
1273
|
-
}
|
|
1274
|
-
if (opts?.prune) {
|
|
1275
|
-
args.push("--prune");
|
|
1276
|
-
}
|
|
1277
|
-
if (opts?.tags) {
|
|
1278
|
-
args.push("--tags");
|
|
1279
|
-
}
|
|
1280
|
-
if (opts?.depth !== void 0) {
|
|
1281
|
-
args.push(`--depth=${opts.depth}`);
|
|
1282
|
-
}
|
|
1283
|
-
if (opts?.remote) {
|
|
1284
|
-
args.push(opts.remote);
|
|
1285
|
-
}
|
|
1286
|
-
if (opts?.refspec) {
|
|
1287
|
-
const refspecs = Array.isArray(opts.refspec) ? opts.refspec : [opts.refspec];
|
|
1288
|
-
args.push(...refspecs);
|
|
1289
|
-
}
|
|
1290
|
-
await this.runner.runOrThrow(this.context, args, {
|
|
1291
|
-
signal: opts?.signal,
|
|
1292
|
-
onProgress: opts?.onProgress
|
|
1293
|
-
});
|
|
1918
|
+
return fetch(this.runner, this.context, opts);
|
|
1294
1919
|
}
|
|
1295
1920
|
/**
|
|
1296
1921
|
* Push to remote
|
|
1297
1922
|
*/
|
|
1298
1923
|
async push(opts) {
|
|
1299
|
-
|
|
1300
|
-
if (opts?.onProgress || opts?.onLfsProgress) {
|
|
1301
|
-
args.push("--progress");
|
|
1302
|
-
}
|
|
1303
|
-
if (opts?.force) {
|
|
1304
|
-
args.push("--force");
|
|
1305
|
-
}
|
|
1306
|
-
if (opts?.tags) {
|
|
1307
|
-
args.push("--tags");
|
|
1308
|
-
}
|
|
1309
|
-
if (opts?.setUpstream) {
|
|
1310
|
-
args.push("--set-upstream");
|
|
1311
|
-
}
|
|
1312
|
-
if (opts?.remote) {
|
|
1313
|
-
args.push(opts.remote);
|
|
1314
|
-
}
|
|
1315
|
-
if (opts?.refspec) {
|
|
1316
|
-
const refspecs = Array.isArray(opts.refspec) ? opts.refspec : [opts.refspec];
|
|
1317
|
-
args.push(...refspecs);
|
|
1318
|
-
}
|
|
1319
|
-
await this.runner.runOrThrow(this.context, args, {
|
|
1320
|
-
signal: opts?.signal,
|
|
1321
|
-
onProgress: opts?.onProgress,
|
|
1322
|
-
onLfsProgress: opts?.onLfsProgress
|
|
1323
|
-
});
|
|
1924
|
+
return push(this.runner, this.context, opts);
|
|
1324
1925
|
}
|
|
1325
1926
|
// ==========================================================================
|
|
1326
1927
|
// Remote Operations
|
|
@@ -1386,6 +1987,7 @@ var BareRepoImpl = class {
|
|
|
1386
1987
|
});
|
|
1387
1988
|
}
|
|
1388
1989
|
async remoteSetHead(remote, branch, opts) {
|
|
1990
|
+
validateOptions("remoteSetHead", opts);
|
|
1389
1991
|
const args = ["remote", "set-head"];
|
|
1390
1992
|
if (opts?.auto) {
|
|
1391
1993
|
args.push("--auto");
|
|
@@ -1459,25 +2061,14 @@ var BareRepoImpl = class {
|
|
|
1459
2061
|
* Get a typed config value
|
|
1460
2062
|
*/
|
|
1461
2063
|
async configGet(key, opts) {
|
|
1462
|
-
const
|
|
1463
|
-
|
|
1464
|
-
});
|
|
1465
|
-
if (result.exitCode !== 0) {
|
|
1466
|
-
return void 0;
|
|
1467
|
-
}
|
|
1468
|
-
return result.stdout.trim();
|
|
2064
|
+
const values = await readTypedConfig(this.runner, this.context, key, opts);
|
|
2065
|
+
return values.at(-1);
|
|
1469
2066
|
}
|
|
1470
2067
|
/**
|
|
1471
2068
|
* Get all values for a typed multi-valued config key
|
|
1472
2069
|
*/
|
|
1473
2070
|
async configGetAll(key, opts) {
|
|
1474
|
-
|
|
1475
|
-
signal: opts?.signal
|
|
1476
|
-
});
|
|
1477
|
-
if (result.exitCode !== 0) {
|
|
1478
|
-
return [];
|
|
1479
|
-
}
|
|
1480
|
-
return parseLines(result.stdout);
|
|
2071
|
+
return readTypedConfig(this.runner, this.context, key, opts, true);
|
|
1481
2072
|
}
|
|
1482
2073
|
/**
|
|
1483
2074
|
* Set a typed config value
|
|
@@ -1503,27 +2094,8 @@ var BareRepoImpl = class {
|
|
|
1503
2094
|
signal: opts?.signal
|
|
1504
2095
|
});
|
|
1505
2096
|
}
|
|
1506
|
-
/**
|
|
1507
|
-
* Get a raw config value (for arbitrary keys)
|
|
1508
|
-
*/
|
|
1509
2097
|
async configGetRaw(key, opts) {
|
|
1510
|
-
|
|
1511
|
-
if (opts?.all) {
|
|
1512
|
-
args.push("--get-all");
|
|
1513
|
-
} else {
|
|
1514
|
-
args.push("--get");
|
|
1515
|
-
}
|
|
1516
|
-
args.push(key);
|
|
1517
|
-
const result = await this.runner.run(this.context, args, {
|
|
1518
|
-
signal: opts?.signal
|
|
1519
|
-
});
|
|
1520
|
-
if (result.exitCode !== 0) {
|
|
1521
|
-
return void 0;
|
|
1522
|
-
}
|
|
1523
|
-
if (opts?.all) {
|
|
1524
|
-
return parseLines(result.stdout);
|
|
1525
|
-
}
|
|
1526
|
-
return result.stdout.trim();
|
|
2098
|
+
return readConfig(this.runner, this.context, key, opts);
|
|
1527
2099
|
}
|
|
1528
2100
|
/**
|
|
1529
2101
|
* Set a raw config value (for arbitrary keys)
|
|
@@ -1550,47 +2122,7 @@ var BareRepoImpl = class {
|
|
|
1550
2122
|
* List all config values
|
|
1551
2123
|
*/
|
|
1552
2124
|
async configList(opts) {
|
|
1553
|
-
|
|
1554
|
-
if (opts?.showOrigin) {
|
|
1555
|
-
args.push("--show-origin");
|
|
1556
|
-
}
|
|
1557
|
-
if (opts?.showScope) {
|
|
1558
|
-
args.push("--show-scope");
|
|
1559
|
-
}
|
|
1560
|
-
if (opts?.includes) {
|
|
1561
|
-
args.push("--includes");
|
|
1562
|
-
}
|
|
1563
|
-
if (opts?.nameOnly) {
|
|
1564
|
-
args.push("--name-only");
|
|
1565
|
-
}
|
|
1566
|
-
const result = await this.runner.runOrThrow(this.context, args, {
|
|
1567
|
-
signal: opts?.signal
|
|
1568
|
-
});
|
|
1569
|
-
const entries = [];
|
|
1570
|
-
for (const line of parseLines(result.stdout)) {
|
|
1571
|
-
let keyValue = line;
|
|
1572
|
-
if (opts?.showOrigin || opts?.showScope) {
|
|
1573
|
-
const tabIndex = line.lastIndexOf(" ");
|
|
1574
|
-
if (tabIndex !== -1) {
|
|
1575
|
-
keyValue = line.slice(tabIndex + 1);
|
|
1576
|
-
}
|
|
1577
|
-
}
|
|
1578
|
-
if (opts?.nameOnly) {
|
|
1579
|
-
entries.push({
|
|
1580
|
-
key: keyValue,
|
|
1581
|
-
value: ""
|
|
1582
|
-
});
|
|
1583
|
-
} else {
|
|
1584
|
-
const eqIndex = keyValue.indexOf("=");
|
|
1585
|
-
if (eqIndex !== -1) {
|
|
1586
|
-
entries.push({
|
|
1587
|
-
key: keyValue.slice(0, eqIndex),
|
|
1588
|
-
value: keyValue.slice(eqIndex + 1)
|
|
1589
|
-
});
|
|
1590
|
-
}
|
|
1591
|
-
}
|
|
1592
|
-
}
|
|
1593
|
-
return entries;
|
|
2125
|
+
return listConfig(this.runner, this.context, opts);
|
|
1594
2126
|
}
|
|
1595
2127
|
async configRenameSection(oldName, newName, opts) {
|
|
1596
2128
|
await this.runner.runOrThrow(this.context, ["config", "--rename-section", oldName, newName], {
|
|
@@ -1604,6 +2136,58 @@ var BareRepoImpl = class {
|
|
|
1604
2136
|
}
|
|
1605
2137
|
};
|
|
1606
2138
|
|
|
2139
|
+
// src/internal/lfs-output.ts
|
|
2140
|
+
function record(value) {
|
|
2141
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
2142
|
+
}
|
|
2143
|
+
function data(stdout) {
|
|
2144
|
+
try {
|
|
2145
|
+
const value = JSON.parse(stdout);
|
|
2146
|
+
if (record(value)) {
|
|
2147
|
+
return value;
|
|
2148
|
+
}
|
|
2149
|
+
} catch {
|
|
2150
|
+
}
|
|
2151
|
+
throw new GitError("ParseError", "Invalid Git LFS JSON", { stdout });
|
|
2152
|
+
}
|
|
2153
|
+
function validSize(value) {
|
|
2154
|
+
return typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
|
|
2155
|
+
}
|
|
2156
|
+
function parseLfsStatusJson(stdout) {
|
|
2157
|
+
const files = data(stdout).files;
|
|
2158
|
+
if (!record(files)) {
|
|
2159
|
+
throw new GitError("ParseError", "Missing Git LFS status files");
|
|
2160
|
+
}
|
|
2161
|
+
return {
|
|
2162
|
+
files: Object.entries(files).map(([name, value]) => {
|
|
2163
|
+
if (!record(value) || typeof value.status !== "string" || value.size !== void 0 && !validSize(value.size)) {
|
|
2164
|
+
throw new GitError("ParseError", "Invalid Git LFS status entry");
|
|
2165
|
+
}
|
|
2166
|
+
return { name, status: value.status, ...validSize(value.size) ? { size: value.size } : {} };
|
|
2167
|
+
})
|
|
2168
|
+
};
|
|
2169
|
+
}
|
|
2170
|
+
function parseLfsFilesJson(stdout) {
|
|
2171
|
+
const files = data(stdout).files;
|
|
2172
|
+
if (files === null) {
|
|
2173
|
+
return [];
|
|
2174
|
+
}
|
|
2175
|
+
if (!Array.isArray(files)) {
|
|
2176
|
+
throw new GitError("ParseError", "Missing Git LFS file list");
|
|
2177
|
+
}
|
|
2178
|
+
return files.map((value) => {
|
|
2179
|
+
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)) {
|
|
2180
|
+
throw new GitError("ParseError", "Invalid Git LFS file entry");
|
|
2181
|
+
}
|
|
2182
|
+
return {
|
|
2183
|
+
path: value.name,
|
|
2184
|
+
oid: value.oid,
|
|
2185
|
+
size: value.size,
|
|
2186
|
+
status: value.checkout ? "checked-out" : "not-checked-out"
|
|
2187
|
+
};
|
|
2188
|
+
});
|
|
2189
|
+
}
|
|
2190
|
+
|
|
1607
2191
|
// src/internal/concurrency.ts
|
|
1608
2192
|
async function runWithConcurrency(items, run, options) {
|
|
1609
2193
|
const { concurrency, warmupCount = 0 } = options;
|
|
@@ -1652,6 +2236,7 @@ var PRE_UPLOAD_DEFAULT_BATCH_SIZE = 200;
|
|
|
1652
2236
|
var PRE_UPLOAD_DEFAULT_CONCURRENCY = 4;
|
|
1653
2237
|
var PRE_UPLOAD_WARMUP_BATCH_COUNT = 1;
|
|
1654
2238
|
var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
2239
|
+
kind = "worktree";
|
|
1655
2240
|
workdir;
|
|
1656
2241
|
runner;
|
|
1657
2242
|
_lfsMode = "enabled";
|
|
@@ -1799,6 +2384,7 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
1799
2384
|
* List references in a remote repository
|
|
1800
2385
|
*/
|
|
1801
2386
|
async lsRemote(remote, opts) {
|
|
2387
|
+
validateOptions("lsRemote", opts);
|
|
1802
2388
|
const args = ["ls-remote"];
|
|
1803
2389
|
if (opts?.heads) {
|
|
1804
2390
|
args.push("--heads");
|
|
@@ -1809,15 +2395,9 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
1809
2395
|
if (opts?.refsOnly) {
|
|
1810
2396
|
args.push("--refs");
|
|
1811
2397
|
}
|
|
1812
|
-
if (opts?.getUrl) {
|
|
1813
|
-
args.push("--get-url");
|
|
1814
|
-
}
|
|
1815
2398
|
if (opts?.sort) {
|
|
1816
2399
|
args.push("--sort", opts.sort);
|
|
1817
2400
|
}
|
|
1818
|
-
if (opts?.symref) {
|
|
1819
|
-
args.push("--symref");
|
|
1820
|
-
}
|
|
1821
2401
|
args.push(remote);
|
|
1822
2402
|
if (opts?.refs && opts.refs.length > 0) {
|
|
1823
2403
|
args.push(...opts.refs);
|
|
@@ -1829,11 +2409,9 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
1829
2409
|
const refs = parseLsRemote(result.stdout);
|
|
1830
2410
|
return { refs };
|
|
1831
2411
|
}
|
|
1832
|
-
/**
|
|
1833
|
-
* List contents of a tree object
|
|
1834
|
-
*/
|
|
1835
2412
|
async lsTree(treeish, opts) {
|
|
1836
|
-
|
|
2413
|
+
validateOptions("lsTree", opts);
|
|
2414
|
+
const args = ["ls-tree", "-z"];
|
|
1837
2415
|
if (opts?.recursive) {
|
|
1838
2416
|
args.push("-r");
|
|
1839
2417
|
}
|
|
@@ -1846,12 +2424,6 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
1846
2424
|
if (opts?.long) {
|
|
1847
2425
|
args.push("--long");
|
|
1848
2426
|
}
|
|
1849
|
-
if (opts?.nameOnly) {
|
|
1850
|
-
args.push("--name-only");
|
|
1851
|
-
}
|
|
1852
|
-
if (opts?.objectOnly) {
|
|
1853
|
-
args.push("--object-only");
|
|
1854
|
-
}
|
|
1855
2427
|
if (opts?.fullName) {
|
|
1856
2428
|
args.push("--full-name");
|
|
1857
2429
|
}
|
|
@@ -1872,20 +2444,21 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
1872
2444
|
const result = await this.runner.runOrThrow(this.context, args, {
|
|
1873
2445
|
signal: opts?.signal
|
|
1874
2446
|
});
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
2447
|
+
const entries = parseLsTree(result.stdout, { long: opts?.long });
|
|
2448
|
+
if (opts?.nameOnly) {
|
|
2449
|
+
return entries.map((entry) => entry.path);
|
|
2450
|
+
}
|
|
2451
|
+
if (opts?.objectOnly) {
|
|
2452
|
+
return entries.map((entry) => entry.hash);
|
|
2453
|
+
}
|
|
2454
|
+
return entries;
|
|
1880
2455
|
}
|
|
1881
2456
|
/**
|
|
1882
2457
|
* Get repository status
|
|
1883
2458
|
*/
|
|
1884
2459
|
async status(opts) {
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
args.push("--verbose");
|
|
1888
|
-
}
|
|
2460
|
+
validateOptions("status", opts);
|
|
2461
|
+
const args = ["status", "--porcelain=v2", "-z"];
|
|
1889
2462
|
if (opts?.untracked) {
|
|
1890
2463
|
switch (opts.untracked) {
|
|
1891
2464
|
case "no":
|
|
@@ -1906,9 +2479,6 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
1906
2479
|
if (opts?.aheadBehind === false) {
|
|
1907
2480
|
args.push("--no-ahead-behind");
|
|
1908
2481
|
}
|
|
1909
|
-
if (opts?.nullTerminated) {
|
|
1910
|
-
args.push("-z");
|
|
1911
|
-
}
|
|
1912
2482
|
if (opts?.ignored) {
|
|
1913
2483
|
switch (opts.ignored) {
|
|
1914
2484
|
case "traditional":
|
|
@@ -1940,81 +2510,60 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
1940
2510
|
return this.parseStatus(result.stdout);
|
|
1941
2511
|
}
|
|
1942
2512
|
parseStatus(stdout) {
|
|
1943
|
-
const
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
let behind;
|
|
1949
|
-
for (const line of lines) {
|
|
1950
|
-
if (line.startsWith("# branch.head ")) {
|
|
1951
|
-
branch = line.slice("# branch.head ".length);
|
|
1952
|
-
} else if (line.startsWith("# branch.upstream ")) {
|
|
1953
|
-
upstream = line.slice("# branch.upstream ".length);
|
|
1954
|
-
} else if (line.startsWith("# branch.ab ")) {
|
|
1955
|
-
const match = line.match(/# branch\.ab \+(\d+) -(\d+)/);
|
|
1956
|
-
const aheadStr = match?.[1];
|
|
1957
|
-
const behindStr = match?.[2];
|
|
1958
|
-
if (aheadStr !== void 0 && behindStr !== void 0) {
|
|
1959
|
-
ahead = Number.parseInt(aheadStr, 10);
|
|
1960
|
-
behind = Number.parseInt(behindStr, 10);
|
|
2513
|
+
const result = {
|
|
2514
|
+
entries: parsePorcelainV2(stdout).map((entry) => {
|
|
2515
|
+
if (entry.type === "untracked" || entry.type === "ignored") {
|
|
2516
|
+
const status = entry.type === "untracked" ? "?" : "!";
|
|
2517
|
+
return { path: entry.path, index: status, workdir: status };
|
|
1961
2518
|
}
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
}
|
|
1991
|
-
} else if (line.startsWith("? ")) {
|
|
1992
|
-
entries.push({
|
|
1993
|
-
path: line.slice(2),
|
|
1994
|
-
index: "?",
|
|
1995
|
-
workdir: "?"
|
|
1996
|
-
});
|
|
1997
|
-
} else if (line.startsWith("! ")) {
|
|
1998
|
-
entries.push({
|
|
1999
|
-
path: line.slice(2),
|
|
2000
|
-
index: "!",
|
|
2001
|
-
workdir: "!"
|
|
2002
|
-
});
|
|
2519
|
+
return {
|
|
2520
|
+
path: entry.path,
|
|
2521
|
+
index: entry.xy[0],
|
|
2522
|
+
workdir: entry.xy[1],
|
|
2523
|
+
..."origPath" in entry && entry.origPath !== void 0 ? { originalPath: entry.origPath } : {}
|
|
2524
|
+
};
|
|
2525
|
+
})
|
|
2526
|
+
};
|
|
2527
|
+
const records = stdout.includes("\0") ? parseRecords(stdout) : parseLines(stdout, { trim: false });
|
|
2528
|
+
for (let i = 0; i < records.length; i++) {
|
|
2529
|
+
const line = records[i];
|
|
2530
|
+
if (line.startsWith("2 ") && stdout.includes("\0")) {
|
|
2531
|
+
i++;
|
|
2532
|
+
continue;
|
|
2533
|
+
}
|
|
2534
|
+
if (line.startsWith("# branch.head ")) {
|
|
2535
|
+
result.branch = line.slice(14);
|
|
2536
|
+
}
|
|
2537
|
+
if (line.startsWith("# branch.upstream ")) {
|
|
2538
|
+
result.upstream = line.slice(18);
|
|
2539
|
+
}
|
|
2540
|
+
const ab = line.match(/^# branch\.ab \+(\d+) -(\d+)$/);
|
|
2541
|
+
if (ab) {
|
|
2542
|
+
result.ahead = Number(ab[1]);
|
|
2543
|
+
result.behind = Number(ab[2]);
|
|
2544
|
+
}
|
|
2545
|
+
if (line.startsWith("# stash ")) {
|
|
2546
|
+
result.stash = Number(line.slice(8));
|
|
2003
2547
|
}
|
|
2004
2548
|
}
|
|
2005
|
-
return
|
|
2006
|
-
entries,
|
|
2007
|
-
branch,
|
|
2008
|
-
upstream,
|
|
2009
|
-
ahead,
|
|
2010
|
-
behind
|
|
2011
|
-
};
|
|
2549
|
+
return result;
|
|
2012
2550
|
}
|
|
2013
2551
|
/**
|
|
2014
2552
|
* Get commit log
|
|
2015
2553
|
*/
|
|
2016
2554
|
async log(opts) {
|
|
2017
|
-
|
|
2555
|
+
validateOptions("log", opts);
|
|
2556
|
+
const format = opts?.useMailmap ? GIT_LOG_FORMAT.replace("%an", "%aN").replace("%ae", "%aE").replace("%cn", "%cN").replace("%ce", "%cE") : GIT_LOG_FORMAT;
|
|
2557
|
+
const args = [
|
|
2558
|
+
"log",
|
|
2559
|
+
"-z",
|
|
2560
|
+
"--no-patch",
|
|
2561
|
+
"--no-notes",
|
|
2562
|
+
"--no-show-signature",
|
|
2563
|
+
"--no-color",
|
|
2564
|
+
"--encoding=UTF-8",
|
|
2565
|
+
`--format=${format}`
|
|
2566
|
+
];
|
|
2018
2567
|
if (opts?.maxCount !== void 0) {
|
|
2019
2568
|
args.push(`-n${opts.maxCount}`);
|
|
2020
2569
|
}
|
|
@@ -2047,33 +2596,9 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
2047
2596
|
if (opts?.firstParent) {
|
|
2048
2597
|
args.push("--first-parent");
|
|
2049
2598
|
}
|
|
2050
|
-
if (opts?.source) {
|
|
2051
|
-
args.push("--source");
|
|
2052
|
-
}
|
|
2053
2599
|
if (opts?.useMailmap) {
|
|
2054
2600
|
args.push("--use-mailmap");
|
|
2055
2601
|
}
|
|
2056
|
-
if (opts?.decorateRefs) {
|
|
2057
|
-
args.push(`--decorate-refs=${opts.decorateRefs}`);
|
|
2058
|
-
}
|
|
2059
|
-
if (opts?.decorateRefsExclude) {
|
|
2060
|
-
args.push(`--decorate-refs-exclude=${opts.decorateRefsExclude}`);
|
|
2061
|
-
}
|
|
2062
|
-
if (opts?.decorate) {
|
|
2063
|
-
args.push(`--decorate=${opts.decorate}`);
|
|
2064
|
-
}
|
|
2065
|
-
if (opts?.stat) {
|
|
2066
|
-
args.push("--stat");
|
|
2067
|
-
}
|
|
2068
|
-
if (opts?.shortstat) {
|
|
2069
|
-
args.push("--shortstat");
|
|
2070
|
-
}
|
|
2071
|
-
if (opts?.nameOnly) {
|
|
2072
|
-
args.push("--name-only");
|
|
2073
|
-
}
|
|
2074
|
-
if (opts?.nameStatus) {
|
|
2075
|
-
args.push("--name-status");
|
|
2076
|
-
}
|
|
2077
2602
|
if (opts?.merges) {
|
|
2078
2603
|
args.push("--merges");
|
|
2079
2604
|
}
|
|
@@ -2115,230 +2640,13 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
2115
2640
|
* Fetch from remote
|
|
2116
2641
|
*/
|
|
2117
2642
|
async fetch(opts) {
|
|
2118
|
-
|
|
2119
|
-
if (opts?.onProgress) {
|
|
2120
|
-
args.push("--progress");
|
|
2121
|
-
}
|
|
2122
|
-
if (opts?.verbose) {
|
|
2123
|
-
args.push("--verbose");
|
|
2124
|
-
}
|
|
2125
|
-
if (opts?.quiet) {
|
|
2126
|
-
args.push("--quiet");
|
|
2127
|
-
}
|
|
2128
|
-
if (opts?.all) {
|
|
2129
|
-
args.push("--all");
|
|
2130
|
-
}
|
|
2131
|
-
if (opts?.setUpstream) {
|
|
2132
|
-
args.push("--set-upstream");
|
|
2133
|
-
}
|
|
2134
|
-
if (opts?.append) {
|
|
2135
|
-
args.push("--append");
|
|
2136
|
-
}
|
|
2137
|
-
if (opts?.atomic) {
|
|
2138
|
-
args.push("--atomic");
|
|
2139
|
-
}
|
|
2140
|
-
if (opts?.force) {
|
|
2141
|
-
args.push("--force");
|
|
2142
|
-
}
|
|
2143
|
-
if (opts?.multiple) {
|
|
2144
|
-
args.push("--multiple");
|
|
2145
|
-
}
|
|
2146
|
-
if (opts?.prune) {
|
|
2147
|
-
args.push("--prune");
|
|
2148
|
-
}
|
|
2149
|
-
if (opts?.pruneTags) {
|
|
2150
|
-
args.push("--prune-tags");
|
|
2151
|
-
}
|
|
2152
|
-
if (opts?.tags) {
|
|
2153
|
-
args.push("--tags");
|
|
2154
|
-
} else if (opts?.noTags) {
|
|
2155
|
-
args.push("--no-tags");
|
|
2156
|
-
}
|
|
2157
|
-
if (opts?.jobs !== void 0) {
|
|
2158
|
-
args.push(`--jobs=${opts.jobs}`);
|
|
2159
|
-
}
|
|
2160
|
-
if (opts?.prefetch) {
|
|
2161
|
-
args.push("--prefetch");
|
|
2162
|
-
}
|
|
2163
|
-
if (opts?.recurseSubmodules !== void 0) {
|
|
2164
|
-
if (opts.recurseSubmodules === true || opts.recurseSubmodules === "yes") {
|
|
2165
|
-
args.push("--recurse-submodules=yes");
|
|
2166
|
-
} else if (opts.recurseSubmodules === "on-demand") {
|
|
2167
|
-
args.push("--recurse-submodules=on-demand");
|
|
2168
|
-
} else if (opts.recurseSubmodules === "no" || opts.recurseSubmodules === false) {
|
|
2169
|
-
args.push("--recurse-submodules=no");
|
|
2170
|
-
}
|
|
2171
|
-
}
|
|
2172
|
-
if (opts?.dryRun) {
|
|
2173
|
-
args.push("--dry-run");
|
|
2174
|
-
}
|
|
2175
|
-
if (opts?.writeFetchHead === false) {
|
|
2176
|
-
args.push("--no-write-fetch-head");
|
|
2177
|
-
}
|
|
2178
|
-
if (opts?.keep) {
|
|
2179
|
-
args.push("--keep");
|
|
2180
|
-
}
|
|
2181
|
-
if (opts?.updateHeadOk) {
|
|
2182
|
-
args.push("--update-head-ok");
|
|
2183
|
-
}
|
|
2184
|
-
if (opts?.depth !== void 0) {
|
|
2185
|
-
args.push(`--depth=${opts.depth}`);
|
|
2186
|
-
}
|
|
2187
|
-
if (opts?.shallowSince) {
|
|
2188
|
-
const since = opts.shallowSince instanceof Date ? opts.shallowSince.toISOString() : opts.shallowSince;
|
|
2189
|
-
args.push(`--shallow-since=${since}`);
|
|
2190
|
-
}
|
|
2191
|
-
if (opts?.shallowExclude) {
|
|
2192
|
-
const excludes = Array.isArray(opts.shallowExclude) ? opts.shallowExclude : [opts.shallowExclude];
|
|
2193
|
-
for (const exclude of excludes) {
|
|
2194
|
-
args.push(`--shallow-exclude=${exclude}`);
|
|
2195
|
-
}
|
|
2196
|
-
}
|
|
2197
|
-
if (opts?.deepen !== void 0) {
|
|
2198
|
-
args.push(`--deepen=${opts.deepen}`);
|
|
2199
|
-
}
|
|
2200
|
-
if (opts?.unshallow) {
|
|
2201
|
-
args.push("--unshallow");
|
|
2202
|
-
}
|
|
2203
|
-
if (opts?.refetch) {
|
|
2204
|
-
args.push("--refetch");
|
|
2205
|
-
}
|
|
2206
|
-
if (opts?.updateShallow) {
|
|
2207
|
-
args.push("--update-shallow");
|
|
2208
|
-
}
|
|
2209
|
-
if (opts?.refmap) {
|
|
2210
|
-
args.push(`--refmap=${opts.refmap}`);
|
|
2211
|
-
}
|
|
2212
|
-
if (opts?.ipv4) {
|
|
2213
|
-
args.push("--ipv4");
|
|
2214
|
-
}
|
|
2215
|
-
if (opts?.ipv6) {
|
|
2216
|
-
args.push("--ipv6");
|
|
2217
|
-
}
|
|
2218
|
-
if (opts?.filter) {
|
|
2219
|
-
args.push(`--filter=${opts.filter}`);
|
|
2220
|
-
}
|
|
2221
|
-
if (opts?.showForcedUpdates === false) {
|
|
2222
|
-
args.push("--no-show-forced-updates");
|
|
2223
|
-
}
|
|
2224
|
-
if (opts?.writeCommitGraph) {
|
|
2225
|
-
args.push("--write-commit-graph");
|
|
2226
|
-
}
|
|
2227
|
-
if (opts?.remote) {
|
|
2228
|
-
args.push(opts.remote);
|
|
2229
|
-
}
|
|
2230
|
-
if (opts?.refspec) {
|
|
2231
|
-
const refspecs = Array.isArray(opts.refspec) ? opts.refspec : [opts.refspec];
|
|
2232
|
-
args.push(...refspecs);
|
|
2233
|
-
}
|
|
2234
|
-
await this.runner.runOrThrow(this.context, args, {
|
|
2235
|
-
signal: opts?.signal,
|
|
2236
|
-
onProgress: opts?.onProgress
|
|
2237
|
-
});
|
|
2643
|
+
return fetch(this.runner, this.context, opts);
|
|
2238
2644
|
}
|
|
2239
2645
|
/**
|
|
2240
2646
|
* Push to remote
|
|
2241
2647
|
*/
|
|
2242
2648
|
async push(opts) {
|
|
2243
|
-
|
|
2244
|
-
if (opts?.onProgress || opts?.onLfsProgress) {
|
|
2245
|
-
args.push("--progress");
|
|
2246
|
-
}
|
|
2247
|
-
if (opts?.verbose) {
|
|
2248
|
-
args.push("--verbose");
|
|
2249
|
-
}
|
|
2250
|
-
if (opts?.quiet) {
|
|
2251
|
-
args.push("--quiet");
|
|
2252
|
-
}
|
|
2253
|
-
if (opts?.repo) {
|
|
2254
|
-
args.push(`--repo=${opts.repo}`);
|
|
2255
|
-
}
|
|
2256
|
-
if (opts?.all) {
|
|
2257
|
-
args.push("--all");
|
|
2258
|
-
} else if (opts?.branches) {
|
|
2259
|
-
args.push("--branches");
|
|
2260
|
-
}
|
|
2261
|
-
if (opts?.mirror) {
|
|
2262
|
-
args.push("--mirror");
|
|
2263
|
-
}
|
|
2264
|
-
if (opts?.deleteRefs) {
|
|
2265
|
-
args.push("--delete");
|
|
2266
|
-
}
|
|
2267
|
-
if (opts?.force) {
|
|
2268
|
-
args.push("--force");
|
|
2269
|
-
} else if (opts?.forceWithLease !== void 0 && opts.forceWithLease !== false) {
|
|
2270
|
-
if (opts.forceWithLease === true) {
|
|
2271
|
-
args.push("--force-with-lease");
|
|
2272
|
-
} else {
|
|
2273
|
-
const leaseOpts = opts.forceWithLease;
|
|
2274
|
-
if (leaseOpts.expect !== void 0) {
|
|
2275
|
-
args.push(`--force-with-lease=${leaseOpts.refname}:${leaseOpts.expect}`);
|
|
2276
|
-
} else {
|
|
2277
|
-
args.push(`--force-with-lease=${leaseOpts.refname}`);
|
|
2278
|
-
}
|
|
2279
|
-
}
|
|
2280
|
-
}
|
|
2281
|
-
if (opts?.forceIfIncludes) {
|
|
2282
|
-
args.push("--force-if-includes");
|
|
2283
|
-
}
|
|
2284
|
-
if (opts?.dryRun) {
|
|
2285
|
-
args.push("--dry-run");
|
|
2286
|
-
}
|
|
2287
|
-
if (opts?.recurseSubmodules) {
|
|
2288
|
-
args.push(`--recurse-submodules=${opts.recurseSubmodules}`);
|
|
2289
|
-
}
|
|
2290
|
-
if (opts?.thin === false) {
|
|
2291
|
-
args.push("--no-thin");
|
|
2292
|
-
}
|
|
2293
|
-
if (opts?.prune) {
|
|
2294
|
-
args.push("--prune");
|
|
2295
|
-
}
|
|
2296
|
-
if (opts?.tags) {
|
|
2297
|
-
args.push("--tags");
|
|
2298
|
-
}
|
|
2299
|
-
if (opts?.followTags) {
|
|
2300
|
-
args.push("--follow-tags");
|
|
2301
|
-
}
|
|
2302
|
-
if (opts?.atomic) {
|
|
2303
|
-
args.push("--atomic");
|
|
2304
|
-
}
|
|
2305
|
-
if (opts?.pushOption) {
|
|
2306
|
-
const pushOptions = Array.isArray(opts.pushOption) ? opts.pushOption : [opts.pushOption];
|
|
2307
|
-
for (const opt of pushOptions) {
|
|
2308
|
-
args.push("--push-option", opt);
|
|
2309
|
-
}
|
|
2310
|
-
}
|
|
2311
|
-
if (opts?.setUpstream) {
|
|
2312
|
-
args.push("--set-upstream");
|
|
2313
|
-
}
|
|
2314
|
-
if (opts?.noVerify) {
|
|
2315
|
-
args.push("--no-verify");
|
|
2316
|
-
}
|
|
2317
|
-
if (opts?.signed !== void 0) {
|
|
2318
|
-
if (opts.signed === true) {
|
|
2319
|
-
args.push("--signed");
|
|
2320
|
-
} else if (opts.signed === "if-asked") {
|
|
2321
|
-
args.push("--signed=if-asked");
|
|
2322
|
-
}
|
|
2323
|
-
}
|
|
2324
|
-
if (opts?.ipv4) {
|
|
2325
|
-
args.push("--ipv4");
|
|
2326
|
-
}
|
|
2327
|
-
if (opts?.ipv6) {
|
|
2328
|
-
args.push("--ipv6");
|
|
2329
|
-
}
|
|
2330
|
-
if (opts?.remote) {
|
|
2331
|
-
args.push(opts.remote);
|
|
2332
|
-
}
|
|
2333
|
-
if (opts?.refspec) {
|
|
2334
|
-
const refspecs = Array.isArray(opts.refspec) ? opts.refspec : [opts.refspec];
|
|
2335
|
-
args.push(...refspecs);
|
|
2336
|
-
}
|
|
2337
|
-
await this.runner.runOrThrow(this.context, args, {
|
|
2338
|
-
signal: opts?.signal,
|
|
2339
|
-
onProgress: opts?.onProgress,
|
|
2340
|
-
onLfsProgress: opts?.onLfsProgress
|
|
2341
|
-
});
|
|
2649
|
+
return push(this.runner, this.context, opts);
|
|
2342
2650
|
}
|
|
2343
2651
|
/**
|
|
2344
2652
|
* Configure LFS mode for this repository
|
|
@@ -2373,6 +2681,7 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
2373
2681
|
// LFS Operations
|
|
2374
2682
|
// ==========================================================================
|
|
2375
2683
|
async lfsPull(opts) {
|
|
2684
|
+
validateOptions("lfsPull", opts);
|
|
2376
2685
|
if (this._lfsMode === "disabled") {
|
|
2377
2686
|
return;
|
|
2378
2687
|
}
|
|
@@ -2380,13 +2689,10 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
2380
2689
|
if (opts?.remote) {
|
|
2381
2690
|
args.push(opts.remote);
|
|
2382
2691
|
}
|
|
2383
|
-
if (opts?.
|
|
2384
|
-
args.push(opts.ref);
|
|
2385
|
-
}
|
|
2386
|
-
if (opts?.include && opts.include.length > 0) {
|
|
2692
|
+
if (opts?.include !== void 0) {
|
|
2387
2693
|
args.push("--include", opts.include.join(","));
|
|
2388
2694
|
}
|
|
2389
|
-
if (opts?.exclude
|
|
2695
|
+
if (opts?.exclude !== void 0) {
|
|
2390
2696
|
args.push("--exclude", opts.exclude.join(","));
|
|
2391
2697
|
}
|
|
2392
2698
|
await this.runner.runOrThrow(this.context, args, {
|
|
@@ -2396,6 +2702,7 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
2396
2702
|
});
|
|
2397
2703
|
}
|
|
2398
2704
|
async lfsPush(opts) {
|
|
2705
|
+
validateOptions("lfsPush", opts);
|
|
2399
2706
|
if (this._lfsMode === "disabled") {
|
|
2400
2707
|
return;
|
|
2401
2708
|
}
|
|
@@ -2429,33 +2736,9 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
2429
2736
|
});
|
|
2430
2737
|
}
|
|
2431
2738
|
async lfsStatus(opts) {
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
}
|
|
2436
|
-
if (opts?.porcelain) {
|
|
2437
|
-
args.push("--porcelain");
|
|
2438
|
-
}
|
|
2439
|
-
const result = await this.runner.runOrThrow(this.context, args, {
|
|
2440
|
-
signal: opts?.signal
|
|
2441
|
-
});
|
|
2442
|
-
const files = [];
|
|
2443
|
-
if (opts?.json) {
|
|
2444
|
-
try {
|
|
2445
|
-
const json = JSON.parse(result.stdout);
|
|
2446
|
-
if (json.files) {
|
|
2447
|
-
for (const [name, info] of Object.entries(json.files)) {
|
|
2448
|
-
files.push({
|
|
2449
|
-
name,
|
|
2450
|
-
size: info.size ?? 0,
|
|
2451
|
-
status: "unknown"
|
|
2452
|
-
});
|
|
2453
|
-
}
|
|
2454
|
-
}
|
|
2455
|
-
} catch {
|
|
2456
|
-
}
|
|
2457
|
-
}
|
|
2458
|
-
return { files };
|
|
2739
|
+
validateOptions("lfsStatus", opts);
|
|
2740
|
+
const result = await this.runner.runOrThrow(this.context, ["lfs", "status", "--json"], opts);
|
|
2741
|
+
return parseLfsStatusJson(result.stdout);
|
|
2459
2742
|
}
|
|
2460
2743
|
/**
|
|
2461
2744
|
* Pre-upload LFS objects before commit/push (2-phase commit pattern)
|
|
@@ -2683,12 +2966,19 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
2683
2966
|
});
|
|
2684
2967
|
}
|
|
2685
2968
|
async lfsFetch(opts) {
|
|
2969
|
+
validateOptions("lfsFetch", opts);
|
|
2686
2970
|
if (this._lfsMode === "disabled") {
|
|
2687
2971
|
return;
|
|
2688
2972
|
}
|
|
2689
2973
|
const args = ["lfs", "fetch"];
|
|
2690
|
-
if (opts?.
|
|
2691
|
-
args.push("--
|
|
2974
|
+
if (opts?.dryRun) {
|
|
2975
|
+
args.push("--dry-run");
|
|
2976
|
+
}
|
|
2977
|
+
if (opts?.refetch) {
|
|
2978
|
+
args.push("--refetch");
|
|
2979
|
+
}
|
|
2980
|
+
if (opts?.json) {
|
|
2981
|
+
args.push("--json");
|
|
2692
2982
|
}
|
|
2693
2983
|
if (opts?.all) {
|
|
2694
2984
|
args.push("--all");
|
|
@@ -2701,18 +2991,14 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
2701
2991
|
}
|
|
2702
2992
|
if (opts?.include) {
|
|
2703
2993
|
const patterns = Array.isArray(opts.include) ? opts.include : [opts.include];
|
|
2704
|
-
|
|
2705
|
-
args.push("--include", pattern);
|
|
2706
|
-
}
|
|
2994
|
+
args.push("--include", patterns.join(","));
|
|
2707
2995
|
}
|
|
2708
2996
|
if (opts?.exclude) {
|
|
2709
2997
|
const patterns = Array.isArray(opts.exclude) ? opts.exclude : [opts.exclude];
|
|
2710
|
-
|
|
2711
|
-
args.push("--exclude", pattern);
|
|
2712
|
-
}
|
|
2998
|
+
args.push("--exclude", patterns.join(","));
|
|
2713
2999
|
}
|
|
2714
|
-
if (opts?.remote) {
|
|
2715
|
-
args.push(opts.remote);
|
|
3000
|
+
if (opts?.remote || opts?.refs) {
|
|
3001
|
+
args.push(opts.remote ?? "origin");
|
|
2716
3002
|
}
|
|
2717
3003
|
if (opts?.refs) {
|
|
2718
3004
|
const refList = Array.isArray(opts.refs) ? opts.refs : [opts.refs];
|
|
@@ -2753,19 +3039,17 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
2753
3039
|
});
|
|
2754
3040
|
}
|
|
2755
3041
|
async lfsLsFiles(opts) {
|
|
3042
|
+
validateOptions("lfsLsFiles", opts);
|
|
2756
3043
|
if (this._lfsMode === "disabled") {
|
|
2757
3044
|
return [];
|
|
2758
3045
|
}
|
|
2759
|
-
const args = ["lfs", "ls-files"];
|
|
3046
|
+
const args = ["lfs", "ls-files", "--json"];
|
|
2760
3047
|
if (opts?.long) {
|
|
2761
3048
|
args.push("--long");
|
|
2762
3049
|
}
|
|
2763
3050
|
if (opts?.size) {
|
|
2764
3051
|
args.push("--size");
|
|
2765
3052
|
}
|
|
2766
|
-
if (opts?.debug) {
|
|
2767
|
-
args.push("--debug");
|
|
2768
|
-
}
|
|
2769
3053
|
if (opts?.all) {
|
|
2770
3054
|
args.push("--all");
|
|
2771
3055
|
}
|
|
@@ -2774,15 +3058,11 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
2774
3058
|
}
|
|
2775
3059
|
if (opts?.include) {
|
|
2776
3060
|
const patterns = Array.isArray(opts.include) ? opts.include : [opts.include];
|
|
2777
|
-
|
|
2778
|
-
args.push("--include", pattern);
|
|
2779
|
-
}
|
|
3061
|
+
args.push("--include", patterns.join(","));
|
|
2780
3062
|
}
|
|
2781
3063
|
if (opts?.exclude) {
|
|
2782
3064
|
const patterns = Array.isArray(opts.exclude) ? opts.exclude : [opts.exclude];
|
|
2783
|
-
|
|
2784
|
-
args.push("--exclude", pattern);
|
|
2785
|
-
}
|
|
3065
|
+
args.push("--exclude", patterns.join(","));
|
|
2786
3066
|
}
|
|
2787
3067
|
if (opts?.ref) {
|
|
2788
3068
|
args.push(opts.ref);
|
|
@@ -2790,19 +3070,7 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
2790
3070
|
const result = await this.runner.runOrThrow(this.context, args, {
|
|
2791
3071
|
signal: opts?.signal
|
|
2792
3072
|
});
|
|
2793
|
-
|
|
2794
|
-
for (const line of parseLines(result.stdout)) {
|
|
2795
|
-
const match = line.match(/^([0-9a-f]+)\s+([-*])\s+(.+?)(?:\s+\((\d+)\s*(?:B|bytes)?\))?$/);
|
|
2796
|
-
if (match) {
|
|
2797
|
-
entries.push({
|
|
2798
|
-
oid: match[1],
|
|
2799
|
-
path: match[3],
|
|
2800
|
-
size: match[4] ? Number.parseInt(match[4], 10) : void 0,
|
|
2801
|
-
status: match[2] === "*" ? "checked-out" : "not-checked-out"
|
|
2802
|
-
});
|
|
2803
|
-
}
|
|
2804
|
-
}
|
|
2805
|
-
return entries;
|
|
3073
|
+
return parseLfsFilesJson(result.stdout);
|
|
2806
3074
|
}
|
|
2807
3075
|
async lfsTrack(patterns, opts) {
|
|
2808
3076
|
const args = ["lfs", "track"];
|
|
@@ -2867,12 +3135,12 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
2867
3135
|
const result = await this.runner.runOrThrow(this.context, args, {
|
|
2868
3136
|
signal: opts?.signal
|
|
2869
3137
|
});
|
|
2870
|
-
const
|
|
3138
|
+
const data2 = JSON.parse(result.stdout);
|
|
2871
3139
|
return {
|
|
2872
|
-
id:
|
|
2873
|
-
path:
|
|
2874
|
-
owner: { name:
|
|
2875
|
-
lockedAt: new Date(
|
|
3140
|
+
id: data2.id,
|
|
3141
|
+
path: data2.path,
|
|
3142
|
+
owner: { name: data2.owner.name },
|
|
3143
|
+
lockedAt: new Date(data2.locked_at)
|
|
2876
3144
|
};
|
|
2877
3145
|
}
|
|
2878
3146
|
async lfsUnlock(pathOrId, opts) {
|
|
@@ -2920,8 +3188,8 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
2920
3188
|
const result = await this.runner.runOrThrow(this.context, args, {
|
|
2921
3189
|
signal: opts?.signal
|
|
2922
3190
|
});
|
|
2923
|
-
const
|
|
2924
|
-
return
|
|
3191
|
+
const data2 = JSON.parse(result.stdout);
|
|
3192
|
+
return data2.map((lock) => ({
|
|
2925
3193
|
id: lock.id,
|
|
2926
3194
|
path: lock.path,
|
|
2927
3195
|
owner: { name: lock.owner.name },
|
|
@@ -3138,6 +3406,7 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
3138
3406
|
return parseWorktreeList(result.stdout);
|
|
3139
3407
|
}
|
|
3140
3408
|
async worktreeAdd(path, opts) {
|
|
3409
|
+
validateOptions("worktreeAdd", opts);
|
|
3141
3410
|
const args = ["worktree", "add"];
|
|
3142
3411
|
if (opts?.detach) {
|
|
3143
3412
|
args.push("--detach");
|
|
@@ -3233,10 +3502,9 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
3233
3502
|
signal: opts?.signal
|
|
3234
3503
|
});
|
|
3235
3504
|
}
|
|
3236
|
-
// ==========================================================================
|
|
3237
|
-
// High-level API - add
|
|
3238
|
-
// ==========================================================================
|
|
3239
3505
|
async add(paths, opts) {
|
|
3506
|
+
validatePathInput("add", paths, opts);
|
|
3507
|
+
validateOptions("add", opts);
|
|
3240
3508
|
const args = ["add"];
|
|
3241
3509
|
if (opts?.verbose) {
|
|
3242
3510
|
args.push("--verbose");
|
|
@@ -3352,12 +3620,12 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
3352
3620
|
return branches;
|
|
3353
3621
|
}
|
|
3354
3622
|
async branchCurrent(opts) {
|
|
3355
|
-
const
|
|
3356
|
-
|
|
3357
|
-
|
|
3358
|
-
if (result.exitCode !== 0) {
|
|
3623
|
+
const args = ["symbolic-ref", "--quiet", "--short", "HEAD"];
|
|
3624
|
+
const result = await this.runner.run(this.context, args, opts);
|
|
3625
|
+
if (result.exitCode === 1 && !result.aborted) {
|
|
3359
3626
|
return null;
|
|
3360
3627
|
}
|
|
3628
|
+
this.runner.checkResult(this.context, args, result);
|
|
3361
3629
|
return result.stdout.trim();
|
|
3362
3630
|
}
|
|
3363
3631
|
async branchCreate(name, opts) {
|
|
@@ -3407,9 +3675,11 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
3407
3675
|
}
|
|
3408
3676
|
// Implementation
|
|
3409
3677
|
async checkout(targetOrPaths, opts) {
|
|
3678
|
+
validateOptions(Array.isArray(targetOrPaths) ? "checkoutPath" : "checkoutBranch", opts);
|
|
3410
3679
|
const args = ["checkout"];
|
|
3411
3680
|
const isPathMode = Array.isArray(targetOrPaths);
|
|
3412
3681
|
if (isPathMode) {
|
|
3682
|
+
validatePathInput("checkout", targetOrPaths, opts);
|
|
3413
3683
|
const pathOpts = opts;
|
|
3414
3684
|
if (pathOpts?.force) {
|
|
3415
3685
|
args.push("--force");
|
|
@@ -3491,6 +3761,7 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
3491
3761
|
// High-level API - commit
|
|
3492
3762
|
// ==========================================================================
|
|
3493
3763
|
async commit(opts) {
|
|
3764
|
+
validateOptions("commit", opts);
|
|
3494
3765
|
const args = ["commit"];
|
|
3495
3766
|
if (opts?.message) {
|
|
3496
3767
|
args.push("-m", opts.message);
|
|
@@ -3511,9 +3782,6 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
3511
3782
|
const date = opts.date instanceof Date ? opts.date.toISOString() : opts.date;
|
|
3512
3783
|
args.push("--date", date);
|
|
3513
3784
|
}
|
|
3514
|
-
if (opts?.dryRun) {
|
|
3515
|
-
args.push("--dry-run");
|
|
3516
|
-
}
|
|
3517
3785
|
if (opts?.noVerify) {
|
|
3518
3786
|
args.push("--no-verify");
|
|
3519
3787
|
}
|
|
@@ -3531,9 +3799,6 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
3531
3799
|
if (opts?.file) {
|
|
3532
3800
|
args.push("--file", opts.file);
|
|
3533
3801
|
}
|
|
3534
|
-
if (opts?.reeditMessage) {
|
|
3535
|
-
args.push("--reedit-message", opts.reeditMessage);
|
|
3536
|
-
}
|
|
3537
3802
|
if (opts?.reuseMessage) {
|
|
3538
3803
|
args.push("--reuse-message", opts.reuseMessage);
|
|
3539
3804
|
}
|
|
@@ -3576,10 +3841,9 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
3576
3841
|
if (opts?.allowEmptyMessage) {
|
|
3577
3842
|
args.push("--allow-empty-message");
|
|
3578
3843
|
}
|
|
3579
|
-
|
|
3844
|
+
await this.runner.runOrThrow(this.context, args, {
|
|
3580
3845
|
signal: opts?.signal
|
|
3581
3846
|
});
|
|
3582
|
-
const output = result.stdout;
|
|
3583
3847
|
let hash = "";
|
|
3584
3848
|
let branch = "";
|
|
3585
3849
|
let summary = "";
|
|
@@ -3590,17 +3854,29 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
3590
3854
|
signal: opts?.signal
|
|
3591
3855
|
});
|
|
3592
3856
|
hash = hashResult.stdout.trim();
|
|
3593
|
-
|
|
3594
|
-
|
|
3595
|
-
|
|
3596
|
-
|
|
3597
|
-
|
|
3598
|
-
/(\d+) files? changed(?:, (\d+) insertions?\(\+\))?(?:, (\d+) deletions?\(-\))?/
|
|
3857
|
+
branch = await this.branchCurrent(opts) ?? "HEAD";
|
|
3858
|
+
const stats = await this.runner.runOrThrow(
|
|
3859
|
+
this.context,
|
|
3860
|
+
["diff-tree", "--root", "--no-commit-id", "--numstat", "-r", "-z", "-M", hash],
|
|
3861
|
+
opts
|
|
3599
3862
|
);
|
|
3600
|
-
|
|
3601
|
-
|
|
3602
|
-
|
|
3603
|
-
|
|
3863
|
+
const records = parseRecords(stats.stdout);
|
|
3864
|
+
for (let i = 0; i < records.length; i++) {
|
|
3865
|
+
const record2 = records[i];
|
|
3866
|
+
const match = record2.match(/^(\d+|-)\t(\d+|-)\t([\s\S]*)$/);
|
|
3867
|
+
if (!match) {
|
|
3868
|
+
throw new GitError("ParseError", "Invalid commit numstat record");
|
|
3869
|
+
}
|
|
3870
|
+
filesChanged++;
|
|
3871
|
+
if (match[1] !== "-") {
|
|
3872
|
+
insertions += Number(match[1]);
|
|
3873
|
+
}
|
|
3874
|
+
if (match[2] !== "-") {
|
|
3875
|
+
deletions += Number(match[2]);
|
|
3876
|
+
}
|
|
3877
|
+
if (match[3] === "") {
|
|
3878
|
+
i += 2;
|
|
3879
|
+
}
|
|
3604
3880
|
}
|
|
3605
3881
|
const logResult = await this.runner.runOrThrow(this.context, ["log", "-1", "--format=%s"], {
|
|
3606
3882
|
signal: opts?.signal
|
|
@@ -3615,11 +3891,12 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
3615
3891
|
deletions
|
|
3616
3892
|
};
|
|
3617
3893
|
}
|
|
3618
|
-
// ==========================================================================
|
|
3619
|
-
// High-level API - diff
|
|
3620
|
-
// ==========================================================================
|
|
3621
3894
|
async diff(target, opts) {
|
|
3622
|
-
|
|
3895
|
+
validateOptions("diff", opts);
|
|
3896
|
+
const args = ["diff", "--no-ext-diff", "--no-textconv", "--no-color"];
|
|
3897
|
+
if (opts?.nameOnly || opts?.nameStatus) {
|
|
3898
|
+
args.push("-z");
|
|
3899
|
+
}
|
|
3623
3900
|
if (opts?.staged) {
|
|
3624
3901
|
args.push("--staged");
|
|
3625
3902
|
}
|
|
@@ -3697,10 +3974,7 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
3697
3974
|
args.push("--text");
|
|
3698
3975
|
}
|
|
3699
3976
|
if (opts?.mergeBase) {
|
|
3700
|
-
args.push(
|
|
3701
|
-
}
|
|
3702
|
-
if (opts?.noIndex) {
|
|
3703
|
-
args.push("--no-index");
|
|
3977
|
+
args.push("--merge-base");
|
|
3704
3978
|
}
|
|
3705
3979
|
if (opts?.wordDiff) {
|
|
3706
3980
|
args.push(`--word-diff=${opts.wordDiff}`);
|
|
@@ -3714,30 +3988,28 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
3714
3988
|
const result = await this.runner.runOrThrow(this.context, args, {
|
|
3715
3989
|
signal: opts?.signal
|
|
3716
3990
|
});
|
|
3991
|
+
if (opts?.nameOnly) {
|
|
3992
|
+
return parseRecords(result.stdout);
|
|
3993
|
+
}
|
|
3717
3994
|
if (opts?.nameStatus) {
|
|
3995
|
+
const records = parseRecords(result.stdout);
|
|
3718
3996
|
const files = [];
|
|
3719
|
-
for (
|
|
3720
|
-
const
|
|
3721
|
-
|
|
3722
|
-
|
|
3723
|
-
const newPath = match?.[3];
|
|
3724
|
-
if (status !== void 0 && pathOrOld !== void 0) {
|
|
3725
|
-
const entry = {
|
|
3726
|
-
status,
|
|
3727
|
-
path: newPath ?? pathOrOld
|
|
3728
|
-
};
|
|
3729
|
-
if (newPath !== void 0) {
|
|
3730
|
-
entry.oldPath = pathOrOld;
|
|
3731
|
-
}
|
|
3732
|
-
files.push(entry);
|
|
3997
|
+
for (let i = 0; i < records.length; ) {
|
|
3998
|
+
const code = records[i++];
|
|
3999
|
+
if (!/^[AMDRTCUXB][0-9]*$/.test(code)) {
|
|
4000
|
+
throw new GitError("ParseError", "Invalid diff status");
|
|
3733
4001
|
}
|
|
3734
|
-
|
|
3735
|
-
|
|
3736
|
-
|
|
3737
|
-
|
|
3738
|
-
|
|
3739
|
-
|
|
3740
|
-
files.push({
|
|
4002
|
+
const oldPath = records[i++];
|
|
4003
|
+
const renamed = code[0] === "R" || code[0] === "C";
|
|
4004
|
+
const path = renamed ? records[i++] : oldPath;
|
|
4005
|
+
if (oldPath === void 0 || path === void 0) {
|
|
4006
|
+
throw new GitError("ParseError", "Missing diff path");
|
|
4007
|
+
}
|
|
4008
|
+
files.push({
|
|
4009
|
+
status: code[0],
|
|
4010
|
+
path,
|
|
4011
|
+
...renamed ? { oldPath, similarity: Number(code.slice(1)) } : {}
|
|
4012
|
+
});
|
|
3741
4013
|
}
|
|
3742
4014
|
return { files };
|
|
3743
4015
|
}
|
|
@@ -3747,6 +4019,7 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
3747
4019
|
// High-level API - merge
|
|
3748
4020
|
// ==========================================================================
|
|
3749
4021
|
async merge(branch, opts) {
|
|
4022
|
+
validateOptions("merge", opts);
|
|
3750
4023
|
if (opts?.abort) {
|
|
3751
4024
|
await this.runner.runOrThrow(this.context, ["merge", "--abort"], {
|
|
3752
4025
|
signal: opts?.signal
|
|
@@ -3760,6 +4033,10 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
3760
4033
|
const hash = (await this.runner.runOrThrow(this.context, ["rev-parse", "HEAD"])).stdout.trim();
|
|
3761
4034
|
return { success: true, hash };
|
|
3762
4035
|
}
|
|
4036
|
+
if (opts?.quit) {
|
|
4037
|
+
await this.runner.runOrThrow(this.context, ["merge", "--quit"], opts);
|
|
4038
|
+
return { success: true };
|
|
4039
|
+
}
|
|
3763
4040
|
const args = ["merge"];
|
|
3764
4041
|
if (opts?.message) {
|
|
3765
4042
|
args.push("-m", opts.message);
|
|
@@ -3844,17 +4121,20 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
3844
4121
|
signal: opts?.signal,
|
|
3845
4122
|
env: this.lfsModeEnv()
|
|
3846
4123
|
});
|
|
4124
|
+
if (result.aborted) {
|
|
4125
|
+
this.runner.checkResult(this.context, args, result);
|
|
4126
|
+
}
|
|
3847
4127
|
if (result.exitCode !== 0) {
|
|
3848
|
-
const statusResult = await this.runner.runOrThrow(
|
|
3849
|
-
|
|
3850
|
-
|
|
3851
|
-
|
|
3852
|
-
|
|
3853
|
-
).
|
|
3854
|
-
|
|
3855
|
-
|
|
3856
|
-
|
|
3857
|
-
};
|
|
4128
|
+
const statusResult = await this.runner.runOrThrow(
|
|
4129
|
+
this.context,
|
|
4130
|
+
["status", "--porcelain=v2", "-z"],
|
|
4131
|
+
{ signal: opts?.signal }
|
|
4132
|
+
);
|
|
4133
|
+
const conflicts = parsePorcelainV2(statusResult.stdout).filter((entry) => entry.type === "unmerged").map((entry) => entry.path);
|
|
4134
|
+
if (conflicts.length === 0) {
|
|
4135
|
+
this.runner.checkResult(this.context, args, result);
|
|
4136
|
+
}
|
|
4137
|
+
return { success: false, conflicts };
|
|
3858
4138
|
}
|
|
3859
4139
|
const hashResult = await this.runner.runOrThrow(this.context, ["rev-parse", "HEAD"], {
|
|
3860
4140
|
signal: opts?.signal
|
|
@@ -3870,6 +4150,7 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
3870
4150
|
// High-level API - pull
|
|
3871
4151
|
// ==========================================================================
|
|
3872
4152
|
async pull(opts) {
|
|
4153
|
+
validateOptions("pull", opts);
|
|
3873
4154
|
const args = ["pull"];
|
|
3874
4155
|
if (opts?.onProgress || opts?.onLfsProgress) {
|
|
3875
4156
|
args.push("--progress");
|
|
@@ -4055,10 +4336,8 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
4055
4336
|
env: this.lfsModeEnv()
|
|
4056
4337
|
});
|
|
4057
4338
|
}
|
|
4058
|
-
// ==========================================================================
|
|
4059
|
-
// High-level API - rm
|
|
4060
|
-
// ==========================================================================
|
|
4061
4339
|
async rm(paths, opts) {
|
|
4340
|
+
validatePathInput("rm", paths, opts);
|
|
4062
4341
|
const args = ["rm"];
|
|
4063
4342
|
if (opts?.force) {
|
|
4064
4343
|
args.push("--force");
|
|
@@ -4094,38 +4373,29 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
4094
4373
|
// High-level API - Stash Operations
|
|
4095
4374
|
// ==========================================================================
|
|
4096
4375
|
async stashList(opts) {
|
|
4097
|
-
const result = await this.runner.runOrThrow(
|
|
4098
|
-
|
|
4099
|
-
|
|
4100
|
-
|
|
4101
|
-
|
|
4102
|
-
|
|
4103
|
-
|
|
4104
|
-
|
|
4105
|
-
const message = match?.[3];
|
|
4106
|
-
if (indexStr !== void 0 && message !== void 0) {
|
|
4107
|
-
const wipMatch = branchOrContext?.match(/^WIP on (.+)$/);
|
|
4108
|
-
entries.push({
|
|
4109
|
-
index: Number.parseInt(indexStr, 10),
|
|
4110
|
-
message,
|
|
4111
|
-
branch: wipMatch?.[1] ?? branchOrContext,
|
|
4112
|
-
commit: ""
|
|
4113
|
-
// We'd need another command to get the commit hash
|
|
4114
|
-
});
|
|
4115
|
-
}
|
|
4376
|
+
const result = await this.runner.runOrThrow(
|
|
4377
|
+
this.context,
|
|
4378
|
+
["stash", "list", "-z", "--format=%gd%x00%H%x00%gs"],
|
|
4379
|
+
opts
|
|
4380
|
+
);
|
|
4381
|
+
const fields = parseRecords(result.stdout);
|
|
4382
|
+
if (fields.length % 3 !== 0) {
|
|
4383
|
+
throw new GitError("ParseError", "Invalid stash record");
|
|
4116
4384
|
}
|
|
4117
|
-
|
|
4118
|
-
|
|
4119
|
-
|
|
4120
|
-
|
|
4121
|
-
|
|
4122
|
-
["rev-parse", `stash@{${entry.index}}`],
|
|
4123
|
-
{ signal: opts?.signal }
|
|
4124
|
-
);
|
|
4125
|
-
entry.commit = hashResult.stdout.trim();
|
|
4126
|
-
} catch {
|
|
4127
|
-
}
|
|
4385
|
+
const entries = [];
|
|
4386
|
+
for (let i = 0; i < fields.length; i += 3) {
|
|
4387
|
+
const index = fields[i]?.match(/^stash@\{(\d+)\}$/)?.[1];
|
|
4388
|
+
if (index === void 0 || !fields[i + 1]) {
|
|
4389
|
+
throw new GitError("ParseError", "Invalid stash metadata");
|
|
4128
4390
|
}
|
|
4391
|
+
const subject = fields[i + 2];
|
|
4392
|
+
const context = subject.match(/^(?:WIP on|On) (.*?): ([\s\S]*)$/);
|
|
4393
|
+
entries.push({
|
|
4394
|
+
index: Number(index),
|
|
4395
|
+
commit: fields[i + 1],
|
|
4396
|
+
message: context?.[2] ?? subject,
|
|
4397
|
+
...context ? { branch: context[1] } : {}
|
|
4398
|
+
});
|
|
4129
4399
|
}
|
|
4130
4400
|
return entries;
|
|
4131
4401
|
}
|
|
@@ -4201,6 +4471,7 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
4201
4471
|
// High-level API - switch
|
|
4202
4472
|
// ==========================================================================
|
|
4203
4473
|
async switch(branch, opts) {
|
|
4474
|
+
validateOptions("switch", opts);
|
|
4204
4475
|
const args = ["switch"];
|
|
4205
4476
|
if (opts?.create) {
|
|
4206
4477
|
args.push("-c");
|
|
@@ -4400,6 +4671,7 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
4400
4671
|
// Medium Priority - cherry-pick
|
|
4401
4672
|
// ==========================================================================
|
|
4402
4673
|
async cherryPick(commits, opts) {
|
|
4674
|
+
validateOptions("cherryPick", opts);
|
|
4403
4675
|
if (opts?.abort) {
|
|
4404
4676
|
await this.runner.runOrThrow(this.context, ["cherry-pick", "--abort"], {
|
|
4405
4677
|
signal: opts?.signal
|
|
@@ -4434,9 +4706,6 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
4434
4706
|
if (opts?.strategy) {
|
|
4435
4707
|
args.push("-s", opts.strategy);
|
|
4436
4708
|
}
|
|
4437
|
-
if (opts?.noVerify) {
|
|
4438
|
-
args.push("--no-verify");
|
|
4439
|
-
}
|
|
4440
4709
|
if (opts?.cleanup) {
|
|
4441
4710
|
args.push("--cleanup", opts.cleanup);
|
|
4442
4711
|
}
|
|
@@ -4481,6 +4750,7 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
4481
4750
|
// Medium Priority - clean
|
|
4482
4751
|
// ==========================================================================
|
|
4483
4752
|
async clean(opts) {
|
|
4753
|
+
validateOptions("clean", opts);
|
|
4484
4754
|
const args = ["clean"];
|
|
4485
4755
|
if (opts?.force) {
|
|
4486
4756
|
args.push("-f");
|
|
@@ -4550,6 +4820,7 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
4550
4820
|
// Medium Priority - rebase
|
|
4551
4821
|
// ==========================================================================
|
|
4552
4822
|
async rebase(opts) {
|
|
4823
|
+
validateOptions("rebase", opts);
|
|
4553
4824
|
if (opts?.abort) {
|
|
4554
4825
|
await this.runner.runOrThrow(this.context, ["rebase", "--abort"], {
|
|
4555
4826
|
signal: opts?.signal
|
|
@@ -4680,10 +4951,9 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
4680
4951
|
env: this.lfsModeEnv()
|
|
4681
4952
|
});
|
|
4682
4953
|
}
|
|
4683
|
-
// ==========================================================================
|
|
4684
|
-
// Medium Priority - restore
|
|
4685
|
-
// ==========================================================================
|
|
4686
4954
|
async restore(paths, opts) {
|
|
4955
|
+
validatePathInput("restore", paths, opts);
|
|
4956
|
+
validateOptions("restore", opts);
|
|
4687
4957
|
const args = ["restore"];
|
|
4688
4958
|
if (opts?.staged) {
|
|
4689
4959
|
args.push("--staged");
|
|
@@ -4743,6 +5013,7 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
4743
5013
|
// Medium Priority - revert
|
|
4744
5014
|
// ==========================================================================
|
|
4745
5015
|
async revert(commits, opts) {
|
|
5016
|
+
validateOptions("revert", opts);
|
|
4746
5017
|
if (opts?.abort) {
|
|
4747
5018
|
await this.runner.runOrThrow(this.context, ["revert", "--abort"], {
|
|
4748
5019
|
signal: opts?.signal
|
|
@@ -4771,9 +5042,6 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
4771
5042
|
if (opts?.mainline !== void 0) {
|
|
4772
5043
|
args.push("-m", opts.mainline.toString());
|
|
4773
5044
|
}
|
|
4774
|
-
if (opts?.noVerify) {
|
|
4775
|
-
args.push("--no-verify");
|
|
4776
|
-
}
|
|
4777
5045
|
if (opts?.cleanup) {
|
|
4778
5046
|
args.push("--cleanup", opts.cleanup);
|
|
4779
5047
|
}
|
|
@@ -4885,6 +5153,10 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
4885
5153
|
});
|
|
4886
5154
|
return result2.stdout.trim();
|
|
4887
5155
|
}
|
|
5156
|
+
validateRevParseQuery(refOrOpts);
|
|
5157
|
+
if ("pathFormat" in refOrOpts && refOrOpts.pathFormat) {
|
|
5158
|
+
args.push(`--path-format=${refOrOpts.pathFormat}`);
|
|
5159
|
+
}
|
|
4888
5160
|
const queryOpts = refOrOpts;
|
|
4889
5161
|
if ("gitDir" in queryOpts && queryOpts.gitDir) {
|
|
4890
5162
|
args.push("--git-dir");
|
|
@@ -4979,9 +5251,6 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
4979
5251
|
} else if ("localEnvVars" in queryOpts && queryOpts.localEnvVars) {
|
|
4980
5252
|
args.push("--local-env-vars");
|
|
4981
5253
|
}
|
|
4982
|
-
if ("pathFormat" in queryOpts && queryOpts.pathFormat) {
|
|
4983
|
-
args.push(`--path-format=${queryOpts.pathFormat}`);
|
|
4984
|
-
}
|
|
4985
5254
|
const result = await this.runner.runOrThrow(this.context, args, {
|
|
4986
5255
|
signal: queryOpts.signal
|
|
4987
5256
|
});
|
|
@@ -5321,6 +5590,7 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
5321
5590
|
});
|
|
5322
5591
|
}
|
|
5323
5592
|
async remoteSetHead(remote, branch, opts) {
|
|
5593
|
+
validateOptions("remoteSetHead", opts);
|
|
5324
5594
|
const args = ["remote", "set-head"];
|
|
5325
5595
|
if (opts?.auto) {
|
|
5326
5596
|
args.push("--auto");
|
|
@@ -5394,25 +5664,14 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
5394
5664
|
* Get a typed config value
|
|
5395
5665
|
*/
|
|
5396
5666
|
async configGet(key, opts) {
|
|
5397
|
-
const
|
|
5398
|
-
|
|
5399
|
-
|
|
5400
|
-
|
|
5401
|
-
|
|
5402
|
-
|
|
5403
|
-
|
|
5404
|
-
|
|
5405
|
-
/**
|
|
5406
|
-
* Get all values for a typed multi-valued config key
|
|
5407
|
-
*/
|
|
5408
|
-
async configGetAll(key, opts) {
|
|
5409
|
-
const result = await this.runner.run(this.context, ["config", "--get-all", key], {
|
|
5410
|
-
signal: opts?.signal
|
|
5411
|
-
});
|
|
5412
|
-
if (result.exitCode !== 0) {
|
|
5413
|
-
return [];
|
|
5414
|
-
}
|
|
5415
|
-
return parseLines(result.stdout);
|
|
5667
|
+
const values = await readTypedConfig(this.runner, this.context, key, opts);
|
|
5668
|
+
return values.at(-1);
|
|
5669
|
+
}
|
|
5670
|
+
/**
|
|
5671
|
+
* Get all values for a typed multi-valued config key
|
|
5672
|
+
*/
|
|
5673
|
+
async configGetAll(key, opts) {
|
|
5674
|
+
return readTypedConfig(this.runner, this.context, key, opts, true);
|
|
5416
5675
|
}
|
|
5417
5676
|
/**
|
|
5418
5677
|
* Set a typed config value
|
|
@@ -5438,33 +5697,8 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
5438
5697
|
signal: opts?.signal
|
|
5439
5698
|
});
|
|
5440
5699
|
}
|
|
5441
|
-
/**
|
|
5442
|
-
* Get a raw config value (for arbitrary keys)
|
|
5443
|
-
*/
|
|
5444
5700
|
async configGetRaw(key, opts) {
|
|
5445
|
-
|
|
5446
|
-
if (opts?.type) {
|
|
5447
|
-
args.push(`--type=${opts.type}`);
|
|
5448
|
-
}
|
|
5449
|
-
if (opts?.default !== void 0) {
|
|
5450
|
-
args.push("--default", opts.default);
|
|
5451
|
-
}
|
|
5452
|
-
if (opts?.all) {
|
|
5453
|
-
args.push("--get-all");
|
|
5454
|
-
} else {
|
|
5455
|
-
args.push("--get");
|
|
5456
|
-
}
|
|
5457
|
-
args.push(key);
|
|
5458
|
-
const result = await this.runner.run(this.context, args, {
|
|
5459
|
-
signal: opts?.signal
|
|
5460
|
-
});
|
|
5461
|
-
if (result.exitCode !== 0) {
|
|
5462
|
-
return void 0;
|
|
5463
|
-
}
|
|
5464
|
-
if (opts?.all) {
|
|
5465
|
-
return parseLines(result.stdout);
|
|
5466
|
-
}
|
|
5467
|
-
return result.stdout.trim();
|
|
5701
|
+
return readConfig(this.runner, this.context, key, opts);
|
|
5468
5702
|
}
|
|
5469
5703
|
/**
|
|
5470
5704
|
* Set a raw config value (for arbitrary keys)
|
|
@@ -5491,47 +5725,7 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
5491
5725
|
* List all config values
|
|
5492
5726
|
*/
|
|
5493
5727
|
async configList(opts) {
|
|
5494
|
-
|
|
5495
|
-
if (opts?.showOrigin) {
|
|
5496
|
-
args.push("--show-origin");
|
|
5497
|
-
}
|
|
5498
|
-
if (opts?.showScope) {
|
|
5499
|
-
args.push("--show-scope");
|
|
5500
|
-
}
|
|
5501
|
-
if (opts?.includes) {
|
|
5502
|
-
args.push("--includes");
|
|
5503
|
-
}
|
|
5504
|
-
if (opts?.nameOnly) {
|
|
5505
|
-
args.push("--name-only");
|
|
5506
|
-
}
|
|
5507
|
-
const result = await this.runner.runOrThrow(this.context, args, {
|
|
5508
|
-
signal: opts?.signal
|
|
5509
|
-
});
|
|
5510
|
-
const entries = [];
|
|
5511
|
-
for (const line of parseLines(result.stdout)) {
|
|
5512
|
-
let keyValue = line;
|
|
5513
|
-
if (opts?.showOrigin || opts?.showScope) {
|
|
5514
|
-
const tabIndex = line.lastIndexOf(" ");
|
|
5515
|
-
if (tabIndex !== -1) {
|
|
5516
|
-
keyValue = line.slice(tabIndex + 1);
|
|
5517
|
-
}
|
|
5518
|
-
}
|
|
5519
|
-
if (opts?.nameOnly) {
|
|
5520
|
-
entries.push({
|
|
5521
|
-
key: keyValue,
|
|
5522
|
-
value: ""
|
|
5523
|
-
});
|
|
5524
|
-
} else {
|
|
5525
|
-
const eqIndex = keyValue.indexOf("=");
|
|
5526
|
-
if (eqIndex !== -1) {
|
|
5527
|
-
entries.push({
|
|
5528
|
-
key: keyValue.slice(0, eqIndex),
|
|
5529
|
-
value: keyValue.slice(eqIndex + 1)
|
|
5530
|
-
});
|
|
5531
|
-
}
|
|
5532
|
-
}
|
|
5533
|
-
}
|
|
5534
|
-
return entries;
|
|
5728
|
+
return listConfig(this.runner, this.context, opts);
|
|
5535
5729
|
}
|
|
5536
5730
|
async configRenameSection(oldName, newName, opts) {
|
|
5537
5731
|
await this.runner.runOrThrow(this.context, ["config", "--rename-section", oldName, newName], {
|
|
@@ -5748,11 +5942,14 @@ var GitImpl = class {
|
|
|
5748
5942
|
return new WorktreeRepoImpl(repoRunner, path, opts);
|
|
5749
5943
|
}
|
|
5750
5944
|
async clone(url, path, opts) {
|
|
5945
|
+
validateOptions("clone", opts);
|
|
5751
5946
|
const args = buildCloneArgs(opts);
|
|
5752
5947
|
if (opts?.onProgress || opts?.onLfsProgress) {
|
|
5753
5948
|
args.push("--progress");
|
|
5754
5949
|
}
|
|
5755
5950
|
args.push(url, path);
|
|
5951
|
+
const destinationExisted = await this.adapters.fs.exists(path);
|
|
5952
|
+
const alreadyAborted = opts?.signal?.aborted;
|
|
5756
5953
|
try {
|
|
5757
5954
|
await this.runner.runOrThrow({ type: "global" }, args, {
|
|
5758
5955
|
signal: opts?.signal,
|
|
@@ -5760,7 +5957,7 @@ var GitImpl = class {
|
|
|
5760
5957
|
onLfsProgress: opts?.onLfsProgress
|
|
5761
5958
|
});
|
|
5762
5959
|
} catch (error) {
|
|
5763
|
-
if (error instanceof GitError && error.kind === "Aborted" && opts?.cleanupOnAbort !== false) {
|
|
5960
|
+
if (error instanceof GitError && error.kind === "Aborted" && opts?.cleanupOnAbort !== false && !destinationExisted && !alreadyAborted) {
|
|
5764
5961
|
await this.adapters.fs.deleteDirectory(path);
|
|
5765
5962
|
}
|
|
5766
5963
|
throw error;
|
|
@@ -5771,6 +5968,7 @@ var GitImpl = class {
|
|
|
5771
5968
|
return new WorktreeRepoImpl(this.runner, path);
|
|
5772
5969
|
}
|
|
5773
5970
|
async init(path, opts) {
|
|
5971
|
+
validateOptions("init", opts);
|
|
5774
5972
|
const args = ["init"];
|
|
5775
5973
|
if (opts?.quiet) {
|
|
5776
5974
|
args.push("--quiet");
|
|
@@ -5802,6 +6000,8 @@ var GitImpl = class {
|
|
|
5802
6000
|
args.push("--separate-git-dir", opts.separateGitDir);
|
|
5803
6001
|
}
|
|
5804
6002
|
args.push(path);
|
|
6003
|
+
const destinationExisted = await this.adapters.fs.exists(path);
|
|
6004
|
+
const alreadyAborted = opts?.signal?.aborted;
|
|
5805
6005
|
try {
|
|
5806
6006
|
await this.runner.runOrThrow({ type: "global" }, args, {
|
|
5807
6007
|
signal: opts?.signal,
|
|
@@ -5818,7 +6018,7 @@ var GitImpl = class {
|
|
|
5818
6018
|
);
|
|
5819
6019
|
}
|
|
5820
6020
|
} catch (error) {
|
|
5821
|
-
if (error instanceof GitError && error.kind === "Aborted" && opts?.cleanupOnAbort !== false) {
|
|
6021
|
+
if (error instanceof GitError && error.kind === "Aborted" && opts?.cleanupOnAbort !== false && !destinationExisted && !alreadyAborted) {
|
|
5822
6022
|
await this.adapters.fs.deleteDirectory(path);
|
|
5823
6023
|
}
|
|
5824
6024
|
throw error;
|
|
@@ -5832,6 +6032,7 @@ var GitImpl = class {
|
|
|
5832
6032
|
* List references in a remote repository
|
|
5833
6033
|
*/
|
|
5834
6034
|
async lsRemote(url, opts) {
|
|
6035
|
+
validateOptions("lsRemote", opts);
|
|
5835
6036
|
const args = ["ls-remote"];
|
|
5836
6037
|
if (opts?.heads) {
|
|
5837
6038
|
args.push("--heads");
|
|
@@ -5842,15 +6043,9 @@ var GitImpl = class {
|
|
|
5842
6043
|
if (opts?.refs) {
|
|
5843
6044
|
args.push("--refs");
|
|
5844
6045
|
}
|
|
5845
|
-
if (opts?.getUrl) {
|
|
5846
|
-
args.push("--get-url");
|
|
5847
|
-
}
|
|
5848
6046
|
if (opts?.sort) {
|
|
5849
6047
|
args.push("--sort", opts.sort);
|
|
5850
6048
|
}
|
|
5851
|
-
if (opts?.symref) {
|
|
5852
|
-
args.push("--symref");
|
|
5853
|
-
}
|
|
5854
6049
|
args.push(url);
|
|
5855
6050
|
const result = await this.runner.runOrThrow({ type: "global" }, args, {
|
|
5856
6051
|
signal: opts?.signal,
|
|
@@ -5894,27 +6089,14 @@ var GitImpl = class {
|
|
|
5894
6089
|
* Get a typed global config value
|
|
5895
6090
|
*/
|
|
5896
6091
|
async configGet(key, opts) {
|
|
5897
|
-
const
|
|
5898
|
-
|
|
5899
|
-
});
|
|
5900
|
-
if (result.exitCode !== 0) {
|
|
5901
|
-
return void 0;
|
|
5902
|
-
}
|
|
5903
|
-
return result.stdout.trim();
|
|
6092
|
+
const values = await readTypedConfig(this.runner, { type: "global" }, key, opts);
|
|
6093
|
+
return values.at(-1);
|
|
5904
6094
|
}
|
|
5905
6095
|
/**
|
|
5906
6096
|
* Get all values for a typed multi-valued global config key
|
|
5907
6097
|
*/
|
|
5908
6098
|
async configGetAll(key, opts) {
|
|
5909
|
-
|
|
5910
|
-
{ type: "global" },
|
|
5911
|
-
["config", "--global", "--get-all", key],
|
|
5912
|
-
{ signal: opts?.signal }
|
|
5913
|
-
);
|
|
5914
|
-
if (result.exitCode !== 0) {
|
|
5915
|
-
return [];
|
|
5916
|
-
}
|
|
5917
|
-
return parseLines(result.stdout);
|
|
6099
|
+
return readTypedConfig(this.runner, { type: "global" }, key, opts, true);
|
|
5918
6100
|
}
|
|
5919
6101
|
/**
|
|
5920
6102
|
* Set a typed global config value
|
|
@@ -5942,27 +6124,8 @@ var GitImpl = class {
|
|
|
5942
6124
|
signal: opts?.signal
|
|
5943
6125
|
});
|
|
5944
6126
|
}
|
|
5945
|
-
/**
|
|
5946
|
-
* Get a raw global config value (for arbitrary keys)
|
|
5947
|
-
*/
|
|
5948
6127
|
async configGetRaw(key, opts) {
|
|
5949
|
-
|
|
5950
|
-
if (opts?.all) {
|
|
5951
|
-
args.push("--get-all");
|
|
5952
|
-
} else {
|
|
5953
|
-
args.push("--get");
|
|
5954
|
-
}
|
|
5955
|
-
args.push(key);
|
|
5956
|
-
const result = await this.runner.run({ type: "global" }, args, {
|
|
5957
|
-
signal: opts?.signal
|
|
5958
|
-
});
|
|
5959
|
-
if (result.exitCode !== 0) {
|
|
5960
|
-
return void 0;
|
|
5961
|
-
}
|
|
5962
|
-
if (opts?.all) {
|
|
5963
|
-
return parseLines(result.stdout);
|
|
5964
|
-
}
|
|
5965
|
-
return result.stdout.trim();
|
|
6128
|
+
return readConfig(this.runner, { type: "global" }, key, opts);
|
|
5966
6129
|
}
|
|
5967
6130
|
/**
|
|
5968
6131
|
* Set a raw global config value (for arbitrary keys)
|
|
@@ -5989,34 +6152,7 @@ var GitImpl = class {
|
|
|
5989
6152
|
* List all global config values
|
|
5990
6153
|
*/
|
|
5991
6154
|
async configList(opts) {
|
|
5992
|
-
|
|
5993
|
-
if (opts?.showOrigin) {
|
|
5994
|
-
args.push("--show-origin");
|
|
5995
|
-
}
|
|
5996
|
-
if (opts?.showScope) {
|
|
5997
|
-
args.push("--show-scope");
|
|
5998
|
-
}
|
|
5999
|
-
const result = await this.runner.runOrThrow({ type: "global" }, args, {
|
|
6000
|
-
signal: opts?.signal
|
|
6001
|
-
});
|
|
6002
|
-
const entries = [];
|
|
6003
|
-
for (const line of parseLines(result.stdout)) {
|
|
6004
|
-
let keyValue = line;
|
|
6005
|
-
if (opts?.showOrigin || opts?.showScope) {
|
|
6006
|
-
const tabIndex = line.lastIndexOf(" ");
|
|
6007
|
-
if (tabIndex !== -1) {
|
|
6008
|
-
keyValue = line.slice(tabIndex + 1);
|
|
6009
|
-
}
|
|
6010
|
-
}
|
|
6011
|
-
const eqIndex = keyValue.indexOf("=");
|
|
6012
|
-
if (eqIndex !== -1) {
|
|
6013
|
-
entries.push({
|
|
6014
|
-
key: keyValue.slice(0, eqIndex),
|
|
6015
|
-
value: keyValue.slice(eqIndex + 1)
|
|
6016
|
-
});
|
|
6017
|
-
}
|
|
6018
|
-
}
|
|
6019
|
-
return entries;
|
|
6155
|
+
return listConfig(this.runner, { type: "global" }, opts);
|
|
6020
6156
|
}
|
|
6021
6157
|
// ==========================================================================
|
|
6022
6158
|
// Global LFS Operations
|
|
@@ -6089,6 +6225,89 @@ async function createGit(options) {
|
|
|
6089
6225
|
return git;
|
|
6090
6226
|
}
|
|
6091
6227
|
|
|
6228
|
+
// src/internal/client.ts
|
|
6229
|
+
var GitClient = class {
|
|
6230
|
+
constructor(git) {
|
|
6231
|
+
this.git = git;
|
|
6232
|
+
}
|
|
6233
|
+
get open() {
|
|
6234
|
+
return this.git.open.bind(this.git);
|
|
6235
|
+
}
|
|
6236
|
+
/**
|
|
6237
|
+
* Open an existing bare repository
|
|
6238
|
+
*
|
|
6239
|
+
* Throws GitError if the repository is not bare.
|
|
6240
|
+
*
|
|
6241
|
+
* @throws GitError with kind 'NotBareRepo' if the repository is not bare
|
|
6242
|
+
*/
|
|
6243
|
+
get openBare() {
|
|
6244
|
+
return this.git.openBare.bind(this.git);
|
|
6245
|
+
}
|
|
6246
|
+
/**
|
|
6247
|
+
* Open an existing repository without type guarantee
|
|
6248
|
+
*
|
|
6249
|
+
* Returns either WorktreeRepo or BareRepo depending on the repository type.
|
|
6250
|
+
* Use this when you don't know the repository type at compile time.
|
|
6251
|
+
*/
|
|
6252
|
+
get openRaw() {
|
|
6253
|
+
return this.git.openRaw.bind(this.git);
|
|
6254
|
+
}
|
|
6255
|
+
clone(url, path, opts) {
|
|
6256
|
+
return this.git.clone(url, path, opts);
|
|
6257
|
+
}
|
|
6258
|
+
init(path, opts) {
|
|
6259
|
+
return this.git.init(path, opts);
|
|
6260
|
+
}
|
|
6261
|
+
/**
|
|
6262
|
+
* List references in a remote repository
|
|
6263
|
+
*/
|
|
6264
|
+
get lsRemote() {
|
|
6265
|
+
return this.git.lsRemote.bind(this.git);
|
|
6266
|
+
}
|
|
6267
|
+
/**
|
|
6268
|
+
* Get git version
|
|
6269
|
+
*/
|
|
6270
|
+
get version() {
|
|
6271
|
+
return this.git.version.bind(this.git);
|
|
6272
|
+
}
|
|
6273
|
+
/**
|
|
6274
|
+
* Execute a raw git command (repository-agnostic)
|
|
6275
|
+
*/
|
|
6276
|
+
get raw() {
|
|
6277
|
+
return this.git.raw.bind(this.git);
|
|
6278
|
+
}
|
|
6279
|
+
/**
|
|
6280
|
+
* Global config operations
|
|
6281
|
+
*
|
|
6282
|
+
* Operates on ~/.gitconfig (user-level configuration).
|
|
6283
|
+
* For repository-level config, use repo.config instead.
|
|
6284
|
+
*/
|
|
6285
|
+
get config() {
|
|
6286
|
+
return this.git.config;
|
|
6287
|
+
}
|
|
6288
|
+
/**
|
|
6289
|
+
* Global LFS operations
|
|
6290
|
+
*
|
|
6291
|
+
* Operates on ~/.gitconfig (user-level) or /etc/gitconfig (system-level).
|
|
6292
|
+
* For repository-level LFS operations, use repo.lfs instead.
|
|
6293
|
+
*
|
|
6294
|
+
* @example
|
|
6295
|
+
* ```typescript
|
|
6296
|
+
* // Install LFS globally
|
|
6297
|
+
* await git.lfs.install();
|
|
6298
|
+
*
|
|
6299
|
+
* // Install system-wide
|
|
6300
|
+
* await git.lfs.install({ system: true });
|
|
6301
|
+
*
|
|
6302
|
+
* // Get LFS version
|
|
6303
|
+
* const version = await git.lfs.version();
|
|
6304
|
+
* ```
|
|
6305
|
+
*/
|
|
6306
|
+
get lfs() {
|
|
6307
|
+
return this.git.lfs;
|
|
6308
|
+
}
|
|
6309
|
+
};
|
|
6310
|
+
|
|
6092
6311
|
// src/adapters/node/exec.ts
|
|
6093
6312
|
import { spawn } from "child_process";
|
|
6094
6313
|
function resolveChildEnv(env, inheritEnv) {
|
|
@@ -6100,7 +6319,7 @@ function resolveChildEnv(env, inheritEnv) {
|
|
|
6100
6319
|
async function* streamToAsyncIterable(stream) {
|
|
6101
6320
|
let buffer = "";
|
|
6102
6321
|
for await (const chunk of stream) {
|
|
6103
|
-
buffer += chunk
|
|
6322
|
+
buffer += chunk;
|
|
6104
6323
|
const lines = buffer.split("\n");
|
|
6105
6324
|
buffer = lines.pop() ?? "";
|
|
6106
6325
|
for (const line of lines) {
|
|
@@ -6129,12 +6348,17 @@ var NodeExecAdapter = class {
|
|
|
6129
6348
|
throw new Error("argv must not be empty");
|
|
6130
6349
|
}
|
|
6131
6350
|
const args = argv.slice(1);
|
|
6351
|
+
if (signal?.aborted) {
|
|
6352
|
+
return Promise.resolve({ stdout: "", stderr: "", exitCode: -1, aborted: true });
|
|
6353
|
+
}
|
|
6132
6354
|
return new Promise((resolve, reject) => {
|
|
6133
6355
|
const child = spawn(command, args, {
|
|
6134
6356
|
cwd,
|
|
6135
6357
|
env: resolveChildEnv(env, inheritEnv),
|
|
6136
6358
|
stdio: [options.stdin === void 0 ? "ignore" : "pipe", "pipe", "pipe"]
|
|
6137
6359
|
});
|
|
6360
|
+
child.stdout?.setEncoding("utf8");
|
|
6361
|
+
child.stderr?.setEncoding("utf8");
|
|
6138
6362
|
let stdout = "";
|
|
6139
6363
|
let stderr = "";
|
|
6140
6364
|
let aborted = false;
|
|
@@ -6152,12 +6376,12 @@ var NodeExecAdapter = class {
|
|
|
6152
6376
|
}
|
|
6153
6377
|
}
|
|
6154
6378
|
child.stdout?.on("data", (chunk) => {
|
|
6155
|
-
const text = chunk
|
|
6379
|
+
const text = chunk;
|
|
6156
6380
|
stdout += text;
|
|
6157
6381
|
handlers?.onStdout?.(text);
|
|
6158
6382
|
});
|
|
6159
6383
|
child.stderr?.on("data", (chunk) => {
|
|
6160
|
-
const text = chunk
|
|
6384
|
+
const text = chunk;
|
|
6161
6385
|
stderr += text;
|
|
6162
6386
|
handlers?.onStderr?.(text);
|
|
6163
6387
|
});
|
|
@@ -6172,6 +6396,7 @@ var NodeExecAdapter = class {
|
|
|
6172
6396
|
reject(error);
|
|
6173
6397
|
});
|
|
6174
6398
|
child.on("close", (code, sig) => {
|
|
6399
|
+
signal?.removeEventListener("abort", abortHandler);
|
|
6175
6400
|
if (sig) {
|
|
6176
6401
|
exitSignal = sig;
|
|
6177
6402
|
}
|
|
@@ -6212,13 +6437,15 @@ var NodeExecAdapter = class {
|
|
|
6212
6437
|
}
|
|
6213
6438
|
}
|
|
6214
6439
|
const waitPromise = new Promise((resolve, reject) => {
|
|
6440
|
+
child.stdout?.setEncoding("utf8");
|
|
6441
|
+
child.stderr?.setEncoding("utf8");
|
|
6215
6442
|
let stdout = "";
|
|
6216
6443
|
let stderr = "";
|
|
6217
6444
|
child.stdout?.on("data", (chunk) => {
|
|
6218
|
-
stdout += chunk
|
|
6445
|
+
stdout += chunk;
|
|
6219
6446
|
});
|
|
6220
6447
|
child.stderr?.on("data", (chunk) => {
|
|
6221
|
-
stderr += chunk
|
|
6448
|
+
stderr += chunk;
|
|
6222
6449
|
});
|
|
6223
6450
|
child.stdin?.on("error", (error) => {
|
|
6224
6451
|
if (error.code !== "EPIPE" && error.code !== "EOF") {
|
|
@@ -6485,114 +6712,14 @@ function createNodeAdapters() {
|
|
|
6485
6712
|
fs: new NodeFsAdapter()
|
|
6486
6713
|
};
|
|
6487
6714
|
}
|
|
6488
|
-
var TypeGit = class _TypeGit {
|
|
6489
|
-
|
|
6490
|
-
|
|
6491
|
-
* Create a TypeGit instance with Git version check
|
|
6492
|
-
*
|
|
6493
|
-
* @param createOpts - Options including skipVersionCheck
|
|
6494
|
-
* @returns TypeGit instance
|
|
6495
|
-
* @throws GitError with kind 'UnsupportedGitVersion' if Git version is below minimum
|
|
6496
|
-
*/
|
|
6497
|
-
static async create(createOpts) {
|
|
6498
|
-
const gitInstance = await createGit({
|
|
6499
|
-
...createOpts,
|
|
6500
|
-
adapters: createNodeAdapters()
|
|
6501
|
-
});
|
|
6502
|
-
return new _TypeGit(gitInstance);
|
|
6715
|
+
var TypeGit = class _TypeGit extends GitClient {
|
|
6716
|
+
static async create(options) {
|
|
6717
|
+
return new _TypeGit(await createGit({ ...options, adapters: createNodeAdapters() }));
|
|
6503
6718
|
}
|
|
6504
6719
|
constructor(optionsOrGit) {
|
|
6505
|
-
|
|
6506
|
-
|
|
6507
|
-
|
|
6508
|
-
this.git = createGitSync({
|
|
6509
|
-
...optionsOrGit,
|
|
6510
|
-
adapters: createNodeAdapters()
|
|
6511
|
-
});
|
|
6512
|
-
}
|
|
6513
|
-
}
|
|
6514
|
-
/**
|
|
6515
|
-
* Open an existing worktree repository
|
|
6516
|
-
*
|
|
6517
|
-
* This is the most common use case. Throws GitError if the repository is bare.
|
|
6518
|
-
*
|
|
6519
|
-
* @throws GitError with kind 'NotWorktreeRepo' if the repository is bare
|
|
6520
|
-
*/
|
|
6521
|
-
get open() {
|
|
6522
|
-
return this.git.open.bind(this.git);
|
|
6523
|
-
}
|
|
6524
|
-
/**
|
|
6525
|
-
* Open an existing bare repository
|
|
6526
|
-
*
|
|
6527
|
-
* Throws GitError if the repository is not bare.
|
|
6528
|
-
*
|
|
6529
|
-
* @throws GitError with kind 'NotBareRepo' if the repository is not bare
|
|
6530
|
-
*/
|
|
6531
|
-
get openBare() {
|
|
6532
|
-
return this.git.openBare.bind(this.git);
|
|
6533
|
-
}
|
|
6534
|
-
/**
|
|
6535
|
-
* Open an existing repository without type guarantee
|
|
6536
|
-
*
|
|
6537
|
-
* Returns either WorktreeRepo or BareRepo depending on the repository type.
|
|
6538
|
-
* Use this when you don't know the repository type at compile time.
|
|
6539
|
-
*/
|
|
6540
|
-
get openRaw() {
|
|
6541
|
-
return this.git.openRaw.bind(this.git);
|
|
6542
|
-
}
|
|
6543
|
-
clone(url, path, opts) {
|
|
6544
|
-
return this.git.clone(url, path, opts);
|
|
6545
|
-
}
|
|
6546
|
-
init(path, opts) {
|
|
6547
|
-
return this.git.init(path, opts);
|
|
6548
|
-
}
|
|
6549
|
-
/**
|
|
6550
|
-
* List references in a remote repository
|
|
6551
|
-
*/
|
|
6552
|
-
get lsRemote() {
|
|
6553
|
-
return this.git.lsRemote.bind(this.git);
|
|
6554
|
-
}
|
|
6555
|
-
/**
|
|
6556
|
-
* Get git version
|
|
6557
|
-
*/
|
|
6558
|
-
get version() {
|
|
6559
|
-
return this.git.version.bind(this.git);
|
|
6560
|
-
}
|
|
6561
|
-
/**
|
|
6562
|
-
* Execute a raw git command (repository-agnostic)
|
|
6563
|
-
*/
|
|
6564
|
-
get raw() {
|
|
6565
|
-
return this.git.raw.bind(this.git);
|
|
6566
|
-
}
|
|
6567
|
-
/**
|
|
6568
|
-
* Global config operations
|
|
6569
|
-
*
|
|
6570
|
-
* Operates on ~/.gitconfig (user-level configuration).
|
|
6571
|
-
* For repository-level config, use repo.config instead.
|
|
6572
|
-
*/
|
|
6573
|
-
get config() {
|
|
6574
|
-
return this.git.config;
|
|
6575
|
-
}
|
|
6576
|
-
/**
|
|
6577
|
-
* Global LFS operations
|
|
6578
|
-
*
|
|
6579
|
-
* Operates on ~/.gitconfig (user-level) or /etc/gitconfig (system-level).
|
|
6580
|
-
* For repository-level LFS operations, use repo.lfs instead.
|
|
6581
|
-
*
|
|
6582
|
-
* @example
|
|
6583
|
-
* ```typescript
|
|
6584
|
-
* // Install LFS globally
|
|
6585
|
-
* await git.lfs.install();
|
|
6586
|
-
*
|
|
6587
|
-
* // Install system-wide
|
|
6588
|
-
* await git.lfs.install({ system: true });
|
|
6589
|
-
*
|
|
6590
|
-
* // Get LFS version
|
|
6591
|
-
* const version = await git.lfs.version();
|
|
6592
|
-
* ```
|
|
6593
|
-
*/
|
|
6594
|
-
get lfs() {
|
|
6595
|
-
return this.git.lfs;
|
|
6720
|
+
super(
|
|
6721
|
+
optionsOrGit && "open" in optionsOrGit ? optionsOrGit : createGitSync({ ...optionsOrGit, adapters: createNodeAdapters() })
|
|
6722
|
+
);
|
|
6596
6723
|
}
|
|
6597
6724
|
};
|
|
6598
6725
|
export {
|