@matheusbsbs / matheus-bagliano / commits / 946d2353a3
Fork 0

t4015: stop losing return codes of git commands

Currently, there are two ways where the return codes of git commands are lost. The first way is when a command is in the upstream of a pipe. In a pipe, only the return code of the last command is used. Thus, all other commands will have their return codes masked. Rewrite pipes so that there are no git commands upstream. The other way is when a command is in a non-assignment command substitution. The return code will be lost in favour of the surrounding command's. Rewrite instances of this so that git commands are either run on their own or in an assignment-only command substitution. Signed-off-by: Denton Liu <liu.denton@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Denton Liu committed Nov 27, 2019 at 11:53 UTC 946d2353a36a6e1ce86e0bcade7ebd304d1c67a8
1 file changed +72 -47
t/t4015-diff-whitespace.sh
+72 -47
@@ -16,7 +16,8 @@ test_expect_success "Ray Lehtiniemi's example" '
16 } while (0);
17 EOF
18 git update-index --add x &&
19 - before=$(git rev-parse --short $(git hash-object x)) &&
19 + old_hash_x=$(git hash-object x) &&
20 + before=$(git rev-parse --short "$old_hash_x") &&
21
22 cat <<-\EOF >x &&
23 do
@@ -25,7 +26,8 @@ test_expect_success "Ray Lehtiniemi's example" '
26 }
27 while (0);
28 EOF
28 - after=$(git rev-parse --short $(git hash-object x)) &&
29 + new_hash_x=$(git hash-object x) &&
30 + after=$(git rev-parse --short "$new_hash_x") &&
31
32 cat <<-EOF >expect &&
33 diff --git a/x b/x
@@ -63,7 +65,8 @@ test_expect_success 'another test, without options' '
65 EOF
66
67 git update-index x &&
66 - before=$(git rev-parse --short $(git hash-object x)) &&
68 + old_hash_x=$(git hash-object x) &&
69 + before=$(git rev-parse --short "$old_hash_x") &&
70
71 tr "_" " " <<-\EOF >x &&
72 _ whitespace at beginning
@@ -73,7 +76,8 @@ test_expect_success 'another test, without options' '
76 unchanged line
77 CR at end
78 EOF
76 - after=$(git rev-parse --short $(git hash-object x)) &&
79 + new_hash_x=$(git hash-object x) &&
80 + after=$(git rev-parse --short "$new_hash_x") &&
81
82 tr "Q_" "\015 " <<-EOF >expect &&
83 diff --git a/x b/x
@@ -526,13 +530,15 @@ test_expect_success 'ignore-blank-lines: mix changes and blank lines' '
530 test_expect_success 'check mixed spaces and tabs in indent' '
531 # This is indented with SP HT SP.
532 echo " foo();" >x &&
529 - git diff --check | grep "space before tab in indent"
533 + test_must_fail git diff --check >check &&
534 + grep "space before tab in indent" check
535 '
536
537 test_expect_success 'check mixed tabs and spaces in indent' '
538 # This is indented with HT SP HT.
539 echo " foo();" >x &&
535 - git diff --check | grep "space before tab in indent"
540 + test_must_fail git diff --check >check &&
541 + grep "space before tab in indent" check
542 '
543
544 test_expect_success 'check with no whitespace errors' '
@@ -753,20 +759,23 @@ test_expect_success 'check tab-in-indent excluded from wildcard whitespace attri
759 test_expect_success 'line numbers in --check output are correct' '
760 echo "" >x &&
761 echo "foo(); " >>x &&
756 - git diff --check | grep "x:2:"
762 + test_must_fail git diff --check >check &&
763 + grep "x:2:" check
764 '
765
766 test_expect_success 'checkdiff detects new trailing blank lines (1)' '
767 echo "foo();" >x &&
768 echo "" >>x &&
762 - git diff --check | grep "new blank line"
769 + test_must_fail git diff --check >check &&
770 + grep "new blank line" check
771 '
772
773 test_expect_success 'checkdiff detects new trailing blank lines (2)' '
774 { echo a; echo b; echo; echo; } >x &&
775 git add x &&
776 { echo a; echo; echo; echo; echo; } >x &&
769 - git diff --check | grep "new blank line"
777 + test_must_fail git diff --check >check &&
778 + grep "new blank line" check
779 '
780
781 test_expect_success 'checkdiff allows new blank lines' '
@@ -794,14 +803,16 @@ test_expect_success 'whitespace-only changes reported across renames' '
803 git reset --hard &&
804 for i in 1 2 3 4 5 6 7 8 9; do echo "$i$i$i$i$i$i"; done >x &&
805 git add x &&
797 - before=$(git rev-parse --short $(git hash-object x)) &&
806 + hash_x=$(git hash-object x) &&
807 + before=$(git rev-parse --short "$hash_x") &&
808 git commit -m "base" &&
809 sed -e "5s/^/ /" x >z &&
810 git rm x &&
811 git add z &&
802 - after=$(git rev-parse --short $(git hash-object z)) &&
803 - git diff -w -M --cached |
804 - sed -e "/^similarity index /s/[0-9][0-9]*/NUM/" >actual &&
812 + hash_z=$(git hash-object z) &&
813 + after=$(git rev-parse --short "$hash_z") &&
814 + git diff -w -M --cached >actual.raw &&
815 + sed -e "/^similarity index /s/[0-9][0-9]*/NUM/" actual.raw >actual &&
816 cat <<-EOF >expect &&
817 diff --git a/x b/z
818 similarity index NUM%
@@ -840,7 +851,8 @@ test_expect_success 'combined diff with autocrlf conversion' '
851 git config core.autocrlf true &&
852 test_must_fail git merge master &&
853
843 - git diff | sed -e "1,/^@@@/d" >actual &&
854 + git diff >actual.raw &&
855 + sed -e "1,/^@@@/d" actual.raw >actual &&
856 ! grep "^-" actual
857
858 '
@@ -864,11 +876,14 @@ test_expect_success 'diff that introduces a line with only tabs' '
876 git config core.whitespace blank-at-eol &&
877 git reset --hard &&
878 echo "test" >x &&
867 - before=$(git rev-parse --short $(git hash-object x)) &&
879 + old_hash_x=$(git hash-object x) &&
880 + before=$(git rev-parse --short "$old_hash_x") &&
881 git commit -m "initial" x &&
882 echo "{NTN}" | tr "NT" "\n\t" >>x &&
870 - after=$(git rev-parse --short $(git hash-object x)) &&
871 - git diff --color | test_decode_color >current &&
883 + new_hash_x=$(git hash-object x) &&
884 + after=$(git rev-parse --short "$new_hash_x") &&
885 + git diff --color >current.raw &&
886 + test_decode_color <current.raw >current &&
887
888 cat >expected <<-EOF &&
889 <BOLD>diff --git a/x b/x<RESET>
@@ -891,17 +906,19 @@ test_expect_success 'diff that introduces and removes ws breakages' '
906 echo "0. blank-at-eol " &&
907 echo "1. blank-at-eol "
908 } >x &&
894 - before=$(git rev-parse --short $(git hash-object x)) &&
909 + old_hash_x=$(git hash-object x) &&
910 + before=$(git rev-parse --short "$old_hash_x") &&
911 git commit -a --allow-empty -m preimage &&
912 {
913 echo "0. blank-at-eol " &&
914 echo "1. still-blank-at-eol " &&
915 echo "2. and a new line "
916 } >x &&
901 - after=$(git rev-parse --short $(git hash-object x)) &&
917 + new_hash_x=$(git hash-object x) &&
918 + after=$(git rev-parse --short "$new_hash_x") &&
919
903 - git diff --color |
904 - test_decode_color >current &&
920 + git diff --color >current.raw &&
921 + test_decode_color <current.raw >current &&
922
923 cat >expected <<-EOF &&
924 <BOLD>diff --git a/x b/x<RESET>
@@ -925,14 +942,16 @@ test_expect_success 'ws-error-highlight test setup' '
942 echo "0. blank-at-eol " &&
943 echo "1. blank-at-eol "
944 } >x &&
928 - before=$(git rev-parse --short $(git hash-object x)) &&
945 + old_hash_x=$(git hash-object x) &&
946 + before=$(git rev-parse --short "$old_hash_x") &&
947 git commit -a --allow-empty -m preimage &&
948 {
949 echo "0. blank-at-eol " &&
950 echo "1. still-blank-at-eol " &&
951 echo "2. and a new line "
952 } >x &&
935 - after=$(git rev-parse --short $(git hash-object x)) &&
953 + new_hash_x=$(git hash-object x) &&
954 + after=$(git rev-parse --short "$new_hash_x") &&
955
956 cat >expect.default-old <<-EOF &&
957 <BOLD>diff --git a/x b/x<RESET>
@@ -974,32 +993,32 @@ test_expect_success 'ws-error-highlight test setup' '
993
994 test_expect_success 'test --ws-error-highlight option' '
995
977 - git diff --color --ws-error-highlight=default,old |
978 - test_decode_color >current &&
996 + git diff --color --ws-error-highlight=default,old >current.raw &&
997 + test_decode_color <current.raw >current &&
998 test_cmp expect.default-old current &&
999
981 - git diff --color --ws-error-highlight=all |
982 - test_decode_color >current &&
1000 + git diff --color --ws-error-highlight=all >current.raw &&
1001 + test_decode_color <current.raw >current &&
1002 test_cmp expect.all current &&
1003
985 - git diff --color --ws-error-highlight=none |
986 - test_decode_color >current &&
1004 + git diff --color --ws-error-highlight=none >current.raw &&
1005 + test_decode_color <current.raw >current &&
1006 test_cmp expect.none current
1007
1008 '
1009
1010 test_expect_success 'test diff.wsErrorHighlight config' '
1011
993 - git -c diff.wsErrorHighlight=default,old diff --color |
994 - test_decode_color >current &&
1012 + git -c diff.wsErrorHighlight=default,old diff --color >current.raw &&
1013 + test_decode_color <current.raw >current &&
1014 test_cmp expect.default-old current &&
1015
997 - git -c diff.wsErrorHighlight=all diff --color |
998 - test_decode_color >current &&
1016 + git -c diff.wsErrorHighlight=all diff --color >current.raw &&
1017 + test_decode_color <current.raw >current &&
1018 test_cmp expect.all current &&
1019
1001 - git -c diff.wsErrorHighlight=none diff --color |
1002 - test_decode_color >current &&
1020 + git -c diff.wsErrorHighlight=none diff --color >current.raw &&
1021 + test_decode_color <current.raw >current &&
1022 test_cmp expect.none current
1023
1024 '
@@ -1007,18 +1026,18 @@ test_expect_success 'test diff.wsErrorHighlight config' '
1026 test_expect_success 'option overrides diff.wsErrorHighlight' '
1027
1028 git -c diff.wsErrorHighlight=none \
1010 - diff --color --ws-error-highlight=default,old |
1011 - test_decode_color >current &&
1029 + diff --color --ws-error-highlight=default,old >current.raw &&
1030 + test_decode_color <current.raw >current &&
1031 test_cmp expect.default-old current &&
1032
1033 git -c diff.wsErrorHighlight=default \
1015 - diff --color --ws-error-highlight=all |
1016 - test_decode_color >current &&
1034 + diff --color --ws-error-highlight=all >current.raw &&
1035 + test_decode_color <current.raw >current &&
1036 test_cmp expect.all current &&
1037
1038 git -c diff.wsErrorHighlight=all \
1020 - diff --color --ws-error-highlight=none |
1021 - test_decode_color >current &&
1039 + diff --color --ws-error-highlight=none >current.raw &&
1040 + test_decode_color <current.raw >current &&
1041 test_cmp expect.none current
1042
1043 '
@@ -1038,7 +1057,8 @@ test_expect_success 'detect moved code, complete file' '
1057 git mv test.c main.c &&
1058 test_config color.diff.oldMoved "normal red" &&
1059 test_config color.diff.newMoved "normal green" &&
1041 - git diff HEAD --color-moved=zebra --color --no-renames | test_decode_color >actual &&
1060 + git diff HEAD --color-moved=zebra --color --no-renames >actual.raw &&
1061 + test_decode_color <actual.raw >actual &&
1062 cat >expected <<-EOF &&
1063 <BOLD>diff --git a/main.c b/main.c<RESET>
1064 <BOLD>new file mode 100644<RESET>
@@ -1141,9 +1161,12 @@ test_expect_success 'detect malicious moved code, inside file' '
1161 bar();
1162 }
1163 EOF
1144 - after_main=$(git rev-parse --short $(git hash-object main.c)) &&
1145 - after_test=$(git rev-parse --short $(git hash-object test.c)) &&
1146 - git diff HEAD --no-renames --color-moved=zebra --color | test_decode_color >actual &&
1164 + hash_main=$(git hash-object main.c) &&
1165 + after_main=$(git rev-parse --short "$hash_main") &&
1166 + hash_test=$(git hash-object test.c) &&
1167 + after_test=$(git rev-parse --short "$hash_test") &&
1168 + git diff HEAD --no-renames --color-moved=zebra --color >actual.raw &&
1169 + test_decode_color <actual.raw >actual &&
1170 cat <<-EOF >expected &&
1171 <BOLD>diff --git a/main.c b/main.c<RESET>
1172 <BOLD>index $before_main..$after_main 100644<RESET>
@@ -1192,7 +1215,8 @@ test_expect_success 'plain moved code, inside file' '
1215 test_config color.diff.oldMovedAlternative "blue" &&
1216 test_config color.diff.newMovedAlternative "yellow" &&
1217 # needs previous test as setup
1195 - git diff HEAD --no-renames --color-moved=plain --color | test_decode_color >actual &&
1218 + git diff HEAD --no-renames --color-moved=plain --color >actual.raw &&
1219 + test_decode_color <actual.raw >actual &&
1220 cat <<-EOF >expected &&
1221 <BOLD>diff --git a/main.c b/main.c<RESET>
1222 <BOLD>index $before_main..$after_main 100644<RESET>
@@ -1771,7 +1795,8 @@ test_expect_success 'move detection with submodules' '
1795 ! grep BRED decoded_actual &&
1796
1797 # nor did we mess with it another way
1774 - git diff --submodule=diff --color | test_decode_color >expect &&
1798 + git diff --submodule=diff --color >expect.raw &&
1799 + test_decode_color <expect.raw >expect &&
1800 test_cmp expect decoded_actual &&
1801 rm -rf bananas &&
1802 git submodule deinit bananas