Merge branch 'master' into next
[git/dscho.git] / t / t3510-cherry-pick-sequence.sh
blob4b122441d0e9ad887ce7c252cd89cf7d3ac4c4e6
1 #!/bin/sh
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
13 . ./test-lib.sh
15 # Repeat first match 10 times
16 _r10='\1\1\1\1\1\1\1\1\1\1'
18 pristine_detach () {
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 &&
27 git add 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 &&
56 echo "1" >expect &&
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 &&
63 patience
64 ours
65 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 &&
93 git add foo &&
94 git commit &&
96 git rev-list HEAD |
97 git diff-tree --root --stdin |
98 sed "s/$_x40/OBJID/g"
99 } >actual &&
100 cat >expect <<-\EOF &&
101 OBJID
102 :100644 100644 OBJID OBJID M foo
103 OBJID
104 :100644 100644 OBJID OBJID M unrelated
105 OBJID
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 &&
135 echo "c" >foo &&
136 git add foo &&
137 git commit &&
138 git cherry-pick --continue &&
139 test_path_is_missing .git/sequencer &&
141 git rev-list HEAD |
142 git diff-tree --root --stdin |
143 sed "s/$_x40/OBJID/g"
144 } >actual &&
145 cat >expect <<-\EOF &&
146 OBJID
147 :100644 100644 OBJID OBJID M foo
148 OBJID
149 :100644 100644 OBJID OBJID M foo
150 OBJID
151 :100644 100644 OBJID OBJID M unrelated
152 OBJID
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 &&
162 echo "c" >foo &&
163 git add foo &&
164 git commit &&
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 &&
180 echo "c" >foo &&
181 git add foo &&
182 git commit &&
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 &&
199 git add foo &&
200 git commit &&
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 &&
210 git add foo &&
211 git commit &&
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 &&
221 git add foo &&
222 git commit &&
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 &&
231 echo "c" >foo &&
232 git add foo &&
233 git commit &&
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 &&
245 echo "c" >foo &&
246 git add foo &&
247 git commit &&
248 git revert --continue &&
249 test_path_is_missing .git/sequencer &&
251 git rev-list HEAD |
252 git diff-tree --root --stdin |
253 sed "s/$_x40/OBJID/g"
254 } >actual &&
255 cat >expect <<-\EOF &&
256 OBJID
257 :100644 100644 OBJID OBJID M foo
258 OBJID
259 :100644 100644 OBJID OBJID M foo
260 OBJID
261 :100644 100644 OBJID OBJID M unrelated
262 OBJID
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 &&
272 echo "c" >foo &&
273 git add foo &&
274 git commit &&
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 &&
280 git rev-list HEAD |
281 git diff-tree --root --stdin |
282 sed "s/$_x40/OBJID/g"
283 } >actual &&
284 cat >expect <<-\EOF &&
285 OBJID
286 :100644 100644 OBJID OBJID M unrelated
287 OBJID
288 :100644 100644 OBJID OBJID M foo
289 OBJID
290 :100644 100644 OBJID OBJID M foo
291 OBJID
292 :100644 100644 OBJID OBJID M unrelated
293 OBJID
294 :000000 100644 OBJID OBJID A foo
295 :000000 100644 OBJID OBJID A unrelated
297 test_cmp expect actual
300 test_done