t0000-t3999: 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
db5875aa9fe056c2db3a463989091c5f70d6c8d1
31 files changed
+55
-55
t/perf/p0100-globbing.sh
+2
-2
@@ -19,9 +19,9 @@ test_expect_success 'setup' '
19
printf "a" >>refname &&
20
for j in $(test_seq 1 $i)
21
do
22
- printf "a*" >>refglob.$i
22
+ printf "a*" >>refglob.$i || return 1
23
done &&
24
- echo b >>refglob.$i
24
+ echo b >>refglob.$i || return 1
25
done &&
26
test_commit test $(cat refname).t "" $(cat refname).t
27
'
t/perf/p1400-update-ref.sh
+2
-2
@@ -13,7 +13,7 @@ test_expect_success "setup" '
13
do
14
printf "start\ncreate refs/heads/%d PRE\ncommit\n" $i &&
15
printf "start\nupdate refs/heads/%d POST PRE\ncommit\n" $i &&
16
- printf "start\ndelete refs/heads/%d POST\ncommit\n" $i
16
+ printf "start\ndelete refs/heads/%d POST\ncommit\n" $i || return 1
17
done >instructions
18
'
19
@@ -22,7 +22,7 @@ test_perf "update-ref" '
22
do
23
git update-ref refs/heads/branch PRE &&
24
git update-ref refs/heads/branch POST PRE &&
25
- git update-ref -d refs/heads/branch
25
+ git update-ref -d refs/heads/branch || return 1
26
done
27
'
28
t/perf/p1451-fsck-skip-list.sh
+1
-1
@@ -15,7 +15,7 @@ test_expect_success "setup $n bad commits" '
15
echo "committer C <c@example.com> 1234567890 +0000" &&
16
echo "data <<EOF" &&
17
echo "$i.Q." &&
18
- echo "EOF"
18
+ echo "EOF" || return 1
19
done | q_to_nul | git fast-import
20
'
21
t/perf/p3400-rebase.sh
+1
-1
@@ -22,7 +22,7 @@ test_expect_success 'setup rebasing on top of a lot of changes' '
22
git add unrelated-file$i &&
23
test_tick &&
24
git commit -m commit$i-reverse unrelated-file$i ||
25
- break
25
+ return 1
26
done &&
27
git checkout to-rebase &&
28
test_commit our-patch interesting-file
t/perf/p5302-pack-index.sh
+1
-1
@@ -22,7 +22,7 @@ test_expect_success 'set up thread-counting tests' '
22
while test $t -gt 0
23
do
24
threads="$t $threads" &&
25
- t=$((t / 2))
25
+ t=$((t / 2)) || return 1
26
done
27
'
28
t/perf/p5303-many-packs.sh
+1
-1
@@ -130,7 +130,7 @@ test_expect_success 'generate lots of packs' '
130
echo "data <<EOF" &&
131
echo "blob $i" &&
132
echo "EOF" &&
133
- echo "checkpoint"
133
+ echo "checkpoint" || return 1
134
done |
135
git -c fastimport.unpackLimit=0 fast-import
136
'
t/perf/p7519-fsmonitor.sh
+4
-4
@@ -119,10 +119,10 @@ test_expect_success "one time repo setup" '
119
fi &&
120
121
mkdir 1_file 10_files 100_files 1000_files 10000_files &&
122
- for i in $(test_seq 1 10); do touch 10_files/$i; done &&
123
- for i in $(test_seq 1 100); do touch 100_files/$i; done &&
124
- for i in $(test_seq 1 1000); do touch 1000_files/$i; done &&
125
- for i in $(test_seq 1 10000); do touch 10000_files/$i; done &&
122
+ for i in $(test_seq 1 10); do touch 10_files/$i || return 1; done &&
123
+ for i in $(test_seq 1 100); do touch 100_files/$i || return 1; done &&
124
+ for i in $(test_seq 1 1000); do touch 1000_files/$i || return 1; done &&
125
+ for i in $(test_seq 1 10000); do touch 10000_files/$i || return 1; done &&
126
git add 1_file 10_files 100_files 1000_files 10000_files &&
127
git commit -qm "Add files" &&
128
t/t0008-ignores.sh
+1
-1
@@ -200,7 +200,7 @@ test_expect_success 'setup' '
200
do
201
: >$dir/not-ignored &&
202
: >$dir/ignored-and-untracked &&
203
- : >$dir/ignored-but-in-index
203
+ : >$dir/ignored-but-in-index || return 1
204
done &&
205
git add -f ignored-but-in-index a/ignored-but-in-index &&
206
cat <<-\EOF >a/.gitignore &&
t/t0011-hashmap.sh
+2
-2
@@ -220,7 +220,7 @@ test_expect_success 'grow / shrink' '
220
for n in $(test_seq 51)
221
do
222
echo put key$n value$n >> in &&
223
- echo NULL >> expect
223
+ echo NULL >> expect || return 1
224
done &&
225
echo size >> in &&
226
echo 64 51 >> expect &&
@@ -231,7 +231,7 @@ test_expect_success 'grow / shrink' '
231
for n in $(test_seq 12)
232
do
233
echo remove key$n >> in &&
234
- echo value$n >> expect
234
+ echo value$n >> expect || return 1
235
done &&
236
echo size >> in &&
237
echo 256 40 >> expect &&
t/t0021-conversion.sh
+4
-4
@@ -285,7 +285,7 @@ test_expect_success 'required filter with absent smudge field' '
285
test_expect_success 'filtering large input to small output should use little memory' '
286
test_config filter.devnull.clean "cat >/dev/null" &&
287
test_config filter.devnull.required true &&
288
- for i in $(test_seq 1 30); do printf "%1048576d" 1; done >30MB &&
288
+ for i in $(test_seq 1 30); do printf "%1048576d" 1 || return 1; done >30MB &&
289
echo "30MB filter=devnull" >.gitattributes &&
290
GIT_MMAP_LIMIT=1m GIT_ALLOC_LIMIT=1m git add 30MB
291
'
@@ -303,7 +303,7 @@ test_expect_success 'filter that does not read is fine' '
303
test_expect_success EXPENSIVE 'filter large file' '
304
test_config filter.largefile.smudge cat &&
305
test_config filter.largefile.clean cat &&
306
- for i in $(test_seq 1 2048); do printf "%1048576d" 1; done >2GB &&
306
+ for i in $(test_seq 1 2048); do printf "%1048576d" 1 || return 1; done >2GB &&
307
echo "2GB filter=largefile" >.gitattributes &&
308
git add 2GB 2>err &&
309
test_must_be_empty err &&
@@ -643,7 +643,7 @@ test_expect_success PERL 'required process filter should process multiple packet
643
for FILE in "$TEST_ROOT"/*.file
644
do
645
cp "$FILE" . &&
646
- rot13.sh <"$FILE" >"$FILE.rot13"
646
+ rot13.sh <"$FILE" >"$FILE.rot13" || return 1
647
done &&
648
649
echo "*.file filter=protocol" >.gitattributes &&
@@ -682,7 +682,7 @@ test_expect_success PERL 'required process filter should process multiple packet
682
683
for FILE in *.file
684
do
685
- test_cmp_committed_rot13 "$TEST_ROOT/$FILE" $FILE
685
+ test_cmp_committed_rot13 "$TEST_ROOT/$FILE" $FILE || return 1
686
done
687
)
688
'
t/t0095-bloom.sh
+2
-2
@@ -84,7 +84,7 @@ test_expect_success 'get bloom filter for commit with 10 changes' '
84
mkdir smallDir &&
85
for i in $(test_seq 0 9)
86
do
87
- echo $i >smallDir/$i
87
+ echo $i >smallDir/$i || return 1
88
done &&
89
git add smallDir &&
90
git commit -m "commit with 10 changes" &&
@@ -102,7 +102,7 @@ test_expect_success EXPENSIVE 'get bloom filter for commit with 513 changes' '
102
mkdir bigDir &&
103
for i in $(test_seq 0 511)
104
do
105
- echo $i >bigDir/$i
105
+ echo $i >bigDir/$i || return 1
106
done &&
107
git add bigDir &&
108
git commit -m "commit with 513 changes" &&
t/t0410-partial-clone.sh
+1
-1
@@ -469,7 +469,7 @@ test_expect_success 'rev-list dies for missing objects on cmd line' '
469
git -C repo rev-list --ignore-missing --objects \
470
--exclude-promisor-objects "$OBJ" &&
471
git -C repo rev-list --ignore-missing --objects-edge-aggressive \
472
- --exclude-promisor-objects "$OBJ"
472
+ --exclude-promisor-objects "$OBJ" || return 1
473
done
474
'
475
t/t1050-large.sh
+2
-2
@@ -105,7 +105,7 @@ test_expect_success 'packsize limit' '
105
count=0 &&
106
for pi in .git/objects/pack/pack-*.idx
107
do
108
- test_path_is_file "$pi" && count=$(( $count + 1 ))
108
+ test_path_is_file "$pi" && count=$(( $count + 1 )) || return 1
109
done &&
110
test $count = 2 &&
111
@@ -118,7 +118,7 @@ test_expect_success 'packsize limit' '
118
119
for pi in .git/objects/pack/pack-*.idx
120
do
121
- git show-index <"$pi"
121
+ git show-index <"$pi" || return 1
122
done |
123
sed -e "s/^[0-9]* \([0-9a-f]*\) .*/\1/" |
124
sort >actual &&
t/t1091-sparse-checkout-builtin.sh
+1
-1
@@ -586,7 +586,7 @@ test_expect_success 'pattern-checks: contained glob characters' '
586
!/*/
587
something$c-else/
588
EOF
589
- check_read_tree_errors repo "a" "disabling cone pattern matching"
589
+ check_read_tree_errors repo "a" "disabling cone pattern matching" || return 1
590
done
591
'
592
t/t1300-config.sh
+1
-1
@@ -718,7 +718,7 @@ test_expect_success bool '
718
for i in 1 2 3 4
719
do
720
git config --bool --get bool.true$i >>result &&
721
- git config --bool --get bool.false$i >>result
721
+ git config --bool --get bool.false$i >>result || return 1
722
done &&
723
test_cmp expect result'
724
t/t1400-update-ref.sh
+2
-2
@@ -1368,7 +1368,7 @@ test_expect_success ULIMIT_FILE_DESCRIPTORS 'large transaction creating branches
1368
(
1369
for i in $(test_seq 33)
1370
do
1371
- echo "create refs/heads/$i HEAD"
1371
+ echo "create refs/heads/$i HEAD" || exit 1
1372
done >large_input &&
1373
run_with_limited_open_files git update-ref --stdin <large_input &&
1374
git rev-parse --verify -q refs/heads/33
@@ -1379,7 +1379,7 @@ test_expect_success ULIMIT_FILE_DESCRIPTORS 'large transaction deleting branches
1379
(
1380
for i in $(test_seq 33)
1381
do
1382
- echo "delete refs/heads/$i HEAD"
1382
+ echo "delete refs/heads/$i HEAD" || exit 1
1383
done >large_input &&
1384
run_with_limited_open_files git update-ref --stdin <large_input &&
1385
test_must_fail git rev-parse --verify -q refs/heads/33
t/t1403-show-ref.sh
+2
-2
@@ -123,14 +123,14 @@ test_expect_success 'show-ref -d' '
123
test_expect_success 'show-ref --heads, --tags, --head, pattern' '
124
for branch in B main side
125
do
126
- echo $(git rev-parse refs/heads/$branch) refs/heads/$branch
126
+ echo $(git rev-parse refs/heads/$branch) refs/heads/$branch || return 1
127
done >expect.heads &&
128
git show-ref --heads >actual &&
129
test_cmp expect.heads actual &&
130
131
for tag in A B C
132
do
133
- echo $(git rev-parse refs/tags/$tag) refs/tags/$tag
133
+ echo $(git rev-parse refs/tags/$tag) refs/tags/$tag || return 1
134
done >expect.tags &&
135
git show-ref --tags >actual &&
136
test_cmp expect.tags actual &&
t/t1410-reflog.sh
+2
-2
@@ -349,12 +349,12 @@ test_expect_success SHA1 'parsing reverse reflogs at BUFSIZ boundaries' '
349
printf "$zf%02d $zf%02d %s\t" $i $(($i+1)) "$ident" &&
350
if test $i = 75; then
351
for j in $(test_seq 1 89); do
352
- printf X
352
+ printf X || return 1
353
done
354
else
355
printf X
356
fi &&
357
- printf "\n"
357
+ printf "\n" || return 1
358
done >.git/logs/refs/heads/reflogskip &&
359
git rev-parse reflogskip@{73} >actual &&
360
echo ${zf}03 >expect &&
t/t1512-rev-parse-disambiguation.sh
+1
-1
@@ -381,7 +381,7 @@ test_expect_success 'ambiguous commits are printed by type first, then hash orde
381
do
382
grep $type objects >$type.objects &&
383
sort $type.objects >$type.objects.sorted &&
384
- test_cmp $type.objects.sorted $type.objects
384
+ test_cmp $type.objects.sorted $type.objects || return 1
385
done
386
'
387
t/t2004-checkout-cache-temp.sh
+2
-2
@@ -57,7 +57,7 @@ test_expect_success 'checkout all stage 0 to temporary files' '
57
test $(grep $f actual | cut "-d " -f2) = $f &&
58
p=$(grep $f actual | cut "-d " -f1) &&
59
test -f $p &&
60
- test $(cat $p) = tree1$f
60
+ test $(cat $p) = tree1$f || return 1
61
done
62
'
63
@@ -85,7 +85,7 @@ test_expect_success 'checkout all stage 2 to temporary files' '
85
test $(grep $f actual | cut "-d " -f2) = $f &&
86
p=$(grep $f actual | cut "-d " -f1) &&
87
test -f $p &&
88
- test $(cat $p) = tree2$f
88
+ test $(cat $p) = tree2$f || return 1
89
done
90
'
91
t/t2012-checkout-last.sh
+2
-2
@@ -49,14 +49,14 @@ test_expect_success '"checkout -" detaches again' '
49
test_expect_success 'more switches' '
50
for i in 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
51
do
52
- git checkout -b branch$i
52
+ git checkout -b branch$i || return 1
53
done
54
'
55
56
more_switches () {
57
for i in 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
58
do
59
- git checkout branch$i
59
+ git checkout branch$i || return 1
60
done
61
}
62
t/t2200-add-update.sh
+1
-1
@@ -152,7 +152,7 @@ test_expect_success 'add -u resolves unmerged paths' '
152
do
153
echo "100644 $one 1 $path" &&
154
echo "100644 $two 2 $path" &&
155
- echo "100644 $three 3 $path"
155
+ echo "100644 $three 3 $path" || return 1
156
done &&
157
echo "100644 $one 1 path3" &&
158
echo "100644 $one 1 path4" &&
t/t2203-add-intent.sh
+1
-1
@@ -116,7 +116,7 @@ test_expect_success 'cache-tree does not ignore dir that has i-t-a entries' '
116
mkdir 2 &&
117
for f in 1 2/1 2/2 3
118
do
119
- echo "$f" >"$f"
119
+ echo "$f" >"$f" || return 1
120
done &&
121
git add 1 2/2 3 &&
122
git add -N 2/1 &&
t/t3202-show-branch.sh
+4
-4
@@ -9,7 +9,7 @@ test_expect_success 'setup' '
9
for i in $(test_seq 1 10)
10
do
11
git checkout -b branch$i initial &&
12
- test_commit --no-tag branch$i
12
+ test_commit --no-tag branch$i || return 1
13
done &&
14
git for-each-ref \
15
--sort=version:refname \
@@ -49,7 +49,7 @@ test_expect_success 'show-branch with more than 8 branches' '
49
test_expect_success 'show-branch with showbranch.default' '
50
for branch in $(cat branches.sorted)
51
do
52
- test_config showbranch.default $branch --add
52
+ test_config showbranch.default $branch --add || return 1
53
done &&
54
git show-branch >actual &&
55
test_cmp expect actual
@@ -124,7 +124,7 @@ test_expect_success 'show branch --merge-base with one argument' '
124
do
125
git rev-parse $branch >expect &&
126
git show-branch --merge-base $branch >actual &&
127
- test_cmp expect actual
127
+ test_cmp expect actual || return 1
128
done
129
'
130
@@ -133,7 +133,7 @@ test_expect_success 'show branch --merge-base with two arguments' '
133
do
134
git rev-parse initial >expect &&
135
git show-branch --merge-base initial $branch >actual &&
136
- test_cmp expect actual
136
+ test_cmp expect actual || return 1
137
done
138
'
139
t/t3303-notes-subtrees.sh
+3
-3
@@ -30,7 +30,7 @@ verify_notes () {
30
while [ $i -gt 0 ]; do
31
echo " commit #$i" &&
32
echo " note for commit #$i" &&
33
- i=$(($i-1));
33
+ i=$(($i-1)) || return 1
34
done > expect &&
35
test_cmp expect output
36
}
@@ -42,7 +42,7 @@ test_expect_success "setup: create $number_of_commits commits" '
42
while [ $nr -lt $number_of_commits ]; do
43
nr=$(($nr+1)) &&
44
test_tick &&
45
- cat <<INPUT_END
45
+ cat <<INPUT_END || return 1
46
commit refs/heads/main
47
committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
48
data <<COMMIT
@@ -178,7 +178,7 @@ verify_concatenated_notes () {
178
echo " first note for commit #$i" &&
179
echo " " &&
180
echo " second note for commit #$i" &&
181
- i=$(($i-1));
181
+ i=$(($i-1)) || return 1
182
done > expect &&
183
test_cmp expect output
184
}
t/t3305-notes-fanout.sh
+2
-2
@@ -57,7 +57,7 @@ test_expect_success 'many notes created correctly with git-notes' '
57
do
58
echo " commit #$i" &&
59
echo " note #$i" &&
60
- i=$(($i - 1));
60
+ i=$(($i - 1)) || return 1
61
done > expect &&
62
test_cmp expect output
63
'
@@ -106,7 +106,7 @@ test_expect_success 'most notes deleted correctly with git-notes' '
106
do
107
echo " commit #$i" &&
108
echo " note #$i" &&
109
- i=$(($i - 1));
109
+ i=$(($i - 1)) || return 1
110
done > expect &&
111
test_cmp expect output
112
'
t/t3404-rebase-interactive.sh
+2
-2
@@ -826,7 +826,7 @@ test_expect_success 'always cherry-pick with --no-ff' '
826
do
827
test ! $(git rev-parse HEAD~$p) = $(git rev-parse original-no-ff-branch~$p) &&
828
git diff HEAD~$p original-no-ff-branch~$p > out &&
829
- test_must_be_empty out
829
+ test_must_be_empty out || return 1
830
done &&
831
test_cmp_rev HEAD~3 original-no-ff-branch~3 &&
832
git diff HEAD~3 original-no-ff-branch~3 > out &&
@@ -1341,7 +1341,7 @@ test_expect_success 'rebase --continue removes CHERRY_PICK_HEAD' '
1341
test_seq 5 | sed "s/$double/&&/" >seq &&
1342
git add seq &&
1343
test_tick &&
1344
- git commit -m seq-$double
1344
+ git commit -m seq-$double || return 1
1345
done &&
1346
git tag seq-onto &&
1347
git reset --hard HEAD~2 &&
t/t3501-revert-cherry-pick.sh
+1
-1
@@ -19,7 +19,7 @@ test_expect_success setup '
19
20
for l in a b c d e f g h i j k l m n o
21
do
22
- echo $l$l$l$l$l$l$l$l$l
22
+ echo $l$l$l$l$l$l$l$l$l || return 1
23
done >oops &&
24
25
test_tick &&
t/t3508-cherry-pick-many-commits.sh
+1
-1
@@ -29,7 +29,7 @@ test_expect_success setup '
29
git add file1 &&
30
test_tick &&
31
git commit -m "$val" &&
32
- git tag $val
32
+ git tag $val || return 1
33
done
34
'
35
t/t3700-add.sh
+1
-1
@@ -143,7 +143,7 @@ test_expect_success 'git add with filemode=0, symlinks=0, and unmerged entries'
143
do
144
echo $s > stage$s &&
145
echo "100755 $(git hash-object -w stage$s) $s file" &&
146
- echo "120000 $(printf $s | git hash-object -w -t blob --stdin) $s symlink"
146
+ echo "120000 $(printf $s | git hash-object -w -t blob --stdin) $s symlink" || return 1
147
done | git update-index --index-info &&
148
git config core.filemode 0 &&
149
git config core.symlinks 0 &&
t/t3920-crlf-messages.sh
+2
-2
@@ -70,7 +70,7 @@ test_crlf_subject_body_and_contents() {
70
for ref in ${LIB_CRLF_BRANCHES}
71
do
72
cat .crlf-${file}-\"\${ref}\".txt >>expect &&
73
- printf \"\n\" >>expect
73
+ printf \"\n\" >>expect || return 1
74
done &&
75
git $command_and_args --format=\"%${atom}\" >actual &&
76
test_cmp expect actual
@@ -90,7 +90,7 @@ test_expect_success 'branch: --verbose works with messages using CRLF' '
90
do
91
printf " " >>expect &&
92
cat .crlf-subject-${branch}.txt >>expect &&
93
- printf "\n" >>expect
93
+ printf "\n" >>expect || return 1
94
done &&
95
git branch -v >tmp &&
96
# Remove first two columns, and the line for the currently checked out branch