Git fork

t6000-t9999: detect and signal failure within loop

Failures within `for` and `while` loops can go unnoticed if not detected
and signaled manually since the loop itself does not abort when a
contained command fails, nor will a failure necessarily be detected when
the loop finishes since the loop returns the exit code of the last
command it ran on the final iteration, which may not be the command
which failed. Therefore, detect and signal failures manually within
loops using the idiom `|| return 1` (or `|| exit 1` within subshells).

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Reviewed-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

authored by

Eric Sunshine and committed by
Junio C Hamano
0c51d6b4 d0fd9931

+65 -65
+1 -1
contrib/mw-to-git/t/t9365-continuing-queries.sh
··· 12 12 for i in $(test_seq 501) 13 13 do 14 14 echo "creating revision $i" && 15 - wiki_editpage foo "revision $i<br/>" true 15 + wiki_editpage foo "revision $i<br/>" true || return 1 16 16 done 17 17 ' 18 18
+1 -1
t/annotate-tests.sh
··· 161 161 GIT_AUTHOR_NAME=$i$j GIT_AUTHOR_EMAIL=$i$j@test.git \ 162 162 git commit -a -m "$i$j" && 163 163 commit=$(git rev-parse --verify HEAD) && 164 - graft="$graft$commit " 164 + graft="$graft$commit " || return 1 165 165 done 166 166 done && 167 167 printf "%s " $graft >.git/info/grafts &&
+1 -1
t/t6005-rev-list-count.sh
··· 8 8 for n in 1 2 3 4 5 ; do 9 9 echo $n > a && 10 10 git add a && 11 - git commit -m "$n" 11 + git commit -m "$n" || return 1 12 12 done 13 13 ' 14 14
+2 -2
t/t6009-rev-list-parent.sh
··· 124 124 git checkout -b root$i five && 125 125 test_commit $i && 126 126 roots="$roots root$i" || 127 - return 127 + return 1 128 128 done && 129 129 git checkout main && 130 130 test_tick && ··· 143 143 test_tick_keep=$test_tick && 144 144 for i in 1 2 3 4 5 6 7 8; do 145 145 test_tick=$test_tick_keep && 146 - test_commit t$i 146 + test_commit t$i || return 1 147 147 done && 148 148 git rev-list t1^! --not t$i >result && 149 149 test_must_be_empty result
+1 -1
t/t6101-rev-parse-parents.sh
··· 32 32 test_tick && 33 33 git commit --allow-empty -m "$i" && 34 34 commit=$(git rev-parse --verify HEAD) && 35 - printf "$commit " >>.git/info/grafts 35 + printf "$commit " >>.git/info/grafts || return 1 36 36 done 37 37 ' 38 38
+4 -4
t/t6112-rev-list-filters-objects.sh
··· 18 18 do 19 19 echo "This is file: $n" > r1/file.$n && 20 20 git -C r1 add file.$n && 21 - git -C r1 commit -m "$n" 21 + git -C r1 commit -m "$n" || return 1 22 22 done 23 23 ' 24 24 ··· 75 75 do 76 76 printf "%"$n"s" X > r2/large.$n && 77 77 git -C r2 add large.$n && 78 - git -C r2 commit -m "$n" 78 + git -C r2 commit -m "$n" || return 1 79 79 done 80 80 ' 81 81 ··· 248 248 echo "This is file: $n" > r3/$n && 249 249 git -C r3 add $n && 250 250 echo "This is file: dir1/$n" > r3/dir1/$n && 251 - git -C r3 add dir1/$n 251 + git -C r3 add dir1/$n || return 1 252 252 done && 253 253 git -C r3 commit -m "sparse" && 254 254 echo dir1/ >pattern1 && ··· 672 672 673 673 for id in `cat expected | sed "s|..|&/|"` 674 674 do 675 - rm r1/.git/objects/$id 675 + rm r1/.git/objects/$id || return 1 676 676 done && 677 677 678 678 git -C r1 rev-list --quiet --missing=print --objects HEAD >revs &&
+3 -3
t/t6120-describe.sh
··· 262 262 >expect.unsorted && 263 263 for rev in $(git rev-list --all) 264 264 do 265 - git name-rev $rev >>expect.unsorted 265 + git name-rev $rev >>expect.unsorted || return 1 266 266 done && 267 267 sort <expect.unsorted >expect && 268 268 git name-rev --all >actual.unsorted && ··· 275 275 for rev in $(git rev-list --all) 276 276 do 277 277 name=$(git name-rev --name-only $rev) && 278 - echo "$rev ($name)" >>expect.unsorted 278 + echo "$rev ($name)" >>expect.unsorted || return 1 279 279 done && 280 280 sort <expect.unsorted >expect && 281 281 git rev-list --all | git name-rev --stdin >actual.unsorted && ··· 395 395 then 396 396 echo "from refs/heads/main^0" 397 397 fi && 398 - i=$(($i + 1)) 398 + i=$(($i + 1)) || return 1 399 399 done | git fast-import && 400 400 git checkout main && 401 401 git tag far-far-away HEAD^ &&
+1 -1
t/t6132-pathspec-exclude.sh
··· 11 11 fi && 12 12 : >$p && 13 13 git add $p && 14 - git commit -m $p 14 + git commit -m $p || return 1 15 15 done && 16 16 git log --oneline --format=%s >actual && 17 17 cat <<EOF >expect &&
+1 -1
t/t6200-fmt-merge-msg.sh
··· 519 519 while test $i -gt 9 520 520 do 521 521 echo " $i" && 522 - i=$(($i-1)) 522 + i=$(($i-1)) || return 1 523 523 done && 524 524 echo " ..." 525 525 } >expected &&
+1 -1
t/t6300-for-each-ref.sh
··· 1338 1338 echo "${pair#*=}" >expect && 1339 1339 git for-each-ref --format="${pair%=*}" \ 1340 1340 refs/heads/main >actual && 1341 - test_cmp expect actual 1341 + test_cmp expect actual || exit 1 1342 1342 done && 1343 1343 git branch push-simple && 1344 1344 git config branch.push-simple.pushRemote from &&
+4 -4
t/t6412-merge-large-rename.sh
··· 37 37 test_might_fail git branch -D test$n && 38 38 git reset --hard initial && 39 39 for i in $(count $n); do 40 - make_text $i initial initial >$i 40 + make_text $i initial initial >$i || return 1 41 41 done && 42 42 git add . && 43 43 git commit -m add=$n && 44 44 for i in $(count $n); do 45 - make_text $i changed initial >$i 45 + make_text $i changed initial >$i || return 1 46 46 done && 47 47 git commit -a -m change=$n && 48 48 git checkout -b test$n HEAD^ && 49 49 for i in $(count $n); do 50 50 git rm $i && 51 - make_text $i initial changed >$i.moved 51 + make_text $i initial changed >$i.moved || return 1 52 52 done && 53 53 git add . && 54 54 git commit -m change+rename=$n && ··· 79 79 80 80 git reset --hard initial && 81 81 for i in $(count 200); do 82 - make_text foo bar baz >$i 82 + make_text foo bar baz >$i || return 1 83 83 done && 84 84 git add . && 85 85 git commit -m create-files &&
+1 -1
t/t6430-merge-recursive.sh
··· 706 706 # more trees than static slots used by oid_to_hex() 707 707 for commit in $c0 $c2 $c4 $c5 $c6 $c7 708 708 do 709 - git rev-parse "$commit^{tree}" 709 + git rev-parse "$commit^{tree}" || return 1 710 710 done >trees && 711 711 712 712 # ignore the return code; it only fails because the input is weird...
+2 -2
t/t6600-test-reach.sh
··· 32 32 do 33 33 test_commit "1-$i" && 34 34 git branch -f commit-1-$i && 35 - git tag -a -m "1-$i" tag-1-$i commit-1-$i 35 + git tag -a -m "1-$i" tag-1-$i commit-1-$i || return 1 36 36 done && 37 37 for j in $(test_seq 1 9) 38 38 do ··· 46 46 do 47 47 git merge commit-$j-$i -m "$x-$i" && 48 48 git branch -f commit-$x-$i && 49 - git tag -a -m "$x-$i" tag-$x-$i commit-$x-$i 49 + git tag -a -m "$x-$i" tag-$x-$i commit-$x-$i || return 1 50 50 done 51 51 done && 52 52 git commit-graph write --reachable &&
+1 -1
t/t7004-tag.sh
··· 1981 1981 then 1982 1982 echo "from refs/heads/main^0" 1983 1983 fi && 1984 - i=$(($i + 1)) 1984 + i=$(($i + 1)) || return 1 1985 1985 done | git fast-import && 1986 1986 git checkout main && 1987 1987 git tag far-far-away HEAD^ &&
+1 -1
t/t7505-prepare-commit-msg-hook.sh
··· 16 16 test_commit rebase-b b bb && 17 17 for i in $(test_seq 1 13) 18 18 do 19 - test_commit rebase-$i c $i 19 + test_commit rebase-$i c $i || return 1 20 20 done && 21 21 git checkout main && 22 22
+1 -1
t/t7600-merge.sh
··· 967 967 # 256 near-identical stanzas... 968 968 for i in $(test_seq 1 256); do 969 969 for j in 1 2 3 4 5; do 970 - echo $i-$j 970 + echo $i-$j || return 1 971 971 done 972 972 done >file && 973 973 git add file &&
+1 -1
t/t7602-merge-octopus-many.sh
··· 30 30 while test $i -le 30 31 31 do 32 32 refs="$refs c$i" && 33 - i=$(expr $i + 1) 33 + i=$(expr $i + 1) || return 1 34 34 done && 35 35 git merge $refs && 36 36 test "$(git rev-parse c1)" != "$(git rev-parse HEAD)" &&
+2 -2
t/t7603-merge-reduce-heads.sh
··· 95 95 echo $i > $i.c && 96 96 git add $i.c && 97 97 git commit -m $i && 98 - git tag $i 98 + git tag $i || return 1 99 99 done && 100 100 git reset --hard A && 101 101 for i in F G H I ··· 103 103 echo $i > $i.c && 104 104 git add $i.c && 105 105 git commit -m $i && 106 - git tag $i 106 + git tag $i || return 1 107 107 done 108 108 ' 109 109
+1 -1
t/t7700-repack.sh
··· 117 117 rm alt_objects/pack/$base_name.keep 118 118 else 119 119 touch alt_objects/pack/$base_name.keep 120 - fi 120 + fi || return 1 121 121 done && 122 122 git repack -a -d && 123 123 test_no_missing_in_packs
+2 -2
t/t8014-blame-ignore-fuzzy.sh
··· 310 310 echo "$line" >>"$i" && 311 311 git add "$i" && 312 312 test_tick && 313 - GIT_AUTHOR_NAME="$line_count" git commit -m "$line_count" 313 + GIT_AUTHOR_NAME="$line_count" git commit -m "$line_count" || return 1 314 314 done <"a$i" 315 315 done && 316 316 ··· 318 318 do 319 319 # Overwrite the files with the final content. 320 320 cp b$i $i && 321 - git add $i 321 + git add $i || return 1 322 322 done && 323 323 test_tick && 324 324
+2 -2
t/t9104-git-svn-follow-parent.sh
··· 117 117 mkdir -p import/trunk/subversion/bindings/swig/perl/t && 118 118 for i in a b c ; do \ 119 119 echo $i > import/trunk/subversion/bindings/swig/perl/$i.pm && 120 - echo _$i > import/trunk/subversion/bindings/swig/perl/t/$i.t; \ 120 + echo _$i > import/trunk/subversion/bindings/swig/perl/t/$i.t || return 1 121 121 done && 122 122 echo "bad delete test" > \ 123 123 import/trunk/subversion/bindings/swig/perl/t/larger-parent && ··· 134 134 svn mv t native/t && 135 135 for i in a b c 136 136 do 137 - svn mv $i.pm native/$i.pm 137 + svn mv $i.pm native/$i.pm || return 1 138 138 done && 139 139 echo z >>native/t/c.t && 140 140 poke native/t/c.t &&
+2 -2
t/t9130-git-svn-authors-file.sh
··· 15 15 test_expect_success 'setup svnrepo' ' 16 16 for i in aa bb cc dd 17 17 do 18 - svn_cmd mkdir -m $i --username $i "$svnrepo"/$i 18 + svn_cmd mkdir -m $i --username $i "$svnrepo"/$i || return 1 19 19 done 20 20 ' 21 21 ··· 60 60 for i in bb ee cc 61 61 do 62 62 branch="aa/branches/$i" && 63 - svn_cmd mkdir -m "$branch" --username $i "$svnrepo/$branch" 63 + svn_cmd mkdir -m "$branch" --username $i "$svnrepo/$branch" || return 1 64 64 done 65 65 ' 66 66
+8 -8
t/t9134-git-svn-ignore-paths.sh
··· 27 27 test_expect_success 'clone an SVN repository with ignored www directory' ' 28 28 git svn clone --ignore-paths="^www" "$svnrepo" g && 29 29 echo test_qqq > expect && 30 - for i in g/*/*.txt; do cat $i >> expect2; done && 30 + for i in g/*/*.txt; do cat $i >> expect2 || return 1; done && 31 31 test_cmp expect expect2 32 32 ' 33 33 ··· 36 36 ( cd c && git svn fetch --ignore-paths="^www" ) && 37 37 rm expect2 && 38 38 echo test_qqq > expect && 39 - for i in c/*/*.txt; do cat $i >> expect2; done && 39 + for i in c/*/*.txt; do cat $i >> expect2 || return 1; done && 40 40 test_cmp expect expect2 41 41 ' 42 42 ··· 62 62 cd g && 63 63 git svn rebase && 64 64 printf "test_qqq\nb\n" > expect && 65 - for i in */*.txt; do cat $i >> expect2; done && 65 + for i in */*.txt; do cat $i >> expect2 || exit 1; done && 66 66 test_cmp expect2 expect && 67 67 rm expect expect2 68 68 ) ··· 73 73 cd c && 74 74 git svn rebase --ignore-paths="^www" && 75 75 printf "test_qqq\nb\n" > expect && 76 - for i in */*.txt; do cat $i >> expect2; done && 76 + for i in */*.txt; do cat $i >> expect2 || exit 1; done && 77 77 test_cmp expect2 expect && 78 78 rm expect expect2 79 79 ) ··· 94 94 cd g && 95 95 git svn rebase && 96 96 printf "test_qqq\nb\n" > expect && 97 - for i in */*.txt; do cat $i >> expect2; done && 97 + for i in */*.txt; do cat $i >> expect2 || exit 1; done && 98 98 test_cmp expect2 expect && 99 99 rm expect expect2 100 100 ) ··· 105 105 cd c && 106 106 git svn rebase --ignore-paths="^www" && 107 107 printf "test_qqq\nb\n" > expect && 108 - for i in */*.txt; do cat $i >> expect2; done && 108 + for i in */*.txt; do cat $i >> expect2 || exit 1; done && 109 109 test_cmp expect2 expect && 110 110 rm expect expect2 111 111 ) ··· 127 127 cd g && 128 128 git svn rebase && 129 129 printf "test_qqq\nb\nygg\n" > expect && 130 - for i in */*.txt; do cat $i >> expect2; done && 130 + for i in */*.txt; do cat $i >> expect2 || exit 1; done && 131 131 test_cmp expect2 expect && 132 132 rm expect expect2 133 133 ) ··· 138 138 cd c && 139 139 git svn rebase --ignore-paths="^www" && 140 140 printf "test_qqq\nb\nygg\n" > expect && 141 - for i in */*.txt; do cat $i >> expect2; done && 141 + for i in */*.txt; do cat $i >> expect2 || exit 1; done && 142 142 test_cmp expect2 expect && 143 143 rm expect expect2 144 144 )
+1 -1
t/t9138-git-svn-authors-prog.sh
··· 27 27 test_expect_success 'setup svnrepo' ' 28 28 for i in aa bb cc-sub dd-sub ee-foo ff 29 29 do 30 - svn mkdir -m $i --username $i "$svnrepo"/$i 30 + svn mkdir -m $i --username $i "$svnrepo"/$i || return 1 31 31 done 32 32 ' 33 33
+2 -2
t/t9146-git-svn-empty-dirs.sh
··· 8 8 test_expect_success 'initialize repo' ' 9 9 for i in a b c d d/e d/e/f "weird file name" 10 10 do 11 - svn_cmd mkdir -m "mkdir $i" "$svnrepo"/"$i" 11 + svn_cmd mkdir -m "mkdir $i" "$svnrepo"/"$i" || return 1 12 12 done 13 13 ' 14 14 ··· 102 102 test_expect_success 'initialize trunk' ' 103 103 for i in trunk trunk/a trunk/"weird file name" 104 104 do 105 - svn_cmd mkdir -m "mkdir $i" "$svnrepo"/"$i" 105 + svn_cmd mkdir -m "mkdir $i" "$svnrepo"/"$i" || return 1 106 106 done 107 107 ' 108 108
+8 -8
t/t9147-git-svn-include-paths.sh
··· 28 28 test_expect_success 'clone an SVN repository with filter to include qqq directory' ' 29 29 git svn clone --include-paths="qqq" "$svnrepo" g && 30 30 echo test_qqq > expect && 31 - for i in g/*/*.txt; do cat $i >> expect2; done && 31 + for i in g/*/*.txt; do cat $i >> expect2 || return 1; done && 32 32 test_cmp expect expect2 33 33 ' 34 34 ··· 38 38 ( cd c && git svn fetch --include-paths="qqq" ) && 39 39 rm expect2 && 40 40 echo test_qqq > expect && 41 - for i in c/*/*.txt; do cat $i >> expect2; done && 41 + for i in c/*/*.txt; do cat $i >> expect2 || return 1; done && 42 42 test_cmp expect expect2 43 43 ' 44 44 ··· 64 64 cd g && 65 65 git svn rebase && 66 66 printf "test_qqq\nb\n" > expect && 67 - for i in */*.txt; do cat $i >> expect2; done && 67 + for i in */*.txt; do cat $i >> expect2 || exit 1; done && 68 68 test_cmp expect2 expect && 69 69 rm expect expect2 70 70 ) ··· 75 75 cd c && 76 76 git svn rebase --include-paths="qqq" && 77 77 printf "test_qqq\nb\n" > expect && 78 - for i in */*.txt; do cat $i >> expect2; done && 78 + for i in */*.txt; do cat $i >> expect2 || exit 1; done && 79 79 test_cmp expect2 expect && 80 80 rm expect expect2 81 81 ) ··· 96 96 cd g && 97 97 git svn rebase && 98 98 printf "test_qqq\nb\n" > expect && 99 - for i in */*.txt; do cat $i >> expect2; done && 99 + for i in */*.txt; do cat $i >> expect2 || exit 1; done && 100 100 test_cmp expect2 expect && 101 101 rm expect expect2 102 102 ) ··· 107 107 cd c && 108 108 git svn rebase --include-paths="qqq" && 109 109 printf "test_qqq\nb\n" > expect && 110 - for i in */*.txt; do cat $i >> expect2; done && 110 + for i in */*.txt; do cat $i >> expect2 || exit 1; done && 111 111 test_cmp expect2 expect && 112 112 rm expect expect2 113 113 ) ··· 129 129 cd g && 130 130 git svn rebase && 131 131 printf "test_qqq\nb\nygg\n" > expect && 132 - for i in */*.txt; do cat $i >> expect2; done && 132 + for i in */*.txt; do cat $i >> expect2 || exit 1; done && 133 133 test_cmp expect2 expect && 134 134 rm expect expect2 135 135 ) ··· 140 140 cd c && 141 141 git svn rebase --include-paths="qqq" && 142 142 printf "test_qqq\nb\nygg\n" > expect && 143 - for i in */*.txt; do cat $i >> expect2; done && 143 + for i in */*.txt; do cat $i >> expect2 || exit 1; done && 144 144 test_cmp expect2 expect && 145 145 rm expect expect2 146 146 )
+1 -1
t/t9152-svn-empty-dirs-after-gc.sh
··· 8 8 test_expect_success 'initialize repo' ' 9 9 for i in a b c d d/e d/e/f "weird file name" 10 10 do 11 - svn_cmd mkdir -m "mkdir $i" "$svnrepo"/"$i" 11 + svn_cmd mkdir -m "mkdir $i" "$svnrepo"/"$i" || return 1 12 12 done 13 13 ' 14 14
+1 -1
t/t9304-fast-import-marks.sh
··· 16 16 blob=$(git rev-parse HEAD:one.t) && 17 17 for i in $(test_seq 1024 16384) 18 18 do 19 - echo ":$i $blob" 19 + echo ":$i $blob" || return 1 20 20 done >>marks 21 21 ' 22 22
+2 -2
t/t9400-git-cvsserver-server.sh
··· 338 338 '(for dir in A A/B A/B/C A/D E; do 339 339 mkdir $dir && 340 340 echo "test file in $dir" >"$dir/file_in_$(echo $dir|sed -e "s#/# #g")" && 341 - git add $dir 341 + git add $dir || exit 1 342 342 done) && 343 343 git commit -q -m "deep sub directory structure" && 344 344 git push gitcvs.git >/dev/null && ··· 381 381 for i in 1 2 3 4 5 6 7 382 382 do 383 383 echo Line $i >>merge && 384 - echo Line $i >>expected 384 + echo Line $i >>expected || return 1 385 385 done && 386 386 echo Line 8 >>expected && 387 387 git add merge &&
+1 -1
t/t9800-git-p4-basic.sh
··· 171 171 cd "$git" && 172 172 git ls-files >lines && 173 173 test_line_count = 8 lines 174 - ) 174 + ) || return 1 175 175 done 176 176 ' 177 177
+3 -3
t/t9818-git-p4-block.sh
··· 92 92 for i in $(test_seq 0 10) 93 93 do 94 94 p4_add_file "included/x$i" && 95 - p4_add_file "excluded/x$i" 95 + p4_add_file "excluded/x$i" || return 1 96 96 done && 97 97 for i in $(test_seq 0 10) 98 98 do 99 - p4_add_file "excluded/y$i" 99 + p4_add_file "excluded/y$i" || return 1 100 100 done 101 101 ' 102 102 ··· 123 123 do 124 124 for i in $(test_seq 1 10) 125 125 do 126 - p4_add_file "$p/file$p$i" 126 + p4_add_file "$p/file$p$i" || return 1 127 127 done 128 128 done 129 129 '
+2 -2
t/t9902-completion.sh
··· 879 879 refs/remotes/remote/branch-in-remote 880 880 do 881 881 git update-ref $remote_ref main && 882 - test_when_finished "git update-ref -d $remote_ref" 882 + test_when_finished "git update-ref -d $remote_ref" || return 1 883 883 done && 884 884 ( 885 885 cur= && ··· 1052 1052 refs/remotes/remote/branch-in-remote 1053 1053 do 1054 1054 git update-ref $remote_ref main && 1055 - test_when_finished "git update-ref -d $remote_ref" 1055 + test_when_finished "git update-ref -d $remote_ref" || return 1 1056 1056 done && 1057 1057 ( 1058 1058 cur=mat &&