Skip to content

Commit e6821d0

Browse files
peffgitster
authored andcommitted
t: fix some trivial cases of ignored exit codes in loops
These are all cases where we do a setup step of the form: for i in $foo; do set_up $i || break done && more_setup would not notice a failure in set_up (because break always returns a 0 exit code). These are just setup steps that we do not expect to fail, but it does not hurt to be defensive. Most can be fixed by converting the "break" to a "return 1" (since we eval our tests inside a function for just this purpose). A few of the loops are inside subshells, so we can use just "exit 1" to break out of the subshell. And a few can actually be made shorter by just unrolling the loop. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 76e057d commit e6821d0

10 files changed

+24
-28
lines changed

t/t3010-ls-files-killed-modified.sh

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,10 @@ test_expect_success 'git update-index --add to add various paths.' '
5555
: >path9 &&
5656
date >path10 &&
5757
git update-index --add -- path0 path?/file? pathx/ju path7 path8 path9 path10 &&
58-
for i in 1 2
59-
do
60-
git init submod$i &&
61-
(
62-
cd submod$i && git commit --allow-empty -m "empty $i"
63-
) || break
64-
done &&
58+
git init submod1 &&
59+
git -C submod1 commit --allow-empty -m "empty 1" &&
60+
git init submod2 &&
61+
git -C submod2 commit --allow-empty -m "empty 2" &&
6562
git update-index --add submod[12] &&
6663
(
6764
cd submod1 &&

t/t3031-merge-criscross.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ test_expect_success 'setup repo with criss-cross history' '
3232
do
3333
echo $n > data/$n &&
3434
n=$(($n+1)) ||
35-
break
35+
return 1
3636
done &&
3737
3838
# check them in

t/t3202-show-branch-octopus.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ test_expect_success 'setup' '
1919
> file$i &&
2020
git add file$i &&
2121
test_tick &&
22-
git commit -m branch$i || break
22+
git commit -m branch$i || return 1
2323
done
2424
2525
'

t/t4024-diff-optimize-common.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ test_expect_success setup '
139139
( printf C; zs $n ) >file-c$n &&
140140
( echo D; zs $n ) >file-d$n &&
141141
142-
expect_pattern $n || break
142+
expect_pattern $n || return 1
143143
144144
done >expect
145145
'

t/t4046-diff-unmerged.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ test_expect_success setup '
88
do
99
blob=$(echo $i | git hash-object --stdin) &&
1010
eval "blob$i=$blob" &&
11-
eval "m$i=\"100644 \$blob$i $i\"" || break
11+
eval "m$i=\"100644 \$blob$i $i\"" || return 1
1212
done &&
1313
paths= &&
1414
for b in o x
@@ -24,9 +24,9 @@ test_expect_success setup '
2424
case "$b" in x) echo "$m1$p" ;; esac &&
2525
case "$o" in x) echo "$m2$p" ;; esac &&
2626
case "$t" in x) echo "$m3$p" ;; esac ||
27-
break
28-
done || break
29-
done || break
27+
return 1
28+
done
29+
done
3030
done >ls-files-s.expect &&
3131
git update-index --index-info <ls-files-s.expect &&
3232
git ls-files -s >ls-files-s.actual &&

t/t4151-am-abort.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ test_expect_success setup '
2020
echo $i >otherfile-$i &&
2121
git add otherfile-$i &&
2222
test_tick &&
23-
git commit -a -m $i || break
23+
git commit -a -m $i || return 1
2424
done &&
2525
git format-patch --no-numbered initial &&
2626
git checkout -b side initial &&

t/t5505-remote.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ test_expect_success 'update with arguments' '
579579
cd one &&
580580
for b in $(git branch -r)
581581
do
582-
git branch -r -d $b || break
582+
git branch -r -d $b || exit 1
583583
done &&
584584
git remote add manduca ../mirror &&
585585
git remote add megaloprepus ../mirror &&
@@ -622,7 +622,7 @@ test_expect_success 'update default' '
622622
cd one &&
623623
for b in $(git branch -r)
624624
do
625-
git branch -r -d $b || break
625+
git branch -r -d $b || exit 1
626626
done &&
627627
git config remote.drosophila.skipDefaultUpdate true &&
628628
git remote update default &&
@@ -642,7 +642,7 @@ test_expect_success 'update default (overridden, with funny whitespace)' '
642642
cd one &&
643643
for b in $(git branch -r)
644644
do
645-
git branch -r -d $b || break
645+
git branch -r -d $b || exit 1
646646
done &&
647647
git config remotes.default "$(printf "\t drosophila \n")" &&
648648
git remote update default &&
@@ -656,7 +656,7 @@ test_expect_success 'update (with remotes.default defined)' '
656656
cd one &&
657657
for b in $(git branch -r)
658658
do
659-
git branch -r -d $b || break
659+
git branch -r -d $b || exit 1
660660
done &&
661661
git config remotes.default "drosophila" &&
662662
git remote update &&

t/t5514-fetch-multiple.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ test_expect_success 'git fetch --all (skipFetchAll)' '
120120
(cd test4 &&
121121
for b in $(git branch -r)
122122
do
123-
git branch -r -d $b || break
123+
git branch -r -d $b || exit 1
124124
done &&
125125
git remote add three ../three &&
126126
git config remote.three.skipFetchAll true &&
@@ -144,7 +144,7 @@ test_expect_success 'git fetch --multiple (ignoring skipFetchAll)' '
144144
(cd test4 &&
145145
for b in $(git branch -r)
146146
do
147-
git branch -r -d $b || break
147+
git branch -r -d $b || exit 1
148148
done &&
149149
git fetch --multiple one two three &&
150150
git branch -r > output &&

t/t6026-merge-attr.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,23 @@ test_expect_success setup '
1111
1212
for f in text binary union
1313
do
14-
echo Initial >$f && git add $f || break
14+
echo Initial >$f && git add $f || return 1
1515
done &&
1616
test_tick &&
1717
git commit -m Initial &&
1818
1919
git branch side &&
2020
for f in text binary union
2121
do
22-
echo Master >>$f && git add $f || break
22+
echo Master >>$f && git add $f || return 1
2323
done &&
2424
test_tick &&
2525
git commit -m Master &&
2626
2727
git checkout side &&
2828
for f in text binary union
2929
do
30-
echo Side >>$f && git add $f || break
30+
echo Side >>$f && git add $f || return 1
3131
done &&
3232
test_tick &&
3333
git commit -m Side &&

t/t6040-tracking-info.sh

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@ advance () {
1212
}
1313

1414
test_expect_success setup '
15-
for i in a b c;
16-
do
17-
advance $i || break
18-
done &&
15+
advance a &&
16+
advance b &&
17+
advance c &&
1918
git clone . test &&
2019
(
2120
cd test &&

0 commit comments

Comments
 (0)