@mcp-s/skills 1.0.5 → 1.3.1

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.
@@ -0,0 +1,3584 @@
1
+ import { r as __toESM } from "../rolldown-runtime.mjs";
2
+ import { n as require_src, t as require_dist } from "./@kwsites/file-exists.mjs";
3
+ import { t as require_dist$1 } from "./@kwsites/promise-deferred.mjs";
4
+ import { spawn } from "child_process";
5
+ import { Buffer as Buffer$1 } from "node:buffer";
6
+ import { normalize } from "node:path";
7
+ import { EventEmitter } from "node:events";
8
+ var import_dist = require_dist();
9
+ var import_src = /* @__PURE__ */ __toESM(require_src(), 1);
10
+ var import_dist$1 = require_dist$1();
11
+ var __defProp = Object.defineProperty;
12
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
13
+ var __getOwnPropNames = Object.getOwnPropertyNames;
14
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
15
+ var __esm = (fn, res) => function __init() {
16
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
17
+ };
18
+ var __commonJS = (cb, mod) => function __require() {
19
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
20
+ };
21
+ var __export = (target, all) => {
22
+ for (var name in all) __defProp(target, name, {
23
+ get: all[name],
24
+ enumerable: true
25
+ });
26
+ };
27
+ var __copyProps = (to, from, except, desc) => {
28
+ if (from && typeof from === "object" || typeof from === "function") {
29
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
30
+ get: () => from[key],
31
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
32
+ });
33
+ }
34
+ return to;
35
+ };
36
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
37
+ function pathspec(...paths) {
38
+ const key = new String(paths);
39
+ cache.set(key, paths);
40
+ return key;
41
+ }
42
+ function isPathSpec(path) {
43
+ return path instanceof String && cache.has(path);
44
+ }
45
+ function toPaths(pathSpec) {
46
+ return cache.get(pathSpec) || [];
47
+ }
48
+ var cache;
49
+ var init_pathspec = __esm({ "src/lib/args/pathspec.ts"() {
50
+ "use strict";
51
+ cache = /* @__PURE__ */ new WeakMap();
52
+ } });
53
+ var GitError;
54
+ var init_git_error = __esm({ "src/lib/errors/git-error.ts"() {
55
+ "use strict";
56
+ GitError = class extends Error {
57
+ constructor(task, message) {
58
+ super(message);
59
+ this.task = task;
60
+ Object.setPrototypeOf(this, new.target.prototype);
61
+ }
62
+ };
63
+ } });
64
+ var GitResponseError;
65
+ var init_git_response_error = __esm({ "src/lib/errors/git-response-error.ts"() {
66
+ "use strict";
67
+ init_git_error();
68
+ GitResponseError = class extends GitError {
69
+ constructor(git, message) {
70
+ super(void 0, message || String(git));
71
+ this.git = git;
72
+ }
73
+ };
74
+ } });
75
+ var TaskConfigurationError;
76
+ var init_task_configuration_error = __esm({ "src/lib/errors/task-configuration-error.ts"() {
77
+ "use strict";
78
+ init_git_error();
79
+ TaskConfigurationError = class extends GitError {
80
+ constructor(message) {
81
+ super(void 0, message);
82
+ }
83
+ };
84
+ } });
85
+ function asFunction(source) {
86
+ if (typeof source !== "function") return NOOP;
87
+ return source;
88
+ }
89
+ function isUserFunction(source) {
90
+ return typeof source === "function" && source !== NOOP;
91
+ }
92
+ function splitOn(input, char) {
93
+ const index = input.indexOf(char);
94
+ if (index <= 0) return [input, ""];
95
+ return [input.substr(0, index), input.substr(index + 1)];
96
+ }
97
+ function first(input, offset = 0) {
98
+ return isArrayLike(input) && input.length > offset ? input[offset] : void 0;
99
+ }
100
+ function last(input, offset = 0) {
101
+ if (isArrayLike(input) && input.length > offset) return input[input.length - 1 - offset];
102
+ }
103
+ function isArrayLike(input) {
104
+ return filterHasLength(input);
105
+ }
106
+ function toLinesWithContent(input = "", trimmed2 = true, separator = "\n") {
107
+ return input.split(separator).reduce((output, line) => {
108
+ const lineContent = trimmed2 ? line.trim() : line;
109
+ if (lineContent) output.push(lineContent);
110
+ return output;
111
+ }, []);
112
+ }
113
+ function forEachLineWithContent(input, callback) {
114
+ return toLinesWithContent(input, true).map((line) => callback(line));
115
+ }
116
+ function folderExists(path) {
117
+ return (0, import_dist.exists)(path, import_dist.FOLDER);
118
+ }
119
+ function append(target, item) {
120
+ if (Array.isArray(target)) {
121
+ if (!target.includes(item)) target.push(item);
122
+ } else target.add(item);
123
+ return item;
124
+ }
125
+ function including(target, item) {
126
+ if (Array.isArray(target) && !target.includes(item)) target.push(item);
127
+ return target;
128
+ }
129
+ function remove(target, item) {
130
+ if (Array.isArray(target)) {
131
+ const index = target.indexOf(item);
132
+ if (index >= 0) target.splice(index, 1);
133
+ } else target.delete(item);
134
+ return item;
135
+ }
136
+ function asArray(source) {
137
+ return Array.isArray(source) ? source : [source];
138
+ }
139
+ function asCamelCase(str) {
140
+ return str.replace(/[\s-]+(.)/g, (_all, chr) => {
141
+ return chr.toUpperCase();
142
+ });
143
+ }
144
+ function asStringArray(source) {
145
+ return asArray(source).map((item) => {
146
+ return item instanceof String ? item : String(item);
147
+ });
148
+ }
149
+ function asNumber(source, onNaN = 0) {
150
+ if (source == null) return onNaN;
151
+ const num = parseInt(source, 10);
152
+ return Number.isNaN(num) ? onNaN : num;
153
+ }
154
+ function prefixedArray(input, prefix) {
155
+ const output = [];
156
+ for (let i = 0, max = input.length; i < max; i++) output.push(prefix, input[i]);
157
+ return output;
158
+ }
159
+ function bufferToString(input) {
160
+ return (Array.isArray(input) ? Buffer$1.concat(input) : input).toString("utf-8");
161
+ }
162
+ function pick(source, properties) {
163
+ const out = {};
164
+ properties.forEach((key) => {
165
+ if (source[key] !== void 0) out[key] = source[key];
166
+ });
167
+ return out;
168
+ }
169
+ function delay(duration = 0) {
170
+ return new Promise((done) => setTimeout(done, duration));
171
+ }
172
+ function orVoid(input) {
173
+ if (input === false) return;
174
+ return input;
175
+ }
176
+ var NULL, NOOP, objectToString;
177
+ var init_util = __esm({ "src/lib/utils/util.ts"() {
178
+ "use strict";
179
+ init_argument_filters();
180
+ NULL = "\0";
181
+ NOOP = () => {};
182
+ objectToString = Object.prototype.toString.call.bind(Object.prototype.toString);
183
+ } });
184
+ function filterType(input, filter, def) {
185
+ if (filter(input)) return input;
186
+ return arguments.length > 2 ? def : void 0;
187
+ }
188
+ function filterPrimitives(input, omit) {
189
+ const type = isPathSpec(input) ? "string" : typeof input;
190
+ return /number|string|boolean/.test(type) && (!omit || !omit.includes(type));
191
+ }
192
+ function filterPlainObject(input) {
193
+ return !!input && objectToString(input) === "[object Object]";
194
+ }
195
+ function filterFunction(input) {
196
+ return typeof input === "function";
197
+ }
198
+ var filterArray, filterNumber, filterString, filterStringOrStringArray, filterHasLength;
199
+ var init_argument_filters = __esm({ "src/lib/utils/argument-filters.ts"() {
200
+ "use strict";
201
+ init_pathspec();
202
+ init_util();
203
+ filterArray = (input) => {
204
+ return Array.isArray(input);
205
+ };
206
+ filterNumber = (input) => {
207
+ return typeof input === "number";
208
+ };
209
+ filterString = (input) => {
210
+ return typeof input === "string";
211
+ };
212
+ filterStringOrStringArray = (input) => {
213
+ return filterString(input) || Array.isArray(input) && input.every(filterString);
214
+ };
215
+ filterHasLength = (input) => {
216
+ if (input == null || "number|boolean|function".includes(typeof input)) return false;
217
+ return typeof input.length === "number";
218
+ };
219
+ } });
220
+ var ExitCodes;
221
+ var init_exit_codes = __esm({ "src/lib/utils/exit-codes.ts"() {
222
+ "use strict";
223
+ ExitCodes = /* @__PURE__ */ ((ExitCodes2) => {
224
+ ExitCodes2[ExitCodes2["SUCCESS"] = 0] = "SUCCESS";
225
+ ExitCodes2[ExitCodes2["ERROR"] = 1] = "ERROR";
226
+ ExitCodes2[ExitCodes2["NOT_FOUND"] = -2] = "NOT_FOUND";
227
+ ExitCodes2[ExitCodes2["UNCLEAN"] = 128] = "UNCLEAN";
228
+ return ExitCodes2;
229
+ })(ExitCodes || {});
230
+ } });
231
+ var GitOutputStreams;
232
+ var init_git_output_streams = __esm({ "src/lib/utils/git-output-streams.ts"() {
233
+ "use strict";
234
+ GitOutputStreams = class _GitOutputStreams {
235
+ constructor(stdOut, stdErr) {
236
+ this.stdOut = stdOut;
237
+ this.stdErr = stdErr;
238
+ }
239
+ asStrings() {
240
+ return new _GitOutputStreams(this.stdOut.toString("utf8"), this.stdErr.toString("utf8"));
241
+ }
242
+ };
243
+ } });
244
+ function useMatchesDefault() {
245
+ throw new Error(`LineParser:useMatches not implemented`);
246
+ }
247
+ var LineParser, RemoteLineParser;
248
+ var init_line_parser = __esm({ "src/lib/utils/line-parser.ts"() {
249
+ "use strict";
250
+ LineParser = class {
251
+ constructor(regExp, useMatches) {
252
+ this.matches = [];
253
+ this.useMatches = useMatchesDefault;
254
+ this.parse = (line, target) => {
255
+ this.resetMatches();
256
+ if (!this._regExp.every((reg, index) => this.addMatch(reg, index, line(index)))) return false;
257
+ return this.useMatches(target, this.prepareMatches()) !== false;
258
+ };
259
+ this._regExp = Array.isArray(regExp) ? regExp : [regExp];
260
+ if (useMatches) this.useMatches = useMatches;
261
+ }
262
+ resetMatches() {
263
+ this.matches.length = 0;
264
+ }
265
+ prepareMatches() {
266
+ return this.matches;
267
+ }
268
+ addMatch(reg, index, line) {
269
+ const matched = line && reg.exec(line);
270
+ if (matched) this.pushMatch(index, matched);
271
+ return !!matched;
272
+ }
273
+ pushMatch(_index, matched) {
274
+ this.matches.push(...matched.slice(1));
275
+ }
276
+ };
277
+ RemoteLineParser = class extends LineParser {
278
+ addMatch(reg, index, line) {
279
+ return /^remote:\s/.test(String(line)) && super.addMatch(reg, index, line);
280
+ }
281
+ pushMatch(index, matched) {
282
+ if (index > 0 || matched.length > 1) super.pushMatch(index, matched);
283
+ }
284
+ };
285
+ } });
286
+ function createInstanceConfig(...options) {
287
+ const baseDir = process.cwd();
288
+ const config = Object.assign({
289
+ baseDir,
290
+ ...defaultOptions
291
+ }, ...options.filter((o) => typeof o === "object" && o));
292
+ config.baseDir = config.baseDir || baseDir;
293
+ config.trimmed = config.trimmed === true;
294
+ return config;
295
+ }
296
+ var defaultOptions;
297
+ var init_simple_git_options = __esm({ "src/lib/utils/simple-git-options.ts"() {
298
+ "use strict";
299
+ defaultOptions = {
300
+ binary: "git",
301
+ maxConcurrentProcesses: 5,
302
+ config: [],
303
+ trimmed: false
304
+ };
305
+ } });
306
+ function appendTaskOptions(options, commands = []) {
307
+ if (!filterPlainObject(options)) return commands;
308
+ return Object.keys(options).reduce((commands2, key) => {
309
+ const value = options[key];
310
+ if (isPathSpec(value)) commands2.push(value);
311
+ else if (filterPrimitives(value, ["boolean"])) commands2.push(key + "=" + value);
312
+ else if (Array.isArray(value)) {
313
+ for (const v of value) if (!filterPrimitives(v, ["string", "number"])) commands2.push(key + "=" + v);
314
+ } else commands2.push(key);
315
+ return commands2;
316
+ }, commands);
317
+ }
318
+ function getTrailingOptions(args, initialPrimitive = 0, objectOnly = false) {
319
+ const command = [];
320
+ for (let i = 0, max = initialPrimitive < 0 ? args.length : initialPrimitive; i < max; i++) if ("string|number".includes(typeof args[i])) command.push(String(args[i]));
321
+ appendTaskOptions(trailingOptionsArgument(args), command);
322
+ if (!objectOnly) command.push(...trailingArrayArgument(args));
323
+ return command;
324
+ }
325
+ function trailingArrayArgument(args) {
326
+ return asStringArray(filterType(last(args, typeof last(args) === "function" ? 1 : 0), filterArray, []));
327
+ }
328
+ function trailingOptionsArgument(args) {
329
+ return filterType(last(args, filterFunction(last(args)) ? 1 : 0), filterPlainObject);
330
+ }
331
+ function trailingFunctionArgument(args, includeNoop = true) {
332
+ const callback = asFunction(last(args));
333
+ return includeNoop || isUserFunction(callback) ? callback : void 0;
334
+ }
335
+ var init_task_options = __esm({ "src/lib/utils/task-options.ts"() {
336
+ "use strict";
337
+ init_argument_filters();
338
+ init_util();
339
+ init_pathspec();
340
+ } });
341
+ function callTaskParser(parser4, streams) {
342
+ return parser4(streams.stdOut, streams.stdErr);
343
+ }
344
+ function parseStringResponse(result, parsers12, texts, trim = true) {
345
+ asArray(texts).forEach((text) => {
346
+ for (let lines = toLinesWithContent(text, trim), i = 0, max = lines.length; i < max; i++) {
347
+ const line = (offset = 0) => {
348
+ if (i + offset >= max) return;
349
+ return lines[i + offset];
350
+ };
351
+ parsers12.some(({ parse }) => parse(line, result));
352
+ }
353
+ });
354
+ return result;
355
+ }
356
+ var init_task_parser = __esm({ "src/lib/utils/task-parser.ts"() {
357
+ "use strict";
358
+ init_util();
359
+ } });
360
+ var utils_exports = {};
361
+ __export(utils_exports, {
362
+ ExitCodes: () => ExitCodes,
363
+ GitOutputStreams: () => GitOutputStreams,
364
+ LineParser: () => LineParser,
365
+ NOOP: () => NOOP,
366
+ NULL: () => NULL,
367
+ RemoteLineParser: () => RemoteLineParser,
368
+ append: () => append,
369
+ appendTaskOptions: () => appendTaskOptions,
370
+ asArray: () => asArray,
371
+ asCamelCase: () => asCamelCase,
372
+ asFunction: () => asFunction,
373
+ asNumber: () => asNumber,
374
+ asStringArray: () => asStringArray,
375
+ bufferToString: () => bufferToString,
376
+ callTaskParser: () => callTaskParser,
377
+ createInstanceConfig: () => createInstanceConfig,
378
+ delay: () => delay,
379
+ filterArray: () => filterArray,
380
+ filterFunction: () => filterFunction,
381
+ filterHasLength: () => filterHasLength,
382
+ filterNumber: () => filterNumber,
383
+ filterPlainObject: () => filterPlainObject,
384
+ filterPrimitives: () => filterPrimitives,
385
+ filterString: () => filterString,
386
+ filterStringOrStringArray: () => filterStringOrStringArray,
387
+ filterType: () => filterType,
388
+ first: () => first,
389
+ folderExists: () => folderExists,
390
+ forEachLineWithContent: () => forEachLineWithContent,
391
+ getTrailingOptions: () => getTrailingOptions,
392
+ including: () => including,
393
+ isUserFunction: () => isUserFunction,
394
+ last: () => last,
395
+ objectToString: () => objectToString,
396
+ orVoid: () => orVoid,
397
+ parseStringResponse: () => parseStringResponse,
398
+ pick: () => pick,
399
+ prefixedArray: () => prefixedArray,
400
+ remove: () => remove,
401
+ splitOn: () => splitOn,
402
+ toLinesWithContent: () => toLinesWithContent,
403
+ trailingFunctionArgument: () => trailingFunctionArgument,
404
+ trailingOptionsArgument: () => trailingOptionsArgument
405
+ });
406
+ var init_utils = __esm({ "src/lib/utils/index.ts"() {
407
+ "use strict";
408
+ init_argument_filters();
409
+ init_exit_codes();
410
+ init_git_output_streams();
411
+ init_line_parser();
412
+ init_simple_git_options();
413
+ init_task_options();
414
+ init_task_parser();
415
+ init_util();
416
+ } });
417
+ var check_is_repo_exports = {};
418
+ __export(check_is_repo_exports, {
419
+ CheckRepoActions: () => CheckRepoActions,
420
+ checkIsBareRepoTask: () => checkIsBareRepoTask,
421
+ checkIsRepoRootTask: () => checkIsRepoRootTask,
422
+ checkIsRepoTask: () => checkIsRepoTask
423
+ });
424
+ function checkIsRepoTask(action) {
425
+ switch (action) {
426
+ case "bare": return checkIsBareRepoTask();
427
+ case "root": return checkIsRepoRootTask();
428
+ }
429
+ return {
430
+ commands: ["rev-parse", "--is-inside-work-tree"],
431
+ format: "utf-8",
432
+ onError,
433
+ parser
434
+ };
435
+ }
436
+ function checkIsRepoRootTask() {
437
+ return {
438
+ commands: ["rev-parse", "--git-dir"],
439
+ format: "utf-8",
440
+ onError,
441
+ parser(path) {
442
+ return /^\.(git)?$/.test(path.trim());
443
+ }
444
+ };
445
+ }
446
+ function checkIsBareRepoTask() {
447
+ return {
448
+ commands: ["rev-parse", "--is-bare-repository"],
449
+ format: "utf-8",
450
+ onError,
451
+ parser
452
+ };
453
+ }
454
+ function isNotRepoMessage(error) {
455
+ return /(Not a git repository|Kein Git-Repository)/i.test(String(error));
456
+ }
457
+ var CheckRepoActions, onError, parser;
458
+ var init_check_is_repo = __esm({ "src/lib/tasks/check-is-repo.ts"() {
459
+ "use strict";
460
+ init_utils();
461
+ CheckRepoActions = /* @__PURE__ */ ((CheckRepoActions2) => {
462
+ CheckRepoActions2["BARE"] = "bare";
463
+ CheckRepoActions2["IN_TREE"] = "tree";
464
+ CheckRepoActions2["IS_REPO_ROOT"] = "root";
465
+ return CheckRepoActions2;
466
+ })(CheckRepoActions || {});
467
+ onError = ({ exitCode }, error, done, fail) => {
468
+ if (exitCode === 128 && isNotRepoMessage(error)) return done(Buffer.from("false"));
469
+ fail(error);
470
+ };
471
+ parser = (text) => {
472
+ return text.trim() === "true";
473
+ };
474
+ } });
475
+ function cleanSummaryParser(dryRun, text) {
476
+ const summary = new CleanResponse(dryRun);
477
+ const regexp = dryRun ? dryRunRemovalRegexp : removalRegexp;
478
+ toLinesWithContent(text).forEach((line) => {
479
+ const removed = line.replace(regexp, "");
480
+ summary.paths.push(removed);
481
+ (isFolderRegexp.test(removed) ? summary.folders : summary.files).push(removed);
482
+ });
483
+ return summary;
484
+ }
485
+ var CleanResponse, removalRegexp, dryRunRemovalRegexp, isFolderRegexp;
486
+ var init_CleanSummary = __esm({ "src/lib/responses/CleanSummary.ts"() {
487
+ "use strict";
488
+ init_utils();
489
+ CleanResponse = class {
490
+ constructor(dryRun) {
491
+ this.dryRun = dryRun;
492
+ this.paths = [];
493
+ this.files = [];
494
+ this.folders = [];
495
+ }
496
+ };
497
+ removalRegexp = /^[a-z]+\s*/i;
498
+ dryRunRemovalRegexp = /^[a-z]+\s+[a-z]+\s*/i;
499
+ isFolderRegexp = /\/$/;
500
+ } });
501
+ var task_exports = {};
502
+ __export(task_exports, {
503
+ EMPTY_COMMANDS: () => EMPTY_COMMANDS,
504
+ adhocExecTask: () => adhocExecTask,
505
+ configurationErrorTask: () => configurationErrorTask,
506
+ isBufferTask: () => isBufferTask,
507
+ isEmptyTask: () => isEmptyTask,
508
+ straightThroughBufferTask: () => straightThroughBufferTask,
509
+ straightThroughStringTask: () => straightThroughStringTask
510
+ });
511
+ function adhocExecTask(parser4) {
512
+ return {
513
+ commands: EMPTY_COMMANDS,
514
+ format: "empty",
515
+ parser: parser4
516
+ };
517
+ }
518
+ function configurationErrorTask(error) {
519
+ return {
520
+ commands: EMPTY_COMMANDS,
521
+ format: "empty",
522
+ parser() {
523
+ throw typeof error === "string" ? new TaskConfigurationError(error) : error;
524
+ }
525
+ };
526
+ }
527
+ function straightThroughStringTask(commands, trimmed2 = false) {
528
+ return {
529
+ commands,
530
+ format: "utf-8",
531
+ parser(text) {
532
+ return trimmed2 ? String(text).trim() : text;
533
+ }
534
+ };
535
+ }
536
+ function straightThroughBufferTask(commands) {
537
+ return {
538
+ commands,
539
+ format: "buffer",
540
+ parser(buffer) {
541
+ return buffer;
542
+ }
543
+ };
544
+ }
545
+ function isBufferTask(task) {
546
+ return task.format === "buffer";
547
+ }
548
+ function isEmptyTask(task) {
549
+ return task.format === "empty" || !task.commands.length;
550
+ }
551
+ var EMPTY_COMMANDS;
552
+ var init_task = __esm({ "src/lib/tasks/task.ts"() {
553
+ "use strict";
554
+ init_task_configuration_error();
555
+ EMPTY_COMMANDS = [];
556
+ } });
557
+ var clean_exports = {};
558
+ __export(clean_exports, {
559
+ CONFIG_ERROR_INTERACTIVE_MODE: () => CONFIG_ERROR_INTERACTIVE_MODE,
560
+ CONFIG_ERROR_MODE_REQUIRED: () => CONFIG_ERROR_MODE_REQUIRED,
561
+ CONFIG_ERROR_UNKNOWN_OPTION: () => CONFIG_ERROR_UNKNOWN_OPTION,
562
+ CleanOptions: () => CleanOptions,
563
+ cleanTask: () => cleanTask,
564
+ cleanWithOptionsTask: () => cleanWithOptionsTask,
565
+ isCleanOptionsArray: () => isCleanOptionsArray
566
+ });
567
+ function cleanWithOptionsTask(mode, customArgs) {
568
+ const { cleanMode, options, valid } = getCleanOptions(mode);
569
+ if (!cleanMode) return configurationErrorTask(CONFIG_ERROR_MODE_REQUIRED);
570
+ if (!valid.options) return configurationErrorTask(CONFIG_ERROR_UNKNOWN_OPTION + JSON.stringify(mode));
571
+ options.push(...customArgs);
572
+ if (options.some(isInteractiveMode)) return configurationErrorTask(CONFIG_ERROR_INTERACTIVE_MODE);
573
+ return cleanTask(cleanMode, options);
574
+ }
575
+ function cleanTask(mode, customArgs) {
576
+ return {
577
+ commands: [
578
+ "clean",
579
+ `-${mode}`,
580
+ ...customArgs
581
+ ],
582
+ format: "utf-8",
583
+ parser(text) {
584
+ return cleanSummaryParser(mode === "n", text);
585
+ }
586
+ };
587
+ }
588
+ function isCleanOptionsArray(input) {
589
+ return Array.isArray(input) && input.every((test) => CleanOptionValues.has(test));
590
+ }
591
+ function getCleanOptions(input) {
592
+ let cleanMode;
593
+ let options = [];
594
+ let valid = {
595
+ cleanMode: false,
596
+ options: true
597
+ };
598
+ input.replace(/[^a-z]i/g, "").split("").forEach((char) => {
599
+ if (isCleanMode(char)) {
600
+ cleanMode = char;
601
+ valid.cleanMode = true;
602
+ } else valid.options = valid.options && isKnownOption(options[options.length] = `-${char}`);
603
+ });
604
+ return {
605
+ cleanMode,
606
+ options,
607
+ valid
608
+ };
609
+ }
610
+ function isCleanMode(cleanMode) {
611
+ return cleanMode === "f" || cleanMode === "n";
612
+ }
613
+ function isKnownOption(option) {
614
+ return /^-[a-z]$/i.test(option) && CleanOptionValues.has(option.charAt(1));
615
+ }
616
+ function isInteractiveMode(option) {
617
+ if (/^-[^\-]/.test(option)) return option.indexOf("i") > 0;
618
+ return option === "--interactive";
619
+ }
620
+ var CONFIG_ERROR_INTERACTIVE_MODE, CONFIG_ERROR_MODE_REQUIRED, CONFIG_ERROR_UNKNOWN_OPTION, CleanOptions, CleanOptionValues;
621
+ var init_clean = __esm({ "src/lib/tasks/clean.ts"() {
622
+ "use strict";
623
+ init_CleanSummary();
624
+ init_utils();
625
+ init_task();
626
+ CONFIG_ERROR_INTERACTIVE_MODE = "Git clean interactive mode is not supported";
627
+ CONFIG_ERROR_MODE_REQUIRED = "Git clean mode parameter (\"n\" or \"f\") is required";
628
+ CONFIG_ERROR_UNKNOWN_OPTION = "Git clean unknown option found in: ";
629
+ CleanOptions = /* @__PURE__ */ ((CleanOptions2) => {
630
+ CleanOptions2["DRY_RUN"] = "n";
631
+ CleanOptions2["FORCE"] = "f";
632
+ CleanOptions2["IGNORED_INCLUDED"] = "x";
633
+ CleanOptions2["IGNORED_ONLY"] = "X";
634
+ CleanOptions2["EXCLUDING"] = "e";
635
+ CleanOptions2["QUIET"] = "q";
636
+ CleanOptions2["RECURSIVE"] = "d";
637
+ return CleanOptions2;
638
+ })(CleanOptions || {});
639
+ CleanOptionValues = /* @__PURE__ */ new Set(["i", ...asStringArray(Object.values(CleanOptions))]);
640
+ } });
641
+ function configListParser(text) {
642
+ const config = new ConfigList();
643
+ for (const item of configParser(text)) config.addValue(item.file, String(item.key), item.value);
644
+ return config;
645
+ }
646
+ function configGetParser(text, key) {
647
+ let value = null;
648
+ const values = [];
649
+ const scopes = /* @__PURE__ */ new Map();
650
+ for (const item of configParser(text, key)) {
651
+ if (item.key !== key) continue;
652
+ values.push(value = item.value);
653
+ if (!scopes.has(item.file)) scopes.set(item.file, []);
654
+ scopes.get(item.file).push(value);
655
+ }
656
+ return {
657
+ key,
658
+ paths: Array.from(scopes.keys()),
659
+ scopes,
660
+ value,
661
+ values
662
+ };
663
+ }
664
+ function configFilePath(filePath) {
665
+ return filePath.replace(/^(file):/, "");
666
+ }
667
+ function* configParser(text, requestedKey = null) {
668
+ const lines = text.split("\0");
669
+ for (let i = 0, max = lines.length - 1; i < max;) {
670
+ const file = configFilePath(lines[i++]);
671
+ let value = lines[i++];
672
+ let key = requestedKey;
673
+ if (value.includes("\n")) {
674
+ const line = splitOn(value, "\n");
675
+ key = line[0];
676
+ value = line[1];
677
+ }
678
+ yield {
679
+ file,
680
+ key,
681
+ value
682
+ };
683
+ }
684
+ }
685
+ var ConfigList;
686
+ var init_ConfigList = __esm({ "src/lib/responses/ConfigList.ts"() {
687
+ "use strict";
688
+ init_utils();
689
+ ConfigList = class {
690
+ constructor() {
691
+ this.files = [];
692
+ this.values = /* @__PURE__ */ Object.create(null);
693
+ }
694
+ get all() {
695
+ if (!this._all) this._all = this.files.reduce((all, file) => {
696
+ return Object.assign(all, this.values[file]);
697
+ }, {});
698
+ return this._all;
699
+ }
700
+ addFile(file) {
701
+ if (!(file in this.values)) {
702
+ const latest = last(this.files);
703
+ this.values[file] = latest ? Object.create(this.values[latest]) : {};
704
+ this.files.push(file);
705
+ }
706
+ return this.values[file];
707
+ }
708
+ addValue(file, key, value) {
709
+ const values = this.addFile(file);
710
+ if (!Object.hasOwn(values, key)) values[key] = value;
711
+ else if (Array.isArray(values[key])) values[key].push(value);
712
+ else values[key] = [values[key], value];
713
+ this._all = void 0;
714
+ }
715
+ };
716
+ } });
717
+ function asConfigScope(scope, fallback) {
718
+ if (typeof scope === "string" && Object.hasOwn(GitConfigScope, scope)) return scope;
719
+ return fallback;
720
+ }
721
+ function addConfigTask(key, value, append2, scope) {
722
+ const commands = ["config", `--${scope}`];
723
+ if (append2) commands.push("--add");
724
+ commands.push(key, value);
725
+ return {
726
+ commands,
727
+ format: "utf-8",
728
+ parser(text) {
729
+ return text;
730
+ }
731
+ };
732
+ }
733
+ function getConfigTask(key, scope) {
734
+ const commands = [
735
+ "config",
736
+ "--null",
737
+ "--show-origin",
738
+ "--get-all",
739
+ key
740
+ ];
741
+ if (scope) commands.splice(1, 0, `--${scope}`);
742
+ return {
743
+ commands,
744
+ format: "utf-8",
745
+ parser(text) {
746
+ return configGetParser(text, key);
747
+ }
748
+ };
749
+ }
750
+ function listConfigTask(scope) {
751
+ const commands = [
752
+ "config",
753
+ "--list",
754
+ "--show-origin",
755
+ "--null"
756
+ ];
757
+ if (scope) commands.push(`--${scope}`);
758
+ return {
759
+ commands,
760
+ format: "utf-8",
761
+ parser(text) {
762
+ return configListParser(text);
763
+ }
764
+ };
765
+ }
766
+ function config_default() {
767
+ return {
768
+ addConfig(key, value, ...rest) {
769
+ return this._runTask(addConfigTask(key, value, rest[0] === true, asConfigScope(rest[1], "local")), trailingFunctionArgument(arguments));
770
+ },
771
+ getConfig(key, scope) {
772
+ return this._runTask(getConfigTask(key, asConfigScope(scope, void 0)), trailingFunctionArgument(arguments));
773
+ },
774
+ listConfig(...rest) {
775
+ return this._runTask(listConfigTask(asConfigScope(rest[0], void 0)), trailingFunctionArgument(arguments));
776
+ }
777
+ };
778
+ }
779
+ var GitConfigScope;
780
+ var init_config = __esm({ "src/lib/tasks/config.ts"() {
781
+ "use strict";
782
+ init_ConfigList();
783
+ init_utils();
784
+ GitConfigScope = /* @__PURE__ */ ((GitConfigScope2) => {
785
+ GitConfigScope2["system"] = "system";
786
+ GitConfigScope2["global"] = "global";
787
+ GitConfigScope2["local"] = "local";
788
+ GitConfigScope2["worktree"] = "worktree";
789
+ return GitConfigScope2;
790
+ })(GitConfigScope || {});
791
+ } });
792
+ function isDiffNameStatus(input) {
793
+ return diffNameStatus.has(input);
794
+ }
795
+ var DiffNameStatus, diffNameStatus;
796
+ var init_diff_name_status = __esm({ "src/lib/tasks/diff-name-status.ts"() {
797
+ "use strict";
798
+ DiffNameStatus = /* @__PURE__ */ ((DiffNameStatus2) => {
799
+ DiffNameStatus2["ADDED"] = "A";
800
+ DiffNameStatus2["COPIED"] = "C";
801
+ DiffNameStatus2["DELETED"] = "D";
802
+ DiffNameStatus2["MODIFIED"] = "M";
803
+ DiffNameStatus2["RENAMED"] = "R";
804
+ DiffNameStatus2["CHANGED"] = "T";
805
+ DiffNameStatus2["UNMERGED"] = "U";
806
+ DiffNameStatus2["UNKNOWN"] = "X";
807
+ DiffNameStatus2["BROKEN"] = "B";
808
+ return DiffNameStatus2;
809
+ })(DiffNameStatus || {});
810
+ diffNameStatus = new Set(Object.values(DiffNameStatus));
811
+ } });
812
+ function grepQueryBuilder(...params) {
813
+ return new GrepQuery().param(...params);
814
+ }
815
+ function parseGrep(grep) {
816
+ const paths = /* @__PURE__ */ new Set();
817
+ const results = {};
818
+ forEachLineWithContent(grep, (input) => {
819
+ const [path, line, preview] = input.split(NULL);
820
+ paths.add(path);
821
+ (results[path] = results[path] || []).push({
822
+ line: asNumber(line),
823
+ path,
824
+ preview
825
+ });
826
+ });
827
+ return {
828
+ paths,
829
+ results
830
+ };
831
+ }
832
+ function grep_default() {
833
+ return { grep(searchTerm) {
834
+ const then = trailingFunctionArgument(arguments);
835
+ const options = getTrailingOptions(arguments);
836
+ for (const option of disallowedOptions) if (options.includes(option)) return this._runTask(configurationErrorTask(`git.grep: use of "${option}" is not supported.`), then);
837
+ if (typeof searchTerm === "string") searchTerm = grepQueryBuilder().param(searchTerm);
838
+ const commands = [
839
+ "grep",
840
+ "--null",
841
+ "-n",
842
+ "--full-name",
843
+ ...options,
844
+ ...searchTerm
845
+ ];
846
+ return this._runTask({
847
+ commands,
848
+ format: "utf-8",
849
+ parser(stdOut) {
850
+ return parseGrep(stdOut);
851
+ }
852
+ }, then);
853
+ } };
854
+ }
855
+ var disallowedOptions, Query, _a, GrepQuery;
856
+ var init_grep = __esm({ "src/lib/tasks/grep.ts"() {
857
+ "use strict";
858
+ init_utils();
859
+ init_task();
860
+ disallowedOptions = ["-h"];
861
+ Query = Symbol("grepQuery");
862
+ GrepQuery = class {
863
+ constructor() {
864
+ this[_a] = [];
865
+ }
866
+ *[(_a = Query, Symbol.iterator)]() {
867
+ for (const query of this[Query]) yield query;
868
+ }
869
+ and(...and) {
870
+ and.length && this[Query].push("--and", "(", ...prefixedArray(and, "-e"), ")");
871
+ return this;
872
+ }
873
+ param(...param) {
874
+ this[Query].push(...prefixedArray(param, "-e"));
875
+ return this;
876
+ }
877
+ };
878
+ } });
879
+ var reset_exports = {};
880
+ __export(reset_exports, {
881
+ ResetMode: () => ResetMode,
882
+ getResetMode: () => getResetMode,
883
+ resetTask: () => resetTask
884
+ });
885
+ function resetTask(mode, customArgs) {
886
+ const commands = ["reset"];
887
+ if (isValidResetMode(mode)) commands.push(`--${mode}`);
888
+ commands.push(...customArgs);
889
+ return straightThroughStringTask(commands);
890
+ }
891
+ function getResetMode(mode) {
892
+ if (isValidResetMode(mode)) return mode;
893
+ switch (typeof mode) {
894
+ case "string":
895
+ case "undefined": return "soft";
896
+ }
897
+ }
898
+ function isValidResetMode(mode) {
899
+ return typeof mode === "string" && validResetModes.includes(mode);
900
+ }
901
+ var ResetMode, validResetModes;
902
+ var init_reset = __esm({ "src/lib/tasks/reset.ts"() {
903
+ "use strict";
904
+ init_utils();
905
+ init_task();
906
+ ResetMode = /* @__PURE__ */ ((ResetMode2) => {
907
+ ResetMode2["MIXED"] = "mixed";
908
+ ResetMode2["SOFT"] = "soft";
909
+ ResetMode2["HARD"] = "hard";
910
+ ResetMode2["MERGE"] = "merge";
911
+ ResetMode2["KEEP"] = "keep";
912
+ return ResetMode2;
913
+ })(ResetMode || {});
914
+ validResetModes = asStringArray(Object.values(ResetMode));
915
+ } });
916
+ function createLog() {
917
+ return (0, import_src.default)("simple-git");
918
+ }
919
+ function prefixedLogger(to, prefix, forward) {
920
+ if (!prefix || !String(prefix).replace(/\s*/, "")) return !forward ? to : (message, ...args) => {
921
+ to(message, ...args);
922
+ forward(message, ...args);
923
+ };
924
+ return (message, ...args) => {
925
+ to(`%s ${message}`, prefix, ...args);
926
+ if (forward) forward(message, ...args);
927
+ };
928
+ }
929
+ function childLoggerName(name, childDebugger, { namespace: parentNamespace }) {
930
+ if (typeof name === "string") return name;
931
+ const childNamespace = childDebugger && childDebugger.namespace || "";
932
+ if (childNamespace.startsWith(parentNamespace)) return childNamespace.substr(parentNamespace.length + 1);
933
+ return childNamespace || parentNamespace;
934
+ }
935
+ function createLogger(label, verbose, initialStep, infoDebugger = createLog()) {
936
+ const labelPrefix = label && `[${label}]` || "";
937
+ const spawned = [];
938
+ const debugDebugger = typeof verbose === "string" ? infoDebugger.extend(verbose) : verbose;
939
+ const key = childLoggerName(filterType(verbose, filterString), debugDebugger, infoDebugger);
940
+ return step(initialStep);
941
+ function sibling(name, initial) {
942
+ return append(spawned, createLogger(label, key.replace(/^[^:]+/, name), initial, infoDebugger));
943
+ }
944
+ function step(phase) {
945
+ const stepPrefix = phase && `[${phase}]` || "";
946
+ const debug2 = debugDebugger && prefixedLogger(debugDebugger, stepPrefix) || NOOP;
947
+ const info = prefixedLogger(infoDebugger, `${labelPrefix} ${stepPrefix}`, debug2);
948
+ return Object.assign(debugDebugger ? debug2 : info, {
949
+ label,
950
+ sibling,
951
+ info,
952
+ step
953
+ });
954
+ }
955
+ }
956
+ var init_git_logger = __esm({ "src/lib/git-logger.ts"() {
957
+ "use strict";
958
+ init_utils();
959
+ import_src.default.formatters.L = (value) => String(filterHasLength(value) ? value.length : "-");
960
+ import_src.default.formatters.B = (value) => {
961
+ if (Buffer.isBuffer(value)) return value.toString("utf8");
962
+ return objectToString(value);
963
+ };
964
+ } });
965
+ var TasksPendingQueue;
966
+ var init_tasks_pending_queue = __esm({ "src/lib/runners/tasks-pending-queue.ts"() {
967
+ "use strict";
968
+ init_git_error();
969
+ init_git_logger();
970
+ TasksPendingQueue = class _TasksPendingQueue {
971
+ constructor(logLabel = "GitExecutor") {
972
+ this.logLabel = logLabel;
973
+ this._queue = /* @__PURE__ */ new Map();
974
+ }
975
+ withProgress(task) {
976
+ return this._queue.get(task);
977
+ }
978
+ createProgress(task) {
979
+ const name = _TasksPendingQueue.getName(task.commands[0]);
980
+ return {
981
+ task,
982
+ logger: createLogger(this.logLabel, name),
983
+ name
984
+ };
985
+ }
986
+ push(task) {
987
+ const progress = this.createProgress(task);
988
+ progress.logger("Adding task to the queue, commands = %o", task.commands);
989
+ this._queue.set(task, progress);
990
+ return progress;
991
+ }
992
+ fatal(err) {
993
+ for (const [task, { logger }] of Array.from(this._queue.entries())) {
994
+ if (task === err.task) {
995
+ logger.info(`Failed %o`, err);
996
+ logger(`Fatal exception, any as-yet un-started tasks run through this executor will not be attempted`);
997
+ } else logger.info(`A fatal exception occurred in a previous task, the queue has been purged: %o`, err.message);
998
+ this.complete(task);
999
+ }
1000
+ if (this._queue.size !== 0) throw new Error(`Queue size should be zero after fatal: ${this._queue.size}`);
1001
+ }
1002
+ complete(task) {
1003
+ if (this.withProgress(task)) this._queue.delete(task);
1004
+ }
1005
+ attempt(task) {
1006
+ const progress = this.withProgress(task);
1007
+ if (!progress) throw new GitError(void 0, "TasksPendingQueue: attempt called for an unknown task");
1008
+ progress.logger("Starting task");
1009
+ return progress;
1010
+ }
1011
+ static getName(name = "empty") {
1012
+ return `task:${name}:${++_TasksPendingQueue.counter}`;
1013
+ }
1014
+ static {
1015
+ this.counter = 0;
1016
+ }
1017
+ };
1018
+ } });
1019
+ function pluginContext(task, commands) {
1020
+ return {
1021
+ method: first(task.commands) || "",
1022
+ commands
1023
+ };
1024
+ }
1025
+ function onErrorReceived(target, logger) {
1026
+ return (err) => {
1027
+ logger(`[ERROR] child process exception %o`, err);
1028
+ target.push(Buffer.from(String(err.stack), "ascii"));
1029
+ };
1030
+ }
1031
+ function onDataReceived(target, name, logger, output) {
1032
+ return (buffer) => {
1033
+ logger(`%s received %L bytes`, name, buffer);
1034
+ output(`%B`, buffer);
1035
+ target.push(buffer);
1036
+ };
1037
+ }
1038
+ var GitExecutorChain;
1039
+ var init_git_executor_chain = __esm({ "src/lib/runners/git-executor-chain.ts"() {
1040
+ "use strict";
1041
+ init_git_error();
1042
+ init_task();
1043
+ init_utils();
1044
+ init_tasks_pending_queue();
1045
+ GitExecutorChain = class {
1046
+ constructor(_executor, _scheduler, _plugins) {
1047
+ this._executor = _executor;
1048
+ this._scheduler = _scheduler;
1049
+ this._plugins = _plugins;
1050
+ this._chain = Promise.resolve();
1051
+ this._queue = new TasksPendingQueue();
1052
+ }
1053
+ get cwd() {
1054
+ return this._cwd || this._executor.cwd;
1055
+ }
1056
+ set cwd(cwd) {
1057
+ this._cwd = cwd;
1058
+ }
1059
+ get env() {
1060
+ return this._executor.env;
1061
+ }
1062
+ get outputHandler() {
1063
+ return this._executor.outputHandler;
1064
+ }
1065
+ chain() {
1066
+ return this;
1067
+ }
1068
+ push(task) {
1069
+ this._queue.push(task);
1070
+ return this._chain = this._chain.then(() => this.attemptTask(task));
1071
+ }
1072
+ async attemptTask(task) {
1073
+ const onScheduleComplete = await this._scheduler.next();
1074
+ const onQueueComplete = () => this._queue.complete(task);
1075
+ try {
1076
+ const { logger } = this._queue.attempt(task);
1077
+ return await (isEmptyTask(task) ? this.attemptEmptyTask(task, logger) : this.attemptRemoteTask(task, logger));
1078
+ } catch (e) {
1079
+ throw this.onFatalException(task, e);
1080
+ } finally {
1081
+ onQueueComplete();
1082
+ onScheduleComplete();
1083
+ }
1084
+ }
1085
+ onFatalException(task, e) {
1086
+ const gitError = e instanceof GitError ? Object.assign(e, { task }) : new GitError(task, e && String(e));
1087
+ this._chain = Promise.resolve();
1088
+ this._queue.fatal(gitError);
1089
+ return gitError;
1090
+ }
1091
+ async attemptRemoteTask(task, logger) {
1092
+ const binary = this._plugins.exec("spawn.binary", "", pluginContext(task, task.commands));
1093
+ const args = this._plugins.exec("spawn.args", [...task.commands], pluginContext(task, task.commands));
1094
+ const raw = await this.gitResponse(task, binary, args, this.outputHandler, logger.step("SPAWN"));
1095
+ const outputStreams = await this.handleTaskData(task, args, raw, logger.step("HANDLE"));
1096
+ logger(`passing response to task's parser as a %s`, task.format);
1097
+ if (isBufferTask(task)) return callTaskParser(task.parser, outputStreams);
1098
+ return callTaskParser(task.parser, outputStreams.asStrings());
1099
+ }
1100
+ async attemptEmptyTask(task, logger) {
1101
+ logger(`empty task bypassing child process to call to task's parser`);
1102
+ return task.parser(this);
1103
+ }
1104
+ handleTaskData(task, args, result, logger) {
1105
+ const { exitCode, rejection, stdOut, stdErr } = result;
1106
+ return new Promise((done, fail) => {
1107
+ logger(`Preparing to handle process response exitCode=%d stdOut=`, exitCode);
1108
+ const { error } = this._plugins.exec("task.error", { error: rejection }, {
1109
+ ...pluginContext(task, args),
1110
+ ...result
1111
+ });
1112
+ if (error && task.onError) {
1113
+ logger.info(`exitCode=%s handling with custom error handler`);
1114
+ return task.onError(result, error, (newStdOut) => {
1115
+ logger.info(`custom error handler treated as success`);
1116
+ logger(`custom error returned a %s`, objectToString(newStdOut));
1117
+ done(new GitOutputStreams(Array.isArray(newStdOut) ? Buffer.concat(newStdOut) : newStdOut, Buffer.concat(stdErr)));
1118
+ }, fail);
1119
+ }
1120
+ if (error) {
1121
+ logger.info(`handling as error: exitCode=%s stdErr=%s rejection=%o`, exitCode, stdErr.length, rejection);
1122
+ return fail(error);
1123
+ }
1124
+ logger.info(`retrieving task output complete`);
1125
+ done(new GitOutputStreams(Buffer.concat(stdOut), Buffer.concat(stdErr)));
1126
+ });
1127
+ }
1128
+ async gitResponse(task, command, args, outputHandler, logger) {
1129
+ const outputLogger = logger.sibling("output");
1130
+ const spawnOptions = this._plugins.exec("spawn.options", {
1131
+ cwd: this.cwd,
1132
+ env: this.env,
1133
+ windowsHide: true
1134
+ }, pluginContext(task, task.commands));
1135
+ return new Promise((done) => {
1136
+ const stdOut = [];
1137
+ const stdErr = [];
1138
+ logger.info(`%s %o`, command, args);
1139
+ logger("%O", spawnOptions);
1140
+ let rejection = this._beforeSpawn(task, args);
1141
+ if (rejection) return done({
1142
+ stdOut,
1143
+ stdErr,
1144
+ exitCode: 9901,
1145
+ rejection
1146
+ });
1147
+ this._plugins.exec("spawn.before", void 0, {
1148
+ ...pluginContext(task, args),
1149
+ kill(reason) {
1150
+ rejection = reason || rejection;
1151
+ }
1152
+ });
1153
+ const spawned = spawn(command, args, spawnOptions);
1154
+ spawned.stdout.on("data", onDataReceived(stdOut, "stdOut", logger, outputLogger.step("stdOut")));
1155
+ spawned.stderr.on("data", onDataReceived(stdErr, "stdErr", logger, outputLogger.step("stdErr")));
1156
+ spawned.on("error", onErrorReceived(stdErr, logger));
1157
+ if (outputHandler) {
1158
+ logger(`Passing child process stdOut/stdErr to custom outputHandler`);
1159
+ outputHandler(command, spawned.stdout, spawned.stderr, [...args]);
1160
+ }
1161
+ this._plugins.exec("spawn.after", void 0, {
1162
+ ...pluginContext(task, args),
1163
+ spawned,
1164
+ close(exitCode, reason) {
1165
+ done({
1166
+ stdOut,
1167
+ stdErr,
1168
+ exitCode,
1169
+ rejection: rejection || reason
1170
+ });
1171
+ },
1172
+ kill(reason) {
1173
+ if (spawned.killed) return;
1174
+ rejection = reason;
1175
+ spawned.kill("SIGINT");
1176
+ }
1177
+ });
1178
+ });
1179
+ }
1180
+ _beforeSpawn(task, args) {
1181
+ let rejection;
1182
+ this._plugins.exec("spawn.before", void 0, {
1183
+ ...pluginContext(task, args),
1184
+ kill(reason) {
1185
+ rejection = reason || rejection;
1186
+ }
1187
+ });
1188
+ return rejection;
1189
+ }
1190
+ };
1191
+ } });
1192
+ var git_executor_exports = {};
1193
+ __export(git_executor_exports, { GitExecutor: () => GitExecutor });
1194
+ var GitExecutor;
1195
+ var init_git_executor = __esm({ "src/lib/runners/git-executor.ts"() {
1196
+ "use strict";
1197
+ init_git_executor_chain();
1198
+ GitExecutor = class {
1199
+ constructor(cwd, _scheduler, _plugins) {
1200
+ this.cwd = cwd;
1201
+ this._scheduler = _scheduler;
1202
+ this._plugins = _plugins;
1203
+ this._chain = new GitExecutorChain(this, this._scheduler, this._plugins);
1204
+ }
1205
+ chain() {
1206
+ return new GitExecutorChain(this, this._scheduler, this._plugins);
1207
+ }
1208
+ push(task) {
1209
+ return this._chain.push(task);
1210
+ }
1211
+ };
1212
+ } });
1213
+ function taskCallback(task, response, callback = NOOP) {
1214
+ const onSuccess = (data) => {
1215
+ callback(null, data);
1216
+ };
1217
+ const onError2 = (err) => {
1218
+ if (err?.task === task) callback(err instanceof GitResponseError ? addDeprecationNoticeToError(err) : err, void 0);
1219
+ };
1220
+ response.then(onSuccess, onError2);
1221
+ }
1222
+ function addDeprecationNoticeToError(err) {
1223
+ let log = (name) => {
1224
+ console.warn(`simple-git deprecation notice: accessing GitResponseError.${name} should be GitResponseError.git.${name}, this will no longer be available in version 3`);
1225
+ log = NOOP;
1226
+ };
1227
+ return Object.create(err, Object.getOwnPropertyNames(err.git).reduce(descriptorReducer, {}));
1228
+ function descriptorReducer(all, name) {
1229
+ if (name in err) return all;
1230
+ all[name] = {
1231
+ enumerable: false,
1232
+ configurable: false,
1233
+ get() {
1234
+ log(name);
1235
+ return err.git[name];
1236
+ }
1237
+ };
1238
+ return all;
1239
+ }
1240
+ }
1241
+ var init_task_callback = __esm({ "src/lib/task-callback.ts"() {
1242
+ "use strict";
1243
+ init_git_response_error();
1244
+ init_utils();
1245
+ } });
1246
+ function changeWorkingDirectoryTask(directory, root) {
1247
+ return adhocExecTask((instance) => {
1248
+ if (!folderExists(directory)) throw new Error(`Git.cwd: cannot change to non-directory "${directory}"`);
1249
+ return (root || instance).cwd = directory;
1250
+ });
1251
+ }
1252
+ var init_change_working_directory = __esm({ "src/lib/tasks/change-working-directory.ts"() {
1253
+ "use strict";
1254
+ init_utils();
1255
+ init_task();
1256
+ } });
1257
+ function checkoutTask(args) {
1258
+ const commands = ["checkout", ...args];
1259
+ if (commands[1] === "-b" && commands.includes("-B")) commands[1] = remove(commands, "-B");
1260
+ return straightThroughStringTask(commands);
1261
+ }
1262
+ function checkout_default() {
1263
+ return {
1264
+ checkout() {
1265
+ return this._runTask(checkoutTask(getTrailingOptions(arguments, 1)), trailingFunctionArgument(arguments));
1266
+ },
1267
+ checkoutBranch(branchName, startPoint) {
1268
+ return this._runTask(checkoutTask([
1269
+ "-b",
1270
+ branchName,
1271
+ startPoint,
1272
+ ...getTrailingOptions(arguments)
1273
+ ]), trailingFunctionArgument(arguments));
1274
+ },
1275
+ checkoutLocalBranch(branchName) {
1276
+ return this._runTask(checkoutTask([
1277
+ "-b",
1278
+ branchName,
1279
+ ...getTrailingOptions(arguments)
1280
+ ]), trailingFunctionArgument(arguments));
1281
+ }
1282
+ };
1283
+ }
1284
+ var init_checkout = __esm({ "src/lib/tasks/checkout.ts"() {
1285
+ "use strict";
1286
+ init_utils();
1287
+ init_task();
1288
+ } });
1289
+ function countObjectsResponse() {
1290
+ return {
1291
+ count: 0,
1292
+ garbage: 0,
1293
+ inPack: 0,
1294
+ packs: 0,
1295
+ prunePackable: 0,
1296
+ size: 0,
1297
+ sizeGarbage: 0,
1298
+ sizePack: 0
1299
+ };
1300
+ }
1301
+ function count_objects_default() {
1302
+ return { countObjects() {
1303
+ return this._runTask({
1304
+ commands: ["count-objects", "--verbose"],
1305
+ format: "utf-8",
1306
+ parser(stdOut) {
1307
+ return parseStringResponse(countObjectsResponse(), [parser2], stdOut);
1308
+ }
1309
+ });
1310
+ } };
1311
+ }
1312
+ var parser2;
1313
+ var init_count_objects = __esm({ "src/lib/tasks/count-objects.ts"() {
1314
+ "use strict";
1315
+ init_utils();
1316
+ parser2 = new LineParser(/([a-z-]+): (\d+)$/, (result, [key, value]) => {
1317
+ const property = asCamelCase(key);
1318
+ if (Object.hasOwn(result, property)) result[property] = asNumber(value);
1319
+ });
1320
+ } });
1321
+ function parseCommitResult(stdOut) {
1322
+ return parseStringResponse({
1323
+ author: null,
1324
+ branch: "",
1325
+ commit: "",
1326
+ root: false,
1327
+ summary: {
1328
+ changes: 0,
1329
+ insertions: 0,
1330
+ deletions: 0
1331
+ }
1332
+ }, parsers, stdOut);
1333
+ }
1334
+ var parsers;
1335
+ var init_parse_commit = __esm({ "src/lib/parsers/parse-commit.ts"() {
1336
+ "use strict";
1337
+ init_utils();
1338
+ parsers = [
1339
+ new LineParser(/^\[([^\s]+)( \([^)]+\))? ([^\]]+)/, (result, [branch, root, commit]) => {
1340
+ result.branch = branch;
1341
+ result.commit = commit;
1342
+ result.root = !!root;
1343
+ }),
1344
+ new LineParser(/\s*Author:\s(.+)/i, (result, [author]) => {
1345
+ const parts = author.split("<");
1346
+ const email = parts.pop();
1347
+ if (!email || !email.includes("@")) return;
1348
+ result.author = {
1349
+ email: email.substr(0, email.length - 1),
1350
+ name: parts.join("<").trim()
1351
+ };
1352
+ }),
1353
+ new LineParser(/(\d+)[^,]*(?:,\s*(\d+)[^,]*)(?:,\s*(\d+))/g, (result, [changes, insertions, deletions]) => {
1354
+ result.summary.changes = parseInt(changes, 10) || 0;
1355
+ result.summary.insertions = parseInt(insertions, 10) || 0;
1356
+ result.summary.deletions = parseInt(deletions, 10) || 0;
1357
+ }),
1358
+ new LineParser(/^(\d+)[^,]*(?:,\s*(\d+)[^(]+\(([+-]))?/, (result, [changes, lines, direction]) => {
1359
+ result.summary.changes = parseInt(changes, 10) || 0;
1360
+ const count = parseInt(lines, 10) || 0;
1361
+ if (direction === "-") result.summary.deletions = count;
1362
+ else if (direction === "+") result.summary.insertions = count;
1363
+ })
1364
+ ];
1365
+ } });
1366
+ function commitTask(message, files, customArgs) {
1367
+ return {
1368
+ commands: [
1369
+ "-c",
1370
+ "core.abbrev=40",
1371
+ "commit",
1372
+ ...prefixedArray(message, "-m"),
1373
+ ...files,
1374
+ ...customArgs
1375
+ ],
1376
+ format: "utf-8",
1377
+ parser: parseCommitResult
1378
+ };
1379
+ }
1380
+ function commit_default() {
1381
+ return { commit(message, ...rest) {
1382
+ const next = trailingFunctionArgument(arguments);
1383
+ const task = rejectDeprecatedSignatures(message) || commitTask(asArray(message), asArray(filterType(rest[0], filterStringOrStringArray, [])), [...asStringArray(filterType(rest[1], filterArray, [])), ...getTrailingOptions(arguments, 0, true)]);
1384
+ return this._runTask(task, next);
1385
+ } };
1386
+ function rejectDeprecatedSignatures(message) {
1387
+ return !filterStringOrStringArray(message) && configurationErrorTask(`git.commit: requires the commit message to be supplied as a string/string[]`);
1388
+ }
1389
+ }
1390
+ var init_commit = __esm({ "src/lib/tasks/commit.ts"() {
1391
+ "use strict";
1392
+ init_parse_commit();
1393
+ init_utils();
1394
+ init_task();
1395
+ } });
1396
+ function first_commit_default() {
1397
+ return { firstCommit() {
1398
+ return this._runTask(straightThroughStringTask([
1399
+ "rev-list",
1400
+ "--max-parents=0",
1401
+ "HEAD"
1402
+ ], true), trailingFunctionArgument(arguments));
1403
+ } };
1404
+ }
1405
+ var init_first_commit = __esm({ "src/lib/tasks/first-commit.ts"() {
1406
+ "use strict";
1407
+ init_utils();
1408
+ init_task();
1409
+ } });
1410
+ function hashObjectTask(filePath, write) {
1411
+ const commands = ["hash-object", filePath];
1412
+ if (write) commands.push("-w");
1413
+ return straightThroughStringTask(commands, true);
1414
+ }
1415
+ var init_hash_object = __esm({ "src/lib/tasks/hash-object.ts"() {
1416
+ "use strict";
1417
+ init_task();
1418
+ } });
1419
+ function parseInit(bare, path, text) {
1420
+ const response = String(text).trim();
1421
+ let result;
1422
+ if (result = initResponseRegex.exec(response)) return new InitSummary(bare, path, false, result[1]);
1423
+ if (result = reInitResponseRegex.exec(response)) return new InitSummary(bare, path, true, result[1]);
1424
+ let gitDir = "";
1425
+ const tokens = response.split(" ");
1426
+ while (tokens.length) if (tokens.shift() === "in") {
1427
+ gitDir = tokens.join(" ");
1428
+ break;
1429
+ }
1430
+ return new InitSummary(bare, path, /^re/i.test(response), gitDir);
1431
+ }
1432
+ var InitSummary, initResponseRegex, reInitResponseRegex;
1433
+ var init_InitSummary = __esm({ "src/lib/responses/InitSummary.ts"() {
1434
+ "use strict";
1435
+ InitSummary = class {
1436
+ constructor(bare, path, existing, gitDir) {
1437
+ this.bare = bare;
1438
+ this.path = path;
1439
+ this.existing = existing;
1440
+ this.gitDir = gitDir;
1441
+ }
1442
+ };
1443
+ initResponseRegex = /^Init.+ repository in (.+)$/;
1444
+ reInitResponseRegex = /^Rein.+ in (.+)$/;
1445
+ } });
1446
+ function hasBareCommand(command) {
1447
+ return command.includes(bareCommand);
1448
+ }
1449
+ function initTask(bare = false, path, customArgs) {
1450
+ const commands = ["init", ...customArgs];
1451
+ if (bare && !hasBareCommand(commands)) commands.splice(1, 0, bareCommand);
1452
+ return {
1453
+ commands,
1454
+ format: "utf-8",
1455
+ parser(text) {
1456
+ return parseInit(commands.includes("--bare"), path, text);
1457
+ }
1458
+ };
1459
+ }
1460
+ var bareCommand;
1461
+ var init_init = __esm({ "src/lib/tasks/init.ts"() {
1462
+ "use strict";
1463
+ init_InitSummary();
1464
+ bareCommand = "--bare";
1465
+ } });
1466
+ function logFormatFromCommand(customArgs) {
1467
+ for (let i = 0; i < customArgs.length; i++) {
1468
+ const format = logFormatRegex.exec(customArgs[i]);
1469
+ if (format) return `--${format[1]}`;
1470
+ }
1471
+ return "";
1472
+ }
1473
+ function isLogFormat(customArg) {
1474
+ return logFormatRegex.test(customArg);
1475
+ }
1476
+ var logFormatRegex;
1477
+ var init_log_format = __esm({ "src/lib/args/log-format.ts"() {
1478
+ "use strict";
1479
+ logFormatRegex = /^--(stat|numstat|name-only|name-status)(=|$)/;
1480
+ } });
1481
+ var DiffSummary;
1482
+ var init_DiffSummary = __esm({ "src/lib/responses/DiffSummary.ts"() {
1483
+ "use strict";
1484
+ DiffSummary = class {
1485
+ constructor() {
1486
+ this.changed = 0;
1487
+ this.deletions = 0;
1488
+ this.insertions = 0;
1489
+ this.files = [];
1490
+ }
1491
+ };
1492
+ } });
1493
+ function getDiffParser(format = "") {
1494
+ const parser4 = diffSummaryParsers[format];
1495
+ return (stdOut) => parseStringResponse(new DiffSummary(), parser4, stdOut, false);
1496
+ }
1497
+ var statParser, numStatParser, nameOnlyParser, nameStatusParser, diffSummaryParsers;
1498
+ var init_parse_diff_summary = __esm({ "src/lib/parsers/parse-diff-summary.ts"() {
1499
+ "use strict";
1500
+ init_log_format();
1501
+ init_DiffSummary();
1502
+ init_diff_name_status();
1503
+ init_utils();
1504
+ statParser = [
1505
+ new LineParser(/^(.+)\s+\|\s+(\d+)(\s+[+\-]+)?$/, (result, [file, changes, alterations = ""]) => {
1506
+ result.files.push({
1507
+ file: file.trim(),
1508
+ changes: asNumber(changes),
1509
+ insertions: alterations.replace(/[^+]/g, "").length,
1510
+ deletions: alterations.replace(/[^-]/g, "").length,
1511
+ binary: false
1512
+ });
1513
+ }),
1514
+ new LineParser(/^(.+) \|\s+Bin ([0-9.]+) -> ([0-9.]+) ([a-z]+)/, (result, [file, before, after]) => {
1515
+ result.files.push({
1516
+ file: file.trim(),
1517
+ before: asNumber(before),
1518
+ after: asNumber(after),
1519
+ binary: true
1520
+ });
1521
+ }),
1522
+ new LineParser(/(\d+) files? changed\s*((?:, \d+ [^,]+){0,2})/, (result, [changed, summary]) => {
1523
+ const inserted = /(\d+) i/.exec(summary);
1524
+ const deleted = /(\d+) d/.exec(summary);
1525
+ result.changed = asNumber(changed);
1526
+ result.insertions = asNumber(inserted?.[1]);
1527
+ result.deletions = asNumber(deleted?.[1]);
1528
+ })
1529
+ ];
1530
+ numStatParser = [new LineParser(/(\d+)\t(\d+)\t(.+)$/, (result, [changesInsert, changesDelete, file]) => {
1531
+ const insertions = asNumber(changesInsert);
1532
+ const deletions = asNumber(changesDelete);
1533
+ result.changed++;
1534
+ result.insertions += insertions;
1535
+ result.deletions += deletions;
1536
+ result.files.push({
1537
+ file,
1538
+ changes: insertions + deletions,
1539
+ insertions,
1540
+ deletions,
1541
+ binary: false
1542
+ });
1543
+ }), new LineParser(/-\t-\t(.+)$/, (result, [file]) => {
1544
+ result.changed++;
1545
+ result.files.push({
1546
+ file,
1547
+ after: 0,
1548
+ before: 0,
1549
+ binary: true
1550
+ });
1551
+ })];
1552
+ nameOnlyParser = [new LineParser(/(.+)$/, (result, [file]) => {
1553
+ result.changed++;
1554
+ result.files.push({
1555
+ file,
1556
+ changes: 0,
1557
+ insertions: 0,
1558
+ deletions: 0,
1559
+ binary: false
1560
+ });
1561
+ })];
1562
+ nameStatusParser = [new LineParser(/([ACDMRTUXB])([0-9]{0,3})\t(.[^\t]*)(\t(.[^\t]*))?$/, (result, [status, similarity, from, _to, to]) => {
1563
+ result.changed++;
1564
+ result.files.push({
1565
+ file: to ?? from,
1566
+ changes: 0,
1567
+ insertions: 0,
1568
+ deletions: 0,
1569
+ binary: false,
1570
+ status: orVoid(isDiffNameStatus(status) && status),
1571
+ from: orVoid(!!to && from !== to && from),
1572
+ similarity: asNumber(similarity)
1573
+ });
1574
+ })];
1575
+ diffSummaryParsers = {
1576
+ [""]: statParser,
1577
+ ["--stat"]: statParser,
1578
+ ["--numstat"]: numStatParser,
1579
+ ["--name-status"]: nameStatusParser,
1580
+ ["--name-only"]: nameOnlyParser
1581
+ };
1582
+ } });
1583
+ function lineBuilder(tokens, fields) {
1584
+ return fields.reduce((line, field, index) => {
1585
+ line[field] = tokens[index] || "";
1586
+ return line;
1587
+ }, /* @__PURE__ */ Object.create({ diff: null }));
1588
+ }
1589
+ function createListLogSummaryParser(splitter = SPLITTER, fields = defaultFieldNames, logFormat = "") {
1590
+ const parseDiffResult = getDiffParser(logFormat);
1591
+ return function(stdOut) {
1592
+ const all = toLinesWithContent(stdOut.trim(), false, START_BOUNDARY).map(function(item) {
1593
+ const lineDetail = item.split(COMMIT_BOUNDARY);
1594
+ const listLogLine = lineBuilder(lineDetail[0].split(splitter), fields);
1595
+ if (lineDetail.length > 1 && !!lineDetail[1].trim()) listLogLine.diff = parseDiffResult(lineDetail[1]);
1596
+ return listLogLine;
1597
+ });
1598
+ return {
1599
+ all,
1600
+ latest: all.length && all[0] || null,
1601
+ total: all.length
1602
+ };
1603
+ };
1604
+ }
1605
+ var START_BOUNDARY, COMMIT_BOUNDARY, SPLITTER, defaultFieldNames;
1606
+ var init_parse_list_log_summary = __esm({ "src/lib/parsers/parse-list-log-summary.ts"() {
1607
+ "use strict";
1608
+ init_utils();
1609
+ init_parse_diff_summary();
1610
+ init_log_format();
1611
+ START_BOUNDARY = "òòòòòò ";
1612
+ COMMIT_BOUNDARY = " òò";
1613
+ SPLITTER = " ò ";
1614
+ defaultFieldNames = [
1615
+ "hash",
1616
+ "date",
1617
+ "message",
1618
+ "refs",
1619
+ "author_name",
1620
+ "author_email"
1621
+ ];
1622
+ } });
1623
+ var diff_exports = {};
1624
+ __export(diff_exports, {
1625
+ diffSummaryTask: () => diffSummaryTask,
1626
+ validateLogFormatConfig: () => validateLogFormatConfig
1627
+ });
1628
+ function diffSummaryTask(customArgs) {
1629
+ let logFormat = logFormatFromCommand(customArgs);
1630
+ const commands = ["diff"];
1631
+ if (logFormat === "") {
1632
+ logFormat = "--stat";
1633
+ commands.push("--stat=4096");
1634
+ }
1635
+ commands.push(...customArgs);
1636
+ return validateLogFormatConfig(commands) || {
1637
+ commands,
1638
+ format: "utf-8",
1639
+ parser: getDiffParser(logFormat)
1640
+ };
1641
+ }
1642
+ function validateLogFormatConfig(customArgs) {
1643
+ const flags = customArgs.filter(isLogFormat);
1644
+ if (flags.length > 1) return configurationErrorTask(`Summary flags are mutually exclusive - pick one of ${flags.join(",")}`);
1645
+ if (flags.length && customArgs.includes("-z")) return configurationErrorTask(`Summary flag ${flags} parsing is not compatible with null termination option '-z'`);
1646
+ }
1647
+ var init_diff = __esm({ "src/lib/tasks/diff.ts"() {
1648
+ "use strict";
1649
+ init_log_format();
1650
+ init_parse_diff_summary();
1651
+ init_task();
1652
+ } });
1653
+ function prettyFormat(format, splitter) {
1654
+ const fields = [];
1655
+ const formatStr = [];
1656
+ Object.keys(format).forEach((field) => {
1657
+ fields.push(field);
1658
+ formatStr.push(String(format[field]));
1659
+ });
1660
+ return [fields, formatStr.join(splitter)];
1661
+ }
1662
+ function userOptions(input) {
1663
+ return Object.keys(input).reduce((out, key) => {
1664
+ if (!(key in excludeOptions)) out[key] = input[key];
1665
+ return out;
1666
+ }, {});
1667
+ }
1668
+ function parseLogOptions(opt = {}, customArgs = []) {
1669
+ const splitter = filterType(opt.splitter, filterString, SPLITTER);
1670
+ const [fields, formatStr] = prettyFormat(filterPlainObject(opt.format) ? opt.format : {
1671
+ hash: "%H",
1672
+ date: opt.strictDate === false ? "%ai" : "%aI",
1673
+ message: "%s",
1674
+ refs: "%D",
1675
+ body: opt.multiLine ? "%B" : "%b",
1676
+ author_name: opt.mailMap !== false ? "%aN" : "%an",
1677
+ author_email: opt.mailMap !== false ? "%aE" : "%ae"
1678
+ }, splitter);
1679
+ const suffix = [];
1680
+ const command = [`--pretty=format:${START_BOUNDARY}${formatStr}${COMMIT_BOUNDARY}`, ...customArgs];
1681
+ const maxCount = opt.n || opt["max-count"] || opt.maxCount;
1682
+ if (maxCount) command.push(`--max-count=${maxCount}`);
1683
+ if (opt.from || opt.to) {
1684
+ const rangeOperator = opt.symmetric !== false ? "..." : "..";
1685
+ suffix.push(`${opt.from || ""}${rangeOperator}${opt.to || ""}`);
1686
+ }
1687
+ if (filterString(opt.file)) command.push("--follow", pathspec(opt.file));
1688
+ appendTaskOptions(userOptions(opt), command);
1689
+ return {
1690
+ fields,
1691
+ splitter,
1692
+ commands: [...command, ...suffix]
1693
+ };
1694
+ }
1695
+ function logTask(splitter, fields, customArgs) {
1696
+ const parser4 = createListLogSummaryParser(splitter, fields, logFormatFromCommand(customArgs));
1697
+ return {
1698
+ commands: ["log", ...customArgs],
1699
+ format: "utf-8",
1700
+ parser: parser4
1701
+ };
1702
+ }
1703
+ function log_default() {
1704
+ return { log(...rest) {
1705
+ const next = trailingFunctionArgument(arguments);
1706
+ const options = parseLogOptions(trailingOptionsArgument(arguments), asStringArray(filterType(arguments[0], filterArray, [])));
1707
+ const task = rejectDeprecatedSignatures(...rest) || validateLogFormatConfig(options.commands) || createLogTask(options);
1708
+ return this._runTask(task, next);
1709
+ } };
1710
+ function createLogTask(options) {
1711
+ return logTask(options.splitter, options.fields, options.commands);
1712
+ }
1713
+ function rejectDeprecatedSignatures(from, to) {
1714
+ return filterString(from) && filterString(to) && configurationErrorTask(`git.log(string, string) should be replaced with git.log({ from: string, to: string })`);
1715
+ }
1716
+ }
1717
+ var excludeOptions;
1718
+ var init_log = __esm({ "src/lib/tasks/log.ts"() {
1719
+ "use strict";
1720
+ init_log_format();
1721
+ init_pathspec();
1722
+ init_parse_list_log_summary();
1723
+ init_utils();
1724
+ init_task();
1725
+ init_diff();
1726
+ excludeOptions = /* @__PURE__ */ ((excludeOptions2) => {
1727
+ excludeOptions2[excludeOptions2["--pretty"] = 0] = "--pretty";
1728
+ excludeOptions2[excludeOptions2["max-count"] = 1] = "max-count";
1729
+ excludeOptions2[excludeOptions2["maxCount"] = 2] = "maxCount";
1730
+ excludeOptions2[excludeOptions2["n"] = 3] = "n";
1731
+ excludeOptions2[excludeOptions2["file"] = 4] = "file";
1732
+ excludeOptions2[excludeOptions2["format"] = 5] = "format";
1733
+ excludeOptions2[excludeOptions2["from"] = 6] = "from";
1734
+ excludeOptions2[excludeOptions2["to"] = 7] = "to";
1735
+ excludeOptions2[excludeOptions2["splitter"] = 8] = "splitter";
1736
+ excludeOptions2[excludeOptions2["symmetric"] = 9] = "symmetric";
1737
+ excludeOptions2[excludeOptions2["mailMap"] = 10] = "mailMap";
1738
+ excludeOptions2[excludeOptions2["multiLine"] = 11] = "multiLine";
1739
+ excludeOptions2[excludeOptions2["strictDate"] = 12] = "strictDate";
1740
+ return excludeOptions2;
1741
+ })(excludeOptions || {});
1742
+ } });
1743
+ var MergeSummaryConflict, MergeSummaryDetail;
1744
+ var init_MergeSummary = __esm({ "src/lib/responses/MergeSummary.ts"() {
1745
+ "use strict";
1746
+ MergeSummaryConflict = class {
1747
+ constructor(reason, file = null, meta) {
1748
+ this.reason = reason;
1749
+ this.file = file;
1750
+ this.meta = meta;
1751
+ }
1752
+ toString() {
1753
+ return `${this.file}:${this.reason}`;
1754
+ }
1755
+ };
1756
+ MergeSummaryDetail = class {
1757
+ constructor() {
1758
+ this.conflicts = [];
1759
+ this.merges = [];
1760
+ this.result = "success";
1761
+ }
1762
+ get failed() {
1763
+ return this.conflicts.length > 0;
1764
+ }
1765
+ get reason() {
1766
+ return this.result;
1767
+ }
1768
+ toString() {
1769
+ if (this.conflicts.length) return `CONFLICTS: ${this.conflicts.join(", ")}`;
1770
+ return "OK";
1771
+ }
1772
+ };
1773
+ } });
1774
+ var PullSummary, PullFailedSummary;
1775
+ var init_PullSummary = __esm({ "src/lib/responses/PullSummary.ts"() {
1776
+ "use strict";
1777
+ PullSummary = class {
1778
+ constructor() {
1779
+ this.remoteMessages = { all: [] };
1780
+ this.created = [];
1781
+ this.deleted = [];
1782
+ this.files = [];
1783
+ this.deletions = {};
1784
+ this.insertions = {};
1785
+ this.summary = {
1786
+ changes: 0,
1787
+ deletions: 0,
1788
+ insertions: 0
1789
+ };
1790
+ }
1791
+ };
1792
+ PullFailedSummary = class {
1793
+ constructor() {
1794
+ this.remote = "";
1795
+ this.hash = {
1796
+ local: "",
1797
+ remote: ""
1798
+ };
1799
+ this.branch = {
1800
+ local: "",
1801
+ remote: ""
1802
+ };
1803
+ this.message = "";
1804
+ }
1805
+ toString() {
1806
+ return this.message;
1807
+ }
1808
+ };
1809
+ } });
1810
+ function objectEnumerationResult(remoteMessages) {
1811
+ return remoteMessages.objects = remoteMessages.objects || {
1812
+ compressing: 0,
1813
+ counting: 0,
1814
+ enumerating: 0,
1815
+ packReused: 0,
1816
+ reused: {
1817
+ count: 0,
1818
+ delta: 0
1819
+ },
1820
+ total: {
1821
+ count: 0,
1822
+ delta: 0
1823
+ }
1824
+ };
1825
+ }
1826
+ function asObjectCount(source) {
1827
+ const count = /^\s*(\d+)/.exec(source);
1828
+ const delta = /delta (\d+)/i.exec(source);
1829
+ return {
1830
+ count: asNumber(count && count[1] || "0"),
1831
+ delta: asNumber(delta && delta[1] || "0")
1832
+ };
1833
+ }
1834
+ var remoteMessagesObjectParsers;
1835
+ var init_parse_remote_objects = __esm({ "src/lib/parsers/parse-remote-objects.ts"() {
1836
+ "use strict";
1837
+ init_utils();
1838
+ remoteMessagesObjectParsers = [
1839
+ new RemoteLineParser(/^remote:\s*(enumerating|counting|compressing) objects: (\d+),/i, (result, [action, count]) => {
1840
+ const key = action.toLowerCase();
1841
+ const enumeration = objectEnumerationResult(result.remoteMessages);
1842
+ Object.assign(enumeration, { [key]: asNumber(count) });
1843
+ }),
1844
+ new RemoteLineParser(/^remote:\s*(enumerating|counting|compressing) objects: \d+% \(\d+\/(\d+)\),/i, (result, [action, count]) => {
1845
+ const key = action.toLowerCase();
1846
+ const enumeration = objectEnumerationResult(result.remoteMessages);
1847
+ Object.assign(enumeration, { [key]: asNumber(count) });
1848
+ }),
1849
+ new RemoteLineParser(/total ([^,]+), reused ([^,]+), pack-reused (\d+)/i, (result, [total, reused, packReused]) => {
1850
+ const objects = objectEnumerationResult(result.remoteMessages);
1851
+ objects.total = asObjectCount(total);
1852
+ objects.reused = asObjectCount(reused);
1853
+ objects.packReused = asNumber(packReused);
1854
+ })
1855
+ ];
1856
+ } });
1857
+ function parseRemoteMessages(_stdOut, stdErr) {
1858
+ return parseStringResponse({ remoteMessages: new RemoteMessageSummary() }, parsers2, stdErr);
1859
+ }
1860
+ var parsers2, RemoteMessageSummary;
1861
+ var init_parse_remote_messages = __esm({ "src/lib/parsers/parse-remote-messages.ts"() {
1862
+ "use strict";
1863
+ init_utils();
1864
+ init_parse_remote_objects();
1865
+ parsers2 = [
1866
+ new RemoteLineParser(/^remote:\s*(.+)$/, (result, [text]) => {
1867
+ result.remoteMessages.all.push(text.trim());
1868
+ return false;
1869
+ }),
1870
+ ...remoteMessagesObjectParsers,
1871
+ new RemoteLineParser([/create a (?:pull|merge) request/i, /\s(https?:\/\/\S+)$/], (result, [pullRequestUrl]) => {
1872
+ result.remoteMessages.pullRequestUrl = pullRequestUrl;
1873
+ }),
1874
+ new RemoteLineParser([/found (\d+) vulnerabilities.+\(([^)]+)\)/i, /\s(https?:\/\/\S+)$/], (result, [count, summary, url]) => {
1875
+ result.remoteMessages.vulnerabilities = {
1876
+ count: asNumber(count),
1877
+ summary,
1878
+ url
1879
+ };
1880
+ })
1881
+ ];
1882
+ RemoteMessageSummary = class {
1883
+ constructor() {
1884
+ this.all = [];
1885
+ }
1886
+ };
1887
+ } });
1888
+ function parsePullErrorResult(stdOut, stdErr) {
1889
+ const pullError = parseStringResponse(new PullFailedSummary(), errorParsers, [stdOut, stdErr]);
1890
+ return pullError.message && pullError;
1891
+ }
1892
+ var FILE_UPDATE_REGEX, SUMMARY_REGEX, ACTION_REGEX, parsers3, errorParsers, parsePullDetail, parsePullResult;
1893
+ var init_parse_pull = __esm({ "src/lib/parsers/parse-pull.ts"() {
1894
+ "use strict";
1895
+ init_PullSummary();
1896
+ init_utils();
1897
+ init_parse_remote_messages();
1898
+ FILE_UPDATE_REGEX = /^\s*(.+?)\s+\|\s+\d+\s*(\+*)(-*)/;
1899
+ SUMMARY_REGEX = /(\d+)\D+((\d+)\D+\(\+\))?(\D+(\d+)\D+\(-\))?/;
1900
+ ACTION_REGEX = /^(create|delete) mode \d+ (.+)/;
1901
+ parsers3 = [
1902
+ new LineParser(FILE_UPDATE_REGEX, (result, [file, insertions, deletions]) => {
1903
+ result.files.push(file);
1904
+ if (insertions) result.insertions[file] = insertions.length;
1905
+ if (deletions) result.deletions[file] = deletions.length;
1906
+ }),
1907
+ new LineParser(SUMMARY_REGEX, (result, [changes, , insertions, , deletions]) => {
1908
+ if (insertions !== void 0 || deletions !== void 0) {
1909
+ result.summary.changes = +changes || 0;
1910
+ result.summary.insertions = +insertions || 0;
1911
+ result.summary.deletions = +deletions || 0;
1912
+ return true;
1913
+ }
1914
+ return false;
1915
+ }),
1916
+ new LineParser(ACTION_REGEX, (result, [action, file]) => {
1917
+ append(result.files, file);
1918
+ append(action === "create" ? result.created : result.deleted, file);
1919
+ })
1920
+ ];
1921
+ errorParsers = [
1922
+ new LineParser(/^from\s(.+)$/i, (result, [remote]) => void (result.remote = remote)),
1923
+ new LineParser(/^fatal:\s(.+)$/, (result, [message]) => void (result.message = message)),
1924
+ new LineParser(/([a-z0-9]+)\.\.([a-z0-9]+)\s+(\S+)\s+->\s+(\S+)$/, (result, [hashLocal, hashRemote, branchLocal, branchRemote]) => {
1925
+ result.branch.local = branchLocal;
1926
+ result.hash.local = hashLocal;
1927
+ result.branch.remote = branchRemote;
1928
+ result.hash.remote = hashRemote;
1929
+ })
1930
+ ];
1931
+ parsePullDetail = (stdOut, stdErr) => {
1932
+ return parseStringResponse(new PullSummary(), parsers3, [stdOut, stdErr]);
1933
+ };
1934
+ parsePullResult = (stdOut, stdErr) => {
1935
+ return Object.assign(new PullSummary(), parsePullDetail(stdOut, stdErr), parseRemoteMessages(stdOut, stdErr));
1936
+ };
1937
+ } });
1938
+ var parsers4, parseMergeResult, parseMergeDetail;
1939
+ var init_parse_merge = __esm({ "src/lib/parsers/parse-merge.ts"() {
1940
+ "use strict";
1941
+ init_MergeSummary();
1942
+ init_utils();
1943
+ init_parse_pull();
1944
+ parsers4 = [
1945
+ new LineParser(/^Auto-merging\s+(.+)$/, (summary, [autoMerge]) => {
1946
+ summary.merges.push(autoMerge);
1947
+ }),
1948
+ new LineParser(/^CONFLICT\s+\((.+)\): Merge conflict in (.+)$/, (summary, [reason, file]) => {
1949
+ summary.conflicts.push(new MergeSummaryConflict(reason, file));
1950
+ }),
1951
+ new LineParser(/^CONFLICT\s+\((.+\/delete)\): (.+) deleted in (.+) and/, (summary, [reason, file, deleteRef]) => {
1952
+ summary.conflicts.push(new MergeSummaryConflict(reason, file, { deleteRef }));
1953
+ }),
1954
+ new LineParser(/^CONFLICT\s+\((.+)\):/, (summary, [reason]) => {
1955
+ summary.conflicts.push(new MergeSummaryConflict(reason, null));
1956
+ }),
1957
+ new LineParser(/^Automatic merge failed;\s+(.+)$/, (summary, [result]) => {
1958
+ summary.result = result;
1959
+ })
1960
+ ];
1961
+ parseMergeResult = (stdOut, stdErr) => {
1962
+ return Object.assign(parseMergeDetail(stdOut, stdErr), parsePullResult(stdOut, stdErr));
1963
+ };
1964
+ parseMergeDetail = (stdOut) => {
1965
+ return parseStringResponse(new MergeSummaryDetail(), parsers4, stdOut);
1966
+ };
1967
+ } });
1968
+ function mergeTask(customArgs) {
1969
+ if (!customArgs.length) return configurationErrorTask("Git.merge requires at least one option");
1970
+ return {
1971
+ commands: ["merge", ...customArgs],
1972
+ format: "utf-8",
1973
+ parser(stdOut, stdErr) {
1974
+ const merge = parseMergeResult(stdOut, stdErr);
1975
+ if (merge.failed) throw new GitResponseError(merge);
1976
+ return merge;
1977
+ }
1978
+ };
1979
+ }
1980
+ var init_merge = __esm({ "src/lib/tasks/merge.ts"() {
1981
+ "use strict";
1982
+ init_git_response_error();
1983
+ init_parse_merge();
1984
+ init_task();
1985
+ } });
1986
+ function pushResultPushedItem(local, remote, status) {
1987
+ const deleted = status.includes("deleted");
1988
+ const tag = status.includes("tag") || /^refs\/tags/.test(local);
1989
+ const alreadyUpdated = !status.includes("new");
1990
+ return {
1991
+ deleted,
1992
+ tag,
1993
+ branch: !tag,
1994
+ new: !alreadyUpdated,
1995
+ alreadyUpdated,
1996
+ local,
1997
+ remote
1998
+ };
1999
+ }
2000
+ var parsers5, parsePushResult, parsePushDetail;
2001
+ var init_parse_push = __esm({ "src/lib/parsers/parse-push.ts"() {
2002
+ "use strict";
2003
+ init_utils();
2004
+ init_parse_remote_messages();
2005
+ parsers5 = [
2006
+ new LineParser(/^Pushing to (.+)$/, (result, [repo]) => {
2007
+ result.repo = repo;
2008
+ }),
2009
+ new LineParser(/^updating local tracking ref '(.+)'/, (result, [local]) => {
2010
+ result.ref = {
2011
+ ...result.ref || {},
2012
+ local
2013
+ };
2014
+ }),
2015
+ new LineParser(/^[=*-]\s+([^:]+):(\S+)\s+\[(.+)]$/, (result, [local, remote, type]) => {
2016
+ result.pushed.push(pushResultPushedItem(local, remote, type));
2017
+ }),
2018
+ new LineParser(/^Branch '([^']+)' set up to track remote branch '([^']+)' from '([^']+)'/, (result, [local, remote, remoteName]) => {
2019
+ result.branch = {
2020
+ ...result.branch || {},
2021
+ local,
2022
+ remote,
2023
+ remoteName
2024
+ };
2025
+ }),
2026
+ new LineParser(/^([^:]+):(\S+)\s+([a-z0-9]+)\.\.([a-z0-9]+)$/, (result, [local, remote, from, to]) => {
2027
+ result.update = {
2028
+ head: {
2029
+ local,
2030
+ remote
2031
+ },
2032
+ hash: {
2033
+ from,
2034
+ to
2035
+ }
2036
+ };
2037
+ })
2038
+ ];
2039
+ parsePushResult = (stdOut, stdErr) => {
2040
+ const pushDetail = parsePushDetail(stdOut, stdErr);
2041
+ const responseDetail = parseRemoteMessages(stdOut, stdErr);
2042
+ return {
2043
+ ...pushDetail,
2044
+ ...responseDetail
2045
+ };
2046
+ };
2047
+ parsePushDetail = (stdOut, stdErr) => {
2048
+ return parseStringResponse({ pushed: [] }, parsers5, [stdOut, stdErr]);
2049
+ };
2050
+ } });
2051
+ var push_exports = {};
2052
+ __export(push_exports, {
2053
+ pushTagsTask: () => pushTagsTask,
2054
+ pushTask: () => pushTask
2055
+ });
2056
+ function pushTagsTask(ref = {}, customArgs) {
2057
+ append(customArgs, "--tags");
2058
+ return pushTask(ref, customArgs);
2059
+ }
2060
+ function pushTask(ref = {}, customArgs) {
2061
+ const commands = ["push", ...customArgs];
2062
+ if (ref.branch) commands.splice(1, 0, ref.branch);
2063
+ if (ref.remote) commands.splice(1, 0, ref.remote);
2064
+ remove(commands, "-v");
2065
+ append(commands, "--verbose");
2066
+ append(commands, "--porcelain");
2067
+ return {
2068
+ commands,
2069
+ format: "utf-8",
2070
+ parser: parsePushResult
2071
+ };
2072
+ }
2073
+ var init_push = __esm({ "src/lib/tasks/push.ts"() {
2074
+ "use strict";
2075
+ init_parse_push();
2076
+ init_utils();
2077
+ } });
2078
+ function show_default() {
2079
+ return {
2080
+ showBuffer() {
2081
+ const commands = ["show", ...getTrailingOptions(arguments, 1)];
2082
+ if (!commands.includes("--binary")) commands.splice(1, 0, "--binary");
2083
+ return this._runTask(straightThroughBufferTask(commands), trailingFunctionArgument(arguments));
2084
+ },
2085
+ show() {
2086
+ const commands = ["show", ...getTrailingOptions(arguments, 1)];
2087
+ return this._runTask(straightThroughStringTask(commands), trailingFunctionArgument(arguments));
2088
+ }
2089
+ };
2090
+ }
2091
+ var init_show = __esm({ "src/lib/tasks/show.ts"() {
2092
+ "use strict";
2093
+ init_utils();
2094
+ init_task();
2095
+ } });
2096
+ var fromPathRegex, FileStatusSummary;
2097
+ var init_FileStatusSummary = __esm({ "src/lib/responses/FileStatusSummary.ts"() {
2098
+ "use strict";
2099
+ fromPathRegex = /^(.+)\0(.+)$/;
2100
+ FileStatusSummary = class {
2101
+ constructor(path, index, working_dir) {
2102
+ this.path = path;
2103
+ this.index = index;
2104
+ this.working_dir = working_dir;
2105
+ if (index === "R" || working_dir === "R") {
2106
+ const detail = fromPathRegex.exec(path) || [
2107
+ null,
2108
+ path,
2109
+ path
2110
+ ];
2111
+ this.from = detail[2] || "";
2112
+ this.path = detail[1] || "";
2113
+ }
2114
+ }
2115
+ };
2116
+ } });
2117
+ function renamedFile(line) {
2118
+ const [to, from] = line.split(NULL);
2119
+ return {
2120
+ from: from || to,
2121
+ to
2122
+ };
2123
+ }
2124
+ function parser3(indexX, indexY, handler) {
2125
+ return [`${indexX}${indexY}`, handler];
2126
+ }
2127
+ function conflicts(indexX, ...indexY) {
2128
+ return indexY.map((y) => parser3(indexX, y, (result, file) => append(result.conflicted, file)));
2129
+ }
2130
+ function splitLine(result, lineStr) {
2131
+ const trimmed2 = lineStr.trim();
2132
+ switch (" ") {
2133
+ case trimmed2.charAt(2): return data(trimmed2.charAt(0), trimmed2.charAt(1), trimmed2.substr(3));
2134
+ case trimmed2.charAt(1): return data(" ", trimmed2.charAt(0), trimmed2.substr(2));
2135
+ default: return;
2136
+ }
2137
+ function data(index, workingDir, path) {
2138
+ const raw = `${index}${workingDir}`;
2139
+ const handler = parsers6.get(raw);
2140
+ if (handler) handler(result, path);
2141
+ if (raw !== "##" && raw !== "!!") result.files.push(new FileStatusSummary(path, index, workingDir));
2142
+ }
2143
+ }
2144
+ var StatusSummary, parsers6, parseStatusSummary;
2145
+ var init_StatusSummary = __esm({ "src/lib/responses/StatusSummary.ts"() {
2146
+ "use strict";
2147
+ init_utils();
2148
+ init_FileStatusSummary();
2149
+ StatusSummary = class {
2150
+ constructor() {
2151
+ this.not_added = [];
2152
+ this.conflicted = [];
2153
+ this.created = [];
2154
+ this.deleted = [];
2155
+ this.ignored = void 0;
2156
+ this.modified = [];
2157
+ this.renamed = [];
2158
+ this.files = [];
2159
+ this.staged = [];
2160
+ this.ahead = 0;
2161
+ this.behind = 0;
2162
+ this.current = null;
2163
+ this.tracking = null;
2164
+ this.detached = false;
2165
+ this.isClean = () => {
2166
+ return !this.files.length;
2167
+ };
2168
+ }
2169
+ };
2170
+ parsers6 = new Map([
2171
+ parser3(" ", "A", (result, file) => append(result.created, file)),
2172
+ parser3(" ", "D", (result, file) => append(result.deleted, file)),
2173
+ parser3(" ", "M", (result, file) => append(result.modified, file)),
2174
+ parser3("A", " ", (result, file) => append(result.created, file) && append(result.staged, file)),
2175
+ parser3("A", "M", (result, file) => append(result.created, file) && append(result.staged, file) && append(result.modified, file)),
2176
+ parser3("D", " ", (result, file) => append(result.deleted, file) && append(result.staged, file)),
2177
+ parser3("M", " ", (result, file) => append(result.modified, file) && append(result.staged, file)),
2178
+ parser3("M", "M", (result, file) => append(result.modified, file) && append(result.staged, file)),
2179
+ parser3("R", " ", (result, file) => {
2180
+ append(result.renamed, renamedFile(file));
2181
+ }),
2182
+ parser3("R", "M", (result, file) => {
2183
+ const renamed = renamedFile(file);
2184
+ append(result.renamed, renamed);
2185
+ append(result.modified, renamed.to);
2186
+ }),
2187
+ parser3("!", "!", (_result, _file) => {
2188
+ append(_result.ignored = _result.ignored || [], _file);
2189
+ }),
2190
+ parser3("?", "?", (result, file) => append(result.not_added, file)),
2191
+ ...conflicts("A", "A", "U"),
2192
+ ...conflicts("D", "D", "U"),
2193
+ ...conflicts("U", "A", "D", "U"),
2194
+ ["##", (result, line) => {
2195
+ const aheadReg = /ahead (\d+)/;
2196
+ const behindReg = /behind (\d+)/;
2197
+ const currentReg = /^(.+?(?=(?:\.{3}|\s|$)))/;
2198
+ const trackingReg = /\.{3}(\S*)/;
2199
+ const onEmptyBranchReg = /\son\s(\S+?)(?=\.{3}|$)/;
2200
+ let regexResult = aheadReg.exec(line);
2201
+ result.ahead = regexResult && +regexResult[1] || 0;
2202
+ regexResult = behindReg.exec(line);
2203
+ result.behind = regexResult && +regexResult[1] || 0;
2204
+ regexResult = currentReg.exec(line);
2205
+ result.current = filterType(regexResult?.[1], filterString, null);
2206
+ regexResult = trackingReg.exec(line);
2207
+ result.tracking = filterType(regexResult?.[1], filterString, null);
2208
+ regexResult = onEmptyBranchReg.exec(line);
2209
+ if (regexResult) result.current = filterType(regexResult?.[1], filterString, result.current);
2210
+ result.detached = /\(no branch\)/.test(line);
2211
+ }]
2212
+ ]);
2213
+ parseStatusSummary = function(text) {
2214
+ const lines = text.split(NULL);
2215
+ const status = new StatusSummary();
2216
+ for (let i = 0, l = lines.length; i < l;) {
2217
+ let line = lines[i++].trim();
2218
+ if (!line) continue;
2219
+ if (line.charAt(0) === "R") line += NULL + (lines[i++] || "");
2220
+ splitLine(status, line);
2221
+ }
2222
+ return status;
2223
+ };
2224
+ } });
2225
+ function statusTask(customArgs) {
2226
+ return {
2227
+ format: "utf-8",
2228
+ commands: [
2229
+ "status",
2230
+ "--porcelain",
2231
+ "-b",
2232
+ "-u",
2233
+ "--null",
2234
+ ...customArgs.filter((arg) => !ignoredOptions.includes(arg))
2235
+ ],
2236
+ parser(text) {
2237
+ return parseStatusSummary(text);
2238
+ }
2239
+ };
2240
+ }
2241
+ var ignoredOptions;
2242
+ var init_status = __esm({ "src/lib/tasks/status.ts"() {
2243
+ "use strict";
2244
+ init_StatusSummary();
2245
+ ignoredOptions = ["--null", "-z"];
2246
+ } });
2247
+ function versionResponse(major = 0, minor = 0, patch = 0, agent = "", installed = true) {
2248
+ return Object.defineProperty({
2249
+ major,
2250
+ minor,
2251
+ patch,
2252
+ agent,
2253
+ installed
2254
+ }, "toString", {
2255
+ value() {
2256
+ return `${this.major}.${this.minor}.${this.patch}`;
2257
+ },
2258
+ configurable: false,
2259
+ enumerable: false
2260
+ });
2261
+ }
2262
+ function notInstalledResponse() {
2263
+ return versionResponse(0, 0, 0, "", false);
2264
+ }
2265
+ function version_default() {
2266
+ return { version() {
2267
+ return this._runTask({
2268
+ commands: ["--version"],
2269
+ format: "utf-8",
2270
+ parser: versionParser,
2271
+ onError(result, error, done, fail) {
2272
+ if (result.exitCode === -2) return done(Buffer.from(NOT_INSTALLED));
2273
+ fail(error);
2274
+ }
2275
+ });
2276
+ } };
2277
+ }
2278
+ function versionParser(stdOut) {
2279
+ if (stdOut === NOT_INSTALLED) return notInstalledResponse();
2280
+ return parseStringResponse(versionResponse(0, 0, 0, stdOut), parsers7, stdOut);
2281
+ }
2282
+ var NOT_INSTALLED, parsers7;
2283
+ var init_version = __esm({ "src/lib/tasks/version.ts"() {
2284
+ "use strict";
2285
+ init_utils();
2286
+ NOT_INSTALLED = "installed=false";
2287
+ parsers7 = [new LineParser(/version (\d+)\.(\d+)\.(\d+)(?:\s*\((.+)\))?/, (result, [major, minor, patch, agent = ""]) => {
2288
+ Object.assign(result, versionResponse(asNumber(major), asNumber(minor), asNumber(patch), agent));
2289
+ }), new LineParser(/version (\d+)\.(\d+)\.(\D+)(.+)?$/, (result, [major, minor, patch, agent = ""]) => {
2290
+ Object.assign(result, versionResponse(asNumber(major), asNumber(minor), patch, agent));
2291
+ })];
2292
+ } });
2293
+ var simple_git_api_exports = {};
2294
+ __export(simple_git_api_exports, { SimpleGitApi: () => SimpleGitApi });
2295
+ var SimpleGitApi;
2296
+ var init_simple_git_api = __esm({ "src/lib/simple-git-api.ts"() {
2297
+ "use strict";
2298
+ init_task_callback();
2299
+ init_change_working_directory();
2300
+ init_checkout();
2301
+ init_count_objects();
2302
+ init_commit();
2303
+ init_config();
2304
+ init_first_commit();
2305
+ init_grep();
2306
+ init_hash_object();
2307
+ init_init();
2308
+ init_log();
2309
+ init_merge();
2310
+ init_push();
2311
+ init_show();
2312
+ init_status();
2313
+ init_task();
2314
+ init_version();
2315
+ init_utils();
2316
+ SimpleGitApi = class {
2317
+ constructor(_executor) {
2318
+ this._executor = _executor;
2319
+ }
2320
+ _runTask(task, then) {
2321
+ const chain = this._executor.chain();
2322
+ const promise = chain.push(task);
2323
+ if (then) taskCallback(task, promise, then);
2324
+ return Object.create(this, {
2325
+ then: { value: promise.then.bind(promise) },
2326
+ catch: { value: promise.catch.bind(promise) },
2327
+ _executor: { value: chain }
2328
+ });
2329
+ }
2330
+ add(files) {
2331
+ return this._runTask(straightThroughStringTask(["add", ...asArray(files)]), trailingFunctionArgument(arguments));
2332
+ }
2333
+ cwd(directory) {
2334
+ const next = trailingFunctionArgument(arguments);
2335
+ if (typeof directory === "string") return this._runTask(changeWorkingDirectoryTask(directory, this._executor), next);
2336
+ if (typeof directory?.path === "string") return this._runTask(changeWorkingDirectoryTask(directory.path, directory.root && this._executor || void 0), next);
2337
+ return this._runTask(configurationErrorTask("Git.cwd: workingDirectory must be supplied as a string"), next);
2338
+ }
2339
+ hashObject(path, write) {
2340
+ return this._runTask(hashObjectTask(path, write === true), trailingFunctionArgument(arguments));
2341
+ }
2342
+ init(bare) {
2343
+ return this._runTask(initTask(bare === true, this._executor.cwd, getTrailingOptions(arguments)), trailingFunctionArgument(arguments));
2344
+ }
2345
+ merge() {
2346
+ return this._runTask(mergeTask(getTrailingOptions(arguments)), trailingFunctionArgument(arguments));
2347
+ }
2348
+ mergeFromTo(remote, branch) {
2349
+ if (!(filterString(remote) && filterString(branch))) return this._runTask(configurationErrorTask(`Git.mergeFromTo requires that the 'remote' and 'branch' arguments are supplied as strings`));
2350
+ return this._runTask(mergeTask([
2351
+ remote,
2352
+ branch,
2353
+ ...getTrailingOptions(arguments)
2354
+ ]), trailingFunctionArgument(arguments, false));
2355
+ }
2356
+ outputHandler(handler) {
2357
+ this._executor.outputHandler = handler;
2358
+ return this;
2359
+ }
2360
+ push() {
2361
+ const task = pushTask({
2362
+ remote: filterType(arguments[0], filterString),
2363
+ branch: filterType(arguments[1], filterString)
2364
+ }, getTrailingOptions(arguments));
2365
+ return this._runTask(task, trailingFunctionArgument(arguments));
2366
+ }
2367
+ stash() {
2368
+ return this._runTask(straightThroughStringTask(["stash", ...getTrailingOptions(arguments)]), trailingFunctionArgument(arguments));
2369
+ }
2370
+ status() {
2371
+ return this._runTask(statusTask(getTrailingOptions(arguments)), trailingFunctionArgument(arguments));
2372
+ }
2373
+ };
2374
+ Object.assign(SimpleGitApi.prototype, checkout_default(), commit_default(), config_default(), count_objects_default(), first_commit_default(), grep_default(), log_default(), show_default(), version_default());
2375
+ } });
2376
+ var scheduler_exports = {};
2377
+ __export(scheduler_exports, { Scheduler: () => Scheduler });
2378
+ var createScheduledTask, Scheduler;
2379
+ var init_scheduler = __esm({ "src/lib/runners/scheduler.ts"() {
2380
+ "use strict";
2381
+ init_utils();
2382
+ init_git_logger();
2383
+ createScheduledTask = /* @__PURE__ */ (() => {
2384
+ let id = 0;
2385
+ return () => {
2386
+ id++;
2387
+ const { promise, done } = (0, import_dist$1.createDeferred)();
2388
+ return {
2389
+ promise,
2390
+ done,
2391
+ id
2392
+ };
2393
+ };
2394
+ })();
2395
+ Scheduler = class {
2396
+ constructor(concurrency = 2) {
2397
+ this.concurrency = concurrency;
2398
+ this.logger = createLogger("", "scheduler");
2399
+ this.pending = [];
2400
+ this.running = [];
2401
+ this.logger(`Constructed, concurrency=%s`, concurrency);
2402
+ }
2403
+ schedule() {
2404
+ if (!this.pending.length || this.running.length >= this.concurrency) {
2405
+ this.logger(`Schedule attempt ignored, pending=%s running=%s concurrency=%s`, this.pending.length, this.running.length, this.concurrency);
2406
+ return;
2407
+ }
2408
+ const task = append(this.running, this.pending.shift());
2409
+ this.logger(`Attempting id=%s`, task.id);
2410
+ task.done(() => {
2411
+ this.logger(`Completing id=`, task.id);
2412
+ remove(this.running, task);
2413
+ this.schedule();
2414
+ });
2415
+ }
2416
+ next() {
2417
+ const { promise, id } = append(this.pending, createScheduledTask());
2418
+ this.logger(`Scheduling id=%s`, id);
2419
+ this.schedule();
2420
+ return promise;
2421
+ }
2422
+ };
2423
+ } });
2424
+ var apply_patch_exports = {};
2425
+ __export(apply_patch_exports, { applyPatchTask: () => applyPatchTask });
2426
+ function applyPatchTask(patches, customArgs) {
2427
+ return straightThroughStringTask([
2428
+ "apply",
2429
+ ...customArgs,
2430
+ ...patches
2431
+ ]);
2432
+ }
2433
+ var init_apply_patch = __esm({ "src/lib/tasks/apply-patch.ts"() {
2434
+ "use strict";
2435
+ init_task();
2436
+ } });
2437
+ function branchDeletionSuccess(branch, hash) {
2438
+ return {
2439
+ branch,
2440
+ hash,
2441
+ success: true
2442
+ };
2443
+ }
2444
+ function branchDeletionFailure(branch) {
2445
+ return {
2446
+ branch,
2447
+ hash: null,
2448
+ success: false
2449
+ };
2450
+ }
2451
+ var BranchDeletionBatch;
2452
+ var init_BranchDeleteSummary = __esm({ "src/lib/responses/BranchDeleteSummary.ts"() {
2453
+ "use strict";
2454
+ BranchDeletionBatch = class {
2455
+ constructor() {
2456
+ this.all = [];
2457
+ this.branches = {};
2458
+ this.errors = [];
2459
+ }
2460
+ get success() {
2461
+ return !this.errors.length;
2462
+ }
2463
+ };
2464
+ } });
2465
+ function hasBranchDeletionError(data, processExitCode) {
2466
+ return processExitCode === 1 && deleteErrorRegex.test(data);
2467
+ }
2468
+ var deleteSuccessRegex, deleteErrorRegex, parsers8, parseBranchDeletions;
2469
+ var init_parse_branch_delete = __esm({ "src/lib/parsers/parse-branch-delete.ts"() {
2470
+ "use strict";
2471
+ init_BranchDeleteSummary();
2472
+ init_utils();
2473
+ deleteSuccessRegex = /(\S+)\s+\(\S+\s([^)]+)\)/;
2474
+ deleteErrorRegex = /^error[^']+'([^']+)'/m;
2475
+ parsers8 = [new LineParser(deleteSuccessRegex, (result, [branch, hash]) => {
2476
+ const deletion = branchDeletionSuccess(branch, hash);
2477
+ result.all.push(deletion);
2478
+ result.branches[branch] = deletion;
2479
+ }), new LineParser(deleteErrorRegex, (result, [branch]) => {
2480
+ const deletion = branchDeletionFailure(branch);
2481
+ result.errors.push(deletion);
2482
+ result.all.push(deletion);
2483
+ result.branches[branch] = deletion;
2484
+ })];
2485
+ parseBranchDeletions = (stdOut, stdErr) => {
2486
+ return parseStringResponse(new BranchDeletionBatch(), parsers8, [stdOut, stdErr]);
2487
+ };
2488
+ } });
2489
+ var BranchSummaryResult;
2490
+ var init_BranchSummary = __esm({ "src/lib/responses/BranchSummary.ts"() {
2491
+ "use strict";
2492
+ BranchSummaryResult = class {
2493
+ constructor() {
2494
+ this.all = [];
2495
+ this.branches = {};
2496
+ this.current = "";
2497
+ this.detached = false;
2498
+ }
2499
+ push(status, detached, name, commit, label) {
2500
+ if (status === "*") {
2501
+ this.detached = detached;
2502
+ this.current = name;
2503
+ }
2504
+ this.all.push(name);
2505
+ this.branches[name] = {
2506
+ current: status === "*",
2507
+ linkedWorkTree: status === "+",
2508
+ name,
2509
+ commit,
2510
+ label
2511
+ };
2512
+ }
2513
+ };
2514
+ } });
2515
+ function branchStatus(input) {
2516
+ return input ? input.charAt(0) : "";
2517
+ }
2518
+ function parseBranchSummary(stdOut, currentOnly = false) {
2519
+ return parseStringResponse(new BranchSummaryResult(), currentOnly ? [currentBranchParser] : parsers9, stdOut);
2520
+ }
2521
+ var parsers9, currentBranchParser;
2522
+ var init_parse_branch = __esm({ "src/lib/parsers/parse-branch.ts"() {
2523
+ "use strict";
2524
+ init_BranchSummary();
2525
+ init_utils();
2526
+ parsers9 = [new LineParser(/^([*+]\s)?\((?:HEAD )?detached (?:from|at) (\S+)\)\s+([a-z0-9]+)\s(.*)$/, (result, [current, name, commit, label]) => {
2527
+ result.push(branchStatus(current), true, name, commit, label);
2528
+ }), new LineParser(/^([*+]\s)?(\S+)\s+([a-z0-9]+)\s?(.*)$/s, (result, [current, name, commit, label]) => {
2529
+ result.push(branchStatus(current), false, name, commit, label);
2530
+ })];
2531
+ currentBranchParser = new LineParser(/^(\S+)$/s, (result, [name]) => {
2532
+ result.push("*", false, name, "", "");
2533
+ });
2534
+ } });
2535
+ var branch_exports = {};
2536
+ __export(branch_exports, {
2537
+ branchLocalTask: () => branchLocalTask,
2538
+ branchTask: () => branchTask,
2539
+ containsDeleteBranchCommand: () => containsDeleteBranchCommand,
2540
+ deleteBranchTask: () => deleteBranchTask,
2541
+ deleteBranchesTask: () => deleteBranchesTask
2542
+ });
2543
+ function containsDeleteBranchCommand(commands) {
2544
+ const deleteCommands = [
2545
+ "-d",
2546
+ "-D",
2547
+ "--delete"
2548
+ ];
2549
+ return commands.some((command) => deleteCommands.includes(command));
2550
+ }
2551
+ function branchTask(customArgs) {
2552
+ const isDelete = containsDeleteBranchCommand(customArgs);
2553
+ const isCurrentOnly = customArgs.includes("--show-current");
2554
+ const commands = ["branch", ...customArgs];
2555
+ if (commands.length === 1) commands.push("-a");
2556
+ if (!commands.includes("-v")) commands.splice(1, 0, "-v");
2557
+ return {
2558
+ format: "utf-8",
2559
+ commands,
2560
+ parser(stdOut, stdErr) {
2561
+ if (isDelete) return parseBranchDeletions(stdOut, stdErr).all[0];
2562
+ return parseBranchSummary(stdOut, isCurrentOnly);
2563
+ }
2564
+ };
2565
+ }
2566
+ function branchLocalTask() {
2567
+ return {
2568
+ format: "utf-8",
2569
+ commands: ["branch", "-v"],
2570
+ parser(stdOut) {
2571
+ return parseBranchSummary(stdOut);
2572
+ }
2573
+ };
2574
+ }
2575
+ function deleteBranchesTask(branches, forceDelete = false) {
2576
+ return {
2577
+ format: "utf-8",
2578
+ commands: [
2579
+ "branch",
2580
+ "-v",
2581
+ forceDelete ? "-D" : "-d",
2582
+ ...branches
2583
+ ],
2584
+ parser(stdOut, stdErr) {
2585
+ return parseBranchDeletions(stdOut, stdErr);
2586
+ },
2587
+ onError({ exitCode, stdOut }, error, done, fail) {
2588
+ if (!hasBranchDeletionError(String(error), exitCode)) return fail(error);
2589
+ done(stdOut);
2590
+ }
2591
+ };
2592
+ }
2593
+ function deleteBranchTask(branch, forceDelete = false) {
2594
+ const task = {
2595
+ format: "utf-8",
2596
+ commands: [
2597
+ "branch",
2598
+ "-v",
2599
+ forceDelete ? "-D" : "-d",
2600
+ branch
2601
+ ],
2602
+ parser(stdOut, stdErr) {
2603
+ return parseBranchDeletions(stdOut, stdErr).branches[branch];
2604
+ },
2605
+ onError({ exitCode, stdErr, stdOut }, error, _, fail) {
2606
+ if (!hasBranchDeletionError(String(error), exitCode)) return fail(error);
2607
+ throw new GitResponseError(task.parser(bufferToString(stdOut), bufferToString(stdErr)), String(error));
2608
+ }
2609
+ };
2610
+ return task;
2611
+ }
2612
+ var init_branch = __esm({ "src/lib/tasks/branch.ts"() {
2613
+ "use strict";
2614
+ init_git_response_error();
2615
+ init_parse_branch_delete();
2616
+ init_parse_branch();
2617
+ init_utils();
2618
+ } });
2619
+ function toPath(input) {
2620
+ const path = input.trim().replace(/^["']|["']$/g, "");
2621
+ return path && normalize(path);
2622
+ }
2623
+ var parseCheckIgnore;
2624
+ var init_CheckIgnore = __esm({ "src/lib/responses/CheckIgnore.ts"() {
2625
+ "use strict";
2626
+ parseCheckIgnore = (text) => {
2627
+ return text.split(/\n/g).map(toPath).filter(Boolean);
2628
+ };
2629
+ } });
2630
+ var check_ignore_exports = {};
2631
+ __export(check_ignore_exports, { checkIgnoreTask: () => checkIgnoreTask });
2632
+ function checkIgnoreTask(paths) {
2633
+ return {
2634
+ commands: ["check-ignore", ...paths],
2635
+ format: "utf-8",
2636
+ parser: parseCheckIgnore
2637
+ };
2638
+ }
2639
+ var init_check_ignore = __esm({ "src/lib/tasks/check-ignore.ts"() {
2640
+ "use strict";
2641
+ init_CheckIgnore();
2642
+ } });
2643
+ var clone_exports = {};
2644
+ __export(clone_exports, {
2645
+ cloneMirrorTask: () => cloneMirrorTask,
2646
+ cloneTask: () => cloneTask
2647
+ });
2648
+ function disallowedCommand(command) {
2649
+ return /^--upload-pack(=|$)/.test(command);
2650
+ }
2651
+ function cloneTask(repo, directory, customArgs) {
2652
+ const commands = ["clone", ...customArgs];
2653
+ filterString(repo) && commands.push(repo);
2654
+ filterString(directory) && commands.push(directory);
2655
+ if (commands.find(disallowedCommand)) return configurationErrorTask(`git.fetch: potential exploit argument blocked.`);
2656
+ return straightThroughStringTask(commands);
2657
+ }
2658
+ function cloneMirrorTask(repo, directory, customArgs) {
2659
+ append(customArgs, "--mirror");
2660
+ return cloneTask(repo, directory, customArgs);
2661
+ }
2662
+ var init_clone = __esm({ "src/lib/tasks/clone.ts"() {
2663
+ "use strict";
2664
+ init_task();
2665
+ init_utils();
2666
+ } });
2667
+ function parseFetchResult(stdOut, stdErr) {
2668
+ return parseStringResponse({
2669
+ raw: stdOut,
2670
+ remote: null,
2671
+ branches: [],
2672
+ tags: [],
2673
+ updated: [],
2674
+ deleted: []
2675
+ }, parsers10, [stdOut, stdErr]);
2676
+ }
2677
+ var parsers10;
2678
+ var init_parse_fetch = __esm({ "src/lib/parsers/parse-fetch.ts"() {
2679
+ "use strict";
2680
+ init_utils();
2681
+ parsers10 = [
2682
+ new LineParser(/From (.+)$/, (result, [remote]) => {
2683
+ result.remote = remote;
2684
+ }),
2685
+ new LineParser(/\* \[new branch]\s+(\S+)\s*-> (.+)$/, (result, [name, tracking]) => {
2686
+ result.branches.push({
2687
+ name,
2688
+ tracking
2689
+ });
2690
+ }),
2691
+ new LineParser(/\* \[new tag]\s+(\S+)\s*-> (.+)$/, (result, [name, tracking]) => {
2692
+ result.tags.push({
2693
+ name,
2694
+ tracking
2695
+ });
2696
+ }),
2697
+ new LineParser(/- \[deleted]\s+\S+\s*-> (.+)$/, (result, [tracking]) => {
2698
+ result.deleted.push({ tracking });
2699
+ }),
2700
+ new LineParser(/\s*([^.]+)\.\.(\S+)\s+(\S+)\s*-> (.+)$/, (result, [from, to, name, tracking]) => {
2701
+ result.updated.push({
2702
+ name,
2703
+ tracking,
2704
+ to,
2705
+ from
2706
+ });
2707
+ })
2708
+ ];
2709
+ } });
2710
+ var fetch_exports = {};
2711
+ __export(fetch_exports, { fetchTask: () => fetchTask });
2712
+ function disallowedCommand2(command) {
2713
+ return /^--upload-pack(=|$)/.test(command);
2714
+ }
2715
+ function fetchTask(remote, branch, customArgs) {
2716
+ const commands = ["fetch", ...customArgs];
2717
+ if (remote && branch) commands.push(remote, branch);
2718
+ if (commands.find(disallowedCommand2)) return configurationErrorTask(`git.fetch: potential exploit argument blocked.`);
2719
+ return {
2720
+ commands,
2721
+ format: "utf-8",
2722
+ parser: parseFetchResult
2723
+ };
2724
+ }
2725
+ var init_fetch = __esm({ "src/lib/tasks/fetch.ts"() {
2726
+ "use strict";
2727
+ init_parse_fetch();
2728
+ init_task();
2729
+ } });
2730
+ function parseMoveResult(stdOut) {
2731
+ return parseStringResponse({ moves: [] }, parsers11, stdOut);
2732
+ }
2733
+ var parsers11;
2734
+ var init_parse_move = __esm({ "src/lib/parsers/parse-move.ts"() {
2735
+ "use strict";
2736
+ init_utils();
2737
+ parsers11 = [new LineParser(/^Renaming (.+) to (.+)$/, (result, [from, to]) => {
2738
+ result.moves.push({
2739
+ from,
2740
+ to
2741
+ });
2742
+ })];
2743
+ } });
2744
+ var move_exports = {};
2745
+ __export(move_exports, { moveTask: () => moveTask });
2746
+ function moveTask(from, to) {
2747
+ return {
2748
+ commands: [
2749
+ "mv",
2750
+ "-v",
2751
+ ...asArray(from),
2752
+ to
2753
+ ],
2754
+ format: "utf-8",
2755
+ parser: parseMoveResult
2756
+ };
2757
+ }
2758
+ var init_move = __esm({ "src/lib/tasks/move.ts"() {
2759
+ "use strict";
2760
+ init_parse_move();
2761
+ init_utils();
2762
+ } });
2763
+ var pull_exports = {};
2764
+ __export(pull_exports, { pullTask: () => pullTask });
2765
+ function pullTask(remote, branch, customArgs) {
2766
+ const commands = ["pull", ...customArgs];
2767
+ if (remote && branch) commands.splice(1, 0, remote, branch);
2768
+ return {
2769
+ commands,
2770
+ format: "utf-8",
2771
+ parser(stdOut, stdErr) {
2772
+ return parsePullResult(stdOut, stdErr);
2773
+ },
2774
+ onError(result, _error, _done, fail) {
2775
+ const pullError = parsePullErrorResult(bufferToString(result.stdOut), bufferToString(result.stdErr));
2776
+ if (pullError) return fail(new GitResponseError(pullError));
2777
+ fail(_error);
2778
+ }
2779
+ };
2780
+ }
2781
+ var init_pull = __esm({ "src/lib/tasks/pull.ts"() {
2782
+ "use strict";
2783
+ init_git_response_error();
2784
+ init_parse_pull();
2785
+ init_utils();
2786
+ } });
2787
+ function parseGetRemotes(text) {
2788
+ const remotes = {};
2789
+ forEach(text, ([name]) => remotes[name] = { name });
2790
+ return Object.values(remotes);
2791
+ }
2792
+ function parseGetRemotesVerbose(text) {
2793
+ const remotes = {};
2794
+ forEach(text, ([name, url, purpose]) => {
2795
+ if (!Object.hasOwn(remotes, name)) remotes[name] = {
2796
+ name,
2797
+ refs: {
2798
+ fetch: "",
2799
+ push: ""
2800
+ }
2801
+ };
2802
+ if (purpose && url) remotes[name].refs[purpose.replace(/[^a-z]/g, "")] = url;
2803
+ });
2804
+ return Object.values(remotes);
2805
+ }
2806
+ function forEach(text, handler) {
2807
+ forEachLineWithContent(text, (line) => handler(line.split(/\s+/)));
2808
+ }
2809
+ var init_GetRemoteSummary = __esm({ "src/lib/responses/GetRemoteSummary.ts"() {
2810
+ "use strict";
2811
+ init_utils();
2812
+ } });
2813
+ var remote_exports = {};
2814
+ __export(remote_exports, {
2815
+ addRemoteTask: () => addRemoteTask,
2816
+ getRemotesTask: () => getRemotesTask,
2817
+ listRemotesTask: () => listRemotesTask,
2818
+ remoteTask: () => remoteTask,
2819
+ removeRemoteTask: () => removeRemoteTask
2820
+ });
2821
+ function addRemoteTask(remoteName, remoteRepo, customArgs) {
2822
+ return straightThroughStringTask([
2823
+ "remote",
2824
+ "add",
2825
+ ...customArgs,
2826
+ remoteName,
2827
+ remoteRepo
2828
+ ]);
2829
+ }
2830
+ function getRemotesTask(verbose) {
2831
+ const commands = ["remote"];
2832
+ if (verbose) commands.push("-v");
2833
+ return {
2834
+ commands,
2835
+ format: "utf-8",
2836
+ parser: verbose ? parseGetRemotesVerbose : parseGetRemotes
2837
+ };
2838
+ }
2839
+ function listRemotesTask(customArgs) {
2840
+ const commands = [...customArgs];
2841
+ if (commands[0] !== "ls-remote") commands.unshift("ls-remote");
2842
+ return straightThroughStringTask(commands);
2843
+ }
2844
+ function remoteTask(customArgs) {
2845
+ const commands = [...customArgs];
2846
+ if (commands[0] !== "remote") commands.unshift("remote");
2847
+ return straightThroughStringTask(commands);
2848
+ }
2849
+ function removeRemoteTask(remoteName) {
2850
+ return straightThroughStringTask([
2851
+ "remote",
2852
+ "remove",
2853
+ remoteName
2854
+ ]);
2855
+ }
2856
+ var init_remote = __esm({ "src/lib/tasks/remote.ts"() {
2857
+ "use strict";
2858
+ init_GetRemoteSummary();
2859
+ init_task();
2860
+ } });
2861
+ var stash_list_exports = {};
2862
+ __export(stash_list_exports, { stashListTask: () => stashListTask });
2863
+ function stashListTask(opt = {}, customArgs) {
2864
+ const options = parseLogOptions(opt);
2865
+ const commands = [
2866
+ "stash",
2867
+ "list",
2868
+ ...options.commands,
2869
+ ...customArgs
2870
+ ];
2871
+ const parser4 = createListLogSummaryParser(options.splitter, options.fields, logFormatFromCommand(commands));
2872
+ return validateLogFormatConfig(commands) || {
2873
+ commands,
2874
+ format: "utf-8",
2875
+ parser: parser4
2876
+ };
2877
+ }
2878
+ var init_stash_list = __esm({ "src/lib/tasks/stash-list.ts"() {
2879
+ "use strict";
2880
+ init_log_format();
2881
+ init_parse_list_log_summary();
2882
+ init_diff();
2883
+ init_log();
2884
+ } });
2885
+ var sub_module_exports = {};
2886
+ __export(sub_module_exports, {
2887
+ addSubModuleTask: () => addSubModuleTask,
2888
+ initSubModuleTask: () => initSubModuleTask,
2889
+ subModuleTask: () => subModuleTask,
2890
+ updateSubModuleTask: () => updateSubModuleTask
2891
+ });
2892
+ function addSubModuleTask(repo, path) {
2893
+ return subModuleTask([
2894
+ "add",
2895
+ repo,
2896
+ path
2897
+ ]);
2898
+ }
2899
+ function initSubModuleTask(customArgs) {
2900
+ return subModuleTask(["init", ...customArgs]);
2901
+ }
2902
+ function subModuleTask(customArgs) {
2903
+ const commands = [...customArgs];
2904
+ if (commands[0] !== "submodule") commands.unshift("submodule");
2905
+ return straightThroughStringTask(commands);
2906
+ }
2907
+ function updateSubModuleTask(customArgs) {
2908
+ return subModuleTask(["update", ...customArgs]);
2909
+ }
2910
+ var init_sub_module = __esm({ "src/lib/tasks/sub-module.ts"() {
2911
+ "use strict";
2912
+ init_task();
2913
+ } });
2914
+ function singleSorted(a, b) {
2915
+ const aIsNum = Number.isNaN(a);
2916
+ if (aIsNum !== Number.isNaN(b)) return aIsNum ? 1 : -1;
2917
+ return aIsNum ? sorted(a, b) : 0;
2918
+ }
2919
+ function sorted(a, b) {
2920
+ return a === b ? 0 : a > b ? 1 : -1;
2921
+ }
2922
+ function trimmed(input) {
2923
+ return input.trim();
2924
+ }
2925
+ function toNumber(input) {
2926
+ if (typeof input === "string") return parseInt(input.replace(/^\D+/g, ""), 10) || 0;
2927
+ return 0;
2928
+ }
2929
+ var TagList, parseTagList;
2930
+ var init_TagList = __esm({ "src/lib/responses/TagList.ts"() {
2931
+ "use strict";
2932
+ TagList = class {
2933
+ constructor(all, latest) {
2934
+ this.all = all;
2935
+ this.latest = latest;
2936
+ }
2937
+ };
2938
+ parseTagList = function(data, customSort = false) {
2939
+ const tags = data.split("\n").map(trimmed).filter(Boolean);
2940
+ if (!customSort) tags.sort(function(tagA, tagB) {
2941
+ const partsA = tagA.split(".");
2942
+ const partsB = tagB.split(".");
2943
+ if (partsA.length === 1 || partsB.length === 1) return singleSorted(toNumber(partsA[0]), toNumber(partsB[0]));
2944
+ for (let i = 0, l = Math.max(partsA.length, partsB.length); i < l; i++) {
2945
+ const diff = sorted(toNumber(partsA[i]), toNumber(partsB[i]));
2946
+ if (diff) return diff;
2947
+ }
2948
+ return 0;
2949
+ });
2950
+ const latest = customSort ? tags[0] : [...tags].reverse().find((tag) => tag.indexOf(".") >= 0);
2951
+ return new TagList(tags, latest);
2952
+ };
2953
+ } });
2954
+ var tag_exports = {};
2955
+ __export(tag_exports, {
2956
+ addAnnotatedTagTask: () => addAnnotatedTagTask,
2957
+ addTagTask: () => addTagTask,
2958
+ tagListTask: () => tagListTask
2959
+ });
2960
+ function tagListTask(customArgs = []) {
2961
+ const hasCustomSort = customArgs.some((option) => /^--sort=/.test(option));
2962
+ return {
2963
+ format: "utf-8",
2964
+ commands: [
2965
+ "tag",
2966
+ "-l",
2967
+ ...customArgs
2968
+ ],
2969
+ parser(text) {
2970
+ return parseTagList(text, hasCustomSort);
2971
+ }
2972
+ };
2973
+ }
2974
+ function addTagTask(name) {
2975
+ return {
2976
+ format: "utf-8",
2977
+ commands: ["tag", name],
2978
+ parser() {
2979
+ return { name };
2980
+ }
2981
+ };
2982
+ }
2983
+ function addAnnotatedTagTask(name, tagMessage) {
2984
+ return {
2985
+ format: "utf-8",
2986
+ commands: [
2987
+ "tag",
2988
+ "-a",
2989
+ "-m",
2990
+ tagMessage,
2991
+ name
2992
+ ],
2993
+ parser() {
2994
+ return { name };
2995
+ }
2996
+ };
2997
+ }
2998
+ var init_tag = __esm({ "src/lib/tasks/tag.ts"() {
2999
+ "use strict";
3000
+ init_TagList();
3001
+ } });
3002
+ var require_git = __commonJS({ "src/git.js"(exports, module) {
3003
+ "use strict";
3004
+ var { GitExecutor: GitExecutor2 } = (init_git_executor(), __toCommonJS(git_executor_exports));
3005
+ var { SimpleGitApi: SimpleGitApi2 } = (init_simple_git_api(), __toCommonJS(simple_git_api_exports));
3006
+ var { Scheduler: Scheduler2 } = (init_scheduler(), __toCommonJS(scheduler_exports));
3007
+ var { configurationErrorTask: configurationErrorTask2 } = (init_task(), __toCommonJS(task_exports));
3008
+ var { asArray: asArray2, filterArray: filterArray2, filterPrimitives: filterPrimitives2, filterString: filterString2, filterStringOrStringArray: filterStringOrStringArray2, filterType: filterType2, getTrailingOptions: getTrailingOptions2, trailingFunctionArgument: trailingFunctionArgument2, trailingOptionsArgument: trailingOptionsArgument2 } = (init_utils(), __toCommonJS(utils_exports));
3009
+ var { applyPatchTask: applyPatchTask2 } = (init_apply_patch(), __toCommonJS(apply_patch_exports));
3010
+ var { branchTask: branchTask2, branchLocalTask: branchLocalTask2, deleteBranchesTask: deleteBranchesTask2, deleteBranchTask: deleteBranchTask2 } = (init_branch(), __toCommonJS(branch_exports));
3011
+ var { checkIgnoreTask: checkIgnoreTask2 } = (init_check_ignore(), __toCommonJS(check_ignore_exports));
3012
+ var { checkIsRepoTask: checkIsRepoTask2 } = (init_check_is_repo(), __toCommonJS(check_is_repo_exports));
3013
+ var { cloneTask: cloneTask2, cloneMirrorTask: cloneMirrorTask2 } = (init_clone(), __toCommonJS(clone_exports));
3014
+ var { cleanWithOptionsTask: cleanWithOptionsTask2, isCleanOptionsArray: isCleanOptionsArray2 } = (init_clean(), __toCommonJS(clean_exports));
3015
+ var { diffSummaryTask: diffSummaryTask2 } = (init_diff(), __toCommonJS(diff_exports));
3016
+ var { fetchTask: fetchTask2 } = (init_fetch(), __toCommonJS(fetch_exports));
3017
+ var { moveTask: moveTask2 } = (init_move(), __toCommonJS(move_exports));
3018
+ var { pullTask: pullTask2 } = (init_pull(), __toCommonJS(pull_exports));
3019
+ var { pushTagsTask: pushTagsTask2 } = (init_push(), __toCommonJS(push_exports));
3020
+ var { addRemoteTask: addRemoteTask2, getRemotesTask: getRemotesTask2, listRemotesTask: listRemotesTask2, remoteTask: remoteTask2, removeRemoteTask: removeRemoteTask2 } = (init_remote(), __toCommonJS(remote_exports));
3021
+ var { getResetMode: getResetMode2, resetTask: resetTask2 } = (init_reset(), __toCommonJS(reset_exports));
3022
+ var { stashListTask: stashListTask2 } = (init_stash_list(), __toCommonJS(stash_list_exports));
3023
+ var { addSubModuleTask: addSubModuleTask2, initSubModuleTask: initSubModuleTask2, subModuleTask: subModuleTask2, updateSubModuleTask: updateSubModuleTask2 } = (init_sub_module(), __toCommonJS(sub_module_exports));
3024
+ var { addAnnotatedTagTask: addAnnotatedTagTask2, addTagTask: addTagTask2, tagListTask: tagListTask2 } = (init_tag(), __toCommonJS(tag_exports));
3025
+ var { straightThroughBufferTask: straightThroughBufferTask2, straightThroughStringTask: straightThroughStringTask2 } = (init_task(), __toCommonJS(task_exports));
3026
+ function Git2(options, plugins) {
3027
+ this._plugins = plugins;
3028
+ this._executor = new GitExecutor2(options.baseDir, new Scheduler2(options.maxConcurrentProcesses), plugins);
3029
+ this._trimmed = options.trimmed;
3030
+ }
3031
+ (Git2.prototype = Object.create(SimpleGitApi2.prototype)).constructor = Git2;
3032
+ Git2.prototype.customBinary = function(command) {
3033
+ this._plugins.reconfigure("binary", command);
3034
+ return this;
3035
+ };
3036
+ Git2.prototype.env = function(name, value) {
3037
+ if (arguments.length === 1 && typeof name === "object") this._executor.env = name;
3038
+ else (this._executor.env = this._executor.env || {})[name] = value;
3039
+ return this;
3040
+ };
3041
+ Git2.prototype.stashList = function(options) {
3042
+ return this._runTask(stashListTask2(trailingOptionsArgument2(arguments) || {}, filterArray2(options) && options || []), trailingFunctionArgument2(arguments));
3043
+ };
3044
+ function createCloneTask(api, task, repoPath, localPath) {
3045
+ if (typeof repoPath !== "string") return configurationErrorTask2(`git.${api}() requires a string 'repoPath'`);
3046
+ return task(repoPath, filterType2(localPath, filterString2), getTrailingOptions2(arguments));
3047
+ }
3048
+ Git2.prototype.clone = function() {
3049
+ return this._runTask(createCloneTask("clone", cloneTask2, ...arguments), trailingFunctionArgument2(arguments));
3050
+ };
3051
+ Git2.prototype.mirror = function() {
3052
+ return this._runTask(createCloneTask("mirror", cloneMirrorTask2, ...arguments), trailingFunctionArgument2(arguments));
3053
+ };
3054
+ Git2.prototype.mv = function(from, to) {
3055
+ return this._runTask(moveTask2(from, to), trailingFunctionArgument2(arguments));
3056
+ };
3057
+ Git2.prototype.checkoutLatestTag = function(then) {
3058
+ var git = this;
3059
+ return this.pull(function() {
3060
+ git.tags(function(err, tags) {
3061
+ git.checkout(tags.latest, then);
3062
+ });
3063
+ });
3064
+ };
3065
+ Git2.prototype.pull = function(remote, branch, options, then) {
3066
+ return this._runTask(pullTask2(filterType2(remote, filterString2), filterType2(branch, filterString2), getTrailingOptions2(arguments)), trailingFunctionArgument2(arguments));
3067
+ };
3068
+ Git2.prototype.fetch = function(remote, branch) {
3069
+ return this._runTask(fetchTask2(filterType2(remote, filterString2), filterType2(branch, filterString2), getTrailingOptions2(arguments)), trailingFunctionArgument2(arguments));
3070
+ };
3071
+ Git2.prototype.silent = function(silence) {
3072
+ console.warn("simple-git deprecation notice: git.silent: logging should be configured using the `debug` library / `DEBUG` environment variable, this will be an error in version 3");
3073
+ return this;
3074
+ };
3075
+ Git2.prototype.tags = function(options, then) {
3076
+ return this._runTask(tagListTask2(getTrailingOptions2(arguments)), trailingFunctionArgument2(arguments));
3077
+ };
3078
+ Git2.prototype.rebase = function() {
3079
+ return this._runTask(straightThroughStringTask2(["rebase", ...getTrailingOptions2(arguments)]), trailingFunctionArgument2(arguments));
3080
+ };
3081
+ Git2.prototype.reset = function(mode) {
3082
+ return this._runTask(resetTask2(getResetMode2(mode), getTrailingOptions2(arguments)), trailingFunctionArgument2(arguments));
3083
+ };
3084
+ Git2.prototype.revert = function(commit) {
3085
+ const next = trailingFunctionArgument2(arguments);
3086
+ if (typeof commit !== "string") return this._runTask(configurationErrorTask2("Commit must be a string"), next);
3087
+ return this._runTask(straightThroughStringTask2([
3088
+ "revert",
3089
+ ...getTrailingOptions2(arguments, 0, true),
3090
+ commit
3091
+ ]), next);
3092
+ };
3093
+ Git2.prototype.addTag = function(name) {
3094
+ const task = typeof name === "string" ? addTagTask2(name) : configurationErrorTask2("Git.addTag requires a tag name");
3095
+ return this._runTask(task, trailingFunctionArgument2(arguments));
3096
+ };
3097
+ Git2.prototype.addAnnotatedTag = function(tagName, tagMessage) {
3098
+ return this._runTask(addAnnotatedTagTask2(tagName, tagMessage), trailingFunctionArgument2(arguments));
3099
+ };
3100
+ Git2.prototype.deleteLocalBranch = function(branchName, forceDelete, then) {
3101
+ return this._runTask(deleteBranchTask2(branchName, typeof forceDelete === "boolean" ? forceDelete : false), trailingFunctionArgument2(arguments));
3102
+ };
3103
+ Git2.prototype.deleteLocalBranches = function(branchNames, forceDelete, then) {
3104
+ return this._runTask(deleteBranchesTask2(branchNames, typeof forceDelete === "boolean" ? forceDelete : false), trailingFunctionArgument2(arguments));
3105
+ };
3106
+ Git2.prototype.branch = function(options, then) {
3107
+ return this._runTask(branchTask2(getTrailingOptions2(arguments)), trailingFunctionArgument2(arguments));
3108
+ };
3109
+ Git2.prototype.branchLocal = function(then) {
3110
+ return this._runTask(branchLocalTask2(), trailingFunctionArgument2(arguments));
3111
+ };
3112
+ Git2.prototype.raw = function(commands) {
3113
+ const createRestCommands = !Array.isArray(commands);
3114
+ const command = [].slice.call(createRestCommands ? arguments : commands, 0);
3115
+ for (let i = 0; i < command.length && createRestCommands; i++) if (!filterPrimitives2(command[i])) {
3116
+ command.splice(i, command.length - i);
3117
+ break;
3118
+ }
3119
+ command.push(...getTrailingOptions2(arguments, 0, true));
3120
+ var next = trailingFunctionArgument2(arguments);
3121
+ if (!command.length) return this._runTask(configurationErrorTask2("Raw: must supply one or more command to execute"), next);
3122
+ return this._runTask(straightThroughStringTask2(command, this._trimmed), next);
3123
+ };
3124
+ Git2.prototype.submoduleAdd = function(repo, path, then) {
3125
+ return this._runTask(addSubModuleTask2(repo, path), trailingFunctionArgument2(arguments));
3126
+ };
3127
+ Git2.prototype.submoduleUpdate = function(args, then) {
3128
+ return this._runTask(updateSubModuleTask2(getTrailingOptions2(arguments, true)), trailingFunctionArgument2(arguments));
3129
+ };
3130
+ Git2.prototype.submoduleInit = function(args, then) {
3131
+ return this._runTask(initSubModuleTask2(getTrailingOptions2(arguments, true)), trailingFunctionArgument2(arguments));
3132
+ };
3133
+ Git2.prototype.subModule = function(options, then) {
3134
+ return this._runTask(subModuleTask2(getTrailingOptions2(arguments)), trailingFunctionArgument2(arguments));
3135
+ };
3136
+ Git2.prototype.listRemote = function() {
3137
+ return this._runTask(listRemotesTask2(getTrailingOptions2(arguments)), trailingFunctionArgument2(arguments));
3138
+ };
3139
+ Git2.prototype.addRemote = function(remoteName, remoteRepo, then) {
3140
+ return this._runTask(addRemoteTask2(remoteName, remoteRepo, getTrailingOptions2(arguments)), trailingFunctionArgument2(arguments));
3141
+ };
3142
+ Git2.prototype.removeRemote = function(remoteName, then) {
3143
+ return this._runTask(removeRemoteTask2(remoteName), trailingFunctionArgument2(arguments));
3144
+ };
3145
+ Git2.prototype.getRemotes = function(verbose, then) {
3146
+ return this._runTask(getRemotesTask2(verbose === true), trailingFunctionArgument2(arguments));
3147
+ };
3148
+ Git2.prototype.remote = function(options, then) {
3149
+ return this._runTask(remoteTask2(getTrailingOptions2(arguments)), trailingFunctionArgument2(arguments));
3150
+ };
3151
+ Git2.prototype.tag = function(options, then) {
3152
+ const command = getTrailingOptions2(arguments);
3153
+ if (command[0] !== "tag") command.unshift("tag");
3154
+ return this._runTask(straightThroughStringTask2(command), trailingFunctionArgument2(arguments));
3155
+ };
3156
+ Git2.prototype.updateServerInfo = function(then) {
3157
+ return this._runTask(straightThroughStringTask2(["update-server-info"]), trailingFunctionArgument2(arguments));
3158
+ };
3159
+ Git2.prototype.pushTags = function(remote, then) {
3160
+ const task = pushTagsTask2({ remote: filterType2(remote, filterString2) }, getTrailingOptions2(arguments));
3161
+ return this._runTask(task, trailingFunctionArgument2(arguments));
3162
+ };
3163
+ Git2.prototype.rm = function(files) {
3164
+ return this._runTask(straightThroughStringTask2([
3165
+ "rm",
3166
+ "-f",
3167
+ ...asArray2(files)
3168
+ ]), trailingFunctionArgument2(arguments));
3169
+ };
3170
+ Git2.prototype.rmKeepLocal = function(files) {
3171
+ return this._runTask(straightThroughStringTask2([
3172
+ "rm",
3173
+ "--cached",
3174
+ ...asArray2(files)
3175
+ ]), trailingFunctionArgument2(arguments));
3176
+ };
3177
+ Git2.prototype.catFile = function(options, then) {
3178
+ return this._catFile("utf-8", arguments);
3179
+ };
3180
+ Git2.prototype.binaryCatFile = function() {
3181
+ return this._catFile("buffer", arguments);
3182
+ };
3183
+ Git2.prototype._catFile = function(format, args) {
3184
+ var handler = trailingFunctionArgument2(args);
3185
+ var command = ["cat-file"];
3186
+ var options = args[0];
3187
+ if (typeof options === "string") return this._runTask(configurationErrorTask2("Git.catFile: options must be supplied as an array of strings"), handler);
3188
+ if (Array.isArray(options)) command.push.apply(command, options);
3189
+ const task = format === "buffer" ? straightThroughBufferTask2(command) : straightThroughStringTask2(command);
3190
+ return this._runTask(task, handler);
3191
+ };
3192
+ Git2.prototype.diff = function(options, then) {
3193
+ const task = filterString2(options) ? configurationErrorTask2("git.diff: supplying options as a single string is no longer supported, switch to an array of strings") : straightThroughStringTask2(["diff", ...getTrailingOptions2(arguments)]);
3194
+ return this._runTask(task, trailingFunctionArgument2(arguments));
3195
+ };
3196
+ Git2.prototype.diffSummary = function() {
3197
+ return this._runTask(diffSummaryTask2(getTrailingOptions2(arguments, 1)), trailingFunctionArgument2(arguments));
3198
+ };
3199
+ Git2.prototype.applyPatch = function(patches) {
3200
+ const task = !filterStringOrStringArray2(patches) ? configurationErrorTask2(`git.applyPatch requires one or more string patches as the first argument`) : applyPatchTask2(asArray2(patches), getTrailingOptions2([].slice.call(arguments, 1)));
3201
+ return this._runTask(task, trailingFunctionArgument2(arguments));
3202
+ };
3203
+ Git2.prototype.revparse = function() {
3204
+ const commands = ["rev-parse", ...getTrailingOptions2(arguments, true)];
3205
+ return this._runTask(straightThroughStringTask2(commands, true), trailingFunctionArgument2(arguments));
3206
+ };
3207
+ Git2.prototype.clean = function(mode, options, then) {
3208
+ const usingCleanOptionsArray = isCleanOptionsArray2(mode);
3209
+ const cleanMode = usingCleanOptionsArray && mode.join("") || filterType2(mode, filterString2) || "";
3210
+ const customArgs = getTrailingOptions2([].slice.call(arguments, usingCleanOptionsArray ? 1 : 0));
3211
+ return this._runTask(cleanWithOptionsTask2(cleanMode, customArgs), trailingFunctionArgument2(arguments));
3212
+ };
3213
+ Git2.prototype.exec = function(then) {
3214
+ return this._runTask({
3215
+ commands: [],
3216
+ format: "utf-8",
3217
+ parser() {
3218
+ if (typeof then === "function") then();
3219
+ }
3220
+ });
3221
+ };
3222
+ Git2.prototype.clearQueue = function() {
3223
+ return this;
3224
+ };
3225
+ Git2.prototype.checkIgnore = function(pathnames, then) {
3226
+ return this._runTask(checkIgnoreTask2(asArray2(filterType2(pathnames, filterStringOrStringArray2, []))), trailingFunctionArgument2(arguments));
3227
+ };
3228
+ Git2.prototype.checkIsRepo = function(checkType, then) {
3229
+ return this._runTask(checkIsRepoTask2(filterType2(checkType, filterString2)), trailingFunctionArgument2(arguments));
3230
+ };
3231
+ module.exports = Git2;
3232
+ } });
3233
+ init_pathspec();
3234
+ init_git_error();
3235
+ var GitConstructError = class extends GitError {
3236
+ constructor(config, message) {
3237
+ super(void 0, message);
3238
+ this.config = config;
3239
+ }
3240
+ };
3241
+ init_git_error();
3242
+ init_git_error();
3243
+ var GitPluginError = class extends GitError {
3244
+ constructor(task, plugin, message) {
3245
+ super(task, message);
3246
+ this.task = task;
3247
+ this.plugin = plugin;
3248
+ Object.setPrototypeOf(this, new.target.prototype);
3249
+ }
3250
+ };
3251
+ init_git_response_error();
3252
+ init_task_configuration_error();
3253
+ init_check_is_repo();
3254
+ init_clean();
3255
+ init_config();
3256
+ init_diff_name_status();
3257
+ init_grep();
3258
+ init_reset();
3259
+ function abortPlugin(signal) {
3260
+ if (!signal) return;
3261
+ return [{
3262
+ type: "spawn.before",
3263
+ action(_data, context) {
3264
+ if (signal.aborted) context.kill(new GitPluginError(void 0, "abort", "Abort already signaled"));
3265
+ }
3266
+ }, {
3267
+ type: "spawn.after",
3268
+ action(_data, context) {
3269
+ function kill() {
3270
+ context.kill(new GitPluginError(void 0, "abort", "Abort signal received"));
3271
+ }
3272
+ signal.addEventListener("abort", kill);
3273
+ context.spawned.on("close", () => signal.removeEventListener("abort", kill));
3274
+ }
3275
+ }];
3276
+ }
3277
+ function isConfigSwitch(arg) {
3278
+ return typeof arg === "string" && arg.trim().toLowerCase() === "-c";
3279
+ }
3280
+ function preventProtocolOverride(arg, next) {
3281
+ if (!isConfigSwitch(arg)) return;
3282
+ if (!/^\s*protocol(.[a-z]+)?.allow/.test(next)) return;
3283
+ throw new GitPluginError(void 0, "unsafe", "Configuring protocol.allow is not permitted without enabling allowUnsafeExtProtocol");
3284
+ }
3285
+ function preventUploadPack(arg, method) {
3286
+ if (/^\s*--(upload|receive)-pack/.test(arg)) throw new GitPluginError(void 0, "unsafe", `Use of --upload-pack or --receive-pack is not permitted without enabling allowUnsafePack`);
3287
+ if (method === "clone" && /^\s*-u\b/.test(arg)) throw new GitPluginError(void 0, "unsafe", `Use of clone with option -u is not permitted without enabling allowUnsafePack`);
3288
+ if (method === "push" && /^\s*--exec\b/.test(arg)) throw new GitPluginError(void 0, "unsafe", `Use of push with option --exec is not permitted without enabling allowUnsafePack`);
3289
+ }
3290
+ function blockUnsafeOperationsPlugin({ allowUnsafeProtocolOverride = false, allowUnsafePack = false } = {}) {
3291
+ return {
3292
+ type: "spawn.args",
3293
+ action(args, context) {
3294
+ args.forEach((current, index) => {
3295
+ const next = index < args.length ? args[index + 1] : "";
3296
+ allowUnsafeProtocolOverride || preventProtocolOverride(current, next);
3297
+ allowUnsafePack || preventUploadPack(current, context.method);
3298
+ });
3299
+ return args;
3300
+ }
3301
+ };
3302
+ }
3303
+ init_utils();
3304
+ function commandConfigPrefixingPlugin(configuration) {
3305
+ const prefix = prefixedArray(configuration, "-c");
3306
+ return {
3307
+ type: "spawn.args",
3308
+ action(data) {
3309
+ return [...prefix, ...data];
3310
+ }
3311
+ };
3312
+ }
3313
+ init_utils();
3314
+ var never = (0, import_dist$1.deferred)().promise;
3315
+ function completionDetectionPlugin({ onClose = true, onExit = 50 } = {}) {
3316
+ function createEvents() {
3317
+ let exitCode = -1;
3318
+ const events = {
3319
+ close: (0, import_dist$1.deferred)(),
3320
+ closeTimeout: (0, import_dist$1.deferred)(),
3321
+ exit: (0, import_dist$1.deferred)(),
3322
+ exitTimeout: (0, import_dist$1.deferred)()
3323
+ };
3324
+ const result = Promise.race([onClose === false ? never : events.closeTimeout.promise, onExit === false ? never : events.exitTimeout.promise]);
3325
+ configureTimeout(onClose, events.close, events.closeTimeout);
3326
+ configureTimeout(onExit, events.exit, events.exitTimeout);
3327
+ return {
3328
+ close(code) {
3329
+ exitCode = code;
3330
+ events.close.done();
3331
+ },
3332
+ exit(code) {
3333
+ exitCode = code;
3334
+ events.exit.done();
3335
+ },
3336
+ get exitCode() {
3337
+ return exitCode;
3338
+ },
3339
+ result
3340
+ };
3341
+ }
3342
+ function configureTimeout(flag, event, timeout) {
3343
+ if (flag === false) return;
3344
+ (flag === true ? event.promise : event.promise.then(() => delay(flag))).then(timeout.done);
3345
+ }
3346
+ return {
3347
+ type: "spawn.after",
3348
+ async action(_data, { spawned, close }) {
3349
+ const events = createEvents();
3350
+ let deferClose = true;
3351
+ let quickClose = () => void (deferClose = false);
3352
+ spawned.stdout?.on("data", quickClose);
3353
+ spawned.stderr?.on("data", quickClose);
3354
+ spawned.on("error", quickClose);
3355
+ spawned.on("close", (code) => events.close(code));
3356
+ spawned.on("exit", (code) => events.exit(code));
3357
+ try {
3358
+ await events.result;
3359
+ if (deferClose) await delay(50);
3360
+ close(events.exitCode);
3361
+ } catch (err) {
3362
+ close(events.exitCode, err);
3363
+ }
3364
+ }
3365
+ };
3366
+ }
3367
+ init_utils();
3368
+ var WRONG_NUMBER_ERR = `Invalid value supplied for custom binary, requires a single string or an array containing either one or two strings`;
3369
+ var WRONG_CHARS_ERR = `Invalid value supplied for custom binary, restricted characters must be removed or supply the unsafe.allowUnsafeCustomBinary option`;
3370
+ function isBadArgument(arg) {
3371
+ return !arg || !/^([a-z]:)?([a-z0-9/.\\_-]+)$/i.test(arg);
3372
+ }
3373
+ function toBinaryConfig(input, allowUnsafe) {
3374
+ if (input.length < 1 || input.length > 2) throw new GitPluginError(void 0, "binary", WRONG_NUMBER_ERR);
3375
+ if (input.some(isBadArgument)) if (allowUnsafe) console.warn(WRONG_CHARS_ERR);
3376
+ else throw new GitPluginError(void 0, "binary", WRONG_CHARS_ERR);
3377
+ const [binary, prefix] = input;
3378
+ return {
3379
+ binary,
3380
+ prefix
3381
+ };
3382
+ }
3383
+ function customBinaryPlugin(plugins, input = ["git"], allowUnsafe = false) {
3384
+ let config = toBinaryConfig(asArray(input), allowUnsafe);
3385
+ plugins.on("binary", (input2) => {
3386
+ config = toBinaryConfig(asArray(input2), allowUnsafe);
3387
+ });
3388
+ plugins.append("spawn.binary", () => {
3389
+ return config.binary;
3390
+ });
3391
+ plugins.append("spawn.args", (data) => {
3392
+ return config.prefix ? [config.prefix, ...data] : data;
3393
+ });
3394
+ }
3395
+ init_git_error();
3396
+ function isTaskError(result) {
3397
+ return !!(result.exitCode && result.stdErr.length);
3398
+ }
3399
+ function getErrorMessage(result) {
3400
+ return Buffer.concat([...result.stdOut, ...result.stdErr]);
3401
+ }
3402
+ function errorDetectionHandler(overwrite = false, isError = isTaskError, errorMessage = getErrorMessage) {
3403
+ return (error, result) => {
3404
+ if (!overwrite && error || !isError(result)) return error;
3405
+ return errorMessage(result);
3406
+ };
3407
+ }
3408
+ function errorDetectionPlugin(config) {
3409
+ return {
3410
+ type: "task.error",
3411
+ action(data, context) {
3412
+ const error = config(data.error, {
3413
+ stdErr: context.stdErr,
3414
+ stdOut: context.stdOut,
3415
+ exitCode: context.exitCode
3416
+ });
3417
+ if (Buffer.isBuffer(error)) return { error: new GitError(void 0, error.toString("utf-8")) };
3418
+ return { error };
3419
+ }
3420
+ };
3421
+ }
3422
+ init_utils();
3423
+ var PluginStore = class {
3424
+ constructor() {
3425
+ this.plugins = /* @__PURE__ */ new Set();
3426
+ this.events = new EventEmitter();
3427
+ }
3428
+ on(type, listener) {
3429
+ this.events.on(type, listener);
3430
+ }
3431
+ reconfigure(type, data) {
3432
+ this.events.emit(type, data);
3433
+ }
3434
+ append(type, action) {
3435
+ const plugin = append(this.plugins, {
3436
+ type,
3437
+ action
3438
+ });
3439
+ return () => this.plugins.delete(plugin);
3440
+ }
3441
+ add(plugin) {
3442
+ const plugins = [];
3443
+ asArray(plugin).forEach((plugin2) => plugin2 && this.plugins.add(append(plugins, plugin2)));
3444
+ return () => {
3445
+ plugins.forEach((plugin2) => this.plugins.delete(plugin2));
3446
+ };
3447
+ }
3448
+ exec(type, data, context) {
3449
+ let output = data;
3450
+ const contextual = Object.freeze(Object.create(context));
3451
+ for (const plugin of this.plugins) if (plugin.type === type) output = plugin.action(output, contextual);
3452
+ return output;
3453
+ }
3454
+ };
3455
+ init_utils();
3456
+ function progressMonitorPlugin(progress) {
3457
+ const progressCommand = "--progress";
3458
+ const progressMethods = [
3459
+ "checkout",
3460
+ "clone",
3461
+ "fetch",
3462
+ "pull",
3463
+ "push"
3464
+ ];
3465
+ return [{
3466
+ type: "spawn.args",
3467
+ action(args, context) {
3468
+ if (!progressMethods.includes(context.method)) return args;
3469
+ return including(args, progressCommand);
3470
+ }
3471
+ }, {
3472
+ type: "spawn.after",
3473
+ action(_data, context) {
3474
+ if (!context.commands.includes(progressCommand)) return;
3475
+ context.spawned.stderr?.on("data", (chunk) => {
3476
+ const message = /^([\s\S]+?):\s*(\d+)% \((\d+)\/(\d+)\)/.exec(chunk.toString("utf8"));
3477
+ if (!message) return;
3478
+ progress({
3479
+ method: context.method,
3480
+ stage: progressEventStage(message[1]),
3481
+ progress: asNumber(message[2]),
3482
+ processed: asNumber(message[3]),
3483
+ total: asNumber(message[4])
3484
+ });
3485
+ });
3486
+ }
3487
+ }];
3488
+ }
3489
+ function progressEventStage(input) {
3490
+ return String(input.toLowerCase().split(" ", 1)) || "unknown";
3491
+ }
3492
+ init_utils();
3493
+ function spawnOptionsPlugin(spawnOptions) {
3494
+ const options = pick(spawnOptions, ["uid", "gid"]);
3495
+ return {
3496
+ type: "spawn.options",
3497
+ action(data) {
3498
+ return {
3499
+ ...options,
3500
+ ...data
3501
+ };
3502
+ }
3503
+ };
3504
+ }
3505
+ function timeoutPlugin({ block, stdErr = true, stdOut = true }) {
3506
+ if (block > 0) return {
3507
+ type: "spawn.after",
3508
+ action(_data, context) {
3509
+ let timeout;
3510
+ function wait() {
3511
+ timeout && clearTimeout(timeout);
3512
+ timeout = setTimeout(kill, block);
3513
+ }
3514
+ function stop() {
3515
+ context.spawned.stdout?.off("data", wait);
3516
+ context.spawned.stderr?.off("data", wait);
3517
+ context.spawned.off("exit", stop);
3518
+ context.spawned.off("close", stop);
3519
+ timeout && clearTimeout(timeout);
3520
+ }
3521
+ function kill() {
3522
+ stop();
3523
+ context.kill(new GitPluginError(void 0, "timeout", `block timeout reached`));
3524
+ }
3525
+ stdOut && context.spawned.stdout?.on("data", wait);
3526
+ stdErr && context.spawned.stderr?.on("data", wait);
3527
+ context.spawned.on("exit", stop);
3528
+ context.spawned.on("close", stop);
3529
+ wait();
3530
+ }
3531
+ };
3532
+ }
3533
+ init_pathspec();
3534
+ function suffixPathsPlugin() {
3535
+ return {
3536
+ type: "spawn.args",
3537
+ action(data) {
3538
+ const prefix = [];
3539
+ let suffix;
3540
+ function append2(args) {
3541
+ (suffix = suffix || []).push(...args);
3542
+ }
3543
+ for (let i = 0; i < data.length; i++) {
3544
+ const param = data[i];
3545
+ if (isPathSpec(param)) {
3546
+ append2(toPaths(param));
3547
+ continue;
3548
+ }
3549
+ if (param === "--") {
3550
+ append2(data.slice(i + 1).flatMap((item) => isPathSpec(item) && toPaths(item) || item));
3551
+ break;
3552
+ }
3553
+ prefix.push(param);
3554
+ }
3555
+ return !suffix ? prefix : [
3556
+ ...prefix,
3557
+ "--",
3558
+ ...suffix.map(String)
3559
+ ];
3560
+ }
3561
+ };
3562
+ }
3563
+ init_utils();
3564
+ var Git = require_git();
3565
+ function gitInstanceFactory(baseDir, options) {
3566
+ const plugins = new PluginStore();
3567
+ const config = createInstanceConfig(baseDir && (typeof baseDir === "string" ? { baseDir } : baseDir) || {}, options);
3568
+ if (!folderExists(config.baseDir)) throw new GitConstructError(config, `Cannot use simple-git on a directory that does not exist`);
3569
+ if (Array.isArray(config.config)) plugins.add(commandConfigPrefixingPlugin(config.config));
3570
+ plugins.add(blockUnsafeOperationsPlugin(config.unsafe));
3571
+ plugins.add(suffixPathsPlugin());
3572
+ plugins.add(completionDetectionPlugin(config.completion));
3573
+ config.abort && plugins.add(abortPlugin(config.abort));
3574
+ config.progress && plugins.add(progressMonitorPlugin(config.progress));
3575
+ config.timeout && plugins.add(timeoutPlugin(config.timeout));
3576
+ config.spawnOptions && plugins.add(spawnOptionsPlugin(config.spawnOptions));
3577
+ plugins.add(errorDetectionPlugin(errorDetectionHandler(true)));
3578
+ config.errors && plugins.add(errorDetectionPlugin(config.errors));
3579
+ customBinaryPlugin(plugins, config.binary, config.unsafe?.allowUnsafeCustomBinary);
3580
+ return new Git(config, plugins);
3581
+ }
3582
+ init_git_response_error();
3583
+ var esm_default = gitInstanceFactory;
3584
+ export { esm_default as t };