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