Skip to content

Commit

Permalink
diff-no-index: correctly diagnose error return from diff_opt_parse()
Browse files Browse the repository at this point in the history
diff_opt_parse() returns the number of options parsed, or often
returns error() which is defined to return -1.  Yes, return value of
0 is "I did not process that option at all", which should cause the
caller to say that, but negative return should not be forgotten.

This bug caused "diff --no-index" to infinitely show the same error
message because the returned value was used to decrement the loop
control variable, e.g.

        $ git diff --no-index --color=words a b
        error: option `color' expects "always", "auto", or "never"
        error: option `color' expects "always", "auto", or "never"
        ...

Instead, make it act like so:

        $ git diff --no-index --color=words a b
        error: option `color' expects "always", "auto", or "never"
        fatal: invalid diff option/value: --color=words

Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Junio C Hamano committed Mar 31, 2014
1 parent 7bbc4e8 commit ad1c3fb
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion diff-no-index.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ void diff_no_index(struct rev_info *revs,
i++;
else {
j = diff_opt_parse(&revs->diffopt, argv + i, argc - i);
if (!j)
if (j <= 0)
die("invalid diff option/value: %s", argv[i]);
i += j;
}
Expand Down

0 comments on commit ad1c3fb

Please sign in to comment.