blob: a03ba1fd34c9c54270e16382c1d5198bdfbdf517 [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
Vincent Driessen4b9545e2011-11-30 22:52:20 +010045# The sed expression here replaces all backslashes by forward slashes.
46# This helps our Windows users, while not bothering our Unix users.
Vincent Driessen5e8cc9f2011-12-01 08:52:33 +010047export GITFLOW_DIR=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
Benedikt Böhm4a864fb2010-01-26 12:59:27 +010048
Benedikt Böhm00ccea62010-01-26 12:39:36 +010049usage() {
Vincent Driessen186d2b52010-01-27 23:48:39 +010050 echo "usage: git flow <subcommand>"
Benedikt Böhm00ccea62010-01-26 12:39:36 +010051 echo
Vincent Driessen186d2b52010-01-27 23:48:39 +010052 echo "Available subcommands are:"
53 echo " init Initialize a new git repo with support for the branching model."
54 echo " feature Manage your feature branches."
55 echo " release Manage your release branches."
56 echo " hotfix Manage your hotfix branches."
57 echo " support Manage your support branches."
Vincent Driessen3625f392010-01-28 00:13:26 +010058 echo " version Shows version information."
Benedikt Böhm7d703a82010-01-26 13:17:12 +010059 echo
Vincent Driessen186d2b52010-01-27 23:48:39 +010060 echo "Try 'git flow <subcommand> help' for details."
Benedikt Böhm00ccea62010-01-26 12:39:36 +010061}
62
63main() {
Benedikt Böhm427c5db2010-01-26 18:23:44 +010064 if [ $# -lt 1 ]; then
Benedikt Böhm00ccea62010-01-26 12:39:36 +010065 usage
66 exit 1
67 fi
68
Vincent Driessenc3607ac2010-02-05 19:53:45 +010069 # load common functionality
70 . "$GITFLOW_DIR/gitflow-common"
71
Vincent Driessene1ec57d2010-10-18 17:25:12 +020072 # This environmental variable fixes non-POSIX getopt style argument
73 # parsing, effectively breaking git-flow subcommand parsing on several
74 # Linux platforms.
75 export POSIXLY_CORRECT=1
76
Vincent Driessenea58d0f2010-01-30 20:51:03 +010077 # use the shFlags project to parse the command line arguments
Vincent Driessenc3607ac2010-02-05 19:53:45 +010078 . "$GITFLOW_DIR/gitflow-shFlags"
Vincent Driessen44174922010-02-02 23:53:21 +010079 FLAGS_PARENT="git flow"
Vincent Driessenea58d0f2010-01-30 20:51:03 +010080 FLAGS "$@" || exit $?
81 eval set -- "${FLAGS_ARGV}"
82
Benedikt Böhm00ccea62010-01-26 12:39:36 +010083 # sanity checks
Vincent Driessen186d2b52010-01-27 23:48:39 +010084 SUBCOMMAND="$1"; shift
Benedikt Böhm427c5db2010-01-26 18:23:44 +010085
Vincent Driessen186d2b52010-01-27 23:48:39 +010086 if [ ! -e "$GITFLOW_DIR/git-flow-$SUBCOMMAND" ]; then
Benedikt Böhm00ccea62010-01-26 12:39:36 +010087 usage
88 exit 1
89 fi
90
Benedikt Böhm00ccea62010-01-26 12:39:36 +010091 # run command
Vincent Driessen186d2b52010-01-27 23:48:39 +010092 . "$GITFLOW_DIR/git-flow-$SUBCOMMAND"
Vincent Driessen44174922010-02-02 23:53:21 +010093 FLAGS_PARENT="git flow $SUBCOMMAND"
Benedikt Böhm00ccea62010-01-26 12:39:36 +010094
Vincent Driessen1b819232010-02-01 15:51:43 +010095 # test if the first argument is a flag (i.e. starts with '-')
96 # in that case, we interpret this arg as a flag for the default
97 # command
98 SUBACTION="default"
Gruen Christian-Rolf (Kiki)06e854a2011-07-06 18:07:01 +030099 if [ "$1" != "" ] && { ! echo "$1" | grep -q "^-"; } then
Vincent Driessen1b819232010-02-01 15:51:43 +0100100 SUBACTION="$1"; shift
101 fi
Vincent Driessen283b0f72010-02-15 23:23:14 +0100102 if ! type "cmd_$SUBACTION" >/dev/null 2>&1; then
Vincent Driessen92770242010-02-04 11:49:47 +0100103 warn "Unknown subcommand: '$SUBACTION'"
Vincent Driessen186d2b52010-01-27 23:48:39 +0100104 usage
105 exit 1
Benedikt Böhm427c5db2010-01-26 18:23:44 +0100106 fi
107
Vincent Driessen186d2b52010-01-27 23:48:39 +0100108 # run the specified action
109 cmd_$SUBACTION "$@"
Benedikt Böhm427c5db2010-01-26 18:23:44 +0100110}
111
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100112main "$@"