pi-orchestrator-config 4.7.2 → 4.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -1
- package/agents/conflict-resolver.md +37 -0
- package/agents/git-expert.md +23 -1
- package/extensions/orchestrator/enforcement-helpers.ts +532 -18
- package/extensions/orchestrator/enforcement.ts +98 -0
- package/extensions/orchestrator/git-helpers.ts +742 -0
- package/extensions/pidiff/pidiff-ui/package.json +1 -1
- package/package.json +2 -1
- package/prompts/review-handler.md +14 -1
- package/rules/10-agent-routing.md +2 -0
- package/rules/35-memory.md +6 -1
- package/rules/40-critical-rules.md +8 -1
- package/rules/50-agent-bug-reporting.md +1 -0
- package/skills/conflict-resolver/SKILL.md +7 -4
|
@@ -3,6 +3,10 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import { execFile, execSync } from "node:child_process";
|
|
6
|
+
import { resolve } from "node:path";
|
|
7
|
+
import { createLogger } from "../shared/logger.js";
|
|
8
|
+
|
|
9
|
+
const gitLog = createLogger("git-helpers");
|
|
6
10
|
|
|
7
11
|
export function runGit(
|
|
8
12
|
args: string[],
|
|
@@ -405,6 +409,744 @@ export function hasGitSub(command: string, sub: string): boolean {
|
|
|
405
409
|
).test(command);
|
|
406
410
|
}
|
|
407
411
|
|
|
412
|
+
/**
|
|
413
|
+
* Split a shell segment into words, honouring quotes and backslash escapes, so
|
|
414
|
+
* `conflicted\ repo` is one word and `-c core.editor="vim -f"` is one option.
|
|
415
|
+
*/
|
|
416
|
+
export function tokenize(text: string): string[] {
|
|
417
|
+
gitLog.debug("tokenize", "chars", text.length);
|
|
418
|
+
const tokens: string[] = [];
|
|
419
|
+
let current = "";
|
|
420
|
+
let quote: string | null = null;
|
|
421
|
+
let has = false;
|
|
422
|
+
for (let i = 0; i < text.length; i++) {
|
|
423
|
+
const ch = text[i];
|
|
424
|
+
if (quote) {
|
|
425
|
+
if (ch === quote) quote = null;
|
|
426
|
+
else current += ch;
|
|
427
|
+
continue;
|
|
428
|
+
}
|
|
429
|
+
if (ch === "'" || ch === '"') { quote = ch; has = true; continue; }
|
|
430
|
+
if (ch === "\\" && i + 1 < text.length) { current += text[i + 1]; i++; continue; }
|
|
431
|
+
if (/\s/.test(ch)) {
|
|
432
|
+
if (has) tokens.push(current);
|
|
433
|
+
current = "";
|
|
434
|
+
has = false;
|
|
435
|
+
continue;
|
|
436
|
+
}
|
|
437
|
+
current += ch;
|
|
438
|
+
has = true;
|
|
439
|
+
}
|
|
440
|
+
if (has) tokens.push(current);
|
|
441
|
+
return tokens;
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
/**
|
|
445
|
+
* The shell part of a command: what it would actually run.
|
|
446
|
+
*
|
|
447
|
+
* Quoted text is not automatically inert — `bash -c 'git add x'`,
|
|
448
|
+
* `eval '...'` and `"$(git add x)"` all execute — and a heredoc body is inert
|
|
449
|
+
* except for substitutions, while the text *after* the delimiter on the opener
|
|
450
|
+
* line still runs. So this scans rather than pattern-matches: literals are kept,
|
|
451
|
+
* `$(...)`, backticks and script arguments are descended into, heredoc bodies
|
|
452
|
+
* contribute only their substitutions, and an inert quoted span collapses to a
|
|
453
|
+
* placeholder token so `git -C "repo" add` stays parseable.
|
|
454
|
+
*/
|
|
455
|
+
type ScanMode = "full" | "words" | "body" | "literal-body";
|
|
456
|
+
|
|
457
|
+
/**
|
|
458
|
+
* Emitted when nesting exceeded the scan depth: the scanner stopped early and
|
|
459
|
+
* did not see everything. Callers must treat it as "not safe to allow" rather
|
|
460
|
+
* than as absence of a command.
|
|
461
|
+
*/
|
|
462
|
+
const UNSCANNED = "\u0000unscanned-nesting\u0000";
|
|
463
|
+
|
|
464
|
+
const SHELL_NAMES = new Set(["bash", "sh", "zsh", "dash", "ksh"]);
|
|
465
|
+
|
|
466
|
+
/** Closing paren of a `$(`, ignoring parens inside quotes. */
|
|
467
|
+
function matchingParen(cmd: string, open: number): number {
|
|
468
|
+
let depth = 0;
|
|
469
|
+
let quote: string | null = null;
|
|
470
|
+
let skippedQuoted = 0;
|
|
471
|
+
for (let i = open; i < cmd.length; i++) {
|
|
472
|
+
const ch = cmd[i];
|
|
473
|
+
if (quote) {
|
|
474
|
+
if (ch === "\\") { i++; continue; }
|
|
475
|
+
if (ch === quote) quote = null;
|
|
476
|
+
continue;
|
|
477
|
+
}
|
|
478
|
+
if (ch === "'" || ch === '"') { quote = ch; skippedQuoted++; }
|
|
479
|
+
else if (ch === "(") depth++;
|
|
480
|
+
else if (ch === ")" && --depth === 0) {
|
|
481
|
+
gitLog.debug("matching_paren", "at", i, "skipped_quoted", skippedQuoted);
|
|
482
|
+
return i;
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
gitLog.debug("matching_paren_unterminated", "open", open, "skipped_quoted", skippedQuoted);
|
|
486
|
+
return cmd.length;
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
/** Index of the closing quote, skipping over $( ) and backtick regions. */
|
|
490
|
+
function closingQuote(cmd: string, open: number, quote: string): number {
|
|
491
|
+
for (let i = open + 1; i < cmd.length; i++) {
|
|
492
|
+
if (cmd[i] === "\\") { i++; continue; }
|
|
493
|
+
if (cmd[i] === "$" && cmd[i + 1] === "(") { i = matchingParen(cmd, i + 1); continue; }
|
|
494
|
+
if (cmd[i] === "`") { const end = cmd.indexOf("`", i + 1); i = end === -1 ? cmd.length : end; continue; }
|
|
495
|
+
if (cmd[i] === quote) {
|
|
496
|
+
gitLog.debug("closing_quote", "quote", quote, "at", i);
|
|
497
|
+
return i;
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
gitLog.debug("closing_quote_unterminated", "quote", quote, "open", open);
|
|
501
|
+
return cmd.length;
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
/**
|
|
505
|
+
* True when the quoted span at `at` is a script argument — the string a shell
|
|
506
|
+
* runs. Covers `bash -c`, bundled short flags (`bash -xc`), options before `-c`
|
|
507
|
+
* (`bash --login -c`), ANSI-C quoting (`bash -c $'…'`), and `eval`.
|
|
508
|
+
*/
|
|
509
|
+
function isScriptArgument(cmd: string, at: number): boolean {
|
|
510
|
+
const before = cmd.slice(0, at).replace(/[$]+$/, "").trimEnd();
|
|
511
|
+
const words = before.split(/\s+/);
|
|
512
|
+
// Walk back over option words to the command word that started them.
|
|
513
|
+
let i = words.length - 1;
|
|
514
|
+
let sawCommandOption = false;
|
|
515
|
+
while (i >= 0 && words[i].startsWith("-") && words[i].length > 1) {
|
|
516
|
+
if (words[i] === "-" || words[i].startsWith("--")) {
|
|
517
|
+
// A long option may take the script as its value.
|
|
518
|
+
if (/^--(command|login|noprofile|norc|interactive|posix|verbose|xtrace|echo|errexit|nounset|pipefail)$/.test(words[i])) sawCommandOption = true;
|
|
519
|
+
} else if (words[i].includes("c")) {
|
|
520
|
+
sawCommandOption = true;
|
|
521
|
+
}
|
|
522
|
+
i--;
|
|
523
|
+
}
|
|
524
|
+
// Compare the executable's name, so /bin/bash and /usr/bin/env-less paths
|
|
525
|
+
// resolve the same as a bare `bash`.
|
|
526
|
+
const command = (words[i] ?? "").split("/").pop() ?? "";
|
|
527
|
+
if (command === "eval" || command === "source" || command === ".") return true;
|
|
528
|
+
if (!SHELL_NAMES.has(command)) return false;
|
|
529
|
+
// A bare `bash 'script'` is a script file, not a script string.
|
|
530
|
+
gitLog.debug("script_argument", "command", command, "option", sawCommandOption);
|
|
531
|
+
return sawCommandOption;
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
/** Does `line` terminate the heredoc? Ordinary delimiters match exactly; `<<-` allows leading tabs. */
|
|
535
|
+
function isHeredocTerminator(line: string, delim: string, stripTabs: boolean): boolean {
|
|
536
|
+
const escaped = delim.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
537
|
+
const re = stripTabs ? new RegExp(`^\\t*${escaped}$`) : new RegExp(`^${escaped}$`);
|
|
538
|
+
const isTerminator = re.test(line);
|
|
539
|
+
gitLog.debug("heredoc_terminator", "delim", delim, "strip_tabs", stripTabs, "matched", isTerminator);
|
|
540
|
+
return isTerminator;
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
export function executableText(cmd: string, depth = 0, mode: ScanMode = "full"): string {
|
|
544
|
+
if (depth > 6) return UNSCANNED;
|
|
545
|
+
const keepLiterals = mode === "full" || mode === "words";
|
|
546
|
+
const keepSubstitutions = mode !== "literal-body";
|
|
547
|
+
let out = "";
|
|
548
|
+
const pendingHeredocs: { delim: string; expand: boolean; stripTabs: boolean }[] = [];
|
|
549
|
+
const add = (s: string) => { out += s; };
|
|
550
|
+
let substitutions = 0;
|
|
551
|
+
let heredocs = 0;
|
|
552
|
+
let continuations = 0;
|
|
553
|
+
let comments = 0;
|
|
554
|
+
let hereStrings = 0;
|
|
555
|
+
|
|
556
|
+
for (let i = 0; i < cmd.length; i++) {
|
|
557
|
+
const ch = cmd[i];
|
|
558
|
+
|
|
559
|
+
// A backslash escapes whatever follows: `conflicted\ repo` is one word with
|
|
560
|
+
// a space, and a backslash before a newline is a continuation the shell
|
|
561
|
+
// removes entirely. Leaving either in place breaks word splitting - which is
|
|
562
|
+
// how `git -C conflicted\ repo add` hid its subcommand from the matcher.
|
|
563
|
+
if (ch === "\\" && i + 1 < cmd.length) {
|
|
564
|
+
if (cmd[i + 1] === "\n") {
|
|
565
|
+
continuations++;
|
|
566
|
+
i++;
|
|
567
|
+
continue;
|
|
568
|
+
}
|
|
569
|
+
// The escape is kept: `conflicted\ repo` is one word, and the tokenizer
|
|
570
|
+
// downstream is what knows that. Stripping it here would turn it into two.
|
|
571
|
+
if (keepLiterals) {
|
|
572
|
+
add(ch);
|
|
573
|
+
add(cmd[i + 1]);
|
|
574
|
+
}
|
|
575
|
+
i++;
|
|
576
|
+
continue;
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
// A `#` at the start of a word begins a comment: nothing after it runs, so a
|
|
580
|
+
// heredoc-looking token inside one must not swallow the lines below.
|
|
581
|
+
if (ch === "#" && (i === 0 || /[\s;&|(]/.test(cmd[i - 1]))) {
|
|
582
|
+
let end = cmd.indexOf("\n", i);
|
|
583
|
+
if (end === -1) end = cmd.length;
|
|
584
|
+
comments++;
|
|
585
|
+
// The newline that ends a comment is a command boundary like any other:
|
|
586
|
+
// dropping it would join the next command onto the previous segment's text
|
|
587
|
+
// and read `note; git add x` as one segment starting with `note`.
|
|
588
|
+
if (end < cmd.length) add("\n");
|
|
589
|
+
i = end;
|
|
590
|
+
continue;
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
// A here-string (`<<<word`) is one data argument, not a heredoc. Its text
|
|
594
|
+
// is inert, but a substitution inside it still runs, so scan it for those.
|
|
595
|
+
if (ch === "<" && cmd[i + 1] === "<" && cmd[i + 2] === "<") {
|
|
596
|
+
let j = i + 3;
|
|
597
|
+
while (j < cmd.length && /[ \t]/.test(cmd[j])) j++;
|
|
598
|
+
const quote = cmd[j];
|
|
599
|
+
let end = j;
|
|
600
|
+
if (quote === "'" || quote === '"') {
|
|
601
|
+
end = closingQuote(cmd, j, quote);
|
|
602
|
+
add(` ${executableText(cmd.slice(j + 1, end), depth + 1, quote === '"' ? "body" : "literal-body")} `);
|
|
603
|
+
hereStrings++;
|
|
604
|
+
} else {
|
|
605
|
+
while (end < cmd.length && !/[\s;&|]/.test(cmd[end])) end++;
|
|
606
|
+
add(` ${executableText(cmd.slice(j, end), depth + 1, "body")} `);
|
|
607
|
+
hereStrings++;
|
|
608
|
+
}
|
|
609
|
+
i = end;
|
|
610
|
+
continue;
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
// Heredoc opener: remember the delimiter, keep scanning the same line.
|
|
614
|
+
if (ch === "<" && cmd[i + 1] === "<") {
|
|
615
|
+
const m = /^<<(-?)\s*(?:'([^']*)'|"([^"]*)"|([^\s;&|)'\n]+))/.exec(cmd.slice(i));
|
|
616
|
+
if (m) {
|
|
617
|
+
pendingHeredocs.push({
|
|
618
|
+
delim: m[2] ?? m[3] ?? m[4],
|
|
619
|
+
expand: !m[2] && !m[3],
|
|
620
|
+
stripTabs: m[1] === "-",
|
|
621
|
+
});
|
|
622
|
+
heredocs++;
|
|
623
|
+
i += m[0].length - 1;
|
|
624
|
+
continue;
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
// Heredoc bodies start after this line. One cursor walks past each body and
|
|
629
|
+
// its terminator, so a second heredoc on the same line resumes in the right
|
|
630
|
+
// place instead of inside the first body.
|
|
631
|
+
if (ch === "\n" && pendingHeredocs.length > 0) {
|
|
632
|
+
let cursor = i + 1;
|
|
633
|
+
for (const h of pendingHeredocs) {
|
|
634
|
+
const bodyLines: string[] = [];
|
|
635
|
+
let closed = false;
|
|
636
|
+
// Consume the whole body — every line until the terminator — so the
|
|
637
|
+
// outer scan cannot resume inside body text.
|
|
638
|
+
while (cursor <= cmd.length) {
|
|
639
|
+
let lineEnd = cmd.indexOf("\n", cursor);
|
|
640
|
+
const atEnd = lineEnd === -1;
|
|
641
|
+
if (atEnd) lineEnd = cmd.length;
|
|
642
|
+
const line = cmd.slice(cursor, lineEnd);
|
|
643
|
+
if (isHeredocTerminator(line, h.delim, h.stripTabs)) {
|
|
644
|
+
cursor = Math.min(lineEnd + 1, cmd.length);
|
|
645
|
+
closed = true;
|
|
646
|
+
break;
|
|
647
|
+
}
|
|
648
|
+
bodyLines.push(line);
|
|
649
|
+
cursor = atEnd ? cmd.length : lineEnd + 1;
|
|
650
|
+
if (atEnd) break;
|
|
651
|
+
}
|
|
652
|
+
if (h.expand && keepSubstitutions) add(` ${executableText(bodyLines.join("\n"), depth + 1, "body")} `);
|
|
653
|
+
if (!closed) break;
|
|
654
|
+
}
|
|
655
|
+
pendingHeredocs.length = 0;
|
|
656
|
+
// A newline, so whatever follows the terminator starts its own command.
|
|
657
|
+
add("\n");
|
|
658
|
+
i = cursor - 1;
|
|
659
|
+
continue;
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
// Command substitution — always executes.
|
|
663
|
+
if (ch === "$" && cmd[i + 1] === "(" && keepSubstitutions) {
|
|
664
|
+
const end = matchingParen(cmd, i + 1);
|
|
665
|
+
substitutions++;
|
|
666
|
+
// Parenthesised so the substituted commands are command positions of their
|
|
667
|
+
// own rather than trailing arguments of the command that expanded them.
|
|
668
|
+
add(`(${executableText(cmd.slice(i + 2, end), depth + 1)})`);
|
|
669
|
+
i = end;
|
|
670
|
+
continue;
|
|
671
|
+
}
|
|
672
|
+
if (ch === "`" && keepSubstitutions) {
|
|
673
|
+
const end = cmd.indexOf("`", i + 1);
|
|
674
|
+
substitutions++;
|
|
675
|
+
add(`(${executableText(cmd.slice(i + 1, end === -1 ? cmd.length : end), depth + 1)})`);
|
|
676
|
+
i = end === -1 ? cmd.length : end;
|
|
677
|
+
continue;
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
// Inside a double-quoted span or a heredoc body an apostrophe is an ordinary
|
|
681
|
+
// character - "it's" is not a quote. Treating it as one swallowed the
|
|
682
|
+
// substitutions that follow, e.g. printf %s "it's $(git add a.txt)".
|
|
683
|
+
if (ch === "'" && !keepLiterals) {
|
|
684
|
+
if (keepSubstitutions) {
|
|
685
|
+
const end = cmd.indexOf("'", i + 1);
|
|
686
|
+
add(` ${executableText(cmd.slice(i + 1, end === -1 ? cmd.length : end), depth + 1, "body")} `);
|
|
687
|
+
i = end === -1 ? cmd.length : end;
|
|
688
|
+
}
|
|
689
|
+
continue;
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
// ANSI-C quoting: $'…' — literal, but still a script argument to `sh -c`.
|
|
693
|
+
const ansi = ch === "$" && cmd[i + 1] === "'";
|
|
694
|
+
if (ansi || ch === "'") {
|
|
695
|
+
const start = ansi ? i + 1 : i;
|
|
696
|
+
// No closing quote: bash reports an unexpected EOF and runs nothing at all,
|
|
697
|
+
// so the rest of the command is not executable. Treating the tail as run
|
|
698
|
+
// would be the unsafe direction — it would invent a staging command the
|
|
699
|
+
// shell never performs.
|
|
700
|
+
const end = cmd.indexOf("'", start + 1);
|
|
701
|
+
const content = cmd.slice(start + 1, end === -1 ? cmd.length : end);
|
|
702
|
+
// A quoted part glued to adjacent text is part of the same shell word
|
|
703
|
+
// (`g'add'` is `gadd`, `git''` is `git`), so it must be concatenated. Only
|
|
704
|
+
// a standalone quoted argument collapses to a placeholder.
|
|
705
|
+
// `$'…'` is its own word — the `$` is a token, not glued text. An
|
|
706
|
+
// unterminated quote is not glued either: bash reports an unexpected EOF
|
|
707
|
+
// and runs nothing, so the tail must not be read as a command.
|
|
708
|
+
const glued = !ansi && end !== -1 && start > 0 && !/[\s;&|(]/.test(cmd[start - 1]);
|
|
709
|
+
if (isScriptArgument(cmd, start)) {
|
|
710
|
+
// Newlines, not spaces: the script is a command of its own, so a cd or
|
|
711
|
+
// git inside it starts a segment rather than trailing an option word.
|
|
712
|
+
if (keepSubstitutions) add(`\n(${executableText(decodeAnsiC(content), depth + 1)})\n`);
|
|
713
|
+
else add(" _ ");
|
|
714
|
+
} else if (glued || /(?:\bgit|\bcd|\bpushd|\bchdir|-C)$/.test(out.trimEnd())) {
|
|
715
|
+
// The subcommand or a directory argument, quoted: `git 'add' x`,
|
|
716
|
+
// `cd 'work tree'`, `git -C 'my repo' add`. A directory is re-quoted so a
|
|
717
|
+
// name with a space stays one word for the directory walker.
|
|
718
|
+
const isDirArg = /(?:\bcd|\bpushd|\bchdir|-C)$/.test(out.trimEnd());
|
|
719
|
+
add(isDirArg ? `"${content}"` : content);
|
|
720
|
+
} else {
|
|
721
|
+
add(" _ ");
|
|
722
|
+
}
|
|
723
|
+
i = end === -1 ? cmd.length : end;
|
|
724
|
+
continue;
|
|
725
|
+
}
|
|
726
|
+
if (ch === '"') {
|
|
727
|
+
const end = closingQuote(cmd, i, '"');
|
|
728
|
+
const content = cmd.slice(i + 1, end);
|
|
729
|
+
const glued = i > 0 && !/[\s;&|(]/.test(cmd[i - 1]);
|
|
730
|
+
if (isScriptArgument(cmd, i)) {
|
|
731
|
+
if (keepSubstitutions) add(`\n(${executableText(content, depth + 1)})\n`);
|
|
732
|
+
} else if (glued || /(?:\bgit|\bcd|\bpushd|\bchdir|-C)$/.test(out.trimEnd())) {
|
|
733
|
+
// Part of a shell word, or a quoted directory argument: keep the text so
|
|
734
|
+
// the word survives concatenation. Quoting is re-emitted so a path with
|
|
735
|
+
// spaces still reaches the directory walker as one argument.
|
|
736
|
+
const isDirArg = /(?:\bcd|\bpushd|\bchdir|-C)$/.test(out.trimEnd());
|
|
737
|
+
add(isDirArg ? `"${content}"` : executableText(content, depth + 1, "full"));
|
|
738
|
+
} else if (keepSubstitutions) {
|
|
739
|
+
// Only the substitutions inside a double-quoted span execute.
|
|
740
|
+
substitutions++;
|
|
741
|
+
add(`(${executableText(content, depth + 1, "body")})`);
|
|
742
|
+
} else {
|
|
743
|
+
add(" _ ");
|
|
744
|
+
}
|
|
745
|
+
i = end;
|
|
746
|
+
continue;
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
if (keepLiterals) add(ch);
|
|
750
|
+
}
|
|
751
|
+
gitLog.debug("shell_scan", "depth", depth, "mode", mode, "heredocs", heredocs, "substitutions", substitutions, "continuations", continuations, "comments", comments, "here_strings", hereStrings);
|
|
752
|
+
return out;
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
/**
|
|
756
|
+
* Git commands that write a *resolution* of an in-progress merge/rebase/
|
|
757
|
+
* cherry-pick. Inspecting a conflicted tree (`git status`, `git diff`) and
|
|
758
|
+
* backing out (`--abort`) are deliberately not in this set.
|
|
759
|
+
*/
|
|
760
|
+
|
|
761
|
+
|
|
762
|
+
/** Shell keywords and `VAR=value` prefixes that precede a segment's command. */
|
|
763
|
+
const SEGMENT_SKIP = new Set(["if", "then", "else", "elif", "fi", "do", "done", "while", "until", "!", "{", "}", "(", ")", "function", "coproc"]);
|
|
764
|
+
|
|
765
|
+
/**
|
|
766
|
+
* Words after which a `git` token is still executed rather than merely printed:
|
|
767
|
+
* these run the command that follows them, so `xargs git add` and
|
|
768
|
+
* `find . -exec git add` stage while `echo git add` does not.
|
|
769
|
+
*/
|
|
770
|
+
const GIT_EXECUTORS = new Set([
|
|
771
|
+
"xargs", "find", "-exec", "-execdir", "env", "sudo", "time", "nohup", "nice",
|
|
772
|
+
"ionice", "stdbuf", "setsid", "command", "exec", "timeout",
|
|
773
|
+
// These run their argument as commands. A shell is deliberately absent: its
|
|
774
|
+
// script argument is emitted as a segment of its own, and treating `bash` as a
|
|
775
|
+
// wrapper instead made `bash -c 'echo git add'` look like a staging command.
|
|
776
|
+
"eval", "source", ".",
|
|
777
|
+
]);
|
|
778
|
+
|
|
779
|
+
/** Wrapper options whose operand names something other than the command. */
|
|
780
|
+
const WRAPPER_VALUE_OPTIONS = new Set([
|
|
781
|
+
"-u", "--user", "-g", "--group", "-h", "--host", "-p", "--prompt", "-r", "--role",
|
|
782
|
+
"-t", "--type", "-U", "--other-user", "-C", "--chdir", "--preserve-env",
|
|
783
|
+
]);
|
|
784
|
+
|
|
785
|
+
/** Options that change directory, which differ per wrapper. */
|
|
786
|
+
const WRAPPER_CHDIR_OPTIONS: Record<string, Set<string>> = {
|
|
787
|
+
sudo: new Set(["-D", "--chdir"]),
|
|
788
|
+
env: new Set(["-C", "--chdir"]),
|
|
789
|
+
};
|
|
790
|
+
/** Git's own directory option. */
|
|
791
|
+
/**
|
|
792
|
+
* Git's own options that name the repository. -C moves the working directory and
|
|
793
|
+
* --git-dir names the repository outright.
|
|
794
|
+
*
|
|
795
|
+
* Deliberately not --work-tree: the git directory is what selects the index that
|
|
796
|
+
* records a merge, so two work trees over one git directory share one conflict
|
|
797
|
+
* state and must not be treated as separate repositories.
|
|
798
|
+
*/
|
|
799
|
+
const GIT_CHDIR_OPTIONS = new Set(["-C", "--git-dir"]);
|
|
800
|
+
|
|
801
|
+
/** For a wrapper with no directory option of its own. */
|
|
802
|
+
const NO_CHDIR_OPTIONS = new Set<string>();
|
|
803
|
+
|
|
804
|
+
/** Is this word the git executable? A full or relative path names it just as well. */
|
|
805
|
+
function isGitWord(word: string): boolean {
|
|
806
|
+
return word === "git" || word.endsWith("/git");
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
/**
|
|
810
|
+
* Does this segment run git? A segment whose *command word* is git, or one that
|
|
811
|
+
* follows a wrapper which executes the rest. Matching the text alone is wrong:
|
|
812
|
+
* `cd ~/git/proj` contains the word without running anything.
|
|
813
|
+
*/
|
|
814
|
+
export function segmentRunsGit(segment: string): boolean {
|
|
815
|
+
const verdict = classifySegment(segment);
|
|
816
|
+
gitLog.debug("segment_runs_git", "verdict", verdict);
|
|
817
|
+
return verdict;
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
function classifySegment(segment: string): boolean {
|
|
821
|
+
const words = tokenize(segment.trim());
|
|
822
|
+
let k = 0;
|
|
823
|
+
while (k < words.length) {
|
|
824
|
+
// `function NAME { ... }` puts the name between the keyword and the body.
|
|
825
|
+
if (words[k] === "function") { k += 2; continue; }
|
|
826
|
+
if (SEGMENT_SKIP.has(words[k]) || /^[A-Za-z_][A-Za-z0-9_]*=/.test(words[k])) { k += 1; continue; }
|
|
827
|
+
break;
|
|
828
|
+
}
|
|
829
|
+
if (k < words.length) {
|
|
830
|
+
// A segment can start mid-subshell, so `(git` is still the git command.
|
|
831
|
+
const head = words[k].replace(/^[()]+|[()]+$/g, "");
|
|
832
|
+
if (isGitWord(head)) return true;
|
|
833
|
+
if (executorRunsGit(words, k, head)) return true;
|
|
834
|
+
}
|
|
835
|
+
// A parenthesised group is real syntax, so a git command inside one runs even
|
|
836
|
+
// when the segment starts with something else: `printf %s ((git add x))`.
|
|
837
|
+
if (/[()]/.test(segment)) {
|
|
838
|
+
for (const inner of segment.split(/[()]+/)) {
|
|
839
|
+
if (inner.trim() && segmentRunsGit(inner)) return true;
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
return false;
|
|
843
|
+
}
|
|
844
|
+
|
|
845
|
+
/**
|
|
846
|
+
* The word lists of every git invocation that actually runs: a git token that is
|
|
847
|
+
* a segment's command word, or one that follows a word which executes what comes
|
|
848
|
+
* after it. An argument that merely names git - `echo git add a.txt` - is not a
|
|
849
|
+
* command. Words are kept as tokens and never rejoined: an option value may hold
|
|
850
|
+
* an escaped space, and joining would split it back into two words.
|
|
851
|
+
*/
|
|
852
|
+
function executedGitCommands(cmd: string): string[][] {
|
|
853
|
+
const kept: string[][] = [];
|
|
854
|
+
for (const raw of cmd.split(/[\n;&|()]+/)) {
|
|
855
|
+
const words = tokenize(raw.trim());
|
|
856
|
+
let k = 0;
|
|
857
|
+
while (k < words.length) {
|
|
858
|
+
// `function NAME { ... }` puts the name between the keyword and the body.
|
|
859
|
+
if (words[k] === "function") { k += 2; continue; }
|
|
860
|
+
if (SEGMENT_SKIP.has(words[k]) || /^[A-Za-z_][A-Za-z0-9_]*=/.test(words[k])) { k += 1; continue; }
|
|
861
|
+
break;
|
|
862
|
+
}
|
|
863
|
+
if (k >= words.length) continue;
|
|
864
|
+
// A segment can start mid-subshell, so `(git` is still the git command.
|
|
865
|
+
const head = words[k].replace(/^[()]+|[()]+$/g, "");
|
|
866
|
+
if (isGitWord(head)) {
|
|
867
|
+
kept.push(words.slice(k));
|
|
868
|
+
} else if (executorRunsGit(words, k, head)) {
|
|
869
|
+
// The wrapper runs the rest, so any git token in the segment counts.
|
|
870
|
+
for (let i = k + 1; i < words.length; i++) {
|
|
871
|
+
if (isGitWord(words[i])) kept.push(words.slice(i));
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
gitLog.debug("executed_git_commands", "count", kept.length);
|
|
876
|
+
return kept;
|
|
877
|
+
}
|
|
878
|
+
|
|
879
|
+
/**
|
|
880
|
+
* Does a wrapper at `k` run git? `command -v git` prints the path instead of
|
|
881
|
+
* running anything, so a lookup is not an invocation.
|
|
882
|
+
*/
|
|
883
|
+
function executorRunsGit(words: string[], k: number, head: string): boolean {
|
|
884
|
+
if (!GIT_EXECUTORS.has(head)) return false;
|
|
885
|
+
if (head === "command" && /^-[vV]$/.test(words[k + 1] ?? "")) return false;
|
|
886
|
+
return words.slice(k + 1).some(isGitWord);
|
|
887
|
+
}
|
|
888
|
+
|
|
889
|
+
/** Global options whose value is the next word rather than an attached one. */
|
|
890
|
+
const GLOBAL_VALUE_OPTIONS = new Set(["-C", "-c"]);
|
|
891
|
+
const GLOBAL_LONG_VALUE_OPTIONS = new Set(["--git-dir", "--work-tree", "--namespace", "--exec-path"]);
|
|
892
|
+
|
|
893
|
+
/**
|
|
894
|
+
* The index of the subcommand in a git word list.
|
|
895
|
+
*
|
|
896
|
+
* Only a few global options take their value as a separate word. Assuming every
|
|
897
|
+
* option does swallowed the subcommand itself — `git --no-pager add x` read
|
|
898
|
+
* `add` as the value of `--no-pager` and then found no subcommand at all.
|
|
899
|
+
*/
|
|
900
|
+
/** The index of the word that runs git, or -1. */
|
|
901
|
+
function gitWordIndex(words: string[]): number {
|
|
902
|
+
let k = 0;
|
|
903
|
+
while (k < words.length) {
|
|
904
|
+
if (words[k] === "function") { k += 2; continue; }
|
|
905
|
+
if (SEGMENT_SKIP.has(words[k]) || /^[A-Za-z_][A-Za-z0-9_]*=/.test(words[k])) { k += 1; continue; }
|
|
906
|
+
const head = words[k].replace(/^[()]+|[()]+$/g, "");
|
|
907
|
+
if (isGitWord(head)) return k;
|
|
908
|
+
// A wrapper runs whatever follows it. `command -v git` prints the path
|
|
909
|
+
// instead of running anything, and `sudo -u git` names a user, not a
|
|
910
|
+
// command - so a wrapper's own options are stepped over, operands included.
|
|
911
|
+
if (GIT_EXECUTORS.has(head) && !/^-[vV]$/.test(words[k + 1] ?? "")) {
|
|
912
|
+
// The operand of a wrapper option names something else: `sudo -u git`
|
|
913
|
+
// runs git as a user called git, and never runs it at all.
|
|
914
|
+
// Walk past the wrapper's own options. One that takes a value takes the
|
|
915
|
+
// next word too, and that word is its operand: in `sudo -u git merge` the
|
|
916
|
+
// git is the user to run as, and the command is merge.
|
|
917
|
+
let i = k + 1;
|
|
918
|
+
let from = i;
|
|
919
|
+
while (i < words.length) {
|
|
920
|
+
const tok = words[i];
|
|
921
|
+
if (!tok.startsWith("-") || tok === "-") break;
|
|
922
|
+
i += WRAPPER_VALUE_OPTIONS.has(tok) ? 2 : 1;
|
|
923
|
+
from = i;
|
|
924
|
+
}
|
|
925
|
+
for (let j = from; j < words.length; j++) if (isGitWord(words[j])) return j;
|
|
926
|
+
}
|
|
927
|
+
return -1;
|
|
928
|
+
}
|
|
929
|
+
return -1;
|
|
930
|
+
}
|
|
931
|
+
|
|
932
|
+
/** The index of the subcommand, given where the git word starts. */
|
|
933
|
+
function gitSubcommandIndex(words: string[], gitAt = 0): number {
|
|
934
|
+
let k = gitAt + 1;
|
|
935
|
+
while (k < words.length && words[k].startsWith("-") && words[k] !== "-") {
|
|
936
|
+
const tok = words[k];
|
|
937
|
+
const attached = tok.length > 2 && !tok.startsWith("--") ? true : tok.includes("=");
|
|
938
|
+
const takesNext = tok.startsWith("--") ? GLOBAL_LONG_VALUE_OPTIONS.has(tok) : GLOBAL_VALUE_OPTIONS.has(tok);
|
|
939
|
+
if (!attached && takesNext && words[k + 1] && !words[k + 1].startsWith("-")) k += 2;
|
|
940
|
+
else k += 1;
|
|
941
|
+
}
|
|
942
|
+
return k;
|
|
943
|
+
}
|
|
944
|
+
|
|
945
|
+
/** The directory a git word list targets, via its global -C values, in order. */
|
|
946
|
+
/**
|
|
947
|
+
* The directory a chdir option names, in whichever of its spellings it is
|
|
948
|
+
* written: separated (`-C dir`, `--chdir dir`), attached (`-Cdir`) or with an
|
|
949
|
+
* equals sign (`--chdir=dir`).
|
|
950
|
+
*/
|
|
951
|
+
function chdirValue(tok: string, options: Set<string>, next?: string): string | undefined {
|
|
952
|
+
for (const opt of options) {
|
|
953
|
+
if (tok === opt) return next;
|
|
954
|
+
// Only a long option separates its value with `=`. On a short one the
|
|
955
|
+
// equals sign is part of the name, so `-C=repo` names the directory
|
|
956
|
+
// `=repo` and not `repo`.
|
|
957
|
+
if (opt.startsWith("--") && tok.startsWith(`${opt}=`)) return tok.slice(opt.length + 1);
|
|
958
|
+
if (!opt.startsWith("--") && tok.startsWith(opt) && tok.length > opt.length) return tok.slice(opt.length);
|
|
959
|
+
}
|
|
960
|
+
return undefined;
|
|
961
|
+
}
|
|
962
|
+
|
|
963
|
+
/**
|
|
964
|
+
* The directories a git invocation is moved into by directory options, in order.
|
|
965
|
+
*
|
|
966
|
+
* Two regions contribute. Before the git word sits a chain of wrappers, each of
|
|
967
|
+
* which may change directory with its own option — and they disagree: sudo
|
|
968
|
+
* changes directory with -D and uses -C for a descriptor limit, while env -C and
|
|
969
|
+
* git -C both change directory. Which wrapper owns which option therefore has to
|
|
970
|
+
* be tracked as the words are read, rather than assumed from the first one.
|
|
971
|
+
*/
|
|
972
|
+
function gitScopeValues(words: string[], gitAt = 0): string[] {
|
|
973
|
+
const values: string[] = [];
|
|
974
|
+
let wrapper = "";
|
|
975
|
+
for (let i = 0; i < gitAt; i++) {
|
|
976
|
+
const tok = words[i];
|
|
977
|
+
if (!tok.startsWith("-") || tok === "-") {
|
|
978
|
+
wrapper = tok.replace(/^[()]+|[()]+$/g, "");
|
|
979
|
+
continue;
|
|
980
|
+
}
|
|
981
|
+
const opt = tok.split("=")[0];
|
|
982
|
+
const value = chdirValue(tok, WRAPPER_CHDIR_OPTIONS[wrapper] ?? NO_CHDIR_OPTIONS, words[i + 1]);
|
|
983
|
+
if (value !== undefined) {
|
|
984
|
+
values.push(value);
|
|
985
|
+
if (!tok.includes("=") && tok === opt) i++;
|
|
986
|
+
continue;
|
|
987
|
+
}
|
|
988
|
+
// Any other option may take a value of its own; step over it so a wrapper
|
|
989
|
+
// name is not mistaken for the command.
|
|
990
|
+
if (!tok.includes("=") && WRAPPER_VALUE_OPTIONS.has(opt) && words[i + 1]) i++;
|
|
991
|
+
}
|
|
992
|
+
// Git's own global options, up to the subcommand.
|
|
993
|
+
for (let i = gitAt + 1; i < words.length; i++) {
|
|
994
|
+
const tok = words[i];
|
|
995
|
+
if (!tok.startsWith("-") || tok === "-") break;
|
|
996
|
+
const value = chdirValue(tok, GIT_CHDIR_OPTIONS, words[i + 1]);
|
|
997
|
+
if (value !== undefined) {
|
|
998
|
+
values.push(value);
|
|
999
|
+
if (!tok.includes("=") && !tok.startsWith("--")) i++;
|
|
1000
|
+
continue;
|
|
1001
|
+
}
|
|
1002
|
+
if (!tok.includes("=") && GLOBAL_LONG_VALUE_OPTIONS.has(tok) && words[i + 1]) i++;
|
|
1003
|
+
}
|
|
1004
|
+
gitLog.debug("git_scope_values", "count", values.length, "last", values[values.length - 1] ?? "cwd");
|
|
1005
|
+
return values;
|
|
1006
|
+
}
|
|
1007
|
+
|
|
1008
|
+
/** ANSI-C quoting turns these escapes into characters the shell really sees. */
|
|
1009
|
+
function decodeAnsiC(text: string): string {
|
|
1010
|
+
return text.replace(/\\n/g, "\n").replace(/\\t/g, " ");
|
|
1011
|
+
}
|
|
1012
|
+
|
|
1013
|
+
/**
|
|
1014
|
+
* Does this command both *create* a conflict and stage a side of it?
|
|
1015
|
+
*
|
|
1016
|
+
* The index is read once, before the command runs, so `git merge branch &&
|
|
1017
|
+
* git add conflicted.txt` sees a clean tree and then does in one line what the
|
|
1018
|
+
* handoff exists to prevent. Reading only the sequencer and only the staging is
|
|
1019
|
+
* enough: neither alone says anything, and together they are the whole bypass.
|
|
1020
|
+
*/
|
|
1021
|
+
export function createsAndResolvesConflict(command: string): boolean {
|
|
1022
|
+
const scanned = executableText(command);
|
|
1023
|
+
if (scanned.includes(UNSCANNED)) return true;
|
|
1024
|
+
// Subcommands that merge, and therefore can leave conflicts behind.
|
|
1025
|
+
const STARTERS = new Set(["merge", "rebase", "cherry-pick", "revert", "am", "pull"]);
|
|
1026
|
+
// Flags that make a sequencer do the opposite: a backout resolves nothing and
|
|
1027
|
+
// finishing an existing conflict is the handoff's job, not a way around it.
|
|
1028
|
+
const BACKOUT = /--(?:abort|quit|continue|skip)\b/;
|
|
1029
|
+
// `git stash list` reads; `stash pop` and `stash apply` merge and can conflict.
|
|
1030
|
+
const STASH_STARTS = new Set(["pop", "apply", "branch"]);
|
|
1031
|
+
const SIDE_PICKING = new Set(["update-index", "restore", "rm", "reset"]);
|
|
1032
|
+
|
|
1033
|
+
// Repositories in which a sequencer has already started, keyed by the directory
|
|
1034
|
+
// each one actually resolves to. A later merge in a different repository must
|
|
1035
|
+
// not be attributed to the first one, and staging is only a resolution in a
|
|
1036
|
+
// repository that started it.
|
|
1037
|
+
const started = new Set<string>();
|
|
1038
|
+
for (const raw of scanned.split(/[\n;&|()]+/)) {
|
|
1039
|
+
const words = tokenize(raw.trim());
|
|
1040
|
+
const k = gitWordIndex(words);
|
|
1041
|
+
if (k === -1) continue;
|
|
1042
|
+
// Which repository this invocation targets: git applies each -C in turn.
|
|
1043
|
+
let scope = "";
|
|
1044
|
+
for (const c of gitScopeValues(words, k)) scope = resolve(scope || ".", c);
|
|
1045
|
+
const k0 = gitSubcommandIndex(words, k);
|
|
1046
|
+
const sub = (words[k0] ?? "").split("=")[0];
|
|
1047
|
+
const rest = words.slice(k0 + 1).join(" ");
|
|
1048
|
+
const starts =
|
|
1049
|
+
(STARTERS.has(sub) && !BACKOUT.test(rest)) ||
|
|
1050
|
+
(sub === "stash" && STASH_STARTS.has((words[k0 + 1] ?? "").split("=")[0]));
|
|
1051
|
+
if (starts) started.add(scope);
|
|
1052
|
+
// Staging counts only after the sequencer, and only in the same repository:
|
|
1053
|
+
// `git -C a merge && git -C b add x` touches two unrelated trees.
|
|
1054
|
+
const stages = sub === "add" || SIDE_PICKING.has(sub) || (sub === "checkout" && /(^|\s)--/.test(rest));
|
|
1055
|
+
if (stages && started.has(scope)) {
|
|
1056
|
+
gitLog.debug("conflict_created_and_resolved", "scope", scope || "cwd", "subcommand", sub);
|
|
1057
|
+
return true;
|
|
1058
|
+
}
|
|
1059
|
+
}
|
|
1060
|
+
gitLog.debug("conflict_created_and_resolved", "started", started.size, "resolved", false);
|
|
1061
|
+
return false;
|
|
1062
|
+
}
|
|
1063
|
+
|
|
1064
|
+
export function isConflictResolutionCommand(command: string): boolean {
|
|
1065
|
+
const scanned = executableText(command);
|
|
1066
|
+
// Nesting deeper than the scan depth means the scanner stopped early. Treat
|
|
1067
|
+
// that as a resolution command rather than as proof there is none — checked on
|
|
1068
|
+
// the scan itself, before filtering, or the marker would be filtered away.
|
|
1069
|
+
if (scanned.includes(UNSCANNED)) {
|
|
1070
|
+
gitLog.warn("conflict_command_unscanned", "depth_limit", 6);
|
|
1071
|
+
return true;
|
|
1072
|
+
}
|
|
1073
|
+
// Every one of these clears an unmerged entry, which is picking a side:
|
|
1074
|
+
// git add / git rm / git restore stage the working tree as-is
|
|
1075
|
+
// git reset drop the index entry
|
|
1076
|
+
// git checkout <side flags> take one side, by flag or by revision
|
|
1077
|
+
// <sequencer> --continue/--skip advance past the conflicted commit
|
|
1078
|
+
// `--abort` is deliberately absent: it backs out rather than resolving.
|
|
1079
|
+
//
|
|
1080
|
+
// Subcommands come from the token stream, not from a `git ... add` pattern: an
|
|
1081
|
+
// option value may contain a space, so `git -C conflicted\ repo add` is `add`
|
|
1082
|
+
// with a two-word value, which no regex over the raw line can see past.
|
|
1083
|
+
const STAGE_SUBCOMMANDS = new Set(["add", "rm", "restore", "reset", "update-index"]);
|
|
1084
|
+
const SEQUENCERS = new Set(["merge", "rebase", "cherry-pick", "revert", "am"]);
|
|
1085
|
+
let matches = false;
|
|
1086
|
+
for (const words of executedGitCommands(scanned)) {
|
|
1087
|
+
const k = gitSubcommandIndex(words);
|
|
1088
|
+
const sub = words[k] || "";
|
|
1089
|
+
const rest = words.slice(k + 1).join(" ");
|
|
1090
|
+
// A subcommand the scanner could not read could be any of them.
|
|
1091
|
+
if (sub === "_" || sub.includes("$")) {
|
|
1092
|
+
gitLog.warn("conflict_command_dynamic_subcommand", "matches", true);
|
|
1093
|
+
matches = true;
|
|
1094
|
+
break;
|
|
1095
|
+
}
|
|
1096
|
+
if (
|
|
1097
|
+
STAGE_SUBCOMMANDS.has(sub) ||
|
|
1098
|
+
// A side flag, `-m` to re-merge, or `-- <path>` after a revision — each
|
|
1099
|
+
// takes one side of the conflict.
|
|
1100
|
+
(sub === "checkout" && /(^|\s)(?:--(?:ours|theirs|mine)\b|-m\b|--(?:\s|$))/.test(rest)) ||
|
|
1101
|
+
(SEQUENCERS.has(sub) && /--(?:continue|skip|quit)\b/.test(rest))
|
|
1102
|
+
) {
|
|
1103
|
+
matches = true;
|
|
1104
|
+
break;
|
|
1105
|
+
}
|
|
1106
|
+
}
|
|
1107
|
+
gitLog.debug("conflict_command_classified", "matches", matches);
|
|
1108
|
+
return matches;
|
|
1109
|
+
}
|
|
1110
|
+
|
|
1111
|
+
/**
|
|
1112
|
+
* Files with an unmerged index entry (merge/rebase/cherry-pick in progress).
|
|
1113
|
+
*
|
|
1114
|
+
* `ok` distinguishes "the index is clean" from "git would not answer". Callers
|
|
1115
|
+
* enforcing a block must fail closed on `ok: false` — treating an unreadable
|
|
1116
|
+
* index as an empty one turns a broken check into a silent pass.
|
|
1117
|
+
*/
|
|
1118
|
+
/**
|
|
1119
|
+
* Is this directory inside a git work tree at all? Distinguishes "no repository
|
|
1120
|
+
* yet" — `git init && git add -A`, a fresh clone — from "a repository whose
|
|
1121
|
+
* index cannot be read", which is the case worth failing closed on.
|
|
1122
|
+
*/
|
|
1123
|
+
export function isInsideGitWorkTree(cwd?: string): boolean {
|
|
1124
|
+
const r = runGit(["rev-parse", "--is-inside-work-tree"], cwd);
|
|
1125
|
+
gitLog.debug("inside_work_tree", "code", r.code);
|
|
1126
|
+
return r.code === 0 && r.stdout.trim() === "true";
|
|
1127
|
+
}
|
|
1128
|
+
|
|
1129
|
+
export function listUnmergedFiles(cwd?: string): { ok: boolean; files: string[] } {
|
|
1130
|
+
// `-- :/` is the whole repository, and `--full-name` makes the paths
|
|
1131
|
+
// repo-relative. Without them git lists only what is under the current
|
|
1132
|
+
// directory, so `git add ../a.txt` from a subdirectory would read as clean
|
|
1133
|
+
// while staging a conflict higher up.
|
|
1134
|
+
const r = runGit(["ls-files", "--unmerged", "--full-name", "--", ":/"], cwd);
|
|
1135
|
+
if (r.code !== 0) {
|
|
1136
|
+
// warn, not debug: this is the check failing, and it gates a block.
|
|
1137
|
+
gitLog.warn("unmerged_lookup_failed", "code", r.code, "repo", Boolean(cwd));
|
|
1138
|
+
return { ok: false, files: [] };
|
|
1139
|
+
}
|
|
1140
|
+
const files = new Set<string>();
|
|
1141
|
+
for (const line of r.stdout.split("\n")) {
|
|
1142
|
+
// <mode> <sha> <stage>\t<path>
|
|
1143
|
+
const path = line.slice(line.indexOf("\t") + 1).trim();
|
|
1144
|
+
if (path) files.add(path);
|
|
1145
|
+
}
|
|
1146
|
+
gitLog.debug("unmerged_lookup", "count", files.size);
|
|
1147
|
+
return { ok: true, files: [...files] };
|
|
1148
|
+
}
|
|
1149
|
+
|
|
408
1150
|
export const DANGEROUS = [
|
|
409
1151
|
/\brm\s+(?:-[a-zA-Z]+\s+)*(-[a-zA-Z]*r[a-zA-Z]*|--recursive)/i,
|
|
410
1152
|
/\bsudo\b/i,
|