Benedikt Böhm | e2fa491 | 2010-01-26 14:41:20 +0100 | [diff] [blame] | 1 | #!/bin/sh |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 2 | # |
Vincent Driessen | 6c2d30b | 2010-01-26 22:18:36 +0100 | [diff] [blame] | 3 | # git-flow -- A collection of Git extensions to provide high-level |
| 4 | # repository operations for Vincent Driessen's branching model. |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 5 | # |
| 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öhm | e5eaff9 | 2010-01-26 12:44:55 +0100 | [diff] [blame] | 16 | # enable debug mode |
| 17 | if [ "$DEBUG" = "yes" ]; then |
| 18 | set -x |
| 19 | fi |
| 20 | |
Benedikt Böhm | 4a864fb | 2010-01-26 12:59:27 +0100 | [diff] [blame] | 21 | export GITFLOW_DIR=$(dirname "$0") |
Vincent Driessen | c3607ac | 2010-02-05 19:53:45 +0100 | [diff] [blame] | 22 | export GIT_DIR=$(git rev-parse --git-dir) |
Benedikt Böhm | 4a864fb | 2010-01-26 12:59:27 +0100 | [diff] [blame] | 23 | export MASTER_BRANCH=$(git config --get gitflow.branch.master || echo master) |
| 24 | export DEVELOP_BRANCH=$(git config --get gitflow.branch.develop || echo develop) |
Benedikt Böhm | 350e715 | 2010-01-26 13:05:05 +0100 | [diff] [blame] | 25 | export ORIGIN=$(git config --get gitflow.origin || echo origin) |
Benedikt Böhm | 427c5db | 2010-01-26 18:23:44 +0100 | [diff] [blame] | 26 | export README=$(git config --get gitflow.readme || echo README) |
Benedikt Böhm | 4a864fb | 2010-01-26 12:59:27 +0100 | [diff] [blame] | 27 | |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 28 | usage() { |
Vincent Driessen | 186d2b5 | 2010-01-27 23:48:39 +0100 | [diff] [blame] | 29 | echo "usage: git flow <subcommand>" |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 30 | echo |
Vincent Driessen | 186d2b5 | 2010-01-27 23:48:39 +0100 | [diff] [blame] | 31 | 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 Driessen | 3625f39 | 2010-01-28 00:13:26 +0100 | [diff] [blame] | 37 | echo " version Shows version information." |
Benedikt Böhm | 7d703a8 | 2010-01-26 13:17:12 +0100 | [diff] [blame] | 38 | echo |
Vincent Driessen | 186d2b5 | 2010-01-27 23:48:39 +0100 | [diff] [blame] | 39 | echo "Try 'git flow <subcommand> help' for details." |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | main() { |
Benedikt Böhm | 427c5db | 2010-01-26 18:23:44 +0100 | [diff] [blame] | 43 | if [ $# -lt 1 ]; then |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 44 | usage |
| 45 | exit 1 |
| 46 | fi |
| 47 | |
Vincent Driessen | c3607ac | 2010-02-05 19:53:45 +0100 | [diff] [blame] | 48 | # load common functionality |
| 49 | . "$GITFLOW_DIR/gitflow-common" |
| 50 | |
Vincent Driessen | ea58d0f | 2010-01-30 20:51:03 +0100 | [diff] [blame] | 51 | # use the shFlags project to parse the command line arguments |
Vincent Driessen | c3607ac | 2010-02-05 19:53:45 +0100 | [diff] [blame] | 52 | . "$GITFLOW_DIR/gitflow-shFlags" |
Vincent Driessen | 4417492 | 2010-02-02 23:53:21 +0100 | [diff] [blame] | 53 | FLAGS_PARENT="git flow" |
Vincent Driessen | ea58d0f | 2010-01-30 20:51:03 +0100 | [diff] [blame] | 54 | FLAGS "$@" || exit $? |
| 55 | eval set -- "${FLAGS_ARGV}" |
| 56 | |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 57 | # sanity checks |
Vincent Driessen | 186d2b5 | 2010-01-27 23:48:39 +0100 | [diff] [blame] | 58 | SUBCOMMAND="$1"; shift |
Benedikt Böhm | 427c5db | 2010-01-26 18:23:44 +0100 | [diff] [blame] | 59 | |
Vincent Driessen | 186d2b5 | 2010-01-27 23:48:39 +0100 | [diff] [blame] | 60 | if [ ! -e "$GITFLOW_DIR/git-flow-$SUBCOMMAND" ]; then |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 61 | usage |
| 62 | exit 1 |
| 63 | fi |
| 64 | |
Vincent Driessen | 2ba9a4d | 2010-01-27 12:51:07 +0100 | [diff] [blame] | 65 | if ! git rev-parse --git-dir >/dev/null; then |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 66 | die "Not a git repository" |
| 67 | fi |
| 68 | |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 69 | # run command |
Vincent Driessen | 186d2b5 | 2010-01-27 23:48:39 +0100 | [diff] [blame] | 70 | . "$GITFLOW_DIR/git-flow-$SUBCOMMAND" |
Vincent Driessen | 4417492 | 2010-02-02 23:53:21 +0100 | [diff] [blame] | 71 | FLAGS_PARENT="git flow $SUBCOMMAND" |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 72 | |
Vincent Driessen | 1b81923 | 2010-02-01 15:51:43 +0100 | [diff] [blame] | 73 | # 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 Driessen | e168487 | 2010-02-02 06:33:53 +0100 | [diff] [blame] | 80 | if ! typeset -f "cmd_$SUBACTION" 2>&1 >/dev/null; then |
Vincent Driessen | 9277024 | 2010-02-04 11:49:47 +0100 | [diff] [blame] | 81 | warn "Unknown subcommand: '$SUBACTION'" |
Vincent Driessen | 186d2b5 | 2010-01-27 23:48:39 +0100 | [diff] [blame] | 82 | usage |
| 83 | exit 1 |
Benedikt Böhm | 427c5db | 2010-01-26 18:23:44 +0100 | [diff] [blame] | 84 | fi |
| 85 | |
Vincent Driessen | 186d2b5 | 2010-01-27 23:48:39 +0100 | [diff] [blame] | 86 | # run the specified action |
| 87 | cmd_$SUBACTION "$@" |
Benedikt Böhm | 427c5db | 2010-01-26 18:23:44 +0100 | [diff] [blame] | 88 | } |
| 89 | |
Vincent Driessen | 3c337fb | 2010-02-04 11:30:18 +0100 | [diff] [blame] | 90 | # helper functions for common reuse |
| 91 | max() { if [ "$1" -gt "$2" ]; then echo "$1"; else echo "$2"; fi; } |
| 92 | |
Vincent Driessen | 4417492 | 2010-02-02 23:53:21 +0100 | [diff] [blame] | 93 | # convenience functions for checking whether flags have been set or not |
| 94 | flag() { eval FLAG=\$FLAGS_$1; [ $FLAG -eq $FLAGS_TRUE ]; } |
| 95 | noflag() { eval FLAG=\$FLAGS_$1; [ $FLAG -ne $FLAGS_TRUE ]; } |
| 96 | |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 97 | main "$@" |