Merge pull request #285 from dscho/readme
[git/mingw/4msysgit.git] / t / t9815-git-p4-submit-fail.sh
blob1243d96092ad5c6a66d66ee9debc399649ffa0a2
1 #!/bin/sh
3 test_description='git p4 submit failure handling'
5 . ./lib-git-p4.sh
7 test_expect_success 'start p4d' '
8 start_p4d
11 test_expect_success 'init depot' '
13 cd "$cli" &&
14 p4 client -o | sed "/LineEnd/s/:.*/:unix/" | p4 client -i &&
15 echo line1 >file1 &&
16 p4 add file1 &&
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 &&
25 cd "$cli" &&
26 p4 open file1 &&
27 echo line2 >>file1 &&
28 p4 submit -d "line2 in file1"
29 ) &&
31 # now this commit should cause a conflict
32 cd "$git" &&
33 git config git-p4.skipSubmitEdit true &&
34 echo line3 >>file1 &&
35 git add file1 &&
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 &&
46 cd "$cli" &&
47 p4 open file1 &&
48 echo line3 >>file1 &&
49 p4 submit -d "line3 in file1"
50 ) &&
52 cd "$git" &&
53 git config git-p4.skipSubmitEdit true &&
54 # this commit is okay
55 test_commit "first_commit_okay" &&
56 # now this submit should cause a conflict
57 echo line4 >>file1 &&
58 git add file1 &&
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 &&
69 cd "$cli" &&
70 p4 open file1 &&
71 echo line4 >>file1 &&
72 p4 submit -d "line4 in file1"
73 ) &&
75 cd "$git" &&
76 git config git-p4.skipSubmitEdit true &&
77 # this submit should cause a conflict
78 echo line5 >>file1 &&
79 git add file1 &&
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 &&
92 cd "$cli" &&
93 p4 open file1 &&
94 echo line7 >>file1 &&
95 p4 submit -d "line7 in file1"
96 ) &&
98 cd "$git" &&
99 git config git-p4.skipSubmitEdit true &&
100 # this submit should cause a conflict
101 echo line8 >>file1 &&
102 git add 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 &&
115 cd "$git" &&
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 &&
124 git p4 submit
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 &&
132 cd "$cli" &&
133 p4 open file1 &&
134 echo line9 >>file1 &&
135 p4 submit -d "line9 in file1"
136 ) &&
138 cd "$git" &&
139 git config git-p4.skipSubmitEdit true &&
140 # this submit should cause a conflict
141 echo line10 >>file1 &&
142 git add 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 &&
155 cd "$cli" &&
156 p4 open file1 &&
157 echo line11 >>file1 &&
158 p4 submit -d "line11 in file1"
159 ) &&
161 cd "$git" &&
162 git config git-p4.skipSubmitEdit true &&
163 # this submit should cause a conflict
164 echo line12 >>file1 &&
165 git add 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' '
183 cd "$cli" &&
184 echo text file >text &&
185 p4 add text &&
186 echo text+x file >text+x &&
187 chmod 755 text+x &&
188 p4 add text+x &&
189 p4 submit -d "populate p4"
193 setup_conflict() {
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
198 test_tick &&
200 cd "$cli" &&
201 p4 open file1 &&
202 echo $test_tick >>file1 &&
203 p4 submit -d "$test_tick in file1"
204 ) &&
205 test_tick &&
207 cd "$git" &&
208 git config git-p4.skipSubmitEdit true &&
209 # easy conflict
210 echo $test_tick >>file1 &&
211 git add file1
212 # caller will add more and submit
216 test_expect_success 'cleanup edit after submit fail' '
217 setup_conflict &&
219 cd "$git" &&
220 echo another line >>text &&
221 git add text &&
222 git commit -m "conflict" &&
223 test_expect_code 1 git p4 submit
224 ) &&
226 cd "$cli" &&
227 # make sure it is not open
228 ! p4 fstat -T action text
232 test_expect_success 'cleanup add after submit fail' '
233 setup_conflict &&
235 cd "$git" &&
236 echo new file >textnew &&
237 git add textnew &&
238 git commit -m "conflict" &&
239 test_expect_code 1 git p4 submit
240 ) &&
242 cd "$cli" &&
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' '
253 setup_conflict &&
255 cd "$git" &&
256 git rm text+x &&
257 git commit -m "conflict" &&
258 test_expect_code 1 git p4 submit
259 ) &&
261 cd "$cli" &&
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' '
269 setup_conflict &&
271 cd "$git" &&
272 cp text text2 &&
273 git add text2 &&
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
280 ) &&
282 cd "$cli" &&
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' '
289 setup_conflict &&
291 cd "$git" &&
292 git mv text text2 &&
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
298 ) &&
300 cd "$cli" &&
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 &&
316 cd "$git" &&
317 echo line >>text &&
318 git add text &&
319 git commit -m text &&
320 echo n | test_expect_code 1 git p4 submit &&
321 git reset --hard HEAD^
322 ) &&
324 cd "$cli" &&
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 &&
334 cd "$git" &&
335 echo line >textnew &&
336 git add textnew &&
337 git commit -m textnew &&
338 echo n | test_expect_code 1 git p4 submit
339 ) &&
341 cd "$cli" &&
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 &&
351 cd "$git" &&
352 git rm text &&
353 git commit -m "rm text" &&
354 echo n | test_expect_code 1 git p4 submit
355 ) &&
357 cd "$cli" &&
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 &&
367 cd "$git" &&
368 cp text text2 &&
369 git add text2 &&
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
375 ) &&
377 cd "$cli" &&
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 &&
387 cd "$git" &&
388 git mv text text2 &&
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
393 ) &&
395 cd "$cli" &&
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 &&
407 cd "$git" &&
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
413 ) &&
415 cd "$cli" &&
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 if test_have_prereq NOT_CYGWIN
421 then
422 stat --format=%A text | egrep ^-r-- &&
423 stat --format=%A text+x | egrep ^-r-x
428 test_expect_success 'kill p4d' '
429 kill_p4d
432 test_done