mailinfo and git-am: allow "John Doe <johndoe>"
[git/fastimport.git] / git-rebase.sh
blobc1619ff1400f68300d5026a00baf72e27f268ba1
1 #!/bin/sh
3 # Copyright (c) 2005 Junio C Hamano.
6 USAGE='<upstream> [<head>]'
7 . git-sh-setup
9 case $# in 1|2) ;; *) usage ;; esac
11 # Make sure we do not have .dotest
12 if mkdir .dotest
13 then
14 rmdir .dotest
15 else
16 echo >&2 '
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.'
21 exit 1
24 # The other head is given. Make sure it is valid.
25 other=$(git-rev-parse --verify "$1^0") || usage
27 # Make sure we have HEAD that is valid.
28 head=$(git-rev-parse --verify "HEAD^0") || exit
30 # The tree must be really really clean.
31 git-update-index --refresh || exit
32 diff=$(git-diff-index --cached --name-status -r HEAD)
33 case "$different" in
34 ?*) echo "$diff"
35 exit 1
37 esac
39 # If the branch to rebase is given, first switch to it.
40 case "$#" in
42 head=$(git-rev-parse --verify "$2^") || usage
43 git-checkout "$2" || usage
44 esac
46 # If the HEAD is a proper descendant of $other, we do not even need
47 # to rebase. Make sure we do not do needless rebase. In such a
48 # case, merge-base should be the same as "$other".
49 mb=$(git-merge-base "$other" "$head")
50 if test "$mb" = "$other"
51 then
52 echo >&2 "Current branch `git-symbolic-ref HEAD` is up to date."
53 exit 0
56 # Rewind the head to "$other"
57 git-reset --hard "$other"
58 git-format-patch -k --stdout --full-index "$other" ORIG_HEAD |
59 git am --binary -3 -k