static enum git_colorbool diff_use_color_default = GIT_COLOR_UNKNOWN;
static int diff_color_moved_default;
static int diff_color_moved_ws_default;
-static int diff_context_default = 3;
+static unsigned int diff_context_default = 3;
static unsigned int diff_interhunk_context_default;
static char *diff_word_regex_cfg;
static struct external_diff external_diff_cfg;
return 0;
}
if (!strcmp(var, "diff.context")) {
- diff_context_default = git_config_int(var, value, ctx->kvi);
- if (diff_context_default < 0)
+ int val = git_config_int(var, value, ctx->kvi);
+ if (val < 0)
return -1;
+ diff_context_default = val;
return 0;
}
if (!strcmp(var, "diff.interhunkcontext")) {
BUG_ON_OPT_NEG(unset);
if (arg) {
- options->context = strtol(arg, &s, 10);
+ long val = strtol(arg, &s, 10);
if (*s)
return error(_("%s expects a numerical value"), "--unified");
+ if (val < 0)
+ return error(_("%s expects a non-negative integer"), "--unified");
+ options->context = val;
}
enable_patch_output(&options->output_format);
test_grep "bad config variable" output
'
+test_expect_success '-U-1 is rejected' '
+ test_must_fail git diff -U-1 2>err &&
+ test_grep "expects a non-negative integer" err
+'
+
test_expect_success '-U0 is valid, so is diff.context=0' '
test_config diff.context 0 &&
git diff >output &&