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: |
Vincent Driessen | ddb350b | 2010-07-09 09:42:09 +0200 | [diff] [blame] | 6 | # http://nvie.com/git-model |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 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 |
Vincent Driessen | c1598bf | 2010-02-20 16:52:48 +0100 | [diff] [blame] | 42 | PREFIX=$(git config --get gitflow.prefix.feature) |
Benedikt Böhm | 49dd62b | 2010-01-28 00:51:15 +0100 | [diff] [blame] | 43 | |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 44 | usage() { |
Vincent Driessen | b03cf96 | 2010-02-01 22:00:39 +0100 | [diff] [blame] | 45 | echo "usage: git flow feature [list] [-v]" |
Vincent Driessen | 2b829ce | 2010-07-09 09:36:20 +0200 | [diff] [blame] | 46 | echo " git flow feature start [-F] <name> [<base>]" |
Guillaume-Jean Herbiet | 8fee0c2 | 2010-10-04 11:35:10 +0200 | [diff] [blame] | 47 | echo " git flow feature finish [-rFk] <name|nameprefix>" |
Vincent Driessen | 186d2b5 | 2010-01-27 23:48:39 +0100 | [diff] [blame] | 48 | echo " git flow feature publish <name>" |
| 49 | echo " git flow feature track <name>" |
Vincent Driessen | a2e4116 | 2010-02-24 01:37:07 +0100 | [diff] [blame] | 50 | echo " git flow feature diff [<name|nameprefix>]" |
| 51 | echo " git flow feature rebase [-i] [<name|nameprefix>]" |
Vincent Driessen | d43ab84 | 2010-05-27 11:26:01 -0700 | [diff] [blame] | 52 | echo " git flow feature checkout [<name|nameprefix>]" |
Vincent Driessen | f68d405 | 2010-07-09 12:34:18 +0200 | [diff] [blame] | 53 | echo " git flow feature pull <remote> [<name>]" |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 54 | } |
| 55 | |
Vincent Driessen | 186d2b5 | 2010-01-27 23:48:39 +0100 | [diff] [blame] | 56 | cmd_default() { |
Vincent Driessen | b866b01 | 2010-01-28 01:01:53 +0100 | [diff] [blame] | 57 | cmd_list "$@" |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 58 | } |
| 59 | |
Vincent Driessen | b866b01 | 2010-01-28 01:01:53 +0100 | [diff] [blame] | 60 | cmd_list() { |
Vincent Driessen | 4417492 | 2010-02-02 23:53:21 +0100 | [diff] [blame] | 61 | DEFINE_boolean verbose false 'verbose (more) output' v |
Vincent Driessen | 1b81923 | 2010-02-01 15:51:43 +0100 | [diff] [blame] | 62 | parse_args "$@" |
| 63 | |
Vincent Driessen | f46e290 | 2010-02-15 23:01:52 +0100 | [diff] [blame] | 64 | local feature_branches |
| 65 | local current_branch |
| 66 | local short_names |
Vincent Driessen | 7832d6e | 2010-02-21 21:31:03 +0100 | [diff] [blame] | 67 | feature_branches=$(echo "$(git_local_branches)" | grep "^$PREFIX") |
Vincent Driessen | 27592dd | 2010-02-06 14:45:39 +0100 | [diff] [blame] | 68 | if [ -z "$feature_branches" ]; then |
Vincent Driessen | 186d2b5 | 2010-01-27 23:48:39 +0100 | [diff] [blame] | 69 | warn "No feature branches exist." |
Randy Merrill | b681b45 | 2010-06-26 13:14:15 +0800 | [diff] [blame] | 70 | warn "" |
| 71 | warn "You can start a new feature branch:" |
| 72 | warn "" |
| 73 | warn " git flow feature start <name> [<base>]" |
Randy Merrill | 4de01f2 | 2010-06-26 13:19:06 +0800 | [diff] [blame] | 74 | warn "" |
Vincent Driessen | 186d2b5 | 2010-01-27 23:48:39 +0100 | [diff] [blame] | 75 | exit 0 |
| 76 | fi |
Adam Gibbins | cf3da5a | 2010-08-22 19:13:34 +0100 | [diff] [blame] | 77 | current_branch=$(git branch --no-color | grep '^\* ' | grep -v 'no branch' | sed 's/^* //g') |
Vincent Driessen | 27592dd | 2010-02-06 14:45:39 +0100 | [diff] [blame] | 78 | short_names=$(echo "$feature_branches" | sed "s ^$PREFIX g") |
Vincent Driessen | f2536f4 | 2010-02-01 15:57:48 +0100 | [diff] [blame] | 79 | |
Vincent Driessen | aa6d016 | 2010-02-01 19:43:46 +0100 | [diff] [blame] | 80 | # determine column width first |
Vincent Driessen | f46e290 | 2010-02-15 23:01:52 +0100 | [diff] [blame] | 81 | local width=0 |
| 82 | local branch |
Vincent Driessen | 27592dd | 2010-02-06 14:45:39 +0100 | [diff] [blame] | 83 | for branch in $short_names; do |
Vincent Driessen | f46e290 | 2010-02-15 23:01:52 +0100 | [diff] [blame] | 84 | local len=${#branch} |
Vincent Driessen | aa6d016 | 2010-02-01 19:43:46 +0100 | [diff] [blame] | 85 | width=$(max $width $len) |
| 86 | done |
Vincent Driessen | f46e290 | 2010-02-15 23:01:52 +0100 | [diff] [blame] | 87 | width=$(($width+3)) |
Vincent Driessen | 1adbc3e | 2010-01-30 16:28:20 +0100 | [diff] [blame] | 88 | |
Vincent Driessen | f46e290 | 2010-02-15 23:01:52 +0100 | [diff] [blame] | 89 | local branch |
Vincent Driessen | 27592dd | 2010-02-06 14:45:39 +0100 | [diff] [blame] | 90 | for branch in $short_names; do |
Vincent Driessen | f46e290 | 2010-02-15 23:01:52 +0100 | [diff] [blame] | 91 | local fullname=$PREFIX$branch |
| 92 | local base=$(git merge-base "$fullname" "$DEVELOP_BRANCH") |
| 93 | local develop_sha=$(git rev-parse "$DEVELOP_BRANCH") |
| 94 | local branch_sha=$(git rev-parse "$fullname") |
Vincent Driessen | 27592dd | 2010-02-06 14:45:39 +0100 | [diff] [blame] | 95 | if [ "$fullname" = "$current_branch" ]; then |
Vincent Driessen | aa6d016 | 2010-02-01 19:43:46 +0100 | [diff] [blame] | 96 | printf "* " |
| 97 | else |
| 98 | printf " " |
| 99 | fi |
Vincent Driessen | 4417492 | 2010-02-02 23:53:21 +0100 | [diff] [blame] | 100 | if flag verbose; then |
Vincent Driessen | 1adbc3e | 2010-01-30 16:28:20 +0100 | [diff] [blame] | 101 | printf "%-${width}s" "$branch" |
Vincent Driessen | f2536f4 | 2010-02-01 15:57:48 +0100 | [diff] [blame] | 102 | if [ "$branch_sha" = "$develop_sha" ]; then |
| 103 | printf "(no commits yet)" |
| 104 | elif [ "$base" = "$branch_sha" ]; then |
| 105 | printf "(is behind develop, may ff)" |
| 106 | elif [ "$base" = "$develop_sha" ]; then |
| 107 | printf "(based on latest develop)" |
| 108 | else |
| 109 | printf "(may be rebased)" |
| 110 | fi |
Vincent Driessen | aa6d016 | 2010-02-01 19:43:46 +0100 | [diff] [blame] | 111 | else |
| 112 | printf "%s" "$branch" |
| 113 | fi |
| 114 | echo |
| 115 | done |
Vincent Driessen | 186d2b5 | 2010-01-27 23:48:39 +0100 | [diff] [blame] | 116 | } |
| 117 | |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 118 | cmd_help() { |
| 119 | usage |
| 120 | exit 0 |
| 121 | } |
| 122 | |
Vincent Driessen | d099126 | 2010-02-06 21:19:07 +0100 | [diff] [blame] | 123 | require_name_arg() { |
Vincent Driessen | 1b81923 | 2010-02-01 15:51:43 +0100 | [diff] [blame] | 124 | if [ "$NAME" = "" ]; then |
Vincent Driessen | 3c337fb | 2010-02-04 11:30:18 +0100 | [diff] [blame] | 125 | warn "Missing argument <name>" |
Vincent Driessen | 1b81923 | 2010-02-01 15:51:43 +0100 | [diff] [blame] | 126 | usage |
Vincent Driessen | 2e1856b | 2010-01-29 15:18:13 +0100 | [diff] [blame] | 127 | exit 1 |
| 128 | fi |
| 129 | } |
| 130 | |
Vincent Driessen | d099126 | 2010-02-06 21:19:07 +0100 | [diff] [blame] | 131 | expand_nameprefix_arg() { |
| 132 | require_name_arg |
| 133 | |
Vincent Driessen | f46e290 | 2010-02-15 23:01:52 +0100 | [diff] [blame] | 134 | local expanded_name |
| 135 | local exitcode |
Vincent Driessen | 7832d6e | 2010-02-21 21:31:03 +0100 | [diff] [blame] | 136 | expanded_name=$(gitflow_resolve_nameprefix "$NAME" "$PREFIX") |
Vincent Driessen | d099126 | 2010-02-06 21:19:07 +0100 | [diff] [blame] | 137 | exitcode=$? |
| 138 | case $exitcode in |
| 139 | 0) NAME=$expanded_name |
| 140 | BRANCH=$PREFIX$NAME |
| 141 | ;; |
| 142 | *) exit 1 ;; |
| 143 | esac |
Vincent Driessen | 2e1856b | 2010-01-29 15:18:13 +0100 | [diff] [blame] | 144 | } |
| 145 | |
Vincent Driessen | f68d405 | 2010-07-09 12:34:18 +0200 | [diff] [blame] | 146 | use_current_feature_branch_name() { |
| 147 | local current_branch=$(git_current_branch) |
| 148 | if startswith "$current_branch" "$PREFIX"; then |
| 149 | BRANCH=$current_branch |
| 150 | NAME=${BRANCH#$PREFIX} |
| 151 | else |
| 152 | warn "The current HEAD is no feature branch." |
| 153 | warn "Please specify a <name> argument." |
| 154 | exit 1 |
| 155 | fi |
| 156 | } |
| 157 | |
Vincent Driessen | d099126 | 2010-02-06 21:19:07 +0100 | [diff] [blame] | 158 | expand_nameprefix_arg_or_current() { |
Vincent Driessen | c62633f | 2010-02-02 10:48:50 +0100 | [diff] [blame] | 159 | if [ "$NAME" != "" ]; then |
Vincent Driessen | d099126 | 2010-02-06 21:19:07 +0100 | [diff] [blame] | 160 | expand_nameprefix_arg |
Vincent Driessen | 7832d6e | 2010-02-21 21:31:03 +0100 | [diff] [blame] | 161 | require_branch "$PREFIX$NAME" |
Vincent Driessen | c62633f | 2010-02-02 10:48:50 +0100 | [diff] [blame] | 162 | else |
Vincent Driessen | f68d405 | 2010-07-09 12:34:18 +0200 | [diff] [blame] | 163 | use_current_feature_branch_name |
Vincent Driessen | c62633f | 2010-02-02 10:48:50 +0100 | [diff] [blame] | 164 | fi |
| 165 | } |
| 166 | |
Vincent Driessen | f68d405 | 2010-07-09 12:34:18 +0200 | [diff] [blame] | 167 | name_or_current() { |
| 168 | if [ -z "$NAME" ]; then |
| 169 | use_current_feature_branch_name |
| 170 | fi |
| 171 | } |
| 172 | |
| 173 | parse_cmdline() { |
Vincent Driessen | 1b81923 | 2010-02-01 15:51:43 +0100 | [diff] [blame] | 174 | # parse options |
| 175 | FLAGS "$@" || exit $? |
| 176 | eval set -- "${FLAGS_ARGV}" |
Vincent Driessen | f68d405 | 2010-07-09 12:34:18 +0200 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | parse_args() { |
| 180 | parse_cmdline "$@" |
Vincent Driessen | 1b81923 | 2010-02-01 15:51:43 +0100 | [diff] [blame] | 181 | |
| 182 | # read arguments into global variables |
Guillaume-Jean Herbiet | 8fee0c2 | 2010-10-04 11:35:10 +0200 | [diff] [blame] | 183 | NAME=${!#} |
Vincent Driessen | 1156092 | 2010-02-01 21:58:37 +0100 | [diff] [blame] | 184 | BRANCH=$PREFIX$NAME |
Vincent Driessen | b866b01 | 2010-01-28 01:01:53 +0100 | [diff] [blame] | 185 | } |
| 186 | |
Vincent Driessen | f68d405 | 2010-07-09 12:34:18 +0200 | [diff] [blame] | 187 | parse_remote_name() { |
| 188 | parse_cmdline "$@" |
| 189 | |
| 190 | # read arguments into global variables |
| 191 | REMOTE=$1 |
| 192 | NAME=$2 |
| 193 | BRANCH=$PREFIX$NAME |
| 194 | } |
| 195 | |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 196 | cmd_start() { |
Vincent Driessen | 4417492 | 2010-02-02 23:53:21 +0100 | [diff] [blame] | 197 | DEFINE_boolean fetch false 'fetch from origin before performing local operation' F |
Vincent Driessen | ea60895 | 2010-01-29 16:56:29 +0100 | [diff] [blame] | 198 | parse_args "$@" |
Vincent Driessen | c5fcc01 | 2010-02-10 00:18:08 +0100 | [diff] [blame] | 199 | BASE=${2:-$DEVELOP_BRANCH} |
Vincent Driessen | d099126 | 2010-02-06 21:19:07 +0100 | [diff] [blame] | 200 | require_name_arg |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 201 | |
| 202 | # sanity checks |
Vincent Driessen | 7832d6e | 2010-02-21 21:31:03 +0100 | [diff] [blame] | 203 | require_branch_absent "$BRANCH" |
Vincent Driessen | e034e4a | 2010-01-29 12:10:44 +0100 | [diff] [blame] | 204 | |
| 205 | # update the local repo with remote changes, if asked |
Vincent Driessen | 4417492 | 2010-02-02 23:53:21 +0100 | [diff] [blame] | 206 | if flag fetch; then |
Vincent Driessen | a4dd223 | 2010-02-10 00:34:59 +0100 | [diff] [blame] | 207 | git fetch -q "$ORIGIN" "$DEVELOP_BRANCH" |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 208 | fi |
| 209 | |
Vincent Driessen | c118a85 | 2010-04-04 16:32:04 +0200 | [diff] [blame] | 210 | # if the origin branch counterpart exists, assert that the local branch |
| 211 | # isn't behind it (to avoid unnecessary rebasing) |
| 212 | if git_branch_exists "$ORIGIN/$DEVELOP_BRANCH"; then |
| 213 | require_branches_equal "$DEVELOP_BRANCH" "$ORIGIN/$DEVELOP_BRANCH" |
| 214 | fi |
Vincent Driessen | e034e4a | 2010-01-29 12:10:44 +0100 | [diff] [blame] | 215 | |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 216 | # create branch |
Vincent Driessen | a4dd223 | 2010-02-10 00:34:59 +0100 | [diff] [blame] | 217 | if ! git checkout -b "$BRANCH" "$BASE"; then |
Vincent Driessen | 5455a6f | 2010-02-03 00:14:05 +0100 | [diff] [blame] | 218 | die "Could not create feature branch '$BRANCH'" |
| 219 | fi |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 220 | |
| 221 | echo |
| 222 | echo "Summary of actions:" |
| 223 | echo "- A new branch '$BRANCH' was created, based on '$BASE'" |
| 224 | echo "- You are now on branch '$BRANCH'" |
| 225 | echo "" |
| 226 | echo "Now, start committing on your feature. When done, use:" |
| 227 | echo "" |
gmallard | 192ff52 | 2010-04-01 19:31:09 -0400 | [diff] [blame] | 228 | echo " git flow feature finish $NAME" |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 229 | echo |
| 230 | } |
| 231 | |
| 232 | cmd_finish() { |
Vincent Driessen | ca73caf | 2010-02-07 19:46:38 +0100 | [diff] [blame] | 233 | DEFINE_boolean fetch false "fetch from $ORIGIN before performing finish" F |
Vincent Driessen | 4417492 | 2010-02-02 23:53:21 +0100 | [diff] [blame] | 234 | DEFINE_boolean rebase false 'rebase instead of merge' r |
Guillaume-Jean Herbiet | 8fee0c2 | 2010-10-04 11:35:10 +0200 | [diff] [blame] | 235 | DEFINE_boolean keep false 'keep branch after performing finish' k |
Vincent Driessen | 1b81923 | 2010-02-01 15:51:43 +0100 | [diff] [blame] | 236 | parse_args "$@" |
Vincent Driessen | d099126 | 2010-02-06 21:19:07 +0100 | [diff] [blame] | 237 | expand_nameprefix_arg |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 238 | |
| 239 | # sanity checks |
Vincent Driessen | 7832d6e | 2010-02-21 21:31:03 +0100 | [diff] [blame] | 240 | require_branch "$BRANCH" |
Vincent Driessen | e034e4a | 2010-01-29 12:10:44 +0100 | [diff] [blame] | 241 | |
Vincent Driessen | 49c7d02 | 2010-01-28 12:40:33 +0100 | [diff] [blame] | 242 | # detect if we're restoring from a merge conflict |
Vincent Driessen | cf6e92a | 2010-02-19 19:44:48 +0100 | [diff] [blame] | 243 | if [ -f "$DOT_GIT_DIR/.gitflow/MERGE_BASE" ]; then |
Vincent Driessen | 49c7d02 | 2010-01-28 12:40:33 +0100 | [diff] [blame] | 244 | # |
| 245 | # TODO: detect that we're working on the correct branch here! |
| 246 | # The user need not necessarily have given the same $NAME twice here |
| 247 | # (although he/she should). |
| 248 | # |
Vincent Driessen | f6f152f | 2010-01-29 10:28:08 +0100 | [diff] [blame] | 249 | |
Vincent Driessen | 7832d6e | 2010-02-21 21:31:03 +0100 | [diff] [blame] | 250 | # TODO: git_is_clean_working_tree() should provide an alternative |
Vincent Driessen | f6f152f | 2010-01-29 10:28:08 +0100 | [diff] [blame] | 251 | # exit code for "unmerged changes in working tree", which we should |
| 252 | # actually be testing for here |
Vincent Driessen | 7832d6e | 2010-02-21 21:31:03 +0100 | [diff] [blame] | 253 | if git_is_clean_working_tree; then |
Vincent Driessen | cf6e92a | 2010-02-19 19:44:48 +0100 | [diff] [blame] | 254 | FINISH_BASE=$(cat "$DOT_GIT_DIR/.gitflow/MERGE_BASE") |
Vincent Driessen | f6f152f | 2010-01-29 10:28:08 +0100 | [diff] [blame] | 255 | |
| 256 | # Since the working tree is now clean, either the user did a |
| 257 | # succesfull merge manually, or the merge was cancelled. |
Vincent Driessen | 7832d6e | 2010-02-21 21:31:03 +0100 | [diff] [blame] | 258 | # We detect this using git_is_branch_merged_into() |
| 259 | if git_is_branch_merged_into "$BRANCH" "$FINISH_BASE"; then |
Vincent Driessen | cf6e92a | 2010-02-19 19:44:48 +0100 | [diff] [blame] | 260 | rm -f "$DOT_GIT_DIR/.gitflow/MERGE_BASE" |
Vincent Driessen | f6f152f | 2010-01-29 10:28:08 +0100 | [diff] [blame] | 261 | helper_finish_cleanup |
| 262 | exit 0 |
| 263 | else |
| 264 | # If the user cancelled the merge and decided to wait until later, |
| 265 | # that's fine. But we have to acknowledge this by removing the |
| 266 | # MERGE_BASE file and continuing normal execution of the finish |
Vincent Driessen | cf6e92a | 2010-02-19 19:44:48 +0100 | [diff] [blame] | 267 | rm -f "$DOT_GIT_DIR/.gitflow/MERGE_BASE" |
Vincent Driessen | f6f152f | 2010-01-29 10:28:08 +0100 | [diff] [blame] | 268 | fi |
Vincent Driessen | 49c7d02 | 2010-01-28 12:40:33 +0100 | [diff] [blame] | 269 | else |
| 270 | echo |
| 271 | echo "Merge conflicts not resolved yet, use:" |
| 272 | echo " git mergetool" |
| 273 | echo " git commit" |
| 274 | echo |
| 275 | echo "You can then complete the finish by running it again:" |
| 276 | echo " git flow feature finish $NAME" |
| 277 | echo |
| 278 | exit 1 |
| 279 | fi |
| 280 | fi |
| 281 | |
Vincent Driessen | f6f152f | 2010-01-29 10:28:08 +0100 | [diff] [blame] | 282 | # sanity checks |
Vincent Driessen | 7832d6e | 2010-02-21 21:31:03 +0100 | [diff] [blame] | 283 | require_clean_working_tree |
Vincent Driessen | f6f152f | 2010-01-29 10:28:08 +0100 | [diff] [blame] | 284 | |
Vincent Driessen | e034e4a | 2010-01-29 12:10:44 +0100 | [diff] [blame] | 285 | # update local repo with remote changes first, if asked |
Mark Derricutt | 8a86c48 | 2010-07-20 21:11:48 +1200 | [diff] [blame] | 286 | if has "$ORIGIN/$BRANCH" "$(git_remote_branches)"; then |
Vincent Driessen | cb654b1 | 2010-07-21 13:28:54 +0200 | [diff] [blame] | 287 | if flag fetch; then |
| 288 | git fetch -q "$ORIGIN" "$BRANCH" |
| 289 | fi |
Vincent Driessen | e034e4a | 2010-01-29 12:10:44 +0100 | [diff] [blame] | 290 | fi |
| 291 | |
Vincent Driessen | 7832d6e | 2010-02-21 21:31:03 +0100 | [diff] [blame] | 292 | if has "$ORIGIN/$BRANCH" "$(git_remote_branches)"; then |
| 293 | require_branches_equal "$BRANCH" "$ORIGIN/$BRANCH" |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 294 | fi |
Mark Derricutt | 8a86c48 | 2010-07-20 21:11:48 +1200 | [diff] [blame] | 295 | if has "$ORIGIN/$DEVELOP_BRANCH" "$(git_remote_branches)"; then |
Vincent Driessen | cb654b1 | 2010-07-21 13:28:54 +0200 | [diff] [blame] | 296 | require_branches_equal "$DEVELOP_BRANCH" "$ORIGIN/$DEVELOP_BRANCH" |
| 297 | fi |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 298 | |
Vincent Driessen | 95bf82c | 2010-02-02 11:58:37 +0100 | [diff] [blame] | 299 | # if the user wants to rebase, do that first |
Vincent Driessen | 4417492 | 2010-02-02 23:53:21 +0100 | [diff] [blame] | 300 | if flag rebase; then |
Vincent Driessen | 010252a | 2010-02-04 10:31:29 +0100 | [diff] [blame] | 301 | if ! git flow feature rebase "$NAME" "$DEVELOP_BRANCH"; then |
Vincent Driessen | 95bf82c | 2010-02-02 11:58:37 +0100 | [diff] [blame] | 302 | warn "Finish was aborted due to conflicts during rebase." |
| 303 | warn "Please finish the rebase manually now." |
| 304 | warn "When finished, re-run:" |
Vincent Driessen | 010252a | 2010-02-04 10:31:29 +0100 | [diff] [blame] | 305 | warn " git flow feature finish '$NAME' '$DEVELOP_BRANCH'" |
Vincent Driessen | 95bf82c | 2010-02-02 11:58:37 +0100 | [diff] [blame] | 306 | exit 1 |
| 307 | fi |
| 308 | fi |
| 309 | |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 310 | # merge into BASE |
Vincent Driessen | a4dd223 | 2010-02-10 00:34:59 +0100 | [diff] [blame] | 311 | git checkout "$DEVELOP_BRANCH" |
| 312 | if [ "$(git rev-list -n2 "$DEVELOP_BRANCH..$BRANCH" | wc -l)" -eq 1 ]; then |
| 313 | git merge --ff "$BRANCH" |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 314 | else |
Vincent Driessen | a4dd223 | 2010-02-10 00:34:59 +0100 | [diff] [blame] | 315 | git merge --no-ff "$BRANCH" |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 316 | fi |
| 317 | |
Vincent Driessen | 49c7d02 | 2010-01-28 12:40:33 +0100 | [diff] [blame] | 318 | if [ $? -ne 0 ]; then |
| 319 | # oops.. we have a merge conflict! |
Vincent Driessen | 010252a | 2010-02-04 10:31:29 +0100 | [diff] [blame] | 320 | # write the given $DEVELOP_BRANCH to a temporary file (we need it later) |
Vincent Driessen | cf6e92a | 2010-02-19 19:44:48 +0100 | [diff] [blame] | 321 | mkdir -p "$DOT_GIT_DIR/.gitflow" |
| 322 | echo "$DEVELOP_BRANCH" > "$DOT_GIT_DIR/.gitflow/MERGE_BASE" |
Vincent Driessen | 49c7d02 | 2010-01-28 12:40:33 +0100 | [diff] [blame] | 323 | echo |
| 324 | echo "There were merge conflicts. To resolve the merge conflict manually, use:" |
| 325 | echo " git mergetool" |
| 326 | echo " git commit" |
| 327 | echo |
| 328 | echo "You can then complete the finish by running it again:" |
| 329 | echo " git flow feature finish $NAME" |
| 330 | echo |
| 331 | exit 1 |
| 332 | fi |
| 333 | |
| 334 | # when no merge conflict is detected, just clean up the feature branch |
| 335 | helper_finish_cleanup |
| 336 | } |
| 337 | |
| 338 | helper_finish_cleanup() { |
Vincent Driessen | f6f152f | 2010-01-29 10:28:08 +0100 | [diff] [blame] | 339 | # sanity checks |
Vincent Driessen | 7832d6e | 2010-02-21 21:31:03 +0100 | [diff] [blame] | 340 | require_branch "$BRANCH" |
| 341 | require_clean_working_tree |
Vincent Driessen | f6f152f | 2010-01-29 10:28:08 +0100 | [diff] [blame] | 342 | |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 343 | # delete branch |
Vincent Driessen | 4417492 | 2010-02-02 23:53:21 +0100 | [diff] [blame] | 344 | if flag fetch; then |
Vincent Driessen | a4dd223 | 2010-02-10 00:34:59 +0100 | [diff] [blame] | 345 | git push "$ORIGIN" ":refs/heads/$BRANCH" |
Vincent Driessen | eec73c6 | 2010-02-02 16:14:16 +0100 | [diff] [blame] | 346 | fi |
Guillaume-Jean Herbiet | 8fee0c2 | 2010-10-04 11:35:10 +0200 | [diff] [blame] | 347 | |
| 348 | |
| 349 | if flag keep; then |
| 350 | echo "Keep this branch" > /dev/null |
| 351 | else |
| 352 | git branch -d "$BRANCH" |
| 353 | fi |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 354 | |
| 355 | echo |
| 356 | echo "Summary of actions:" |
Vincent Driessen | 010252a | 2010-02-04 10:31:29 +0100 | [diff] [blame] | 357 | echo "- The feature branch '$BRANCH' was merged into '$DEVELOP_BRANCH'" |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 358 | #echo "- Merge conflicts were resolved" # TODO: Add this line when it's supported |
Guillaume-Jean Herbiet | 8fee0c2 | 2010-10-04 11:35:10 +0200 | [diff] [blame] | 359 | if flag keep; then |
| 360 | echo "- Feature branch '$BRANCH' has been kept" |
| 361 | else |
| 362 | echo "- Feature branch '$BRANCH' has been removed" |
| 363 | fi |
Vincent Driessen | 010252a | 2010-02-04 10:31:29 +0100 | [diff] [blame] | 364 | echo "- You are now on branch '$DEVELOP_BRANCH'" |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 365 | echo |
| 366 | } |
| 367 | |
| 368 | cmd_publish() { |
Vincent Driessen | ea60895 | 2010-01-29 16:56:29 +0100 | [diff] [blame] | 369 | parse_args "$@" |
Vincent Driessen | d099126 | 2010-02-06 21:19:07 +0100 | [diff] [blame] | 370 | expand_nameprefix_arg |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 371 | |
| 372 | # sanity checks |
Vincent Driessen | 7832d6e | 2010-02-21 21:31:03 +0100 | [diff] [blame] | 373 | require_clean_working_tree |
| 374 | require_branch "$BRANCH" |
Vincent Driessen | a4dd223 | 2010-02-10 00:34:59 +0100 | [diff] [blame] | 375 | git fetch -q "$ORIGIN" |
Vincent Driessen | 7832d6e | 2010-02-21 21:31:03 +0100 | [diff] [blame] | 376 | require_branch_absent "$ORIGIN/$BRANCH" |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 377 | |
| 378 | # create remote branch |
Vincent Driessen | a4dd223 | 2010-02-10 00:34:59 +0100 | [diff] [blame] | 379 | git push "$ORIGIN" "$BRANCH:refs/heads/$BRANCH" |
| 380 | git fetch -q "$ORIGIN" |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 381 | |
| 382 | # configure remote tracking |
Vincent Driessen | a4dd223 | 2010-02-10 00:34:59 +0100 | [diff] [blame] | 383 | git config "branch.$BRANCH.remote" "$ORIGIN" |
| 384 | git config "branch.$BRANCH.merge" "refs/heads/$BRANCH" |
| 385 | git checkout "$BRANCH" |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 386 | |
| 387 | echo |
| 388 | echo "Summary of actions:" |
| 389 | echo "- A new remote branch '$BRANCH' was created" |
| 390 | echo "- The local branch '$BRANCH' was configured to track the remote branch" |
| 391 | echo "- You are now on branch '$BRANCH'" |
| 392 | echo |
| 393 | } |
| 394 | |
| 395 | cmd_track() { |
Vincent Driessen | ea60895 | 2010-01-29 16:56:29 +0100 | [diff] [blame] | 396 | parse_args "$@" |
Vincent Driessen | d099126 | 2010-02-06 21:19:07 +0100 | [diff] [blame] | 397 | require_name_arg |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 398 | |
| 399 | # sanity checks |
Vincent Driessen | 7832d6e | 2010-02-21 21:31:03 +0100 | [diff] [blame] | 400 | require_clean_working_tree |
| 401 | require_branch_absent "$BRANCH" |
Vincent Driessen | a4dd223 | 2010-02-10 00:34:59 +0100 | [diff] [blame] | 402 | git fetch -q "$ORIGIN" |
Vincent Driessen | 7832d6e | 2010-02-21 21:31:03 +0100 | [diff] [blame] | 403 | require_branch "$ORIGIN/$BRANCH" |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 404 | |
| 405 | # create tracking branch |
Vincent Driessen | a4dd223 | 2010-02-10 00:34:59 +0100 | [diff] [blame] | 406 | git checkout -b "$BRANCH" "$ORIGIN/$BRANCH" |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 407 | |
| 408 | echo |
| 409 | echo "Summary of actions:" |
| 410 | echo "- A new remote tracking branch '$BRANCH' was created" |
| 411 | echo "- You are now on branch '$BRANCH'" |
| 412 | echo |
| 413 | } |
Vincent Driessen | bd4f095 | 2010-01-27 13:57:15 +0100 | [diff] [blame] | 414 | |
Vincent Driessen | bd4f095 | 2010-01-27 13:57:15 +0100 | [diff] [blame] | 415 | cmd_diff() { |
Vincent Driessen | 1b81923 | 2010-02-01 15:51:43 +0100 | [diff] [blame] | 416 | parse_args "$@" |
Vincent Driessen | 1b81923 | 2010-02-01 15:51:43 +0100 | [diff] [blame] | 417 | |
Vincent Driessen | 5474e46 | 2010-02-04 15:50:06 +0100 | [diff] [blame] | 418 | if [ "$NAME" != "" ]; then |
Vincent Driessen | d099126 | 2010-02-06 21:19:07 +0100 | [diff] [blame] | 419 | expand_nameprefix_arg |
Vincent Driessen | a4dd223 | 2010-02-10 00:34:59 +0100 | [diff] [blame] | 420 | BASE=$(git merge-base "$DEVELOP_BRANCH" "$BRANCH") |
| 421 | git diff "$BASE..$BRANCH" |
Vincent Driessen | 5474e46 | 2010-02-04 15:50:06 +0100 | [diff] [blame] | 422 | else |
Vincent Driessen | 7832d6e | 2010-02-21 21:31:03 +0100 | [diff] [blame] | 423 | if ! git_current_branch | grep -q "^$PREFIX"; then |
Vincent Driessen | 5474e46 | 2010-02-04 15:50:06 +0100 | [diff] [blame] | 424 | die "Not on a feature branch. Name one explicitly." |
| 425 | fi |
| 426 | |
Vincent Driessen | a4dd223 | 2010-02-10 00:34:59 +0100 | [diff] [blame] | 427 | BASE=$(git merge-base "$DEVELOP_BRANCH" HEAD) |
| 428 | git diff "$BASE" |
Vincent Driessen | 5474e46 | 2010-02-04 15:50:06 +0100 | [diff] [blame] | 429 | fi |
Vincent Driessen | bd4f095 | 2010-01-27 13:57:15 +0100 | [diff] [blame] | 430 | } |
Vincent Driessen | c62633f | 2010-02-02 10:48:50 +0100 | [diff] [blame] | 431 | |
Vincent Driessen | d43ab84 | 2010-05-27 11:26:01 -0700 | [diff] [blame] | 432 | cmd_checkout() { |
| 433 | parse_args "$@" |
| 434 | |
| 435 | if [ "$NAME" != "" ]; then |
| 436 | expand_nameprefix_arg |
| 437 | git checkout "$BRANCH" |
| 438 | else |
| 439 | die "Name a feature branch explicitly." |
| 440 | fi |
| 441 | } |
| 442 | |
Vincent Driessen | a2baef9 | 2010-05-27 11:52:31 -0700 | [diff] [blame] | 443 | cmd_co() { |
| 444 | # Alias for checkout |
| 445 | cmd_checkout "$@" |
| 446 | } |
| 447 | |
Vincent Driessen | c62633f | 2010-02-02 10:48:50 +0100 | [diff] [blame] | 448 | cmd_rebase() { |
Vincent Driessen | 4417492 | 2010-02-02 23:53:21 +0100 | [diff] [blame] | 449 | DEFINE_boolean interactive false 'do an interactive rebase' i |
Vincent Driessen | c62633f | 2010-02-02 10:48:50 +0100 | [diff] [blame] | 450 | parse_args "$@" |
Vincent Driessen | d099126 | 2010-02-06 21:19:07 +0100 | [diff] [blame] | 451 | expand_nameprefix_arg_or_current |
Vincent Driessen | c62633f | 2010-02-02 10:48:50 +0100 | [diff] [blame] | 452 | warn "Will try to rebase '$NAME'..." |
Vincent Driessen | 7832d6e | 2010-02-21 21:31:03 +0100 | [diff] [blame] | 453 | require_clean_working_tree |
| 454 | require_branch "$BRANCH" |
Vincent Driessen | c62633f | 2010-02-02 10:48:50 +0100 | [diff] [blame] | 455 | |
| 456 | git checkout -q "$BRANCH" |
Vincent Driessen | f46e290 | 2010-02-15 23:01:52 +0100 | [diff] [blame] | 457 | local OPTS= |
Vincent Driessen | 4417492 | 2010-02-02 23:53:21 +0100 | [diff] [blame] | 458 | if flag interactive; then |
Vincent Driessen | c62633f | 2010-02-02 10:48:50 +0100 | [diff] [blame] | 459 | OPTS="$OPTS -i" |
| 460 | fi |
Vincent Driessen | 010252a | 2010-02-04 10:31:29 +0100 | [diff] [blame] | 461 | git rebase $OPTS "$DEVELOP_BRANCH" |
Vincent Driessen | c62633f | 2010-02-02 10:48:50 +0100 | [diff] [blame] | 462 | } |
Vincent Driessen | f68d405 | 2010-07-09 12:34:18 +0200 | [diff] [blame] | 463 | |
| 464 | avoid_accidental_cross_branch_action() { |
| 465 | local current_branch=$(git_current_branch) |
| 466 | if [ "$BRANCH" != "$current_branch" ]; then |
| 467 | warn "Trying to pull from '$BRANCH' while currently on branch '$current_branch'." |
| 468 | warn "To avoid unintended merges, git-flow aborted." |
| 469 | return 1 |
| 470 | fi |
| 471 | return 0 |
| 472 | } |
| 473 | |
| 474 | cmd_pull() { |
| 475 | #DEFINE_string prefix false 'alternative remote feature branch name prefix' p |
| 476 | parse_remote_name "$@" |
| 477 | |
| 478 | if [ -z "$REMOTE" ]; then |
| 479 | die "Name a remote explicitly." |
| 480 | fi |
| 481 | name_or_current |
| 482 | |
| 483 | # To avoid accidentally merging different feature branches into each other, |
| 484 | # die if the current feature branch differs from the requested $NAME |
| 485 | # argument. |
| 486 | local current_branch=$(git_current_branch) |
| 487 | if startswith "$current_branch" "$PREFIX"; then |
| 488 | # we are on a local feature branch already, so $BRANCH must be equal to |
| 489 | # the current branch |
| 490 | avoid_accidental_cross_branch_action || die |
| 491 | fi |
| 492 | |
| 493 | require_clean_working_tree |
| 494 | |
| 495 | if git_branch_exists "$BRANCH"; then |
| 496 | # Again, avoid accidental merges |
| 497 | avoid_accidental_cross_branch_action || die |
| 498 | |
| 499 | # we already have a local branch called like this, so simply pull the |
| 500 | # remote changes in |
| 501 | git pull -q "$REMOTE" "$BRANCH" || die "Failed to pull from remote '$REMOTE'." |
| 502 | echo "Pulled $REMOTE's changes into $BRANCH." |
| 503 | else |
| 504 | # setup the local branch clone for the first time |
| 505 | git fetch -q "$REMOTE" "$BRANCH" || die "Fetch failed." # stores in FETCH_HEAD |
| 506 | git branch --no-track "$BRANCH" FETCH_HEAD || die "Branch failed." |
| 507 | git checkout -q "$BRANCH" || die "Checking out new local branch failed." |
| 508 | echo "Created local branch $BRANCH based on $REMOTE's $BRANCH." |
| 509 | fi |
| 510 | } |