type-git 0.0.3 → 0.1.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 +33 -4
- package/dist/adapters/bun/index.cjs +115 -89
- package/dist/adapters/bun/index.cjs.map +1 -1
- package/dist/adapters/bun/index.d.cts +1 -1
- package/dist/adapters/bun/index.d.ts +1 -1
- package/dist/adapters/bun/index.js +115 -89
- package/dist/adapters/bun/index.js.map +1 -1
- package/dist/adapters/deno/index.cjs +126 -97
- package/dist/adapters/deno/index.cjs.map +1 -1
- package/dist/adapters/deno/index.d.cts +1 -1
- package/dist/adapters/deno/index.d.ts +1 -1
- package/dist/adapters/deno/index.js +126 -97
- package/dist/adapters/deno/index.js.map +1 -1
- package/dist/adapters/node/index.cjs +956 -327
- package/dist/adapters/node/index.cjs.map +1 -1
- package/dist/adapters/node/index.d.cts +4233 -2
- package/dist/adapters/node/index.d.ts +4233 -2
- package/dist/adapters/node/index.js +956 -327
- package/dist/adapters/node/index.js.map +1 -1
- package/dist/{adapters-w9tZ_Qbd.d.cts → adapters-DehG3CsV.d.cts} +4 -2
- package/dist/{adapters-w9tZ_Qbd.d.ts → adapters-DehG3CsV.d.ts} +4 -2
- package/dist/index.cjs +968 -329
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -208
- package/dist/index.d.ts +2 -208
- package/dist/index.js +964 -329
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/index-D9acU30I.d.ts +0 -3649
- package/dist/index-DRd85eN5.d.cts +0 -3649
|
@@ -63,6 +63,14 @@ var GitError = class extends Error {
|
|
|
63
63
|
};
|
|
64
64
|
|
|
65
65
|
// src/parsers/index.ts
|
|
66
|
+
var GIT_PROGRESS_PERCENT_REGEX = /^(.+?):\s*(\d+)%\s*\((\d+)\/(\d+)\)(?:,\s*(done))?/;
|
|
67
|
+
var GIT_PROGRESS_SIMPLE_REGEX = /^(.+?):\s*(\d+)\/(\d+)/;
|
|
68
|
+
var SIZE_REGEX = /^([\d.]+)\s*(B|KB|MB|GB|TB)?$/i;
|
|
69
|
+
var BITRATE_REGEX = /^([\d.]+)\s*(B|KB|MB|GB)\/s$/i;
|
|
70
|
+
var LFS_DOWNLOAD_REGEX = /downloading|filtering/i;
|
|
71
|
+
var LFS_UPLOAD_REGEX = /uploading/i;
|
|
72
|
+
var LFS_CHECKOUT_REGEX = /checking out/i;
|
|
73
|
+
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;
|
|
66
74
|
function at(arr, index, context) {
|
|
67
75
|
const value = arr[index];
|
|
68
76
|
if (value === void 0) {
|
|
@@ -140,7 +148,7 @@ function parsePorcelainV2(stdout) {
|
|
|
140
148
|
return entries;
|
|
141
149
|
}
|
|
142
150
|
function parseGitProgress(line) {
|
|
143
|
-
const match = line.match(
|
|
151
|
+
const match = line.match(GIT_PROGRESS_PERCENT_REGEX);
|
|
144
152
|
if (match) {
|
|
145
153
|
const percent = match[2];
|
|
146
154
|
const current = match[3];
|
|
@@ -156,7 +164,7 @@ function parseGitProgress(line) {
|
|
|
156
164
|
done: match[5] === "done"
|
|
157
165
|
};
|
|
158
166
|
}
|
|
159
|
-
const simpleMatch = line.match(
|
|
167
|
+
const simpleMatch = line.match(GIT_PROGRESS_SIMPLE_REGEX);
|
|
160
168
|
if (simpleMatch) {
|
|
161
169
|
const currentStr = simpleMatch[2];
|
|
162
170
|
const totalStr = simpleMatch[3];
|
|
@@ -176,7 +184,7 @@ function parseGitProgress(line) {
|
|
|
176
184
|
return null;
|
|
177
185
|
}
|
|
178
186
|
function parseSizeToBytes(sizeStr) {
|
|
179
|
-
const match = sizeStr.match(
|
|
187
|
+
const match = sizeStr.match(SIZE_REGEX);
|
|
180
188
|
if (!match) {
|
|
181
189
|
return 0;
|
|
182
190
|
}
|
|
@@ -192,7 +200,7 @@ function parseSizeToBytes(sizeStr) {
|
|
|
192
200
|
return Math.round(value * (multipliers[unit] || 1));
|
|
193
201
|
}
|
|
194
202
|
function parseBitrateToBytes(bitrateStr) {
|
|
195
|
-
const match = bitrateStr.match(
|
|
203
|
+
const match = bitrateStr.match(BITRATE_REGEX);
|
|
196
204
|
if (!match) {
|
|
197
205
|
return null;
|
|
198
206
|
}
|
|
@@ -208,18 +216,16 @@ function parseBitrateToBytes(bitrateStr) {
|
|
|
208
216
|
}
|
|
209
217
|
function parseLfsStderrProgress(line) {
|
|
210
218
|
let direction;
|
|
211
|
-
if (
|
|
219
|
+
if (LFS_DOWNLOAD_REGEX.test(line)) {
|
|
212
220
|
direction = "download";
|
|
213
|
-
} else if (
|
|
221
|
+
} else if (LFS_UPLOAD_REGEX.test(line)) {
|
|
214
222
|
direction = "upload";
|
|
215
|
-
} else if (
|
|
223
|
+
} else if (LFS_CHECKOUT_REGEX.test(line)) {
|
|
216
224
|
direction = "checkout";
|
|
217
225
|
} else {
|
|
218
226
|
return null;
|
|
219
227
|
}
|
|
220
|
-
const progressMatch = line.match(
|
|
221
|
-
/(\d+)%\s*\((\d+)\/(\d+)\)(?:,\s*([\d.]+\s*(?:B|KB|MB|GB|TB)?)\s*(?:\|\s*([\d.]+\s*(?:B|KB|MB|GB)\/s))?)?/i
|
|
222
|
-
);
|
|
228
|
+
const progressMatch = line.match(LFS_PROGRESS_REGEX);
|
|
223
229
|
if (!progressMatch) {
|
|
224
230
|
return null;
|
|
225
231
|
}
|
|
@@ -260,6 +266,68 @@ function parseLsRemote(stdout) {
|
|
|
260
266
|
}
|
|
261
267
|
return refs;
|
|
262
268
|
}
|
|
269
|
+
var LS_TREE_REGEX = /^(\d+)\s+(blob|tree|commit)\s+([a-f0-9]+)\t(.+)$/;
|
|
270
|
+
var LS_TREE_LONG_REGEX = /^(\d+)\s+(blob|tree|commit)\s+([a-f0-9]+)\s+(-|\d+)\t(.+)$/;
|
|
271
|
+
function parseLsTree(stdout, opts) {
|
|
272
|
+
const entries = [];
|
|
273
|
+
const lines = parseLines(stdout);
|
|
274
|
+
for (const line of lines) {
|
|
275
|
+
if (opts?.nameOnly) {
|
|
276
|
+
entries.push({
|
|
277
|
+
mode: "",
|
|
278
|
+
type: "blob",
|
|
279
|
+
hash: "",
|
|
280
|
+
path: line
|
|
281
|
+
});
|
|
282
|
+
continue;
|
|
283
|
+
}
|
|
284
|
+
if (opts?.objectOnly) {
|
|
285
|
+
entries.push({
|
|
286
|
+
mode: "",
|
|
287
|
+
type: "blob",
|
|
288
|
+
hash: line,
|
|
289
|
+
path: ""
|
|
290
|
+
});
|
|
291
|
+
continue;
|
|
292
|
+
}
|
|
293
|
+
if (opts?.long) {
|
|
294
|
+
const longMatch = line.match(LS_TREE_LONG_REGEX);
|
|
295
|
+
if (longMatch) {
|
|
296
|
+
const mode = longMatch[1];
|
|
297
|
+
const type = longMatch[2];
|
|
298
|
+
const hash = longMatch[3];
|
|
299
|
+
const sizeStr = longMatch[4];
|
|
300
|
+
const path = longMatch[5];
|
|
301
|
+
if (mode && type && hash && path) {
|
|
302
|
+
entries.push({
|
|
303
|
+
mode,
|
|
304
|
+
type,
|
|
305
|
+
hash,
|
|
306
|
+
path,
|
|
307
|
+
size: sizeStr === "-" || !sizeStr ? void 0 : Number.parseInt(sizeStr, 10)
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
continue;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
const match = line.match(LS_TREE_REGEX);
|
|
314
|
+
if (match) {
|
|
315
|
+
const mode = match[1];
|
|
316
|
+
const type = match[2];
|
|
317
|
+
const hash = match[3];
|
|
318
|
+
const path = match[4];
|
|
319
|
+
if (mode && type && hash && path) {
|
|
320
|
+
entries.push({
|
|
321
|
+
mode,
|
|
322
|
+
type,
|
|
323
|
+
hash,
|
|
324
|
+
path
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
return entries;
|
|
330
|
+
}
|
|
263
331
|
var GIT_LOG_FORMAT = "%H%x00%h%x00%P%x00%an%x00%ae%x00%at%x00%cn%x00%ce%x00%ct%x00%s%x00%b%x01";
|
|
264
332
|
function parseGitLog(stdout) {
|
|
265
333
|
const commits = [];
|
|
@@ -391,6 +459,51 @@ var import_node_process = __toESM(require("process"), 1);
|
|
|
391
459
|
var FATAL_ERROR_PATTERN = /fatal:\s*(.+)/i;
|
|
392
460
|
var ERROR_PATTERN = /error:\s*(.+)/i;
|
|
393
461
|
var LINE_SEPARATOR_PATTERN = /\r|\n/;
|
|
462
|
+
function toLfsProgress(info) {
|
|
463
|
+
if (!info) {
|
|
464
|
+
return null;
|
|
465
|
+
}
|
|
466
|
+
return {
|
|
467
|
+
direction: info.direction,
|
|
468
|
+
bytesSoFar: info.bytesSoFar,
|
|
469
|
+
bytesTotal: info.bytesTotal,
|
|
470
|
+
bitrate: info.bitrate ?? void 0,
|
|
471
|
+
filesCompleted: info.filesCompleted,
|
|
472
|
+
filesTotal: info.filesTotal,
|
|
473
|
+
percent: info.percent
|
|
474
|
+
};
|
|
475
|
+
}
|
|
476
|
+
function toGitProgress(info, message) {
|
|
477
|
+
if (!info) {
|
|
478
|
+
return null;
|
|
479
|
+
}
|
|
480
|
+
return {
|
|
481
|
+
phase: info.phase,
|
|
482
|
+
current: info.current,
|
|
483
|
+
total: info.total,
|
|
484
|
+
percent: info.percent,
|
|
485
|
+
message
|
|
486
|
+
};
|
|
487
|
+
}
|
|
488
|
+
function processProgressLine(line, onProgress, onLfsProgress) {
|
|
489
|
+
const trimmed = line.trim();
|
|
490
|
+
if (!trimmed) {
|
|
491
|
+
return;
|
|
492
|
+
}
|
|
493
|
+
if (onLfsProgress) {
|
|
494
|
+
const lfsProgress = toLfsProgress(parseLfsStderrProgress(trimmed));
|
|
495
|
+
if (lfsProgress) {
|
|
496
|
+
onLfsProgress(lfsProgress);
|
|
497
|
+
return;
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
if (onProgress) {
|
|
501
|
+
const gitProgress = toGitProgress(parseGitProgress(trimmed), trimmed);
|
|
502
|
+
if (gitProgress) {
|
|
503
|
+
onProgress(gitProgress);
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
}
|
|
394
507
|
var CliRunner = class _CliRunner {
|
|
395
508
|
exec;
|
|
396
509
|
gitBinary;
|
|
@@ -517,73 +630,13 @@ var CliRunner = class _CliRunner {
|
|
|
517
630
|
const lines = stderrBuffer.split(LINE_SEPARATOR_PATTERN);
|
|
518
631
|
stderrBuffer = lines.pop() ?? "";
|
|
519
632
|
for (const line of lines) {
|
|
520
|
-
|
|
521
|
-
if (!trimmed) {
|
|
522
|
-
continue;
|
|
523
|
-
}
|
|
524
|
-
if (onLfsProgress) {
|
|
525
|
-
const lfsProgressInfo = parseLfsStderrProgress(trimmed);
|
|
526
|
-
if (lfsProgressInfo) {
|
|
527
|
-
const lfsProgress = {
|
|
528
|
-
direction: lfsProgressInfo.direction,
|
|
529
|
-
bytesSoFar: lfsProgressInfo.bytesSoFar,
|
|
530
|
-
bytesTotal: lfsProgressInfo.bytesTotal,
|
|
531
|
-
bitrate: lfsProgressInfo.bitrate ?? void 0,
|
|
532
|
-
filesCompleted: lfsProgressInfo.filesCompleted,
|
|
533
|
-
filesTotal: lfsProgressInfo.filesTotal,
|
|
534
|
-
percent: lfsProgressInfo.percent
|
|
535
|
-
};
|
|
536
|
-
onLfsProgress(lfsProgress);
|
|
537
|
-
continue;
|
|
538
|
-
}
|
|
539
|
-
}
|
|
540
|
-
if (onProgress) {
|
|
541
|
-
const gitProgressInfo = parseGitProgress(trimmed);
|
|
542
|
-
if (gitProgressInfo) {
|
|
543
|
-
const gitProgress = {
|
|
544
|
-
phase: gitProgressInfo.phase,
|
|
545
|
-
current: gitProgressInfo.current,
|
|
546
|
-
total: gitProgressInfo.total,
|
|
547
|
-
percent: gitProgressInfo.percent,
|
|
548
|
-
message: trimmed
|
|
549
|
-
};
|
|
550
|
-
onProgress(gitProgress);
|
|
551
|
-
}
|
|
552
|
-
}
|
|
633
|
+
processProgressLine(line, onProgress, onLfsProgress);
|
|
553
634
|
}
|
|
554
635
|
}
|
|
555
636
|
} : void 0
|
|
556
637
|
);
|
|
557
638
|
if (stderrBuffer.trim() && (onProgress || onLfsProgress)) {
|
|
558
|
-
|
|
559
|
-
if (onLfsProgress) {
|
|
560
|
-
const lfsProgressInfo = parseLfsStderrProgress(trimmed);
|
|
561
|
-
if (lfsProgressInfo) {
|
|
562
|
-
const lfsProgress = {
|
|
563
|
-
direction: lfsProgressInfo.direction,
|
|
564
|
-
bytesSoFar: lfsProgressInfo.bytesSoFar,
|
|
565
|
-
bytesTotal: lfsProgressInfo.bytesTotal,
|
|
566
|
-
bitrate: lfsProgressInfo.bitrate ?? void 0,
|
|
567
|
-
filesCompleted: lfsProgressInfo.filesCompleted,
|
|
568
|
-
filesTotal: lfsProgressInfo.filesTotal,
|
|
569
|
-
percent: lfsProgressInfo.percent
|
|
570
|
-
};
|
|
571
|
-
onLfsProgress(lfsProgress);
|
|
572
|
-
}
|
|
573
|
-
}
|
|
574
|
-
if (onProgress && !onLfsProgress) {
|
|
575
|
-
const gitProgressInfo = parseGitProgress(trimmed);
|
|
576
|
-
if (gitProgressInfo) {
|
|
577
|
-
const gitProgress = {
|
|
578
|
-
phase: gitProgressInfo.phase,
|
|
579
|
-
current: gitProgressInfo.current,
|
|
580
|
-
total: gitProgressInfo.total,
|
|
581
|
-
percent: gitProgressInfo.percent,
|
|
582
|
-
message: trimmed
|
|
583
|
-
};
|
|
584
|
-
onProgress(gitProgress);
|
|
585
|
-
}
|
|
586
|
-
}
|
|
639
|
+
processProgressLine(stderrBuffer, onProgress, onLfsProgress);
|
|
587
640
|
}
|
|
588
641
|
return {
|
|
589
642
|
stdout: result.stdout,
|
|
@@ -668,6 +721,196 @@ var CliRunner = class _CliRunner {
|
|
|
668
721
|
};
|
|
669
722
|
|
|
670
723
|
// src/impl/bare-repo-impl.ts
|
|
724
|
+
var REMOTE_LINE_PATTERN = /^(\S+)\t(.+?)\s+\((fetch|push)\)$/;
|
|
725
|
+
var PRUNED_REF_PATTERN = /\* \[pruned\] (.+)/;
|
|
726
|
+
function parseRemoteLine(line, remotes) {
|
|
727
|
+
const match = line.match(REMOTE_LINE_PATTERN);
|
|
728
|
+
if (!match) {
|
|
729
|
+
return;
|
|
730
|
+
}
|
|
731
|
+
const name = match[1];
|
|
732
|
+
const url = match[2];
|
|
733
|
+
const type = match[3];
|
|
734
|
+
if (name === void 0 || url === void 0) {
|
|
735
|
+
return;
|
|
736
|
+
}
|
|
737
|
+
const existing = remotes.get(name);
|
|
738
|
+
if (existing) {
|
|
739
|
+
updateRemoteUrl(existing, type, url);
|
|
740
|
+
} else {
|
|
741
|
+
remotes.set(name, {
|
|
742
|
+
name,
|
|
743
|
+
fetchUrl: type === "fetch" ? url : "",
|
|
744
|
+
pushUrl: type === "push" ? url : ""
|
|
745
|
+
});
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
function updateRemoteUrl(remote, type, url) {
|
|
749
|
+
if (type === "fetch") {
|
|
750
|
+
remote.fetchUrl = url;
|
|
751
|
+
} else if (type === "push") {
|
|
752
|
+
remote.pushUrl = url;
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
function normalizeRemoteUrls(remotes) {
|
|
756
|
+
for (const remote of remotes.values()) {
|
|
757
|
+
if (!remote.fetchUrl && remote.pushUrl) {
|
|
758
|
+
remote.fetchUrl = remote.pushUrl;
|
|
759
|
+
}
|
|
760
|
+
if (!remote.pushUrl && remote.fetchUrl) {
|
|
761
|
+
remote.pushUrl = remote.fetchUrl;
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
function addRefOptions(args, opts) {
|
|
766
|
+
if (!opts) {
|
|
767
|
+
return;
|
|
768
|
+
}
|
|
769
|
+
if (opts.verify) {
|
|
770
|
+
args.push("--verify");
|
|
771
|
+
}
|
|
772
|
+
if (opts.short !== void 0) {
|
|
773
|
+
if (typeof opts.short === "number") {
|
|
774
|
+
args.push(`--short=${opts.short}`);
|
|
775
|
+
} else if (opts.short) {
|
|
776
|
+
args.push("--short");
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
if (opts.abbrevRef !== void 0) {
|
|
780
|
+
if (opts.abbrevRef === "strict") {
|
|
781
|
+
args.push("--abbrev-ref=strict");
|
|
782
|
+
} else if (opts.abbrevRef === "loose") {
|
|
783
|
+
args.push("--abbrev-ref=loose");
|
|
784
|
+
} else if (opts.abbrevRef) {
|
|
785
|
+
args.push("--abbrev-ref");
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
if (opts.symbolic) {
|
|
789
|
+
args.push("--symbolic");
|
|
790
|
+
}
|
|
791
|
+
if (opts.symbolicFullName) {
|
|
792
|
+
args.push("--symbolic-full-name");
|
|
793
|
+
}
|
|
794
|
+
if (opts.quiet) {
|
|
795
|
+
args.push("--quiet");
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
var PATH_QUERY_FLAGS = [
|
|
799
|
+
["gitDir", "--git-dir"],
|
|
800
|
+
["absoluteGitDir", "--absolute-git-dir"],
|
|
801
|
+
["gitCommonDir", "--git-common-dir"],
|
|
802
|
+
["showToplevel", "--show-toplevel"],
|
|
803
|
+
["showCdup", "--show-cdup"],
|
|
804
|
+
["showPrefix", "--show-prefix"],
|
|
805
|
+
["showSuperprojectWorkingTree", "--show-superproject-working-tree"],
|
|
806
|
+
["sharedIndexPath", "--shared-index-path"]
|
|
807
|
+
];
|
|
808
|
+
var PATH_QUERY_VALUE_FLAGS = [
|
|
809
|
+
["gitPath", "--git-path"],
|
|
810
|
+
["resolveGitDir", "--resolve-git-dir"]
|
|
811
|
+
];
|
|
812
|
+
var BOOLEAN_QUERY_FLAGS = [
|
|
813
|
+
["isInsideGitDir", "--is-inside-git-dir"],
|
|
814
|
+
["isInsideWorkTree", "--is-inside-work-tree"],
|
|
815
|
+
["isBareRepository", "--is-bare-repository"],
|
|
816
|
+
["isShallowRepository", "--is-shallow-repository"]
|
|
817
|
+
];
|
|
818
|
+
var LIST_QUERY_FLAGS = [
|
|
819
|
+
["all", "--all"],
|
|
820
|
+
["branches", "--branches"],
|
|
821
|
+
["tags", "--tags"],
|
|
822
|
+
["remotes", "--remotes"]
|
|
823
|
+
];
|
|
824
|
+
function addExcludeOptions(args, opts) {
|
|
825
|
+
if ("exclude" in opts && opts.exclude) {
|
|
826
|
+
args.push(`--exclude=${opts.exclude}`);
|
|
827
|
+
}
|
|
828
|
+
if ("excludeHidden" in opts && opts.excludeHidden) {
|
|
829
|
+
args.push(`--exclude-hidden=${opts.excludeHidden}`);
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
function tryAddPathQuery(args, opts) {
|
|
833
|
+
for (const [key, flag] of PATH_QUERY_FLAGS) {
|
|
834
|
+
if (key in opts && opts[key]) {
|
|
835
|
+
args.push(flag);
|
|
836
|
+
return true;
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
for (const [key, flag] of PATH_QUERY_VALUE_FLAGS) {
|
|
840
|
+
if (key in opts && typeof opts[key] === "string") {
|
|
841
|
+
args.push(flag, opts[key]);
|
|
842
|
+
return true;
|
|
843
|
+
}
|
|
844
|
+
}
|
|
845
|
+
return false;
|
|
846
|
+
}
|
|
847
|
+
function tryAddBooleanQuery(args, opts) {
|
|
848
|
+
for (const [key, flag] of BOOLEAN_QUERY_FLAGS) {
|
|
849
|
+
if (key in opts && opts[key]) {
|
|
850
|
+
args.push(flag);
|
|
851
|
+
return true;
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
return false;
|
|
855
|
+
}
|
|
856
|
+
function tryAddListQuery(args, opts) {
|
|
857
|
+
for (const [key, flag] of LIST_QUERY_FLAGS) {
|
|
858
|
+
if (key in opts && opts[key]) {
|
|
859
|
+
addExcludeOptions(args, opts);
|
|
860
|
+
if (typeof opts[key] === "string") {
|
|
861
|
+
args.push(`${flag}=${opts[key]}`);
|
|
862
|
+
} else {
|
|
863
|
+
args.push(flag);
|
|
864
|
+
}
|
|
865
|
+
return true;
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
if ("glob" in opts && typeof opts.glob === "string") {
|
|
869
|
+
addExcludeOptions(args, opts);
|
|
870
|
+
args.push(`--glob=${opts.glob}`);
|
|
871
|
+
return true;
|
|
872
|
+
}
|
|
873
|
+
if ("disambiguate" in opts && typeof opts.disambiguate === "string") {
|
|
874
|
+
args.push(`--disambiguate=${opts.disambiguate}`);
|
|
875
|
+
return true;
|
|
876
|
+
}
|
|
877
|
+
return false;
|
|
878
|
+
}
|
|
879
|
+
function tryAddOtherQuery(args, opts) {
|
|
880
|
+
if ("showObjectFormat" in opts && opts.showObjectFormat) {
|
|
881
|
+
if (opts.showObjectFormat === true) {
|
|
882
|
+
args.push("--show-object-format");
|
|
883
|
+
} else {
|
|
884
|
+
args.push(`--show-object-format=${opts.showObjectFormat}`);
|
|
885
|
+
}
|
|
886
|
+
return true;
|
|
887
|
+
}
|
|
888
|
+
if ("showRefFormat" in opts && opts.showRefFormat) {
|
|
889
|
+
args.push("--show-ref-format");
|
|
890
|
+
return true;
|
|
891
|
+
}
|
|
892
|
+
if ("localEnvVars" in opts && opts.localEnvVars) {
|
|
893
|
+
args.push("--local-env-vars");
|
|
894
|
+
return true;
|
|
895
|
+
}
|
|
896
|
+
return false;
|
|
897
|
+
}
|
|
898
|
+
function isBooleanQuery(opts) {
|
|
899
|
+
for (const [key] of BOOLEAN_QUERY_FLAGS) {
|
|
900
|
+
if (key in opts && opts[key]) {
|
|
901
|
+
return true;
|
|
902
|
+
}
|
|
903
|
+
}
|
|
904
|
+
return false;
|
|
905
|
+
}
|
|
906
|
+
function isListQuery(opts) {
|
|
907
|
+
for (const [key] of LIST_QUERY_FLAGS) {
|
|
908
|
+
if (key in opts && opts[key]) {
|
|
909
|
+
return true;
|
|
910
|
+
}
|
|
911
|
+
}
|
|
912
|
+
return "glob" in opts && !!opts.glob || "disambiguate" in opts && !!opts.disambiguate || "localEnvVars" in opts && !!opts.localEnvVars;
|
|
913
|
+
}
|
|
671
914
|
var BareRepoImpl = class {
|
|
672
915
|
gitDir;
|
|
673
916
|
runner;
|
|
@@ -730,6 +973,116 @@ var BareRepoImpl = class {
|
|
|
730
973
|
const result = await this.runner.run(this.context, ["rev-parse", "--is-bare-repository"]);
|
|
731
974
|
return result.exitCode === 0 && result.stdout.trim() === "true";
|
|
732
975
|
}
|
|
976
|
+
/**
|
|
977
|
+
* List references in a remote repository
|
|
978
|
+
*/
|
|
979
|
+
async lsRemote(remote, opts) {
|
|
980
|
+
const args = ["ls-remote"];
|
|
981
|
+
if (opts?.heads) {
|
|
982
|
+
args.push("--heads");
|
|
983
|
+
}
|
|
984
|
+
if (opts?.tags) {
|
|
985
|
+
args.push("--tags");
|
|
986
|
+
}
|
|
987
|
+
if (opts?.refsOnly) {
|
|
988
|
+
args.push("--refs");
|
|
989
|
+
}
|
|
990
|
+
if (opts?.getUrl) {
|
|
991
|
+
args.push("--get-url");
|
|
992
|
+
}
|
|
993
|
+
if (opts?.sort) {
|
|
994
|
+
args.push("--sort", opts.sort);
|
|
995
|
+
}
|
|
996
|
+
if (opts?.symref) {
|
|
997
|
+
args.push("--symref");
|
|
998
|
+
}
|
|
999
|
+
args.push(remote);
|
|
1000
|
+
if (opts?.refs && opts.refs.length > 0) {
|
|
1001
|
+
args.push(...opts.refs);
|
|
1002
|
+
}
|
|
1003
|
+
const result = await this.runner.runOrThrow(this.context, args, {
|
|
1004
|
+
signal: opts?.signal,
|
|
1005
|
+
onProgress: opts?.onProgress
|
|
1006
|
+
});
|
|
1007
|
+
const refs = parseLsRemote(result.stdout);
|
|
1008
|
+
return { refs };
|
|
1009
|
+
}
|
|
1010
|
+
/**
|
|
1011
|
+
* List contents of a tree object
|
|
1012
|
+
*/
|
|
1013
|
+
async lsTree(treeish, opts) {
|
|
1014
|
+
const args = ["ls-tree"];
|
|
1015
|
+
if (opts?.recursive) {
|
|
1016
|
+
args.push("-r");
|
|
1017
|
+
}
|
|
1018
|
+
if (opts?.treeOnly) {
|
|
1019
|
+
args.push("-d");
|
|
1020
|
+
}
|
|
1021
|
+
if (opts?.showTrees) {
|
|
1022
|
+
args.push("-t");
|
|
1023
|
+
}
|
|
1024
|
+
if (opts?.long) {
|
|
1025
|
+
args.push("--long");
|
|
1026
|
+
}
|
|
1027
|
+
if (opts?.nameOnly) {
|
|
1028
|
+
args.push("--name-only");
|
|
1029
|
+
}
|
|
1030
|
+
if (opts?.objectOnly) {
|
|
1031
|
+
args.push("--object-only");
|
|
1032
|
+
}
|
|
1033
|
+
if (opts?.fullName) {
|
|
1034
|
+
args.push("--full-name");
|
|
1035
|
+
}
|
|
1036
|
+
if (opts?.fullTree) {
|
|
1037
|
+
args.push("--full-tree");
|
|
1038
|
+
}
|
|
1039
|
+
if (opts?.abbrev !== void 0) {
|
|
1040
|
+
if (opts.abbrev === true) {
|
|
1041
|
+
args.push("--abbrev");
|
|
1042
|
+
} else if (typeof opts.abbrev === "number") {
|
|
1043
|
+
args.push(`--abbrev=${opts.abbrev}`);
|
|
1044
|
+
}
|
|
1045
|
+
}
|
|
1046
|
+
args.push(treeish);
|
|
1047
|
+
if (opts?.paths && opts.paths.length > 0) {
|
|
1048
|
+
args.push("--", ...opts.paths);
|
|
1049
|
+
}
|
|
1050
|
+
const result = await this.runner.runOrThrow(this.context, args, {
|
|
1051
|
+
signal: opts?.signal
|
|
1052
|
+
});
|
|
1053
|
+
return parseLsTree(result.stdout, {
|
|
1054
|
+
nameOnly: opts?.nameOnly,
|
|
1055
|
+
objectOnly: opts?.objectOnly,
|
|
1056
|
+
long: opts?.long
|
|
1057
|
+
});
|
|
1058
|
+
}
|
|
1059
|
+
async revParse(refOrOpts, opts) {
|
|
1060
|
+
const args = ["rev-parse"];
|
|
1061
|
+
if (typeof refOrOpts === "string") {
|
|
1062
|
+
addRefOptions(args, opts);
|
|
1063
|
+
args.push(refOrOpts);
|
|
1064
|
+
const result2 = await this.runner.runOrThrow(this.context, args, {
|
|
1065
|
+
signal: opts?.signal
|
|
1066
|
+
});
|
|
1067
|
+
return result2.stdout.trim();
|
|
1068
|
+
}
|
|
1069
|
+
const queryOpts = refOrOpts;
|
|
1070
|
+
tryAddPathQuery(args, queryOpts) || tryAddBooleanQuery(args, queryOpts) || tryAddListQuery(args, queryOpts) || tryAddOtherQuery(args, queryOpts);
|
|
1071
|
+
if ("pathFormat" in queryOpts && queryOpts.pathFormat) {
|
|
1072
|
+
args.push(`--path-format=${queryOpts.pathFormat}`);
|
|
1073
|
+
}
|
|
1074
|
+
const result = await this.runner.runOrThrow(this.context, args, {
|
|
1075
|
+
signal: refOrOpts.signal
|
|
1076
|
+
});
|
|
1077
|
+
const output = result.stdout.trim();
|
|
1078
|
+
if (isBooleanQuery(queryOpts)) {
|
|
1079
|
+
return output === "true";
|
|
1080
|
+
}
|
|
1081
|
+
if (isListQuery(queryOpts)) {
|
|
1082
|
+
return output ? output.split("\n").filter((line) => line.length > 0) : [];
|
|
1083
|
+
}
|
|
1084
|
+
return output;
|
|
1085
|
+
}
|
|
733
1086
|
/**
|
|
734
1087
|
* Fetch from remote
|
|
735
1088
|
*/
|
|
@@ -797,37 +1150,9 @@ var BareRepoImpl = class {
|
|
|
797
1150
|
});
|
|
798
1151
|
const remotes = /* @__PURE__ */ new Map();
|
|
799
1152
|
for (const line of parseLines(result.stdout)) {
|
|
800
|
-
|
|
801
|
-
if (match) {
|
|
802
|
-
const name = match[1];
|
|
803
|
-
const url = match[2];
|
|
804
|
-
const type = match[3];
|
|
805
|
-
if (name !== void 0 && url !== void 0) {
|
|
806
|
-
const existing = remotes.get(name);
|
|
807
|
-
if (existing) {
|
|
808
|
-
if (type === "fetch") {
|
|
809
|
-
existing.fetchUrl = url;
|
|
810
|
-
} else if (type === "push") {
|
|
811
|
-
existing.pushUrl = url;
|
|
812
|
-
}
|
|
813
|
-
} else {
|
|
814
|
-
remotes.set(name, {
|
|
815
|
-
name,
|
|
816
|
-
fetchUrl: type === "fetch" ? url : "",
|
|
817
|
-
pushUrl: type === "push" ? url : ""
|
|
818
|
-
});
|
|
819
|
-
}
|
|
820
|
-
}
|
|
821
|
-
}
|
|
822
|
-
}
|
|
823
|
-
for (const remote of remotes.values()) {
|
|
824
|
-
if (!remote.fetchUrl && remote.pushUrl) {
|
|
825
|
-
remote.fetchUrl = remote.pushUrl;
|
|
826
|
-
}
|
|
827
|
-
if (!remote.pushUrl && remote.fetchUrl) {
|
|
828
|
-
remote.pushUrl = remote.fetchUrl;
|
|
829
|
-
}
|
|
1153
|
+
parseRemoteLine(line, remotes);
|
|
830
1154
|
}
|
|
1155
|
+
normalizeRemoteUrls(remotes);
|
|
831
1156
|
return Array.from(remotes.values());
|
|
832
1157
|
}
|
|
833
1158
|
async remoteAdd(name, url, opts) {
|
|
@@ -916,7 +1241,7 @@ var BareRepoImpl = class {
|
|
|
916
1241
|
});
|
|
917
1242
|
const pruned = [];
|
|
918
1243
|
for (const line of parseLines(result.stdout)) {
|
|
919
|
-
const match = line.match(
|
|
1244
|
+
const match = line.match(PRUNED_REF_PATTERN);
|
|
920
1245
|
const ref = match?.[1];
|
|
921
1246
|
if (ref) {
|
|
922
1247
|
pruned.push(ref);
|
|
@@ -1243,6 +1568,89 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
1243
1568
|
const result = await this.runner.run(this.context, ["rev-parse", "--is-bare-repository"]);
|
|
1244
1569
|
return result.exitCode === 0 && result.stdout.trim() === "true";
|
|
1245
1570
|
}
|
|
1571
|
+
/**
|
|
1572
|
+
* List references in a remote repository
|
|
1573
|
+
*/
|
|
1574
|
+
async lsRemote(remote, opts) {
|
|
1575
|
+
const args = ["ls-remote"];
|
|
1576
|
+
if (opts?.heads) {
|
|
1577
|
+
args.push("--heads");
|
|
1578
|
+
}
|
|
1579
|
+
if (opts?.tags) {
|
|
1580
|
+
args.push("--tags");
|
|
1581
|
+
}
|
|
1582
|
+
if (opts?.refsOnly) {
|
|
1583
|
+
args.push("--refs");
|
|
1584
|
+
}
|
|
1585
|
+
if (opts?.getUrl) {
|
|
1586
|
+
args.push("--get-url");
|
|
1587
|
+
}
|
|
1588
|
+
if (opts?.sort) {
|
|
1589
|
+
args.push("--sort", opts.sort);
|
|
1590
|
+
}
|
|
1591
|
+
if (opts?.symref) {
|
|
1592
|
+
args.push("--symref");
|
|
1593
|
+
}
|
|
1594
|
+
args.push(remote);
|
|
1595
|
+
if (opts?.refs && opts.refs.length > 0) {
|
|
1596
|
+
args.push(...opts.refs);
|
|
1597
|
+
}
|
|
1598
|
+
const result = await this.runner.runOrThrow(this.context, args, {
|
|
1599
|
+
signal: opts?.signal,
|
|
1600
|
+
onProgress: opts?.onProgress
|
|
1601
|
+
});
|
|
1602
|
+
const refs = parseLsRemote(result.stdout);
|
|
1603
|
+
return { refs };
|
|
1604
|
+
}
|
|
1605
|
+
/**
|
|
1606
|
+
* List contents of a tree object
|
|
1607
|
+
*/
|
|
1608
|
+
async lsTree(treeish, opts) {
|
|
1609
|
+
const args = ["ls-tree"];
|
|
1610
|
+
if (opts?.recursive) {
|
|
1611
|
+
args.push("-r");
|
|
1612
|
+
}
|
|
1613
|
+
if (opts?.treeOnly) {
|
|
1614
|
+
args.push("-d");
|
|
1615
|
+
}
|
|
1616
|
+
if (opts?.showTrees) {
|
|
1617
|
+
args.push("-t");
|
|
1618
|
+
}
|
|
1619
|
+
if (opts?.long) {
|
|
1620
|
+
args.push("--long");
|
|
1621
|
+
}
|
|
1622
|
+
if (opts?.nameOnly) {
|
|
1623
|
+
args.push("--name-only");
|
|
1624
|
+
}
|
|
1625
|
+
if (opts?.objectOnly) {
|
|
1626
|
+
args.push("--object-only");
|
|
1627
|
+
}
|
|
1628
|
+
if (opts?.fullName) {
|
|
1629
|
+
args.push("--full-name");
|
|
1630
|
+
}
|
|
1631
|
+
if (opts?.fullTree) {
|
|
1632
|
+
args.push("--full-tree");
|
|
1633
|
+
}
|
|
1634
|
+
if (opts?.abbrev !== void 0) {
|
|
1635
|
+
if (opts.abbrev === true) {
|
|
1636
|
+
args.push("--abbrev");
|
|
1637
|
+
} else if (typeof opts.abbrev === "number") {
|
|
1638
|
+
args.push(`--abbrev=${opts.abbrev}`);
|
|
1639
|
+
}
|
|
1640
|
+
}
|
|
1641
|
+
args.push(treeish);
|
|
1642
|
+
if (opts?.paths && opts.paths.length > 0) {
|
|
1643
|
+
args.push("--", ...opts.paths);
|
|
1644
|
+
}
|
|
1645
|
+
const result = await this.runner.runOrThrow(this.context, args, {
|
|
1646
|
+
signal: opts?.signal
|
|
1647
|
+
});
|
|
1648
|
+
return parseLsTree(result.stdout, {
|
|
1649
|
+
nameOnly: opts?.nameOnly,
|
|
1650
|
+
objectOnly: opts?.objectOnly,
|
|
1651
|
+
long: opts?.long
|
|
1652
|
+
});
|
|
1653
|
+
}
|
|
1246
1654
|
/**
|
|
1247
1655
|
* Get repository status
|
|
1248
1656
|
*/
|
|
@@ -4138,17 +4546,151 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
4138
4546
|
});
|
|
4139
4547
|
return result.stdout;
|
|
4140
4548
|
}
|
|
4141
|
-
|
|
4142
|
-
|
|
4143
|
-
|
|
4144
|
-
|
|
4145
|
-
|
|
4146
|
-
|
|
4147
|
-
|
|
4148
|
-
|
|
4149
|
-
|
|
4549
|
+
async revParse(refOrOpts, opts) {
|
|
4550
|
+
const args = ["rev-parse"];
|
|
4551
|
+
if (typeof refOrOpts === "string") {
|
|
4552
|
+
if (opts?.verify) {
|
|
4553
|
+
args.push("--verify");
|
|
4554
|
+
}
|
|
4555
|
+
if (opts?.short !== void 0) {
|
|
4556
|
+
if (typeof opts.short === "number") {
|
|
4557
|
+
args.push(`--short=${opts.short}`);
|
|
4558
|
+
} else if (opts.short) {
|
|
4559
|
+
args.push("--short");
|
|
4560
|
+
}
|
|
4561
|
+
}
|
|
4562
|
+
if (opts?.abbrevRef !== void 0) {
|
|
4563
|
+
if (opts.abbrevRef === "strict") {
|
|
4564
|
+
args.push("--abbrev-ref=strict");
|
|
4565
|
+
} else if (opts.abbrevRef === "loose") {
|
|
4566
|
+
args.push("--abbrev-ref=loose");
|
|
4567
|
+
} else if (opts.abbrevRef) {
|
|
4568
|
+
args.push("--abbrev-ref");
|
|
4569
|
+
}
|
|
4570
|
+
}
|
|
4571
|
+
if (opts?.symbolic) {
|
|
4572
|
+
args.push("--symbolic");
|
|
4573
|
+
}
|
|
4574
|
+
if (opts?.symbolicFullName) {
|
|
4575
|
+
args.push("--symbolic-full-name");
|
|
4576
|
+
}
|
|
4577
|
+
if (opts?.quiet) {
|
|
4578
|
+
args.push("--quiet");
|
|
4579
|
+
}
|
|
4580
|
+
args.push(refOrOpts);
|
|
4581
|
+
const result2 = await this.runner.runOrThrow(this.context, args, {
|
|
4582
|
+
signal: opts?.signal
|
|
4583
|
+
});
|
|
4584
|
+
return result2.stdout.trim();
|
|
4585
|
+
}
|
|
4586
|
+
const queryOpts = refOrOpts;
|
|
4587
|
+
if ("gitDir" in queryOpts && queryOpts.gitDir) {
|
|
4588
|
+
args.push("--git-dir");
|
|
4589
|
+
} else if ("absoluteGitDir" in queryOpts && queryOpts.absoluteGitDir) {
|
|
4590
|
+
args.push("--absolute-git-dir");
|
|
4591
|
+
} else if ("gitCommonDir" in queryOpts && queryOpts.gitCommonDir) {
|
|
4592
|
+
args.push("--git-common-dir");
|
|
4593
|
+
} else if ("showToplevel" in queryOpts && queryOpts.showToplevel) {
|
|
4594
|
+
args.push("--show-toplevel");
|
|
4595
|
+
} else if ("showCdup" in queryOpts && queryOpts.showCdup) {
|
|
4596
|
+
args.push("--show-cdup");
|
|
4597
|
+
} else if ("showPrefix" in queryOpts && queryOpts.showPrefix) {
|
|
4598
|
+
args.push("--show-prefix");
|
|
4599
|
+
} else if ("showSuperprojectWorkingTree" in queryOpts && queryOpts.showSuperprojectWorkingTree) {
|
|
4600
|
+
args.push("--show-superproject-working-tree");
|
|
4601
|
+
} else if ("sharedIndexPath" in queryOpts && queryOpts.sharedIndexPath) {
|
|
4602
|
+
args.push("--shared-index-path");
|
|
4603
|
+
} else if ("gitPath" in queryOpts && typeof queryOpts.gitPath === "string") {
|
|
4604
|
+
args.push("--git-path", queryOpts.gitPath);
|
|
4605
|
+
} else if ("resolveGitDir" in queryOpts && typeof queryOpts.resolveGitDir === "string") {
|
|
4606
|
+
args.push("--resolve-git-dir", queryOpts.resolveGitDir);
|
|
4607
|
+
} else if ("isInsideGitDir" in queryOpts && queryOpts.isInsideGitDir) {
|
|
4608
|
+
args.push("--is-inside-git-dir");
|
|
4609
|
+
} else if ("isInsideWorkTree" in queryOpts && queryOpts.isInsideWorkTree) {
|
|
4610
|
+
args.push("--is-inside-work-tree");
|
|
4611
|
+
} else if ("isBareRepository" in queryOpts && queryOpts.isBareRepository) {
|
|
4612
|
+
args.push("--is-bare-repository");
|
|
4613
|
+
} else if ("isShallowRepository" in queryOpts && queryOpts.isShallowRepository) {
|
|
4614
|
+
args.push("--is-shallow-repository");
|
|
4615
|
+
} else if ("all" in queryOpts && queryOpts.all) {
|
|
4616
|
+
if ("exclude" in queryOpts && queryOpts.exclude) {
|
|
4617
|
+
args.push(`--exclude=${queryOpts.exclude}`);
|
|
4618
|
+
}
|
|
4619
|
+
if ("excludeHidden" in queryOpts && queryOpts.excludeHidden) {
|
|
4620
|
+
args.push(`--exclude-hidden=${queryOpts.excludeHidden}`);
|
|
4621
|
+
}
|
|
4622
|
+
args.push("--all");
|
|
4623
|
+
} else if ("branches" in queryOpts && queryOpts.branches) {
|
|
4624
|
+
if ("exclude" in queryOpts && queryOpts.exclude) {
|
|
4625
|
+
args.push(`--exclude=${queryOpts.exclude}`);
|
|
4626
|
+
}
|
|
4627
|
+
if ("excludeHidden" in queryOpts && queryOpts.excludeHidden) {
|
|
4628
|
+
args.push(`--exclude-hidden=${queryOpts.excludeHidden}`);
|
|
4629
|
+
}
|
|
4630
|
+
if (typeof queryOpts.branches === "string") {
|
|
4631
|
+
args.push(`--branches=${queryOpts.branches}`);
|
|
4632
|
+
} else {
|
|
4633
|
+
args.push("--branches");
|
|
4634
|
+
}
|
|
4635
|
+
} else if ("tags" in queryOpts && queryOpts.tags) {
|
|
4636
|
+
if ("exclude" in queryOpts && queryOpts.exclude) {
|
|
4637
|
+
args.push(`--exclude=${queryOpts.exclude}`);
|
|
4638
|
+
}
|
|
4639
|
+
if ("excludeHidden" in queryOpts && queryOpts.excludeHidden) {
|
|
4640
|
+
args.push(`--exclude-hidden=${queryOpts.excludeHidden}`);
|
|
4641
|
+
}
|
|
4642
|
+
if (typeof queryOpts.tags === "string") {
|
|
4643
|
+
args.push(`--tags=${queryOpts.tags}`);
|
|
4644
|
+
} else {
|
|
4645
|
+
args.push("--tags");
|
|
4646
|
+
}
|
|
4647
|
+
} else if ("remotes" in queryOpts && queryOpts.remotes) {
|
|
4648
|
+
if ("exclude" in queryOpts && queryOpts.exclude) {
|
|
4649
|
+
args.push(`--exclude=${queryOpts.exclude}`);
|
|
4650
|
+
}
|
|
4651
|
+
if ("excludeHidden" in queryOpts && queryOpts.excludeHidden) {
|
|
4652
|
+
args.push(`--exclude-hidden=${queryOpts.excludeHidden}`);
|
|
4653
|
+
}
|
|
4654
|
+
if (typeof queryOpts.remotes === "string") {
|
|
4655
|
+
args.push(`--remotes=${queryOpts.remotes}`);
|
|
4656
|
+
} else {
|
|
4657
|
+
args.push("--remotes");
|
|
4658
|
+
}
|
|
4659
|
+
} else if ("glob" in queryOpts && typeof queryOpts.glob === "string") {
|
|
4660
|
+
if ("exclude" in queryOpts && queryOpts.exclude) {
|
|
4661
|
+
args.push(`--exclude=${queryOpts.exclude}`);
|
|
4662
|
+
}
|
|
4663
|
+
if ("excludeHidden" in queryOpts && queryOpts.excludeHidden) {
|
|
4664
|
+
args.push(`--exclude-hidden=${queryOpts.excludeHidden}`);
|
|
4665
|
+
}
|
|
4666
|
+
args.push(`--glob=${queryOpts.glob}`);
|
|
4667
|
+
} else if ("disambiguate" in queryOpts && typeof queryOpts.disambiguate === "string") {
|
|
4668
|
+
args.push(`--disambiguate=${queryOpts.disambiguate}`);
|
|
4669
|
+
} else if ("showObjectFormat" in queryOpts && queryOpts.showObjectFormat) {
|
|
4670
|
+
if (queryOpts.showObjectFormat === true) {
|
|
4671
|
+
args.push("--show-object-format");
|
|
4672
|
+
} else {
|
|
4673
|
+
args.push(`--show-object-format=${queryOpts.showObjectFormat}`);
|
|
4674
|
+
}
|
|
4675
|
+
} else if ("showRefFormat" in queryOpts && queryOpts.showRefFormat) {
|
|
4676
|
+
args.push("--show-ref-format");
|
|
4677
|
+
} else if ("localEnvVars" in queryOpts && queryOpts.localEnvVars) {
|
|
4678
|
+
args.push("--local-env-vars");
|
|
4679
|
+
}
|
|
4680
|
+
if ("pathFormat" in queryOpts && queryOpts.pathFormat) {
|
|
4681
|
+
args.push(`--path-format=${queryOpts.pathFormat}`);
|
|
4682
|
+
}
|
|
4683
|
+
const result = await this.runner.runOrThrow(this.context, args, {
|
|
4684
|
+
signal: queryOpts.signal
|
|
4150
4685
|
});
|
|
4151
|
-
|
|
4686
|
+
const output = result.stdout.trim();
|
|
4687
|
+
if ("isInsideGitDir" in queryOpts && queryOpts.isInsideGitDir || "isInsideWorkTree" in queryOpts && queryOpts.isInsideWorkTree || "isBareRepository" in queryOpts && queryOpts.isBareRepository || "isShallowRepository" in queryOpts && queryOpts.isShallowRepository) {
|
|
4688
|
+
return output === "true";
|
|
4689
|
+
}
|
|
4690
|
+
if ("all" in queryOpts && queryOpts.all || "branches" in queryOpts && queryOpts.branches || "tags" in queryOpts && queryOpts.tags || "remotes" in queryOpts && queryOpts.remotes || "glob" in queryOpts && queryOpts.glob || "disambiguate" in queryOpts && queryOpts.disambiguate || "localEnvVars" in queryOpts && queryOpts.localEnvVars) {
|
|
4691
|
+
return output ? output.split("\n").filter((line) => line.length > 0) : [];
|
|
4692
|
+
}
|
|
4693
|
+
return output;
|
|
4152
4694
|
}
|
|
4153
4695
|
/**
|
|
4154
4696
|
* Count the number of commits reachable from a ref
|
|
@@ -4702,6 +5244,101 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
4702
5244
|
};
|
|
4703
5245
|
|
|
4704
5246
|
// src/impl/git-impl.ts
|
|
5247
|
+
var GIT_VERSION_REGEX = /git version (\S+)/;
|
|
5248
|
+
function buildCloneArgs(opts) {
|
|
5249
|
+
const args = ["clone"];
|
|
5250
|
+
if (!opts) {
|
|
5251
|
+
return args;
|
|
5252
|
+
}
|
|
5253
|
+
const booleanFlags = [
|
|
5254
|
+
["verbose", "--verbose"],
|
|
5255
|
+
["quiet", "--quiet"],
|
|
5256
|
+
["bare", "--bare"],
|
|
5257
|
+
["mirror", "--mirror"],
|
|
5258
|
+
["rejectShallow", "--reject-shallow"],
|
|
5259
|
+
["singleBranch", "--single-branch"],
|
|
5260
|
+
["noCheckout", "--no-checkout"],
|
|
5261
|
+
["sparse", "--sparse"],
|
|
5262
|
+
["local", "--local"],
|
|
5263
|
+
["noHardlinks", "--no-hardlinks"],
|
|
5264
|
+
["shared", "--shared"],
|
|
5265
|
+
["dissociate", "--dissociate"],
|
|
5266
|
+
["recurseSubmodules", "--recurse-submodules"],
|
|
5267
|
+
["shallowSubmodules", "--shallow-submodules"],
|
|
5268
|
+
["remoteSubmodules", "--remote-submodules"],
|
|
5269
|
+
["noTags", "--no-tags"],
|
|
5270
|
+
["alsoFilterSubmodules", "--also-filter-submodules"],
|
|
5271
|
+
["ipv4", "--ipv4"],
|
|
5272
|
+
["ipv6", "--ipv6"]
|
|
5273
|
+
];
|
|
5274
|
+
for (const [key, flag] of booleanFlags) {
|
|
5275
|
+
if (opts[key]) {
|
|
5276
|
+
args.push(flag);
|
|
5277
|
+
}
|
|
5278
|
+
}
|
|
5279
|
+
const stringFlags = [
|
|
5280
|
+
["branch", "--branch"],
|
|
5281
|
+
["reference", "--reference"],
|
|
5282
|
+
["referenceIfAble", "--reference-if-able"],
|
|
5283
|
+
["template", "--template"],
|
|
5284
|
+
["origin", "--origin"],
|
|
5285
|
+
["separateGitDir", "--separate-git-dir"],
|
|
5286
|
+
["filter", "--filter"]
|
|
5287
|
+
];
|
|
5288
|
+
for (const [key, flag] of stringFlags) {
|
|
5289
|
+
const value = opts[key];
|
|
5290
|
+
if (typeof value === "string") {
|
|
5291
|
+
args.push(flag, value);
|
|
5292
|
+
}
|
|
5293
|
+
}
|
|
5294
|
+
if (opts.depth !== void 0) {
|
|
5295
|
+
args.push("--depth", String(opts.depth));
|
|
5296
|
+
}
|
|
5297
|
+
if (opts.jobs !== void 0) {
|
|
5298
|
+
args.push("--jobs", String(opts.jobs));
|
|
5299
|
+
}
|
|
5300
|
+
if (opts.shallowSince) {
|
|
5301
|
+
const since = opts.shallowSince instanceof Date ? opts.shallowSince.toISOString() : opts.shallowSince;
|
|
5302
|
+
args.push("--shallow-since", since);
|
|
5303
|
+
}
|
|
5304
|
+
if (opts.shallowExclude) {
|
|
5305
|
+
const excludes = Array.isArray(opts.shallowExclude) ? opts.shallowExclude : [opts.shallowExclude];
|
|
5306
|
+
for (const exclude of excludes) {
|
|
5307
|
+
args.push("--shallow-exclude", exclude);
|
|
5308
|
+
}
|
|
5309
|
+
}
|
|
5310
|
+
if (opts.config) {
|
|
5311
|
+
for (const [key, value] of Object.entries(opts.config)) {
|
|
5312
|
+
args.push("-c", `${key}=${value}`);
|
|
5313
|
+
}
|
|
5314
|
+
}
|
|
5315
|
+
return args;
|
|
5316
|
+
}
|
|
5317
|
+
var MIN_GIT_VERSION = "2.30.0";
|
|
5318
|
+
var LEGACY_GIT_VERSION = "2.25.0";
|
|
5319
|
+
var VERSION_REGEX = /^(\d+)\.(\d+)\.(\d+)/;
|
|
5320
|
+
function parseVersion(version) {
|
|
5321
|
+
const match = version.match(VERSION_REGEX);
|
|
5322
|
+
if (!match) {
|
|
5323
|
+
return [0, 0, 0];
|
|
5324
|
+
}
|
|
5325
|
+
return [
|
|
5326
|
+
Number.parseInt(match[1], 10),
|
|
5327
|
+
Number.parseInt(match[2], 10),
|
|
5328
|
+
Number.parseInt(match[3], 10)
|
|
5329
|
+
];
|
|
5330
|
+
}
|
|
5331
|
+
function compareVersions(a, b) {
|
|
5332
|
+
const [aMajor, aMinor, aPatch] = parseVersion(a);
|
|
5333
|
+
const [bMajor, bMinor, bPatch] = parseVersion(b);
|
|
5334
|
+
if (aMajor !== bMajor) {
|
|
5335
|
+
return aMajor - bMajor;
|
|
5336
|
+
}
|
|
5337
|
+
if (aMinor !== bMinor) {
|
|
5338
|
+
return aMinor - bMinor;
|
|
5339
|
+
}
|
|
5340
|
+
return aPatch - bPatch;
|
|
5341
|
+
}
|
|
4705
5342
|
function toCliRunnerOptions(opts) {
|
|
4706
5343
|
if (!opts) {
|
|
4707
5344
|
return {};
|
|
@@ -4719,6 +5356,7 @@ function toCliRunnerOptions(opts) {
|
|
|
4719
5356
|
var GitImpl = class {
|
|
4720
5357
|
runner;
|
|
4721
5358
|
adapters;
|
|
5359
|
+
cachedVersion = null;
|
|
4722
5360
|
config;
|
|
4723
5361
|
lfs;
|
|
4724
5362
|
constructor(options) {
|
|
@@ -4807,109 +5445,10 @@ var GitImpl = class {
|
|
|
4807
5445
|
return new WorktreeRepoImpl(repoRunner, path, opts);
|
|
4808
5446
|
}
|
|
4809
5447
|
async clone(url, path, opts) {
|
|
4810
|
-
const args =
|
|
5448
|
+
const args = buildCloneArgs(opts);
|
|
4811
5449
|
if (opts?.onProgress) {
|
|
4812
5450
|
args.push("--progress");
|
|
4813
5451
|
}
|
|
4814
|
-
if (opts?.verbose) {
|
|
4815
|
-
args.push("--verbose");
|
|
4816
|
-
}
|
|
4817
|
-
if (opts?.quiet) {
|
|
4818
|
-
args.push("--quiet");
|
|
4819
|
-
}
|
|
4820
|
-
if (opts?.bare) {
|
|
4821
|
-
args.push("--bare");
|
|
4822
|
-
}
|
|
4823
|
-
if (opts?.mirror) {
|
|
4824
|
-
args.push("--mirror");
|
|
4825
|
-
}
|
|
4826
|
-
if (opts?.depth !== void 0) {
|
|
4827
|
-
args.push("--depth", String(opts.depth));
|
|
4828
|
-
}
|
|
4829
|
-
if (opts?.shallowSince) {
|
|
4830
|
-
const since = opts.shallowSince instanceof Date ? opts.shallowSince.toISOString() : opts.shallowSince;
|
|
4831
|
-
args.push("--shallow-since", since);
|
|
4832
|
-
}
|
|
4833
|
-
if (opts?.shallowExclude) {
|
|
4834
|
-
const excludes = Array.isArray(opts.shallowExclude) ? opts.shallowExclude : [opts.shallowExclude];
|
|
4835
|
-
for (const exclude of excludes) {
|
|
4836
|
-
args.push("--shallow-exclude", exclude);
|
|
4837
|
-
}
|
|
4838
|
-
}
|
|
4839
|
-
if (opts?.rejectShallow) {
|
|
4840
|
-
args.push("--reject-shallow");
|
|
4841
|
-
}
|
|
4842
|
-
if (opts?.branch) {
|
|
4843
|
-
args.push("--branch", opts.branch);
|
|
4844
|
-
}
|
|
4845
|
-
if (opts?.singleBranch) {
|
|
4846
|
-
args.push("--single-branch");
|
|
4847
|
-
}
|
|
4848
|
-
if (opts?.noCheckout) {
|
|
4849
|
-
args.push("--no-checkout");
|
|
4850
|
-
}
|
|
4851
|
-
if (opts?.sparse) {
|
|
4852
|
-
args.push("--sparse");
|
|
4853
|
-
}
|
|
4854
|
-
if (opts?.local) {
|
|
4855
|
-
args.push("--local");
|
|
4856
|
-
}
|
|
4857
|
-
if (opts?.noHardlinks) {
|
|
4858
|
-
args.push("--no-hardlinks");
|
|
4859
|
-
}
|
|
4860
|
-
if (opts?.shared) {
|
|
4861
|
-
args.push("--shared");
|
|
4862
|
-
}
|
|
4863
|
-
if (opts?.reference) {
|
|
4864
|
-
args.push("--reference", opts.reference);
|
|
4865
|
-
}
|
|
4866
|
-
if (opts?.referenceIfAble) {
|
|
4867
|
-
args.push("--reference-if-able", opts.referenceIfAble);
|
|
4868
|
-
}
|
|
4869
|
-
if (opts?.dissociate) {
|
|
4870
|
-
args.push("--dissociate");
|
|
4871
|
-
}
|
|
4872
|
-
if (opts?.recurseSubmodules) {
|
|
4873
|
-
args.push("--recurse-submodules");
|
|
4874
|
-
}
|
|
4875
|
-
if (opts?.shallowSubmodules) {
|
|
4876
|
-
args.push("--shallow-submodules");
|
|
4877
|
-
}
|
|
4878
|
-
if (opts?.remoteSubmodules) {
|
|
4879
|
-
args.push("--remote-submodules");
|
|
4880
|
-
}
|
|
4881
|
-
if (opts?.jobs !== void 0) {
|
|
4882
|
-
args.push("--jobs", String(opts.jobs));
|
|
4883
|
-
}
|
|
4884
|
-
if (opts?.noTags) {
|
|
4885
|
-
args.push("--no-tags");
|
|
4886
|
-
}
|
|
4887
|
-
if (opts?.template) {
|
|
4888
|
-
args.push("--template", opts.template);
|
|
4889
|
-
}
|
|
4890
|
-
if (opts?.origin) {
|
|
4891
|
-
args.push("--origin", opts.origin);
|
|
4892
|
-
}
|
|
4893
|
-
if (opts?.separateGitDir) {
|
|
4894
|
-
args.push("--separate-git-dir", opts.separateGitDir);
|
|
4895
|
-
}
|
|
4896
|
-
if (opts?.config) {
|
|
4897
|
-
for (const [key, value] of Object.entries(opts.config)) {
|
|
4898
|
-
args.push("-c", `${key}=${value}`);
|
|
4899
|
-
}
|
|
4900
|
-
}
|
|
4901
|
-
if (opts?.filter) {
|
|
4902
|
-
args.push("--filter", opts.filter);
|
|
4903
|
-
}
|
|
4904
|
-
if (opts?.alsoFilterSubmodules) {
|
|
4905
|
-
args.push("--also-filter-submodules");
|
|
4906
|
-
}
|
|
4907
|
-
if (opts?.ipv4) {
|
|
4908
|
-
args.push("--ipv4");
|
|
4909
|
-
}
|
|
4910
|
-
if (opts?.ipv6) {
|
|
4911
|
-
args.push("--ipv6");
|
|
4912
|
-
}
|
|
4913
5452
|
args.push(url, path);
|
|
4914
5453
|
try {
|
|
4915
5454
|
await this.runner.runOrThrow({ type: "global" }, args, {
|
|
@@ -4949,7 +5488,7 @@ var GitImpl = class {
|
|
|
4949
5488
|
args.push(`--shared=${opts.shared}`);
|
|
4950
5489
|
}
|
|
4951
5490
|
}
|
|
4952
|
-
if (opts?.initialBranch) {
|
|
5491
|
+
if (opts?.initialBranch && await this.supportsInitialBranch()) {
|
|
4953
5492
|
args.push("--initial-branch", opts.initialBranch);
|
|
4954
5493
|
}
|
|
4955
5494
|
if (opts?.objectFormat) {
|
|
@@ -4964,6 +5503,16 @@ var GitImpl = class {
|
|
|
4964
5503
|
signal: opts?.signal,
|
|
4965
5504
|
onProgress: opts?.onProgress
|
|
4966
5505
|
});
|
|
5506
|
+
if (opts?.initialBranch && !await this.supportsInitialBranch()) {
|
|
5507
|
+
const context = opts?.bare ? { type: "bare", gitDir: path } : { type: "worktree", workdir: path };
|
|
5508
|
+
await this.runner.runOrThrow(
|
|
5509
|
+
context,
|
|
5510
|
+
["symbolic-ref", "HEAD", `refs/heads/${opts.initialBranch}`],
|
|
5511
|
+
{
|
|
5512
|
+
signal: opts?.signal
|
|
5513
|
+
}
|
|
5514
|
+
);
|
|
5515
|
+
}
|
|
4967
5516
|
} catch (error) {
|
|
4968
5517
|
if (error instanceof GitError && error.kind === "Aborted" && opts?.cleanupOnAbort !== false) {
|
|
4969
5518
|
await this.adapters.fs.deleteDirectory(path);
|
|
@@ -5010,17 +5559,28 @@ var GitImpl = class {
|
|
|
5010
5559
|
* Get git version
|
|
5011
5560
|
*/
|
|
5012
5561
|
async version(opts) {
|
|
5562
|
+
if (this.cachedVersion) {
|
|
5563
|
+
return this.cachedVersion;
|
|
5564
|
+
}
|
|
5013
5565
|
const result = await this.runner.runOrThrow({ type: "global" }, ["--version"], {
|
|
5014
5566
|
signal: opts?.signal
|
|
5015
5567
|
});
|
|
5016
|
-
const match = result.stdout.match(
|
|
5017
|
-
const version = match?.[1];
|
|
5018
|
-
|
|
5568
|
+
const match = result.stdout.match(GIT_VERSION_REGEX);
|
|
5569
|
+
const version = match?.[1] ?? result.stdout.trim();
|
|
5570
|
+
this.cachedVersion = version;
|
|
5571
|
+
return version;
|
|
5572
|
+
}
|
|
5573
|
+
/**
|
|
5574
|
+
* Check if Git version supports --initial-branch option (Git 2.28+)
|
|
5575
|
+
*/
|
|
5576
|
+
async supportsInitialBranch() {
|
|
5577
|
+
const version = await this.version();
|
|
5578
|
+
return compareVersions(version, "2.28.0") >= 0;
|
|
5019
5579
|
}
|
|
5020
5580
|
/**
|
|
5021
5581
|
* Execute a raw git command (repository-agnostic)
|
|
5022
5582
|
*/
|
|
5023
|
-
|
|
5583
|
+
raw(argv, opts) {
|
|
5024
5584
|
return this.runner.run({ type: "global" }, argv, opts);
|
|
5025
5585
|
}
|
|
5026
5586
|
// ==========================================================================
|
|
@@ -5206,9 +5766,24 @@ var GitImpl = class {
|
|
|
5206
5766
|
return result.stdout.trim();
|
|
5207
5767
|
}
|
|
5208
5768
|
};
|
|
5209
|
-
function
|
|
5769
|
+
function createGitSync(options) {
|
|
5210
5770
|
return new GitImpl(options);
|
|
5211
5771
|
}
|
|
5772
|
+
async function createGit(options) {
|
|
5773
|
+
const git = new GitImpl(options);
|
|
5774
|
+
if (!options.skipVersionCheck) {
|
|
5775
|
+
const versionString = await git.version();
|
|
5776
|
+
const minVersion = options.useLegacyVersion ? LEGACY_GIT_VERSION : MIN_GIT_VERSION;
|
|
5777
|
+
if (compareVersions(versionString, minVersion) < 0) {
|
|
5778
|
+
throw new GitError(
|
|
5779
|
+
"UnsupportedGitVersion",
|
|
5780
|
+
`Git version ${versionString} is not supported. Minimum required version is ${minVersion}.`,
|
|
5781
|
+
{}
|
|
5782
|
+
);
|
|
5783
|
+
}
|
|
5784
|
+
}
|
|
5785
|
+
return git;
|
|
5786
|
+
}
|
|
5212
5787
|
|
|
5213
5788
|
// src/adapters/node/exec.ts
|
|
5214
5789
|
var import_node_child_process = require("child_process");
|
|
@@ -5367,52 +5942,132 @@ var NodeExecAdapter = class {
|
|
|
5367
5942
|
var import_promises = require("fs/promises");
|
|
5368
5943
|
var import_node_os = require("os");
|
|
5369
5944
|
var import_node_path = require("path");
|
|
5945
|
+
|
|
5946
|
+
// src/internal/file-polling.ts
|
|
5947
|
+
async function runTailPolling(options) {
|
|
5948
|
+
const { adapter, signal, pollInterval = 100, onLine } = options;
|
|
5949
|
+
let position = 0;
|
|
5950
|
+
let buffer = "";
|
|
5951
|
+
while (!signal?.aborted) {
|
|
5952
|
+
const result = await adapter.readChunk(position);
|
|
5953
|
+
if (result !== null && result.data.length > 0) {
|
|
5954
|
+
position = result.newPosition;
|
|
5955
|
+
buffer += result.data;
|
|
5956
|
+
const lines = buffer.split("\n");
|
|
5957
|
+
buffer = lines.pop() ?? "";
|
|
5958
|
+
for (const line of lines) {
|
|
5959
|
+
if (line) {
|
|
5960
|
+
onLine(line);
|
|
5961
|
+
}
|
|
5962
|
+
}
|
|
5963
|
+
}
|
|
5964
|
+
if (!signal?.aborted) {
|
|
5965
|
+
await adapter.sleep(pollInterval);
|
|
5966
|
+
}
|
|
5967
|
+
}
|
|
5968
|
+
}
|
|
5969
|
+
function createTailPolling(options) {
|
|
5970
|
+
const { adapter, signal, pollInterval = 100 } = options;
|
|
5971
|
+
const state = {
|
|
5972
|
+
stopped: false,
|
|
5973
|
+
resolveNext: null,
|
|
5974
|
+
lineQueue: []
|
|
5975
|
+
};
|
|
5976
|
+
const stop = () => {
|
|
5977
|
+
state.stopped = true;
|
|
5978
|
+
if (state.resolveNext) {
|
|
5979
|
+
state.resolveNext({ done: true, value: void 0 });
|
|
5980
|
+
state.resolveNext = null;
|
|
5981
|
+
}
|
|
5982
|
+
};
|
|
5983
|
+
startPollingLoop(adapter, state, signal, pollInterval, stop).catch(() => {
|
|
5984
|
+
});
|
|
5985
|
+
const lines = {
|
|
5986
|
+
[Symbol.asyncIterator]() {
|
|
5987
|
+
return {
|
|
5988
|
+
next() {
|
|
5989
|
+
if (state.stopped) {
|
|
5990
|
+
return Promise.resolve({ done: true, value: void 0 });
|
|
5991
|
+
}
|
|
5992
|
+
if (state.lineQueue.length > 0) {
|
|
5993
|
+
const value = state.lineQueue.shift();
|
|
5994
|
+
if (value !== void 0) {
|
|
5995
|
+
return Promise.resolve({ done: false, value });
|
|
5996
|
+
}
|
|
5997
|
+
}
|
|
5998
|
+
return new Promise((resolve) => {
|
|
5999
|
+
state.resolveNext = resolve;
|
|
6000
|
+
});
|
|
6001
|
+
}
|
|
6002
|
+
};
|
|
6003
|
+
}
|
|
6004
|
+
};
|
|
6005
|
+
return { lines, stop };
|
|
6006
|
+
}
|
|
6007
|
+
async function startPollingLoop(adapter, state, signal, pollInterval, stop) {
|
|
6008
|
+
let position = 0;
|
|
6009
|
+
let buffer = "";
|
|
6010
|
+
while (!(state.stopped || signal?.aborted)) {
|
|
6011
|
+
const result = await adapter.readChunk(position);
|
|
6012
|
+
if (result !== null && result.data.length > 0) {
|
|
6013
|
+
position = result.newPosition;
|
|
6014
|
+
buffer += result.data;
|
|
6015
|
+
const lines = buffer.split("\n");
|
|
6016
|
+
buffer = lines.pop() ?? "";
|
|
6017
|
+
for (const line of lines) {
|
|
6018
|
+
if (line) {
|
|
6019
|
+
if (state.resolveNext) {
|
|
6020
|
+
const resolver = state.resolveNext;
|
|
6021
|
+
state.resolveNext = null;
|
|
6022
|
+
resolver({ done: false, value: line });
|
|
6023
|
+
} else {
|
|
6024
|
+
state.lineQueue.push(line);
|
|
6025
|
+
}
|
|
6026
|
+
}
|
|
6027
|
+
}
|
|
6028
|
+
}
|
|
6029
|
+
await adapter.sleep(pollInterval);
|
|
6030
|
+
}
|
|
6031
|
+
stop();
|
|
6032
|
+
}
|
|
6033
|
+
|
|
6034
|
+
// src/adapters/node/fs.ts
|
|
5370
6035
|
var NodeFsAdapter = class {
|
|
5371
6036
|
async createTempFile(prefix = "type-git-") {
|
|
5372
6037
|
const dir = await (0, import_promises.mkdtemp)((0, import_node_path.join)((0, import_node_os.tmpdir)(), prefix));
|
|
5373
6038
|
return (0, import_node_path.join)(dir, "temp");
|
|
5374
6039
|
}
|
|
5375
6040
|
async tail(options) {
|
|
5376
|
-
const { filePath, signal, onLine } = options;
|
|
5377
|
-
const
|
|
5378
|
-
let position = 0;
|
|
6041
|
+
const { filePath, signal, onLine, pollInterval = 100 } = options;
|
|
6042
|
+
const state = { file: null };
|
|
5379
6043
|
const decoder = new TextDecoder();
|
|
5380
|
-
|
|
5381
|
-
|
|
5382
|
-
|
|
5383
|
-
|
|
5384
|
-
|
|
5385
|
-
}
|
|
5386
|
-
try {
|
|
5387
|
-
const { bytesRead, buffer: chunk } = await file.read({
|
|
5388
|
-
buffer: Buffer.alloc(4096),
|
|
5389
|
-
position
|
|
5390
|
-
});
|
|
5391
|
-
if (bytesRead > 0) {
|
|
5392
|
-
position += bytesRead;
|
|
5393
|
-
buffer += decoder.decode(chunk.subarray(0, bytesRead), { stream: true });
|
|
5394
|
-
const lines = buffer.split("\n");
|
|
5395
|
-
buffer = lines.pop() ?? "";
|
|
5396
|
-
for (const line of lines) {
|
|
5397
|
-
if (line) {
|
|
5398
|
-
onLine(line);
|
|
5399
|
-
}
|
|
6044
|
+
const adapter = {
|
|
6045
|
+
readChunk: async (position) => {
|
|
6046
|
+
try {
|
|
6047
|
+
if (!state.file) {
|
|
6048
|
+
state.file = await (0, import_promises.open)(filePath, "r");
|
|
5400
6049
|
}
|
|
5401
|
-
|
|
5402
|
-
|
|
5403
|
-
|
|
5404
|
-
throw error;
|
|
5405
|
-
}
|
|
5406
|
-
if (!signal?.aborted) {
|
|
5407
|
-
setTimeout(() => {
|
|
5408
|
-
poll().catch(() => {
|
|
6050
|
+
const { bytesRead, buffer: chunk } = await state.file.read({
|
|
6051
|
+
buffer: Buffer.alloc(4096),
|
|
6052
|
+
position
|
|
5409
6053
|
});
|
|
5410
|
-
|
|
5411
|
-
|
|
5412
|
-
|
|
5413
|
-
|
|
6054
|
+
return {
|
|
6055
|
+
data: decoder.decode(chunk.subarray(0, bytesRead), { stream: true }),
|
|
6056
|
+
newPosition: position + bytesRead
|
|
6057
|
+
};
|
|
6058
|
+
} catch {
|
|
6059
|
+
return null;
|
|
6060
|
+
}
|
|
6061
|
+
},
|
|
6062
|
+
sleep: (ms) => new Promise((resolve) => setTimeout(resolve, ms))
|
|
5414
6063
|
};
|
|
5415
|
-
|
|
6064
|
+
try {
|
|
6065
|
+
await runTailPolling({ adapter, signal, pollInterval, onLine });
|
|
6066
|
+
} finally {
|
|
6067
|
+
if (state.file) {
|
|
6068
|
+
await state.file.close();
|
|
6069
|
+
}
|
|
6070
|
+
}
|
|
5416
6071
|
}
|
|
5417
6072
|
async deleteFile(filePath) {
|
|
5418
6073
|
await (0, import_promises.rm)(filePath, { force: true });
|
|
@@ -5436,83 +6091,39 @@ var NodeFsAdapter = class {
|
|
|
5436
6091
|
}
|
|
5437
6092
|
tailStreaming(filePath, options) {
|
|
5438
6093
|
const { signal, pollInterval = 100 } = options ?? {};
|
|
5439
|
-
const state = {
|
|
5440
|
-
|
|
5441
|
-
|
|
5442
|
-
|
|
5443
|
-
};
|
|
5444
|
-
const stop = () => {
|
|
5445
|
-
state.stopped = true;
|
|
5446
|
-
if (state.resolveNext) {
|
|
5447
|
-
state.resolveNext({ done: true, value: void 0 });
|
|
5448
|
-
state.resolveNext = null;
|
|
5449
|
-
}
|
|
5450
|
-
};
|
|
5451
|
-
const startPolling = async () => {
|
|
5452
|
-
let file;
|
|
5453
|
-
try {
|
|
5454
|
-
file = await (0, import_promises.open)(filePath, "r");
|
|
5455
|
-
} catch {
|
|
5456
|
-
stop();
|
|
5457
|
-
return;
|
|
5458
|
-
}
|
|
5459
|
-
let position = 0;
|
|
5460
|
-
const decoder = new TextDecoder();
|
|
5461
|
-
let buffer = "";
|
|
5462
|
-
while (!(state.stopped || signal?.aborted)) {
|
|
6094
|
+
const state = { file: null };
|
|
6095
|
+
const decoder = new TextDecoder();
|
|
6096
|
+
const adapter = {
|
|
6097
|
+
readChunk: async (position) => {
|
|
5463
6098
|
try {
|
|
5464
|
-
|
|
6099
|
+
if (!state.file) {
|
|
6100
|
+
state.file = await (0, import_promises.open)(filePath, "r");
|
|
6101
|
+
}
|
|
6102
|
+
const { bytesRead, buffer: chunk } = await state.file.read({
|
|
5465
6103
|
buffer: Buffer.alloc(4096),
|
|
5466
6104
|
position
|
|
5467
6105
|
});
|
|
5468
|
-
|
|
5469
|
-
|
|
5470
|
-
|
|
5471
|
-
|
|
5472
|
-
buffer = lines2.pop() ?? "";
|
|
5473
|
-
for (const line of lines2) {
|
|
5474
|
-
if (line) {
|
|
5475
|
-
if (state.resolveNext) {
|
|
5476
|
-
const resolver = state.resolveNext;
|
|
5477
|
-
state.resolveNext = null;
|
|
5478
|
-
resolver({ done: false, value: line });
|
|
5479
|
-
} else {
|
|
5480
|
-
state.lineQueue.push(line);
|
|
5481
|
-
}
|
|
5482
|
-
}
|
|
5483
|
-
}
|
|
5484
|
-
}
|
|
6106
|
+
return {
|
|
6107
|
+
data: decoder.decode(chunk.subarray(0, bytesRead), { stream: true }),
|
|
6108
|
+
newPosition: position + bytesRead
|
|
6109
|
+
};
|
|
5485
6110
|
} catch {
|
|
5486
|
-
|
|
6111
|
+
return null;
|
|
5487
6112
|
}
|
|
5488
|
-
|
|
5489
|
-
|
|
5490
|
-
await file.close();
|
|
5491
|
-
stop();
|
|
6113
|
+
},
|
|
6114
|
+
sleep: (ms) => new Promise((resolve) => setTimeout(resolve, ms))
|
|
5492
6115
|
};
|
|
5493
|
-
|
|
5494
|
-
|
|
5495
|
-
const
|
|
5496
|
-
|
|
5497
|
-
|
|
5498
|
-
|
|
5499
|
-
|
|
5500
|
-
|
|
5501
|
-
}
|
|
5502
|
-
if (state.lineQueue.length > 0) {
|
|
5503
|
-
const value = state.lineQueue.shift();
|
|
5504
|
-
if (value !== void 0) {
|
|
5505
|
-
return Promise.resolve({ done: false, value });
|
|
5506
|
-
}
|
|
5507
|
-
}
|
|
5508
|
-
return new Promise((resolve) => {
|
|
5509
|
-
state.resolveNext = resolve;
|
|
5510
|
-
});
|
|
5511
|
-
}
|
|
5512
|
-
};
|
|
6116
|
+
const polling = createTailPolling({ adapter, signal, pollInterval });
|
|
6117
|
+
const originalStop = polling.stop;
|
|
6118
|
+
const enhancedStop = () => {
|
|
6119
|
+
originalStop();
|
|
6120
|
+
if (state.file) {
|
|
6121
|
+
state.file.close().catch(() => {
|
|
6122
|
+
});
|
|
6123
|
+
state.file = null;
|
|
5513
6124
|
}
|
|
5514
6125
|
};
|
|
5515
|
-
return { lines, stop };
|
|
6126
|
+
return { lines: polling.lines, stop: enhancedStop };
|
|
5516
6127
|
}
|
|
5517
6128
|
};
|
|
5518
6129
|
|
|
@@ -5523,13 +6134,31 @@ function createNodeAdapters() {
|
|
|
5523
6134
|
fs: new NodeFsAdapter()
|
|
5524
6135
|
};
|
|
5525
6136
|
}
|
|
5526
|
-
var TypeGit = class {
|
|
6137
|
+
var TypeGit = class _TypeGit {
|
|
5527
6138
|
git;
|
|
5528
|
-
|
|
5529
|
-
|
|
5530
|
-
|
|
6139
|
+
/**
|
|
6140
|
+
* Create a TypeGit instance with Git version check
|
|
6141
|
+
*
|
|
6142
|
+
* @param createOpts - Options including skipVersionCheck
|
|
6143
|
+
* @returns TypeGit instance
|
|
6144
|
+
* @throws GitError with kind 'UnsupportedGitVersion' if Git version is below minimum
|
|
6145
|
+
*/
|
|
6146
|
+
static async create(createOpts) {
|
|
6147
|
+
const gitInstance = await createGit({
|
|
6148
|
+
...createOpts,
|
|
5531
6149
|
adapters: createNodeAdapters()
|
|
5532
6150
|
});
|
|
6151
|
+
return new _TypeGit(gitInstance);
|
|
6152
|
+
}
|
|
6153
|
+
constructor(optionsOrGit) {
|
|
6154
|
+
if (optionsOrGit && "open" in optionsOrGit) {
|
|
6155
|
+
this.git = optionsOrGit;
|
|
6156
|
+
} else {
|
|
6157
|
+
this.git = createGitSync({
|
|
6158
|
+
...optionsOrGit,
|
|
6159
|
+
adapters: createNodeAdapters()
|
|
6160
|
+
});
|
|
6161
|
+
}
|
|
5533
6162
|
}
|
|
5534
6163
|
/**
|
|
5535
6164
|
* Open an existing worktree repository
|