t5000-t5999: 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>
Eric Sunshine committed
Dec 9, 2021 at 00:11 UTC
d0fd993137cf41be66b54628f124b6651eea0bd2
20 files changed
+50
-50
t/t5000-tar-tree.sh
+2
-2
@@ -77,7 +77,7 @@ check_tar() {
77
path=$(get_pax_header $header path) &&
78
if test -n "$path"
79
then
80
- mv "$data" "$path"
80
+ mv "$data" "$path" || exit 1
81
fi
82
fi
83
done
@@ -133,7 +133,7 @@ test_expect_success 'populate workdir' '
133
for depth in 1 2 3 4 5
134
do
135
mkdir $p &&
136
- cd $p
136
+ cd $p || exit 1
137
done &&
138
echo text >file_with_long_path
139
) &&
t/t5003-archive-zip.sh
+1
-1
@@ -106,7 +106,7 @@ test_expect_success \
106
printf "A\$Format:%s\$O" "$SUBSTFORMAT" >a/substfile1 &&
107
printf "A not substituted O" >a/substfile2 &&
108
(p=long_path_to_a_file && cd a &&
109
- for depth in 1 2 3 4 5; do mkdir $p && cd $p; done &&
109
+ for depth in 1 2 3 4 5; do mkdir $p && cd $p || exit 1; done &&
110
echo text >file_with_long_path)
111
'
112
t/t5004-archive-corner-cases.sh
+3
-3
@@ -131,7 +131,7 @@ test_expect_success ZIPINFO 'zip archive with many entries' '
131
do
132
for b in 0 1 2 3 4 5 6 7 8 9 a b c d e f
133
do
134
- : >00/$a$b
134
+ : >00/$a$b || return 1
135
done
136
done &&
137
git add 00 &&
@@ -143,7 +143,7 @@ test_expect_success ZIPINFO 'zip archive with many entries' '
143
do
144
for d in 0 1 2 3 4 5 6 7 8 9 a b c d e f
145
do
146
- echo "040000 tree $subtree $c$d"
146
+ echo "040000 tree $subtree $c$d" || return 1
147
done
148
done >tree &&
149
tree=$(git mktree <tree) &&
@@ -171,7 +171,7 @@ test_expect_success EXPENSIVE,UNZIP,UNZIP_ZIP64_SUPPORT \
171
# create tree containing 65500 entries of that blob
172
for i in $(test_seq 1 65500)
173
do
174
- echo "100644 blob $blob $i"
174
+ echo "100644 blob $blob $i" || return 1
175
done >tree &&
176
tree=$(git mktree <tree) &&
177
t/t5100-mailinfo.sh
+1
-1
@@ -122,7 +122,7 @@ test_expect_success 'mailinfo unescapes with --mboxrd' '
122
do
123
git mailinfo mboxrd/msg mboxrd/patch \
124
<mboxrd/$i >mboxrd/out &&
125
- test_cmp "$DATA/${i}mboxrd" mboxrd/msg
125
+ test_cmp "$DATA/${i}mboxrd" mboxrd/msg || return 1
126
done &&
127
sp=" " &&
128
echo "From " >expect &&
t/t5300-pack-object.sh
+3
-3
@@ -347,7 +347,7 @@ test_expect_success 'unpacking with --strict' '
347
for i in 0 1 2 3 4 5 6 7 8 9
348
do
349
o=$(echo $j$i | git hash-object -w --stdin) &&
350
- echo "100644 $o 0 $j$i"
350
+ echo "100644 $o 0 $j$i" || return 1
351
done
352
done >LIST &&
353
rm -f .git/index &&
@@ -390,7 +390,7 @@ test_expect_success 'index-pack with --strict' '
390
for i in 0 1 2 3 4 5 6 7 8 9
391
do
392
o=$(echo $j$i | git hash-object -w --stdin) &&
393
- echo "100644 $o 0 $j$i"
393
+ echo "100644 $o 0 $j$i" || return 1
394
done
395
done >LIST &&
396
rm -f .git/index &&
@@ -586,7 +586,7 @@ test_expect_success 'setup for --stdin-packs tests' '
586
for id in A B C
587
do
588
git pack-objects .git/objects/pack/pack-$id \
589
- --incremental --revs <<-EOF
589
+ --incremental --revs <<-EOF || exit 1
590
refs/tags/$id
591
EOF
592
done &&
t/t5307-pack-missing-commit.sh
+1
-1
@@ -11,7 +11,7 @@ test_expect_success setup '
11
git add "file$i" &&
12
test_tick &&
13
git commit -m "$i" &&
14
- git tag "tag$i"
14
+ git tag "tag$i" || return 1
15
done &&
16
obj=$(git rev-parse --verify tag3) &&
17
fanout=$(expr "$obj" : "\(..\)") &&
t/t5310-pack-bitmaps.sh
+1
-1
@@ -230,7 +230,7 @@ test_expect_success 'pack reuse respects --honor-pack-keep' '
230
test_when_finished "rm -f .git/objects/pack/*.keep" &&
231
for i in .git/objects/pack/*.pack
232
do
233
- >${i%.pack}.keep
233
+ >${i%.pack}.keep || return 1
234
done &&
235
reusable_pack --honor-pack-keep >empty.pack &&
236
git index-pack empty.pack &&
t/t5317-pack-objects-filter-objects.sh
+5
-5
@@ -18,7 +18,7 @@ test_expect_success 'setup r1' '
18
do
19
echo "This is file: $n" > r1/file.$n &&
20
git -C r1 add file.$n &&
21
- git -C r1 commit -m "$n"
21
+ git -C r1 commit -m "$n" || return 1
22
done
23
'
24
@@ -118,7 +118,7 @@ test_expect_success 'setup r2' '
118
do
119
printf "%"$n"s" X > r2/large.$n &&
120
git -C r2 add large.$n &&
121
- git -C r2 commit -m "$n"
121
+ git -C r2 commit -m "$n" || return 1
122
done
123
'
124
@@ -281,7 +281,7 @@ test_expect_success 'setup r3' '
281
echo "This is file: $n" > r3/$n &&
282
git -C r3 add $n &&
283
echo "This is file: dir1/$n" > r3/dir1/$n &&
284
- git -C r3 add dir1/$n
284
+ git -C r3 add dir1/$n || return 1
285
done &&
286
git -C r3 commit -m "sparse" &&
287
echo dir1/ >pattern1 &&
@@ -334,7 +334,7 @@ test_expect_success 'setup r4' '
334
echo "This is file: $n" > r4/$n &&
335
git -C r4 add $n &&
336
echo "This is file: dir1/$n" > r4/dir1/$n &&
337
- git -C r4 add dir1/$n
337
+ git -C r4 add dir1/$n || return 1
338
done &&
339
echo dir1/ >r4/pattern &&
340
git -C r4 add pattern &&
@@ -409,7 +409,7 @@ test_expect_success 'setup r1 - delete loose blobs' '
409
410
for id in `cat expected | sed "s|..|&/|"`
411
do
412
- rm r1/.git/objects/$id
412
+ rm r1/.git/objects/$id || return 1
413
done
414
'
415
t/t5318-commit-graph.sh
+3
-3
@@ -64,7 +64,7 @@ test_expect_success 'create commits and repack' '
64
for i in $(test_seq 3)
65
do
66
test_commit $i &&
67
- git branch commits/$i
67
+ git branch commits/$i || return 1
68
done &&
69
git repack
70
'
@@ -147,13 +147,13 @@ test_expect_success 'Add more commits' '
147
for i in $(test_seq 4 5)
148
do
149
test_commit $i &&
150
- git branch commits/$i
150
+ git branch commits/$i || return 1
151
done &&
152
git reset --hard commits/2 &&
153
for i in $(test_seq 6 7)
154
do
155
test_commit $i &&
156
- git branch commits/$i
156
+ git branch commits/$i || return 1
157
done &&
158
git reset --hard commits/2 &&
159
git merge commits/4 &&
t/t5319-multi-pack-index.sh
+5
-5
@@ -93,7 +93,7 @@ test_expect_success 'create objects' '
93
test_commit initial &&
94
for i in $(test_seq 1 5)
95
do
96
- generate_objects $i
96
+ generate_objects $i || return 1
97
done &&
98
commit_and_list_objects
99
'
@@ -155,7 +155,7 @@ test_expect_success 'corrupt idx reports errors' '
155
test_expect_success 'add more objects' '
156
for i in $(test_seq 6 10)
157
do
158
- generate_objects $i
158
+ generate_objects $i || return 1
159
done &&
160
commit_and_list_objects
161
'
@@ -203,7 +203,7 @@ test_expect_success 'add more packs' '
203
do
204
generate_objects $j &&
205
commit_and_list_objects &&
206
- git pack-objects --index-version=2 $objdir/pack/test-pack <obj-list
206
+ git pack-objects --index-version=2 $objdir/pack/test-pack <obj-list || return 1
207
done
208
'
209
@@ -594,7 +594,7 @@ test_expect_success 'force some 64-bit offsets with pack-objects' '
594
mkdir objects64/pack &&
595
for i in $(test_seq 1 11)
596
do
597
- generate_objects 11
597
+ generate_objects 11 || return 1
598
done &&
599
commit_and_list_objects &&
600
pack64=$(git pack-objects --index-version=2,0x40 objects64/pack/test-64 <obj-list) &&
@@ -638,7 +638,7 @@ test_expect_success 'setup expire tests' '
638
git update-index --add large_file.txt &&
639
for i in $(test_seq 1 20)
640
do
641
- test_commit $i
641
+ test_commit $i || exit 1
642
done &&
643
git branch A HEAD &&
644
git branch B HEAD~8 &&
t/t5322-pack-objects-sparse.sh
+2
-2
@@ -14,7 +14,7 @@ test_expect_success 'setup repo' '
14
for j in $(test_seq 1 3)
15
do
16
mkdir f$i/f$j &&
17
- echo $j >f$i/f$j/data.txt
17
+ echo $j >f$i/f$j/data.txt || return 1
18
done
19
done &&
20
git add . &&
@@ -23,7 +23,7 @@ test_expect_success 'setup repo' '
23
do
24
git checkout -b topic$i main &&
25
echo change-$i >f$i/f$i/data.txt &&
26
- git commit -a -m "Changed f$i/f$i/data.txt"
26
+ git commit -a -m "Changed f$i/f$i/data.txt" || return 1
27
done &&
28
cat >packinput.txt <<-EOF &&
29
topic1
t/t5325-reverse-index.sh
+1
-1
@@ -46,7 +46,7 @@ test_expect_success 'index-pack with --[no-]rev-index' '
46
test_path_exists $rev &&
47
48
test_index_pack "$conf" --no-rev-index &&
49
- test_path_is_missing $rev
49
+ test_path_is_missing $rev || return 1
50
done
51
'
52
t/t5500-fetch-pack.sh
+4
-4
@@ -95,7 +95,7 @@ test_expect_success 'setup' '
95
while [ $cur -le 10 ]; do
96
add A$cur $(eval echo \$A$prev) &&
97
prev=$cur &&
98
- cur=$(($cur+1))
98
+ cur=$(($cur+1)) || return 1
99
done &&
100
add B1 $A1 &&
101
git update-ref refs/heads/A "$ATIP" &&
@@ -112,7 +112,7 @@ test_expect_success 'post 1st pull setup' '
112
while [ $cur -le 65 ]; do
113
add B$cur $(eval echo \$B$prev) &&
114
prev=$cur &&
115
- cur=$(($cur+1))
115
+ cur=$(($cur+1)) || return 1
116
done
117
'
118
@@ -464,11 +464,11 @@ test_expect_success 'fetch creating new shallow root' '
464
test_expect_success 'setup tests for the --stdin parameter' '
465
for head in C D E F
466
do
467
- add $head
467
+ add $head || return 1
468
done &&
469
for head in A B C D E F
470
do
471
- git tag $head $head
471
+ git tag $head $head || return 1
472
done &&
473
cat >input <<-\EOF &&
474
refs/heads/C
t/t5502-quickfetch.sh
+1
-1
@@ -130,7 +130,7 @@ test_expect_success 'quickfetch should handle ~1000 refs (on Windows)' '
130
for i in 0 1 2 3 4 5 6 7 8 9; do
131
for j in 0 1 2 3 4 5 6 7 8 9; do
132
for k in 0 1 2 3 4 5 6 7 8 9; do
133
- echo "$branchprefix$i$j$k" >> .git/packed-refs
133
+ echo "$branchprefix$i$j$k" >> .git/packed-refs || return 1
134
done
135
done
136
done &&
t/t5510-fetch.sh
+1
-1
@@ -550,7 +550,7 @@ test_expect_success 'bundle should record HEAD correctly' '
550
git bundle list-heads bundle5 >actual &&
551
for h in HEAD refs/heads/main
552
do
553
- echo "$(git rev-parse --verify $h) $h"
553
+ echo "$(git rev-parse --verify $h) $h" || return 1
554
done >expect &&
555
test_cmp expect actual
556
t/t5515-fetch-merge-logic.sh
+2
-2
@@ -133,7 +133,7 @@ test_expect_success setup '
133
git config branch.br-$remote-merge.merge refs/heads/three &&
134
git config branch.br-$remote-octopus.remote $remote &&
135
git config branch.br-$remote-octopus.merge refs/heads/one &&
136
- git config --add branch.br-$remote-octopus.merge two
136
+ git config --add branch.br-$remote-octopus.merge two || return 1
137
done &&
138
build_script sed_script
139
'
@@ -199,7 +199,7 @@ do
199
refs/heads refs/remotes/rem refs/tags |
200
while read val type refname
201
do
202
- git update-ref -d "$refname" "$val"
202
+ git update-ref -d "$refname" "$val" || return 1
203
done &&
204
git fetch "$@" >/dev/null &&
205
cat .git/FETCH_HEAD
t/t5552-skipping-fetch-negotiator.sh
+5
-5
@@ -48,7 +48,7 @@ test_expect_success 'commits with no parents are sent regardless of skip distanc
48
git init client &&
49
for i in $(test_seq 7)
50
do
51
- test_commit -C client c$i
51
+ test_commit -C client c$i || return 1
52
done &&
53
54
# We send: "c7" (skip 1) "c5" (skip 2) "c2" (skip 4). After that, since
@@ -68,7 +68,7 @@ test_expect_success 'when two skips collide, favor the larger one' '
68
git init client &&
69
for i in $(test_seq 11)
70
do
71
- test_commit -C client c$i
71
+ test_commit -C client c$i || return 1
72
done &&
73
git -C client checkout c5 &&
74
test_commit -C client c5side &&
@@ -155,14 +155,14 @@ test_expect_success 'do not send "have" with ancestors of commits that server AC
155
for i in $(test_seq 8)
156
do
157
git -C client checkout --orphan b$i &&
158
- test_commit -C client b$i.c0
158
+ test_commit -C client b$i.c0 || return 1
159
done &&
160
for j in $(test_seq 19)
161
do
162
for i in $(test_seq 8)
163
do
164
git -C client checkout b$i &&
165
- test_commit -C client b$i.c$j
165
+ test_commit -C client b$i.c$j || return 1
166
done
167
done &&
168
@@ -201,7 +201,7 @@ test_expect_success 'do not send "have" with ancestors of commits that server AC
201
# should still send the others (in this test, just check b2).
202
for i in $(test_seq 0 8)
203
do
204
- have_not_sent b1.c$i
204
+ have_not_sent b1.c$i || return 1
205
done &&
206
have_sent b2.c1 b2.c0
207
'
t/t5571-pre-push-hook.sh
+1
-1
@@ -118,7 +118,7 @@ test_expect_success 'set up many-ref tests' '
118
while test $nr -lt 2000
119
do
120
nr=$(( $nr + 1 )) &&
121
- echo "create refs/heads/b/$nr $COMMIT3"
121
+ echo "create refs/heads/b/$nr $COMMIT3" || return 1
122
done
123
} | git update-ref --stdin
124
'
t/t5616-partial-clone.sh
+6
-6
@@ -19,7 +19,7 @@ test_expect_success 'setup normal src repo' '
19
echo "This is file: $n" > src/file.$n.txt &&
20
git -C src add file.$n.txt &&
21
git -C src commit -m "file $n" &&
22
- git -C src ls-files -s file.$n.txt >>temp
22
+ git -C src ls-files -s file.$n.txt >>temp || return 1
23
done &&
24
awk -f print_2.awk <temp | sort >expect_1.oids &&
25
test_line_count = 4 expect_1.oids
@@ -74,7 +74,7 @@ test_expect_success 'push new commits to server' '
74
do
75
echo "Mod file.1.txt $x" >>src/file.1.txt &&
76
git -C src add file.1.txt &&
77
- git -C src commit -m "mod $x"
77
+ git -C src commit -m "mod $x" || return 1
78
done &&
79
git -C src blame main -- file.1.txt >expect.blame &&
80
git -C src push -u srv main
@@ -116,7 +116,7 @@ test_expect_success 'push new commits to server for file.2.txt' '
116
do
117
echo "Mod file.2.txt $x" >>src/file.2.txt &&
118
git -C src add file.2.txt &&
119
- git -C src commit -m "mod $x"
119
+ git -C src commit -m "mod $x" || return 1
120
done &&
121
git -C src push -u srv main
122
'
@@ -137,7 +137,7 @@ test_expect_success 'push new commits to server for file.3.txt' '
137
do
138
echo "Mod file.3.txt $x" >>src/file.3.txt &&
139
git -C src add file.3.txt &&
140
- git -C src commit -m "mod $x"
140
+ git -C src commit -m "mod $x" || return 1
141
done &&
142
git -C src push -u srv main
143
'
@@ -385,7 +385,7 @@ setup_triangle () {
385
for i in $(test_seq 1 100)
386
do
387
echo "make the tree big" >server/file$i &&
388
- git -C server add file$i
388
+ git -C server add file$i || return 1
389
done &&
390
git -C server commit -m "initial" &&
391
git clone --bare --filter=tree:0 "file://$(pwd)/server" client &&
@@ -669,7 +669,7 @@ test_expect_success 'tolerate server sending REF_DELTA against missing promisor
669
for i in $(test_seq 10)
670
do
671
echo "this is a line" >>"$SERVER/foo.txt" &&
672
- echo "this is another line" >>"$SERVER/have.txt"
672
+ echo "this is another line" >>"$SERVER/have.txt" || return 1
673
done &&
674
git -C "$SERVER" add foo.txt have.txt &&
675
git -C "$SERVER" commit -m bar &&
t/t5702-protocol-v2.sh
+2
-2
@@ -747,7 +747,7 @@ test_expect_success 'clone big repository with http:// using protocol v2' '
747
echo "data 0" &&
748
echo "M 644 inline bla.txt" &&
749
echo "data 4" &&
750
- echo "bla"
750
+ echo "bla" || return 1
751
done | git -C "$HTTPD_DOCUMENT_ROOT_PATH/big" fast-import &&
752
753
GIT_TRACE_PACKET="$(pwd)/log" GIT_TRACE_CURL="$(pwd)/log" git \
@@ -942,7 +942,7 @@ test_expect_success 'part of packfile response provided as URI' '
942
then
943
>h2found
944
fi
945
- fi
945
+ fi || return 1
946
done &&
947
test -f hfound &&
948
test -f h2found &&