Message ID | xmqqy2jglv29.fsf_-_@gitster.c.googlers.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | log: diagnose -L used with pathspec as an error | expand |
On Wed, Nov 04, 2020 at 12:35:10PM -0800, Junio C Hamano wrote: > The new tests say they may fail with "-L and --follow being > incompatible" instead of "-L and pathspec being imcompatible". > 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. This explanation makes sense (though s/imcompat/incompat/). > +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 && > + > + # This must fail due to "-L is incompatible with pathspec". > + test_must_fail git log -L1,1:b.c -- b.c 2>error && > + test_i18ngrep "cannot be used with pathspec" error && The renaming makes sense... > + > + # Note that incompatibility between -L/--follow is not > + # explicitly checked to avoid redundant code and the comments > + # on the following tests are merely for future-proofing. ...as does this comment to explain the rest of the tests. > + # These must fail due to "follow requires one pathspec", or > + # "-L is incompatible with --follow", depending on the > + # order the error is checked. Either is acceptable. > + test_must_fail git log -L1,1:b.c --follow && > + test_must_fail git log --follow -L1,1:b.c && > + > + # This may fail due to "-L is incompatible with pathspec", or > + # "-L is incompatible with --follow", depending on the > + # order the error is checked. Either is acceptable. > + test_must_fail git log --follow -L1,1:b.c -- b.c > +' Though "depending on the order" is a bit of a fiction, because those checks do not exist at all. I'm OK with it because the earlier comment explains what is going. I guess: # This may fail due to "-L is incompatible with pathspec", or # "-L is incompatible with --follow". We don't have the latter as of # the writing of this test, but either would be acceptable if we added # it. would be an alternative. I doubt it's worth spending too much time polishing. -Peff
diff --git a/builtin/log.c b/builtin/log.c index 0a7ed4bef9..9d70f3e60b 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -206,6 +206,9 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix, if (argc > 1) die(_("unrecognized argument: %s"), argv[1]); + if (rev->line_level_traverse && rev->prune_data.nr) + die(_("-L<range>:<file> cannot be used with pathspec")); + memset(&w, 0, sizeof(w)); userformat_find_requirements(NULL, &w); diff --git a/t/t4211-line-log.sh b/t/t4211-line-log.sh index 2d1d7b5d19..b85c4a8a04 100755 --- a/t/t4211-line-log.sh +++ b/t/t4211-line-log.sh @@ -8,6 +8,32 @@ 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 && + + # This must fail due to "-L is incompatible with pathspec". + test_must_fail git log -L1,1:b.c -- b.c 2>error && + test_i18ngrep "cannot be used with pathspec" error && + + # Note that incompatibility between -L/--follow is not + # explicitly checked to avoid redundant code and the comments + # on the following tests are merely for future-proofing. + + # These must fail due to "follow requires one pathspec", or + # "-L is incompatible with --follow", depending on the + # order the error is checked. Either is acceptable. + test_must_fail git log -L1,1:b.c --follow && + test_must_fail git log --follow -L1,1:b.c && + + # This may fail due to "-L is incompatible with pathspec", or + # "-L is incompatible with --follow", depending on the + # order the error is checked. 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 &&
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 imcompatible". 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> --- builtin/log.c | 3 +++ t/t4211-line-log.sh | 26 ++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) * This time, as a standalone patch, instead of a comment in a discussion thread.