mirror of
https://github.com/git/git
synced 2024-08-27 03:29:21 +00:00
subtree: add 'die_incompatible_opt' function to reduce duplication
9a3e3ca2ba
(subtree: be stricter about validating flags, 2021-04-27)
added validation code to check that options given to 'git subtree <cmd>'
made sense with the command being used.
Refactor these checks by adding a 'die_incompatible_opt' function to
reduce code duplication.
Signed-off-by: Philippe Blain <levraiphilippeblain@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
a50fcc13dd
commit
2e94339fdc
|
@ -102,6 +102,14 @@ assert () {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Usage: die_incompatible_opt OPTION COMMAND
|
||||||
|
die_incompatible_opt () {
|
||||||
|
assert test "$#" = 2
|
||||||
|
opt="$1"
|
||||||
|
arg_command="$2"
|
||||||
|
die "The '$opt' flag does not make sense with 'git subtree $arg_command'."
|
||||||
|
}
|
||||||
|
|
||||||
main () {
|
main () {
|
||||||
if test $# -eq 0
|
if test $# -eq 0
|
||||||
then
|
then
|
||||||
|
@ -176,16 +184,16 @@ main () {
|
||||||
arg_debug=1
|
arg_debug=1
|
||||||
;;
|
;;
|
||||||
--annotate)
|
--annotate)
|
||||||
test -n "$allow_split" || die "The '$opt' flag does not make sense with 'git subtree $arg_command'."
|
test -n "$allow_split" || die_incompatible_opt "$opt" "$arg_command"
|
||||||
arg_split_annotate="$1"
|
arg_split_annotate="$1"
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
--no-annotate)
|
--no-annotate)
|
||||||
test -n "$allow_split" || die "The '$opt' flag does not make sense with 'git subtree $arg_command'."
|
test -n "$allow_split" || die_incompatible_opt "$opt" "$arg_command"
|
||||||
arg_split_annotate=
|
arg_split_annotate=
|
||||||
;;
|
;;
|
||||||
-b)
|
-b)
|
||||||
test -n "$allow_split" || die "The '$opt' flag does not make sense with 'git subtree $arg_command'."
|
test -n "$allow_split" || die_incompatible_opt "$opt" "$arg_command"
|
||||||
arg_split_branch="$1"
|
arg_split_branch="$1"
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
|
@ -194,7 +202,7 @@ main () {
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
-m)
|
-m)
|
||||||
test -n "$allow_addmerge" || die "The '$opt' flag does not make sense with 'git subtree $arg_command'."
|
test -n "$allow_addmerge" || die_incompatible_opt "$opt" "$arg_command"
|
||||||
arg_addmerge_message="$1"
|
arg_addmerge_message="$1"
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
|
@ -202,34 +210,34 @@ main () {
|
||||||
arg_prefix=
|
arg_prefix=
|
||||||
;;
|
;;
|
||||||
--onto)
|
--onto)
|
||||||
test -n "$allow_split" || die "The '$opt' flag does not make sense with 'git subtree $arg_command'."
|
test -n "$allow_split" || die_incompatible_opt "$opt" "$arg_command"
|
||||||
arg_split_onto="$1"
|
arg_split_onto="$1"
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
--no-onto)
|
--no-onto)
|
||||||
test -n "$allow_split" || die "The '$opt' flag does not make sense with 'git subtree $arg_command'."
|
test -n "$allow_split" || die_incompatible_opt "$opt" "$arg_command"
|
||||||
arg_split_onto=
|
arg_split_onto=
|
||||||
;;
|
;;
|
||||||
--rejoin)
|
--rejoin)
|
||||||
test -n "$allow_split" || die "The '$opt' flag does not make sense with 'git subtree $arg_command'."
|
test -n "$allow_split" || die_incompatible_opt "$opt" "$arg_command"
|
||||||
;;
|
;;
|
||||||
--no-rejoin)
|
--no-rejoin)
|
||||||
test -n "$allow_split" || die "The '$opt' flag does not make sense with 'git subtree $arg_command'."
|
test -n "$allow_split" || die_incompatible_opt "$opt" "$arg_command"
|
||||||
;;
|
;;
|
||||||
--ignore-joins)
|
--ignore-joins)
|
||||||
test -n "$allow_split" || die "The '$opt' flag does not make sense with 'git subtree $arg_command'."
|
test -n "$allow_split" || die_incompatible_opt "$opt" "$arg_command"
|
||||||
arg_split_ignore_joins=1
|
arg_split_ignore_joins=1
|
||||||
;;
|
;;
|
||||||
--no-ignore-joins)
|
--no-ignore-joins)
|
||||||
test -n "$allow_split" || die "The '$opt' flag does not make sense with 'git subtree $arg_command'."
|
test -n "$allow_split" || die_incompatible_opt "$opt" "$arg_command"
|
||||||
arg_split_ignore_joins=
|
arg_split_ignore_joins=
|
||||||
;;
|
;;
|
||||||
--squash)
|
--squash)
|
||||||
test -n "$allow_addmerge" || die "The '$opt' flag does not make sense with 'git subtree $arg_command'."
|
test -n "$allow_addmerge" || die_incompatible_opt "$opt" "$arg_command"
|
||||||
arg_addmerge_squash=1
|
arg_addmerge_squash=1
|
||||||
;;
|
;;
|
||||||
--no-squash)
|
--no-squash)
|
||||||
test -n "$allow_addmerge" || die "The '$opt' flag does not make sense with 'git subtree $arg_command'."
|
test -n "$allow_addmerge" || die_incompatible_opt "$opt" "$arg_command"
|
||||||
arg_addmerge_squash=
|
arg_addmerge_squash=
|
||||||
;;
|
;;
|
||||||
--)
|
--)
|
||||||
|
|
Loading…
Reference in a new issue