🌐 AI搜索 & 代理 主页
blob: ebd4df3a0e821ddcfd1eabfcaac17f854e172a85 [file] [log] [blame]
Junio C Hamano59e6b232005-06-25 09:23:431#!/bin/sh
2#
3# Copyright (c) 2005 Junio C Hamano.
4#
5
Johannes Schindelin1b1dce42007-06-25 00:11:146USAGE='[--interactive | -i] [-v] [--onto <newbase>] <upstream> [<branch>]'
sean031321c2006-04-26 14:49:387LONG_USAGE='git-rebase replaces <branch> with a new branch of the
8same name. When the --onto option is provided the new branch starts
9out with a HEAD equal to <newbase>, otherwise it is equal to <upstream>
10It then attempts to create a new commit for each commit from the original
11<branch> that does not exist in the <upstream> branch.
Carl Worth69a60af2006-02-22 01:10:1212
sean031321c2006-04-26 14:49:3813It is possible that a merge failure will prevent this process from being
14completely automatic. You will have to resolve any such merge failure
Seancc120052006-05-14 03:34:0815and run git rebase --continue. Another option is to bypass the commit
16that caused the merge failure with git rebase --skip. To restore the
Johannes Schindelin51ef1da2008-07-21 10:51:0217original <branch> and remove the .git/rebase-apply working files, use the
18command git rebase --abort instead.
Carl Worth69a60af2006-02-22 01:10:1219
sean031321c2006-04-26 14:49:3820Note that if <branch> is not specified on the command line, the
SZEDER Gábor702088a2008-03-10 14:38:3321currently checked out branch is used.
Junio C Hamanoe646c9c2006-02-14 22:42:0522
sean031321c2006-04-26 14:49:3823Example: git-rebase master~1 topic
Junio C Hamanoe646c9c2006-02-14 22:42:0524
sean031321c2006-04-26 14:49:3825 A---B---C topic A'\''--B'\''--C'\'' topic
26 / --> /
27 D---E---F---G master D---E---F---G master
Junio C Hamanoe646c9c2006-02-14 22:42:0528'
Junio C Hamano533b7032007-01-12 20:52:0329
30SUBDIRECTORY_OK=Yes
Junio C Hamano8f321a32007-11-06 09:50:0231OPTIONS_SPEC=
Junio C Hamanoae2b0f12005-11-24 08:12:1132. git-sh-setup
Shawn O. Pearcef9474132006-12-28 07:34:4833set_reflog_action rebase
Shawn O. Pearce7eff28a2006-12-31 04:32:3834require_work_tree
Junio C Hamano533b7032007-01-12 20:52:0335cd_to_toplevel
Junio C Hamano4282c4f2005-08-07 22:51:0936
Nanako Shiraishic4427652008-10-06 05:14:2937OK_TO_SKIP_PRE_REBASE=
Seancc120052006-05-14 03:34:0838RESOLVEMSG="
39When you have resolved this problem run \"git rebase --continue\".
40If you would prefer to skip this patch, instead run \"git rebase --skip\".
41To restore the original branch and stop rebasing run \"git rebase --abort\".
42"
Junio C Hamanoe646c9c2006-02-14 22:42:0543unset newbase
Junio C Hamanoa06f6782006-09-25 02:49:4744strategy=recursive
Eric Wong58634db2006-06-21 10:04:4145do_merge=
Johannes Schindelin28ed6e72008-07-16 01:33:4446dotest="$GIT_DIR"/rebase-merge
Eric Wong58634db2006-06-21 10:04:4147prec=4
Robert Shearmanb7587892006-10-03 16:29:3148verbose=
Michael S. Tsirkin67dad682007-02-08 13:57:0849git_am_opt=
Eric Wong58634db2006-06-21 10:04:4150
51continue_merge () {
52 test -n "$prev_head" || die "prev_head must be defined"
53 test -d "$dotest" || die "$dotest directory does not exist"
54
Junio C Hamano5be60072007-07-03 05:52:1455 unmerged=$(git ls-files -u)
Eric Wong58634db2006-06-21 10:04:4156 if test -n "$unmerged"
57 then
58 echo "You still have unmerged paths in your index"
Jonas Fonseca9b078732007-06-02 17:59:4959 echo "did you forget to use git add?"
Eric Wong66eb64c2006-06-28 09:11:0660 die "$RESOLVEMSG"
Eric Wong58634db2006-06-21 10:04:4161 fi
62
Jonathan del Strother889a50e2007-10-17 09:31:3563 cmt=`cat "$dotest/current"`
Johannes Schindelin6848d582008-05-14 17:03:5964 if ! git diff-index --quiet --ignore-submodules HEAD --
Eric Wong58634db2006-06-21 10:04:4165 then
Junio C Hamanoe6371222008-03-16 07:50:2266 if ! git commit --no-verify -C "$cmt"
Eric Wongf0ef0592006-06-28 10:24:2367 then
68 echo "Commit failed, please do not call \"git commit\""
69 echo "directly, but instead do one of the following: "
70 die "$RESOLVEMSG"
71 fi
Johannes Sixt7afa8452007-09-01 07:25:2772 printf "Committed: %0${prec}d " $msgnum
Eric Wong58634db2006-06-21 10:04:4173 else
Johannes Sixt7afa8452007-09-01 07:25:2774 printf "Already applied: %0${prec}d " $msgnum
Eric Wong58634db2006-06-21 10:04:4175 fi
Junio C Hamanoc7965af2007-09-01 09:17:2876 git rev-list --pretty=oneline -1 "$cmt" | sed -e 's/^[^ ]* //'
Eric Wong58634db2006-06-21 10:04:4177
Junio C Hamano5be60072007-07-03 05:52:1478 prev_head=`git rev-parse HEAD^0`
Eric Wong58634db2006-06-21 10:04:4179 # save the resulting commit so we can read-tree on it later
Eric Wong58634db2006-06-21 10:04:4180 echo "$prev_head" > "$dotest/prev_head"
81
82 # onto the next patch:
83 msgnum=$(($msgnum + 1))
Junio C Hamano5887ac82006-06-22 08:44:5484 echo "$msgnum" >"$dotest/msgnum"
Eric Wong58634db2006-06-21 10:04:4185}
86
87call_merge () {
Jonathan del Strother889a50e2007-10-17 09:31:3588 cmt="$(cat "$dotest/cmt.$1")"
Eric Wong58634db2006-06-21 10:04:4189 echo "$cmt" > "$dotest/current"
Junio C Hamano5be60072007-07-03 05:52:1490 hd=$(git rev-parse --verify HEAD)
Johannes Schindelin6fd2f5e2007-11-08 18:19:0891 cmt_name=$(git symbolic-ref HEAD 2> /dev/null || echo HEAD)
Jonathan del Strother889a50e2007-10-17 09:31:3592 msgnum=$(cat "$dotest/msgnum")
93 end=$(cat "$dotest/end")
Shawn O. Pearce0bb733c2006-12-28 07:34:5694 eval GITHEAD_$cmt='"${cmt_name##refs/heads/}~$(($end - $msgnum))"'
Jonathan del Strother889a50e2007-10-17 09:31:3595 eval GITHEAD_$hd='$(cat "$dotest/onto_name")'
Shawn O. Pearce0bb733c2006-12-28 07:34:5696 export GITHEAD_$cmt GITHEAD_$hd
97 git-merge-$strategy "$cmt^" -- "$hd" "$cmt"
Eric Wong58634db2006-06-21 10:04:4198 rv=$?
99 case "$rv" in
100 0)
Shawn O. Pearce0bb733c2006-12-28 07:34:56101 unset GITHEAD_$cmt GITHEAD_$hd
Eric Wong9e4bc7d2006-06-25 01:29:48102 return
Eric Wong58634db2006-06-21 10:04:41103 ;;
104 1)
Johannes Schindelinb4372ef2007-07-06 12:05:59105 git rerere
Eric Wong66eb64c2006-06-28 09:11:06106 die "$RESOLVEMSG"
Eric Wong58634db2006-06-21 10:04:41107 ;;
108 2)
109 echo "Strategy: $rv $strategy failed, try another" 1>&2
Eric Wong66eb64c2006-06-28 09:11:06110 die "$RESOLVEMSG"
Eric Wong58634db2006-06-21 10:04:41111 ;;
112 *)
113 die "Unknown exit code ($rv) from command:" \
114 "git-merge-$strategy $cmt^ -- HEAD $cmt"
115 ;;
116 esac
117}
118
Johannes Schindelin6fd2f5e2007-11-08 18:19:08119move_to_original_branch () {
120 test -z "$head_name" &&
121 head_name="$(cat "$dotest"/head-name)" &&
122 onto="$(cat "$dotest"/onto)" &&
123 orig_head="$(cat "$dotest"/orig-head)"
124 case "$head_name" in
125 refs/*)
126 message="rebase finished: $head_name onto $onto"
127 git update-ref -m "$message" \
128 $head_name $(git rev-parse HEAD) $orig_head &&
129 git symbolic-ref HEAD $head_name ||
130 die "Could not move back to $head_name"
131 ;;
132 esac
133}
134
Eric Wong58634db2006-06-21 10:04:41135finish_rb_merge () {
Johannes Schindelin6fd2f5e2007-11-08 18:19:08136 move_to_original_branch
Eric Wong58634db2006-06-21 10:04:41137 rm -r "$dotest"
138 echo "All done."
139}
140
Johannes Schindelin1b1dce42007-06-25 00:11:14141is_interactive () {
Andreas Ericssonf8cca012008-09-29 20:28:57142 while test $# != 0
143 do
144 case "$1" in
145 -i|--interactive)
146 interactive_rebase=explicit
147 break
148 ;;
149 -p|--preserve-merges)
150 interactive_rebase=implied
151 ;;
152 esac
Johannes Schindelin1b1dce42007-06-25 00:11:14153 shift
Andreas Ericssonf8cca012008-09-29 20:28:57154 done
155
156 if [ "$interactive_rebase" = implied ]; then
157 GIT_EDITOR=:
158 export GIT_EDITOR
159 fi
160
161 test -n "$interactive_rebase" || test -f "$dotest"/interactive
Johannes Schindelin1b1dce42007-06-25 00:11:14162}
163
Nanako Shiraishid70b4a82008-10-06 05:14:24164run_pre_rebase_hook () {
Nanako Shiraishic4427652008-10-06 05:14:29165 if test -z "$OK_TO_SKIP_PRE_REBASE" &&
166 test -x "$GIT_DIR/hooks/pre-rebase"
Nanako Shiraishid70b4a82008-10-06 05:14:24167 then
168 "$GIT_DIR/hooks/pre-rebase" ${1+"$@"} || {
169 echo >&2 "The pre-rebase hook refused to rebase."
170 exit 1
171 }
172 fi
173}
174
Stephan Beyer9b752a62008-08-17 04:25:43175test -f "$GIT_DIR"/rebase-apply/applying &&
176 die 'It looks like git-am is in progress. Cannot rebase.'
177
Johannes Schindelin1b1dce42007-06-25 00:11:14178is_interactive "$@" && exec git-rebase--interactive "$@"
179
Stephan Beyer9b752a62008-08-17 04:25:43180if test $# -eq 0
181then
182 test -d "$dotest" -o -d "$GIT_DIR"/rebase-apply || usage
183 test -d "$dotest" -o -f "$GIT_DIR"/rebase-apply/rebasing &&
184 die 'A rebase is in progress, try --continue, --skip or --abort.'
185 die "No arguments given and $GIT_DIR/rebase-apply already exists."
186fi
187
David Kastrup822f7c72007-09-23 20:42:08188while test $# != 0
Junio C Hamanoe646c9c2006-02-14 22:42:05189do
190 case "$1" in
Nanako Shiraishic4427652008-10-06 05:14:29191 --no-verify)
192 OK_TO_SKIP_PRE_REBASE=yes
193 ;;
sean031321c2006-04-26 14:49:38194 --continue)
Johannes Schindelin51ef1da2008-07-21 10:51:02195 test -d "$dotest" -o -d "$GIT_DIR"/rebase-apply ||
Stephan Beyercd5320f2008-06-22 14:07:02196 die "No rebase in progress?"
197
Johannes Schindelin6848d582008-05-14 17:03:59198 git diff-files --quiet --ignore-submodules || {
Alex Riesen06aff472007-03-25 00:56:13199 echo "You must edit all merge conflicts and then"
Jonas Fonseca9b078732007-06-02 17:59:49200 echo "mark them as resolved using git add"
sean031321c2006-04-26 14:49:38201 exit 1
Alex Riesen06aff472007-03-25 00:56:13202 }
Eric Wong58634db2006-06-21 10:04:41203 if test -d "$dotest"
204 then
Jonathan del Strother889a50e2007-10-17 09:31:35205 prev_head=$(cat "$dotest/prev_head")
206 end=$(cat "$dotest/end")
207 msgnum=$(cat "$dotest/msgnum")
208 onto=$(cat "$dotest/onto")
Eric Wong58634db2006-06-21 10:04:41209 continue_merge
210 while test "$msgnum" -le "$end"
211 do
212 call_merge "$msgnum"
213 continue_merge
214 done
215 finish_rb_merge
216 exit
217 fi
Johannes Schindelin51ef1da2008-07-21 10:51:02218 head_name=$(cat "$GIT_DIR"/rebase-apply/head-name) &&
219 onto=$(cat "$GIT_DIR"/rebase-apply/onto) &&
220 orig_head=$(cat "$GIT_DIR"/rebase-apply/orig-head) &&
Johannes Schindelin3f735b62007-11-12 13:11:46221 git am --resolved --3way --resolvemsg="$RESOLVEMSG" &&
222 move_to_original_branch
Seancc120052006-05-14 03:34:08223 exit
224 ;;
225 --skip)
Johannes Schindelin51ef1da2008-07-21 10:51:02226 test -d "$dotest" -o -d "$GIT_DIR"/rebase-apply ||
Stephan Beyercd5320f2008-06-22 14:07:02227 die "No rebase in progress?"
228
Mike Hommeyfb6e4e12007-11-08 07:03:06229 git reset --hard HEAD || exit $?
Eric Wong58634db2006-06-21 10:04:41230 if test -d "$dotest"
231 then
Johannes Schindelinb4372ef2007-07-06 12:05:59232 git rerere clear
Jonathan del Strother889a50e2007-10-17 09:31:35233 prev_head=$(cat "$dotest/prev_head")
234 end=$(cat "$dotest/end")
235 msgnum=$(cat "$dotest/msgnum")
Eric Wongd5e673b2006-06-25 01:29:49236 msgnum=$(($msgnum + 1))
Jonathan del Strother889a50e2007-10-17 09:31:35237 onto=$(cat "$dotest/onto")
Eric Wongd5e673b2006-06-25 01:29:49238 while test "$msgnum" -le "$end"
239 do
240 call_merge "$msgnum"
241 continue_merge
242 done
243 finish_rb_merge
244 exit
Eric Wong58634db2006-06-21 10:04:41245 fi
Johannes Schindelin51ef1da2008-07-21 10:51:02246 head_name=$(cat "$GIT_DIR"/rebase-apply/head-name) &&
247 onto=$(cat "$GIT_DIR"/rebase-apply/onto) &&
248 orig_head=$(cat "$GIT_DIR"/rebase-apply/orig-head) &&
Johannes Schindelin6fd2f5e2007-11-08 18:19:08249 git am -3 --skip --resolvemsg="$RESOLVEMSG" &&
250 move_to_original_branch
sean031321c2006-04-26 14:49:38251 exit
252 ;;
253 --abort)
Johannes Schindelin51ef1da2008-07-21 10:51:02254 test -d "$dotest" -o -d "$GIT_DIR"/rebase-apply ||
Stephan Beyercd5320f2008-06-22 14:07:02255 die "No rebase in progress?"
256
Johannes Schindelinb4372ef2007-07-06 12:05:59257 git rerere clear
Eric Wong58634db2006-06-21 10:04:41258 if test -d "$dotest"
259 then
Johannes Schindelin6fd2f5e2007-11-08 18:19:08260 move_to_original_branch
Stephan Beyercd5320f2008-06-22 14:07:02261 else
Johannes Schindelin51ef1da2008-07-21 10:51:02262 dotest="$GIT_DIR"/rebase-apply
Johannes Schindelin6fd2f5e2007-11-08 18:19:08263 move_to_original_branch
Eric Wong58634db2006-06-21 10:04:41264 fi
Bryan Donlan97b88dd2008-05-04 05:37:51265 git reset --hard $(cat "$dotest/orig-head")
Mike Hommey48411d22008-03-01 10:32:14266 rm -r "$dotest"
sean031321c2006-04-26 14:49:38267 exit
268 ;;
Junio C Hamanoe646c9c2006-02-14 22:42:05269 --onto)
270 test 2 -le "$#" || usage
271 newbase="$2"
272 shift
273 ;;
Eric Wong58634db2006-06-21 10:04:41274 -M|-m|--m|--me|--mer|--merg|--merge)
275 do_merge=t
276 ;;
277 -s=*|--s=*|--st=*|--str=*|--stra=*|--strat=*|--strate=*|\
278 --strateg=*|--strategy=*|\
279 -s|--s|--st|--str|--stra|--strat|--strate|--strateg|--strategy)
280 case "$#,$1" in
281 *,*=*)
Dennis Stosberg8096fae2006-06-27 16:54:26282 strategy=`expr "z$1" : 'z-[^=]*=\(.*\)'` ;;
Eric Wong58634db2006-06-21 10:04:41283 1,*)
284 usage ;;
285 *)
286 strategy="$2"
287 shift ;;
288 esac
289 do_merge=t
290 ;;
Robert Shearmanb7587892006-10-03 16:29:31291 -v|--verbose)
292 verbose=t
293 ;;
J. Bruce Fields059f4462007-09-07 14:20:50294 --whitespace=*)
295 git_am_opt="$git_am_opt $1"
296 ;;
Michael S. Tsirkin67dad682007-02-08 13:57:08297 -C*)
J. Bruce Fields059f4462007-09-07 14:20:50298 git_am_opt="$git_am_opt $1"
Michael S. Tsirkin67dad682007-02-08 13:57:08299 ;;
Junio C Hamanoe646c9c2006-02-14 22:42:05300 -*)
301 usage
302 ;;
303 *)
304 break
305 ;;
306 esac
307 shift
308done
Junio C Hamano2db8aae2005-12-14 11:11:37309
Johannes Schindelin51ef1da2008-07-21 10:51:02310# Make sure we do not have $GIT_DIR/rebase-apply
Eric Wong58634db2006-06-21 10:04:41311if test -z "$do_merge"
Junio C Hamano7f4bd5d2005-11-28 21:00:31312then
Stephan Beyer9b752a62008-08-17 04:25:43313 if mkdir "$GIT_DIR"/rebase-apply 2>/dev/null
Eric Wong58634db2006-06-21 10:04:41314 then
Johannes Schindelin51ef1da2008-07-21 10:51:02315 rmdir "$GIT_DIR"/rebase-apply
Eric Wong58634db2006-06-21 10:04:41316 else
317 echo >&2 '
Stephan Beyer9b752a62008-08-17 04:25:43318It seems that I cannot create a rebase-apply directory, and
319I wonder if you are in the middle of patch application or another
Johannes Schindelin51ef1da2008-07-21 10:51:02320rebase. If that is not the case, please
321 rm -fr '"$GIT_DIR"'/rebase-apply
Stephan Beyer9b752a62008-08-17 04:25:43322and run me again. I am stopping in case you still have something
Johannes Schindelin51ef1da2008-07-21 10:51:02323valuable there.'
Eric Wong58634db2006-06-21 10:04:41324 exit 1
325 fi
326else
327 if test -d "$dotest"
328 then
Johannes Schindelin28ed6e72008-07-16 01:33:44329 die "previous rebase directory $dotest still exists." \
Stephan Beyer9b752a62008-08-17 04:25:43330 'Try git rebase (--continue | --abort | --skip)'
Eric Wong58634db2006-06-21 10:04:41331 fi
Junio C Hamano7f4bd5d2005-11-28 21:00:31332fi
333
Junio C Hamano7f59dbb2005-11-14 08:41:53334# The tree must be really really clean.
Jeff King07e62b72008-12-10 09:25:19335if ! git update-index --ignore-submodules --refresh; then
336 echo >&2 "cannot rebase: you have unstaged changes"
337 exit 1
338fi
Johannes Schindelin6848d582008-05-14 17:03:59339diff=$(git diff-index --cached --name-status -r --ignore-submodules HEAD --)
Lukas Sandström32d99542005-12-14 23:36:35340case "$diff" in
Jeff King07e62b72008-12-10 09:25:19341?*) echo >&2 "cannot rebase: your index contains uncommitted changes"
342 echo >&2 "$diff"
Junio C Hamano7f59dbb2005-11-14 08:41:53343 exit 1
344 ;;
Junio C Hamano59e6b232005-06-25 09:23:43345esac
346
Junio C Hamanoe646c9c2006-02-14 22:42:05347# The upstream head must be given. Make sure it is valid.
348upstream_name="$1"
349upstream=`git rev-parse --verify "${upstream_name}^0"` ||
Jason Riedyd0080b32006-02-21 20:56:14350 die "invalid upstream $upstream_name"
Lukas Sandström32d99542005-12-14 23:36:35351
Junio C Hamanoa1bf91e2007-03-22 09:54:59352# Make sure the branch to rebase onto is valid.
353onto_name=${newbase-"$upstream_name"}
Junio C Hamano5be60072007-07-03 05:52:14354onto=$(git rev-parse --verify "${onto_name}^0") || exit
Junio C Hamanoa1bf91e2007-03-22 09:54:59355
Junio C Hamano9a111c92006-02-13 07:17:04356# If a hook exists, give it a chance to interrupt
Nanako Shiraishid70b4a82008-10-06 05:14:24357run_pre_rebase_hook ${1+"$@"}
Junio C Hamano9a111c92006-02-13 07:17:04358
Junio C Hamano0cb06642008-03-15 20:17:42359# If the branch to rebase is given, that is the branch we will rebase
360# $branch_name -- branch being rebased, or HEAD (already detached)
361# $orig_head -- commit object name of tip of the branch before rebasing
362# $head_name -- refs/heads/<that-branch> or "detached HEAD"
363switch_to=
Junio C Hamano7f59dbb2005-11-14 08:41:53364case "$#" in
3652)
Junio C Hamano0cb06642008-03-15 20:17:42366 # Is it "rebase other $branchname" or "rebase other $commit"?
Junio C Hamanoe646c9c2006-02-14 22:42:05367 branch_name="$2"
Junio C Hamano0cb06642008-03-15 20:17:42368 switch_to="$2"
369
370 if git show-ref --verify --quiet -- "refs/heads/$2" &&
Miklos Vajna5a92d192008-12-03 13:26:51371 branch=$(git rev-parse -q --verify "refs/heads/$2")
Junio C Hamanobcf31612007-01-21 03:11:29372 then
Junio C Hamano0cb06642008-03-15 20:17:42373 head_name="refs/heads/$2"
Miklos Vajna5a92d192008-12-03 13:26:51374 elif branch=$(git rev-parse -q --verify "$2")
Junio C Hamano0cb06642008-03-15 20:17:42375 then
376 head_name="detached HEAD"
Junio C Hamanobcf31612007-01-21 03:11:29377 else
Junio C Hamano0cb06642008-03-15 20:17:42378 usage
Junio C Hamanobcf31612007-01-21 03:11:29379 fi
Junio C Hamanoe646c9c2006-02-14 22:42:05380 ;;
Junio C Hamano0cb06642008-03-15 20:17:42381*)
382 # Do not need to switch branches, we are already on it.
383 if branch_name=`git symbolic-ref -q HEAD`
384 then
385 head_name=$branch_name
386 branch_name=`expr "z$branch_name" : 'zrefs/heads/\(.*\)'`
387 else
388 head_name="detached HEAD"
389 branch_name=HEAD ;# detached
390 fi
391 branch=$(git rev-parse --verify "${branch_name}^0") || exit
392 ;;
Junio C Hamano7f59dbb2005-11-14 08:41:53393esac
Junio C Hamano0cb06642008-03-15 20:17:42394orig_head=$branch
Junio C Hamano99a92f92005-08-17 22:19:57395
Junio C Hamanoe646c9c2006-02-14 22:42:05396# Now we are rebasing commits $upstream..$branch on top of $onto
397
Johannes Sixt1308c172007-07-04 20:09:10398# Check if we are already based on $onto with linear history,
399# but this should be done only when upstream and onto are the same.
Junio C Hamano5be60072007-07-03 05:52:14400mb=$(git merge-base "$onto" "$branch")
Johannes Sixt1308c172007-07-04 20:09:10401if test "$upstream" = "$onto" && test "$mb" = "$onto" &&
402 # linear history?
Jeff Kingbbf08122008-05-14 04:01:22403 ! (git rev-list --parents "$onto".."$branch" | grep " .* ") > /dev/null
Junio C Hamano7f4bd5d2005-11-28 21:00:31404then
Junio C Hamano0cb06642008-03-15 20:17:42405 # Lazily switch to the target branch if needed...
406 test -z "$switch_to" || git checkout "$switch_to"
Robert Shearman83c31612006-07-27 09:32:25407 echo >&2 "Current branch $branch_name is up to date."
408 exit 0
Junio C Hamano7f4bd5d2005-11-28 21:00:31409fi
410
Robert Shearmanb7587892006-10-03 16:29:31411if test -n "$verbose"
412then
413 echo "Changes from $mb to $onto:"
James Bowesfefe49d2007-05-05 20:48:54414 # We want color (if set), but no pager
Junio C Hamano5be60072007-07-03 05:52:14415 GIT_PAGER='' git diff --stat --summary "$mb" "$onto"
Robert Shearmanb7587892006-10-03 16:29:31416fi
417
Junio C Hamano0cb06642008-03-15 20:17:42418# Detach HEAD and reset the tree
Junio C Hamano228e2eb2006-12-22 23:21:55419echo "First, rewinding head to replay your work on top of it..."
Junio C Hamano324c2c32008-07-14 21:05:35420git checkout -q "$onto^0" || die "could not detach HEAD"
Junio C Hamano22e40792008-07-07 07:16:38421git update-ref ORIG_HEAD $branch
Lukas Sandström32d99542005-12-14 23:36:35422
Junio C Hamanoe646c9c2006-02-14 22:42:05423# If the $onto is a proper descendant of the tip of the branch, then
Lukas Sandström32d99542005-12-14 23:36:35424# we just fast forwarded.
Robert Shearman83c31612006-07-27 09:32:25425if test "$mb" = "$branch"
Lukas Sandström32d99542005-12-14 23:36:35426then
Robert Shearmand587ed12006-07-27 09:32:46427 echo >&2 "Fast-forwarded $branch_name to $onto_name."
Johannes Schindelin6fd2f5e2007-11-08 18:19:08428 move_to_original_branch
Lukas Sandström32d99542005-12-14 23:36:35429 exit 0
430fi
431
Eric Wong58634db2006-06-21 10:04:41432if test -z "$do_merge"
433then
Junio C Hamano0cb06642008-03-15 20:17:42434 git format-patch -k --stdout --full-index --ignore-if-in-upstream \
435 "$upstream..$orig_head" |
Junio C Hamano3041c322008-03-04 08:25:06436 git am $git_am_opt --rebasing --resolvemsg="$RESOLVEMSG" &&
Johannes Schindelin6fd2f5e2007-11-08 18:19:08437 move_to_original_branch
438 ret=$?
Johannes Schindelin51ef1da2008-07-21 10:51:02439 test 0 != $ret -a -d "$GIT_DIR"/rebase-apply &&
440 echo $head_name > "$GIT_DIR"/rebase-apply/head-name &&
441 echo $onto > "$GIT_DIR"/rebase-apply/onto &&
442 echo $orig_head > "$GIT_DIR"/rebase-apply/orig-head
Johannes Schindelin6fd2f5e2007-11-08 18:19:08443 exit $ret
Eric Wong58634db2006-06-21 10:04:41444fi
Seancc120052006-05-14 03:34:08445
Eric Wong58634db2006-06-21 10:04:41446# start doing a rebase with git-merge
447# this is rename-aware if the recursive (default) strategy is used
448
449mkdir -p "$dotest"
450echo "$onto" > "$dotest/onto"
Shawn O. Pearce0bb733c2006-12-28 07:34:56451echo "$onto_name" > "$dotest/onto_name"
Johannes Schindelin6fd2f5e2007-11-08 18:19:08452prev_head=$orig_head
Eric Wong58634db2006-06-21 10:04:41453echo "$prev_head" > "$dotest/prev_head"
Johannes Schindelin6fd2f5e2007-11-08 18:19:08454echo "$orig_head" > "$dotest/orig-head"
455echo "$head_name" > "$dotest/head-name"
Eric Wong58634db2006-06-21 10:04:41456
457msgnum=0
Junio C Hamano0cb06642008-03-15 20:17:42458for cmt in `git rev-list --reverse --no-merges "$upstream..$orig_head"`
Eric Wong58634db2006-06-21 10:04:41459do
460 msgnum=$(($msgnum + 1))
Junio C Hamano5887ac82006-06-22 08:44:54461 echo "$cmt" > "$dotest/cmt.$msgnum"
Eric Wong58634db2006-06-21 10:04:41462done
463
Junio C Hamano5887ac82006-06-22 08:44:54464echo 1 >"$dotest/msgnum"
465echo $msgnum >"$dotest/end"
Eric Wong58634db2006-06-21 10:04:41466
467end=$msgnum
468msgnum=1
469
470while test "$msgnum" -le "$end"
471do
472 call_merge "$msgnum"
473 continue_merge
474done
475
476finish_rb_merge