Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 1 | # |
Vincent Driessen | 6c2d30b | 2010-01-26 22:18:36 +0100 | [diff] [blame] | 2 | # git-flow -- A collection of Git extensions to provide high-level |
| 3 | # repository operations for Vincent Driessen's branching model. |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 4 | # |
| 5 | # Original blog post presenting this model is found at: |
| 6 | # http://nvie.com/archives/323 |
| 7 | # |
| 8 | # Feel free to contribute to this project at: |
| 9 | # http://github.com/nvie/gitflow |
| 10 | # |
| 11 | # Copyright (c) 2010 by Vincent Driessen |
| 12 | # Copyright (c) 2010 by Benedikt Böhm |
| 13 | # |
| 14 | |
Benedikt Böhm | 49dd62b | 2010-01-28 00:51:15 +0100 | [diff] [blame] | 15 | VERSION_PREFIX=$(git config --get gitflow.prefix.versiontag) |
| 16 | PREFIX=$(git config --get gitflow.prefix.support || echo support/) |
| 17 | |
Vincent Driessen | 3c337fb | 2010-02-04 11:30:18 +0100 | [diff] [blame] | 18 | warn "note: The support subcommand is still very EXPERIMENTAL!" |
| 19 | warn "note: DO NOT use it in a production situation." |
| 20 | |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 21 | usage() { |
Vincent Driessen | 3c337fb | 2010-02-04 11:30:18 +0100 | [diff] [blame] | 22 | echo "usage: git flow support [list] [-v]" |
Vincent Driessen | 010252a | 2010-02-04 10:31:29 +0100 | [diff] [blame] | 23 | echo " git flow support start <version> <base>" |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 24 | } |
| 25 | |
Vincent Driessen | b866b01 | 2010-01-28 01:01:53 +0100 | [diff] [blame] | 26 | cmd_default() { |
| 27 | cmd_list "$@" |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 28 | } |
| 29 | |
Vincent Driessen | b866b01 | 2010-01-28 01:01:53 +0100 | [diff] [blame] | 30 | cmd_list() { |
Vincent Driessen | 3c337fb | 2010-02-04 11:30:18 +0100 | [diff] [blame] | 31 | DEFINE_boolean verbose false 'verbose (more) output' v |
| 32 | parse_args "$@" |
| 33 | |
Vincent Driessen | 27592dd | 2010-02-06 14:45:39 +0100 | [diff] [blame] | 34 | typeset support_branches |
| 35 | typeset current_branch |
| 36 | typeset short_names |
Vincent Driessen | c5fcc01 | 2010-02-10 00:18:08 +0100 | [diff] [blame] | 37 | support_branches=$(echo "$LOCAL_BRANCHES" | grep "^$PREFIX") |
Vincent Driessen | 27592dd | 2010-02-06 14:45:39 +0100 | [diff] [blame] | 38 | if [ -z "$support_branches" ]; then |
Vincent Driessen | 170dc74 | 2010-01-28 00:20:51 +0100 | [diff] [blame] | 39 | warn "No support branches exist." |
| 40 | exit 0 |
| 41 | fi |
Vincent Driessen | 27592dd | 2010-02-06 14:45:39 +0100 | [diff] [blame] | 42 | current_branch=$(git branch | grep '^\* ' | grep -v 'no branch' | sed 's/^* //g') |
Vincent Driessen | 6884523 | 2010-02-10 00:43:21 +0100 | [diff] [blame] | 43 | short_names=$(echo "$support_branches" | sed "s ^$PREFIX g") |
Vincent Driessen | 3c337fb | 2010-02-04 11:30:18 +0100 | [diff] [blame] | 44 | |
Vincent Driessen | 3c337fb | 2010-02-04 11:30:18 +0100 | [diff] [blame] | 45 | # determine column width first |
Vincent Driessen | 27592dd | 2010-02-06 14:45:39 +0100 | [diff] [blame] | 46 | typeset -i width=0 |
| 47 | typeset branch |
| 48 | for branch in $short_names; do |
Vincent Driessen | b673c44 | 2010-02-10 00:43:53 +0100 | [diff] [blame] | 49 | typeset -i len=${#branch} |
Vincent Driessen | 3c337fb | 2010-02-04 11:30:18 +0100 | [diff] [blame] | 50 | width=$(max $width $len) |
| 51 | done |
Vincent Driessen | 27592dd | 2010-02-06 14:45:39 +0100 | [diff] [blame] | 52 | width=width+3 |
Vincent Driessen | 3c337fb | 2010-02-04 11:30:18 +0100 | [diff] [blame] | 53 | |
Vincent Driessen | 27592dd | 2010-02-06 14:45:39 +0100 | [diff] [blame] | 54 | typeset branch |
| 55 | for branch in $short_names; do |
Vincent Driessen | c5fcc01 | 2010-02-10 00:18:08 +0100 | [diff] [blame] | 56 | typeset fullname=$PREFIX$branch |
Vincent Driessen | 27592dd | 2010-02-06 14:45:39 +0100 | [diff] [blame] | 57 | typeset base=$(git merge-base "$fullname" "$MASTER_BRANCH") |
| 58 | typeset master_sha=$(git rev-parse "$MASTER_BRANCH") |
| 59 | typeset branch_sha=$(git rev-parse "$fullname") |
| 60 | if [ "$fullname" = "$current_branch" ]; then |
Vincent Driessen | 3c337fb | 2010-02-04 11:30:18 +0100 | [diff] [blame] | 61 | printf "* " |
| 62 | else |
| 63 | printf " " |
| 64 | fi |
| 65 | if flag verbose; then |
| 66 | printf "%-${width}s" "$branch" |
| 67 | if [ "$branch_sha" = "$master_sha" ]; then |
| 68 | printf "(no commits yet)" |
| 69 | else |
Vincent Driessen | a4dd223 | 2010-02-10 00:34:59 +0100 | [diff] [blame] | 70 | typeset tagname=$(git name-rev --tags --no-undefined --name-only "$base") |
Vincent Driessen | 27592dd | 2010-02-06 14:45:39 +0100 | [diff] [blame] | 71 | typeset nicename |
Vincent Driessen | 3c337fb | 2010-02-04 11:30:18 +0100 | [diff] [blame] | 72 | if [ "$tagname" != "" ]; then |
Vincent Driessen | c5fcc01 | 2010-02-10 00:18:08 +0100 | [diff] [blame] | 73 | nicename=$tagname |
Vincent Driessen | 3c337fb | 2010-02-04 11:30:18 +0100 | [diff] [blame] | 74 | else |
Vincent Driessen | a4dd223 | 2010-02-10 00:34:59 +0100 | [diff] [blame] | 75 | nicename=$(git rev-parse --short "$base") |
Vincent Driessen | 3c337fb | 2010-02-04 11:30:18 +0100 | [diff] [blame] | 76 | fi |
| 77 | printf "(based on $nicename)" |
| 78 | fi |
| 79 | else |
| 80 | printf "%s" "$branch" |
| 81 | fi |
| 82 | echo |
| 83 | done |
Vincent Driessen | 170dc74 | 2010-01-28 00:20:51 +0100 | [diff] [blame] | 84 | } |
| 85 | |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 86 | cmd_help() { |
| 87 | usage |
| 88 | exit 0 |
| 89 | } |
| 90 | |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 91 | parse_args() { |
Vincent Driessen | 3c337fb | 2010-02-04 11:30:18 +0100 | [diff] [blame] | 92 | # parse options |
| 93 | FLAGS "$@" || exit $? |
| 94 | eval set -- "${FLAGS_ARGV}" |
| 95 | |
| 96 | # read arguments into global variables |
Vincent Driessen | c5fcc01 | 2010-02-10 00:18:08 +0100 | [diff] [blame] | 97 | VERSION=$1 |
| 98 | BASE=$2 |
Vincent Driessen | 3c337fb | 2010-02-04 11:30:18 +0100 | [diff] [blame] | 99 | BRANCH=$PREFIX$VERSION |
| 100 | } |
| 101 | |
| 102 | require_version_arg() { |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 103 | if [ "$VERSION" = "" ]; then |
Vincent Driessen | 3c337fb | 2010-02-04 11:30:18 +0100 | [diff] [blame] | 104 | warn "Missing argument <version>" |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 105 | usage |
| 106 | exit 1 |
| 107 | fi |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 108 | } |
| 109 | |
Vincent Driessen | 010252a | 2010-02-04 10:31:29 +0100 | [diff] [blame] | 110 | require_base_arg() { |
| 111 | if [ "$BASE" = "" ]; then |
| 112 | warn "Missing argument <base>" |
| 113 | usage |
| 114 | exit 1 |
| 115 | fi |
| 116 | } |
| 117 | |
| 118 | require_base_is_on_master() { |
| 119 | if ! git branch --contains "$BASE" 2>/dev/null \ |
| 120 | | sed 's/[* ] //g' \ |
| 121 | | grep -q "^$MASTER_BRANCH\$"; then |
| 122 | die "fatal: Given base '$BASE' is not a valid commit on '$MASTER_BRANCH'." |
| 123 | fi |
| 124 | } |
| 125 | |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 126 | cmd_start() { |
Vincent Driessen | ca73caf | 2010-02-07 19:46:38 +0100 | [diff] [blame] | 127 | DEFINE_boolean fetch true "fetch from $ORIGIN before performing finish" F |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 128 | parse_args "$@" |
Vincent Driessen | 3c337fb | 2010-02-04 11:30:18 +0100 | [diff] [blame] | 129 | require_version_arg |
Vincent Driessen | 010252a | 2010-02-04 10:31:29 +0100 | [diff] [blame] | 130 | require_base_arg |
| 131 | require_base_is_on_master |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 132 | |
| 133 | # sanity checks |
Vincent Driessen | 4838644 | 2010-01-29 10:30:40 +0100 | [diff] [blame] | 134 | gitflow_require_clean_working_tree |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 135 | |
Vincent Driessen | 2acfffd | 2010-01-29 12:37:22 +0100 | [diff] [blame] | 136 | # fetch remote changes |
Vincent Driessen | ca73caf | 2010-02-07 19:46:38 +0100 | [diff] [blame] | 137 | if flag fetch; then |
Vincent Driessen | a4dd223 | 2010-02-10 00:34:59 +0100 | [diff] [blame] | 138 | git fetch -q "$ORIGIN" "$BASE" |
Vincent Driessen | 2acfffd | 2010-01-29 12:37:22 +0100 | [diff] [blame] | 139 | fi |
Vincent Driessen | a4dd223 | 2010-02-10 00:34:59 +0100 | [diff] [blame] | 140 | gitflow_require_branch_absent "$BRANCH" |
Vincent Driessen | 2acfffd | 2010-01-29 12:37:22 +0100 | [diff] [blame] | 141 | |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 142 | # create branch |
Vincent Driessen | 3c337fb | 2010-02-04 11:30:18 +0100 | [diff] [blame] | 143 | git checkout -b "$BRANCH" "$BASE" |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 144 | |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 145 | echo |
| 146 | echo "Summary of actions:" |
Vincent Driessen | 010252a | 2010-02-04 10:31:29 +0100 | [diff] [blame] | 147 | echo "- A new branch '$BRANCH' was created, based on '$BASE'" |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 148 | echo "- You are now on branch '$BRANCH'" |
| 149 | echo |
| 150 | } |