]> git.ipfire.org Git - thirdparty/git.git/commitdiff
t3305: fix ignored exit code inside loop
authorJeff King <peff@peff.net>
Wed, 25 Mar 2015 05:28:57 +0000 (01:28 -0400)
committerJunio C Hamano <gitster@pobox.com>
Wed, 25 Mar 2015 17:23:58 +0000 (10:23 -0700)
When we test deleting notes, we run "git notes remove" in a
loop. However, the exit value of the loop will only reflect
the final note we process. We should break out of the loop
with a failing exit code as soon as we see a problem.

Note that we can call "exit 1" here without explicitly
creating a subshell, because the while loop on the
right-hand side of a pipe executes in its own implicit
subshell.

Note also that the "break" above does not suffer the same
problem; it is meant to exit the loop early at a certain
number of iterations. We can bump it into the conditional of
the loop to make this more obvious.

Signed-off-by: Jeff King <peff@peff.net>
Acked-by: Johan Herland <johan@herland.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/t3305-notes-fanout.sh

index b1ea64b2130354b1305e752923595128782bc880..54460beec469c0d3fe5db57508b6b762fd540cf2 100755 (executable)
@@ -51,15 +51,12 @@ test_expect_success 'deleting most notes with git-notes' '
        num_notes=250 &&
        i=0 &&
        git rev-list HEAD |
-       while read sha1
+       while test $i -lt $num_notes && read sha1
        do
                i=$(($i + 1)) &&
-               if test $i -gt $num_notes
-               then
-                       break
-               fi &&
                test_tick &&
-               git notes remove "$sha1"
+               git notes remove "$sha1" ||
+               exit 1
        done
 '