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