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 <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Patrick Steinhardt committed
Nov 10, 2023 at 11:01 UTC
47c39c28bc1a0001e4341ae70629adcb10f425cc
1 file changed
+10
-4
contrib/subtree/git-subtree.sh
+10
-4
@@ -641,10 +641,16 @@ subtree_for_commit () {
641
while read mode type tree name
642
do
643
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
654
done || exit $?
655
}
656