Skip to content

Commit 47c39c2

Browse files
pks-tgitster
authored andcommitted
contrib/subtree: convert subtree type check to use case statement
The `subtree_for_commit ()` helper function asserts that the subtree identified by its parameters are either a commit or tree. This is done via the `-o` parameter of test, which is discouraged. Refactor the code to instead use a switch statement over the type. Despite being aligned with our coding guidelines, the resulting code is arguably also easier to read. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8898394 commit 47c39c2

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

contrib/subtree/git-subtree.sh

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -641,10 +641,16 @@ subtree_for_commit () {
641641
while read mode type tree name
642642
do
643643
assert test "$name" = "$dir"
644-
assert test "$type" = "tree" -o "$type" = "commit"
645-
test "$type" = "commit" && continue # ignore submodules
646-
echo $tree
647-
break
644+
645+
case "$type" in
646+
commit)
647+
continue;; # ignore submodules
648+
tree)
649+
echo $tree
650+
break;;
651+
*)
652+
die "fatal: tree entry is of type ${type}, expected tree or commit";;
653+
esac
648654
done || exit $?
649655
}
650656

0 commit comments

Comments
 (0)