summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2025-02-25 14:19:35 -0800
committerJunio C Hamano <gitster@pobox.com>2025-02-25 14:19:35 -0800
commita8a5bb1f7813ceb42199ef2bcf9d925da007f047 (patch)
treedcea38f52ccbe9319804bcc33c47fc42be4e5c60
parent5ce6e0e2421af8aaa2be5684176a66388561d44e (diff)
parenta620046b29d3a9b8a0337c0396441c26ac84ebe9 (diff)
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
-rw-r--r--diff.c4
-rwxr-xr-xt/t4209-log-pickaxe.sh16
2 files changed, 20 insertions, 0 deletions
diff --git a/diff.c b/diff.c
index 019fb893a7..c89c15d98e 100644
--- a/diff.c
+++ b/diff.c
@@ -5493,6 +5493,8 @@ static int diff_opt_pickaxe_regex(const struct option *opt,
BUG_ON_OPT_NEG(unset);
options->pickaxe = arg;
options->pickaxe_opts |= DIFF_PICKAXE_KIND_G;
+ if (arg && !*arg)
+ return error(_("-G requires a non-empty argument"));
return 0;
}
@@ -5504,6 +5506,8 @@ static int diff_opt_pickaxe_string(const struct option *opt,
BUG_ON_OPT_NEG(unset);
options->pickaxe = arg;
options->pickaxe_opts |= DIFF_PICKAXE_KIND_S;
+ if (arg && !*arg)
+ return error(_("-S requires a non-empty argument"));
return 0;
}
diff --git a/t/t4209-log-pickaxe.sh b/t/t4209-log-pickaxe.sh
index a675ace081..0e2f80a268 100755
--- a/t/t4209-log-pickaxe.sh
+++ b/t/t4209-log-pickaxe.sh
@@ -93,6 +93,22 @@ test_expect_success 'usage: --no-pickaxe-regex' '
test_cmp expect actual
'
+test_expect_success 'usage: -G and -S with empty argument' '
+ cat >expect <<-\EOF &&
+ error: -S requires a non-empty argument
+ EOF
+
+ test_expect_code 129 git log -S "" 2>actual &&
+ test_cmp expect actual &&
+
+ cat >expect <<-\EOF &&
+ error: -G requires a non-empty argument
+ EOF
+
+ test_expect_code 129 git log -G "" 2>actual &&
+ test_cmp expect actual
+'
+
test_log expect_initial --grep initial
test_log expect_nomatch --grep InItial
test_log_icase expect_initial --grep InItial