]>
Commit | Line | Data |
---|---|---|
59e6b23a JH |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2005 Junio C Hamano. | |
4 | # | |
5 | ||
215a7ad1 | 6 | . git-sh-setup || die "Not a git archive." |
4282c4fb | 7 | |
59e6b23a JH |
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 | ||
4282c4fb JH |
13 | case "$#,$1" in |
14 | 1,*..*) | |
15 | upstream=$(expr "$1" : '\(.*\)\.\.') ours=$(expr "$1" : '.*\.\.\(.*\)$') | |
16 | set x "$upstream" "$ours" | |
17 | shift ;; | |
18 | esac | |
59e6b23a | 19 | |
215a7ad1 | 20 | git-update-index --refresh || exit |
99a92f92 | 21 | |
59e6b23a | 22 | case "$#" in |
99a92f92 JH |
23 | 1) ours_symbolic=HEAD ;; |
24 | 2) ours_symbolic="$2" ;; | |
25 | *) die "$usage" ;; | |
59e6b23a JH |
26 | esac |
27 | ||
99a92f92 | 28 | upstream=`git-rev-parse --verify "$1"` && |
66e06b6a | 29 | ours=`git-rev-parse --verify "$ours_symbolic"` || exit |
215a7ad1 JH |
30 | different1=$(git-diff-index --name-only --cached "$ours") && |
31 | different2=$(git-diff-index --name-only "$ours") && | |
a8055f8a | 32 | test "$different1$different2" = "" || |
99a92f92 JH |
33 | die "Your working tree does not match $ours_symbolic." |
34 | ||
4282c4fb | 35 | git-read-tree -m -u $ours $upstream && |
2ad77e67 | 36 | git-rev-parse --verify "$upstream^0" >"$GIT_DIR/HEAD" || exit |
59e6b23a JH |
37 | |
38 | tmp=.rebase-tmp$$ | |
39 | fail=$tmp-fail | |
48313592 | 40 | trap "rm -rf $tmp-*" 1 2 3 15 |
59e6b23a JH |
41 | |
42 | >$fail | |
43 | ||
48313592 JH |
44 | git-cherry -v $upstream $ours | |
45 | while read sign commit msg | |
59e6b23a JH |
46 | do |
47 | case "$sign" in | |
48313592 JH |
48 | -) |
49 | echo >&2 "* Already applied: $msg" | |
50 | continue ;; | |
59e6b23a | 51 | esac |
48313592 | 52 | echo >&2 "* Applying: $msg" |
59e6b23a | 53 | S=`cat "$GIT_DIR/HEAD"` && |
215a7ad1 | 54 | git-cherry-pick --replay $commit || { |
48313592 | 55 | echo >&2 "* Not applying the patch and continuing." |
59e6b23a | 56 | echo $commit >>$fail |
215a7ad1 | 57 | git-reset --hard $S |
59e6b23a JH |
58 | } |
59 | done | |
60 | if test -s $fail | |
61 | then | |
48313592 JH |
62 | echo >&2 Some commits could not be rebased, check by hand: |
63 | cat >&2 $fail | |
64 | echo >&2 "(the same list of commits are found in $tmp)" | |
65 | exit 1 | |
66 | else | |
67 | rm -f $fail | |
59e6b23a | 68 | fi |