Skip to content

Commit 932b867

Browse files
committed
Merge branch 'sb/diff-color-moved-config-option-fixup'
Minor inconsistency fix. * sb/diff-color-moved-config-option-fixup: diff: align move detection error handling with other options
2 parents 20b3bc1 + d173e79 commit 932b867

File tree

3 files changed

+36
-10
lines changed

3 files changed

+36
-10
lines changed

diff.c

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ static int parse_color_moved(const char *arg)
291291
return error(_("color moved setting must be one of 'no', 'default', 'blocks', 'zebra', 'dimmed-zebra', 'plain'"));
292292
}
293293

294-
static int parse_color_moved_ws(const char *arg)
294+
static unsigned parse_color_moved_ws(const char *arg)
295295
{
296296
int ret = 0;
297297
struct string_list l = STRING_LIST_INIT_DUP;
@@ -312,15 +312,19 @@ static int parse_color_moved_ws(const char *arg)
312312
ret |= XDF_IGNORE_WHITESPACE;
313313
else if (!strcmp(sb.buf, "allow-indentation-change"))
314314
ret |= COLOR_MOVED_WS_ALLOW_INDENTATION_CHANGE;
315-
else
316-
error(_("ignoring unknown color-moved-ws mode '%s'"), sb.buf);
315+
else {
316+
ret |= COLOR_MOVED_WS_ERROR;
317+
error(_("unknown color-moved-ws mode '%s', possible values are 'ignore-space-change', 'ignore-space-at-eol', 'ignore-all-space', 'allow-indentation-change'"), sb.buf);
318+
}
317319

318320
strbuf_release(&sb);
319321
}
320322

321323
if ((ret & COLOR_MOVED_WS_ALLOW_INDENTATION_CHANGE) &&
322-
(ret & XDF_WHITESPACE_FLAGS))
323-
die(_("color-moved-ws: allow-indentation-change cannot be combined with other white space modes"));
324+
(ret & XDF_WHITESPACE_FLAGS)) {
325+
error(_("color-moved-ws: allow-indentation-change cannot be combined with other white space modes"));
326+
ret |= COLOR_MOVED_WS_ERROR;
327+
}
324328

325329
string_list_clear(&l, 0);
326330

@@ -341,8 +345,8 @@ int git_diff_ui_config(const char *var, const char *value, void *cb)
341345
return 0;
342346
}
343347
if (!strcmp(var, "diff.colormovedws")) {
344-
int cm = parse_color_moved_ws(value);
345-
if (cm < 0)
348+
unsigned cm = parse_color_moved_ws(value);
349+
if (cm & COLOR_MOVED_WS_ERROR)
346350
return -1;
347351
diff_color_moved_ws_default = cm;
348352
return 0;
@@ -5034,10 +5038,13 @@ int diff_opt_parse(struct diff_options *options,
50345038
else if (skip_prefix(arg, "--color-moved=", &arg)) {
50355039
int cm = parse_color_moved(arg);
50365040
if (cm < 0)
5037-
die("bad --color-moved argument: %s", arg);
5041+
return error("bad --color-moved argument: %s", arg);
50385042
options->color_moved = cm;
50395043
} else if (skip_prefix(arg, "--color-moved-ws=", &arg)) {
5040-
options->color_moved_ws_handling = parse_color_moved_ws(arg);
5044+
unsigned cm = parse_color_moved_ws(arg);
5045+
if (cm & COLOR_MOVED_WS_ERROR)
5046+
return -1;
5047+
options->color_moved_ws_handling = cm;
50415048
} else if (skip_to_optional_arg_default(arg, "--color-words", &options->word_regex, NULL)) {
50425049
options->use_color = 1;
50435050
options->word_diff = DIFF_WORDS_COLOR;

diff.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,8 @@ struct diff_options {
225225

226226
/* XDF_WHITESPACE_FLAGS regarding block detection are set at 2, 3, 4 */
227227
#define COLOR_MOVED_WS_ALLOW_INDENTATION_CHANGE (1<<5)
228-
int color_moved_ws_handling;
228+
#define COLOR_MOVED_WS_ERROR (1<<0)
229+
unsigned color_moved_ws_handling;
229230

230231
struct repository *repo;
231232
};

t/t4015-diff-whitespace.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1890,6 +1890,24 @@ test_expect_success 'compare whitespace delta across moved blocks' '
18901890
test_cmp expected actual
18911891
'
18921892

1893+
test_expect_success 'bogus settings in move detection erroring out' '
1894+
test_must_fail git diff --color-moved=bogus 2>err &&
1895+
test_i18ngrep "must be one of" err &&
1896+
test_i18ngrep bogus err &&
1897+
1898+
test_must_fail git -c diff.colormoved=bogus diff 2>err &&
1899+
test_i18ngrep "must be one of" err &&
1900+
test_i18ngrep "from command-line config" err &&
1901+
1902+
test_must_fail git diff --color-moved-ws=bogus 2>err &&
1903+
test_i18ngrep "possible values" err &&
1904+
test_i18ngrep bogus err &&
1905+
1906+
test_must_fail git -c diff.colormovedws=bogus diff 2>err &&
1907+
test_i18ngrep "possible values" err &&
1908+
test_i18ngrep "from command-line config" err
1909+
'
1910+
18931911
test_expect_success 'compare whitespace delta incompatible with other space options' '
18941912
test_must_fail git diff \
18951913
--color-moved-ws=allow-indentation-change,ignore-all-space \

0 commit comments

Comments
 (0)