Thread (35 messages) flat view 35 messages, 4 authors, 2021-07-30

Re: [PATCH 1/5] t1092: test merge conflicts outside cone

From: Elijah Newren <hidden>
Date: 2021-07-23 17:47:16

On Fri, Jul 23, 2021 at 10:44 AM Eric Sunshine [off-list ref] wrote:
On Fri, Jul 23, 2021 at 1:34 PM Elijah Newren [off-list ref] wrote:
quoted
On Wed, Jul 21, 2021 at 2:07 PM Derrick Stolee via GitGitGadget
[off-list ref] wrote:
quoted
+               for side in left right
+               do
+                       git checkout -b merge-$side base &&
+                       echo $side >>deep/deeper2/a &&
+                       echo $side >>folder1/a &&
+                       echo $side >>folder2/a &&
+                       git add . &&
+                       git commit -m "$side" || return 1
Why is this "|| return 1" here?

It looks like there are a number of other cases of this in the file
too, which I must have overlooked previously, because I don't
understand any of them.
A shell for-loop won't automatically terminate just because some
command in its body fails. Instead it will run to completion and
return the status of the last command of the last iteration, which may
not be the iteration which failed, thus a failure can be hidden.
Therefore, we need to proactively stop the loop iteration _and_ ensure
that the return status of the loop itself reflects the failure, which
we do by `|| return 1`. (If this loop was inside a subshell, we'd use
`|| exit 1` instead.)
Ah, thanks for the explanation.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help