]>
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 | |
2db8aaec JH |
9 | case $# in 1|2) ;; *) usage ;; esac |
10 | ||
7f4bd5d8 JH |
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 | |
22 | fi | |
23 | ||
7f59dbbb | 24 | # The tree must be really really clean. |
215a7ad1 | 25 | git-update-index --refresh || exit |
7f59dbbb | 26 | diff=$(git-diff-index --cached --name-status -r HEAD) |
32d99544 | 27 | case "$diff" in |
7f59dbbb JH |
28 | ?*) echo "$diff" |
29 | exit 1 | |
30 | ;; | |
31 | esac | |
99a92f92 | 32 | |
32d99544 LS |
33 | # The other head is given. Make sure it is valid. |
34 | other=$(git-rev-parse --verify "$1^0") || usage | |
35 | ||
36 | # Make sure the branch to rebase is valid. | |
37 | head=$(git-rev-parse --verify "${2-HEAD}^0") || exit | |
38 | ||
7f59dbbb | 39 | # If the branch to rebase is given, first switch to it. |
59e6b23a | 40 | case "$#" in |
7f59dbbb | 41 | 2) |
3ae39ab2 | 42 | git-checkout "$2" || usage |
59e6b23a JH |
43 | esac |
44 | ||
7f4bd5d8 | 45 | mb=$(git-merge-base "$other" "$head") |
32d99544 LS |
46 | |
47 | # Check if we are already based on $other. | |
7f4bd5d8 JH |
48 | if test "$mb" = "$other" |
49 | then | |
50 | echo >&2 "Current branch `git-symbolic-ref HEAD` is up to date." | |
51 | exit 0 | |
52 | fi | |
53 | ||
7f59dbbb JH |
54 | # Rewind the head to "$other" |
55 | git-reset --hard "$other" | |
32d99544 LS |
56 | |
57 | # If the $other is a proper descendant of the tip of the branch, then | |
58 | # we just fast forwarded. | |
59 | if test "$mb" = "$head" | |
60 | then | |
61 | echo >&2 "Fast-forwarded $head to $other." | |
62 | exit 0 | |
63 | fi | |
64 | ||
7f59dbbb JH |
65 | git-format-patch -k --stdout --full-index "$other" ORIG_HEAD | |
66 | git am --binary -3 -k |