3 test_description
='git p4 submit failure handling'
7 test_expect_success
'start p4d' '
11 test_expect_success
'init depot' '
14 p4 client -o | sed "/LineEnd/s/:.*/:unix/" | p4 client -i &&
17 p4 submit -d "line1 in file1"
21 test_expect_success
'conflict on one commit' '
22 test_when_finished cleanup_git &&
23 git p4 clone --dest="$git" //depot &&
28 p4 submit -d "line2 in file1"
31 # now this commit should cause a conflict
33 git config git-p4.skipSubmitEdit true &&
36 git commit -m "line3 in file1 will conflict" &&
37 test_expect_code 1 git p4 submit >out &&
38 test_i18ngrep "No commits applied" out
42 test_expect_success
'conflict on second of two commits' '
43 test_when_finished cleanup_git &&
44 git p4 clone --dest="$git" //depot &&
49 p4 submit -d "line3 in file1"
53 git config git-p4.skipSubmitEdit true &&
55 test_commit "first_commit_okay" &&
56 # now this submit should cause a conflict
59 git commit -m "line4 in file1 will conflict" &&
60 test_expect_code 1 git p4 submit >out &&
61 test_i18ngrep "Applied only the commits" out
65 test_expect_success
'conflict on first of two commits, skip' '
66 test_when_finished cleanup_git &&
67 git p4 clone --dest="$git" //depot &&
72 p4 submit -d "line4 in file1"
76 git config git-p4.skipSubmitEdit true &&
77 # this submit should cause a conflict
80 git commit -m "line5 in file1 will conflict" &&
81 # but this commit is okay
82 test_commit "okay_commit_after_skip" &&
83 echo s | test_expect_code 1 git p4 submit >out &&
84 test_i18ngrep "Applied only the commits" out
88 test_expect_success
'conflict on first of two commits, quit' '
89 test_when_finished cleanup_git &&
90 git p4 clone --dest="$git" //depot &&
95 p4 submit -d "line7 in file1"
99 git config git-p4.skipSubmitEdit true &&
100 # this submit should cause a conflict
101 echo line8 >>file1 &&
103 git commit -m "line8 in file1 will conflict" &&
104 # but this commit is okay
105 test_commit "okay_commit_after_quit" &&
106 echo q | test_expect_code 1 git p4 submit >out &&
107 test_i18ngrep "No commits applied" out
111 test_expect_success
'conflict cli and config options' '
112 test_when_finished cleanup_git &&
113 git p4 clone --dest="$git" //depot &&
116 git p4 submit --conflict=ask &&
117 git p4 submit --conflict=skip &&
118 git p4 submit --conflict=quit &&
119 test_expect_code 2 git p4 submit --conflict=foo &&
120 test_expect_code 2 git p4 submit --conflict &&
121 git config git-p4.conflict foo &&
122 test_expect_code 1 git p4 submit &&
123 git config --unset git-p4.conflict &&
128 test_expect_success
'conflict on first of two commits, --conflict=skip' '
129 test_when_finished cleanup_git &&
130 git p4 clone --dest="$git" //depot &&
134 echo line9 >>file1 &&
135 p4 submit -d "line9 in file1"
139 git config git-p4.skipSubmitEdit true &&
140 # this submit should cause a conflict
141 echo line10 >>file1 &&
143 git commit -m "line10 in file1 will conflict" &&
144 # but this commit is okay
145 test_commit "okay_commit_after_auto_skip" &&
146 test_expect_code 1 git p4 submit --conflict=skip >out &&
147 test_i18ngrep "Applied only the commits" out
151 test_expect_success
'conflict on first of two commits, --conflict=quit' '
152 test_when_finished cleanup_git &&
153 git p4 clone --dest="$git" //depot &&
157 echo line11 >>file1 &&
158 p4 submit -d "line11 in file1"
162 git config git-p4.skipSubmitEdit true &&
163 # this submit should cause a conflict
164 echo line12 >>file1 &&
166 git commit -m "line12 in file1 will conflict" &&
167 # but this commit is okay
168 test_commit "okay_commit_after_auto_quit" &&
169 test_expect_code 1 git p4 submit --conflict=quit >out &&
170 test_i18ngrep "No commits applied" out
175 # Cleanup after submit fail, all cases. Some modifications happen
176 # before trying to apply the patch. Make sure these are unwound
177 # properly. Put each one in a diff along with something that will
178 # obviously conflict. Make sure it is back to normal after.
181 test_expect_success
'cleanup edit p4 populate' '
184 echo text file >text &&
186 echo text+x file >text+x &&
189 p4 submit -d "populate p4"
194 # clone before modifying file1 to force it to conflict
195 test_when_finished cleanup_git
&&
196 git p4 clone
--dest="$git" //depot
&&
197 # ticks outside subshells
202 echo $test_tick >>file1
&&
203 p4 submit
-d "$test_tick in file1"
208 git config git-p4.skipSubmitEdit true
&&
210 echo $test_tick >>file1
&&
212 # caller will add more and submit
216 test_expect_success
'cleanup edit after submit fail' '
220 echo another line >>text &&
222 git commit -m "conflict" &&
223 test_expect_code 1 git p4 submit
227 # make sure it is not open
228 ! p4 fstat -T action text
232 test_expect_success
'cleanup add after submit fail' '
236 echo new file >textnew &&
238 git commit -m "conflict" &&
239 test_expect_code 1 git p4 submit
243 # make sure it is not there
244 # and that p4 thinks it is not added
245 # P4 returns 0 both for "not there but added" and
246 # "not there", so grep.
247 test_path_is_missing textnew &&
248 p4 fstat -T action textnew 2>&1 | grep "no such file"
252 test_expect_success
'cleanup delete after submit fail' '
257 git commit -m "conflict" &&
258 test_expect_code 1 git p4 submit
262 # make sure it is there
263 test_path_is_file text+x &&
264 ! p4 fstat -T action text+x
268 test_expect_success
'cleanup copy after submit fail' '
274 git commit -m "conflict" &&
275 git config git-p4.detectCopies true &&
276 git config git-p4.detectCopiesHarder true &&
277 # make sure setup is okay
278 git diff-tree -r -C --find-copies-harder HEAD | grep text2 | grep C100 &&
279 test_expect_code 1 git p4 submit
283 test_path_is_missing text2 &&
284 p4 fstat -T action text2 2>&1 | grep "no such file"
288 test_expect_success
'cleanup rename after submit fail' '
293 git commit -m "conflict" &&
294 git config git-p4.detectRenames true &&
295 # make sure setup is okay
296 git diff-tree -r -M HEAD | grep text2 | grep R100 &&
297 test_expect_code 1 git p4 submit
301 test_path_is_missing text2 &&
302 p4 fstat -T action text2 2>&1 | grep "no such file"
307 # Cleanup after deciding not to submit during editTemplate. This
308 # involves unwinding more work, because files have been added, deleted
309 # and chmod-ed now. Same approach as above.
312 test_expect_success
'cleanup edit after submit cancel' '
313 test_when_finished cleanup_git &&
314 git p4 clone --dest="$git" //depot &&
319 git commit -m text &&
320 echo n | test_expect_code 1 git p4 submit &&
321 git reset --hard HEAD^
325 ! p4 fstat -T action text &&
326 test_cmp "$git"/text text
330 test_expect_success
'cleanup add after submit cancel' '
331 test_when_finished cleanup_git &&
332 git p4 clone --dest="$git" //depot &&
335 echo line >textnew &&
337 git commit -m textnew &&
338 echo n | test_expect_code 1 git p4 submit
342 test_path_is_missing textnew &&
343 p4 fstat -T action textnew 2>&1 | grep "no such file"
347 test_expect_success
'cleanup delete after submit cancel' '
348 test_when_finished cleanup_git &&
349 git p4 clone --dest="$git" //depot &&
353 git commit -m "rm text" &&
354 echo n | test_expect_code 1 git p4 submit
358 test_path_is_file text &&
359 ! p4 fstat -T action text
363 test_expect_success
'cleanup copy after submit cancel' '
364 test_when_finished cleanup_git &&
365 git p4 clone --dest="$git" //depot &&
370 git commit -m text2 &&
371 git config git-p4.detectCopies true &&
372 git config git-p4.detectCopiesHarder true &&
373 git diff-tree -r -C --find-copies-harder HEAD | grep text2 | grep C100 &&
374 echo n | test_expect_code 1 git p4 submit
378 test_path_is_missing text2 &&
379 p4 fstat -T action text2 2>&1 | grep "no such file"
383 test_expect_success
'cleanup rename after submit cancel' '
384 test_when_finished cleanup_git &&
385 git p4 clone --dest="$git" //depot &&
389 git commit -m text2 &&
390 git config git-p4.detectRenames true &&
391 git diff-tree -r -M HEAD | grep text2 | grep R100 &&
392 echo n | test_expect_code 1 git p4 submit
396 test_path_is_missing text2 &&
397 p4 fstat -T action text2 2>&1 | grep "no such file" &&
398 test_path_is_file text &&
399 ! p4 fstat -T action text
403 test_expect_success
'cleanup chmod after submit cancel' '
404 test_when_finished cleanup_git &&
405 git p4 clone --dest="$git" //depot &&
408 test_chmod +x text &&
409 test_chmod -x text+x &&
410 git add text text+x &&
411 git commit -m "chmod texts" &&
412 echo n | test_expect_code 1 git p4 submit
416 test_path_is_file text &&
417 ! p4 fstat -T action text &&
418 test_path_is_file text+x &&
419 ! p4 fstat -T action text+x &&
420 ls -l text | egrep ^-r-- &&
421 ls -l text+x | egrep ^-r-x
425 test_expect_success
'kill p4d' '