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