summaryrefslogtreecommitdiff
path: root/t/t4211-line-log.sh
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2020-11-04 17:54:01 (GMT)
committerJunio C Hamano <gitster@pobox.com>2020-11-04 21:38:33 (GMT)
commit39664cb0aca42f240468ddf84fe75df4172ab63f (patch)
tree8d30a57c2447d38bb76662d17a7578cbb103511a /t/t4211-line-log.sh
parent898f80736c75878acc02dc55672317fcc0e0a5a6 (diff)
downloadgit-39664cb0aca42f240468ddf84fe75df4172ab63f.zip
git-39664cb0aca42f240468ddf84fe75df4172ab63f.tar.gz
git-39664cb0aca42f240468ddf84fe75df4172ab63f.tar.bz2
log: diagnose -L used with pathspec as an error
The -L option is documented to accept no pathspec, but the command line option parser has allowed the combination without checking so far. Ensure that there is no pathspec when the -L option is in effect to fix this. Incidentally, this change fixes another bug in the command line option parser, which has allowed the -L option used together with the --follow option. Because the latter requires exactly one path given, but the former takes no pathspec, they become mutually incompatible automatically. Because the -L option follows renames on its own, there is no reason to give --follow at the same time. The new tests say they may fail with "-L and --follow being incompatible" instead of "-L and pathspec being incompatible". Currently the expected failure can come only from the latter, but this is to futureproof them, in case we decide to add code to explicititly die on -L and --follow used together. Heled-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't/t4211-line-log.sh')
-rwxr-xr-xt/t4211-line-log.sh22
1 files changed, 22 insertions, 0 deletions
diff --git a/t/t4211-line-log.sh b/t/t4211-line-log.sh
index 2d1d7b5..85d1514 100755
--- a/t/t4211-line-log.sh
+++ b/t/t4211-line-log.sh
@@ -8,6 +8,28 @@ test_expect_success 'setup (import history)' '
git reset --hard
'
+test_expect_success 'basic command line parsing' '
+ # This may fail due to "no such path a.c in commit", or
+ # "-L is incompatible with pathspec", depending on the
+ # order the error is checked. Either is acceptable.
+ test_must_fail git log -L1,1:a.c -- a.c &&
+
+ # -L requires there is no pathspec
+ test_must_fail git log -L1,1:b.c -- b.c 2>error &&
+ test_i18ngrep "cannot be used with pathspec" error &&
+
+ # This would fail because --follow wants a single path, but
+ # we may fail due to incompatibility between -L/--follow in
+ # the future. Either is acceptable.
+ test_must_fail git log -L1,1:b.c --follow &&
+ test_must_fail git log --follow -L1,1:b.c &&
+
+ # This would fail because -L wants no pathspec, but
+ # we may fail due to incompatibility between -L/--follow in
+ # the future. Either is acceptable.
+ test_must_fail git log --follow -L1,1:b.c -- b.c
+'
+
canned_test_1 () {
test_expect_$1 "$2" "
git log $2 >actual &&