Merge branch 'feature/flip-args' into develop
diff --git a/README.mdown b/README.mdown
index 70a8b1b..f1232dc 100644
--- a/README.mdown
+++ b/README.mdown
@@ -5,17 +5,9 @@
 blog post").
 
 
-Release 0.1
------------
-A quick release of version 0.1 has arrived. The main scripts are functional and
-should be usable under "normal" use.
-
-There have barely been any real-world tests, but I encourage you to start using
-it actively. [Feedback](http://github.com/nvie/gitflow/issues) is also very
-welcome. See the "Please help out" section below, also.
-
-**Make sure to validate the modifications to your repo after running any of the
-`git-flow` commands, before pushing them permanently.**
+> **IMPORTANT NOTE:**  
+> In release 0.2, the order of the arguments has changed to provide a logical
+> subcommand hierarchy.
 
 
 Installing git-flow
@@ -60,35 +52,31 @@
   
   		git flow init
 
-* To start a new feature branch, use:
+* List all feature branches:
   
-  		git flow start feature <name> [<base>]
-  		git flow start feature foo-support
+  		git flow feature
   
-  `base` is `develop` by default.
+* To list/start/finish feature branches, use:
+  
+  		git flow feature
+  		git flow feature start <name> [<base>]
+  		git flow feature finish <name>
+  
+  (`base` is `develop` by default)
 
-* To finish this feature and have it merged into `develop`, use:
+* To list/start/finish release branches, use:
   
-  		git flow finish feature <name>
-  		git flow finish feature foo-support
+  		git flow release 
+  		git flow release start <release>
+  		git flow release finish <release>
   
-* To start a new release branch for 2.0, based on the 1.1 production release, use:
+* To list/start/finish hotfix branches, use:
   
-  		git flow start release <release>
-  		git flow start release 2.0
+  		git flow hotfix start <release> [<base-release>]
+  		git flow hotfix finish <release>
+
+* To list/start support branches, use:
   
-* To finish the release branch (i.e. to make an actual production release), use:
-  
-  		git flow finish release <release>
-  		git flow finish release 2.0
-  
-* To start a new hotfix branch for 2.1, based on the 2.0 production release, use:
-  
-  		git flow start hotfix <release> [<base-release>]
-  		git flow start hotfix 2.1 2.0
-  
-* To finish the hotfix branch, use:
-  
-  		git flow finish hotfix <release>
-  		git flow finish hotfix 2.1
+  		git flow support
+  		git flow support start <release> [<base-release>]
 
diff --git a/bump-version b/bump-version
index f8ae3de..f7494c9 100755
--- a/bump-version
+++ b/bump-version
@@ -8,6 +8,11 @@
 	exit 1
 fi
 
-echo "GITFLOW_VERSION=$1" > git-flow-version
+if ! sed 's/^GITFLOW_VERSION=.*$/GITFLOW_VERSION='$1'/g' git-flow-version > .git-flow-version.new; then
+	echo "Could not replace GITFLOW_VERSION variable." >&2
+	exit 2
+fi
+
+mv .git-flow-version.new git-flow-version
 git add git-flow-version
 git commit -m "Bumped version number to $1" git-flow-version
diff --git a/git-flow b/git-flow
index f44f261..de8d9a1 100755
--- a/git-flow
+++ b/git-flow
@@ -33,15 +33,17 @@
 }
 
 usage() {
-	. "$GITFLOW_DIR/git-flow-version"
-	echo "git-flow, version $GITFLOW_VERSION"
+	echo "usage: git flow <subcommand>"
 	echo
-	echo "usage: git flow <cmd> <type> <args>"
-	echo "       git flow init [<url>]"
+	echo "Available subcommands are:"
+	echo "   init      Initialize a new git repo with support for the branching model."
+	echo "   feature   Manage your feature branches."
+	echo "   release   Manage your release branches."
+	echo "   hotfix    Manage your hotfix branches."
+	echo "   support   Manage your support branches."
+	echo "   version   Shows version information."
 	echo
-	echo "<type> can be any of: feature, release, hotfix, support"
-	echo
-	echo "Try 'git flow help <type>' for details."
+	echo "Try 'git flow <subcommand> help' for details."
 }
 
 main() {
@@ -51,16 +53,9 @@
 	fi
 
 	# sanity checks
-	ACTION="$1"; shift
+	SUBCOMMAND="$1"; shift
 
-	if [ "$ACTION" = "init" ]; then
-		gitflow_init "$@"
-		exit 0
-	fi
-
-	BTYPE="$1"; shift
-
-	if [ ! -e "$GITFLOW_DIR/git-flow-$BTYPE" ]; then
+	if [ ! -e "$GITFLOW_DIR/git-flow-$SUBCOMMAND" ]; then
 		usage
 		exit 1
 	fi
@@ -75,69 +70,27 @@
 	ALL_BRANCHES="$LOCAL_BRANCHES $REMOTE_BRANCHES"
 
 	# run command
-	. "$GITFLOW_DIR/git-flow-$BTYPE"
+	. "$GITFLOW_DIR/git-flow-$SUBCOMMAND"
 
-	if ! typeset -f cmd_$ACTION >/dev/null; then
+	if ! typeset -f sub_main >/dev/null; then
 		usage
 		exit 1
 	fi
 
 	# run command
-	cmd_$ACTION "$@"
+	sub_main "$@"
 }
 
-gitflow_init() {
-	echo
-	echo "Summary of actions:"
-
-	if ! git rev-parse --git-dir 2>&1 >/dev/null; then
-		git init --quiet
-		echo "- A new git repository at $PWD was created"
+sub_main() {
+	SUBACTION="${1:-default}"; shift
+	if ! typeset -f cmd_$SUBACTION 2>&1 >/dev/null; then
+		warn "Unknown subcommand: '$1'"
+		usage
+		exit 1
 	fi
 
-	if ! git rev-parse --quiet --verify HEAD 2>&1 >/dev/null; then
-		touch $README
-		git add $README
-		git commit --quiet -m "initial commit"
-		if [ "$MASTER_BRANCH" != "master" ]; then
-			git branch -m master $MASTER_BRANCH
-		fi
-		echo "- An initial commit was created at branch '$MASTER_BRANCH'"
-	fi
-
-	if ! git rev-parse --verify $MASTER_BRANCH 2>&1 >/dev/null; then
-		die "Cannot find your master branch. Try: git branch -m <mymaster> $MASTER_BRANCH"
-	fi
-
-	gitflow_check_clean_working_tree
-
-	if git remote | grep -q $ORIGIN; then
-		git fetch -q $ORIGIN
-		gitflow_require_branches_equal $MASTER_BRANCH $ORIGIN/$MASTER_BRANCH
-	fi
-
-	if git rev-parse --verify $DEVELOP_BRANCH 2>&1 >/dev/null; then
-		gitflow_require_branches_equal $DEVELOP_BRANCH $ORIGIN/$DEVELOP_BRANCH
-	else
-		git checkout -q -b $DEVELOP_BRANCH $MASTER_BRANCH
-		echo "- A new branch '$DEVELOP_BRANCH' was created"
-		echo "- You are now on branch '$DEVELOP_BRANCH'"
-	fi
-
-	if ! git remote | grep -q $ORIGIN; then
-		if [ "$1" = "" ]; then
-			echo "- No remote location was added. Try: git remote add $ORIGIN <url>"
-		else
-			git remote add $ORIGIN $1
-			echo "- A new remote location '$1' was added"
-		fi
-	fi
-
-	echo
-
-	if git remote | grep -q $ORIGIN; then
-		git push $ORIGIN $MASTER_BRANCH $DEVELOP_BRANCH
-	fi
+	# run the specified action
+	cmd_$SUBACTION "$@"
 }
 
 gitflow_check_clean_working_tree() {
diff --git a/git-flow-feature b/git-flow-feature
index 663e788..6f3a0bb 100644
--- a/git-flow-feature
+++ b/git-flow-feature
@@ -13,12 +13,12 @@
 #
 
 usage() {
-	echo "usage: git flow list feature"
-	echo "       git flow start feature <name> [<base>]"
-	echo "       git flow finish feature <name> [<base>]"
-	echo "       git flow publish feature <name>"
-	echo "       git flow track feature <name>"
-	echo "       git flow diff feature <name>"
+	echo "usage: git flow feature"
+	echo "       git flow feature start <name> [<base>]"
+	echo "       git flow feature finish <name> [<base>]"
+	echo "       git flow feature publish <name>"
+	echo "       git flow feature track <name>"
+	echo "       git flow feature diff <name>"
 	# TODO
 	#echo ""
 	#echo "options:"
@@ -46,6 +46,17 @@
 	BRANCH=$PREFIX$NAME
 }
 
+cmd_default() {
+	# TODO: Refactor getting this prefix into a general function
+	PREFIX=$(git config --get gitflow.prefix.feature || echo feature/)
+	FEATURE_BRANCHES="$(echo "$LOCAL_BRANCHES" | grep "^$PREFIX")"
+	if [ -z "$FEATURE_BRANCHES" ]; then
+		warn "No feature branches exist."
+		exit 0
+	fi
+	echo "$FEATURE_BRANCHES" | sed "s?^$PREFIX??g"
+}
+
 cmd_help() {
 	usage
 	exit 0
@@ -157,17 +168,6 @@
 	echo
 }
 
-cmd_list() {
-	# TODO: refactor this, because passing in this dummy "foo" is really ugly!
-	parse_args "$@" foo
-	FEATURE_BRANCHES="$(echo "$LOCAL_BRANCHES" | grep "^$PREFIX")"
-	if [ -z "$FEATURE_BRANCHES" ]; then
-		warn "No feature branches exist."
-		exit 0
-	fi
-	echo "$FEATURE_BRANCHES" | sed "s?^$PREFIX??g"
-}
-
 cmd_diff() {
 	parse_args "$@"
 	# TODO: if this feature has been based on a non-develop branch, we really
diff --git a/git-flow-hotfix b/git-flow-hotfix
index 47b2bd7..d921762 100644
--- a/git-flow-hotfix
+++ b/git-flow-hotfix
@@ -13,8 +13,9 @@
 #
 
 usage() {
-	echo "usage: git flow start hotfix <version> [<base>]"
-	echo "       git flow finish hotfix <version> [<base>]"
+	echo "usage: git flow hotfix"
+	echo "       git flow hotfix start <version> [<base>]"
+	echo "       git flow hotfix finish <version> [<base>]"
 	# TODO
 	#echo ""
 	#echo "options:"
@@ -39,6 +40,17 @@
 	BRANCH=$PREFIX$VERSION
 }
 
+cmd_default() {
+	# TODO: Refactor getting this prefix into a general function
+	PREFIX=$(git config --get gitflow.prefix.hotfix || echo hotfix/)
+	HOTFIX_BRANCHES="$(echo "$LOCAL_BRANCHES" | grep "^$PREFIX")"
+	if [ -z "$HOTFIX_BRANCHES" ]; then
+		warn "No hotfix branches exist."
+		exit 0
+	fi
+	echo "$HOTFIX_BRANCHES" | sed "s?^$PREFIX??g"
+}
+
 cmd_help() {
 	usage
 	exit 0
diff --git a/git-flow-init b/git-flow-init
new file mode 100644
index 0000000..84ba142
--- /dev/null
+++ b/git-flow-init
@@ -0,0 +1,78 @@
+#
+# git-flow -- A collection of Git extensions to provide high-level
+# repository operations for Vincent Driessen's branching model.
+#
+# Original blog post presenting this model is found at:
+#    http://nvie.com/archives/323
+#
+# Feel free to contribute to this project at:
+#    http://github.com/nvie/gitflow
+#
+# Copyright (c) 2010 by Vincent Driessen
+# Copyright (c) 2010 by Benedikt Böhm
+#
+
+usage() {
+	echo "usage: git flow init"
+}
+
+cmd_help() {
+	usage
+	exit 0
+}
+
+# Default entry when no SUBACTION is given
+cmd_default() {
+	echo
+	echo "Summary of actions:"
+
+	if ! git rev-parse --git-dir 2>&1 >/dev/null; then
+		git init --quiet
+		echo "- A new git repository at $PWD was created"
+	fi
+
+	if ! git rev-parse --quiet --verify HEAD 2>&1 >/dev/null; then
+		touch $README
+		git add $README
+		git commit --quiet -m "initial commit"
+		if [ "$MASTER_BRANCH" != "master" ]; then
+			git branch -m master $MASTER_BRANCH
+		fi
+		echo "- An initial commit was created at branch '$MASTER_BRANCH'"
+	fi
+
+	if ! git rev-parse --verify $MASTER_BRANCH 2>&1 >/dev/null; then
+		die "Cannot find your master branch. Try: git branch -m <mymaster> $MASTER_BRANCH"
+	fi
+
+	gitflow_check_clean_working_tree
+
+	if git remote | grep -q $ORIGIN; then
+		git fetch -q $ORIGIN
+		gitflow_require_branches_equal $MASTER_BRANCH $ORIGIN/$MASTER_BRANCH
+	fi
+
+	if git rev-parse --verify $DEVELOP_BRANCH 2>&1 >/dev/null; then
+		gitflow_require_branches_equal $DEVELOP_BRANCH $ORIGIN/$DEVELOP_BRANCH
+	else
+		git checkout -q -b $DEVELOP_BRANCH $MASTER_BRANCH
+		echo "- A new branch '$DEVELOP_BRANCH' was created"
+		echo "- You are now on branch '$DEVELOP_BRANCH'"
+	fi
+
+	if ! git remote | grep -q $ORIGIN; then
+		if [ "$1" = "" ]; then
+			echo "- No remote location was added. Try: git remote add $ORIGIN <url>"
+		else
+			git remote add $ORIGIN $1
+			echo "- A new remote location '$1' was added"
+		fi
+	fi
+
+	echo
+
+	if git remote | grep -q $ORIGIN; then
+		git push $ORIGIN $MASTER_BRANCH $DEVELOP_BRANCH
+	fi
+}
+
diff --git a/git-flow-release b/git-flow-release
index aebffa1..1fec600 100644
--- a/git-flow-release
+++ b/git-flow-release
@@ -13,8 +13,9 @@
 #
 
 usage() {
-	echo "usage: git flow start release <version>"
-	echo "       git flow finish release <version>"
+	echo "usage: git flow release"
+	echo "       git flow release start <version>"
+	echo "       git flow release finish <version>"
 	# TODO
 	#echo ""
 	#echo "options:"
@@ -40,6 +41,17 @@
 	BRANCH=$PREFIX$VERSION
 }
 
+cmd_default() {
+	# TODO: Refactor getting this prefix into a general function
+	PREFIX=$(git config --get gitflow.prefix.release || echo release/)
+	RELEASE_BRANCHES="$(echo "$LOCAL_BRANCHES" | grep "^$PREFIX")"
+	if [ -z "$RELEASE_BRANCHES" ]; then
+		warn "No release branches exist."
+		exit 0
+	fi
+	echo "$RELEASE_BRANCHES" | sed "s?^$PREFIX??g"
+}
+
 cmd_help() {
 	usage
 	exit 0
diff --git a/git-flow-support b/git-flow-support
index d855eaa..adb336d 100644
--- a/git-flow-support
+++ b/git-flow-support
@@ -13,7 +13,8 @@
 #
 
 usage() {
-	echo "usage: git flow start support <version> [<base>]"
+	echo "usage: git flow support"
+	echo "       git flow support start <version> [<base>]"
 }
 
 parse_args() {
@@ -29,6 +30,17 @@
 	BRANCH=$PREFIX$VERSION
 }
 
+cmd_default() {
+	# TODO: Refactor getting this prefix into a general function
+	PREFIX=$(git config --get gitflow.prefix.support || echo support/)
+	SUPPORT_BRANCHES="$(echo "$LOCAL_BRANCHES" | grep "^$PREFIX")"
+	if [ -z "$SUPPORT_BRANCHES" ]; then
+		warn "No support branches exist."
+		exit 0
+	fi
+	echo "$SUPPORT_BRANCHES" | sed "s?^$PREFIX??g"
+}
+
 cmd_help() {
 	usage
 	exit 0
diff --git a/git-flow-version b/git-flow-version
index ae551c6..cbb66b6 100644
--- a/git-flow-version
+++ b/git-flow-version
@@ -1 +1,27 @@
+#
+# git-flow -- A collection of Git extensions to provide high-level
+# repository operations for Vincent Driessen's branching model.
+#
+# Original blog post presenting this model is found at:
+#    http://nvie.com/archives/323
+#
+# Feel free to contribute to this project at:
+#    http://github.com/nvie/gitflow
+#
+# Copyright (c) 2010 by Vincent Driessen
+# Copyright (c) 2010 by Benedikt Böhm
+#
 GITFLOW_VERSION=0.2-dirty
+
+usage() {
+	echo "usage: git flow version"
+}
+
+cmd_help() {
+	usage
+	exit 0
+}
+
+cmd_default() {
+	echo "$GITFLOW_VERSION"
+}