line-log: detect unsupported formats
authorJeff King <peff@peff.net>
Mon, 11 Mar 2019 03:54:33 +0000 (23:54 -0400)
committerJunio C Hamano <gitster@pobox.com>
Mon, 11 Mar 2019 07:31:07 +0000 (16:31 +0900)
If you use "log -L" with an output format like "--raw" or "--stat",
we'll silently ignore the format and just output the normal patch.
Let's detect and complain about this, which at least tells the user
what's going on.

The tests here aren't exhaustive over the set of all formats, but it
should at least let us know if somebody breaks the format-checking.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
revision.c
t/t4211-line-log.sh
index 162d511d4686bc43f2032a57fa95e3601eb3d6b2..fc4f33fdd5345acb703433fd2d020627f49c2f78 100644 (file)
@@ -2683,6 +2683,10 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
        if (revs->first_parent_only && revs->bisect)
                die(_("--first-parent is incompatible with --bisect"));
 
+       if (revs->line_level_traverse &&
+           (revs->diffopt.output_format & ~(DIFF_FORMAT_PATCH | DIFF_FORMAT_NO_OUTPUT)))
+               die(_("-L does not yet support diff formats besides -p and -s"));
+
        if (revs->expand_tabs_in_log < 0)
                revs->expand_tabs_in_log = revs->expand_tabs_in_log_default;
 
index c9f2036f6881467a727104d62d126594b08aab8b..1db7bd0f59b46768d6559c37e026cde41821763a 100755 (executable)
@@ -122,4 +122,14 @@ test_expect_success '-s shows only line-log commits' '
        test_cmp expect actual
 '
 
+test_expect_success '-p shows the default patch output' '
+       git log -L1,24:b.c >expect &&
+       git log -L1,24:b.c -p >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success '--raw is forbidden' '
+       test_must_fail git log -L1,24:b.c --raw
+'
+
 test_done