Clean-up output from "git show-branch" and document it.
[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 git-update-cache --refresh || exit
21
22 case "$#" in
23 1) ours_symbolic=HEAD ;;
24 2) ours_symbolic="$2" ;;
25 *) die "$usage" ;;
26 esac
27
28 upstream=`git-rev-parse --verify "$1"` &&
29 ours=`git-rev-parse --verify "$ours_symbolic"` || exit
30 different1=$(git-diff-cache --name-only --cached "$ours") &&
31 different2=$(git-diff-cache --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 git-rev-parse --verify "$upstream^0" >"$GIT_DIR/HEAD" || exit
37
38 tmp=.rebase-tmp$$
39 fail=$tmp-fail
40 trap "rm -rf $tmp-*" 0 1 2 3 15
41
42 >$fail
43
44 git-cherry $upstream $ours |
45 while read sign commit
46 do
47         case "$sign" in
48         -) continue ;;
49         esac
50         S=`cat "$GIT_DIR/HEAD"` &&
51         GIT_EXTERNAL_DIFF=git-apply-patch-script git-diff-tree -p $commit &&
52         git-commit-script -C "$commit" || {
53                 echo $commit >>$fail
54                 git-read-tree --reset -u $S
55         }
56 done
57 if test -s $fail
58 then
59         echo Some commits could not be rebased, check by hand:
60         cat $fail
61 fi