]>
Commit | Line | Data |
---|---|---|
59e6b23a JH |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2005 Junio C Hamano. | |
4 | # | |
5 | ||
bffd750a | 6 | USAGE='[--interactive | -i] [-v] [--force-rebase | -f] [--no-ff] [--onto <newbase>] (<upstream>|--root) [<branch>] [--quiet | -q]' |
031321c6 SE |
7 | LONG_USAGE='git-rebase replaces <branch> with a new branch of the |
8 | same name. When the --onto option is provided the new branch starts | |
9 | out with a HEAD equal to <newbase>, otherwise it is equal to <upstream> | |
10 | It then attempts to create a new commit for each commit from the original | |
11 | <branch> that does not exist in the <upstream> branch. | |
69a60af5 | 12 | |
031321c6 SE |
13 | It is possible that a merge failure will prevent this process from being |
14 | completely automatic. You will have to resolve any such merge failure | |
cc120056 SE |
15 | and run git rebase --continue. Another option is to bypass the commit |
16 | that caused the merge failure with git rebase --skip. To restore the | |
51ef1daa JS |
17 | original <branch> and remove the .git/rebase-apply working files, use the |
18 | command git rebase --abort instead. | |
69a60af5 | 19 | |
031321c6 | 20 | Note that if <branch> is not specified on the command line, the |
702088af | 21 | currently checked out branch is used. |
e646c9c8 | 22 | |
031321c6 | 23 | Example: git-rebase master~1 topic |
e646c9c8 | 24 | |
031321c6 SE |
25 | A---B---C topic A'\''--B'\''--C'\'' topic |
26 | / --> / | |
27 | D---E---F---G master D---E---F---G master | |
e646c9c8 | 28 | ' |
533b7039 JH |
29 | |
30 | SUBDIRECTORY_OK=Yes | |
8f321a39 | 31 | OPTIONS_SPEC= |
ae2b0f15 | 32 | . git-sh-setup |
f9474132 | 33 | set_reflog_action rebase |
7eff28a9 | 34 | require_work_tree |
533b7039 | 35 | cd_to_toplevel |
4282c4fb | 36 | |
61dfa1bb JH |
37 | LF=' |
38 | ' | |
c4427656 | 39 | OK_TO_SKIP_PRE_REBASE= |
cc120056 SE |
40 | RESOLVEMSG=" |
41 | When you have resolved this problem run \"git rebase --continue\". | |
42 | If you would prefer to skip this patch, instead run \"git rebase --skip\". | |
43 | To restore the original branch and stop rebasing run \"git rebase --abort\". | |
44 | " | |
e646c9c8 | 45 | unset newbase |
a06f678e | 46 | strategy=recursive |
93ce190c | 47 | strategy_opts= |
58634dbf | 48 | do_merge= |
69a636ad MZ |
49 | merge_dir="$GIT_DIR"/rebase-merge |
50 | apply_dir="$GIT_DIR"/rebase-apply | |
58634dbf | 51 | prec=4 |
b758789c | 52 | verbose= |
9474a029 MZ |
53 | diffstat= |
54 | test "$(git config --bool rebase.stat)" = true && diffstat=t | |
67dad687 | 55 | git_am_opt= |
190f5323 | 56 | rebase_root= |
b2f82e05 | 57 | force_rebase= |
cb6020bb | 58 | allow_rerere_autoupdate= |
99de0640 MZ |
59 | # Non-empty if a rebase was in progress when 'git rebase' was invoked |
60 | in_progress= | |
61 | # One of {am, merge, interactive} | |
62 | type= | |
63 | # One of {"$GIT_DIR"/rebase-apply, "$GIT_DIR"/rebase-merge} | |
64 | state_dir= | |
34262322 MZ |
65 | # One of {'', continue, skip, abort}, as parsed from command line |
66 | action= | |
58634dbf | 67 | |
02ac45fa | 68 | read_state () { |
99de0640 | 69 | if test "$type" = merge |
02ac45fa | 70 | then |
99de0640 MZ |
71 | onto_name=$(cat "$state_dir"/onto_name) && |
72 | end=$(cat "$state_dir"/end) && | |
73 | msgnum=$(cat "$state_dir"/msgnum) | |
02ac45fa MZ |
74 | fi && |
75 | head_name=$(cat "$state_dir"/head-name) && | |
76 | onto=$(cat "$state_dir"/onto) && | |
77 | orig_head=$(cat "$state_dir"/orig-head) && | |
78 | GIT_QUIET=$(cat "$state_dir"/quiet) | |
79 | } | |
80 | ||
58634dbf | 81 | continue_merge () { |
69a636ad | 82 | test -d "$merge_dir" || die "$merge_dir directory does not exist" |
58634dbf | 83 | |
5be60078 | 84 | unmerged=$(git ls-files -u) |
58634dbf EW |
85 | if test -n "$unmerged" |
86 | then | |
87 | echo "You still have unmerged paths in your index" | |
9b07873a | 88 | echo "did you forget to use git add?" |
66eb64cb | 89 | die "$RESOLVEMSG" |
58634dbf EW |
90 | fi |
91 | ||
69a636ad | 92 | cmt=`cat "$merge_dir/current"` |
6848d58c | 93 | if ! git diff-index --quiet --ignore-submodules HEAD -- |
58634dbf | 94 | then |
e637122e | 95 | if ! git commit --no-verify -C "$cmt" |
f0ef0596 EW |
96 | then |
97 | echo "Commit failed, please do not call \"git commit\"" | |
98 | echo "directly, but instead do one of the following: " | |
99 | die "$RESOLVEMSG" | |
100 | fi | |
0e987a12 SB |
101 | if test -z "$GIT_QUIET" |
102 | then | |
103 | printf "Committed: %0${prec}d " $msgnum | |
104 | fi | |
69a636ad | 105 | echo "$cmt $(git rev-parse HEAD^0)" >> "$merge_dir/rewritten" |
58634dbf | 106 | else |
0e987a12 SB |
107 | if test -z "$GIT_QUIET" |
108 | then | |
109 | printf "Already applied: %0${prec}d " $msgnum | |
110 | fi | |
111 | fi | |
0aa958d4 | 112 | test -z "$GIT_QUIET" && |
31d87385 | 113 | GIT_PAGER='' git log --format=%s -1 "$cmt" |
58634dbf | 114 | |
58634dbf EW |
115 | # onto the next patch: |
116 | msgnum=$(($msgnum + 1)) | |
69a636ad | 117 | echo "$msgnum" >"$merge_dir/msgnum" |
58634dbf EW |
118 | } |
119 | ||
120 | call_merge () { | |
69a636ad MZ |
121 | cmt="$(cat "$merge_dir/cmt.$1")" |
122 | echo "$cmt" > "$merge_dir/current" | |
5be60078 | 123 | hd=$(git rev-parse --verify HEAD) |
6fd2f5e6 | 124 | cmt_name=$(git symbolic-ref HEAD 2> /dev/null || echo HEAD) |
69a636ad | 125 | msgnum=$(cat "$merge_dir/msgnum") |
0bb733c9 | 126 | eval GITHEAD_$cmt='"${cmt_name##refs/heads/}~$(($end - $msgnum))"' |
10ffca7d | 127 | eval GITHEAD_$hd='$onto_name' |
0bb733c9 | 128 | export GITHEAD_$cmt GITHEAD_$hd |
0e987a12 SB |
129 | if test -n "$GIT_QUIET" |
130 | then | |
69ae92bd | 131 | GIT_MERGE_VERBOSITY=1 && export GIT_MERGE_VERBOSITY |
0e987a12 | 132 | fi |
93ce190c | 133 | eval 'git-merge-$strategy' $strategy_opts '"$cmt^" -- "$hd" "$cmt"' |
58634dbf EW |
134 | rv=$? |
135 | case "$rv" in | |
136 | 0) | |
0bb733c9 | 137 | unset GITHEAD_$cmt GITHEAD_$hd |
9e4bc7dd | 138 | return |
58634dbf EW |
139 | ;; |
140 | 1) | |
cb6020bb | 141 | git rerere $allow_rerere_autoupdate |
66eb64cb | 142 | die "$RESOLVEMSG" |
58634dbf EW |
143 | ;; |
144 | 2) | |
145 | echo "Strategy: $rv $strategy failed, try another" 1>&2 | |
66eb64cb | 146 | die "$RESOLVEMSG" |
58634dbf EW |
147 | ;; |
148 | *) | |
149 | die "Unknown exit code ($rv) from command:" \ | |
150 | "git-merge-$strategy $cmt^ -- HEAD $cmt" | |
151 | ;; | |
152 | esac | |
153 | } | |
154 | ||
6fd2f5e6 | 155 | move_to_original_branch () { |
6fd2f5e6 JS |
156 | case "$head_name" in |
157 | refs/*) | |
158 | message="rebase finished: $head_name onto $onto" | |
159 | git update-ref -m "$message" \ | |
160 | $head_name $(git rev-parse HEAD) $orig_head && | |
161 | git symbolic-ref HEAD $head_name || | |
162 | die "Could not move back to $head_name" | |
163 | ;; | |
164 | esac | |
165 | } | |
166 | ||
58634dbf | 167 | finish_rb_merge () { |
6fd2f5e6 | 168 | move_to_original_branch |
69a636ad | 169 | git notes copy --for-rewrite=rebase < "$merge_dir"/rewritten |
96e19488 | 170 | if test -x "$GIT_DIR"/hooks/post-rewrite && |
69a636ad MZ |
171 | test -s "$merge_dir"/rewritten; then |
172 | "$GIT_DIR"/hooks/post-rewrite rebase < "$merge_dir"/rewritten | |
96e19488 | 173 | fi |
69a636ad | 174 | rm -r "$merge_dir" |
0e987a12 | 175 | say All done. |
58634dbf EW |
176 | } |
177 | ||
1b1dce4b | 178 | is_interactive () { |
f8cca019 AE |
179 | while test $# != 0 |
180 | do | |
181 | case "$1" in | |
182 | -i|--interactive) | |
183 | interactive_rebase=explicit | |
184 | break | |
185 | ;; | |
186 | -p|--preserve-merges) | |
187 | interactive_rebase=implied | |
188 | ;; | |
189 | esac | |
1b1dce4b | 190 | shift |
f8cca019 AE |
191 | done |
192 | ||
193 | if [ "$interactive_rebase" = implied ]; then | |
194 | GIT_EDITOR=: | |
195 | export GIT_EDITOR | |
196 | fi | |
197 | ||
69a636ad | 198 | test -n "$interactive_rebase" || test -f "$merge_dir"/interactive |
1b1dce4b JS |
199 | } |
200 | ||
d70b4a8f | 201 | run_pre_rebase_hook () { |
c4427656 NS |
202 | if test -z "$OK_TO_SKIP_PRE_REBASE" && |
203 | test -x "$GIT_DIR/hooks/pre-rebase" | |
d70b4a8f | 204 | then |
bc2bbc45 SB |
205 | "$GIT_DIR/hooks/pre-rebase" ${1+"$@"} || |
206 | die "The pre-rebase hook refused to rebase." | |
d70b4a8f NS |
207 | fi |
208 | } | |
209 | ||
69a636ad | 210 | test -f "$apply_dir"/applying && |
9b752a6e SB |
211 | die 'It looks like git-am is in progress. Cannot rebase.' |
212 | ||
1b1dce4b JS |
213 | is_interactive "$@" && exec git-rebase--interactive "$@" |
214 | ||
99de0640 MZ |
215 | if test -d "$apply_dir" |
216 | then | |
217 | type=am | |
218 | state_dir="$apply_dir" | |
219 | elif test -d "$merge_dir" | |
220 | then | |
221 | if test -f "$merge_dir"/interactive | |
222 | then | |
223 | type=interactive | |
224 | interactive_rebase=explicit | |
225 | else | |
226 | type=merge | |
227 | fi | |
228 | state_dir="$merge_dir" | |
229 | fi | |
230 | test -n "$type" && in_progress=t | |
231 | ||
822f7c73 | 232 | while test $# != 0 |
e646c9c8 JH |
233 | do |
234 | case "$1" in | |
c4427656 NS |
235 | --no-verify) |
236 | OK_TO_SKIP_PRE_REBASE=yes | |
237 | ;; | |
7baf9c4b MZ |
238 | --verify) |
239 | OK_TO_SKIP_PRE_REBASE= | |
240 | ;; | |
34262322 MZ |
241 | --continue|--skip|--abort) |
242 | action=${1##--} | |
243 | shift | |
244 | break | |
031321c6 | 245 | ;; |
e646c9c8 JH |
246 | --onto) |
247 | test 2 -le "$#" || usage | |
248 | newbase="$2" | |
249 | shift | |
250 | ;; | |
58634dbf EW |
251 | -M|-m|--m|--me|--mer|--merg|--merge) |
252 | do_merge=t | |
253 | ;; | |
93ce190c ML |
254 | -X*|--strategy-option*) |
255 | case "$#,$1" in | |
256 | 1,-X|1,--strategy-option) | |
257 | usage ;; | |
258 | *,-X|*,--strategy-option) | |
259 | newopt="$2" | |
260 | shift ;; | |
261 | *,--strategy-option=*) | |
262 | newopt="$(expr " $1" : ' --strategy-option=\(.*\)')" ;; | |
263 | *,-X*) | |
264 | newopt="$(expr " $1" : ' -X\(.*\)')" ;; | |
265 | 1,*) | |
266 | usage ;; | |
267 | esac | |
268 | strategy_opts="$strategy_opts $(git rev-parse --sq-quote "--$newopt")" | |
269 | do_merge=t | |
93ce190c | 270 | ;; |
58634dbf EW |
271 | -s=*|--s=*|--st=*|--str=*|--stra=*|--strat=*|--strate=*|\ |
272 | --strateg=*|--strategy=*|\ | |
273 | -s|--s|--st|--str|--stra|--strat|--strate|--strateg|--strategy) | |
274 | case "$#,$1" in | |
275 | *,*=*) | |
8096fae7 | 276 | strategy=`expr "z$1" : 'z-[^=]*=\(.*\)'` ;; |
58634dbf EW |
277 | 1,*) |
278 | usage ;; | |
279 | *) | |
280 | strategy="$2" | |
281 | shift ;; | |
282 | esac | |
283 | do_merge=t | |
284 | ;; | |
a9c3821c TAV |
285 | -n|--no-stat) |
286 | diffstat= | |
287 | ;; | |
288 | --stat) | |
289 | diffstat=t | |
290 | ;; | |
b758789c RS |
291 | -v|--verbose) |
292 | verbose=t | |
a9c3821c | 293 | diffstat=t |
0e987a12 SB |
294 | GIT_QUIET= |
295 | ;; | |
296 | -q|--quiet) | |
297 | GIT_QUIET=t | |
298 | git_am_opt="$git_am_opt -q" | |
299 | verbose= | |
300 | diffstat= | |
b758789c | 301 | ;; |
059f446d BF |
302 | --whitespace=*) |
303 | git_am_opt="$git_am_opt $1" | |
b2f82e05 SR |
304 | case "$1" in |
305 | --whitespace=fix|--whitespace=strip) | |
306 | force_rebase=t | |
307 | ;; | |
308 | esac | |
059f446d | 309 | ;; |
86c91f91 GB |
310 | --ignore-whitespace) |
311 | git_am_opt="$git_am_opt $1" | |
312 | ;; | |
570ccad3 MB |
313 | --committer-date-is-author-date|--ignore-date) |
314 | git_am_opt="$git_am_opt $1" | |
315 | force_rebase=t | |
316 | ;; | |
67dad687 | 317 | -C*) |
059f446d | 318 | git_am_opt="$git_am_opt $1" |
67dad687 | 319 | ;; |
190f5323 TR |
320 | --root) |
321 | rebase_root=t | |
322 | ;; | |
1bc6bf6d | 323 | -f|--f|--fo|--for|--forc|--force|--force-r|--force-re|--force-reb|--force-reba|--force-rebas|--force-rebase|--no-ff) |
b2f82e05 SR |
324 | force_rebase=t |
325 | ;; | |
cb6020bb JH |
326 | --rerere-autoupdate|--no-rerere-autoupdate) |
327 | allow_rerere_autoupdate="$1" | |
328 | ;; | |
e646c9c8 JH |
329 | -*) |
330 | usage | |
331 | ;; | |
332 | *) | |
333 | break | |
334 | ;; | |
335 | esac | |
336 | shift | |
337 | done | |
51b2ead0 | 338 | test $# -gt 2 && usage |
2db8aaec | 339 | |
34262322 MZ |
340 | test -n "$action" && test -z "$in_progress" && die "No rebase in progress?" |
341 | ||
342 | case "$action" in | |
343 | continue) | |
344 | git update-index --ignore-submodules --refresh && | |
345 | git diff-files --quiet --ignore-submodules || { | |
346 | echo "You must edit all merge conflicts and then" | |
347 | echo "mark them as resolved using git add" | |
348 | exit 1 | |
349 | } | |
350 | read_state | |
351 | if test -d "$merge_dir" | |
352 | then | |
353 | continue_merge | |
354 | while test "$msgnum" -le "$end" | |
355 | do | |
356 | call_merge "$msgnum" | |
357 | continue_merge | |
358 | done | |
359 | finish_rb_merge | |
360 | exit | |
361 | fi | |
362 | git am --resolved --3way --resolvemsg="$RESOLVEMSG" && | |
363 | move_to_original_branch | |
364 | exit | |
365 | ;; | |
366 | skip) | |
367 | git reset --hard HEAD || exit $? | |
368 | read_state | |
369 | if test -d "$merge_dir" | |
370 | then | |
371 | git rerere clear | |
372 | msgnum=$(($msgnum + 1)) | |
373 | while test "$msgnum" -le "$end" | |
374 | do | |
375 | call_merge "$msgnum" | |
376 | continue_merge | |
377 | done | |
378 | finish_rb_merge | |
379 | exit | |
380 | fi | |
381 | git am -3 --skip --resolvemsg="$RESOLVEMSG" && | |
382 | move_to_original_branch | |
383 | exit | |
384 | ;; | |
385 | abort) | |
386 | git rerere clear | |
387 | read_state | |
388 | case "$head_name" in | |
389 | refs/*) | |
390 | git symbolic-ref HEAD $head_name || | |
391 | die "Could not move back to $head_name" | |
392 | ;; | |
393 | esac | |
394 | git reset --hard $orig_head | |
395 | rm -r "$state_dir" | |
396 | exit | |
397 | ;; | |
398 | esac | |
399 | ||
99de0640 MZ |
400 | # Make sure no rebase is in progress |
401 | if test -n "$in_progress" | |
7f4bd5d8 | 402 | then |
99de0640 MZ |
403 | die ' |
404 | It seems that there is already a '"${state_dir##*/}"' directory, and | |
405 | I wonder if you are in the middle of another rebase. If that is the | |
406 | case, please try | |
407 | git rebase (--continue | --abort | --skip) | |
408 | If that is not the case, please | |
409 | rm -fr '"$state_dir"' | |
9b752a6e | 410 | and run me again. I am stopping in case you still have something |
51ef1daa | 411 | valuable there.' |
7f4bd5d8 JH |
412 | fi |
413 | ||
99de0640 MZ |
414 | test $# -eq 0 && test -z "$rebase_root" && usage |
415 | ||
92c62a3f | 416 | require_clean_work_tree "rebase" "Please commit or stash them." |
99a92f92 | 417 | |
190f5323 TR |
418 | if test -z "$rebase_root" |
419 | then | |
420 | # The upstream head must be given. Make sure it is valid. | |
421 | upstream_name="$1" | |
422 | shift | |
423 | upstream=`git rev-parse --verify "${upstream_name}^0"` || | |
424 | die "invalid upstream $upstream_name" | |
425 | unset root_flag | |
426 | upstream_arg="$upstream_name" | |
427 | else | |
428 | test -z "$newbase" && die "--root must be used with --onto" | |
429 | unset upstream_name | |
430 | unset upstream | |
431 | root_flag="--root" | |
432 | upstream_arg="$root_flag" | |
433 | fi | |
32d99544 | 434 | |
a1bf91e0 JH |
435 | # Make sure the branch to rebase onto is valid. |
436 | onto_name=${newbase-"$upstream_name"} | |
9f21e97d NS |
437 | case "$onto_name" in |
438 | *...*) | |
439 | if left=${onto_name%...*} right=${onto_name#*...} && | |
440 | onto=$(git merge-base --all ${left:-HEAD} ${right:-HEAD}) | |
441 | then | |
442 | case "$onto" in | |
443 | ?*"$LF"?*) | |
444 | die "$onto_name: there are more than one merge bases" | |
445 | ;; | |
446 | '') | |
447 | die "$onto_name: there is no merge base" | |
448 | ;; | |
449 | esac | |
450 | else | |
61dfa1bb | 451 | die "$onto_name: there is no merge base" |
9f21e97d NS |
452 | fi |
453 | ;; | |
454 | *) | |
61dfa1bb | 455 | onto=$(git rev-parse --verify "${onto_name}^0") || exit |
9f21e97d NS |
456 | ;; |
457 | esac | |
a1bf91e0 | 458 | |
9a111c91 | 459 | # If a hook exists, give it a chance to interrupt |
190f5323 | 460 | run_pre_rebase_hook "$upstream_arg" "$@" |
9a111c91 | 461 | |
0cb06644 JH |
462 | # If the branch to rebase is given, that is the branch we will rebase |
463 | # $branch_name -- branch being rebased, or HEAD (already detached) | |
464 | # $orig_head -- commit object name of tip of the branch before rebasing | |
465 | # $head_name -- refs/heads/<that-branch> or "detached HEAD" | |
466 | switch_to= | |
59e6b23a | 467 | case "$#" in |
190f5323 | 468 | 1) |
0cb06644 | 469 | # Is it "rebase other $branchname" or "rebase other $commit"? |
190f5323 TR |
470 | branch_name="$1" |
471 | switch_to="$1" | |
0cb06644 | 472 | |
190f5323 TR |
473 | if git show-ref --verify --quiet -- "refs/heads/$1" && |
474 | branch=$(git rev-parse -q --verify "refs/heads/$1") | |
0cb06644 | 475 | then |
190f5323 TR |
476 | head_name="refs/heads/$1" |
477 | elif branch=$(git rev-parse -q --verify "$1") | |
0cb06644 JH |
478 | then |
479 | head_name="detached HEAD" | |
480 | else | |
4ac5356c | 481 | echo >&2 "fatal: no such branch: $1" |
0cb06644 JH |
482 | usage |
483 | fi | |
e646c9c8 JH |
484 | ;; |
485 | *) | |
0cb06644 | 486 | # Do not need to switch branches, we are already on it. |
bcf31618 JH |
487 | if branch_name=`git symbolic-ref -q HEAD` |
488 | then | |
0cb06644 | 489 | head_name=$branch_name |
bcf31618 JH |
490 | branch_name=`expr "z$branch_name" : 'zrefs/heads/\(.*\)'` |
491 | else | |
0cb06644 | 492 | head_name="detached HEAD" |
bcf31618 JH |
493 | branch_name=HEAD ;# detached |
494 | fi | |
0cb06644 | 495 | branch=$(git rev-parse --verify "${branch_name}^0") || exit |
e646c9c8 | 496 | ;; |
59e6b23a | 497 | esac |
0cb06644 | 498 | orig_head=$branch |
59e6b23a | 499 | |
190f5323 TR |
500 | # Now we are rebasing commits $upstream..$branch (or with --root, |
501 | # everything leading up to $branch) on top of $onto | |
e646c9c8 | 502 | |
1308c17b JS |
503 | # Check if we are already based on $onto with linear history, |
504 | # but this should be done only when upstream and onto are the same. | |
5be60078 | 505 | mb=$(git merge-base "$onto" "$branch") |
1308c17b JS |
506 | if test "$upstream" = "$onto" && test "$mb" = "$onto" && |
507 | # linear history? | |
e1622bfc | 508 | ! (git rev-list --parents "$onto".."$branch" | sane_grep " .* ") > /dev/null |
7f4bd5d8 | 509 | then |
b2f82e05 SR |
510 | if test -z "$force_rebase" |
511 | then | |
512 | # Lazily switch to the target branch if needed... | |
3b21a438 | 513 | test -z "$switch_to" || git checkout "$switch_to" -- |
0e987a12 | 514 | say "Current branch $branch_name is up to date." |
b2f82e05 SR |
515 | exit 0 |
516 | else | |
0e987a12 | 517 | say "Current branch $branch_name is up to date, rebase forced." |
b2f82e05 | 518 | fi |
7f4bd5d8 JH |
519 | fi |
520 | ||
0cb06644 | 521 | # Detach HEAD and reset the tree |
0e987a12 | 522 | say "First, rewinding head to replay your work on top of it..." |
324c2c31 | 523 | git checkout -q "$onto^0" || die "could not detach HEAD" |
22e40795 | 524 | git update-ref ORIG_HEAD $branch |
32d99544 | 525 | |
a9c3821c TAV |
526 | if test -n "$diffstat" |
527 | then | |
528 | if test -n "$verbose" | |
529 | then | |
530 | echo "Changes from $mb to $onto:" | |
531 | fi | |
532 | # We want color (if set), but no pager | |
533 | GIT_PAGER='' git diff --stat --summary "$mb" "$onto" | |
534 | fi | |
535 | ||
e646c9c8 | 536 | # If the $onto is a proper descendant of the tip of the branch, then |
a75d7b54 | 537 | # we just fast-forwarded. |
83c31614 | 538 | if test "$mb" = "$branch" |
32d99544 | 539 | then |
0e987a12 | 540 | say "Fast-forwarded $branch_name to $onto_name." |
6fd2f5e6 | 541 | move_to_original_branch |
32d99544 LS |
542 | exit 0 |
543 | fi | |
544 | ||
190f5323 TR |
545 | if test -n "$rebase_root" |
546 | then | |
547 | revisions="$onto..$orig_head" | |
548 | else | |
549 | revisions="$upstream..$orig_head" | |
550 | fi | |
551 | ||
58634dbf EW |
552 | if test -z "$do_merge" |
553 | then | |
0cb06644 | 554 | git format-patch -k --stdout --full-index --ignore-if-in-upstream \ |
5b220a68 | 555 | --src-prefix=a/ --dst-prefix=b/ \ |
840b3ca7 | 556 | --no-renames $root_flag "$revisions" | |
3041c324 | 557 | git am $git_am_opt --rebasing --resolvemsg="$RESOLVEMSG" && |
6fd2f5e6 JS |
558 | move_to_original_branch |
559 | ret=$? | |
69a636ad MZ |
560 | test 0 != $ret -a -d "$apply_dir" && |
561 | echo $head_name > "$apply_dir/head-name" && | |
562 | echo $onto > "$apply_dir/onto" && | |
563 | echo $orig_head > "$apply_dir/orig-head" && | |
564 | echo "$GIT_QUIET" > "$apply_dir/quiet" | |
6fd2f5e6 | 565 | exit $ret |
58634dbf EW |
566 | fi |
567 | ||
568 | # start doing a rebase with git-merge | |
569 | # this is rename-aware if the recursive (default) strategy is used | |
570 | ||
69a636ad | 571 | mkdir -p "$merge_dir" |
69a636ad | 572 | echo "$onto_name" > "$merge_dir/onto_name" |
69a636ad | 573 | echo "$head_name" > "$merge_dir/head-name" |
02ac45fa MZ |
574 | echo "$onto" > "$merge_dir/onto" |
575 | echo "$orig_head" > "$merge_dir/orig-head" | |
69a636ad | 576 | echo "$GIT_QUIET" > "$merge_dir/quiet" |
58634dbf EW |
577 | |
578 | msgnum=0 | |
190f5323 | 579 | for cmt in `git rev-list --reverse --no-merges "$revisions"` |
58634dbf EW |
580 | do |
581 | msgnum=$(($msgnum + 1)) | |
69a636ad | 582 | echo "$cmt" > "$merge_dir/cmt.$msgnum" |
58634dbf EW |
583 | done |
584 | ||
69a636ad MZ |
585 | echo 1 >"$merge_dir/msgnum" |
586 | echo $msgnum >"$merge_dir/end" | |
58634dbf EW |
587 | |
588 | end=$msgnum | |
589 | msgnum=1 | |
590 | ||
591 | while test "$msgnum" -le "$end" | |
592 | do | |
593 | call_merge "$msgnum" | |
594 | continue_merge | |
595 | done | |
cc120056 | 596 | |
58634dbf | 597 | finish_rb_merge |