When giving options how move coloring should treat white spaces, the user
expects that move coloring is actually active. If it is not active, we
can just take the default mode.

Signed-off-by: Stefan Beller <sbel...@google.com>
---
 diff.c                     | 18 +++++++++++++-----
 t/t4015-diff-whitespace.sh |  9 +++++++--
 2 files changed, 20 insertions(+), 7 deletions(-)

diff --git a/diff.c b/diff.c
index 1227a4d2a83..a10184e576e 100644
--- a/diff.c
+++ b/diff.c
@@ -4713,15 +4713,23 @@ int diff_opt_parse(struct diff_options *options,
                options->color_moved_ws_handling &= 
~XDF_IGNORE_WHITESPACE_AT_EOL;
        else if (!strcmp(arg, "--color-moved-no-ignore-space-prefix-delta"))
                options->color_moved_ws_handling &= 
~COLOR_MOVED_DELTA_WHITESPACES;
-       else if (!strcmp(arg, "--color-moved-ignore-all-space"))
+       else if (!strcmp(arg, "--color-moved-ignore-all-space")) {
+               if (options->color_moved == COLOR_MOVED_NO)
+                       options->color_moved = COLOR_MOVED_DEFAULT;
                options->color_moved_ws_handling |= XDF_IGNORE_WHITESPACE;
-       else if (!strcmp(arg, "--color-moved-ignore-space-change"))
+       } else if (!strcmp(arg, "--color-moved-ignore-space-change")) {
                options->color_moved_ws_handling |= 
XDF_IGNORE_WHITESPACE_CHANGE;
-       else if (!strcmp(arg, "--color-moved-ignore-space-at-eol"))
+               if (options->color_moved == COLOR_MOVED_NO)
+                       options->color_moved = COLOR_MOVED_DEFAULT;
+       } else if (!strcmp(arg, "--color-moved-ignore-space-at-eol")) {
                options->color_moved_ws_handling |= 
XDF_IGNORE_WHITESPACE_AT_EOL;
-       else if (!strcmp(arg, "--color-moved-ignore-space-prefix-delta"))
+               if (options->color_moved == COLOR_MOVED_NO)
+                       options->color_moved = COLOR_MOVED_DEFAULT;
+       } else if (!strcmp(arg, "--color-moved-ignore-space-prefix-delta")) {
                options->color_moved_ws_handling |= 
COLOR_MOVED_DELTA_WHITESPACES;
-       else if (!strcmp(arg, "--indent-heuristic"))
+               if (options->color_moved == COLOR_MOVED_NO)
+                       options->color_moved = COLOR_MOVED_DEFAULT;
+       } else if (!strcmp(arg, "--indent-heuristic"))
                DIFF_XDL_SET(options, INDENT_HEURISTIC);
        else if (!strcmp(arg, "--no-indent-heuristic"))
                DIFF_XDL_CLR(options, INDENT_HEURISTIC);
diff --git a/t/t4015-diff-whitespace.sh b/t/t4015-diff-whitespace.sh
index 37ff528822f..e1ab08d7bb4 100755
--- a/t/t4015-diff-whitespace.sh
+++ b/t/t4015-diff-whitespace.sh
@@ -1875,7 +1875,11 @@ test_expect_success 'compare whitespace delta across 
moved blocks' '
 
        git diff --color --color-moved --color-moved-ignore-space-prefix-delta |
                grep -v "index" |
-               test_decode_color >actual &&
+               test_decode_color >actual1 &&
+
+       git diff --color --color-moved-ignore-space-prefix-delta |
+               grep -v "index" |
+               test_decode_color >actual2 &&
 
        q_to_tab <<-\EOF >expected &&
                <BOLD>diff --git a/text.txt b/text.txt<RESET>
@@ -1898,7 +1902,8 @@ test_expect_success 'compare whitespace delta across 
moved blocks' '
                <BOLD;YELLOW>+<RESET><BOLD;YELLOW>not adjust<RESET>
        EOF
 
-       test_cmp expected actual
+       test_cmp expected actual1 &&
+       test_cmp expected actual2
 '
 
 test_done
-- 
2.17.0.582.gccdcbd54c44.dirty

Reply via email to