[PATCH] When copying or renaming, keep the mode, please
[git.git] / git-rebase-script
1 #!/bin/sh
2 #
3 # Copyright (c) 2005 Junio C Hamano.
4 #
5
6 . git-sh-setup-script || die "Not a git archive."
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
19
20 case "$#" in
21 1) upstream=`git-rev-parse --verify "$1"` &&
22    ours=`git-rev-parse --verify HEAD` || exit
23    ;;
24 2) upstream=`git-rev-parse --verify "$1"` &&
25    ours=`git-rev-parse --verify "$2"` || exit
26    ;;
27 *) echo >&2 "$usage"; exit 1 ;;
28 esac
29
30 git-read-tree -m -u $ours $upstream &&
31 git-rev-parse --verify "$upstream^0" >"$GIT_DIR/HEAD" || exit
32
33 tmp=.rebase-tmp$$
34 fail=$tmp-fail
35 trap "rm -rf $tmp-*" 0 1 2 3 15
36
37 >$fail
38
39 git-cherry $upstream $ours |
40 while read sign commit
41 do
42         case "$sign" in
43         -) continue ;;
44         esac
45         S=`cat "$GIT_DIR/HEAD"` &&
46         GIT_EXTERNAL_DIFF=git-apply-patch-script git-diff-tree -p $commit &&
47         git-commit-script -C "$commit" || {
48                 echo $commit >>$fail
49                 git-read-tree --reset -u $S
50         }
51 done
52 if test -s $fail
53 then
54         echo Some commits could not be rebased, check by hand:
55         cat $fail
56 fi