Skip to content

Commit 0824879

Browse files
peffgitster
authored andcommitted
diff: give more detailed messages for bogus diff.* config
The config callbacks for a few diff.* variables simply return -1 when we encounter an error. The message you get mentions the offending location, like: fatal: bad config variable 'diff.algorithm' in file '.git/config' at line 7 but is vague about "bad" (as it must be, since the message comes from the generic config code). Most callbacks add their own messages here, so let's do the same. E.g.: error: unknown value for config 'diff.algorithm': foo fatal: bad config variable 'diff.algorithm' in file '.git/config' at line 7 I've written the string in a way that should be reusable for translators, and matches another similar message in transport.c (there doesn't yet seem to be a popular generic message to reuse here, so hopefully this will get the ball rolling). Note that in the case of diff.algorithm, our parse_algorithm_value() helper does detect a NULL value string. But it's still worth detecting it ourselves here, since we can give a more specific error message (and which is the usual one for unexpected implicit-bool values). Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 92cecce commit 0824879

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

diff.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -445,9 +445,12 @@ int git_diff_ui_config(const char *var, const char *value,
445445
}
446446

447447
if (!strcmp(var, "diff.algorithm")) {
448+
if (!value)
449+
return config_error_nonbool(var);
448450
diff_algorithm = parse_algorithm_value(value);
449451
if (diff_algorithm < 0)
450-
return -1;
452+
return error(_("unknown value for config '%s': %s"),
453+
var, value);
451454
return 0;
452455
}
453456

@@ -486,7 +489,8 @@ int git_diff_basic_config(const char *var, const char *value,
486489
return config_error_nonbool(var);
487490
val = parse_ws_error_highlight(value);
488491
if (val < 0)
489-
return -1;
492+
return error(_("unknown value for config '%s': %s"),
493+
var, value);
490494
ws_error_highlight_default = val;
491495
return 0;
492496
}

0 commit comments

Comments
 (0)