blob: fa87e71f4d792bf0cca3b0ec24baab36d3a52fbf [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:
Vincent Driessenddb350b2010-07-09 09:42:09 +02007# http://nvie.com/git-model
Benedikt Böhm00ccea62010-01-26 12:39:36 +01008#
9# Feel free to contribute to this project at:
10# http://github.com/nvie/gitflow
11#
Vincent Driessend72acba2010-04-04 16:10:17 +020012# Copyright 2010 Vincent Driessen. All rights reserved.
13#
14# Redistribution and use in source and binary forms, with or without
15# modification, are permitted provided that the following conditions are met:
16#
17# 1. Redistributions of source code must retain the above copyright notice,
18# this list of conditions and the following disclaimer.
19#
20# 2. Redistributions in binary form must reproduce the above copyright
21# notice, this list of conditions and the following disclaimer in the
22# documentation and/or other materials provided with the distribution.
23#
24# THIS SOFTWARE IS PROVIDED BY VINCENT DRIESSEN ``AS IS'' AND ANY EXPRESS OR
25# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
26# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
27# EVENT SHALL VINCENT DRIESSEN OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
28# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
31# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
33# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34#
35# The views and conclusions contained in the software and documentation are
36# those of the authors and should not be interpreted as representing official
37# policies, either expressed or implied, of Vincent Driessen.
Benedikt Böhm00ccea62010-01-26 12:39:36 +010038#
39
Benedikt Böhme5eaff92010-01-26 12:44:55 +010040# enable debug mode
41if [ "$DEBUG" = "yes" ]; then
42 set -x
43fi
44
Benedikt Böhm4a864fb2010-01-26 12:59:27 +010045export GITFLOW_DIR=$(dirname "$0")
Benedikt Böhm4a864fb2010-01-26 12:59:27 +010046
Benedikt Böhm00ccea62010-01-26 12:39:36 +010047usage() {
Vincent Driessen186d2b52010-01-27 23:48:39 +010048 echo "usage: git flow <subcommand>"
Benedikt Böhm00ccea62010-01-26 12:39:36 +010049 echo
Vincent Driessen186d2b52010-01-27 23:48:39 +010050 echo "Available subcommands are:"
51 echo " init Initialize a new git repo with support for the branching model."
52 echo " feature Manage your feature branches."
53 echo " release Manage your release branches."
54 echo " hotfix Manage your hotfix branches."
55 echo " support Manage your support branches."
Vincent Driessen3625f392010-01-28 00:13:26 +010056 echo " version Shows version information."
Benedikt Böhm7d703a82010-01-26 13:17:12 +010057 echo
Vincent Driessen186d2b52010-01-27 23:48:39 +010058 echo "Try 'git flow <subcommand> help' for details."
Benedikt Böhm00ccea62010-01-26 12:39:36 +010059}
60
61main() {
Benedikt Böhm427c5db2010-01-26 18:23:44 +010062 if [ $# -lt 1 ]; then
Benedikt Böhm00ccea62010-01-26 12:39:36 +010063 usage
64 exit 1
65 fi
66
Vincent Driessenc3607ac2010-02-05 19:53:45 +010067 # load common functionality
68 . "$GITFLOW_DIR/gitflow-common"
69
Vincent Driessene1ec57d2010-10-18 17:25:12 +020070 # This environmental variable fixes non-POSIX getopt style argument
71 # parsing, effectively breaking git-flow subcommand parsing on several
72 # Linux platforms.
73 export POSIXLY_CORRECT=1
74
Vincent Driessenea58d0f2010-01-30 20:51:03 +010075 # use the shFlags project to parse the command line arguments
Vincent Driessenc3607ac2010-02-05 19:53:45 +010076 . "$GITFLOW_DIR/gitflow-shFlags"
Vincent Driessen44174922010-02-02 23:53:21 +010077 FLAGS_PARENT="git flow"
Vincent Driessenea58d0f2010-01-30 20:51:03 +010078 FLAGS "$@" || exit $?
79 eval set -- "${FLAGS_ARGV}"
80
Benedikt Böhm00ccea62010-01-26 12:39:36 +010081 # sanity checks
Vincent Driessen186d2b52010-01-27 23:48:39 +010082 SUBCOMMAND="$1"; shift
Benedikt Böhm427c5db2010-01-26 18:23:44 +010083
Vincent Driessen186d2b52010-01-27 23:48:39 +010084 if [ ! -e "$GITFLOW_DIR/git-flow-$SUBCOMMAND" ]; then
Benedikt Böhm00ccea62010-01-26 12:39:36 +010085 usage
86 exit 1
87 fi
88
Benedikt Böhm00ccea62010-01-26 12:39:36 +010089 # run command
Vincent Driessen186d2b52010-01-27 23:48:39 +010090 . "$GITFLOW_DIR/git-flow-$SUBCOMMAND"
Vincent Driessen44174922010-02-02 23:53:21 +010091 FLAGS_PARENT="git flow $SUBCOMMAND"
Benedikt Böhm00ccea62010-01-26 12:39:36 +010092
Vincent Driessen1b819232010-02-01 15:51:43 +010093 # test if the first argument is a flag (i.e. starts with '-')
94 # in that case, we interpret this arg as a flag for the default
95 # command
96 SUBACTION="default"
97 if [ "$1" != "" ] && ! echo "$1" | grep -q "^-"; then
98 SUBACTION="$1"; shift
99 fi
Vincent Driessen283b0f72010-02-15 23:23:14 +0100100 if ! type "cmd_$SUBACTION" >/dev/null 2>&1; then
Vincent Driessen92770242010-02-04 11:49:47 +0100101 warn "Unknown subcommand: '$SUBACTION'"
Vincent Driessen186d2b52010-01-27 23:48:39 +0100102 usage
103 exit 1
Benedikt Böhm427c5db2010-01-26 18:23:44 +0100104 fi
105
Vincent Driessen186d2b52010-01-27 23:48:39 +0100106 # run the specified action
107 cmd_$SUBACTION "$@"
Benedikt Böhm427c5db2010-01-26 18:23:44 +0100108}
109
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100110main "$@"