Sync with 'master'
[alt-git.git] / t / t9815-git-p4-submit-fail.sh
blob92ef9d8c242559b9d7b90b975d9d9905922ef24a
1 #!/bin/sh
3 test_description='git p4 submit failure handling'
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./lib-git-p4.sh
8 test_expect_success 'start p4d' '
9 start_p4d
12 test_expect_success 'init depot' '
14 cd "$cli" &&
15 p4 client -o | sed "/LineEnd/s/:.*/:unix/" | p4 client -i &&
16 echo line1 >file1 &&
17 p4 add file1 &&
18 p4 submit -d "line1 in file1"
22 test_expect_success 'conflict on one commit' '
23 test_when_finished cleanup_git &&
24 git p4 clone --dest="$git" //depot &&
26 cd "$cli" &&
27 p4 open file1 &&
28 echo line2 >>file1 &&
29 p4 submit -d "line2 in file1"
30 ) &&
32 # now this commit should cause a conflict
33 cd "$git" &&
34 git config git-p4.skipSubmitEdit true &&
35 echo line3 >>file1 &&
36 git add file1 &&
37 git commit -m "line3 in file1 will conflict" &&
38 test_expect_code 1 git p4 submit >out &&
39 test_grep "No commits applied" out
43 test_expect_success 'conflict on second of two commits' '
44 test_when_finished cleanup_git &&
45 git p4 clone --dest="$git" //depot &&
47 cd "$cli" &&
48 p4 open file1 &&
49 echo line3 >>file1 &&
50 p4 submit -d "line3 in file1"
51 ) &&
53 cd "$git" &&
54 git config git-p4.skipSubmitEdit true &&
55 # this commit is okay
56 test_commit "first_commit_okay" &&
57 # now this submit should cause a conflict
58 echo line4 >>file1 &&
59 git add file1 &&
60 git commit -m "line4 in file1 will conflict" &&
61 test_expect_code 1 git p4 submit >out &&
62 test_grep "Applied only the commits" out
66 test_expect_success 'conflict on first of two commits, skip' '
67 test_when_finished cleanup_git &&
68 git p4 clone --dest="$git" //depot &&
70 cd "$cli" &&
71 p4 open file1 &&
72 echo line4 >>file1 &&
73 p4 submit -d "line4 in file1"
74 ) &&
76 cd "$git" &&
77 git config git-p4.skipSubmitEdit true &&
78 # this submit should cause a conflict
79 echo line5 >>file1 &&
80 git add file1 &&
81 git commit -m "line5 in file1 will conflict" &&
82 # but this commit is okay
83 test_commit "okay_commit_after_skip" &&
84 echo s | test_expect_code 1 git p4 submit >out &&
85 test_grep "Applied only the commits" out
89 test_expect_success 'conflict on first of two commits, quit' '
90 test_when_finished cleanup_git &&
91 git p4 clone --dest="$git" //depot &&
93 cd "$cli" &&
94 p4 open file1 &&
95 echo line7 >>file1 &&
96 p4 submit -d "line7 in file1"
97 ) &&
99 cd "$git" &&
100 git config git-p4.skipSubmitEdit true &&
101 # this submit should cause a conflict
102 echo line8 >>file1 &&
103 git add file1 &&
104 git commit -m "line8 in file1 will conflict" &&
105 # but this commit is okay
106 test_commit "okay_commit_after_quit" &&
107 echo q | test_expect_code 1 git p4 submit >out &&
108 test_grep "No commits applied" out
112 test_expect_success 'conflict cli and config options' '
113 test_when_finished cleanup_git &&
114 git p4 clone --dest="$git" //depot &&
116 cd "$git" &&
117 git p4 submit --conflict=ask &&
118 git p4 submit --conflict=skip &&
119 git p4 submit --conflict=quit &&
120 test_expect_code 2 git p4 submit --conflict=foo &&
121 test_expect_code 2 git p4 submit --conflict &&
122 git config git-p4.conflict foo &&
123 test_expect_code 1 git p4 submit &&
124 git config --unset git-p4.conflict &&
125 git p4 submit
129 test_expect_success 'conflict on first of two commits, --conflict=skip' '
130 test_when_finished cleanup_git &&
131 git p4 clone --dest="$git" //depot &&
133 cd "$cli" &&
134 p4 open file1 &&
135 echo line9 >>file1 &&
136 p4 submit -d "line9 in file1"
137 ) &&
139 cd "$git" &&
140 git config git-p4.skipSubmitEdit true &&
141 # this submit should cause a conflict
142 echo line10 >>file1 &&
143 git add file1 &&
144 git commit -m "line10 in file1 will conflict" &&
145 # but this commit is okay
146 test_commit "okay_commit_after_auto_skip" &&
147 test_expect_code 1 git p4 submit --conflict=skip >out &&
148 test_grep "Applied only the commits" out
152 test_expect_success 'conflict on first of two commits, --conflict=quit' '
153 test_when_finished cleanup_git &&
154 git p4 clone --dest="$git" //depot &&
156 cd "$cli" &&
157 p4 open file1 &&
158 echo line11 >>file1 &&
159 p4 submit -d "line11 in file1"
160 ) &&
162 cd "$git" &&
163 git config git-p4.skipSubmitEdit true &&
164 # this submit should cause a conflict
165 echo line12 >>file1 &&
166 git add file1 &&
167 git commit -m "line12 in file1 will conflict" &&
168 # but this commit is okay
169 test_commit "okay_commit_after_auto_quit" &&
170 test_expect_code 1 git p4 submit --conflict=quit >out &&
171 test_grep "No commits applied" out
176 # Cleanup after submit fail, all cases. Some modifications happen
177 # before trying to apply the patch. Make sure these are unwound
178 # properly. Put each one in a diff along with something that will
179 # obviously conflict. Make sure it is back to normal after.
182 test_expect_success 'cleanup edit p4 populate' '
184 cd "$cli" &&
185 echo text file >text &&
186 p4 add text &&
187 echo text+x file >text+x &&
188 chmod 755 text+x &&
189 p4 add text+x &&
190 p4 submit -d "populate p4"
194 setup_conflict() {
195 # clone before modifying file1 to force it to conflict
196 test_when_finished cleanup_git &&
197 git p4 clone --dest="$git" //depot &&
198 # ticks outside subshells
199 test_tick &&
201 cd "$cli" &&
202 p4 open file1 &&
203 echo $test_tick >>file1 &&
204 p4 submit -d "$test_tick in file1"
205 ) &&
206 test_tick &&
208 cd "$git" &&
209 git config git-p4.skipSubmitEdit true &&
210 # easy conflict
211 echo $test_tick >>file1 &&
212 git add file1
213 # caller will add more and submit
217 test_expect_success 'cleanup edit after submit fail' '
218 setup_conflict &&
220 cd "$git" &&
221 echo another line >>text &&
222 git add text &&
223 git commit -m "conflict" &&
224 test_expect_code 1 git p4 submit
225 ) &&
227 cd "$cli" &&
228 # make sure it is not open
229 ! p4 fstat -T action text
233 test_expect_success 'cleanup add after submit fail' '
234 setup_conflict &&
236 cd "$git" &&
237 echo new file >textnew &&
238 git add textnew &&
239 git commit -m "conflict" &&
240 test_expect_code 1 git p4 submit
241 ) &&
243 cd "$cli" &&
244 # make sure it is not there
245 # and that p4 thinks it is not added
246 # P4 returns 0 both for "not there but added" and
247 # "not there", so grep.
248 test_path_is_missing textnew &&
249 p4 fstat -T action textnew 2>&1 | grep "no such file"
253 test_expect_success 'cleanup delete after submit fail' '
254 setup_conflict &&
256 cd "$git" &&
257 git rm text+x &&
258 git commit -m "conflict" &&
259 test_expect_code 1 git p4 submit
260 ) &&
262 cd "$cli" &&
263 # make sure it is there
264 test_path_is_file text+x &&
265 ! p4 fstat -T action text+x
269 test_expect_success 'cleanup copy after submit fail' '
270 setup_conflict &&
272 cd "$git" &&
273 cp text text2 &&
274 git add text2 &&
275 git commit -m "conflict" &&
276 git config git-p4.detectCopies true &&
277 git config git-p4.detectCopiesHarder true &&
278 # make sure setup is okay
279 git diff-tree -r -C --find-copies-harder HEAD | grep text2 | grep C100 &&
280 test_expect_code 1 git p4 submit
281 ) &&
283 cd "$cli" &&
284 test_path_is_missing text2 &&
285 p4 fstat -T action text2 2>&1 | grep "no such file"
289 test_expect_success 'cleanup rename after submit fail' '
290 setup_conflict &&
292 cd "$git" &&
293 git mv text text2 &&
294 git commit -m "conflict" &&
295 git config git-p4.detectRenames true &&
296 # make sure setup is okay
297 git diff-tree -r -M HEAD | grep text2 | grep R100 &&
298 test_expect_code 1 git p4 submit
299 ) &&
301 cd "$cli" &&
302 test_path_is_missing text2 &&
303 p4 fstat -T action text2 2>&1 | grep "no such file"
308 # Cleanup after deciding not to submit during editTemplate. This
309 # involves unwinding more work, because files have been added, deleted
310 # and chmod-ed now. Same approach as above.
313 test_expect_success 'cleanup edit after submit cancel' '
314 test_when_finished cleanup_git &&
315 git p4 clone --dest="$git" //depot &&
317 cd "$git" &&
318 echo line >>text &&
319 git add text &&
320 git commit -m text &&
321 echo n | test_expect_code 1 git p4 submit &&
322 git reset --hard HEAD^
323 ) &&
325 cd "$cli" &&
326 ! p4 fstat -T action text &&
327 test_cmp "$git"/text text
331 test_expect_success 'cleanup add after submit cancel' '
332 test_when_finished cleanup_git &&
333 git p4 clone --dest="$git" //depot &&
335 cd "$git" &&
336 echo line >textnew &&
337 git add textnew &&
338 git commit -m textnew &&
339 echo n | test_expect_code 1 git p4 submit
340 ) &&
342 cd "$cli" &&
343 test_path_is_missing textnew &&
344 p4 fstat -T action textnew 2>&1 | grep "no such file"
348 test_expect_success 'cleanup delete after submit cancel' '
349 test_when_finished cleanup_git &&
350 git p4 clone --dest="$git" //depot &&
352 cd "$git" &&
353 git rm text &&
354 git commit -m "rm text" &&
355 echo n | test_expect_code 1 git p4 submit
356 ) &&
358 cd "$cli" &&
359 test_path_is_file text &&
360 ! p4 fstat -T action text
364 test_expect_success 'cleanup copy after submit cancel' '
365 test_when_finished cleanup_git &&
366 git p4 clone --dest="$git" //depot &&
368 cd "$git" &&
369 cp text text2 &&
370 git add text2 &&
371 git commit -m text2 &&
372 git config git-p4.detectCopies true &&
373 git config git-p4.detectCopiesHarder true &&
374 git diff-tree -r -C --find-copies-harder HEAD | grep text2 | grep C100 &&
375 echo n | test_expect_code 1 git p4 submit
376 ) &&
378 cd "$cli" &&
379 test_path_is_missing text2 &&
380 p4 fstat -T action text2 2>&1 | grep "no such file"
384 test_expect_success 'cleanup rename after submit cancel' '
385 test_when_finished cleanup_git &&
386 git p4 clone --dest="$git" //depot &&
388 cd "$git" &&
389 git mv text text2 &&
390 git commit -m text2 &&
391 git config git-p4.detectRenames true &&
392 git diff-tree -r -M HEAD | grep text2 | grep R100 &&
393 echo n | test_expect_code 1 git p4 submit
394 ) &&
396 cd "$cli" &&
397 test_path_is_missing text2 &&
398 p4 fstat -T action text2 2>&1 | grep "no such file" &&
399 test_path_is_file text &&
400 ! p4 fstat -T action text
404 test_expect_success 'cleanup chmod after submit cancel' '
405 test_when_finished cleanup_git &&
406 git p4 clone --dest="$git" //depot &&
408 cd "$git" &&
409 test_chmod +x text &&
410 test_chmod -x text+x &&
411 git add text text+x &&
412 git commit -m "chmod texts" &&
413 echo n | test_expect_code 1 git p4 submit
414 ) &&
416 cd "$cli" &&
417 test_path_is_file text &&
418 ! p4 fstat -T action text &&
419 test_path_is_file text+x &&
420 ! p4 fstat -T action text+x &&
421 ls -l text | grep -E ^-r-- &&
422 ls -l text+x | grep -E ^-r-x
426 test_done