Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 1 | # |
Vincent Driessen | 6c2d30b | 2010-01-26 22:18:36 +0100 | [diff] [blame] | 2 | # git-flow -- A collection of Git extensions to provide high-level |
| 3 | # repository operations for Vincent Driessen's branching model. |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 4 | # |
| 5 | # Original blog post presenting this model is found at: |
| 6 | # http://nvie.com/archives/323 |
| 7 | # |
| 8 | # Feel free to contribute to this project at: |
| 9 | # http://github.com/nvie/gitflow |
| 10 | # |
Vincent Driessen | d72acba | 2010-04-04 16:10:17 +0200 | [diff] [blame] | 11 | # Copyright 2010 Vincent Driessen. All rights reserved. |
| 12 | # |
| 13 | # Redistribution and use in source and binary forms, with or without |
| 14 | # modification, are permitted provided that the following conditions are met: |
| 15 | # |
| 16 | # 1. Redistributions of source code must retain the above copyright notice, |
| 17 | # this list of conditions and the following disclaimer. |
| 18 | # |
| 19 | # 2. Redistributions in binary form must reproduce the above copyright |
| 20 | # notice, this list of conditions and the following disclaimer in the |
| 21 | # documentation and/or other materials provided with the distribution. |
| 22 | # |
| 23 | # THIS SOFTWARE IS PROVIDED BY VINCENT DRIESSEN ``AS IS'' AND ANY EXPRESS OR |
| 24 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 25 | # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
| 26 | # EVENT SHALL VINCENT DRIESSEN OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, |
| 27 | # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
| 28 | # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 29 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 30 | # OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 31 | # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, |
| 32 | # EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 33 | # |
| 34 | # The views and conclusions contained in the software and documentation are |
| 35 | # those of the authors and should not be interpreted as representing official |
| 36 | # policies, either expressed or implied, of Vincent Driessen. |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 37 | # |
| 38 | |
Vincent Driessen | 7832d6e | 2010-02-21 21:31:03 +0100 | [diff] [blame] | 39 | require_git_repo |
| 40 | require_gitflow_initialized |
Vincent Driessen | d72e4ac | 2010-02-16 21:33:51 +0100 | [diff] [blame] | 41 | gitflow_load_settings |
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 | a2e4116 | 2010-02-24 01:37:07 +0100 | [diff] [blame] | 46 | echo " git flow feature start [-Ff] <name> [<base>]" |
| 47 | echo " git flow feature finish [-rF] <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>]" |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 52 | } |
| 53 | |
Vincent Driessen | 186d2b5 | 2010-01-27 23:48:39 +0100 | [diff] [blame] | 54 | cmd_default() { |
Vincent Driessen | b866b01 | 2010-01-28 01:01:53 +0100 | [diff] [blame] | 55 | cmd_list "$@" |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 56 | } |
| 57 | |
Vincent Driessen | b866b01 | 2010-01-28 01:01:53 +0100 | [diff] [blame] | 58 | cmd_list() { |
Vincent Driessen | 4417492 | 2010-02-02 23:53:21 +0100 | [diff] [blame] | 59 | DEFINE_boolean verbose false 'verbose (more) output' v |
Vincent Driessen | 1b81923 | 2010-02-01 15:51:43 +0100 | [diff] [blame] | 60 | parse_args "$@" |
| 61 | |
Vincent Driessen | f46e290 | 2010-02-15 23:01:52 +0100 | [diff] [blame] | 62 | local feature_branches |
| 63 | local current_branch |
| 64 | local short_names |
Vincent Driessen | 7832d6e | 2010-02-21 21:31:03 +0100 | [diff] [blame] | 65 | feature_branches=$(echo "$(git_local_branches)" | grep "^$PREFIX") |
Vincent Driessen | 27592dd | 2010-02-06 14:45:39 +0100 | [diff] [blame] | 66 | if [ -z "$feature_branches" ]; then |
Vincent Driessen | 186d2b5 | 2010-01-27 23:48:39 +0100 | [diff] [blame] | 67 | warn "No feature branches exist." |
| 68 | exit 0 |
| 69 | fi |
Vincent Driessen | 27592dd | 2010-02-06 14:45:39 +0100 | [diff] [blame] | 70 | current_branch=$(git branch | grep '^\* ' | grep -v 'no branch' | sed 's/^* //g') |
| 71 | short_names=$(echo "$feature_branches" | sed "s ^$PREFIX g") |
Vincent Driessen | f2536f4 | 2010-02-01 15:57:48 +0100 | [diff] [blame] | 72 | |
Vincent Driessen | aa6d016 | 2010-02-01 19:43:46 +0100 | [diff] [blame] | 73 | # determine column width first |
Vincent Driessen | f46e290 | 2010-02-15 23:01:52 +0100 | [diff] [blame] | 74 | local width=0 |
| 75 | local branch |
Vincent Driessen | 27592dd | 2010-02-06 14:45:39 +0100 | [diff] [blame] | 76 | for branch in $short_names; do |
Vincent Driessen | f46e290 | 2010-02-15 23:01:52 +0100 | [diff] [blame] | 77 | local len=${#branch} |
Vincent Driessen | aa6d016 | 2010-02-01 19:43:46 +0100 | [diff] [blame] | 78 | width=$(max $width $len) |
| 79 | done |
Vincent Driessen | f46e290 | 2010-02-15 23:01:52 +0100 | [diff] [blame] | 80 | width=$(($width+3)) |
Vincent Driessen | 1adbc3e | 2010-01-30 16:28:20 +0100 | [diff] [blame] | 81 | |
Vincent Driessen | f46e290 | 2010-02-15 23:01:52 +0100 | [diff] [blame] | 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 fullname=$PREFIX$branch |
| 85 | local base=$(git merge-base "$fullname" "$DEVELOP_BRANCH") |
| 86 | local develop_sha=$(git rev-parse "$DEVELOP_BRANCH") |
| 87 | local branch_sha=$(git rev-parse "$fullname") |
Vincent Driessen | 27592dd | 2010-02-06 14:45:39 +0100 | [diff] [blame] | 88 | if [ "$fullname" = "$current_branch" ]; then |
Vincent Driessen | aa6d016 | 2010-02-01 19:43:46 +0100 | [diff] [blame] | 89 | printf "* " |
| 90 | else |
| 91 | printf " " |
| 92 | fi |
Vincent Driessen | 4417492 | 2010-02-02 23:53:21 +0100 | [diff] [blame] | 93 | if flag verbose; then |
Vincent Driessen | 1adbc3e | 2010-01-30 16:28:20 +0100 | [diff] [blame] | 94 | printf "%-${width}s" "$branch" |
Vincent Driessen | f2536f4 | 2010-02-01 15:57:48 +0100 | [diff] [blame] | 95 | if [ "$branch_sha" = "$develop_sha" ]; then |
| 96 | printf "(no commits yet)" |
| 97 | elif [ "$base" = "$branch_sha" ]; then |
| 98 | printf "(is behind develop, may ff)" |
| 99 | elif [ "$base" = "$develop_sha" ]; then |
| 100 | printf "(based on latest develop)" |
| 101 | else |
| 102 | printf "(may be rebased)" |
| 103 | fi |
Vincent Driessen | aa6d016 | 2010-02-01 19:43:46 +0100 | [diff] [blame] | 104 | else |
| 105 | printf "%s" "$branch" |
| 106 | fi |
| 107 | echo |
| 108 | done |
Vincent Driessen | 186d2b5 | 2010-01-27 23:48:39 +0100 | [diff] [blame] | 109 | } |
| 110 | |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 111 | cmd_help() { |
| 112 | usage |
| 113 | exit 0 |
| 114 | } |
| 115 | |
Vincent Driessen | d099126 | 2010-02-06 21:19:07 +0100 | [diff] [blame] | 116 | require_name_arg() { |
Vincent Driessen | 1b81923 | 2010-02-01 15:51:43 +0100 | [diff] [blame] | 117 | if [ "$NAME" = "" ]; then |
Vincent Driessen | 3c337fb | 2010-02-04 11:30:18 +0100 | [diff] [blame] | 118 | warn "Missing argument <name>" |
Vincent Driessen | 1b81923 | 2010-02-01 15:51:43 +0100 | [diff] [blame] | 119 | usage |
Vincent Driessen | 2e1856b | 2010-01-29 15:18:13 +0100 | [diff] [blame] | 120 | exit 1 |
| 121 | fi |
| 122 | } |
| 123 | |
Vincent Driessen | d099126 | 2010-02-06 21:19:07 +0100 | [diff] [blame] | 124 | expand_nameprefix_arg() { |
| 125 | require_name_arg |
| 126 | |
Vincent Driessen | f46e290 | 2010-02-15 23:01:52 +0100 | [diff] [blame] | 127 | local expanded_name |
| 128 | local exitcode |
Vincent Driessen | 7832d6e | 2010-02-21 21:31:03 +0100 | [diff] [blame] | 129 | expanded_name=$(gitflow_resolve_nameprefix "$NAME" "$PREFIX") |
Vincent Driessen | d099126 | 2010-02-06 21:19:07 +0100 | [diff] [blame] | 130 | exitcode=$? |
| 131 | case $exitcode in |
| 132 | 0) NAME=$expanded_name |
| 133 | BRANCH=$PREFIX$NAME |
| 134 | ;; |
| 135 | *) exit 1 ;; |
| 136 | esac |
Vincent Driessen | 2e1856b | 2010-01-29 15:18:13 +0100 | [diff] [blame] | 137 | } |
| 138 | |
Vincent Driessen | d099126 | 2010-02-06 21:19:07 +0100 | [diff] [blame] | 139 | expand_nameprefix_arg_or_current() { |
Vincent Driessen | c62633f | 2010-02-02 10:48:50 +0100 | [diff] [blame] | 140 | if [ "$NAME" != "" ]; then |
Vincent Driessen | d099126 | 2010-02-06 21:19:07 +0100 | [diff] [blame] | 141 | expand_nameprefix_arg |
Vincent Driessen | 7832d6e | 2010-02-21 21:31:03 +0100 | [diff] [blame] | 142 | require_branch "$PREFIX$NAME" |
Vincent Driessen | c62633f | 2010-02-02 10:48:50 +0100 | [diff] [blame] | 143 | else |
Vincent Driessen | 7832d6e | 2010-02-21 21:31:03 +0100 | [diff] [blame] | 144 | local current_branch=$(git_current_branch) |
Vincent Driessen | d099126 | 2010-02-06 21:19:07 +0100 | [diff] [blame] | 145 | if startswith "$current_branch" "$PREFIX"; then |
| 146 | BRANCH=$current_branch |
| 147 | NAME=${BRANCH#$PREFIX} |
| 148 | else |
| 149 | warn "The current HEAD is no feature branch." |
| 150 | warn "To diff a feature, specify a <name> argument." |
| 151 | usage |
| 152 | exit 1 |
| 153 | fi |
Vincent Driessen | c62633f | 2010-02-02 10:48:50 +0100 | [diff] [blame] | 154 | fi |
| 155 | } |
| 156 | |
Vincent Driessen | ea60895 | 2010-01-29 16:56:29 +0100 | [diff] [blame] | 157 | parse_args() { |
Vincent Driessen | 1b81923 | 2010-02-01 15:51:43 +0100 | [diff] [blame] | 158 | # parse options |
| 159 | FLAGS "$@" || exit $? |
| 160 | eval set -- "${FLAGS_ARGV}" |
| 161 | |
| 162 | # read arguments into global variables |
Vincent Driessen | c5fcc01 | 2010-02-10 00:18:08 +0100 | [diff] [blame] | 163 | NAME=$1 |
Vincent Driessen | 1156092 | 2010-02-01 21:58:37 +0100 | [diff] [blame] | 164 | BRANCH=$PREFIX$NAME |
Vincent Driessen | b866b01 | 2010-01-28 01:01:53 +0100 | [diff] [blame] | 165 | } |
| 166 | |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 167 | cmd_start() { |
Vincent Driessen | 4417492 | 2010-02-02 23:53:21 +0100 | [diff] [blame] | 168 | DEFINE_boolean fetch false 'fetch from origin before performing local operation' F |
Vincent Driessen | 5455a6f | 2010-02-03 00:14:05 +0100 | [diff] [blame] | 169 | DEFINE_boolean force false 'force creation of feature branch (ignores dirty working tree)' f |
Vincent Driessen | ea60895 | 2010-01-29 16:56:29 +0100 | [diff] [blame] | 170 | parse_args "$@" |
Vincent Driessen | c5fcc01 | 2010-02-10 00:18:08 +0100 | [diff] [blame] | 171 | BASE=${2:-$DEVELOP_BRANCH} |
Vincent Driessen | d099126 | 2010-02-06 21:19:07 +0100 | [diff] [blame] | 172 | require_name_arg |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 173 | |
| 174 | # sanity checks |
Vincent Driessen | 5455a6f | 2010-02-03 00:14:05 +0100 | [diff] [blame] | 175 | if noflag force; then |
Vincent Driessen | 7832d6e | 2010-02-21 21:31:03 +0100 | [diff] [blame] | 176 | require_clean_working_tree |
Vincent Driessen | 5455a6f | 2010-02-03 00:14:05 +0100 | [diff] [blame] | 177 | fi |
Vincent Driessen | 7832d6e | 2010-02-21 21:31:03 +0100 | [diff] [blame] | 178 | require_branch_absent "$BRANCH" |
Vincent Driessen | e034e4a | 2010-01-29 12:10:44 +0100 | [diff] [blame] | 179 | |
| 180 | # update the local repo with remote changes, if asked |
Vincent Driessen | 4417492 | 2010-02-02 23:53:21 +0100 | [diff] [blame] | 181 | if flag fetch; then |
Vincent Driessen | a4dd223 | 2010-02-10 00:34:59 +0100 | [diff] [blame] | 182 | git fetch -q "$ORIGIN" "$DEVELOP_BRANCH" |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 183 | fi |
| 184 | |
Vincent Driessen | c118a85 | 2010-04-04 16:32:04 +0200 | [diff] [blame^] | 185 | # if the origin branch counterpart exists, assert that the local branch |
| 186 | # isn't behind it (to avoid unnecessary rebasing) |
| 187 | if git_branch_exists "$ORIGIN/$DEVELOP_BRANCH"; then |
| 188 | require_branches_equal "$DEVELOP_BRANCH" "$ORIGIN/$DEVELOP_BRANCH" |
| 189 | fi |
Vincent Driessen | e034e4a | 2010-01-29 12:10:44 +0100 | [diff] [blame] | 190 | |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 191 | # create branch |
Vincent Driessen | a4dd223 | 2010-02-10 00:34:59 +0100 | [diff] [blame] | 192 | if ! git checkout -b "$BRANCH" "$BASE"; then |
Vincent Driessen | 5455a6f | 2010-02-03 00:14:05 +0100 | [diff] [blame] | 193 | die "Could not create feature branch '$BRANCH'" |
| 194 | fi |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 195 | |
| 196 | echo |
| 197 | echo "Summary of actions:" |
| 198 | echo "- A new branch '$BRANCH' was created, based on '$BASE'" |
| 199 | echo "- You are now on branch '$BRANCH'" |
| 200 | echo "" |
| 201 | echo "Now, start committing on your feature. When done, use:" |
| 202 | echo "" |
gmallard | 192ff52 | 2010-04-01 19:31:09 -0400 | [diff] [blame] | 203 | echo " git flow feature finish $NAME" |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 204 | echo |
| 205 | } |
| 206 | |
| 207 | cmd_finish() { |
Vincent Driessen | ca73caf | 2010-02-07 19:46:38 +0100 | [diff] [blame] | 208 | DEFINE_boolean fetch false "fetch from $ORIGIN before performing finish" F |
Vincent Driessen | 4417492 | 2010-02-02 23:53:21 +0100 | [diff] [blame] | 209 | DEFINE_boolean rebase false 'rebase instead of merge' r |
Vincent Driessen | 1b81923 | 2010-02-01 15:51:43 +0100 | [diff] [blame] | 210 | parse_args "$@" |
Vincent Driessen | d099126 | 2010-02-06 21:19:07 +0100 | [diff] [blame] | 211 | expand_nameprefix_arg |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 212 | |
| 213 | # sanity checks |
Vincent Driessen | 7832d6e | 2010-02-21 21:31:03 +0100 | [diff] [blame] | 214 | require_branch "$BRANCH" |
Vincent Driessen | e034e4a | 2010-01-29 12:10:44 +0100 | [diff] [blame] | 215 | |
Vincent Driessen | 49c7d02 | 2010-01-28 12:40:33 +0100 | [diff] [blame] | 216 | # detect if we're restoring from a merge conflict |
Vincent Driessen | cf6e92a | 2010-02-19 19:44:48 +0100 | [diff] [blame] | 217 | if [ -f "$DOT_GIT_DIR/.gitflow/MERGE_BASE" ]; then |
Vincent Driessen | 49c7d02 | 2010-01-28 12:40:33 +0100 | [diff] [blame] | 218 | # |
| 219 | # TODO: detect that we're working on the correct branch here! |
| 220 | # The user need not necessarily have given the same $NAME twice here |
| 221 | # (although he/she should). |
| 222 | # |
Vincent Driessen | f6f152f | 2010-01-29 10:28:08 +0100 | [diff] [blame] | 223 | |
Vincent Driessen | 7832d6e | 2010-02-21 21:31:03 +0100 | [diff] [blame] | 224 | # TODO: git_is_clean_working_tree() should provide an alternative |
Vincent Driessen | f6f152f | 2010-01-29 10:28:08 +0100 | [diff] [blame] | 225 | # exit code for "unmerged changes in working tree", which we should |
| 226 | # actually be testing for here |
Vincent Driessen | 7832d6e | 2010-02-21 21:31:03 +0100 | [diff] [blame] | 227 | if git_is_clean_working_tree; then |
Vincent Driessen | cf6e92a | 2010-02-19 19:44:48 +0100 | [diff] [blame] | 228 | FINISH_BASE=$(cat "$DOT_GIT_DIR/.gitflow/MERGE_BASE") |
Vincent Driessen | f6f152f | 2010-01-29 10:28:08 +0100 | [diff] [blame] | 229 | |
| 230 | # Since the working tree is now clean, either the user did a |
| 231 | # succesfull merge manually, or the merge was cancelled. |
Vincent Driessen | 7832d6e | 2010-02-21 21:31:03 +0100 | [diff] [blame] | 232 | # We detect this using git_is_branch_merged_into() |
| 233 | if git_is_branch_merged_into "$BRANCH" "$FINISH_BASE"; then |
Vincent Driessen | cf6e92a | 2010-02-19 19:44:48 +0100 | [diff] [blame] | 234 | rm -f "$DOT_GIT_DIR/.gitflow/MERGE_BASE" |
Vincent Driessen | f6f152f | 2010-01-29 10:28:08 +0100 | [diff] [blame] | 235 | helper_finish_cleanup |
| 236 | exit 0 |
| 237 | else |
| 238 | # If the user cancelled the merge and decided to wait until later, |
| 239 | # that's fine. But we have to acknowledge this by removing the |
| 240 | # MERGE_BASE file and continuing normal execution of the finish |
Vincent Driessen | cf6e92a | 2010-02-19 19:44:48 +0100 | [diff] [blame] | 241 | rm -f "$DOT_GIT_DIR/.gitflow/MERGE_BASE" |
Vincent Driessen | f6f152f | 2010-01-29 10:28:08 +0100 | [diff] [blame] | 242 | fi |
Vincent Driessen | 49c7d02 | 2010-01-28 12:40:33 +0100 | [diff] [blame] | 243 | else |
| 244 | echo |
| 245 | echo "Merge conflicts not resolved yet, use:" |
| 246 | echo " git mergetool" |
| 247 | echo " git commit" |
| 248 | echo |
| 249 | echo "You can then complete the finish by running it again:" |
| 250 | echo " git flow feature finish $NAME" |
| 251 | echo |
| 252 | exit 1 |
| 253 | fi |
| 254 | fi |
| 255 | |
Vincent Driessen | f6f152f | 2010-01-29 10:28:08 +0100 | [diff] [blame] | 256 | # sanity checks |
Vincent Driessen | 7832d6e | 2010-02-21 21:31:03 +0100 | [diff] [blame] | 257 | require_clean_working_tree |
Vincent Driessen | f6f152f | 2010-01-29 10:28:08 +0100 | [diff] [blame] | 258 | |
Vincent Driessen | e034e4a | 2010-01-29 12:10:44 +0100 | [diff] [blame] | 259 | # update local repo with remote changes first, if asked |
Vincent Driessen | 4417492 | 2010-02-02 23:53:21 +0100 | [diff] [blame] | 260 | if flag fetch; then |
Vincent Driessen | a4dd223 | 2010-02-10 00:34:59 +0100 | [diff] [blame] | 261 | git fetch -q "$ORIGIN" "$BRANCH" |
Vincent Driessen | e034e4a | 2010-01-29 12:10:44 +0100 | [diff] [blame] | 262 | fi |
| 263 | |
Vincent Driessen | 7832d6e | 2010-02-21 21:31:03 +0100 | [diff] [blame] | 264 | if has "$ORIGIN/$BRANCH" "$(git_remote_branches)"; then |
| 265 | require_branches_equal "$BRANCH" "$ORIGIN/$BRANCH" |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 266 | fi |
Vincent Driessen | 7832d6e | 2010-02-21 21:31:03 +0100 | [diff] [blame] | 267 | require_branches_equal "$DEVELOP_BRANCH" "$ORIGIN/$DEVELOP_BRANCH" |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 268 | |
Vincent Driessen | 95bf82c | 2010-02-02 11:58:37 +0100 | [diff] [blame] | 269 | # if the user wants to rebase, do that first |
Vincent Driessen | 4417492 | 2010-02-02 23:53:21 +0100 | [diff] [blame] | 270 | if flag rebase; then |
Vincent Driessen | 010252a | 2010-02-04 10:31:29 +0100 | [diff] [blame] | 271 | if ! git flow feature rebase "$NAME" "$DEVELOP_BRANCH"; then |
Vincent Driessen | 95bf82c | 2010-02-02 11:58:37 +0100 | [diff] [blame] | 272 | warn "Finish was aborted due to conflicts during rebase." |
| 273 | warn "Please finish the rebase manually now." |
| 274 | warn "When finished, re-run:" |
Vincent Driessen | 010252a | 2010-02-04 10:31:29 +0100 | [diff] [blame] | 275 | warn " git flow feature finish '$NAME' '$DEVELOP_BRANCH'" |
Vincent Driessen | 95bf82c | 2010-02-02 11:58:37 +0100 | [diff] [blame] | 276 | exit 1 |
| 277 | fi |
| 278 | fi |
| 279 | |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 280 | # merge into BASE |
Vincent Driessen | a4dd223 | 2010-02-10 00:34:59 +0100 | [diff] [blame] | 281 | git checkout "$DEVELOP_BRANCH" |
| 282 | if [ "$(git rev-list -n2 "$DEVELOP_BRANCH..$BRANCH" | wc -l)" -eq 1 ]; then |
| 283 | git merge --ff "$BRANCH" |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 284 | else |
Vincent Driessen | a4dd223 | 2010-02-10 00:34:59 +0100 | [diff] [blame] | 285 | git merge --no-ff "$BRANCH" |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 286 | fi |
| 287 | |
Vincent Driessen | 49c7d02 | 2010-01-28 12:40:33 +0100 | [diff] [blame] | 288 | if [ $? -ne 0 ]; then |
| 289 | # oops.. we have a merge conflict! |
Vincent Driessen | 010252a | 2010-02-04 10:31:29 +0100 | [diff] [blame] | 290 | # 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] | 291 | mkdir -p "$DOT_GIT_DIR/.gitflow" |
| 292 | echo "$DEVELOP_BRANCH" > "$DOT_GIT_DIR/.gitflow/MERGE_BASE" |
Vincent Driessen | 49c7d02 | 2010-01-28 12:40:33 +0100 | [diff] [blame] | 293 | echo |
| 294 | echo "There were merge conflicts. To resolve the merge conflict manually, use:" |
| 295 | echo " git mergetool" |
| 296 | echo " git commit" |
| 297 | echo |
| 298 | echo "You can then complete the finish by running it again:" |
| 299 | echo " git flow feature finish $NAME" |
| 300 | echo |
| 301 | exit 1 |
| 302 | fi |
| 303 | |
| 304 | # when no merge conflict is detected, just clean up the feature branch |
| 305 | helper_finish_cleanup |
| 306 | } |
| 307 | |
| 308 | helper_finish_cleanup() { |
Vincent Driessen | f6f152f | 2010-01-29 10:28:08 +0100 | [diff] [blame] | 309 | # sanity checks |
Vincent Driessen | 7832d6e | 2010-02-21 21:31:03 +0100 | [diff] [blame] | 310 | require_branch "$BRANCH" |
| 311 | require_clean_working_tree |
Vincent Driessen | f6f152f | 2010-01-29 10:28:08 +0100 | [diff] [blame] | 312 | |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 313 | # delete branch |
Vincent Driessen | 4417492 | 2010-02-02 23:53:21 +0100 | [diff] [blame] | 314 | if flag fetch; then |
Vincent Driessen | a4dd223 | 2010-02-10 00:34:59 +0100 | [diff] [blame] | 315 | git push "$ORIGIN" ":refs/heads/$BRANCH" |
Vincent Driessen | eec73c6 | 2010-02-02 16:14:16 +0100 | [diff] [blame] | 316 | fi |
Vincent Driessen | a4dd223 | 2010-02-10 00:34:59 +0100 | [diff] [blame] | 317 | git branch -d "$BRANCH" |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 318 | |
| 319 | echo |
| 320 | echo "Summary of actions:" |
Vincent Driessen | 010252a | 2010-02-04 10:31:29 +0100 | [diff] [blame] | 321 | echo "- The feature branch '$BRANCH' was merged into '$DEVELOP_BRANCH'" |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 322 | #echo "- Merge conflicts were resolved" # TODO: Add this line when it's supported |
| 323 | echo "- Feature branch '$BRANCH' has been removed" |
Vincent Driessen | 010252a | 2010-02-04 10:31:29 +0100 | [diff] [blame] | 324 | echo "- You are now on branch '$DEVELOP_BRANCH'" |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 325 | echo |
| 326 | } |
| 327 | |
| 328 | cmd_publish() { |
Vincent Driessen | ea60895 | 2010-01-29 16:56:29 +0100 | [diff] [blame] | 329 | parse_args "$@" |
Vincent Driessen | d099126 | 2010-02-06 21:19:07 +0100 | [diff] [blame] | 330 | expand_nameprefix_arg |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 331 | |
| 332 | # sanity checks |
Vincent Driessen | 7832d6e | 2010-02-21 21:31:03 +0100 | [diff] [blame] | 333 | require_clean_working_tree |
| 334 | require_branch "$BRANCH" |
Vincent Driessen | a4dd223 | 2010-02-10 00:34:59 +0100 | [diff] [blame] | 335 | git fetch -q "$ORIGIN" |
Vincent Driessen | 7832d6e | 2010-02-21 21:31:03 +0100 | [diff] [blame] | 336 | require_branch_absent "$ORIGIN/$BRANCH" |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 337 | |
| 338 | # create remote branch |
Vincent Driessen | a4dd223 | 2010-02-10 00:34:59 +0100 | [diff] [blame] | 339 | git push "$ORIGIN" "$BRANCH:refs/heads/$BRANCH" |
| 340 | git fetch -q "$ORIGIN" |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 341 | |
| 342 | # configure remote tracking |
Vincent Driessen | a4dd223 | 2010-02-10 00:34:59 +0100 | [diff] [blame] | 343 | git config "branch.$BRANCH.remote" "$ORIGIN" |
| 344 | git config "branch.$BRANCH.merge" "refs/heads/$BRANCH" |
| 345 | git checkout "$BRANCH" |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 346 | |
| 347 | echo |
| 348 | echo "Summary of actions:" |
| 349 | echo "- A new remote branch '$BRANCH' was created" |
| 350 | echo "- The local branch '$BRANCH' was configured to track the remote branch" |
| 351 | echo "- You are now on branch '$BRANCH'" |
| 352 | echo |
| 353 | } |
| 354 | |
| 355 | cmd_track() { |
Vincent Driessen | ea60895 | 2010-01-29 16:56:29 +0100 | [diff] [blame] | 356 | parse_args "$@" |
Vincent Driessen | d099126 | 2010-02-06 21:19:07 +0100 | [diff] [blame] | 357 | require_name_arg |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 358 | |
| 359 | # sanity checks |
Vincent Driessen | 7832d6e | 2010-02-21 21:31:03 +0100 | [diff] [blame] | 360 | require_clean_working_tree |
| 361 | require_branch_absent "$BRANCH" |
Vincent Driessen | a4dd223 | 2010-02-10 00:34:59 +0100 | [diff] [blame] | 362 | git fetch -q "$ORIGIN" |
Vincent Driessen | 7832d6e | 2010-02-21 21:31:03 +0100 | [diff] [blame] | 363 | require_branch "$ORIGIN/$BRANCH" |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 364 | |
| 365 | # create tracking branch |
Vincent Driessen | a4dd223 | 2010-02-10 00:34:59 +0100 | [diff] [blame] | 366 | git checkout -b "$BRANCH" "$ORIGIN/$BRANCH" |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 367 | |
| 368 | echo |
| 369 | echo "Summary of actions:" |
| 370 | echo "- A new remote tracking branch '$BRANCH' was created" |
| 371 | echo "- You are now on branch '$BRANCH'" |
| 372 | echo |
| 373 | } |
Vincent Driessen | bd4f095 | 2010-01-27 13:57:15 +0100 | [diff] [blame] | 374 | |
Vincent Driessen | bd4f095 | 2010-01-27 13:57:15 +0100 | [diff] [blame] | 375 | cmd_diff() { |
Vincent Driessen | 1b81923 | 2010-02-01 15:51:43 +0100 | [diff] [blame] | 376 | parse_args "$@" |
Vincent Driessen | 1b81923 | 2010-02-01 15:51:43 +0100 | [diff] [blame] | 377 | |
Vincent Driessen | 5474e46 | 2010-02-04 15:50:06 +0100 | [diff] [blame] | 378 | if [ "$NAME" != "" ]; then |
Vincent Driessen | d099126 | 2010-02-06 21:19:07 +0100 | [diff] [blame] | 379 | expand_nameprefix_arg |
Vincent Driessen | a4dd223 | 2010-02-10 00:34:59 +0100 | [diff] [blame] | 380 | BASE=$(git merge-base "$DEVELOP_BRANCH" "$BRANCH") |
| 381 | git diff "$BASE..$BRANCH" |
Vincent Driessen | 5474e46 | 2010-02-04 15:50:06 +0100 | [diff] [blame] | 382 | else |
Vincent Driessen | 7832d6e | 2010-02-21 21:31:03 +0100 | [diff] [blame] | 383 | if ! git_current_branch | grep -q "^$PREFIX"; then |
Vincent Driessen | 5474e46 | 2010-02-04 15:50:06 +0100 | [diff] [blame] | 384 | die "Not on a feature branch. Name one explicitly." |
| 385 | fi |
| 386 | |
Vincent Driessen | a4dd223 | 2010-02-10 00:34:59 +0100 | [diff] [blame] | 387 | BASE=$(git merge-base "$DEVELOP_BRANCH" HEAD) |
| 388 | git diff "$BASE" |
Vincent Driessen | 5474e46 | 2010-02-04 15:50:06 +0100 | [diff] [blame] | 389 | fi |
Vincent Driessen | bd4f095 | 2010-01-27 13:57:15 +0100 | [diff] [blame] | 390 | } |
Vincent Driessen | c62633f | 2010-02-02 10:48:50 +0100 | [diff] [blame] | 391 | |
| 392 | cmd_rebase() { |
Vincent Driessen | 4417492 | 2010-02-02 23:53:21 +0100 | [diff] [blame] | 393 | DEFINE_boolean interactive false 'do an interactive rebase' i |
Vincent Driessen | c62633f | 2010-02-02 10:48:50 +0100 | [diff] [blame] | 394 | parse_args "$@" |
Vincent Driessen | d099126 | 2010-02-06 21:19:07 +0100 | [diff] [blame] | 395 | expand_nameprefix_arg_or_current |
Vincent Driessen | c62633f | 2010-02-02 10:48:50 +0100 | [diff] [blame] | 396 | warn "Will try to rebase '$NAME'..." |
Vincent Driessen | 7832d6e | 2010-02-21 21:31:03 +0100 | [diff] [blame] | 397 | require_clean_working_tree |
| 398 | require_branch "$BRANCH" |
Vincent Driessen | c62633f | 2010-02-02 10:48:50 +0100 | [diff] [blame] | 399 | |
| 400 | git checkout -q "$BRANCH" |
Vincent Driessen | f46e290 | 2010-02-15 23:01:52 +0100 | [diff] [blame] | 401 | local OPTS= |
Vincent Driessen | 4417492 | 2010-02-02 23:53:21 +0100 | [diff] [blame] | 402 | if flag interactive; then |
Vincent Driessen | c62633f | 2010-02-02 10:48:50 +0100 | [diff] [blame] | 403 | OPTS="$OPTS -i" |
| 404 | fi |
Vincent Driessen | 010252a | 2010-02-04 10:31:29 +0100 | [diff] [blame] | 405 | git rebase $OPTS "$DEVELOP_BRANCH" |
Vincent Driessen | c62633f | 2010-02-02 10:48:50 +0100 | [diff] [blame] | 406 | } |