]>
Commit | Line | Data |
---|---|---|
59e6b23a JH |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2005 Junio C Hamano. | |
4 | # | |
5 | ||
3ae39ab2 | 6 | USAGE='<upstream> [<head>]' |
ae2b0f15 | 7 | . git-sh-setup |
4282c4fb | 8 | |
7f4bd5d8 JH |
9 | # Make sure we do not have .dotest |
10 | if mkdir .dotest | |
11 | then | |
12 | rmdir .dotest | |
13 | else | |
14 | echo >&2 ' | |
15 | It seems that I cannot create a .dotest directory, and I wonder if you | |
16 | are in the middle of patch application or another rebase. If that is not | |
17 | the case, please rm -fr .dotest and run me again. I am stopping in case | |
18 | you still have something valuable there.' | |
19 | exit 1 | |
20 | fi | |
21 | ||
22 | # The other head is given. Make sure it is valid. | |
3ae39ab2 | 23 | other=$(git-rev-parse --verify "$1^0") || usage |
59e6b23a | 24 | |
7f4bd5d8 JH |
25 | # Make sure we have HEAD that is valid. |
26 | head=$(git-rev-parse --verify "HEAD^0") || exit | |
27 | ||
7f59dbbb | 28 | # The tree must be really really clean. |
215a7ad1 | 29 | git-update-index --refresh || exit |
7f59dbbb JH |
30 | diff=$(git-diff-index --cached --name-status -r HEAD) |
31 | case "$different" in | |
32 | ?*) echo "$diff" | |
33 | exit 1 | |
34 | ;; | |
35 | esac | |
99a92f92 | 36 | |
7f59dbbb | 37 | # If the branch to rebase is given, first switch to it. |
59e6b23a | 38 | case "$#" in |
7f59dbbb | 39 | 2) |
3ae39ab2 | 40 | git-checkout "$2" || usage |
59e6b23a JH |
41 | esac |
42 | ||
7f4bd5d8 JH |
43 | # If the HEAD is a proper descendant of $other, we do not even need |
44 | # to rebase. Make sure we do not do needless rebase. In such a | |
45 | # case, merge-base should be the same as "$other". | |
46 | mb=$(git-merge-base "$other" "$head") | |
47 | if test "$mb" = "$other" | |
48 | then | |
49 | echo >&2 "Current branch `git-symbolic-ref HEAD` is up to date." | |
50 | exit 0 | |
51 | fi | |
52 | ||
7f59dbbb JH |
53 | # Rewind the head to "$other" |
54 | git-reset --hard "$other" | |
55 | git-format-patch -k --stdout --full-index "$other" ORIG_HEAD | | |
56 | git am --binary -3 -k |