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.release || echo release/) |
| 17 | |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 18 | usage() { |
Vincent Driessen | 3c337fb | 2010-02-04 11:30:18 +0100 | [diff] [blame] | 19 | echo "usage: git flow release [list] [-v]" |
Vincent Driessen | 170dc74 | 2010-01-28 00:20:51 +0100 | [diff] [blame] | 20 | echo " git flow release start <version>" |
| 21 | echo " git flow release finish <version>" |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 22 | # TODO |
| 23 | #echo "" |
| 24 | #echo "options:" |
| 25 | #echo "--option Explanation" |
| 26 | #echo "" |
| 27 | #echo "start-only options:" |
| 28 | #echo "--bump <script>" |
| 29 | #echo " Run the given script to auto-update the version number" |
| 30 | #echo "" |
| 31 | #echo "finish-only options:" |
| 32 | #echo "--push Push to the origin repo when finished" |
| 33 | } |
| 34 | |
Vincent Driessen | 170dc74 | 2010-01-28 00:20:51 +0100 | [diff] [blame] | 35 | cmd_default() { |
Vincent Driessen | b866b01 | 2010-01-28 01:01:53 +0100 | [diff] [blame] | 36 | cmd_list "$@" |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 37 | } |
| 38 | |
Vincent Driessen | b866b01 | 2010-01-28 01:01:53 +0100 | [diff] [blame] | 39 | cmd_list() { |
Vincent Driessen | 3c337fb | 2010-02-04 11:30:18 +0100 | [diff] [blame] | 40 | DEFINE_boolean verbose false 'verbose (more) output' v |
| 41 | parse_args "$@" |
| 42 | |
Vincent Driessen | 27592dd | 2010-02-06 14:45:39 +0100 | [diff] [blame] | 43 | typeset release_branches |
| 44 | typeset current_branch |
| 45 | typeset short_names |
Vincent Driessen | c5fcc01 | 2010-02-10 00:18:08 +0100 | [diff] [blame] | 46 | release_branches=$(echo "$LOCAL_BRANCHES" | grep "^$PREFIX") |
Vincent Driessen | 27592dd | 2010-02-06 14:45:39 +0100 | [diff] [blame] | 47 | if [ -z "$release_branches" ]; then |
Vincent Driessen | 170dc74 | 2010-01-28 00:20:51 +0100 | [diff] [blame] | 48 | warn "No release branches exist." |
| 49 | exit 0 |
| 50 | fi |
Vincent Driessen | 3c337fb | 2010-02-04 11:30:18 +0100 | [diff] [blame] | 51 | |
Vincent Driessen | 27592dd | 2010-02-06 14:45:39 +0100 | [diff] [blame] | 52 | current_branch=$(git branch | grep '^\* ' | grep -v 'no branch' | sed 's/^* //g') |
Vincent Driessen | 6884523 | 2010-02-10 00:43:21 +0100 | [diff] [blame^] | 53 | short_names=$(echo "$release_branches" | sed "s ^$PREFIX g") |
Vincent Driessen | 27592dd | 2010-02-06 14:45:39 +0100 | [diff] [blame] | 54 | |
Vincent Driessen | 3c337fb | 2010-02-04 11:30:18 +0100 | [diff] [blame] | 55 | # determine column width first |
Vincent Driessen | 27592dd | 2010-02-06 14:45:39 +0100 | [diff] [blame] | 56 | typeset -i width=0 |
| 57 | typeset branch |
| 58 | for branch in $short_names; do |
| 59 | typeset -i len=$(($(echo "$branch" | wc -c) - 1)) |
Vincent Driessen | 3c337fb | 2010-02-04 11:30:18 +0100 | [diff] [blame] | 60 | width=$(max $width $len) |
| 61 | done |
Vincent Driessen | 27592dd | 2010-02-06 14:45:39 +0100 | [diff] [blame] | 62 | width=width+3 |
Vincent Driessen | 3c337fb | 2010-02-04 11:30:18 +0100 | [diff] [blame] | 63 | |
Vincent Driessen | 27592dd | 2010-02-06 14:45:39 +0100 | [diff] [blame] | 64 | typeset branch |
| 65 | for branch in $short_names; do |
Vincent Driessen | c5fcc01 | 2010-02-10 00:18:08 +0100 | [diff] [blame] | 66 | typeset fullname=$PREFIX$branch |
Vincent Driessen | 27592dd | 2010-02-06 14:45:39 +0100 | [diff] [blame] | 67 | typeset base=$(git merge-base "$fullname" "$DEVELOP_BRANCH") |
| 68 | typeset develop_sha=$(git rev-parse "$DEVELOP_BRANCH") |
| 69 | typeset branch_sha=$(git rev-parse "$fullname") |
| 70 | if [ "$fullname" = "$current_branch" ]; then |
Vincent Driessen | 3c337fb | 2010-02-04 11:30:18 +0100 | [diff] [blame] | 71 | printf "* " |
| 72 | else |
| 73 | printf " " |
| 74 | fi |
| 75 | if flag verbose; then |
| 76 | printf "%-${width}s" "$branch" |
| 77 | if [ "$branch_sha" = "$develop_sha" ]; then |
| 78 | printf "(no commits yet)" |
| 79 | else |
Vincent Driessen | a4dd223 | 2010-02-10 00:34:59 +0100 | [diff] [blame] | 80 | typeset nicename=$(git rev-parse --short "$base") |
Vincent Driessen | 3c337fb | 2010-02-04 11:30:18 +0100 | [diff] [blame] | 81 | printf "(based on $nicename)" |
| 82 | fi |
| 83 | else |
| 84 | printf "%s" "$branch" |
| 85 | fi |
| 86 | echo |
| 87 | done |
Vincent Driessen | 170dc74 | 2010-01-28 00:20:51 +0100 | [diff] [blame] | 88 | } |
| 89 | |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 90 | cmd_help() { |
| 91 | usage |
| 92 | exit 0 |
| 93 | } |
| 94 | |
Vincent Driessen | b866b01 | 2010-01-28 01:01:53 +0100 | [diff] [blame] | 95 | parse_args() { |
Vincent Driessen | 3c337fb | 2010-02-04 11:30:18 +0100 | [diff] [blame] | 96 | # parse options |
| 97 | FLAGS "$@" || exit $? |
| 98 | eval set -- "${FLAGS_ARGV}" |
| 99 | |
| 100 | # read arguments into global variables |
Vincent Driessen | c5fcc01 | 2010-02-10 00:18:08 +0100 | [diff] [blame] | 101 | VERSION=$1 |
| 102 | BRANCH=$PREFIX$VERSION |
Vincent Driessen | 3c337fb | 2010-02-04 11:30:18 +0100 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | require_version_arg() { |
Vincent Driessen | b866b01 | 2010-01-28 01:01:53 +0100 | [diff] [blame] | 106 | if [ "$VERSION" = "" ]; then |
Vincent Driessen | 3c337fb | 2010-02-04 11:30:18 +0100 | [diff] [blame] | 107 | warn "Missing argument <version>" |
Vincent Driessen | b866b01 | 2010-01-28 01:01:53 +0100 | [diff] [blame] | 108 | usage |
| 109 | exit 1 |
| 110 | fi |
Vincent Driessen | b866b01 | 2010-01-28 01:01:53 +0100 | [diff] [blame] | 111 | } |
| 112 | |
Vincent Driessen | 010252a | 2010-02-04 10:31:29 +0100 | [diff] [blame] | 113 | require_base_is_on_develop() { |
| 114 | if ! git branch --contains "$BASE" 2>/dev/null \ |
| 115 | | sed 's/[* ] //g' \ |
| 116 | | grep -q "^$DEVELOP_BRANCH\$"; then |
| 117 | die "fatal: Given base '$BASE' is not a valid commit on '$DEVELOP_BRANCH'." |
| 118 | fi |
| 119 | } |
| 120 | |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 121 | cmd_start() { |
Vincent Driessen | ca73caf | 2010-02-07 19:46:38 +0100 | [diff] [blame] | 122 | DEFINE_boolean fetch true "fetch from $ORIGIN before performing finish" F |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 123 | parse_args "$@" |
Vincent Driessen | c5fcc01 | 2010-02-10 00:18:08 +0100 | [diff] [blame] | 124 | BASE=${2:-$DEVELOP_BRANCH} |
Vincent Driessen | 3c337fb | 2010-02-04 11:30:18 +0100 | [diff] [blame] | 125 | require_version_arg |
Vincent Driessen | 010252a | 2010-02-04 10:31:29 +0100 | [diff] [blame] | 126 | require_base_is_on_develop |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 127 | |
| 128 | # sanity checks |
Vincent Driessen | 4838644 | 2010-01-29 10:30:40 +0100 | [diff] [blame] | 129 | gitflow_require_clean_working_tree |
Vincent Driessen | a4dd223 | 2010-02-10 00:34:59 +0100 | [diff] [blame] | 130 | gitflow_require_branch_absent "$BRANCH" |
| 131 | gitflow_require_tag_absent "$VERSION_PREFIX$VERSION" |
Vincent Driessen | ca73caf | 2010-02-07 19:46:38 +0100 | [diff] [blame] | 132 | if flag fetch; then |
Vincent Driessen | a4dd223 | 2010-02-10 00:34:59 +0100 | [diff] [blame] | 133 | git fetch -q "$ORIGIN" "$DEVELOP_BRANCH" |
Vincent Driessen | 2acfffd | 2010-01-29 12:37:22 +0100 | [diff] [blame] | 134 | fi |
Vincent Driessen | a4dd223 | 2010-02-10 00:34:59 +0100 | [diff] [blame] | 135 | gitflow_require_branches_equal "$DEVELOP_BRANCH" "$ORIGIN/$DEVELOP_BRANCH" |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 136 | |
| 137 | # create branch |
Vincent Driessen | a4dd223 | 2010-02-10 00:34:59 +0100 | [diff] [blame] | 138 | git checkout -b "$BRANCH" "$BASE" |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 139 | |
| 140 | echo |
| 141 | echo "Summary of actions:" |
Vincent Driessen | 010252a | 2010-02-04 10:31:29 +0100 | [diff] [blame] | 142 | echo "- A new branch '$BRANCH' was created, based on '$BASE'" |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 143 | echo "- You are now on branch '$BRANCH'" |
| 144 | echo |
| 145 | echo "Follow-up actions:" |
| 146 | echo "- Bump the version number now!" |
| 147 | echo "- Start committing last-minute fixes in preparing your release" |
| 148 | echo "- When done, run:" |
| 149 | echo |
Vincent Driessen | 010252a | 2010-02-04 10:31:29 +0100 | [diff] [blame] | 150 | echo " git flow release finish '$VERSION'" |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 151 | echo |
| 152 | } |
| 153 | |
| 154 | cmd_finish() { |
Vincent Driessen | ca73caf | 2010-02-07 19:46:38 +0100 | [diff] [blame] | 155 | DEFINE_boolean fetch true "fetch from $ORIGIN before performing finish" F |
Vincent Driessen | 1a2868b | 2010-02-07 23:23:16 +0100 | [diff] [blame] | 156 | DEFINE_boolean sign false "sign the release tag cryptographically" s |
| 157 | DEFINE_string signingkey "" "use the given GPG-key for the digital signature (implies -s)" u |
| 158 | DEFINE_string message "" "use the given tag message" m |
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 |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 161 | |
Vincent Driessen | 1a2868b | 2010-02-07 23:23:16 +0100 | [diff] [blame] | 162 | # handle flags that imply other flags |
| 163 | if [ "$FLAGS_signingkey" != "" ]; then |
| 164 | FLAGS_sign=$FLAGS_TRUE |
| 165 | fi |
| 166 | |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 167 | # sanity checks |
Vincent Driessen | a4dd223 | 2010-02-10 00:34:59 +0100 | [diff] [blame] | 168 | gitflow_require_branch "$BRANCH" |
Vincent Driessen | 4838644 | 2010-01-29 10:30:40 +0100 | [diff] [blame] | 169 | gitflow_require_clean_working_tree |
Vincent Driessen | ca73caf | 2010-02-07 19:46:38 +0100 | [diff] [blame] | 170 | if flag fetch; then |
Vincent Driessen | a4dd223 | 2010-02-10 00:34:59 +0100 | [diff] [blame] | 171 | git fetch -q "$ORIGIN" "$MASTER_BRANCH" || \ |
Vincent Driessen | 1a2868b | 2010-02-07 23:23:16 +0100 | [diff] [blame] | 172 | die "Could not fetch $MASTER_BRANCH from $ORIGIN." |
Vincent Driessen | a4dd223 | 2010-02-10 00:34:59 +0100 | [diff] [blame] | 173 | git fetch -q "$ORIGIN" "$DEVELOP_BRANCH" || \ |
Vincent Driessen | 1a2868b | 2010-02-07 23:23:16 +0100 | [diff] [blame] | 174 | die "Could not fetch $DEVELOP_BRANCH from $ORIGIN." |
Vincent Driessen | 2acfffd | 2010-01-29 12:37:22 +0100 | [diff] [blame] | 175 | fi |
Vincent Driessen | a4dd223 | 2010-02-10 00:34:59 +0100 | [diff] [blame] | 176 | gitflow_require_branches_equal "$MASTER_BRANCH" "$ORIGIN/$MASTER_BRANCH" |
| 177 | gitflow_require_branches_equal "$DEVELOP_BRANCH" "$ORIGIN/$DEVELOP_BRANCH" |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 178 | |
Vincent Driessen | 5fa4758 | 2010-02-09 00:31:33 +0100 | [diff] [blame] | 179 | # try to merge into master |
| 180 | # in case a previous attempt to finish this release branch has failed, |
| 181 | # but the merge into master was successful, we skip it now |
Vincent Driessen | a4dd223 | 2010-02-10 00:34:59 +0100 | [diff] [blame] | 182 | if ! gitflow_is_branch_merged_into "$BRANCH" "$MASTER_BRANCH"; then |
| 183 | git checkout "$MASTER_BRANCH" || \ |
Vincent Driessen | 5fa4758 | 2010-02-09 00:31:33 +0100 | [diff] [blame] | 184 | die "Could not check out $MASTER_BRANCH." |
Vincent Driessen | a4dd223 | 2010-02-10 00:34:59 +0100 | [diff] [blame] | 185 | git merge --no-ff "$BRANCH" || \ |
Vincent Driessen | 5fa4758 | 2010-02-09 00:31:33 +0100 | [diff] [blame] | 186 | die "There were merge conflicts." |
| 187 | # TODO: What do we do now? |
| 188 | fi |
Vincent Driessen | 1a2868b | 2010-02-07 23:23:16 +0100 | [diff] [blame] | 189 | |
Vincent Driessen | 5fa4758 | 2010-02-09 00:31:33 +0100 | [diff] [blame] | 190 | # try to tag the release |
| 191 | # in case a previous attempt to finish this release branch has failed, |
| 192 | # but the tag was set successful, we skip it now |
| 193 | typeset tagname=$VERSION_PREFIX$VERSION |
Vincent Driessen | a4dd223 | 2010-02-10 00:34:59 +0100 | [diff] [blame] | 194 | if ! gitflow_tag_exists "$tagname"; then |
Vincent Driessen | 5fa4758 | 2010-02-09 00:31:33 +0100 | [diff] [blame] | 195 | typeset opts="-a" |
| 196 | flag sign && opts="$opts -s" |
| 197 | [ "$FLAGS_signingkey" != "" ] && opts="$opts -u '$FLAGS_signingkey'" |
| 198 | [ "$FLAGS_message" != "" ] && opts="$opts -m '$FLAGS_message'" |
| 199 | git tag $opts "$tagname" || \ |
| 200 | die "Tagging failed. Please run finish again to retry." |
| 201 | fi |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 202 | |
Vincent Driessen | 5fa4758 | 2010-02-09 00:31:33 +0100 | [diff] [blame] | 203 | # try to merge into develop |
| 204 | # in case a previous attempt to finish this release branch has failed, |
| 205 | # but the merge into develop was successful, we skip it now |
Vincent Driessen | a4dd223 | 2010-02-10 00:34:59 +0100 | [diff] [blame] | 206 | if ! gitflow_is_branch_merged_into "$BRANCH" "$DEVELOP_BRANCH"; then |
| 207 | git checkout "$DEVELOP_BRANCH" || \ |
Vincent Driessen | 5fa4758 | 2010-02-09 00:31:33 +0100 | [diff] [blame] | 208 | die "Could not check out $DEVELOP_BRANCH." |
Vincent Driessen | d29e315 | 2010-02-09 00:55:06 +0100 | [diff] [blame] | 209 | |
| 210 | # TODO: Actually, accounting for 'git describe' pays, so we should |
| 211 | # ideally git merge --no-ff $tagname here, instead! |
Vincent Driessen | a4dd223 | 2010-02-10 00:34:59 +0100 | [diff] [blame] | 212 | git merge --no-ff "$BRANCH" || \ |
Vincent Driessen | 5fa4758 | 2010-02-09 00:31:33 +0100 | [diff] [blame] | 213 | die "There were merge conflicts." |
| 214 | # TODO: What do we do now? |
| 215 | fi |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 216 | |
| 217 | # delete branch |
Vincent Driessen | a4dd223 | 2010-02-10 00:34:59 +0100 | [diff] [blame] | 218 | git branch -d "$BRANCH" |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 219 | |
| 220 | # TODO: Implement an optional push to master |
| 221 | # git push origin develop; git push origin master; git push --tags origin |
| 222 | |
| 223 | echo |
| 224 | echo "Summary of actions:" |
Benedikt Böhm | 350e715 | 2010-01-26 13:05:05 +0100 | [diff] [blame] | 225 | echo "- Latest objects have been fetched from '$ORIGIN'" |
Benedikt Böhm | 4a864fb | 2010-01-26 12:59:27 +0100 | [diff] [blame] | 226 | echo "- Release branch has been merged into '$MASTER_BRANCH'" |
Vincent Driessen | 5fa4758 | 2010-02-09 00:31:33 +0100 | [diff] [blame] | 227 | echo "- The release was tagged '$tagname'" |
Benedikt Böhm | 4a864fb | 2010-01-26 12:59:27 +0100 | [diff] [blame] | 228 | echo "- Release branch has been back-merged into '$DEVELOP_BRANCH'" |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 229 | echo "- Release branch '$BRANCH' has been deleted" |
| 230 | echo |
| 231 | } |