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