Commit b866b01b authored by Vincent Driessen's avatar Vincent Driessen

Give all subcommands an optional setup() function that will be called by...

Give all subcommands an optional setup() function that will be called by git-flow in order to let the subcommand initialize its environment.

Give all the branch-type subcommands a default explicit "list" action, too.

Order the functions inside each of the subcommands in a specific order, for consistency:
- usage()
- setup()
- cmd_default()
- cmd_list()
- cmd_help()
- parse_args()
- other commands
parent fb238a24
...@@ -90,6 +90,10 @@ sub_main() { ...@@ -90,6 +90,10 @@ sub_main() {
fi fi
# run the specified action # run the specified action
# if the subcommand declares a setup() function, call that first
if typeset -f setup >/dev/null; then
setup
fi
cmd_$SUBACTION "$@" cmd_$SUBACTION "$@"
} }
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
# #
usage() { usage() {
echo "usage: git flow feature" echo "usage: git flow feature [list]"
echo " git flow feature start <name> [<base>]" echo " git flow feature start <name> [<base>]"
echo " git flow feature finish <name> [<base>]" echo " git flow feature finish <name> [<base>]"
echo " git flow feature publish <name>" echo " git flow feature publish <name>"
...@@ -34,21 +34,16 @@ usage() { ...@@ -34,21 +34,16 @@ usage() {
#echo "--push Push to the origin repo when finished" #echo "--push Push to the origin repo when finished"
} }
parse_args() { # setup will always be called before the actual cmd_* functions
NAME="$1" setup() {
BASE="${2:-$DEVELOP_BRANCH}"
if [ "$NAME" = "" ]; then
echo "Missing argument <name>."
usage
exit 1
fi
PREFIX=$(git config --get gitflow.prefix.feature || echo feature/) PREFIX=$(git config --get gitflow.prefix.feature || echo feature/)
BRANCH=$PREFIX$NAME
} }
cmd_default() { cmd_default() {
# TODO: Refactor getting this prefix into a general function cmd_list "$@"
PREFIX=$(git config --get gitflow.prefix.feature || echo feature/) }
cmd_list() {
FEATURE_BRANCHES="$(echo "$LOCAL_BRANCHES" | grep "^$PREFIX")" FEATURE_BRANCHES="$(echo "$LOCAL_BRANCHES" | grep "^$PREFIX")"
if [ -z "$FEATURE_BRANCHES" ]; then if [ -z "$FEATURE_BRANCHES" ]; then
warn "No feature branches exist." warn "No feature branches exist."
...@@ -62,6 +57,18 @@ cmd_help() { ...@@ -62,6 +57,18 @@ cmd_help() {
exit 0 exit 0
} }
parse_args() {
NAME="$1"
BASE="${2:-$DEVELOP_BRANCH}"
if [ "$NAME" = "" ]; then
echo "Missing argument <name>."
usage
exit 1
fi
PREFIX=$(git config --get gitflow.prefix.feature || echo feature/)
BRANCH=$PREFIX$NAME
}
cmd_start() { cmd_start() {
parse_args "$@" parse_args "$@"
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
# #
usage() { usage() {
echo "usage: git flow hotfix" echo "usage: git flow hotfix [list]"
echo " git flow hotfix start <version> [<base>]" echo " git flow hotfix start <version> [<base>]"
echo " git flow hotfix finish <version> [<base>]" echo " git flow hotfix finish <version> [<base>]"
# TODO # TODO
...@@ -28,21 +28,16 @@ usage() { ...@@ -28,21 +28,16 @@ usage() {
#echo "--push Push to the origin repo when finished" #echo "--push Push to the origin repo when finished"
} }
parse_args() { # setup will always be called before the actual cmd_* functions
VERSION="$1" setup() {
BASE="${2:-$MASTER_BRANCH}"
if [ "$VERSION" = "" ]; then
echo "Missing argument <version>."
usage
exit 1
fi
PREFIX=$(git config --get gitflow.prefix.hotfix || echo hotfix/) PREFIX=$(git config --get gitflow.prefix.hotfix || echo hotfix/)
BRANCH=$PREFIX$VERSION
} }
cmd_default() { cmd_default() {
# TODO: Refactor getting this prefix into a general function cmd_list "$@"
PREFIX=$(git config --get gitflow.prefix.hotfix || echo hotfix/) }
cmd_list() {
HOTFIX_BRANCHES="$(echo "$LOCAL_BRANCHES" | grep "^$PREFIX")" HOTFIX_BRANCHES="$(echo "$LOCAL_BRANCHES" | grep "^$PREFIX")"
if [ -z "$HOTFIX_BRANCHES" ]; then if [ -z "$HOTFIX_BRANCHES" ]; then
warn "No hotfix branches exist." warn "No hotfix branches exist."
...@@ -56,6 +51,18 @@ cmd_help() { ...@@ -56,6 +51,18 @@ cmd_help() {
exit 0 exit 0
} }
parse_args() {
VERSION="$1"
BASE="${2:-$MASTER_BRANCH}"
if [ "$VERSION" = "" ]; then
echo "Missing argument <version>."
usage
exit 1
fi
PREFIX=$(git config --get gitflow.prefix.hotfix || echo hotfix/)
BRANCH=$PREFIX$VERSION
}
cmd_start() { cmd_start() {
parse_args "$@" parse_args "$@"
......
...@@ -16,11 +16,6 @@ usage() { ...@@ -16,11 +16,6 @@ usage() {
echo "usage: git flow init" echo "usage: git flow init"
} }
cmd_help() {
usage
exit 0
}
# Default entry when no SUBACTION is given # Default entry when no SUBACTION is given
cmd_default() { cmd_default() {
echo echo
...@@ -76,3 +71,7 @@ cmd_default() { ...@@ -76,3 +71,7 @@ cmd_default() {
fi fi
} }
cmd_help() {
usage
exit 0
}
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
# #
usage() { usage() {
echo "usage: git flow release" echo "usage: git flow release [list]"
echo " git flow release start <version>" echo " git flow release start <version>"
echo " git flow release finish <version>" echo " git flow release finish <version>"
# TODO # TODO
...@@ -29,21 +29,17 @@ usage() { ...@@ -29,21 +29,17 @@ usage() {
#echo "--push Push to the origin repo when finished" #echo "--push Push to the origin repo when finished"
} }
parse_args() { # setup will always be called before the actual cmd_* functions
VERSION_PREFIX=$(git config --get gitflow.prefix.versiontag) setup() {
VERSION="$1"
if [ "$VERSION" = "" ]; then
echo "Missing argument <version>."
usage
exit 1
fi
PREFIX=$(git config --get gitflow.prefix.release || echo release/) PREFIX=$(git config --get gitflow.prefix.release || echo release/)
BRANCH=$PREFIX$VERSION VERSION_PREFIX=$(git config --get gitflow.prefix.versiontag)
} }
cmd_default() { cmd_default() {
# TODO: Refactor getting this prefix into a general function cmd_list "$@"
PREFIX=$(git config --get gitflow.prefix.release || echo release/) }
cmd_list() {
RELEASE_BRANCHES="$(echo "$LOCAL_BRANCHES" | grep "^$PREFIX")" RELEASE_BRANCHES="$(echo "$LOCAL_BRANCHES" | grep "^$PREFIX")"
if [ -z "$RELEASE_BRANCHES" ]; then if [ -z "$RELEASE_BRANCHES" ]; then
warn "No release branches exist." warn "No release branches exist."
...@@ -57,6 +53,16 @@ cmd_help() { ...@@ -57,6 +53,16 @@ cmd_help() {
exit 0 exit 0
} }
parse_args() {
VERSION="$1"
if [ "$VERSION" = "" ]; then
echo "Missing argument <version>."
usage
exit 1
fi
BRANCH=$PREFIX$VERSION
}
cmd_start() { cmd_start() {
parse_args "$@" parse_args "$@"
......
...@@ -13,26 +13,19 @@ ...@@ -13,26 +13,19 @@
# #
usage() { usage() {
echo "usage: git flow support" echo "usage: git flow support [list]"
echo " git flow support start <version> [<base>]" echo " git flow support start <version> [<base>]"
} }
parse_args() { setup() {
VERSION_PREFIX=$(git config --get gitflow.prefix.versiontag)
VERSION="$1"
BASE="${2:-${VERSION_PREFIX}${VERSION}}"
if [ "$VERSION" = "" ]; then
echo "Missing argument <version>."
usage
exit 1
fi
PREFIX=$(git config --get gitflow.prefix.support || echo support/) PREFIX=$(git config --get gitflow.prefix.support || echo support/)
BRANCH=$PREFIX$VERSION
} }
cmd_default() { cmd_default() {
# TODO: Refactor getting this prefix into a general function cmd_list "$@"
PREFIX=$(git config --get gitflow.prefix.support || echo support/) }
cmd_list() {
SUPPORT_BRANCHES="$(echo "$LOCAL_BRANCHES" | grep "^$PREFIX")" SUPPORT_BRANCHES="$(echo "$LOCAL_BRANCHES" | grep "^$PREFIX")"
if [ -z "$SUPPORT_BRANCHES" ]; then if [ -z "$SUPPORT_BRANCHES" ]; then
warn "No support branches exist." warn "No support branches exist."
...@@ -46,6 +39,19 @@ cmd_help() { ...@@ -46,6 +39,19 @@ cmd_help() {
exit 0 exit 0
} }
parse_args() {
VERSION_PREFIX=$(git config --get gitflow.prefix.versiontag)
VERSION="$1"
BASE="${2:-${VERSION_PREFIX}${VERSION}}"
if [ "$VERSION" = "" ]; then
echo "Missing argument <version>."
usage
exit 1
fi
PREFIX=$(git config --get gitflow.prefix.support || echo support/)
BRANCH=$PREFIX$VERSION
}
cmd_start() { cmd_start() {
parse_args "$@" parse_args "$@"
......
...@@ -17,11 +17,11 @@ usage() { ...@@ -17,11 +17,11 @@ usage() {
echo "usage: git flow version" echo "usage: git flow version"
} }
cmd_default() {
echo "$GITFLOW_VERSION"
}
cmd_help() { cmd_help() {
usage usage
exit 0 exit 0
} }
cmd_default() {
echo "$GITFLOW_VERSION"
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment