Merge branch 'hn/config-in-code-comment'
[gitweb.git] / t / t4015-diff-whitespace.sh
index e54529f026dc4b64adefe8991025d8110c19acc2..e2dc1895ba3942954dfaba3c0af914494d2aa317 100755 (executable)
@@ -1305,7 +1305,7 @@ test_expect_success 'detect blocks of moved code' '
 
 '
 
-test_expect_success 'detect permutations inside moved code -- dimmed_zebra' '
+test_expect_success 'detect permutations inside moved code -- dimmed-zebra' '
        # reuse setup from test before!
        test_config color.diff.oldMoved "magenta" &&
        test_config color.diff.newMoved "cyan" &&
@@ -1315,7 +1315,7 @@ test_expect_success 'detect permutations inside moved code -- dimmed_zebra' '
        test_config color.diff.newMovedDimmed "normal cyan" &&
        test_config color.diff.oldMovedAlternativeDimmed "normal blue" &&
        test_config color.diff.newMovedAlternativeDimmed "normal yellow" &&
-       git diff HEAD --no-renames --color-moved=dimmed_zebra --color >actual.raw &&
+       git diff HEAD --no-renames --color-moved=dimmed-zebra --color >actual.raw &&
        grep -v "index" actual.raw | test_decode_color >actual &&
        cat <<-\EOF >expected &&
        <BOLD>diff --git a/lines.txt b/lines.txt<RESET>
@@ -1460,7 +1460,8 @@ test_expect_success 'move detection ignoring whitespace ' '
        EOF
        test_cmp expected actual &&
 
-       git diff HEAD --no-renames -w --color-moved --color >actual.raw &&
+       git diff HEAD --no-renames --color-moved --color \
+               --color-moved-ws=ignore-all-space >actual.raw &&
        grep -v "index" actual.raw | test_decode_color >actual &&
        cat <<-\EOF >expected &&
        <BOLD>diff --git a/lines.txt b/lines.txt<RESET>
@@ -1522,7 +1523,8 @@ test_expect_success 'move detection ignoring whitespace changes' '
        EOF
        test_cmp expected actual &&
 
-       git diff HEAD --no-renames -b --color-moved --color >actual.raw &&
+       git diff HEAD --no-renames --color-moved --color \
+               --color-moved-ws=ignore-space-change >actual.raw &&
        grep -v "index" actual.raw | test_decode_color >actual &&
        cat <<-\EOF >expected &&
        <BOLD>diff --git a/lines.txt b/lines.txt<RESET>
@@ -1587,7 +1589,8 @@ test_expect_success 'move detection ignoring whitespace at eol' '
        EOF
        test_cmp expected actual &&
 
-       git diff HEAD --no-renames --ignore-space-at-eol --color-moved --color >actual.raw &&
+       git diff HEAD --no-renames --color-moved --color \
+               --color-moved-ws=ignore-space-at-eol >actual.raw &&
        grep -v "index" actual.raw | test_decode_color >actual &&
        cat <<-\EOF >expected &&
        <BOLD>diff --git a/lines.txt b/lines.txt<RESET>
@@ -1757,7 +1760,146 @@ test_expect_success 'move detection with submodules' '
 
        # nor did we mess with it another way
        git diff --submodule=diff --color | test_decode_color >expect &&
-       test_cmp expect decoded_actual
+       test_cmp expect decoded_actual &&
+       rm -rf bananas &&
+       git submodule deinit bananas
+'
+
+test_expect_success 'only move detection ignores white spaces' '
+       git reset --hard &&
+       q_to_tab <<-\EOF >text.txt &&
+               a long line to exceed per-line minimum
+               another long line to exceed per-line minimum
+               original file
+       EOF
+       git add text.txt &&
+       git commit -m "add text" &&
+       q_to_tab <<-\EOF >text.txt &&
+               Qa long line to exceed per-line minimum
+               Qanother long line to exceed per-line minimum
+               new file
+       EOF
+
+       # Make sure we get a different diff using -w
+       git diff --color --color-moved -w >actual.raw &&
+       grep -v "index" actual.raw | test_decode_color >actual &&
+       q_to_tab <<-\EOF >expected &&
+       <BOLD>diff --git a/text.txt b/text.txt<RESET>
+       <BOLD>--- a/text.txt<RESET>
+       <BOLD>+++ b/text.txt<RESET>
+       <CYAN>@@ -1,3 +1,3 @@<RESET>
+        Qa long line to exceed per-line minimum<RESET>
+        Qanother long line to exceed per-line minimum<RESET>
+       <RED>-original file<RESET>
+       <GREEN>+<RESET><GREEN>new file<RESET>
+       EOF
+       test_cmp expected actual &&
+
+       # And now ignoring white space only in the move detection
+       git diff --color --color-moved \
+               --color-moved-ws=ignore-all-space,ignore-space-change,ignore-space-at-eol >actual.raw &&
+       grep -v "index" actual.raw | test_decode_color >actual &&
+       q_to_tab <<-\EOF >expected &&
+       <BOLD>diff --git a/text.txt b/text.txt<RESET>
+       <BOLD>--- a/text.txt<RESET>
+       <BOLD>+++ b/text.txt<RESET>
+       <CYAN>@@ -1,3 +1,3 @@<RESET>
+       <BOLD;MAGENTA>-a long line to exceed per-line minimum<RESET>
+       <BOLD;MAGENTA>-another long line to exceed per-line minimum<RESET>
+       <RED>-original file<RESET>
+       <BOLD;YELLOW>+<RESET>Q<BOLD;YELLOW>a long line to exceed per-line minimum<RESET>
+       <BOLD;YELLOW>+<RESET>Q<BOLD;YELLOW>another long line to exceed per-line minimum<RESET>
+       <GREEN>+<RESET><GREEN>new file<RESET>
+       EOF
+       test_cmp expected actual
+'
+
+test_expect_success 'compare whitespace delta across moved blocks' '
+
+       git reset --hard &&
+       q_to_tab <<-\EOF >text.txt &&
+       QIndented
+       QText across
+       Qsome lines
+       QBut! <- this stands out
+       QAdjusting with
+       QQdifferent starting
+       Qwhite spaces
+       QAnother outlier
+       QQQIndented
+       QQQText across
+       QQQfive lines
+       QQQthat has similar lines
+       QQQto previous blocks, but with different indent
+       QQQYetQAnotherQoutlierQ
+       EOF
+
+       git add text.txt &&
+       git commit -m "add text.txt" &&
+
+       q_to_tab <<-\EOF >text.txt &&
+       QQIndented
+       QQText across
+       QQsome lines
+       QQQBut! <- this stands out
+       Adjusting with
+       Qdifferent starting
+       white spaces
+       AnotherQoutlier
+       QQIndented
+       QQText across
+       QQfive lines
+       QQthat has similar lines
+       QQto previous blocks, but with different indent
+       QQYetQAnotherQoutlier
+       EOF
+
+       git diff --color --color-moved --color-moved-ws=allow-indentation-change >actual.raw &&
+       grep -v "index" actual.raw | test_decode_color >actual &&
+
+       q_to_tab <<-\EOF >expected &&
+               <BOLD>diff --git a/text.txt b/text.txt<RESET>
+               <BOLD>--- a/text.txt<RESET>
+               <BOLD>+++ b/text.txt<RESET>
+               <CYAN>@@ -1,14 +1,14 @@<RESET>
+               <BOLD;MAGENTA>-QIndented<RESET>
+               <BOLD;MAGENTA>-QText across<RESET>
+               <BOLD;MAGENTA>-Qsome lines<RESET>
+               <RED>-QBut! <- this stands out<RESET>
+               <BOLD;MAGENTA>-QAdjusting with<RESET>
+               <BOLD;MAGENTA>-QQdifferent starting<RESET>
+               <BOLD;MAGENTA>-Qwhite spaces<RESET>
+               <RED>-QAnother outlier<RESET>
+               <BOLD;MAGENTA>-QQQIndented<RESET>
+               <BOLD;MAGENTA>-QQQText across<RESET>
+               <BOLD;MAGENTA>-QQQfive lines<RESET>
+               <BOLD;MAGENTA>-QQQthat has similar lines<RESET>
+               <BOLD;MAGENTA>-QQQto previous blocks, but with different indent<RESET>
+               <RED>-QQQYetQAnotherQoutlierQ<RESET>
+               <BOLD;CYAN>+<RESET>QQ<BOLD;CYAN>Indented<RESET>
+               <BOLD;CYAN>+<RESET>QQ<BOLD;CYAN>Text across<RESET>
+               <BOLD;CYAN>+<RESET>QQ<BOLD;CYAN>some lines<RESET>
+               <GREEN>+<RESET>QQQ<GREEN>But! <- this stands out<RESET>
+               <BOLD;CYAN>+<RESET><BOLD;CYAN>Adjusting with<RESET>
+               <BOLD;CYAN>+<RESET>Q<BOLD;CYAN>different starting<RESET>
+               <BOLD;CYAN>+<RESET><BOLD;CYAN>white spaces<RESET>
+               <GREEN>+<RESET><GREEN>AnotherQoutlier<RESET>
+               <BOLD;CYAN>+<RESET>QQ<BOLD;CYAN>Indented<RESET>
+               <BOLD;CYAN>+<RESET>QQ<BOLD;CYAN>Text across<RESET>
+               <BOLD;CYAN>+<RESET>QQ<BOLD;CYAN>five lines<RESET>
+               <BOLD;CYAN>+<RESET>QQ<BOLD;CYAN>that has similar lines<RESET>
+               <BOLD;CYAN>+<RESET>QQ<BOLD;CYAN>to previous blocks, but with different indent<RESET>
+               <GREEN>+<RESET>QQ<GREEN>YetQAnotherQoutlier<RESET>
+       EOF
+
+       test_cmp expected actual
+'
+
+test_expect_success 'compare whitespace delta incompatible with other space options' '
+       test_must_fail git diff \
+               --color-moved-ws=allow-indentation-change,ignore-all-space \
+               2>err &&
+       test_i18ngrep allow-indentation-change err
 '
 
 test_done