blob: e5d0ed6411b622ed518cc151932e6166aa08ad7b [file] [log] [blame]
Benedikt Böhm00ccea62010-01-26 12:39:36 +01001#
Vincent Driessen6c2d30b2010-01-26 22:18:36 +01002# git-flow -- A collection of Git extensions to provide high-level
3# repository operations for Vincent Driessen's branching model.
Benedikt Böhm00ccea62010-01-26 12:39:36 +01004#
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#
Vincent Driessend72acba2010-04-04 16:10:17 +020011# Copyright 2010 Vincent Driessen. All rights reserved.
12#
13# Redistribution and use in source and binary forms, with or without
14# modification, are permitted provided that the following conditions are met:
15#
16# 1. Redistributions of source code must retain the above copyright notice,
17# this list of conditions and the following disclaimer.
18#
19# 2. Redistributions in binary form must reproduce the above copyright
20# notice, this list of conditions and the following disclaimer in the
21# documentation and/or other materials provided with the distribution.
22#
23# THIS SOFTWARE IS PROVIDED BY VINCENT DRIESSEN ``AS IS'' AND ANY EXPRESS OR
24# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
26# EVENT SHALL VINCENT DRIESSEN OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
30# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
31# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
32# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33#
34# The views and conclusions contained in the software and documentation are
35# those of the authors and should not be interpreted as representing official
36# policies, either expressed or implied, of Vincent Driessen.
Benedikt Böhm00ccea62010-01-26 12:39:36 +010037#
38
Vincent Driessen7832d6e2010-02-21 21:31:03 +010039require_git_repo
40require_gitflow_initialized
Vincent Driessend72e4ac2010-02-16 21:33:51 +010041gitflow_load_settings
Vincent Driessenc1598bf2010-02-20 16:52:48 +010042PREFIX=$(git config --get gitflow.prefix.feature)
Benedikt Böhm49dd62b2010-01-28 00:51:15 +010043
Benedikt Böhm00ccea62010-01-26 12:39:36 +010044usage() {
Vincent Driessenb03cf962010-02-01 22:00:39 +010045 echo "usage: git flow feature [list] [-v]"
Vincent Driessena2e41162010-02-24 01:37:07 +010046 echo " git flow feature start [-Ff] <name> [<base>]"
47 echo " git flow feature finish [-rF] <name|nameprefix>"
Vincent Driessen186d2b52010-01-27 23:48:39 +010048 echo " git flow feature publish <name>"
49 echo " git flow feature track <name>"
Vincent Driessena2e41162010-02-24 01:37:07 +010050 echo " git flow feature diff [<name|nameprefix>]"
51 echo " git flow feature rebase [-i] [<name|nameprefix>]"
Vincent Driessend43ab842010-05-27 11:26:01 -070052 echo " git flow feature checkout [<name|nameprefix>]"
Benedikt Böhm00ccea62010-01-26 12:39:36 +010053}
54
Vincent Driessen186d2b52010-01-27 23:48:39 +010055cmd_default() {
Vincent Driessenb866b012010-01-28 01:01:53 +010056 cmd_list "$@"
Benedikt Böhm00ccea62010-01-26 12:39:36 +010057}
58
Vincent Driessenb866b012010-01-28 01:01:53 +010059cmd_list() {
Vincent Driessen44174922010-02-02 23:53:21 +010060 DEFINE_boolean verbose false 'verbose (more) output' v
Vincent Driessen1b819232010-02-01 15:51:43 +010061 parse_args "$@"
62
Vincent Driessenf46e2902010-02-15 23:01:52 +010063 local feature_branches
64 local current_branch
65 local short_names
Vincent Driessen7832d6e2010-02-21 21:31:03 +010066 feature_branches=$(echo "$(git_local_branches)" | grep "^$PREFIX")
Vincent Driessen27592dd2010-02-06 14:45:39 +010067 if [ -z "$feature_branches" ]; then
Vincent Driessen186d2b52010-01-27 23:48:39 +010068 warn "No feature branches exist."
Randy Merrillb681b452010-06-26 13:14:15 +080069 warn ""
70 warn "You can start a new feature branch:"
71 warn ""
72 warn " git flow feature start <name> [<base>]"
Vincent Driessen186d2b52010-01-27 23:48:39 +010073 exit 0
74 fi
Vincent Driessen27592dd2010-02-06 14:45:39 +010075 current_branch=$(git branch | grep '^\* ' | grep -v 'no branch' | sed 's/^* //g')
76 short_names=$(echo "$feature_branches" | sed "s ^$PREFIX g")
Vincent Driessenf2536f42010-02-01 15:57:48 +010077
Vincent Driessenaa6d0162010-02-01 19:43:46 +010078 # determine column width first
Vincent Driessenf46e2902010-02-15 23:01:52 +010079 local width=0
80 local branch
Vincent Driessen27592dd2010-02-06 14:45:39 +010081 for branch in $short_names; do
Vincent Driessenf46e2902010-02-15 23:01:52 +010082 local len=${#branch}
Vincent Driessenaa6d0162010-02-01 19:43:46 +010083 width=$(max $width $len)
84 done
Vincent Driessenf46e2902010-02-15 23:01:52 +010085 width=$(($width+3))
Vincent Driessen1adbc3e2010-01-30 16:28:20 +010086
Vincent Driessenf46e2902010-02-15 23:01:52 +010087 local branch
Vincent Driessen27592dd2010-02-06 14:45:39 +010088 for branch in $short_names; do
Vincent Driessenf46e2902010-02-15 23:01:52 +010089 local fullname=$PREFIX$branch
90 local base=$(git merge-base "$fullname" "$DEVELOP_BRANCH")
91 local develop_sha=$(git rev-parse "$DEVELOP_BRANCH")
92 local branch_sha=$(git rev-parse "$fullname")
Vincent Driessen27592dd2010-02-06 14:45:39 +010093 if [ "$fullname" = "$current_branch" ]; then
Vincent Driessenaa6d0162010-02-01 19:43:46 +010094 printf "* "
95 else
96 printf " "
97 fi
Vincent Driessen44174922010-02-02 23:53:21 +010098 if flag verbose; then
Vincent Driessen1adbc3e2010-01-30 16:28:20 +010099 printf "%-${width}s" "$branch"
Vincent Driessenf2536f42010-02-01 15:57:48 +0100100 if [ "$branch_sha" = "$develop_sha" ]; then
101 printf "(no commits yet)"
102 elif [ "$base" = "$branch_sha" ]; then
103 printf "(is behind develop, may ff)"
104 elif [ "$base" = "$develop_sha" ]; then
105 printf "(based on latest develop)"
106 else
107 printf "(may be rebased)"
108 fi
Vincent Driessenaa6d0162010-02-01 19:43:46 +0100109 else
110 printf "%s" "$branch"
111 fi
112 echo
113 done
Vincent Driessen186d2b52010-01-27 23:48:39 +0100114}
115
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100116cmd_help() {
117 usage
118 exit 0
119}
120
Vincent Driessend0991262010-02-06 21:19:07 +0100121require_name_arg() {
Vincent Driessen1b819232010-02-01 15:51:43 +0100122 if [ "$NAME" = "" ]; then
Vincent Driessen3c337fb2010-02-04 11:30:18 +0100123 warn "Missing argument <name>"
Vincent Driessen1b819232010-02-01 15:51:43 +0100124 usage
Vincent Driessen2e1856b2010-01-29 15:18:13 +0100125 exit 1
126 fi
127}
128
Vincent Driessend0991262010-02-06 21:19:07 +0100129expand_nameprefix_arg() {
130 require_name_arg
131
Vincent Driessenf46e2902010-02-15 23:01:52 +0100132 local expanded_name
133 local exitcode
Vincent Driessen7832d6e2010-02-21 21:31:03 +0100134 expanded_name=$(gitflow_resolve_nameprefix "$NAME" "$PREFIX")
Vincent Driessend0991262010-02-06 21:19:07 +0100135 exitcode=$?
136 case $exitcode in
137 0) NAME=$expanded_name
138 BRANCH=$PREFIX$NAME
139 ;;
140 *) exit 1 ;;
141 esac
Vincent Driessen2e1856b2010-01-29 15:18:13 +0100142}
143
Vincent Driessend0991262010-02-06 21:19:07 +0100144expand_nameprefix_arg_or_current() {
Vincent Driessenc62633f2010-02-02 10:48:50 +0100145 if [ "$NAME" != "" ]; then
Vincent Driessend0991262010-02-06 21:19:07 +0100146 expand_nameprefix_arg
Vincent Driessen7832d6e2010-02-21 21:31:03 +0100147 require_branch "$PREFIX$NAME"
Vincent Driessenc62633f2010-02-02 10:48:50 +0100148 else
Vincent Driessen7832d6e2010-02-21 21:31:03 +0100149 local current_branch=$(git_current_branch)
Vincent Driessend0991262010-02-06 21:19:07 +0100150 if startswith "$current_branch" "$PREFIX"; then
151 BRANCH=$current_branch
152 NAME=${BRANCH#$PREFIX}
153 else
154 warn "The current HEAD is no feature branch."
155 warn "To diff a feature, specify a <name> argument."
156 usage
157 exit 1
158 fi
Vincent Driessenc62633f2010-02-02 10:48:50 +0100159 fi
160}
161
Vincent Driessenea608952010-01-29 16:56:29 +0100162parse_args() {
Vincent Driessen1b819232010-02-01 15:51:43 +0100163 # parse options
164 FLAGS "$@" || exit $?
165 eval set -- "${FLAGS_ARGV}"
166
167 # read arguments into global variables
Vincent Driessenc5fcc012010-02-10 00:18:08 +0100168 NAME=$1
Vincent Driessen11560922010-02-01 21:58:37 +0100169 BRANCH=$PREFIX$NAME
Vincent Driessenb866b012010-01-28 01:01:53 +0100170}
171
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100172cmd_start() {
Vincent Driessen44174922010-02-02 23:53:21 +0100173 DEFINE_boolean fetch false 'fetch from origin before performing local operation' F
Vincent Driessen5455a6f2010-02-03 00:14:05 +0100174 DEFINE_boolean force false 'force creation of feature branch (ignores dirty working tree)' f
Vincent Driessenea608952010-01-29 16:56:29 +0100175 parse_args "$@"
Vincent Driessenc5fcc012010-02-10 00:18:08 +0100176 BASE=${2:-$DEVELOP_BRANCH}
Vincent Driessend0991262010-02-06 21:19:07 +0100177 require_name_arg
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100178
179 # sanity checks
Vincent Driessen5455a6f2010-02-03 00:14:05 +0100180 if noflag force; then
Vincent Driessen7832d6e2010-02-21 21:31:03 +0100181 require_clean_working_tree
Vincent Driessen5455a6f2010-02-03 00:14:05 +0100182 fi
Vincent Driessen7832d6e2010-02-21 21:31:03 +0100183 require_branch_absent "$BRANCH"
Vincent Driessene034e4a2010-01-29 12:10:44 +0100184
185 # update the local repo with remote changes, if asked
Vincent Driessen44174922010-02-02 23:53:21 +0100186 if flag fetch; then
Vincent Driessena4dd2232010-02-10 00:34:59 +0100187 git fetch -q "$ORIGIN" "$DEVELOP_BRANCH"
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100188 fi
189
Vincent Driessenc118a852010-04-04 16:32:04 +0200190 # if the origin branch counterpart exists, assert that the local branch
191 # isn't behind it (to avoid unnecessary rebasing)
192 if git_branch_exists "$ORIGIN/$DEVELOP_BRANCH"; then
193 require_branches_equal "$DEVELOP_BRANCH" "$ORIGIN/$DEVELOP_BRANCH"
194 fi
Vincent Driessene034e4a2010-01-29 12:10:44 +0100195
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100196 # create branch
Vincent Driessena4dd2232010-02-10 00:34:59 +0100197 if ! git checkout -b "$BRANCH" "$BASE"; then
Vincent Driessen5455a6f2010-02-03 00:14:05 +0100198 die "Could not create feature branch '$BRANCH'"
199 fi
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100200
201 echo
202 echo "Summary of actions:"
203 echo "- A new branch '$BRANCH' was created, based on '$BASE'"
204 echo "- You are now on branch '$BRANCH'"
205 echo ""
206 echo "Now, start committing on your feature. When done, use:"
207 echo ""
gmallard192ff522010-04-01 19:31:09 -0400208 echo " git flow feature finish $NAME"
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100209 echo
210}
211
212cmd_finish() {
Vincent Driessenca73caf2010-02-07 19:46:38 +0100213 DEFINE_boolean fetch false "fetch from $ORIGIN before performing finish" F
Vincent Driessen44174922010-02-02 23:53:21 +0100214 DEFINE_boolean rebase false 'rebase instead of merge' r
Vincent Driessen1b819232010-02-01 15:51:43 +0100215 parse_args "$@"
Vincent Driessend0991262010-02-06 21:19:07 +0100216 expand_nameprefix_arg
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100217
218 # sanity checks
Vincent Driessen7832d6e2010-02-21 21:31:03 +0100219 require_branch "$BRANCH"
Vincent Driessene034e4a2010-01-29 12:10:44 +0100220
Vincent Driessen49c7d022010-01-28 12:40:33 +0100221 # detect if we're restoring from a merge conflict
Vincent Driessencf6e92a2010-02-19 19:44:48 +0100222 if [ -f "$DOT_GIT_DIR/.gitflow/MERGE_BASE" ]; then
Vincent Driessen49c7d022010-01-28 12:40:33 +0100223 #
224 # TODO: detect that we're working on the correct branch here!
225 # The user need not necessarily have given the same $NAME twice here
226 # (although he/she should).
227 #
Vincent Driessenf6f152f2010-01-29 10:28:08 +0100228
Vincent Driessen7832d6e2010-02-21 21:31:03 +0100229 # TODO: git_is_clean_working_tree() should provide an alternative
Vincent Driessenf6f152f2010-01-29 10:28:08 +0100230 # exit code for "unmerged changes in working tree", which we should
231 # actually be testing for here
Vincent Driessen7832d6e2010-02-21 21:31:03 +0100232 if git_is_clean_working_tree; then
Vincent Driessencf6e92a2010-02-19 19:44:48 +0100233 FINISH_BASE=$(cat "$DOT_GIT_DIR/.gitflow/MERGE_BASE")
Vincent Driessenf6f152f2010-01-29 10:28:08 +0100234
235 # Since the working tree is now clean, either the user did a
236 # succesfull merge manually, or the merge was cancelled.
Vincent Driessen7832d6e2010-02-21 21:31:03 +0100237 # We detect this using git_is_branch_merged_into()
238 if git_is_branch_merged_into "$BRANCH" "$FINISH_BASE"; then
Vincent Driessencf6e92a2010-02-19 19:44:48 +0100239 rm -f "$DOT_GIT_DIR/.gitflow/MERGE_BASE"
Vincent Driessenf6f152f2010-01-29 10:28:08 +0100240 helper_finish_cleanup
241 exit 0
242 else
243 # If the user cancelled the merge and decided to wait until later,
244 # that's fine. But we have to acknowledge this by removing the
245 # MERGE_BASE file and continuing normal execution of the finish
Vincent Driessencf6e92a2010-02-19 19:44:48 +0100246 rm -f "$DOT_GIT_DIR/.gitflow/MERGE_BASE"
Vincent Driessenf6f152f2010-01-29 10:28:08 +0100247 fi
Vincent Driessen49c7d022010-01-28 12:40:33 +0100248 else
249 echo
250 echo "Merge conflicts not resolved yet, use:"
251 echo " git mergetool"
252 echo " git commit"
253 echo
254 echo "You can then complete the finish by running it again:"
255 echo " git flow feature finish $NAME"
256 echo
257 exit 1
258 fi
259 fi
260
Vincent Driessenf6f152f2010-01-29 10:28:08 +0100261 # sanity checks
Vincent Driessen7832d6e2010-02-21 21:31:03 +0100262 require_clean_working_tree
Vincent Driessenf6f152f2010-01-29 10:28:08 +0100263
Vincent Driessene034e4a2010-01-29 12:10:44 +0100264 # update local repo with remote changes first, if asked
Vincent Driessen44174922010-02-02 23:53:21 +0100265 if flag fetch; then
Vincent Driessena4dd2232010-02-10 00:34:59 +0100266 git fetch -q "$ORIGIN" "$BRANCH"
Vincent Driessene034e4a2010-01-29 12:10:44 +0100267 fi
268
Vincent Driessen7832d6e2010-02-21 21:31:03 +0100269 if has "$ORIGIN/$BRANCH" "$(git_remote_branches)"; then
270 require_branches_equal "$BRANCH" "$ORIGIN/$BRANCH"
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100271 fi
Vincent Driessen7832d6e2010-02-21 21:31:03 +0100272 require_branches_equal "$DEVELOP_BRANCH" "$ORIGIN/$DEVELOP_BRANCH"
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100273
Vincent Driessen95bf82c2010-02-02 11:58:37 +0100274 # if the user wants to rebase, do that first
Vincent Driessen44174922010-02-02 23:53:21 +0100275 if flag rebase; then
Vincent Driessen010252a2010-02-04 10:31:29 +0100276 if ! git flow feature rebase "$NAME" "$DEVELOP_BRANCH"; then
Vincent Driessen95bf82c2010-02-02 11:58:37 +0100277 warn "Finish was aborted due to conflicts during rebase."
278 warn "Please finish the rebase manually now."
279 warn "When finished, re-run:"
Vincent Driessen010252a2010-02-04 10:31:29 +0100280 warn " git flow feature finish '$NAME' '$DEVELOP_BRANCH'"
Vincent Driessen95bf82c2010-02-02 11:58:37 +0100281 exit 1
282 fi
283 fi
284
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100285 # merge into BASE
Vincent Driessena4dd2232010-02-10 00:34:59 +0100286 git checkout "$DEVELOP_BRANCH"
287 if [ "$(git rev-list -n2 "$DEVELOP_BRANCH..$BRANCH" | wc -l)" -eq 1 ]; then
288 git merge --ff "$BRANCH"
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100289 else
Vincent Driessena4dd2232010-02-10 00:34:59 +0100290 git merge --no-ff "$BRANCH"
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100291 fi
292
Vincent Driessen49c7d022010-01-28 12:40:33 +0100293 if [ $? -ne 0 ]; then
294 # oops.. we have a merge conflict!
Vincent Driessen010252a2010-02-04 10:31:29 +0100295 # write the given $DEVELOP_BRANCH to a temporary file (we need it later)
Vincent Driessencf6e92a2010-02-19 19:44:48 +0100296 mkdir -p "$DOT_GIT_DIR/.gitflow"
297 echo "$DEVELOP_BRANCH" > "$DOT_GIT_DIR/.gitflow/MERGE_BASE"
Vincent Driessen49c7d022010-01-28 12:40:33 +0100298 echo
299 echo "There were merge conflicts. To resolve the merge conflict manually, use:"
300 echo " git mergetool"
301 echo " git commit"
302 echo
303 echo "You can then complete the finish by running it again:"
304 echo " git flow feature finish $NAME"
305 echo
306 exit 1
307 fi
308
309 # when no merge conflict is detected, just clean up the feature branch
310 helper_finish_cleanup
311}
312
313helper_finish_cleanup() {
Vincent Driessenf6f152f2010-01-29 10:28:08 +0100314 # sanity checks
Vincent Driessen7832d6e2010-02-21 21:31:03 +0100315 require_branch "$BRANCH"
316 require_clean_working_tree
Vincent Driessenf6f152f2010-01-29 10:28:08 +0100317
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100318 # delete branch
Vincent Driessen44174922010-02-02 23:53:21 +0100319 if flag fetch; then
Vincent Driessena4dd2232010-02-10 00:34:59 +0100320 git push "$ORIGIN" ":refs/heads/$BRANCH"
Vincent Driesseneec73c62010-02-02 16:14:16 +0100321 fi
Vincent Driessena4dd2232010-02-10 00:34:59 +0100322 git branch -d "$BRANCH"
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100323
324 echo
325 echo "Summary of actions:"
Vincent Driessen010252a2010-02-04 10:31:29 +0100326 echo "- The feature branch '$BRANCH' was merged into '$DEVELOP_BRANCH'"
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100327 #echo "- Merge conflicts were resolved" # TODO: Add this line when it's supported
328 echo "- Feature branch '$BRANCH' has been removed"
Vincent Driessen010252a2010-02-04 10:31:29 +0100329 echo "- You are now on branch '$DEVELOP_BRANCH'"
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100330 echo
331}
332
333cmd_publish() {
Vincent Driessenea608952010-01-29 16:56:29 +0100334 parse_args "$@"
Vincent Driessend0991262010-02-06 21:19:07 +0100335 expand_nameprefix_arg
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100336
337 # sanity checks
Vincent Driessen7832d6e2010-02-21 21:31:03 +0100338 require_clean_working_tree
339 require_branch "$BRANCH"
Vincent Driessena4dd2232010-02-10 00:34:59 +0100340 git fetch -q "$ORIGIN"
Vincent Driessen7832d6e2010-02-21 21:31:03 +0100341 require_branch_absent "$ORIGIN/$BRANCH"
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100342
343 # create remote branch
Vincent Driessena4dd2232010-02-10 00:34:59 +0100344 git push "$ORIGIN" "$BRANCH:refs/heads/$BRANCH"
345 git fetch -q "$ORIGIN"
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100346
347 # configure remote tracking
Vincent Driessena4dd2232010-02-10 00:34:59 +0100348 git config "branch.$BRANCH.remote" "$ORIGIN"
349 git config "branch.$BRANCH.merge" "refs/heads/$BRANCH"
350 git checkout "$BRANCH"
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100351
352 echo
353 echo "Summary of actions:"
354 echo "- A new remote branch '$BRANCH' was created"
355 echo "- The local branch '$BRANCH' was configured to track the remote branch"
356 echo "- You are now on branch '$BRANCH'"
357 echo
358}
359
360cmd_track() {
Vincent Driessenea608952010-01-29 16:56:29 +0100361 parse_args "$@"
Vincent Driessend0991262010-02-06 21:19:07 +0100362 require_name_arg
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100363
364 # sanity checks
Vincent Driessen7832d6e2010-02-21 21:31:03 +0100365 require_clean_working_tree
366 require_branch_absent "$BRANCH"
Vincent Driessena4dd2232010-02-10 00:34:59 +0100367 git fetch -q "$ORIGIN"
Vincent Driessen7832d6e2010-02-21 21:31:03 +0100368 require_branch "$ORIGIN/$BRANCH"
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100369
370 # create tracking branch
Vincent Driessena4dd2232010-02-10 00:34:59 +0100371 git checkout -b "$BRANCH" "$ORIGIN/$BRANCH"
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100372
373 echo
374 echo "Summary of actions:"
375 echo "- A new remote tracking branch '$BRANCH' was created"
376 echo "- You are now on branch '$BRANCH'"
377 echo
378}
Vincent Driessenbd4f0952010-01-27 13:57:15 +0100379
Vincent Driessenbd4f0952010-01-27 13:57:15 +0100380cmd_diff() {
Vincent Driessen1b819232010-02-01 15:51:43 +0100381 parse_args "$@"
Vincent Driessen1b819232010-02-01 15:51:43 +0100382
Vincent Driessen5474e462010-02-04 15:50:06 +0100383 if [ "$NAME" != "" ]; then
Vincent Driessend0991262010-02-06 21:19:07 +0100384 expand_nameprefix_arg
Vincent Driessena4dd2232010-02-10 00:34:59 +0100385 BASE=$(git merge-base "$DEVELOP_BRANCH" "$BRANCH")
386 git diff "$BASE..$BRANCH"
Vincent Driessen5474e462010-02-04 15:50:06 +0100387 else
Vincent Driessen7832d6e2010-02-21 21:31:03 +0100388 if ! git_current_branch | grep -q "^$PREFIX"; then
Vincent Driessen5474e462010-02-04 15:50:06 +0100389 die "Not on a feature branch. Name one explicitly."
390 fi
391
Vincent Driessena4dd2232010-02-10 00:34:59 +0100392 BASE=$(git merge-base "$DEVELOP_BRANCH" HEAD)
393 git diff "$BASE"
Vincent Driessen5474e462010-02-04 15:50:06 +0100394 fi
Vincent Driessenbd4f0952010-01-27 13:57:15 +0100395}
Vincent Driessenc62633f2010-02-02 10:48:50 +0100396
Vincent Driessend43ab842010-05-27 11:26:01 -0700397cmd_checkout() {
398 parse_args "$@"
399
400 if [ "$NAME" != "" ]; then
401 expand_nameprefix_arg
402 git checkout "$BRANCH"
403 else
404 die "Name a feature branch explicitly."
405 fi
406}
407
Vincent Driessena2baef92010-05-27 11:52:31 -0700408cmd_co() {
409 # Alias for checkout
410 cmd_checkout "$@"
411}
412
Vincent Driessenc62633f2010-02-02 10:48:50 +0100413cmd_rebase() {
Vincent Driessen44174922010-02-02 23:53:21 +0100414 DEFINE_boolean interactive false 'do an interactive rebase' i
Vincent Driessenc62633f2010-02-02 10:48:50 +0100415 parse_args "$@"
Vincent Driessend0991262010-02-06 21:19:07 +0100416 expand_nameprefix_arg_or_current
Vincent Driessenc62633f2010-02-02 10:48:50 +0100417 warn "Will try to rebase '$NAME'..."
Vincent Driessen7832d6e2010-02-21 21:31:03 +0100418 require_clean_working_tree
419 require_branch "$BRANCH"
Vincent Driessenc62633f2010-02-02 10:48:50 +0100420
421 git checkout -q "$BRANCH"
Vincent Driessenf46e2902010-02-15 23:01:52 +0100422 local OPTS=
Vincent Driessen44174922010-02-02 23:53:21 +0100423 if flag interactive; then
Vincent Driessenc62633f2010-02-02 10:48:50 +0100424 OPTS="$OPTS -i"
425 fi
Vincent Driessen010252a2010-02-04 10:31:29 +0100426 git rebase $OPTS "$DEVELOP_BRANCH"
Vincent Driessenc62633f2010-02-02 10:48:50 +0100427}