blob: 84adc05e4f4e8aa33c69b4c74bc2e2c699177224 [file] [log] [blame]
Benedikt Böhme2fa4912010-01-26 14:41:20 +01001#!/bin/sh
Benedikt Böhm00ccea62010-01-26 12:39:36 +01002#
Vincent Driessen6c2d30b2010-01-26 22:18:36 +01003# git-flow -- A collection of Git extensions to provide high-level
4# repository operations for Vincent Driessen's branching model.
Benedikt Böhm00ccea62010-01-26 12:39:36 +01005#
6# Original blog post presenting this model is found at:
7# http://nvie.com/archives/323
8#
9# Feel free to contribute to this project at:
10# http://github.com/nvie/gitflow
11#
12# Copyright (c) 2010 by Vincent Driessen
13# Copyright (c) 2010 by Benedikt Böhm
14#
15
Benedikt Böhme5eaff92010-01-26 12:44:55 +010016# enable debug mode
17if [ "$DEBUG" = "yes" ]; then
18 set -x
19fi
20
Benedikt Böhm4a864fb2010-01-26 12:59:27 +010021export GITFLOW_DIR=$(dirname "$0")
Benedikt Böhm4a864fb2010-01-26 12:59:27 +010022
Benedikt Böhm00ccea62010-01-26 12:39:36 +010023usage() {
Vincent Driessen186d2b52010-01-27 23:48:39 +010024 echo "usage: git flow <subcommand>"
Benedikt Böhm00ccea62010-01-26 12:39:36 +010025 echo
Vincent Driessen186d2b52010-01-27 23:48:39 +010026 echo "Available subcommands are:"
27 echo " init Initialize a new git repo with support for the branching model."
28 echo " feature Manage your feature branches."
29 echo " release Manage your release branches."
30 echo " hotfix Manage your hotfix branches."
31 echo " support Manage your support branches."
Vincent Driessen3625f392010-01-28 00:13:26 +010032 echo " version Shows version information."
Benedikt Böhm7d703a82010-01-26 13:17:12 +010033 echo
Vincent Driessen186d2b52010-01-27 23:48:39 +010034 echo "Try 'git flow <subcommand> help' for details."
Benedikt Böhm00ccea62010-01-26 12:39:36 +010035}
36
37main() {
Benedikt Böhm427c5db2010-01-26 18:23:44 +010038 if [ $# -lt 1 ]; then
Benedikt Böhm00ccea62010-01-26 12:39:36 +010039 usage
40 exit 1
41 fi
42
Vincent Driessenc3607ac2010-02-05 19:53:45 +010043 # load common functionality
44 . "$GITFLOW_DIR/gitflow-common"
45
Vincent Driessenea58d0f2010-01-30 20:51:03 +010046 # use the shFlags project to parse the command line arguments
Vincent Driessenc3607ac2010-02-05 19:53:45 +010047 . "$GITFLOW_DIR/gitflow-shFlags"
Vincent Driessen44174922010-02-02 23:53:21 +010048 FLAGS_PARENT="git flow"
Vincent Driessenea58d0f2010-01-30 20:51:03 +010049 FLAGS "$@" || exit $?
50 eval set -- "${FLAGS_ARGV}"
51
Benedikt Böhm00ccea62010-01-26 12:39:36 +010052 # sanity checks
Vincent Driessen186d2b52010-01-27 23:48:39 +010053 SUBCOMMAND="$1"; shift
Benedikt Böhm427c5db2010-01-26 18:23:44 +010054
Vincent Driessen186d2b52010-01-27 23:48:39 +010055 if [ ! -e "$GITFLOW_DIR/git-flow-$SUBCOMMAND" ]; then
Benedikt Böhm00ccea62010-01-26 12:39:36 +010056 usage
57 exit 1
58 fi
59
Benedikt Böhm00ccea62010-01-26 12:39:36 +010060 # run command
Vincent Driessen186d2b52010-01-27 23:48:39 +010061 . "$GITFLOW_DIR/git-flow-$SUBCOMMAND"
Vincent Driessen44174922010-02-02 23:53:21 +010062 FLAGS_PARENT="git flow $SUBCOMMAND"
Benedikt Böhm00ccea62010-01-26 12:39:36 +010063
Vincent Driessen1b819232010-02-01 15:51:43 +010064 # test if the first argument is a flag (i.e. starts with '-')
65 # in that case, we interpret this arg as a flag for the default
66 # command
67 SUBACTION="default"
68 if [ "$1" != "" ] && ! echo "$1" | grep -q "^-"; then
69 SUBACTION="$1"; shift
70 fi
Vincent Driessen283b0f72010-02-15 23:23:14 +010071 if ! type "cmd_$SUBACTION" >/dev/null 2>&1; then
Vincent Driessen92770242010-02-04 11:49:47 +010072 warn "Unknown subcommand: '$SUBACTION'"
Vincent Driessen186d2b52010-01-27 23:48:39 +010073 usage
74 exit 1
Benedikt Böhm427c5db2010-01-26 18:23:44 +010075 fi
76
Vincent Driessen186d2b52010-01-27 23:48:39 +010077 # run the specified action
78 cmd_$SUBACTION "$@"
Benedikt Böhm427c5db2010-01-26 18:23:44 +010079}
80
Vincent Driessen3c337fb2010-02-04 11:30:18 +010081# helper functions for common reuse
82max() { if [ "$1" -gt "$2" ]; then echo "$1"; else echo "$2"; fi; }
83
Vincent Driessen44174922010-02-02 23:53:21 +010084# convenience functions for checking whether flags have been set or not
85flag() { eval FLAG=\$FLAGS_$1; [ $FLAG -eq $FLAGS_TRUE ]; }
86noflag() { eval FLAG=\$FLAGS_$1; [ $FLAG -ne $FLAGS_TRUE ]; }
87
Benedikt Böhm00ccea62010-01-26 12:39:36 +010088main "$@"