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 | d72e4ac | 2010-02-16 21:33:51 +0100 | [diff] [blame] | 15 | gitflow_require_git_repo |
Vincent Driessen | c1598bf | 2010-02-20 16:52:48 +0100 | [diff] [blame] | 16 | gitflow_require_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]" |
| 22 | echo " git flow feature start [-Fv] <name> [<base>]" |
Vincent Driessen | 010252a | 2010-02-04 10:31:29 +0100 | [diff] [blame] | 23 | echo " git flow feature finish [-rsFv] <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 | ea60895 | 2010-01-29 16:56:29 +0100 | [diff] [blame] | 26 | echo " git flow feature diff <name|nameprefix>" |
Vincent Driessen | c62633f | 2010-02-02 10:48:50 +0100 | [diff] [blame] | 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 | 21c7aa9 | 2010-02-16 20:57:35 +0100 | [diff] [blame] | 41 | feature_branches=$(echo "$(gitflow_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 | d099126 | 2010-02-06 21:19:07 +0100 | [diff] [blame] | 105 | expanded_name=$(resolve_nameprefix "$NAME" "$PREFIX") |
| 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 |
| 118 | gitflow_require_branch "$PREFIX$NAME" |
Vincent Driessen | c62633f | 2010-02-02 10:48:50 +0100 | [diff] [blame] | 119 | else |
Vincent Driessen | f46e290 | 2010-02-15 23:01:52 +0100 | [diff] [blame] | 120 | local current_branch=$(gitflow_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 |
| 152 | gitflow_require_clean_working_tree |
| 153 | fi |
Vincent Driessen | a4dd223 | 2010-02-10 00:34:59 +0100 | [diff] [blame] | 154 | gitflow_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 | a4dd223 | 2010-02-10 00:34:59 +0100 | [diff] [blame] | 161 | gitflow_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 |
| 182 | DEFINE_boolean squash false 'squash all commits when rebasing (implies --rebase)' s |
Vincent Driessen | 1b81923 | 2010-02-01 15:51:43 +0100 | [diff] [blame] | 183 | parse_args "$@" |
Vincent Driessen | d099126 | 2010-02-06 21:19:07 +0100 | [diff] [blame] | 184 | expand_nameprefix_arg |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 185 | |
| 186 | # sanity checks |
Vincent Driessen | a4dd223 | 2010-02-10 00:34:59 +0100 | [diff] [blame] | 187 | gitflow_require_branch "$BRANCH" |
Vincent Driessen | e034e4a | 2010-01-29 12:10:44 +0100 | [diff] [blame] | 188 | |
Vincent Driessen | 49c7d02 | 2010-01-28 12:40:33 +0100 | [diff] [blame] | 189 | # detect if we're restoring from a merge conflict |
Vincent Driessen | cf6e92a | 2010-02-19 19:44:48 +0100 | [diff] [blame] | 190 | if [ -f "$DOT_GIT_DIR/.gitflow/MERGE_BASE" ]; then |
Vincent Driessen | 49c7d02 | 2010-01-28 12:40:33 +0100 | [diff] [blame] | 191 | # |
| 192 | # TODO: detect that we're working on the correct branch here! |
| 193 | # The user need not necessarily have given the same $NAME twice here |
| 194 | # (although he/she should). |
| 195 | # |
Vincent Driessen | f6f152f | 2010-01-29 10:28:08 +0100 | [diff] [blame] | 196 | |
| 197 | # TODO: gitflow_test_clean_working_tree() should provide an alternative |
| 198 | # exit code for "unmerged changes in working tree", which we should |
| 199 | # actually be testing for here |
| 200 | if gitflow_test_clean_working_tree; then |
Vincent Driessen | cf6e92a | 2010-02-19 19:44:48 +0100 | [diff] [blame] | 201 | FINISH_BASE=$(cat "$DOT_GIT_DIR/.gitflow/MERGE_BASE") |
Vincent Driessen | f6f152f | 2010-01-29 10:28:08 +0100 | [diff] [blame] | 202 | |
| 203 | # Since the working tree is now clean, either the user did a |
| 204 | # succesfull merge manually, or the merge was cancelled. |
| 205 | # We detect this using gitflow_is_branch_merged_into() |
Vincent Driessen | a4dd223 | 2010-02-10 00:34:59 +0100 | [diff] [blame] | 206 | if gitflow_is_branch_merged_into "$BRANCH" "$FINISH_BASE"; then |
Vincent Driessen | cf6e92a | 2010-02-19 19:44:48 +0100 | [diff] [blame] | 207 | rm -f "$DOT_GIT_DIR/.gitflow/MERGE_BASE" |
Vincent Driessen | f6f152f | 2010-01-29 10:28:08 +0100 | [diff] [blame] | 208 | helper_finish_cleanup |
| 209 | exit 0 |
| 210 | else |
| 211 | # If the user cancelled the merge and decided to wait until later, |
| 212 | # that's fine. But we have to acknowledge this by removing the |
| 213 | # MERGE_BASE file and continuing normal execution of the finish |
Vincent Driessen | cf6e92a | 2010-02-19 19:44:48 +0100 | [diff] [blame] | 214 | rm -f "$DOT_GIT_DIR/.gitflow/MERGE_BASE" |
Vincent Driessen | f6f152f | 2010-01-29 10:28:08 +0100 | [diff] [blame] | 215 | fi |
Vincent Driessen | 49c7d02 | 2010-01-28 12:40:33 +0100 | [diff] [blame] | 216 | else |
| 217 | echo |
| 218 | echo "Merge conflicts not resolved yet, use:" |
| 219 | echo " git mergetool" |
| 220 | echo " git commit" |
| 221 | echo |
| 222 | echo "You can then complete the finish by running it again:" |
| 223 | echo " git flow feature finish $NAME" |
| 224 | echo |
| 225 | exit 1 |
| 226 | fi |
| 227 | fi |
| 228 | |
Vincent Driessen | f6f152f | 2010-01-29 10:28:08 +0100 | [diff] [blame] | 229 | # sanity checks |
| 230 | gitflow_require_clean_working_tree |
| 231 | |
Vincent Driessen | e034e4a | 2010-01-29 12:10:44 +0100 | [diff] [blame] | 232 | # update local repo with remote changes first, if asked |
Vincent Driessen | 4417492 | 2010-02-02 23:53:21 +0100 | [diff] [blame] | 233 | if flag fetch; then |
Vincent Driessen | a4dd223 | 2010-02-10 00:34:59 +0100 | [diff] [blame] | 234 | git fetch -q "$ORIGIN" "$BRANCH" |
Vincent Driessen | e034e4a | 2010-01-29 12:10:44 +0100 | [diff] [blame] | 235 | fi |
| 236 | |
Vincent Driessen | 21c7aa9 | 2010-02-16 20:57:35 +0100 | [diff] [blame] | 237 | if has "$ORIGIN/$BRANCH" "$(gitflow_remote_branches)"; then |
Vincent Driessen | a4dd223 | 2010-02-10 00:34:59 +0100 | [diff] [blame] | 238 | gitflow_require_branches_equal "$BRANCH" "$ORIGIN/$BRANCH" |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 239 | fi |
Vincent Driessen | a4dd223 | 2010-02-10 00:34:59 +0100 | [diff] [blame] | 240 | gitflow_require_branches_equal "$DEVELOP_BRANCH" "$ORIGIN/$DEVELOP_BRANCH" |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 241 | |
Vincent Driessen | 95bf82c | 2010-02-02 11:58:37 +0100 | [diff] [blame] | 242 | # if the user wants to rebase, do that first |
Vincent Driessen | 4417492 | 2010-02-02 23:53:21 +0100 | [diff] [blame] | 243 | if flag rebase; then |
Vincent Driessen | 010252a | 2010-02-04 10:31:29 +0100 | [diff] [blame] | 244 | if ! git flow feature rebase "$NAME" "$DEVELOP_BRANCH"; then |
Vincent Driessen | 95bf82c | 2010-02-02 11:58:37 +0100 | [diff] [blame] | 245 | warn "Finish was aborted due to conflicts during rebase." |
| 246 | warn "Please finish the rebase manually now." |
| 247 | warn "When finished, re-run:" |
Vincent Driessen | 010252a | 2010-02-04 10:31:29 +0100 | [diff] [blame] | 248 | warn " git flow feature finish '$NAME' '$DEVELOP_BRANCH'" |
Vincent Driessen | 95bf82c | 2010-02-02 11:58:37 +0100 | [diff] [blame] | 249 | exit 1 |
| 250 | fi |
| 251 | fi |
| 252 | |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 253 | # merge into BASE |
Vincent Driessen | a4dd223 | 2010-02-10 00:34:59 +0100 | [diff] [blame] | 254 | git checkout "$DEVELOP_BRANCH" |
| 255 | if [ "$(git rev-list -n2 "$DEVELOP_BRANCH..$BRANCH" | wc -l)" -eq 1 ]; then |
| 256 | git merge --ff "$BRANCH" |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 257 | else |
Vincent Driessen | a4dd223 | 2010-02-10 00:34:59 +0100 | [diff] [blame] | 258 | git merge --no-ff "$BRANCH" |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 259 | fi |
| 260 | |
Vincent Driessen | 49c7d02 | 2010-01-28 12:40:33 +0100 | [diff] [blame] | 261 | if [ $? -ne 0 ]; then |
| 262 | # oops.. we have a merge conflict! |
Vincent Driessen | 010252a | 2010-02-04 10:31:29 +0100 | [diff] [blame] | 263 | # 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] | 264 | mkdir -p "$DOT_GIT_DIR/.gitflow" |
| 265 | echo "$DEVELOP_BRANCH" > "$DOT_GIT_DIR/.gitflow/MERGE_BASE" |
Vincent Driessen | 49c7d02 | 2010-01-28 12:40:33 +0100 | [diff] [blame] | 266 | echo |
| 267 | echo "There were merge conflicts. To resolve the merge conflict manually, use:" |
| 268 | echo " git mergetool" |
| 269 | echo " git commit" |
| 270 | echo |
| 271 | echo "You can then complete the finish by running it again:" |
| 272 | echo " git flow feature finish $NAME" |
| 273 | echo |
| 274 | exit 1 |
| 275 | fi |
| 276 | |
| 277 | # when no merge conflict is detected, just clean up the feature branch |
| 278 | helper_finish_cleanup |
| 279 | } |
| 280 | |
| 281 | helper_finish_cleanup() { |
Vincent Driessen | f6f152f | 2010-01-29 10:28:08 +0100 | [diff] [blame] | 282 | # sanity checks |
Vincent Driessen | a4dd223 | 2010-02-10 00:34:59 +0100 | [diff] [blame] | 283 | gitflow_require_branch "$BRANCH" |
Vincent Driessen | 1ee37e7 | 2010-01-29 17:36:21 +0100 | [diff] [blame] | 284 | gitflow_require_clean_working_tree |
Vincent Driessen | f6f152f | 2010-01-29 10:28:08 +0100 | [diff] [blame] | 285 | |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 286 | # delete branch |
Vincent Driessen | 4417492 | 2010-02-02 23:53:21 +0100 | [diff] [blame] | 287 | if flag fetch; then |
Vincent Driessen | a4dd223 | 2010-02-10 00:34:59 +0100 | [diff] [blame] | 288 | git push "$ORIGIN" ":refs/heads/$BRANCH" |
Vincent Driessen | eec73c6 | 2010-02-02 16:14:16 +0100 | [diff] [blame] | 289 | fi |
Vincent Driessen | a4dd223 | 2010-02-10 00:34:59 +0100 | [diff] [blame] | 290 | git branch -d "$BRANCH" |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 291 | |
| 292 | echo |
| 293 | echo "Summary of actions:" |
Vincent Driessen | 010252a | 2010-02-04 10:31:29 +0100 | [diff] [blame] | 294 | echo "- The feature branch '$BRANCH' was merged into '$DEVELOP_BRANCH'" |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 295 | #echo "- Merge conflicts were resolved" # TODO: Add this line when it's supported |
| 296 | echo "- Feature branch '$BRANCH' has been removed" |
Vincent Driessen | 010252a | 2010-02-04 10:31:29 +0100 | [diff] [blame] | 297 | echo "- You are now on branch '$DEVELOP_BRANCH'" |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 298 | echo |
| 299 | } |
| 300 | |
| 301 | cmd_publish() { |
Vincent Driessen | ea60895 | 2010-01-29 16:56:29 +0100 | [diff] [blame] | 302 | parse_args "$@" |
Vincent Driessen | d099126 | 2010-02-06 21:19:07 +0100 | [diff] [blame] | 303 | expand_nameprefix_arg |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 304 | |
| 305 | # sanity checks |
Vincent Driessen | 4838644 | 2010-01-29 10:30:40 +0100 | [diff] [blame] | 306 | gitflow_require_clean_working_tree |
Vincent Driessen | a4dd223 | 2010-02-10 00:34:59 +0100 | [diff] [blame] | 307 | gitflow_require_branch "$BRANCH" |
| 308 | git fetch -q "$ORIGIN" |
| 309 | gitflow_require_branch_absent "$ORIGIN/$BRANCH" |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 310 | |
| 311 | # create remote branch |
Vincent Driessen | a4dd223 | 2010-02-10 00:34:59 +0100 | [diff] [blame] | 312 | git push "$ORIGIN" "$BRANCH:refs/heads/$BRANCH" |
| 313 | git fetch -q "$ORIGIN" |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 314 | |
| 315 | # configure remote tracking |
Vincent Driessen | a4dd223 | 2010-02-10 00:34:59 +0100 | [diff] [blame] | 316 | git config "branch.$BRANCH.remote" "$ORIGIN" |
| 317 | git config "branch.$BRANCH.merge" "refs/heads/$BRANCH" |
| 318 | git checkout "$BRANCH" |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 319 | |
| 320 | echo |
| 321 | echo "Summary of actions:" |
| 322 | echo "- A new remote branch '$BRANCH' was created" |
| 323 | echo "- The local branch '$BRANCH' was configured to track the remote branch" |
| 324 | echo "- You are now on branch '$BRANCH'" |
| 325 | echo |
| 326 | } |
| 327 | |
| 328 | cmd_track() { |
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 | require_name_arg |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 331 | |
| 332 | # sanity checks |
Vincent Driessen | 4838644 | 2010-01-29 10:30:40 +0100 | [diff] [blame] | 333 | gitflow_require_clean_working_tree |
Vincent Driessen | a4dd223 | 2010-02-10 00:34:59 +0100 | [diff] [blame] | 334 | gitflow_require_branch_absent "$BRANCH" |
| 335 | git fetch -q "$ORIGIN" |
| 336 | gitflow_require_branch "$ORIGIN/$BRANCH" |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 337 | |
| 338 | # create tracking branch |
Vincent Driessen | a4dd223 | 2010-02-10 00:34:59 +0100 | [diff] [blame] | 339 | git checkout -b "$BRANCH" "$ORIGIN/$BRANCH" |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 340 | |
| 341 | echo |
| 342 | echo "Summary of actions:" |
| 343 | echo "- A new remote tracking branch '$BRANCH' was created" |
| 344 | echo "- You are now on branch '$BRANCH'" |
| 345 | echo |
| 346 | } |
Vincent Driessen | bd4f095 | 2010-01-27 13:57:15 +0100 | [diff] [blame] | 347 | |
Vincent Driessen | bd4f095 | 2010-01-27 13:57:15 +0100 | [diff] [blame] | 348 | cmd_diff() { |
Vincent Driessen | 1b81923 | 2010-02-01 15:51:43 +0100 | [diff] [blame] | 349 | parse_args "$@" |
Vincent Driessen | 1b81923 | 2010-02-01 15:51:43 +0100 | [diff] [blame] | 350 | |
Vincent Driessen | 5474e46 | 2010-02-04 15:50:06 +0100 | [diff] [blame] | 351 | if [ "$NAME" != "" ]; then |
Vincent Driessen | d099126 | 2010-02-06 21:19:07 +0100 | [diff] [blame] | 352 | expand_nameprefix_arg |
Vincent Driessen | a4dd223 | 2010-02-10 00:34:59 +0100 | [diff] [blame] | 353 | BASE=$(git merge-base "$DEVELOP_BRANCH" "$BRANCH") |
| 354 | git diff "$BASE..$BRANCH" |
Vincent Driessen | 5474e46 | 2010-02-04 15:50:06 +0100 | [diff] [blame] | 355 | else |
Vincent Driessen | d099126 | 2010-02-06 21:19:07 +0100 | [diff] [blame] | 356 | if ! gitflow_current_branch | grep -q "^$PREFIX"; then |
Vincent Driessen | 5474e46 | 2010-02-04 15:50:06 +0100 | [diff] [blame] | 357 | die "Not on a feature branch. Name one explicitly." |
| 358 | fi |
| 359 | |
Vincent Driessen | a4dd223 | 2010-02-10 00:34:59 +0100 | [diff] [blame] | 360 | BASE=$(git merge-base "$DEVELOP_BRANCH" HEAD) |
| 361 | git diff "$BASE" |
Vincent Driessen | 5474e46 | 2010-02-04 15:50:06 +0100 | [diff] [blame] | 362 | fi |
Vincent Driessen | bd4f095 | 2010-01-27 13:57:15 +0100 | [diff] [blame] | 363 | } |
Vincent Driessen | c62633f | 2010-02-02 10:48:50 +0100 | [diff] [blame] | 364 | |
| 365 | cmd_rebase() { |
Vincent Driessen | 4417492 | 2010-02-02 23:53:21 +0100 | [diff] [blame] | 366 | DEFINE_boolean interactive false 'do an interactive rebase' i |
Vincent Driessen | c62633f | 2010-02-02 10:48:50 +0100 | [diff] [blame] | 367 | parse_args "$@" |
Vincent Driessen | d099126 | 2010-02-06 21:19:07 +0100 | [diff] [blame] | 368 | expand_nameprefix_arg_or_current |
Vincent Driessen | c62633f | 2010-02-02 10:48:50 +0100 | [diff] [blame] | 369 | warn "Will try to rebase '$NAME'..." |
| 370 | gitflow_require_clean_working_tree |
| 371 | gitflow_require_branch "$BRANCH" |
| 372 | |
| 373 | git checkout -q "$BRANCH" |
Vincent Driessen | f46e290 | 2010-02-15 23:01:52 +0100 | [diff] [blame] | 374 | local OPTS= |
Vincent Driessen | 4417492 | 2010-02-02 23:53:21 +0100 | [diff] [blame] | 375 | if flag interactive; then |
Vincent Driessen | c62633f | 2010-02-02 10:48:50 +0100 | [diff] [blame] | 376 | OPTS="$OPTS -i" |
| 377 | fi |
Vincent Driessen | 010252a | 2010-02-04 10:31:29 +0100 | [diff] [blame] | 378 | git rebase $OPTS "$DEVELOP_BRANCH" |
Vincent Driessen | c62633f | 2010-02-02 10:48:50 +0100 | [diff] [blame] | 379 | } |