|
5 | 5 |
|
6 | 6 | . git-sh-setup || die "Not a git archive." |
7 | 7 |
|
8 | | -usage="usage: $0 "'<upstream> [<head>] |
9 | | -
|
10 | | -Uses output from git-cherry to rebase local commits to the new head of |
11 | | -upstream tree.' |
12 | | - |
13 | | -case "$#,$1" in |
14 | | -1,*..*) |
15 | | - upstream=$(expr "$1" : '\(.*\)\.\.') ours=$(expr "$1" : '.*\.\.\(.*\)$') |
16 | | - set x "$upstream" "$ours" |
17 | | - shift ;; |
18 | | -esac |
| 8 | +# The other head is given |
| 9 | +other=$(git-rev-parse --verify "$1^0") || exit |
19 | 10 |
|
| 11 | +# The tree must be really really clean. |
20 | 12 | git-update-index --refresh || exit |
| 13 | +diff=$(git-diff-index --cached --name-status -r HEAD) |
| 14 | +case "$different" in |
| 15 | +?*) echo "$diff" |
| 16 | + exit 1 |
| 17 | + ;; |
| 18 | +esac |
21 | 19 |
|
| 20 | +# If the branch to rebase is given, first switch to it. |
22 | 21 | case "$#" in |
23 | | -1) ours_symbolic=HEAD ;; |
24 | | -2) ours_symbolic="$2" ;; |
25 | | -*) die "$usage" ;; |
| 22 | +2) |
| 23 | + git-checkout "$2" || exit |
26 | 24 | esac |
27 | 25 |
|
28 | | -upstream=`git-rev-parse --verify "$1"` && |
29 | | -ours=`git-rev-parse --verify "$ours_symbolic"` || exit |
30 | | -different1=$(git-diff-index --name-only --cached "$ours") && |
31 | | -different2=$(git-diff-index --name-only "$ours") && |
32 | | -test "$different1$different2" = "" || |
33 | | -die "Your working tree does not match $ours_symbolic." |
34 | | - |
35 | | -git-read-tree -m -u $ours $upstream && |
36 | | -new_head=$(git-rev-parse --verify "$upstream^0") && |
37 | | -git-update-ref HEAD "$new_head" || exit |
38 | | - |
39 | | -tmp=.rebase-tmp$$ |
40 | | -fail=$tmp-fail |
41 | | -trap "rm -rf $tmp-*" 1 2 3 15 |
42 | | - |
43 | | ->$fail |
44 | | - |
45 | | -git-cherry -v $upstream $ours | |
46 | | -while read sign commit msg |
47 | | -do |
48 | | - case "$sign" in |
49 | | - -) |
50 | | - echo >&2 "* Already applied: $msg" |
51 | | - continue ;; |
52 | | - esac |
53 | | - echo >&2 "* Applying: $msg" |
54 | | - S=$(git-rev-parse --verify HEAD) && |
55 | | - git-cherry-pick --replay $commit || { |
56 | | - echo >&2 "* Not applying the patch and continuing." |
57 | | - echo $commit >>$fail |
58 | | - git-reset --hard $S |
59 | | - } |
60 | | -done |
61 | | -if test -s $fail |
62 | | -then |
63 | | - echo >&2 Some commits could not be rebased, check by hand: |
64 | | - cat >&2 $fail |
65 | | - echo >&2 "(the same list of commits are found in $tmp)" |
66 | | - exit 1 |
67 | | -else |
68 | | - rm -f $fail |
69 | | -fi |
| 26 | +# Rewind the head to "$other" |
| 27 | +git-reset --hard "$other" |
| 28 | +git-format-patch -k --stdout --full-index "$other" ORIG_HEAD | |
| 29 | +git am --binary -3 -k |
0 commit comments