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") |
Benedikt Böhm | 4a864fb | 2010-01-26 12:59:27 +0100 | [diff] [blame] | 22 | |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 23 | usage() { |
Vincent Driessen | 186d2b5 | 2010-01-27 23:48:39 +0100 | [diff] [blame] | 24 | echo "usage: git flow <subcommand>" |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 25 | echo |
Vincent Driessen | 186d2b5 | 2010-01-27 23:48:39 +0100 | [diff] [blame] | 26 | 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 Driessen | 3625f39 | 2010-01-28 00:13:26 +0100 | [diff] [blame] | 32 | echo " version Shows version information." |
Benedikt Böhm | 7d703a8 | 2010-01-26 13:17:12 +0100 | [diff] [blame] | 33 | echo |
Vincent Driessen | 186d2b5 | 2010-01-27 23:48:39 +0100 | [diff] [blame] | 34 | echo "Try 'git flow <subcommand> help' for details." |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | main() { |
Benedikt Böhm | 427c5db | 2010-01-26 18:23:44 +0100 | [diff] [blame] | 38 | if [ $# -lt 1 ]; then |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 39 | usage |
| 40 | exit 1 |
| 41 | fi |
| 42 | |
Vincent Driessen | c3607ac | 2010-02-05 19:53:45 +0100 | [diff] [blame] | 43 | # load common functionality |
| 44 | . "$GITFLOW_DIR/gitflow-common" |
| 45 | |
Vincent Driessen | ea58d0f | 2010-01-30 20:51:03 +0100 | [diff] [blame] | 46 | # use the shFlags project to parse the command line arguments |
Vincent Driessen | c3607ac | 2010-02-05 19:53:45 +0100 | [diff] [blame] | 47 | . "$GITFLOW_DIR/gitflow-shFlags" |
Vincent Driessen | 4417492 | 2010-02-02 23:53:21 +0100 | [diff] [blame] | 48 | FLAGS_PARENT="git flow" |
Vincent Driessen | ea58d0f | 2010-01-30 20:51:03 +0100 | [diff] [blame] | 49 | FLAGS "$@" || exit $? |
| 50 | eval set -- "${FLAGS_ARGV}" |
| 51 | |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 52 | # sanity checks |
Vincent Driessen | 186d2b5 | 2010-01-27 23:48:39 +0100 | [diff] [blame] | 53 | SUBCOMMAND="$1"; shift |
Benedikt Böhm | 427c5db | 2010-01-26 18:23:44 +0100 | [diff] [blame] | 54 | |
Vincent Driessen | 186d2b5 | 2010-01-27 23:48:39 +0100 | [diff] [blame] | 55 | if [ ! -e "$GITFLOW_DIR/git-flow-$SUBCOMMAND" ]; then |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 56 | usage |
| 57 | exit 1 |
| 58 | fi |
| 59 | |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 60 | # run command |
Vincent Driessen | 186d2b5 | 2010-01-27 23:48:39 +0100 | [diff] [blame] | 61 | . "$GITFLOW_DIR/git-flow-$SUBCOMMAND" |
Vincent Driessen | 4417492 | 2010-02-02 23:53:21 +0100 | [diff] [blame] | 62 | FLAGS_PARENT="git flow $SUBCOMMAND" |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 63 | |
Vincent Driessen | 1b81923 | 2010-02-01 15:51:43 +0100 | [diff] [blame] | 64 | # 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 Driessen | 283b0f7 | 2010-02-15 23:23:14 +0100 | [diff] [blame] | 71 | if ! type "cmd_$SUBACTION" >/dev/null 2>&1; then |
Vincent Driessen | 9277024 | 2010-02-04 11:49:47 +0100 | [diff] [blame] | 72 | warn "Unknown subcommand: '$SUBACTION'" |
Vincent Driessen | 186d2b5 | 2010-01-27 23:48:39 +0100 | [diff] [blame] | 73 | usage |
| 74 | exit 1 |
Benedikt Böhm | 427c5db | 2010-01-26 18:23:44 +0100 | [diff] [blame] | 75 | fi |
| 76 | |
Vincent Driessen | 186d2b5 | 2010-01-27 23:48:39 +0100 | [diff] [blame] | 77 | # run the specified action |
| 78 | cmd_$SUBACTION "$@" |
Benedikt Böhm | 427c5db | 2010-01-26 18:23:44 +0100 | [diff] [blame] | 79 | } |
| 80 | |
Vincent Driessen | 3c337fb | 2010-02-04 11:30:18 +0100 | [diff] [blame] | 81 | # helper functions for common reuse |
| 82 | max() { if [ "$1" -gt "$2" ]; then echo "$1"; else echo "$2"; fi; } |
| 83 | |
Vincent Driessen | 4417492 | 2010-02-02 23:53:21 +0100 | [diff] [blame] | 84 | # convenience functions for checking whether flags have been set or not |
| 85 | flag() { eval FLAG=\$FLAGS_$1; [ $FLAG -eq $FLAGS_TRUE ]; } |
| 86 | noflag() { eval FLAG=\$FLAGS_$1; [ $FLAG -ne $FLAGS_TRUE ]; } |
| 87 | |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 88 | main "$@" |