blob: 573aa25e14de55d6f31cce0cdbfe163e0ed42f04 [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")
Vincent Driessenc3607ac2010-02-05 19:53:45 +010022export GIT_DIR=$(git rev-parse --git-dir)
Benedikt Böhm4a864fb2010-01-26 12:59:27 +010023export MASTER_BRANCH=$(git config --get gitflow.branch.master || echo master)
24export DEVELOP_BRANCH=$(git config --get gitflow.branch.develop || echo develop)
Benedikt Böhm350e7152010-01-26 13:05:05 +010025export ORIGIN=$(git config --get gitflow.origin || echo origin)
Benedikt Böhm427c5db2010-01-26 18:23:44 +010026export README=$(git config --get gitflow.readme || echo README)
Benedikt Böhm4a864fb2010-01-26 12:59:27 +010027
Benedikt Böhm00ccea62010-01-26 12:39:36 +010028usage() {
Vincent Driessen186d2b52010-01-27 23:48:39 +010029 echo "usage: git flow <subcommand>"
Benedikt Böhm00ccea62010-01-26 12:39:36 +010030 echo
Vincent Driessen186d2b52010-01-27 23:48:39 +010031 echo "Available subcommands are:"
32 echo " init Initialize a new git repo with support for the branching model."
33 echo " feature Manage your feature branches."
34 echo " release Manage your release branches."
35 echo " hotfix Manage your hotfix branches."
36 echo " support Manage your support branches."
Vincent Driessen3625f392010-01-28 00:13:26 +010037 echo " version Shows version information."
Benedikt Böhm7d703a82010-01-26 13:17:12 +010038 echo
Vincent Driessen186d2b52010-01-27 23:48:39 +010039 echo "Try 'git flow <subcommand> help' for details."
Benedikt Böhm00ccea62010-01-26 12:39:36 +010040}
41
42main() {
Benedikt Böhm427c5db2010-01-26 18:23:44 +010043 if [ $# -lt 1 ]; then
Benedikt Böhm00ccea62010-01-26 12:39:36 +010044 usage
45 exit 1
46 fi
47
Vincent Driessenc3607ac2010-02-05 19:53:45 +010048 # load common functionality
49 . "$GITFLOW_DIR/gitflow-common"
50
Vincent Driessenea58d0f2010-01-30 20:51:03 +010051 # use the shFlags project to parse the command line arguments
Vincent Driessenc3607ac2010-02-05 19:53:45 +010052 . "$GITFLOW_DIR/gitflow-shFlags"
Vincent Driessen44174922010-02-02 23:53:21 +010053 FLAGS_PARENT="git flow"
Vincent Driessenea58d0f2010-01-30 20:51:03 +010054 FLAGS "$@" || exit $?
55 eval set -- "${FLAGS_ARGV}"
56
Benedikt Böhm00ccea62010-01-26 12:39:36 +010057 # sanity checks
Vincent Driessen186d2b52010-01-27 23:48:39 +010058 SUBCOMMAND="$1"; shift
Benedikt Böhm427c5db2010-01-26 18:23:44 +010059
Vincent Driessen186d2b52010-01-27 23:48:39 +010060 if [ ! -e "$GITFLOW_DIR/git-flow-$SUBCOMMAND" ]; then
Benedikt Böhm00ccea62010-01-26 12:39:36 +010061 usage
62 exit 1
63 fi
64
Vincent Driessen2ba9a4d2010-01-27 12:51:07 +010065 if ! git rev-parse --git-dir >/dev/null; then
Benedikt Böhm00ccea62010-01-26 12:39:36 +010066 die "Not a git repository"
67 fi
68
Benedikt Böhm00ccea62010-01-26 12:39:36 +010069 # run command
Vincent Driessen186d2b52010-01-27 23:48:39 +010070 . "$GITFLOW_DIR/git-flow-$SUBCOMMAND"
Vincent Driessen44174922010-02-02 23:53:21 +010071 FLAGS_PARENT="git flow $SUBCOMMAND"
Benedikt Böhm00ccea62010-01-26 12:39:36 +010072
Vincent Driessen1b819232010-02-01 15:51:43 +010073 # test if the first argument is a flag (i.e. starts with '-')
74 # in that case, we interpret this arg as a flag for the default
75 # command
76 SUBACTION="default"
77 if [ "$1" != "" ] && ! echo "$1" | grep -q "^-"; then
78 SUBACTION="$1"; shift
79 fi
Vincent Driessene1684872010-02-02 06:33:53 +010080 if ! typeset -f "cmd_$SUBACTION" 2>&1 >/dev/null; then
Vincent Driessen92770242010-02-04 11:49:47 +010081 warn "Unknown subcommand: '$SUBACTION'"
Vincent Driessen186d2b52010-01-27 23:48:39 +010082 usage
83 exit 1
Benedikt Böhm427c5db2010-01-26 18:23:44 +010084 fi
85
Vincent Driessen186d2b52010-01-27 23:48:39 +010086 # run the specified action
87 cmd_$SUBACTION "$@"
Benedikt Böhm427c5db2010-01-26 18:23:44 +010088}
89
Vincent Driessen3c337fb2010-02-04 11:30:18 +010090# helper functions for common reuse
91max() { if [ "$1" -gt "$2" ]; then echo "$1"; else echo "$2"; fi; }
92
Vincent Driessen44174922010-02-02 23:53:21 +010093# convenience functions for checking whether flags have been set or not
94flag() { eval FLAG=\$FLAGS_$1; [ $FLAG -eq $FLAGS_TRUE ]; }
95noflag() { eval FLAG=\$FLAGS_$1; [ $FLAG -ne $FLAGS_TRUE ]; }
96
Benedikt Böhm00ccea62010-01-26 12:39:36 +010097main "$@"