3 test_description
='Test cherry-pick continuation features
5 + anotherpick: rewrites foo to d
6 + picked: rewrites foo to c
7 + unrelatedpick: rewrites unrelated to reallyunrelated
8 + base: rewrites foo to b
9 + initial: writes foo as a, unrelated as unrelated
15 # Repeat first match 10 times
16 _r10
='\1\1\1\1\1\1\1\1\1\1'
19 git cherry-pick
--reset &&
20 git checkout
-f "$1^0" &&
21 git read-tree
-u --reset HEAD
&&
22 git clean
-d -f -f -q -x
25 test_expect_success setup
'
26 echo unrelated >unrelated &&
28 test_commit initial foo a &&
29 test_commit base foo b &&
30 test_commit unrelatedpick unrelated reallyunrelated &&
31 test_commit picked foo c &&
32 test_commit anotherpick foo d &&
33 git config advice.detachedhead false
37 test_expect_success
'cherry-pick persists data on failure' '
38 pristine_detach initial &&
39 test_must_fail git cherry-pick -s base..anotherpick &&
40 test_path_is_dir .git/sequencer &&
41 test_path_is_file .git/sequencer/head &&
42 test_path_is_file .git/sequencer/todo &&
43 test_path_is_file .git/sequencer/opts
46 test_expect_success
'cherry-pick persists opts correctly' '
47 pristine_detach initial &&
48 test_must_fail git cherry-pick -s -m 1 --strategy=recursive -X patience -X ours base..anotherpick &&
49 test_path_is_dir .git/sequencer &&
50 test_path_is_file .git/sequencer/head &&
51 test_path_is_file .git/sequencer/todo &&
52 test_path_is_file .git/sequencer/opts &&
53 echo "true" >expect &&
54 git config --file=.git/sequencer/opts --get-all options.signoff >actual &&
55 test_cmp expect actual &&
57 git config --file=.git/sequencer/opts --get-all options.mainline >actual &&
58 test_cmp expect actual &&
59 echo "recursive" >expect &&
60 git config --file=.git/sequencer/opts --get-all options.strategy >actual &&
61 test_cmp expect actual &&
62 cat >expect <<-\EOF &&
66 git config --file=.git/sequencer/opts --get-all options.strategy-option >actual &&
67 test_cmp expect actual
70 test_expect_success
'cherry-pick cleans up sequencer state upon success' '
71 pristine_detach initial &&
72 git cherry-pick initial..picked &&
73 test_path_is_missing .git/sequencer
76 test_expect_success
'--reset does not complain when no cherry-pick is in progress' '
77 pristine_detach initial &&
78 git cherry-pick --reset
81 test_expect_success
'--reset cleans up sequencer state' '
82 pristine_detach initial &&
83 test_must_fail git cherry-pick base..picked &&
84 git cherry-pick --reset &&
85 test_path_is_missing .git/sequencer
88 test_expect_success
'cherry-pick cleans up sequencer state when one commit is left' '
89 pristine_detach initial &&
90 test_must_fail git cherry-pick base..picked &&
91 test_path_is_missing .git/sequencer &&
92 echo "resolved" >foo &&
97 git diff-tree --root --stdin |
100 cat >expect <<-\EOF &&
102 :100644 100644 OBJID OBJID M foo
104 :100644 100644 OBJID OBJID M unrelated
106 :000000 100644 OBJID OBJID A foo
107 :000000 100644 OBJID OBJID A unrelated
109 test_cmp expect actual
112 test_expect_success
'cherry-pick does not implicitly stomp an existing operation' '
113 pristine_detach initial &&
114 test_must_fail git cherry-pick base..anotherpick &&
115 test-chmtime -v +0 .git/sequencer >expect &&
116 test_must_fail git cherry-pick unrelatedpick &&
117 test-chmtime -v +0 .git/sequencer >actual &&
118 test_cmp expect actual
121 test_expect_success
'--continue complains when no cherry-pick is in progress' '
122 pristine_detach initial &&
123 test_must_fail git cherry-pick --continue
126 test_expect_success
'--continue complains when there are unresolved conflicts' '
127 pristine_detach initial &&
128 test_must_fail git cherry-pick base..anotherpick &&
129 test_must_fail git cherry-pick --continue
132 test_expect_success
'--continue continues after conflicts are resolved' '
133 pristine_detach initial &&
134 test_must_fail git cherry-pick base..anotherpick &&
138 git cherry-pick --continue &&
139 test_path_is_missing .git/sequencer &&
142 git diff-tree --root --stdin |
143 sed "s/$_x40/OBJID/g"
145 cat >expect <<-\EOF &&
147 :100644 100644 OBJID OBJID M foo
149 :100644 100644 OBJID OBJID M foo
151 :100644 100644 OBJID OBJID M unrelated
153 :000000 100644 OBJID OBJID A foo
154 :000000 100644 OBJID OBJID A unrelated
156 test_cmp expect actual
159 test_expect_success
'--continue respects opts' '
160 pristine_detach initial &&
161 test_must_fail git cherry-pick -x base..anotherpick &&
165 git cherry-pick --continue &&
166 test_path_is_missing .git/sequencer &&
167 git cat-file commit HEAD >anotherpick_msg &&
168 git cat-file commit HEAD~1 >picked_msg &&
169 git cat-file commit HEAD~2 >unrelatedpick_msg &&
170 git cat-file commit HEAD~3 >initial_msg &&
171 test_must_fail grep "cherry picked from" initial_msg &&
172 grep "cherry picked from" unrelatedpick_msg &&
173 grep "cherry picked from" picked_msg &&
174 grep "cherry picked from" anotherpick_msg
177 test_expect_success
'--signoff is not automatically propagated to resolved conflict' '
178 pristine_detach initial &&
179 test_must_fail git cherry-pick --signoff base..anotherpick &&
183 git cherry-pick --continue &&
184 test_path_is_missing .git/sequencer &&
185 git cat-file commit HEAD >anotherpick_msg &&
186 git cat-file commit HEAD~1 >picked_msg &&
187 git cat-file commit HEAD~2 >unrelatedpick_msg &&
188 git cat-file commit HEAD~3 >initial_msg &&
189 test_must_fail grep "Signed-off-by:" initial_msg &&
190 grep "Signed-off-by:" unrelatedpick_msg &&
191 test_must_fail grep "Signed-off-by:" picked_msg &&
192 grep "Signed-off-by:" anotherpick_msg
195 test_expect_success
'malformed instruction sheet 1' '
196 pristine_detach initial &&
197 test_must_fail git cherry-pick base..anotherpick &&
198 echo "resolved" >foo &&
201 sed "s/pick /pick/" .git/sequencer/todo >new_sheet &&
202 cp new_sheet .git/sequencer/todo &&
203 test_must_fail git cherry-pick --continue
206 test_expect_success
'malformed instruction sheet 2' '
207 pristine_detach initial &&
208 test_must_fail git cherry-pick base..anotherpick &&
209 echo "resolved" >foo &&
212 sed "s/pick/revert/" .git/sequencer/todo >new_sheet &&
213 cp new_sheet .git/sequencer/todo &&
214 test_must_fail git cherry-pick --continue
217 test_expect_success
'malformed instruction sheet 3' '
218 pristine_detach initial &&
219 test_must_fail git cherry-pick base..anotherpick &&
220 echo "resolved" >foo &&
223 sed "s/pick \([0-9a-f]*\)/pick $_r10/" .git/sequencer/todo >new_sheet &&
224 cp new_sheet .git/sequencer/todo &&
225 test_must_fail git cherry-pick --continue
228 test_expect_success
'commit descriptions in insn sheet are optional' '
229 pristine_detach initial &&
230 test_must_fail git cherry-pick base..anotherpick &&
234 cut -d" " -f1,2 .git/sequencer/todo >new_sheet &&
235 cp new_sheet .git/sequencer/todo &&
236 git cherry-pick --continue &&
237 test_path_is_missing .git/sequencer &&
238 git rev-list HEAD >commits
239 test_line_count = 4 commits
242 test_expect_success
'revert --continue continues after cherry-pick' '
243 pristine_detach initial &&
244 test_must_fail git cherry-pick base..anotherpick &&
248 git revert --continue &&
249 test_path_is_missing .git/sequencer &&
252 git diff-tree --root --stdin |
253 sed "s/$_x40/OBJID/g"
255 cat >expect <<-\EOF &&
257 :100644 100644 OBJID OBJID M foo
259 :100644 100644 OBJID OBJID M foo
261 :100644 100644 OBJID OBJID M unrelated
263 :000000 100644 OBJID OBJID A foo
264 :000000 100644 OBJID OBJID A unrelated
266 test_cmp expect actual
269 test_expect_success
'mixed pick and revert instructions' '
270 pristine_detach initial &&
271 test_must_fail git cherry-pick base..anotherpick &&
275 oldsha=`git rev-parse --short HEAD~1` &&
276 echo "revert $oldsha unrelatedpick" >>.git/sequencer/todo &&
277 git cherry-pick --continue &&
278 test_path_is_missing .git/sequencer &&
281 git diff-tree --root --stdin |
282 sed "s/$_x40/OBJID/g"
284 cat >expect <<-\EOF &&
286 :100644 100644 OBJID OBJID M unrelated
288 :100644 100644 OBJID OBJID M foo
290 :100644 100644 OBJID OBJID M foo
292 :100644 100644 OBJID OBJID M unrelated
294 :000000 100644 OBJID OBJID A foo
295 :000000 100644 OBJID OBJID A unrelated
297 test_cmp expect actual