]> git.ipfire.org Git - thirdparty/git.git/blame - git-rebase--merge.sh
fast-import: disallow "feature export-marks" by default
[thirdparty/git.git] / git-rebase--merge.sh
CommitLineData
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
8prec=4
9
10read_state () {
11 onto_name=$(cat "$state_dir"/onto_name) &&
12 end=$(cat "$state_dir"/end) &&
13 msgnum=$(cat "$state_dir"/msgnum)
14}
15
16continue_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
3ee5e540 30 if ! git commit ${gpg_sign_opt:+"$gpg_sign_opt"} --no-verify -C "$cmt"
fa99c1e1
MZ
31 then
32 echo "Commit failed, please do not call \"git commit\""
33 echo "directly, but instead do one of the following: "
34 die "$resolvemsg"
35 fi
36 if test -z "$GIT_QUIET"
37 then
38 printf "Committed: %0${prec}d " $msgnum
39 fi
40 echo "$cmt $(git rev-parse HEAD^0)" >> "$state_dir/rewritten"
41 else
42 if test -z "$GIT_QUIET"
43 then
44 printf "Already applied: %0${prec}d " $msgnum
45 fi
46 fi
47 test -z "$GIT_QUIET" &&
48 GIT_PAGER='' git log --format=%s -1 "$cmt"
49
50 # onto the next patch:
51 msgnum=$(($msgnum + 1))
52 echo "$msgnum" >"$state_dir/msgnum"
53}
54
55call_merge () {
95104c7e 56 msgnum="$1"
57 echo "$msgnum" >"$state_dir/msgnum"
58 cmt="$(cat "$state_dir/cmt.$msgnum")"
fa99c1e1
MZ
59 echo "$cmt" > "$state_dir/current"
60 hd=$(git rev-parse --verify HEAD)
61 cmt_name=$(git symbolic-ref HEAD 2> /dev/null || echo HEAD)
fa99c1e1
MZ
62 eval GITHEAD_$cmt='"${cmt_name##refs/heads/}~$(($end - $msgnum))"'
63 eval GITHEAD_$hd='$onto_name'
64 export GITHEAD_$cmt GITHEAD_$hd
65 if test -n "$GIT_QUIET"
66 then
67 GIT_MERGE_VERBOSITY=1 && export GIT_MERGE_VERBOSITY
68 fi
69 test -z "$strategy" && strategy=recursive
79f43447
BW
70 # If cmt doesn't have a parent, don't include it as a base
71 base=$(git rev-parse --verify --quiet $cmt^)
72 eval 'git-merge-$strategy' $strategy_opts $base ' -- "$hd" "$cmt"'
fa99c1e1
MZ
73 rv=$?
74 case "$rv" in
75 0)
76 unset GITHEAD_$cmt GITHEAD_$hd
77 return
78 ;;
79 1)
80 git rerere $allow_rerere_autoupdate
81 die "$resolvemsg"
82 ;;
83 2)
b3256809 84 echo "Strategy: $strategy failed, try another" 1>&2
fa99c1e1
MZ
85 die "$resolvemsg"
86 ;;
87 *)
88 die "Unknown exit code ($rv) from command:" \
89 "git-merge-$strategy $cmt^ -- HEAD $cmt"
90 ;;
91 esac
92}
93
94finish_rb_merge () {
95 move_to_original_branch
ad687b44
AW
96 if test -s "$state_dir"/rewritten
97 then
98 git notes copy --for-rewrite=rebase <"$state_dir"/rewritten
b849b954
NTND
99 hook="$(git rev-parse --git-path hooks/post-rewrite)"
100 test -x "$hook" && "$hook" rebase <"$state_dir"/rewritten
fa99c1e1 101 fi
fa99c1e1
MZ
102 say All done.
103}
104
9f50d32b
KM
105# The whole contents of this file is run by dot-sourcing it from
106# inside a shell function. It used to be that "return"s we see
107# below were not inside any function, and expected to return
108# to the function that dot-sourced us.
109#
9b35cadc
EM
110# However, older (9.x) versions of FreeBSD /bin/sh misbehave on such a
111# construct and continue to run the statements that follow such a "return".
9f50d32b
KM
112# As a work-around, we introduce an extra layer of a function
113# here, and immediately call it after defining it.
114git_rebase__merge () {
115
fa99c1e1
MZ
116case "$action" in
117continue)
118 read_state
119 continue_merge
120 while test "$msgnum" -le "$end"
121 do
122 call_merge "$msgnum"
123 continue_merge
124 done
125 finish_rb_merge
01a1e646 126 return
fa99c1e1
MZ
127 ;;
128skip)
129 read_state
130 git rerere clear
131 msgnum=$(($msgnum + 1))
132 while test "$msgnum" -le "$end"
133 do
134 call_merge "$msgnum"
135 continue_merge
136 done
137 finish_rb_merge
01a1e646 138 return
fa99c1e1
MZ
139 ;;
140esac
141
142mkdir -p "$state_dir"
143echo "$onto_name" > "$state_dir/onto_name"
84df4560 144write_basic_state
fa99c1e1
MZ
145
146msgnum=0
f257482c 147for cmt in $(git rev-list --reverse --no-merges "$revisions")
fa99c1e1
MZ
148do
149 msgnum=$(($msgnum + 1))
150 echo "$cmt" > "$state_dir/cmt.$msgnum"
151done
152
153echo 1 >"$state_dir/msgnum"
154echo $msgnum >"$state_dir/end"
155
156end=$msgnum
157msgnum=1
158
159while test "$msgnum" -le "$end"
160do
161 call_merge "$msgnum"
162 continue_merge
163done
164
165finish_rb_merge
9f50d32b
KM
166
167}
168# ... and then we call the whole thing.
169git_rebase__merge