1#!/bin/sh
2#
3# Copyright (c) 2005 Junio C Hamano.
4#
5
6. git-sh-setup-script || die "Not a git archive."
7
8usage="usage: $0 "'<upstream> [<head>]
9
10Uses output from git-cherry to rebase local commits to the new head of
11upstream tree.'
12
13case "$#,$1" in
141,*..*)
15 upstream=$(expr "$1" : '\(.*\)\.\.') ours=$(expr "$1" : '.*\.\.\(.*\)$')
16 set x "$upstream" "$ours"
17 shift ;;
18esac
19
20git-update-cache --refresh || exit
21
22case "$#" in
231) ours_symbolic=HEAD ;;
242) ours_symbolic="$2" ;;
25*) die "$usage" ;;
26esac
27
28upstream=`git-rev-parse --verify "$1"` &&
29ours=`git-rev-parse --verify "$ours_symbolic^` || exit
30test "$(git-diff-cache --cached "$ours")" = "" ||
31die "Your working tree does not match $ours_symbolic."
32
33git-read-tree -m -u $ours $upstream &&
34git-rev-parse --verify "$upstream^0" >"$GIT_DIR/HEAD" || exit
35
36tmp=.rebase-tmp$$
37fail=$tmp-fail
38trap "rm -rf $tmp-*" 0 1 2 3 15
39
40>$fail
41
42git-cherry $upstream $ours |
43while read sign commit
44do
45 case "$sign" in
46 -) continue ;;
47 esac
48 S=`cat "$GIT_DIR/HEAD"` &&
49 GIT_EXTERNAL_DIFF=git-apply-patch-script git-diff-tree -p $commit &&
50 git-commit-script -C "$commit" || {
51 echo $commit >>$fail
52 git-read-tree --reset -u $S
53 }
54done
55if test -s $fail
56then
57 echo Some commits could not be rebased, check by hand:
58 cat $fail
59fi