Skip to content

Commit 49325e5

Browse files
committed
fix(shared): abbreviated symbolic-ref deletes keep their console
1 parent eb422eb commit 49325e5

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

‎packages/shared/src/shell.test.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,7 @@ describe("runsGitWithoutConsole", () => {
616616
expect(runs(["config", "get", "user.name"])).toBe(true);
617617
expect(runs(["config", "--list"])).toBe(true);
618618
expect(runs(["symbolic-ref", "--quiet", "--short", "HEAD"])).toBe(true);
619+
expect(runs(["symbolic-ref", "refs/remotes/origin/HEAD"])).toBe(true);
619620
expect(runs(["remote", "-v"])).toBe(true);
620621
expect(runs(["remote", "get-url", "origin"])).toBe(true);
621622
});
@@ -635,6 +636,8 @@ describe("runsGitWithoutConsole", () => {
635636
expect(runs(["rev-parse", "--help"])).toBe(false);
636637
expect(runs(["--help", "rev-parse"])).toBe(false);
637638
expect(runs(["symbolic-ref", "--delete", "refs/remotes/origin/HEAD"])).toBe(false);
639+
expect(runs(["symbolic-ref", "--del", "refs/remotes/origin/HEAD"])).toBe(false);
640+
expect(runs(["symbolic-ref", "-qd", "refs/remotes/origin/HEAD"])).toBe(false);
638641
expect(runs(["-C", "rev-parse", "status"])).toBe(false);
639642
});
640643

‎packages/shared/src/shell.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,10 @@ const GIT_GLOBAL_OPTIONS_WITH_VALUE = new Set([
719719

720720
const positionals = (args: ReadonlyArray<string>) => args.filter((arg) => !arg.startsWith("-"));
721721

722+
// Git accepts abbreviated and bundled options (`--del`, `-qd`), so a read is
723+
// recognized by allowing its options rather than by rejecting the write ones.
724+
const SYMBOLIC_REF_READ_OPTIONS = new Set(["-q", "--quiet", "--short"]);
725+
722726
const GIT_READ_SUBCOMMANDS = new Map<string, (args: ReadonlyArray<string>) => boolean>([
723727
["rev-parse", () => true],
724728
["rev-list", () => true],
@@ -736,7 +740,9 @@ const GIT_READ_SUBCOMMANDS = new Map<string, (args: ReadonlyArray<string>) => bo
736740
],
737741
[
738742
"symbolic-ref",
739-
(args) => !args.includes("--delete") && !args.includes("-d") && positionals(args).length <= 1,
743+
(args) =>
744+
args.every((arg) => !arg.startsWith("-") || SYMBOLIC_REF_READ_OPTIONS.has(arg)) &&
745+
positionals(args).length <= 1,
740746
],
741747
[
742748
"remote",

0 commit comments

Comments
 (0)