Skip to content

Commit d2f0f81

Browse files
LukeShugitster
authored andcommitted
subtree: more consistent error propagation
Ensure that every $(subshell) that calls a function (as opposed to an external executable) is followed by `|| exit $?`. Similarly, ensure that every `cmd | while read; do ... done` loop is followed by `|| exit $?`. Both of those constructs mean that it can miss `die` calls, and keep running when it shouldn't. Signed-off-by: Luke Shumaker <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5a35697 commit d2f0f81

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

contrib/subtree/git-subtree.sh

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ cache_miss () {
243243
}
244244

245245
check_parents () {
246-
missed=$(cache_miss "$1")
246+
missed=$(cache_miss "$1") || exit $?
247247
local indent=$(($2 + 1))
248248
for miss in $missed
249249
do
@@ -345,7 +345,7 @@ find_latest_squash () {
345345
sub=
346346
;;
347347
esac
348-
done
348+
done || exit $?
349349
}
350350

351351
find_existing_splits () {
@@ -394,7 +394,7 @@ find_existing_splits () {
394394
sub=
395395
;;
396396
esac
397-
done
397+
done || exit $?
398398
}
399399

400400
copy_commit () {
@@ -508,7 +508,7 @@ subtree_for_commit () {
508508
test "$type" = "commit" && continue # ignore submodules
509509
echo $tree
510510
break
511-
done
511+
done || exit $?
512512
}
513513

514514
tree_changed () {
@@ -518,7 +518,7 @@ tree_changed () {
518518
then
519519
return 0 # weird parents, consider it changed
520520
else
521-
ptree=$(toptree_for_commit $1)
521+
ptree=$(toptree_for_commit $1) || exit $?
522522
if test "$ptree" != "$tree"
523523
then
524524
return 0 # changed
@@ -652,7 +652,7 @@ process_split_commit () {
652652
progress "$revcount/$revmax ($createcount) [$extracount]"
653653

654654
debug "Processing commit: $rev"
655-
exists=$(cache_get "$rev")
655+
exists=$(cache_get "$rev") || exit $?
656656
if test -n "$exists"
657657
then
658658
debug " prior: $exists"
@@ -661,10 +661,10 @@ process_split_commit () {
661661
createcount=$(($createcount + 1))
662662
debug " parents: $parents"
663663
check_parents "$parents" "$indent"
664-
newparents=$(cache_get $parents)
664+
newparents=$(cache_get $parents) || exit $?
665665
debug " newparents: $newparents"
666666

667-
tree=$(subtree_for_commit "$rev" "$dir")
667+
tree=$(subtree_for_commit "$rev" "$dir") || exit $?
668668
debug " tree is: $tree"
669669

670670
# ugly. is there no better way to tell if this is a subtree
@@ -750,7 +750,7 @@ cmd_add_commit () {
750750
commit=$(add_squashed_msg "$rev" "$dir" |
751751
git commit-tree "$tree" $headp -p "$rev") || exit $?
752752
else
753-
revp=$(peel_committish "$rev") &&
753+
revp=$(peel_committish "$rev") || exit $?
754754
commit=$(add_msg "$dir" $headrev "$rev" |
755755
git commit-tree "$tree" $headp -p "$revp") || exit $?
756756
fi
@@ -773,10 +773,10 @@ cmd_split () {
773773
# any parent we find there can be used verbatim
774774
debug " cache: $rev"
775775
cache_set "$rev" "$rev"
776-
done
776+
done || exit $?
777777
fi
778778

779-
unrevs="$(find_existing_splits "$dir" "$revs")"
779+
unrevs="$(find_existing_splits "$dir" "$revs")" || exit $?
780780

781781
# We can't restrict rev-list to only $dir here, because some of our
782782
# parents have the $dir contents the root, and those won't match.
@@ -792,7 +792,7 @@ cmd_split () {
792792
process_split_commit "$rev" "$parents" 0
793793
done || exit $?
794794

795-
latest_new=$(cache_get latest_new)
795+
latest_new=$(cache_get latest_new) || exit $?
796796
if test -z "$latest_new"
797797
then
798798
die "No new revisions were found"
@@ -801,7 +801,7 @@ cmd_split () {
801801
if test -n "$rejoin"
802802
then
803803
debug "Merging split branch into HEAD..."
804-
latest_old=$(cache_get latest_old)
804+
latest_old=$(cache_get latest_old) || exit $?
805805
git merge -s ours \
806806
--allow-unrelated-histories \
807807
-m "$(rejoin_msg "$dir" "$latest_old" "$latest_new")" \
@@ -834,7 +834,7 @@ cmd_merge () {
834834

835835
if test -n "$squash"
836836
then
837-
first_split="$(find_latest_squash "$dir")"
837+
first_split="$(find_latest_squash "$dir")" || exit $?
838838
if test -z "$first_split"
839839
then
840840
die "Can't squash-merge: '$dir' was never added."

0 commit comments

Comments
 (0)