Skip to content

Commit a8a5bb1

Browse files
committed
Merge branch 'bc/diff-reject-empty-arg-to-pickaxe'
The -G/-S options to the "diff" family of commands caused us to hit a BUG() when they get no values; they have been corrected. * bc/diff-reject-empty-arg-to-pickaxe: diff: don't crash with empty argument to -G or -S
2 parents 5ce6e0e + a620046 commit a8a5bb1

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

diff.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5493,6 +5493,8 @@ static int diff_opt_pickaxe_regex(const struct option *opt,
54935493
BUG_ON_OPT_NEG(unset);
54945494
options->pickaxe = arg;
54955495
options->pickaxe_opts |= DIFF_PICKAXE_KIND_G;
5496+
if (arg && !*arg)
5497+
return error(_("-G requires a non-empty argument"));
54965498
return 0;
54975499
}
54985500

@@ -5504,6 +5506,8 @@ static int diff_opt_pickaxe_string(const struct option *opt,
55045506
BUG_ON_OPT_NEG(unset);
55055507
options->pickaxe = arg;
55065508
options->pickaxe_opts |= DIFF_PICKAXE_KIND_S;
5509+
if (arg && !*arg)
5510+
return error(_("-S requires a non-empty argument"));
55075511
return 0;
55085512
}
55095513

t/t4209-log-pickaxe.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,22 @@ test_expect_success 'usage: --no-pickaxe-regex' '
9393
test_cmp expect actual
9494
'
9595

96+
test_expect_success 'usage: -G and -S with empty argument' '
97+
cat >expect <<-\EOF &&
98+
error: -S requires a non-empty argument
99+
EOF
100+
101+
test_expect_code 129 git log -S "" 2>actual &&
102+
test_cmp expect actual &&
103+
104+
cat >expect <<-\EOF &&
105+
error: -G requires a non-empty argument
106+
EOF
107+
108+
test_expect_code 129 git log -G "" 2>actual &&
109+
test_cmp expect actual
110+
'
111+
96112
test_log expect_initial --grep initial
97113
test_log expect_nomatch --grep InItial
98114
test_log_icase expect_initial --grep InItial

0 commit comments

Comments
 (0)