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