perl: move the perl/Git/FromCPAN tree to perl/FromCPAN
[git.git] / git-rebase--merge.sh
blob1831e589b8c94b3fbcee710c5742b71a3e7e8f9e
1 # This shell script fragment is sourced by git-rebase to implement
2 # its merge-based non-interactive mode that copes well with renamed
3 # files.
5 # Copyright (c) 2010 Junio C Hamano.
8 prec=4
10 read_state () {
11 onto_name=$(cat "$state_dir"/onto_name) &&
12 end=$(cat "$state_dir"/end) &&
13 msgnum=$(cat "$state_dir"/msgnum)
16 continue_merge () {
17 test -d "$state_dir" || die "$state_dir directory does not exist"
19 unmerged=$(git ls-files -u)
20 if test -n "$unmerged"
21 then
22 echo "You still have unmerged paths in your index"
23 echo "did you forget to use git add?"
24 die "$resolvemsg"
27 cmt=$(cat "$state_dir/current")
28 if ! git diff-index --quiet --ignore-submodules HEAD --
29 then
30 if ! git commit ${gpg_sign_opt:+"$gpg_sign_opt"} $allow_empty_message \
31 --no-verify -C "$cmt"
32 then
33 echo "Commit failed, please do not call \"git commit\""
34 echo "directly, but instead do one of the following: "
35 die "$resolvemsg"
37 if test -z "$GIT_QUIET"
38 then
39 printf "Committed: %0${prec}d " $msgnum
41 echo "$cmt $(git rev-parse HEAD^0)" >> "$state_dir/rewritten"
42 else
43 if test -z "$GIT_QUIET"
44 then
45 printf "Already applied: %0${prec}d " $msgnum
48 test -z "$GIT_QUIET" &&
49 GIT_PAGER='' git log --format=%s -1 "$cmt"
51 # onto the next patch:
52 msgnum=$(($msgnum + 1))
53 echo "$msgnum" >"$state_dir/msgnum"
56 call_merge () {
57 msgnum="$1"
58 echo "$msgnum" >"$state_dir/msgnum"
59 cmt="$(cat "$state_dir/cmt.$msgnum")"
60 echo "$cmt" > "$state_dir/current"
61 hd=$(git rev-parse --verify HEAD)
62 cmt_name=$(git symbolic-ref HEAD 2> /dev/null || echo HEAD)
63 eval GITHEAD_$cmt='"${cmt_name##refs/heads/}~$(($end - $msgnum))"'
64 eval GITHEAD_$hd='$onto_name'
65 export GITHEAD_$cmt GITHEAD_$hd
66 if test -n "$GIT_QUIET"
67 then
68 GIT_MERGE_VERBOSITY=1 && export GIT_MERGE_VERBOSITY
70 test -z "$strategy" && strategy=recursive
71 # If cmt doesn't have a parent, don't include it as a base
72 base=$(git rev-parse --verify --quiet $cmt^)
73 eval 'git-merge-$strategy' $strategy_opts $base ' -- "$hd" "$cmt"'
74 rv=$?
75 case "$rv" in
77 unset GITHEAD_$cmt GITHEAD_$hd
78 return
81 git rerere $allow_rerere_autoupdate
82 die "$resolvemsg"
85 echo "Strategy: $strategy failed, try another" 1>&2
86 die "$resolvemsg"
89 die "Unknown exit code ($rv) from command:" \
90 "git-merge-$strategy $cmt^ -- HEAD $cmt"
92 esac
95 finish_rb_merge () {
96 move_to_original_branch
97 if test -s "$state_dir"/rewritten
98 then
99 git notes copy --for-rewrite=rebase <"$state_dir"/rewritten
100 hook="$(git rev-parse --git-path hooks/post-rewrite)"
101 test -x "$hook" && "$hook" rebase <"$state_dir"/rewritten
103 say All done.
106 # The whole contents of this file is run by dot-sourcing it from
107 # inside a shell function. It used to be that "return"s we see
108 # below were not inside any function, and expected to return
109 # to the function that dot-sourced us.
111 # However, older (9.x) versions of FreeBSD /bin/sh misbehave on such a
112 # construct and continue to run the statements that follow such a "return".
113 # As a work-around, we introduce an extra layer of a function
114 # here, and immediately call it after defining it.
115 git_rebase__merge () {
117 case "$action" in
118 continue)
119 read_state
120 continue_merge
121 while test "$msgnum" -le "$end"
123 call_merge "$msgnum"
124 continue_merge
125 done
126 finish_rb_merge
127 return
129 skip)
130 read_state
131 git rerere clear
132 msgnum=$(($msgnum + 1))
133 while test "$msgnum" -le "$end"
135 call_merge "$msgnum"
136 continue_merge
137 done
138 finish_rb_merge
139 return
141 esac
143 mkdir -p "$state_dir"
144 echo "$onto_name" > "$state_dir/onto_name"
145 write_basic_state
147 msgnum=0
148 for cmt in $(git rev-list --reverse --no-merges "$revisions")
150 msgnum=$(($msgnum + 1))
151 echo "$cmt" > "$state_dir/cmt.$msgnum"
152 done
154 echo 1 >"$state_dir/msgnum"
155 echo $msgnum >"$state_dir/end"
157 end=$msgnum
158 msgnum=1
160 while test "$msgnum" -le "$end"
162 call_merge "$msgnum"
163 continue_merge
164 done
166 finish_rb_merge
169 # ... and then we call the whole thing.
170 git_rebase__merge