3 # Copyright (c) 2005 Junio C Hamano.
6 USAGE
='<upstream> [<head>]'
9 case $# in 1|
2) ;; *) usage
;; esac
11 # Make sure we do not have .dotest
17 It seems that I cannot create a .dotest directory, and I wonder if you
18 are in the middle of patch application or another rebase. If that is not
19 the case, please rm -fr .dotest and run me again. I am stopping in case
20 you still have something valuable there.'
24 # The tree must be really really clean.
25 git-update-index
--refresh ||
exit
26 diff=$
(git-diff-index
--cached --name-status -r HEAD
)
33 # The other head is given. Make sure it is valid.
34 other
=$
(git-rev-parse
--verify "$1^0") || usage
36 # Make sure the branch to rebase is valid.
37 head=$
(git-rev-parse
--verify "${2-HEAD}^0") ||
exit
39 # If a hook exists, give it a chance to interrupt
40 if test -x "$GIT_DIR/hooks/pre-rebase"
42 "$GIT_DIR/hooks/pre-rebase" ${1+"$@"} ||
{
43 echo >&2 "The pre-rebase hook refused to rebase."
48 # If the branch to rebase is given, first switch to it.
51 git-checkout
"$2" || usage
54 mb
=$
(git-merge-base
"$other" "$head")
56 # Check if we are already based on $other.
57 if test "$mb" = "$other"
59 echo >&2 "Current branch `git-symbolic-ref HEAD` is up to date."
63 # Rewind the head to "$other"
64 git-reset
--hard "$other"
66 # If the $other is a proper descendant of the tip of the branch, then
67 # we just fast forwarded.
68 if test "$mb" = "$head"
70 echo >&2 "Fast-forwarded $head to $other."
74 git-format-patch
-k --stdout --full-index "$other" ORIG_HEAD |