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/) |
Vincent Driessen | 2acfffd | 2010-01-29 12:37:22 +0100 | [diff] [blame] | 17 | FLAG_FETCH=1 |
Benedikt Böhm | 49dd62b | 2010-01-28 00:51:15 +0100 | [diff] [blame] | 18 | |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 19 | usage() { |
Vincent Driessen | 3c337fb | 2010-02-04 11:30:18 +0100 | [diff] [blame] | 20 | echo "usage: git flow release [list] [-v]" |
Vincent Driessen | 170dc74 | 2010-01-28 00:20:51 +0100 | [diff] [blame] | 21 | echo " git flow release start <version>" |
| 22 | echo " git flow release finish <version>" |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 23 | # TODO |
| 24 | #echo "" |
| 25 | #echo "options:" |
| 26 | #echo "--option Explanation" |
| 27 | #echo "" |
| 28 | #echo "start-only options:" |
| 29 | #echo "--bump <script>" |
| 30 | #echo " Run the given script to auto-update the version number" |
| 31 | #echo "" |
| 32 | #echo "finish-only options:" |
| 33 | #echo "--push Push to the origin repo when finished" |
| 34 | } |
| 35 | |
Vincent Driessen | 170dc74 | 2010-01-28 00:20:51 +0100 | [diff] [blame] | 36 | cmd_default() { |
Vincent Driessen | b866b01 | 2010-01-28 01:01:53 +0100 | [diff] [blame] | 37 | cmd_list "$@" |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 38 | } |
| 39 | |
Vincent Driessen | b866b01 | 2010-01-28 01:01:53 +0100 | [diff] [blame] | 40 | cmd_list() { |
Vincent Driessen | 3c337fb | 2010-02-04 11:30:18 +0100 | [diff] [blame] | 41 | DEFINE_boolean verbose false 'verbose (more) output' v |
| 42 | parse_args "$@" |
| 43 | |
Vincent Driessen | 170dc74 | 2010-01-28 00:20:51 +0100 | [diff] [blame] | 44 | RELEASE_BRANCHES="$(echo "$LOCAL_BRANCHES" | grep "^$PREFIX")" |
| 45 | if [ -z "$RELEASE_BRANCHES" ]; then |
| 46 | warn "No release branches exist." |
| 47 | exit 0 |
| 48 | fi |
Vincent Driessen | 3c337fb | 2010-02-04 11:30:18 +0100 | [diff] [blame] | 49 | |
| 50 | CURRENT_BRANCH=$(git branch | grep '^\* ' | grep -v 'no branch' | sed 's/^* //g') |
| 51 | SHORT_NAMES=$(echo "$RELEASE_BRANCHES" | sed "s?^$PREFIX??g") |
| 52 | # determine column width first |
| 53 | width=0 |
| 54 | for branch in $SHORT_NAMES; do |
| 55 | len=$(($(echo "$branch" | wc -c) - 1)) |
| 56 | width=$(max $width $len) |
| 57 | done |
| 58 | width=$(($width + 3)) |
| 59 | |
| 60 | for branch in $SHORT_NAMES; do |
| 61 | fullname="$PREFIX$branch" |
| 62 | base=$(git merge-base "$fullname" "$DEVELOP_BRANCH") |
| 63 | develop_sha=$(git rev-parse "$DEVELOP_BRANCH") |
| 64 | branch_sha=$(git rev-parse "$fullname") |
| 65 | if [ "$fullname" = "$CURRENT_BRANCH" ]; then |
| 66 | printf "* " |
| 67 | else |
| 68 | printf " " |
| 69 | fi |
| 70 | if flag verbose; then |
| 71 | printf "%-${width}s" "$branch" |
| 72 | if [ "$branch_sha" = "$develop_sha" ]; then |
| 73 | printf "(no commits yet)" |
| 74 | else |
| 75 | nicename="$(git rev-parse --short $base)" |
| 76 | printf "(based on $nicename)" |
| 77 | fi |
| 78 | else |
| 79 | printf "%s" "$branch" |
| 80 | fi |
| 81 | echo |
| 82 | done |
Vincent Driessen | 170dc74 | 2010-01-28 00:20:51 +0100 | [diff] [blame] | 83 | } |
| 84 | |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 85 | cmd_help() { |
| 86 | usage |
| 87 | exit 0 |
| 88 | } |
| 89 | |
Vincent Driessen | b866b01 | 2010-01-28 01:01:53 +0100 | [diff] [blame] | 90 | parse_args() { |
Vincent Driessen | 3c337fb | 2010-02-04 11:30:18 +0100 | [diff] [blame] | 91 | # parse options |
| 92 | FLAGS "$@" || exit $? |
| 93 | eval set -- "${FLAGS_ARGV}" |
| 94 | |
| 95 | # read arguments into global variables |
Vincent Driessen | b866b01 | 2010-01-28 01:01:53 +0100 | [diff] [blame] | 96 | VERSION="$1" |
Vincent Driessen | 3c337fb | 2010-02-04 11:30:18 +0100 | [diff] [blame] | 97 | BRANCH="$PREFIX$VERSION" |
| 98 | } |
| 99 | |
| 100 | require_version_arg() { |
Vincent Driessen | b866b01 | 2010-01-28 01:01:53 +0100 | [diff] [blame] | 101 | if [ "$VERSION" = "" ]; then |
Vincent Driessen | 3c337fb | 2010-02-04 11:30:18 +0100 | [diff] [blame] | 102 | warn "Missing argument <version>" |
Vincent Driessen | b866b01 | 2010-01-28 01:01:53 +0100 | [diff] [blame] | 103 | usage |
| 104 | exit 1 |
| 105 | fi |
Vincent Driessen | b866b01 | 2010-01-28 01:01:53 +0100 | [diff] [blame] | 106 | } |
| 107 | |
Vincent Driessen | 010252a | 2010-02-04 10:31:29 +0100 | [diff] [blame] | 108 | require_base_is_on_develop() { |
| 109 | if ! git branch --contains "$BASE" 2>/dev/null \ |
| 110 | | sed 's/[* ] //g' \ |
| 111 | | grep -q "^$DEVELOP_BRANCH\$"; then |
| 112 | die "fatal: Given base '$BASE' is not a valid commit on '$DEVELOP_BRANCH'." |
| 113 | fi |
| 114 | } |
| 115 | |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 116 | cmd_start() { |
| 117 | parse_args "$@" |
Vincent Driessen | 010252a | 2010-02-04 10:31:29 +0100 | [diff] [blame] | 118 | BASE="${2:-$DEVELOP_BRANCH}" |
Vincent Driessen | 3c337fb | 2010-02-04 11:30:18 +0100 | [diff] [blame] | 119 | require_version_arg |
Vincent Driessen | 010252a | 2010-02-04 10:31:29 +0100 | [diff] [blame] | 120 | require_base_is_on_develop |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 121 | |
| 122 | # sanity checks |
Vincent Driessen | 4838644 | 2010-01-29 10:30:40 +0100 | [diff] [blame] | 123 | gitflow_require_clean_working_tree |
Vincent Driessen | 2acfffd | 2010-01-29 12:37:22 +0100 | [diff] [blame] | 124 | if [ $FLAG_FETCH -eq 1 ]; then |
| 125 | git fetch -q $ORIGIN $DEVELOP_BRANCH |
| 126 | fi |
Benedikt Böhm | 350e715 | 2010-01-26 13:05:05 +0100 | [diff] [blame] | 127 | gitflow_require_branches_equal $DEVELOP_BRANCH $ORIGIN/$DEVELOP_BRANCH |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 128 | gitflow_require_branch_absent $BRANCH |
| 129 | |
| 130 | # create branch |
Vincent Driessen | 010252a | 2010-02-04 10:31:29 +0100 | [diff] [blame] | 131 | git checkout -b $BRANCH $BASE |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 132 | |
| 133 | echo |
| 134 | echo "Summary of actions:" |
Vincent Driessen | 010252a | 2010-02-04 10:31:29 +0100 | [diff] [blame] | 135 | echo "- A new branch '$BRANCH' was created, based on '$BASE'" |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 136 | echo "- You are now on branch '$BRANCH'" |
| 137 | echo |
| 138 | echo "Follow-up actions:" |
| 139 | echo "- Bump the version number now!" |
| 140 | echo "- Start committing last-minute fixes in preparing your release" |
| 141 | echo "- When done, run:" |
| 142 | echo |
Vincent Driessen | 010252a | 2010-02-04 10:31:29 +0100 | [diff] [blame] | 143 | echo " git flow release finish '$VERSION'" |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 144 | echo |
| 145 | } |
| 146 | |
| 147 | cmd_finish() { |
| 148 | parse_args "$@" |
Vincent Driessen | 3c337fb | 2010-02-04 11:30:18 +0100 | [diff] [blame] | 149 | require_version_arg |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 150 | |
| 151 | # sanity checks |
Vincent Driessen | 4838644 | 2010-01-29 10:30:40 +0100 | [diff] [blame] | 152 | gitflow_require_clean_working_tree |
Vincent Driessen | 2acfffd | 2010-01-29 12:37:22 +0100 | [diff] [blame] | 153 | if [ $FLAG_FETCH -eq 1 ]; then |
| 154 | git fetch -q $ORIGIN $MASTER_BRANCH |
| 155 | git fetch -q $ORIGIN $DEVELOP_BRANCH |
| 156 | fi |
Benedikt Böhm | 350e715 | 2010-01-26 13:05:05 +0100 | [diff] [blame] | 157 | gitflow_require_branches_equal $MASTER_BRANCH $ORIGIN/$MASTER_BRANCH |
| 158 | gitflow_require_branches_equal $DEVELOP_BRANCH $ORIGIN/$DEVELOP_BRANCH |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 159 | |
| 160 | # merge into master |
Benedikt Böhm | 4a864fb | 2010-01-26 12:59:27 +0100 | [diff] [blame] | 161 | git checkout $MASTER_BRANCH |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 162 | git merge --no-ff $BRANCH |
Benedikt Böhm | b22a076 | 2010-01-28 01:07:06 +0800 | [diff] [blame] | 163 | git tag $VERSION_PREFIX$VERSION |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 164 | |
| 165 | # merge into develop |
Benedikt Böhm | 4a864fb | 2010-01-26 12:59:27 +0100 | [diff] [blame] | 166 | git checkout $DEVELOP_BRANCH |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 167 | git merge --no-ff $BRANCH |
| 168 | |
| 169 | # delete branch |
| 170 | git branch -d $BRANCH |
| 171 | |
| 172 | # TODO: Implement an optional push to master |
| 173 | # git push origin develop; git push origin master; git push --tags origin |
| 174 | |
| 175 | echo |
| 176 | echo "Summary of actions:" |
Benedikt Böhm | 350e715 | 2010-01-26 13:05:05 +0100 | [diff] [blame] | 177 | echo "- Latest objects have been fetched from '$ORIGIN'" |
Benedikt Böhm | 4a864fb | 2010-01-26 12:59:27 +0100 | [diff] [blame] | 178 | echo "- Release branch has been merged into '$MASTER_BRANCH'" |
Vincent Driessen | 3911e16 | 2010-01-27 22:20:47 +0100 | [diff] [blame] | 179 | echo "- The release was tagged '$VERSION_PREFIX$VERSION'" |
Benedikt Böhm | 4a864fb | 2010-01-26 12:59:27 +0100 | [diff] [blame] | 180 | echo "- Release branch has been back-merged into '$DEVELOP_BRANCH'" |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 181 | echo "- Release branch '$BRANCH' has been deleted" |
| 182 | echo |
| 183 | } |