Git fork

diff: don't crash with empty argument to -G or -S

The pickaxe options, -G and -S, need either a regex or a string to look
through the history for. An empty value isn't very useful since it
would either match everything or nothing, and what's worse, we presently
crash with a BUG like so when the user provides one:

BUG: diffcore-pickaxe.c:241: should have needle under -G or -S

Since it's not very nice of us to crash and this wouldn't do anything
useful anyway, let's simply inform the user that they must provide a
non-empty argument and exit with an error if they provide an empty one
instead.

Reported-by: Jared Van Bortel <cebtenzzre@gmail.com>
Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Acked-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

authored by

brian m. carlson and committed by
Junio C Hamano
a620046b f93ff170

+20
+4
diff.c
··· 5493 5493 BUG_ON_OPT_NEG(unset); 5494 5494 options->pickaxe = arg; 5495 5495 options->pickaxe_opts |= DIFF_PICKAXE_KIND_G; 5496 + if (arg && !*arg) 5497 + return error(_("-G requires a non-empty argument")); 5496 5498 return 0; 5497 5499 } 5498 5500 ··· 5504 5506 BUG_ON_OPT_NEG(unset); 5505 5507 options->pickaxe = arg; 5506 5508 options->pickaxe_opts |= DIFF_PICKAXE_KIND_S; 5509 + if (arg && !*arg) 5510 + return error(_("-S requires a non-empty argument")); 5507 5511 return 0; 5508 5512 } 5509 5513
+16
t/t4209-log-pickaxe.sh
··· 93 93 test_cmp expect actual 94 94 ' 95 95 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 + 96 112 test_log expect_initial --grep initial 97 113 test_log expect_nomatch --grep InItial 98 114 test_log_icase expect_initial --grep InItial