Skip to content

Commit 8898394

Browse files
pks-tgitster
authored andcommitted
contrib/subtree: stop using -o to test for number of args
Functions in git-subtree.sh all assert that they are being passed the correct number of arguments. In cases where we accept a variable number of arguments we assert this via a single call to `test` with `-o`, which is discouraged by our coding guidelines. Convert these cases to stop doing so. This requires us to decompose assertions of the style `assert test $# = 2 -o $# = 3` into two calls because we have no easy way to logically chain statements passed to the assert function. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1342002 commit 8898394

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

contrib/subtree/git-subtree.sh

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,8 @@ try_remove_previous () {
373373

374374
# Usage: process_subtree_split_trailer SPLIT_HASH MAIN_HASH [REPOSITORY]
375375
process_subtree_split_trailer () {
376-
assert test $# = 2 -o $# = 3
376+
assert test $# -ge 2
377+
assert test $# -le 3
377378
b="$1"
378379
sq="$2"
379380
repository=""
@@ -402,7 +403,8 @@ process_subtree_split_trailer () {
402403

403404
# Usage: find_latest_squash DIR [REPOSITORY]
404405
find_latest_squash () {
405-
assert test $# = 1 -o $# = 2
406+
assert test $# -ge 1
407+
assert test $# -le 2
406408
dir="$1"
407409
repository=""
408410
if test "$#" = 2
@@ -455,7 +457,8 @@ find_latest_squash () {
455457

456458
# Usage: find_existing_splits DIR REV [REPOSITORY]
457459
find_existing_splits () {
458-
assert test $# = 2 -o $# = 3
460+
assert test $# -ge 2
461+
assert test $# -le 3
459462
debug "Looking for prior splits..."
460463
local indent=$(($indent + 1))
461464

@@ -916,7 +919,7 @@ cmd_split () {
916919
if test $# -eq 0
917920
then
918921
rev=$(git rev-parse HEAD)
919-
elif test $# -eq 1 -o $# -eq 2
922+
elif test $# -eq 1 || test $# -eq 2
920923
then
921924
rev=$(git rev-parse -q --verify "$1^{commit}") ||
922925
die "fatal: '$1' does not refer to a commit"
@@ -1006,8 +1009,11 @@ cmd_split () {
10061009

10071010
# Usage: cmd_merge REV [REPOSITORY]
10081011
cmd_merge () {
1009-
test $# -eq 1 -o $# -eq 2 ||
1012+
if test $# -lt 1 || test $# -gt 2
1013+
then
10101014
die "fatal: you must provide exactly one revision, and optionally a repository. Got: '$*'"
1015+
fi
1016+
10111017
rev=$(git rev-parse -q --verify "$1^{commit}") ||
10121018
die "fatal: '$1' does not refer to a commit"
10131019
repository=""

0 commit comments

Comments
 (0)