]>
Commit | Line | Data |
---|---|---|
11d62145 JN |
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. | |
fa99c1e1 MZ |
4 | # |
5 | # Copyright (c) 2010 Junio C Hamano. | |
6 | # | |
7 | ||
fa99c1e1 MZ |
8 | prec=4 |
9 | ||
10 | read_state () { | |
11 | onto_name=$(cat "$state_dir"/onto_name) && | |
12 | end=$(cat "$state_dir"/end) && | |
13 | msgnum=$(cat "$state_dir"/msgnum) | |
14 | } | |
15 | ||
16 | continue_merge () { | |
17 | test -d "$state_dir" || die "$state_dir directory does not exist" | |
18 | ||
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" | |
25 | fi | |
26 | ||
f257482c | 27 | cmt=$(cat "$state_dir/current") |
fa99c1e1 MZ |
28 | if ! git diff-index --quiet --ignore-submodules HEAD -- |
29 | then | |
850e9257 | 30 | if ! git commit ${gpg_sign_opt:+"$gpg_sign_opt"} $signoff $allow_empty_message \ |
a6c612b5 | 31 | --no-verify -C "$cmt" |
fa99c1e1 MZ |
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" | |
36 | fi | |
37 | if test -z "$GIT_QUIET" | |
38 | then | |
39 | printf "Committed: %0${prec}d " $msgnum | |
40 | fi | |
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 | |
46 | fi | |
47 | fi | |
48 | test -z "$GIT_QUIET" && | |
49 | GIT_PAGER='' git log --format=%s -1 "$cmt" | |
50 | ||
51 | # onto the next patch: | |
52 | msgnum=$(($msgnum + 1)) | |
53 | echo "$msgnum" >"$state_dir/msgnum" | |
54 | } | |
55 | ||
56 | call_merge () { | |
95104c7e | 57 | msgnum="$1" |
58 | echo "$msgnum" >"$state_dir/msgnum" | |
59 | cmt="$(cat "$state_dir/cmt.$msgnum")" | |
fa99c1e1 | 60 | echo "$cmt" > "$state_dir/current" |
fbd7a232 | 61 | git update-ref REBASE_HEAD "$cmt" |
fa99c1e1 MZ |
62 | hd=$(git rev-parse --verify HEAD) |
63 | cmt_name=$(git symbolic-ref HEAD 2> /dev/null || echo HEAD) | |
fa99c1e1 MZ |
64 | eval GITHEAD_$cmt='"${cmt_name##refs/heads/}~$(($end - $msgnum))"' |
65 | eval GITHEAD_$hd='$onto_name' | |
66 | export GITHEAD_$cmt GITHEAD_$hd | |
67 | if test -n "$GIT_QUIET" | |
68 | then | |
69 | GIT_MERGE_VERBOSITY=1 && export GIT_MERGE_VERBOSITY | |
70 | fi | |
71 | test -z "$strategy" && strategy=recursive | |
79f43447 BW |
72 | # If cmt doesn't have a parent, don't include it as a base |
73 | base=$(git rev-parse --verify --quiet $cmt^) | |
74 | eval 'git-merge-$strategy' $strategy_opts $base ' -- "$hd" "$cmt"' | |
fa99c1e1 MZ |
75 | rv=$? |
76 | case "$rv" in | |
77 | 0) | |
78 | unset GITHEAD_$cmt GITHEAD_$hd | |
79 | return | |
80 | ;; | |
81 | 1) | |
82 | git rerere $allow_rerere_autoupdate | |
83 | die "$resolvemsg" | |
84 | ;; | |
85 | 2) | |
b3256809 | 86 | echo "Strategy: $strategy failed, try another" 1>&2 |
fa99c1e1 MZ |
87 | die "$resolvemsg" |
88 | ;; | |
89 | *) | |
90 | die "Unknown exit code ($rv) from command:" \ | |
91 | "git-merge-$strategy $cmt^ -- HEAD $cmt" | |
92 | ;; | |
93 | esac | |
94 | } | |
95 | ||
96 | finish_rb_merge () { | |
97 | move_to_original_branch | |
ad687b44 AW |
98 | if test -s "$state_dir"/rewritten |
99 | then | |
100 | git notes copy --for-rewrite=rebase <"$state_dir"/rewritten | |
b849b954 NTND |
101 | hook="$(git rev-parse --git-path hooks/post-rewrite)" |
102 | test -x "$hook" && "$hook" rebase <"$state_dir"/rewritten | |
fa99c1e1 | 103 | fi |
fa99c1e1 MZ |
104 | say All done. |
105 | } | |
106 | ||
9f50d32b KM |
107 | git_rebase__merge () { |
108 | ||
fa99c1e1 MZ |
109 | case "$action" in |
110 | continue) | |
111 | read_state | |
112 | continue_merge | |
113 | while test "$msgnum" -le "$end" | |
114 | do | |
115 | call_merge "$msgnum" | |
116 | continue_merge | |
117 | done | |
118 | finish_rb_merge | |
01a1e646 | 119 | return |
fa99c1e1 MZ |
120 | ;; |
121 | skip) | |
122 | read_state | |
123 | git rerere clear | |
124 | msgnum=$(($msgnum + 1)) | |
125 | while test "$msgnum" -le "$end" | |
126 | do | |
127 | call_merge "$msgnum" | |
128 | continue_merge | |
129 | done | |
130 | finish_rb_merge | |
01a1e646 | 131 | return |
fa99c1e1 | 132 | ;; |
66335298 | 133 | show-current-patch) |
fbd7a232 | 134 | exec git show REBASE_HEAD -- |
66335298 | 135 | ;; |
fa99c1e1 MZ |
136 | esac |
137 | ||
138 | mkdir -p "$state_dir" | |
139 | echo "$onto_name" > "$state_dir/onto_name" | |
84df4560 | 140 | write_basic_state |
fbd7a232 | 141 | rm -f "$(git rev-parse --git-path REBASE_HEAD)" |
fa99c1e1 MZ |
142 | |
143 | msgnum=0 | |
f257482c | 144 | for cmt in $(git rev-list --reverse --no-merges "$revisions") |
fa99c1e1 MZ |
145 | do |
146 | msgnum=$(($msgnum + 1)) | |
147 | echo "$cmt" > "$state_dir/cmt.$msgnum" | |
148 | done | |
149 | ||
150 | echo 1 >"$state_dir/msgnum" | |
151 | echo $msgnum >"$state_dir/end" | |
152 | ||
153 | end=$msgnum | |
154 | msgnum=1 | |
155 | ||
156 | while test "$msgnum" -le "$end" | |
157 | do | |
158 | call_merge "$msgnum" | |
159 | continue_merge | |
160 | done | |
161 | ||
162 | finish_rb_merge | |
9f50d32b KM |
163 | |
164 | } |