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 | # |
Vincent Driessen | d72acba | 2010-04-04 16:10:17 +0200 | [diff] [blame] | 11 | # Copyright 2010 Vincent Driessen. All rights reserved. |
| 12 | # |
| 13 | # Redistribution and use in source and binary forms, with or without |
| 14 | # modification, are permitted provided that the following conditions are met: |
| 15 | # |
| 16 | # 1. Redistributions of source code must retain the above copyright notice, |
| 17 | # this list of conditions and the following disclaimer. |
| 18 | # |
| 19 | # 2. Redistributions in binary form must reproduce the above copyright |
| 20 | # notice, this list of conditions and the following disclaimer in the |
| 21 | # documentation and/or other materials provided with the distribution. |
| 22 | # |
| 23 | # THIS SOFTWARE IS PROVIDED BY VINCENT DRIESSEN ``AS IS'' AND ANY EXPRESS OR |
| 24 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 25 | # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
| 26 | # EVENT SHALL VINCENT DRIESSEN OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, |
| 27 | # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
| 28 | # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 29 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 30 | # OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 31 | # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, |
| 32 | # EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 33 | # |
| 34 | # The views and conclusions contained in the software and documentation are |
| 35 | # those of the authors and should not be interpreted as representing official |
| 36 | # policies, either expressed or implied, of Vincent Driessen. |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 37 | # |
| 38 | |
Vincent Driessen | 7832d6e | 2010-02-21 21:31:03 +0100 | [diff] [blame] | 39 | require_git_repo |
| 40 | require_gitflow_initialized |
Vincent Driessen | d72e4ac | 2010-02-16 21:33:51 +0100 | [diff] [blame] | 41 | gitflow_load_settings |
Benedikt Böhm | 49dd62b | 2010-01-28 00:51:15 +0100 | [diff] [blame] | 42 | VERSION_PREFIX=$(git config --get gitflow.prefix.versiontag) |
Vincent Driessen | c1598bf | 2010-02-20 16:52:48 +0100 | [diff] [blame] | 43 | PREFIX=$(git config --get gitflow.prefix.support) |
Benedikt Böhm | 49dd62b | 2010-01-28 00:51:15 +0100 | [diff] [blame] | 44 | |
Vincent Driessen | 3c337fb | 2010-02-04 11:30:18 +0100 | [diff] [blame] | 45 | warn "note: The support subcommand is still very EXPERIMENTAL!" |
| 46 | warn "note: DO NOT use it in a production situation." |
| 47 | |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 48 | usage() { |
Vincent Driessen | 3c337fb | 2010-02-04 11:30:18 +0100 | [diff] [blame] | 49 | echo "usage: git flow support [list] [-v]" |
Vincent Driessen | a2e4116 | 2010-02-24 01:37:07 +0100 | [diff] [blame] | 50 | echo " git flow support start [-F] <version> <base>" |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 51 | } |
| 52 | |
Vincent Driessen | b866b01 | 2010-01-28 01:01:53 +0100 | [diff] [blame] | 53 | cmd_default() { |
| 54 | cmd_list "$@" |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 55 | } |
| 56 | |
Vincent Driessen | b866b01 | 2010-01-28 01:01:53 +0100 | [diff] [blame] | 57 | cmd_list() { |
Vincent Driessen | 3c337fb | 2010-02-04 11:30:18 +0100 | [diff] [blame] | 58 | DEFINE_boolean verbose false 'verbose (more) output' v |
| 59 | parse_args "$@" |
| 60 | |
Vincent Driessen | f46e290 | 2010-02-15 23:01:52 +0100 | [diff] [blame] | 61 | local support_branches |
| 62 | local current_branch |
| 63 | local short_names |
Vincent Driessen | 7832d6e | 2010-02-21 21:31:03 +0100 | [diff] [blame] | 64 | support_branches=$(echo "$(git_local_branches)" | grep "^$PREFIX") |
Vincent Driessen | 27592dd | 2010-02-06 14:45:39 +0100 | [diff] [blame] | 65 | if [ -z "$support_branches" ]; then |
Vincent Driessen | 170dc74 | 2010-01-28 00:20:51 +0100 | [diff] [blame] | 66 | warn "No support branches exist." |
Randy Merrill | b681b45 | 2010-06-26 13:14:15 +0800 | [diff] [blame^] | 67 | warn "" |
| 68 | warn "You can start a new support branch:" |
| 69 | warn "" |
| 70 | warn " git flow support start <name> <base>" |
Vincent Driessen | 170dc74 | 2010-01-28 00:20:51 +0100 | [diff] [blame] | 71 | exit 0 |
| 72 | fi |
Vincent Driessen | 27592dd | 2010-02-06 14:45:39 +0100 | [diff] [blame] | 73 | current_branch=$(git branch | grep '^\* ' | grep -v 'no branch' | sed 's/^* //g') |
Vincent Driessen | 6884523 | 2010-02-10 00:43:21 +0100 | [diff] [blame] | 74 | short_names=$(echo "$support_branches" | sed "s ^$PREFIX g") |
Vincent Driessen | 3c337fb | 2010-02-04 11:30:18 +0100 | [diff] [blame] | 75 | |
Vincent Driessen | 3c337fb | 2010-02-04 11:30:18 +0100 | [diff] [blame] | 76 | # determine column width first |
Vincent Driessen | f46e290 | 2010-02-15 23:01:52 +0100 | [diff] [blame] | 77 | local width=0 |
| 78 | local branch |
Vincent Driessen | 27592dd | 2010-02-06 14:45:39 +0100 | [diff] [blame] | 79 | for branch in $short_names; do |
Vincent Driessen | f46e290 | 2010-02-15 23:01:52 +0100 | [diff] [blame] | 80 | local len=${#branch} |
Vincent Driessen | 3c337fb | 2010-02-04 11:30:18 +0100 | [diff] [blame] | 81 | width=$(max $width $len) |
| 82 | done |
Vincent Driessen | f46e290 | 2010-02-15 23:01:52 +0100 | [diff] [blame] | 83 | width=$(($width+3)) |
Vincent Driessen | 3c337fb | 2010-02-04 11:30:18 +0100 | [diff] [blame] | 84 | |
Vincent Driessen | f46e290 | 2010-02-15 23:01:52 +0100 | [diff] [blame] | 85 | local branch |
Vincent Driessen | 27592dd | 2010-02-06 14:45:39 +0100 | [diff] [blame] | 86 | for branch in $short_names; do |
Vincent Driessen | f46e290 | 2010-02-15 23:01:52 +0100 | [diff] [blame] | 87 | local fullname=$PREFIX$branch |
| 88 | local base=$(git merge-base "$fullname" "$MASTER_BRANCH") |
| 89 | local master_sha=$(git rev-parse "$MASTER_BRANCH") |
| 90 | local branch_sha=$(git rev-parse "$fullname") |
Vincent Driessen | 27592dd | 2010-02-06 14:45:39 +0100 | [diff] [blame] | 91 | if [ "$fullname" = "$current_branch" ]; then |
Vincent Driessen | 3c337fb | 2010-02-04 11:30:18 +0100 | [diff] [blame] | 92 | printf "* " |
| 93 | else |
| 94 | printf " " |
| 95 | fi |
| 96 | if flag verbose; then |
| 97 | printf "%-${width}s" "$branch" |
| 98 | if [ "$branch_sha" = "$master_sha" ]; then |
| 99 | printf "(no commits yet)" |
| 100 | else |
Vincent Driessen | f46e290 | 2010-02-15 23:01:52 +0100 | [diff] [blame] | 101 | local tagname=$(git name-rev --tags --no-undefined --name-only "$base") |
| 102 | local nicename |
Vincent Driessen | 3c337fb | 2010-02-04 11:30:18 +0100 | [diff] [blame] | 103 | if [ "$tagname" != "" ]; then |
Vincent Driessen | c5fcc01 | 2010-02-10 00:18:08 +0100 | [diff] [blame] | 104 | nicename=$tagname |
Vincent Driessen | 3c337fb | 2010-02-04 11:30:18 +0100 | [diff] [blame] | 105 | else |
Vincent Driessen | a4dd223 | 2010-02-10 00:34:59 +0100 | [diff] [blame] | 106 | nicename=$(git rev-parse --short "$base") |
Vincent Driessen | 3c337fb | 2010-02-04 11:30:18 +0100 | [diff] [blame] | 107 | fi |
| 108 | printf "(based on $nicename)" |
| 109 | fi |
| 110 | else |
| 111 | printf "%s" "$branch" |
| 112 | fi |
| 113 | echo |
| 114 | done |
Vincent Driessen | 170dc74 | 2010-01-28 00:20:51 +0100 | [diff] [blame] | 115 | } |
| 116 | |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 117 | cmd_help() { |
| 118 | usage |
| 119 | exit 0 |
| 120 | } |
| 121 | |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 122 | parse_args() { |
Vincent Driessen | 3c337fb | 2010-02-04 11:30:18 +0100 | [diff] [blame] | 123 | # parse options |
| 124 | FLAGS "$@" || exit $? |
| 125 | eval set -- "${FLAGS_ARGV}" |
| 126 | |
| 127 | # read arguments into global variables |
Vincent Driessen | c5fcc01 | 2010-02-10 00:18:08 +0100 | [diff] [blame] | 128 | VERSION=$1 |
| 129 | BASE=$2 |
Vincent Driessen | 3c337fb | 2010-02-04 11:30:18 +0100 | [diff] [blame] | 130 | BRANCH=$PREFIX$VERSION |
| 131 | } |
| 132 | |
| 133 | require_version_arg() { |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 134 | if [ "$VERSION" = "" ]; then |
Vincent Driessen | 3c337fb | 2010-02-04 11:30:18 +0100 | [diff] [blame] | 135 | warn "Missing argument <version>" |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 136 | usage |
| 137 | exit 1 |
| 138 | fi |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 139 | } |
| 140 | |
Vincent Driessen | 010252a | 2010-02-04 10:31:29 +0100 | [diff] [blame] | 141 | require_base_arg() { |
| 142 | if [ "$BASE" = "" ]; then |
| 143 | warn "Missing argument <base>" |
| 144 | usage |
| 145 | exit 1 |
| 146 | fi |
| 147 | } |
| 148 | |
| 149 | require_base_is_on_master() { |
| 150 | if ! git branch --contains "$BASE" 2>/dev/null \ |
| 151 | | sed 's/[* ] //g' \ |
| 152 | | grep -q "^$MASTER_BRANCH\$"; then |
| 153 | die "fatal: Given base '$BASE' is not a valid commit on '$MASTER_BRANCH'." |
| 154 | fi |
| 155 | } |
| 156 | |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 157 | cmd_start() { |
Vincent Driessen | ca73caf | 2010-02-07 19:46:38 +0100 | [diff] [blame] | 158 | DEFINE_boolean fetch true "fetch from $ORIGIN before performing finish" F |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 159 | parse_args "$@" |
Vincent Driessen | 3c337fb | 2010-02-04 11:30:18 +0100 | [diff] [blame] | 160 | require_version_arg |
Vincent Driessen | 010252a | 2010-02-04 10:31:29 +0100 | [diff] [blame] | 161 | require_base_arg |
| 162 | require_base_is_on_master |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 163 | |
| 164 | # sanity checks |
Vincent Driessen | 7832d6e | 2010-02-21 21:31:03 +0100 | [diff] [blame] | 165 | require_clean_working_tree |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 166 | |
Vincent Driessen | 2acfffd | 2010-01-29 12:37:22 +0100 | [diff] [blame] | 167 | # fetch remote changes |
Vincent Driessen | ca73caf | 2010-02-07 19:46:38 +0100 | [diff] [blame] | 168 | if flag fetch; then |
Vincent Driessen | a4dd223 | 2010-02-10 00:34:59 +0100 | [diff] [blame] | 169 | git fetch -q "$ORIGIN" "$BASE" |
Vincent Driessen | 2acfffd | 2010-01-29 12:37:22 +0100 | [diff] [blame] | 170 | fi |
Vincent Driessen | 7832d6e | 2010-02-21 21:31:03 +0100 | [diff] [blame] | 171 | require_branch_absent "$BRANCH" |
Vincent Driessen | 2acfffd | 2010-01-29 12:37:22 +0100 | [diff] [blame] | 172 | |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 173 | # create branch |
Vincent Driessen | 3c337fb | 2010-02-04 11:30:18 +0100 | [diff] [blame] | 174 | git checkout -b "$BRANCH" "$BASE" |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 175 | |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 176 | echo |
| 177 | echo "Summary of actions:" |
Vincent Driessen | 010252a | 2010-02-04 10:31:29 +0100 | [diff] [blame] | 178 | echo "- A new branch '$BRANCH' was created, based on '$BASE'" |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 179 | echo "- You are now on branch '$BRANCH'" |
| 180 | echo |
| 181 | } |