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 | |
Vincent Driessen | 95bf82c | 2010-02-02 11:58:37 +0100 | [diff] [blame] | 252 | # if the user wants to rebase, do that first |
| 253 | if [ $FLAGS_rebase -eq 1 ]; then |
| 254 | if ! git flow feature rebase "$NAME" "$BASE"; then |
| 255 | warn "Finish was aborted due to conflicts during rebase." |
| 256 | warn "Please finish the rebase manually now." |
| 257 | warn "When finished, re-run:" |
| 258 | warn " git flow feature finish '$NAME' '$BASE'" |
| 259 | exit 1 |
| 260 | fi |
| 261 | fi |
| 262 | |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 263 | # merge into BASE |
| 264 | git checkout $BASE |
Vincent Driessen | 9cf5673 | 2010-02-02 11:57:51 +0100 | [diff] [blame] | 265 | if [ "$(git rev-list -n2 $BASE..$BRANCH | wc -l)" -eq 1 ]; then |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 266 | git merge --ff $BRANCH |
| 267 | else |
| 268 | git merge --no-ff $BRANCH |
| 269 | fi |
| 270 | |
Vincent Driessen | 49c7d02 | 2010-01-28 12:40:33 +0100 | [diff] [blame] | 271 | if [ $? -ne 0 ]; then |
| 272 | # oops.. we have a merge conflict! |
| 273 | # write the given $BASE to a temporary file (we need it later) |
Vincent Driessen | f6f152f | 2010-01-29 10:28:08 +0100 | [diff] [blame] | 274 | mkdir -p "$GIT_DIR/.gitflow" |
Vincent Driessen | 49c7d02 | 2010-01-28 12:40:33 +0100 | [diff] [blame] | 275 | echo "$BASE" > "$GIT_DIR/.gitflow/MERGE_BASE" |
| 276 | echo |
| 277 | echo "There were merge conflicts. To resolve the merge conflict manually, use:" |
| 278 | echo " git mergetool" |
| 279 | echo " git commit" |
| 280 | echo |
| 281 | echo "You can then complete the finish by running it again:" |
| 282 | echo " git flow feature finish $NAME" |
| 283 | echo |
| 284 | exit 1 |
| 285 | fi |
| 286 | |
| 287 | # when no merge conflict is detected, just clean up the feature branch |
| 288 | helper_finish_cleanup |
| 289 | } |
| 290 | |
| 291 | helper_finish_cleanup() { |
Vincent Driessen | f6f152f | 2010-01-29 10:28:08 +0100 | [diff] [blame] | 292 | # sanity checks |
| 293 | gitflow_require_branch $BRANCH |
Vincent Driessen | 1ee37e7 | 2010-01-29 17:36:21 +0100 | [diff] [blame] | 294 | gitflow_require_clean_working_tree |
Vincent Driessen | f6f152f | 2010-01-29 10:28:08 +0100 | [diff] [blame] | 295 | |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 296 | # delete branch |
Benedikt Böhm | 350e715 | 2010-01-26 13:05:05 +0100 | [diff] [blame] | 297 | git push $ORIGIN :refs/heads/$BRANCH |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 298 | git branch -d $BRANCH |
| 299 | |
| 300 | echo |
| 301 | echo "Summary of actions:" |
| 302 | echo "- The feature branch '$BRANCH' was merged into '$BASE'" |
| 303 | #echo "- Merge conflicts were resolved" # TODO: Add this line when it's supported |
| 304 | echo "- Feature branch '$BRANCH' has been removed" |
| 305 | echo "- You are now on branch '$BASE'" |
| 306 | echo |
| 307 | } |
| 308 | |
| 309 | cmd_publish() { |
Vincent Driessen | ea60895 | 2010-01-29 16:56:29 +0100 | [diff] [blame] | 310 | parse_args "$@" |
Vincent Driessen | 1b81923 | 2010-02-01 15:51:43 +0100 | [diff] [blame] | 311 | expand_name_arg_prefix |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 312 | |
| 313 | # sanity checks |
Vincent Driessen | 4838644 | 2010-01-29 10:30:40 +0100 | [diff] [blame] | 314 | gitflow_require_clean_working_tree |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 315 | gitflow_require_branch $BRANCH |
Benedikt Böhm | 4d22227 | 2010-01-26 14:46:56 +0100 | [diff] [blame] | 316 | git fetch -q $ORIGIN |
Benedikt Böhm | 350e715 | 2010-01-26 13:05:05 +0100 | [diff] [blame] | 317 | gitflow_require_branch_absent $ORIGIN/$BRANCH |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 318 | |
| 319 | # create remote branch |
Benedikt Böhm | 350e715 | 2010-01-26 13:05:05 +0100 | [diff] [blame] | 320 | git push $ORIGIN $BRANCH:refs/heads/$BRANCH |
Benedikt Böhm | 4d22227 | 2010-01-26 14:46:56 +0100 | [diff] [blame] | 321 | git fetch -q $ORIGIN |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 322 | |
| 323 | # configure remote tracking |
Benedikt Böhm | 350e715 | 2010-01-26 13:05:05 +0100 | [diff] [blame] | 324 | git config branch.$BRANCH.remote $ORIGIN |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 325 | git config branch.$BRANCH.merge refs/heads/$BRANCH |
| 326 | git checkout $BRANCH |
| 327 | |
| 328 | echo |
| 329 | echo "Summary of actions:" |
| 330 | echo "- A new remote branch '$BRANCH' was created" |
| 331 | echo "- The local branch '$BRANCH' was configured to track the remote branch" |
| 332 | echo "- You are now on branch '$BRANCH'" |
| 333 | echo |
| 334 | } |
| 335 | |
| 336 | cmd_track() { |
Vincent Driessen | ea60895 | 2010-01-29 16:56:29 +0100 | [diff] [blame] | 337 | parse_args "$@" |
Vincent Driessen | 1b81923 | 2010-02-01 15:51:43 +0100 | [diff] [blame] | 338 | require_name |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 339 | |
| 340 | # sanity checks |
Vincent Driessen | 4838644 | 2010-01-29 10:30:40 +0100 | [diff] [blame] | 341 | gitflow_require_clean_working_tree |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 342 | gitflow_require_branch_absent $BRANCH |
Benedikt Böhm | 4d22227 | 2010-01-26 14:46:56 +0100 | [diff] [blame] | 343 | git fetch -q $ORIGIN |
Benedikt Böhm | 350e715 | 2010-01-26 13:05:05 +0100 | [diff] [blame] | 344 | gitflow_require_branch $ORIGIN/$BRANCH |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 345 | |
| 346 | # create tracking branch |
Benedikt Böhm | 350e715 | 2010-01-26 13:05:05 +0100 | [diff] [blame] | 347 | git checkout -b $BRANCH $ORIGIN/$BRANCH |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 348 | |
| 349 | echo |
| 350 | echo "Summary of actions:" |
| 351 | echo "- A new remote tracking branch '$BRANCH' was created" |
| 352 | echo "- You are now on branch '$BRANCH'" |
| 353 | echo |
| 354 | } |
Vincent Driessen | bd4f095 | 2010-01-27 13:57:15 +0100 | [diff] [blame] | 355 | |
Vincent Driessen | bd4f095 | 2010-01-27 13:57:15 +0100 | [diff] [blame] | 356 | cmd_diff() { |
Vincent Driessen | 1b81923 | 2010-02-01 15:51:43 +0100 | [diff] [blame] | 357 | parse_args "$@" |
Vincent Driessen | c62633f | 2010-02-02 10:48:50 +0100 | [diff] [blame] | 358 | expand_name_arg_prefix_or_current |
Vincent Driessen | 1b81923 | 2010-02-01 15:51:43 +0100 | [diff] [blame] | 359 | |
Vincent Driessen | bd4f095 | 2010-01-27 13:57:15 +0100 | [diff] [blame] | 360 | # TODO: if this feature has been based on a non-develop branch, we really |
| 361 | # should not be comparing to $DEVELOP. How to deal with this? |
Vincent Driessen | 278884b | 2010-01-28 16:29:34 +0100 | [diff] [blame] | 362 | git diff $DEVELOP_BRANCH..$BRANCH |
Vincent Driessen | bd4f095 | 2010-01-27 13:57:15 +0100 | [diff] [blame] | 363 | } |
Vincent Driessen | c62633f | 2010-02-02 10:48:50 +0100 | [diff] [blame] | 364 | |
| 365 | cmd_rebase() { |
| 366 | DEFINE_boolean interactive 0 'do an interactive rebase' i |
| 367 | parse_args "$@" |
| 368 | expand_name_arg_prefix_or_current |
| 369 | warn "Will try to rebase '$NAME'..." |
| 370 | gitflow_require_clean_working_tree |
| 371 | gitflow_require_branch "$BRANCH" |
| 372 | |
| 373 | git checkout -q "$BRANCH" |
| 374 | OPTS= |
| 375 | if [ $FLAGS_interactive -eq 1 ]; then |
| 376 | OPTS="$OPTS -i" |
| 377 | fi |
| 378 | git rebase $OPTS "$BASE" |
| 379 | } |