t/t5100: no need to use 'echo' command substitutions for globbing
[gitweb.git] / t / t4015-diff-whitespace.sh
index 0bfc7ffac8ba123bd210792b34bbba4babfcdc8e..2434157aa7632551e8f7b9db59b34405f8fbefa3 100755 (executable)
@@ -810,11 +810,20 @@ test_expect_success 'setup diff colors' '
        git config color.diff.old red &&
        git config color.diff.new green &&
        git config color.diff.commit yellow &&
-       git config color.diff.whitespace "normal red" &&
+       git config color.diff.whitespace blue &&
 
-       git config core.autocrlf false &&
+       git config core.autocrlf false
+'
+
+test_expect_success 'diff that introduces a line with only tabs' '
+       git config core.whitespace blank-at-eol &&
+       git reset --hard &&
+       echo "test" >x &&
+       git commit -m "initial" x &&
+       echo "{NTN}" | tr "NT" "\n\t" >>x &&
+       git -c color.diff=always diff | test_decode_color >current &&
 
-       cat >expected <<-\EOF
+       cat >expected <<-\EOF &&
        <BOLD>diff --git a/x b/x<RESET>
        <BOLD>index 9daeafb..2874b91 100644<RESET>
        <BOLD>--- a/x<RESET>
@@ -822,18 +831,106 @@ test_expect_success 'setup diff colors' '
        <CYAN>@@ -1 +1,4 @@<RESET>
         test<RESET>
        <GREEN>+<RESET><GREEN>{<RESET>
-       <GREEN>+<RESET><BRED>   <RESET>
+       <GREEN>+<RESET><BLUE>   <RESET>
        <GREEN>+<RESET><GREEN>}<RESET>
        EOF
+
+       test_cmp expected current
 '
 
-test_expect_success 'diff that introduces a line with only tabs' '
-       git config core.whitespace blank-at-eol &&
+test_expect_success 'diff that introduces and removes ws breakages' '
        git reset --hard &&
-       echo "test" >x &&
-       git commit -m "initial" x &&
-       echo "{NTN}" | tr "NT" "\n\t" >>x &&
-       git -c color.diff=always diff | test_decode_color >current &&
+       {
+               echo "0. blank-at-eol " &&
+               echo "1. blank-at-eol "
+       } >x &&
+       git commit -a --allow-empty -m preimage &&
+       {
+               echo "0. blank-at-eol " &&
+               echo "1. still-blank-at-eol " &&
+               echo "2. and a new line "
+       } >x &&
+
+       git -c color.diff=always diff |
+       test_decode_color >current &&
+
+       cat >expected <<-\EOF &&
+       <BOLD>diff --git a/x b/x<RESET>
+       <BOLD>index d0233a2..700886e 100644<RESET>
+       <BOLD>--- a/x<RESET>
+       <BOLD>+++ b/x<RESET>
+       <CYAN>@@ -1,2 +1,3 @@<RESET>
+        0. blank-at-eol <RESET>
+       <RED>-1. blank-at-eol <RESET>
+       <GREEN>+<RESET><GREEN>1. still-blank-at-eol<RESET><BLUE> <RESET>
+       <GREEN>+<RESET><GREEN>2. and a new line<RESET><BLUE> <RESET>
+       EOF
+
+       test_cmp expected current
+'
+
+test_expect_success 'the same with --ws-error-highlight' '
+       git reset --hard &&
+       {
+               echo "0. blank-at-eol " &&
+               echo "1. blank-at-eol "
+       } >x &&
+       git commit -a --allow-empty -m preimage &&
+       {
+               echo "0. blank-at-eol " &&
+               echo "1. still-blank-at-eol " &&
+               echo "2. and a new line "
+       } >x &&
+
+       git -c color.diff=always diff --ws-error-highlight=default,old |
+       test_decode_color >current &&
+
+       cat >expected <<-\EOF &&
+       <BOLD>diff --git a/x b/x<RESET>
+       <BOLD>index d0233a2..700886e 100644<RESET>
+       <BOLD>--- a/x<RESET>
+       <BOLD>+++ b/x<RESET>
+       <CYAN>@@ -1,2 +1,3 @@<RESET>
+        0. blank-at-eol <RESET>
+       <RED>-<RESET><RED>1. blank-at-eol<RESET><BLUE> <RESET>
+       <GREEN>+<RESET><GREEN>1. still-blank-at-eol<RESET><BLUE> <RESET>
+       <GREEN>+<RESET><GREEN>2. and a new line<RESET><BLUE> <RESET>
+       EOF
+
+       test_cmp expected current &&
+
+       git -c color.diff=always diff --ws-error-highlight=all |
+       test_decode_color >current &&
+
+       cat >expected <<-\EOF &&
+       <BOLD>diff --git a/x b/x<RESET>
+       <BOLD>index d0233a2..700886e 100644<RESET>
+       <BOLD>--- a/x<RESET>
+       <BOLD>+++ b/x<RESET>
+       <CYAN>@@ -1,2 +1,3 @@<RESET>
+        <RESET>0. blank-at-eol<RESET><BLUE> <RESET>
+       <RED>-<RESET><RED>1. blank-at-eol<RESET><BLUE> <RESET>
+       <GREEN>+<RESET><GREEN>1. still-blank-at-eol<RESET><BLUE> <RESET>
+       <GREEN>+<RESET><GREEN>2. and a new line<RESET><BLUE> <RESET>
+       EOF
+
+       test_cmp expected current &&
+
+       git -c color.diff=always diff --ws-error-highlight=none |
+       test_decode_color >current &&
+
+       cat >expected <<-\EOF &&
+       <BOLD>diff --git a/x b/x<RESET>
+       <BOLD>index d0233a2..700886e 100644<RESET>
+       <BOLD>--- a/x<RESET>
+       <BOLD>+++ b/x<RESET>
+       <CYAN>@@ -1,2 +1,3 @@<RESET>
+        0. blank-at-eol <RESET>
+       <RED>-1. blank-at-eol <RESET>
+       <GREEN>+1. still-blank-at-eol <RESET>
+       <GREEN>+2. and a new line <RESET>
+       EOF
+
        test_cmp expected current
 '