diff: report bogus input to -C/-M/-B
We already detect invalid input to these functions, but we simply exit with an error code, never saying anything as simple as "your input was wrong". Let's fix that. Before: $ git diff -CM $ echo $? 128 After: $ git diff -CM error: invalid argument to -C: M $ echo $? 128 There should be no problems with having diff_opt_parse print to stderr, as there is already precedent in complaining about bogus --color and --output arguments. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Oct 21, 2010 at 10:49 UTC
07cd7265274ba6aed2589e6b22eae7d413640037
1 file changed
+3
-3
diff.c
+3
-3
@@ -3142,18 +3142,18 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
3142
/* renames options */
3143
else if (!prefixcmp(arg, "-B")) {
3144
if ((options->break_opt = diff_scoreopt_parse(arg)) == -1)
3145
- return -1;
3145
+ return error("invalid argument to -B: %s", arg+2);
3146
}
3147
else if (!prefixcmp(arg, "-M")) {
3148
if ((options->rename_score = diff_scoreopt_parse(arg)) == -1)
3149
- return -1;
3149
+ return error("invalid argument to -M: %s", arg+2);
3150
options->detect_rename = DIFF_DETECT_RENAME;
3151
}
3152
else if (!prefixcmp(arg, "-C")) {
3153
if (options->detect_rename == DIFF_DETECT_COPY)
3154
DIFF_OPT_SET(options, FIND_COPIES_HARDER);
3155
if ((options->rename_score = diff_scoreopt_parse(arg)) == -1)
3156
- return -1;
3156
+ return error("invalid argument to -C: %s", arg+2);
3157
options->detect_rename = DIFF_DETECT_COPY;
3158
}
3159
else if (!strcmp(arg, "--no-renames"))