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