1#!/bin/sh
2
3test_description='git p4 submit'
4
5. ./lib-git-p4.sh
6
7test_expect_success 'start p4d' '
8 start_p4d
9'
10
11test_expect_success 'init depot' '
12 (
13 cd "$cli" &&
14 echo file1 >file1 &&
15 p4 add file1 &&
16 p4 submit -d "change 1"
17 )
18'
19
20test_expect_success 'is_cli_file_writeable function' '
21 (
22 cd "$cli" &&
23 echo a >a &&
24 is_cli_file_writeable a &&
25 ! is_cli_file_writeable file1 &&
26 rm a
27 )
28'
29
30test_expect_success 'submit with no client dir' '
31 test_when_finished cleanup_git &&
32 git p4 clone --dest="$git" //depot &&
33 (
34 cd "$git" &&
35 echo file2 >file2 &&
36 git add file2 &&
37 git commit -m "git commit 2" &&
38 rm -rf "$cli" &&
39 git config git-p4.skipSubmitEdit true &&
40 git p4 submit
41 ) &&
42 (
43 cd "$cli" &&
44 test_path_is_file file1 &&
45 test_path_is_file file2
46 )
47'
48
49# make two commits, but tell it to apply only from HEAD^
50test_expect_success 'submit --origin' '
51 test_when_finished cleanup_git &&
52 git p4 clone --dest="$git" //depot &&
53 (
54 cd "$git" &&
55 test_commit "file3" &&
56 test_commit "file4" &&
57 git config git-p4.skipSubmitEdit true &&
58 git p4 submit --origin=HEAD^
59 ) &&
60 (
61 cd "$cli" &&
62 test_path_is_missing "file3.t" &&
63 test_path_is_file "file4.t"
64 )
65'
66
67test_expect_success 'submit --dry-run' '
68 test_when_finished cleanup_git &&
69 git p4 clone --dest="$git" //depot &&
70 (
71 cd "$git" &&
72 test_commit "dry-run1" &&
73 test_commit "dry-run2" &&
74 git p4 submit --dry-run >out &&
75 test_i18ngrep "Would apply" out
76 ) &&
77 (
78 cd "$cli" &&
79 test_path_is_missing "dry-run1.t" &&
80 test_path_is_missing "dry-run2.t"
81 )
82'
83
84test_expect_success 'submit --dry-run --export-labels' '
85 test_when_finished cleanup_git &&
86 git p4 clone --dest="$git" //depot &&
87 (
88 cd "$git" &&
89 echo dry-run1 >dry-run1 &&
90 git add dry-run1 &&
91 git commit -m "dry-run1" dry-run1 &&
92 git config git-p4.skipSubmitEdit true &&
93 git p4 submit &&
94 echo dry-run2 >dry-run2 &&
95 git add dry-run2 &&
96 git commit -m "dry-run2" dry-run2 &&
97 git tag -m "dry-run-tag1" dry-run-tag1 HEAD^ &&
98 git p4 submit --dry-run --export-labels >out &&
99 test_i18ngrep "Would create p4 label" out
100 ) &&
101 (
102 cd "$cli" &&
103 test_path_is_file "dry-run1" &&
104 test_path_is_missing "dry-run2"
105 )
106'
107
108test_expect_success 'submit with allowSubmit' '
109 test_when_finished cleanup_git &&
110 git p4 clone --dest="$git" //depot &&
111 (
112 cd "$git" &&
113 test_commit "file5" &&
114 git config git-p4.skipSubmitEdit true &&
115 git config git-p4.allowSubmit "nobranch" &&
116 test_must_fail git p4 submit &&
117 git config git-p4.allowSubmit "nobranch,master" &&
118 git p4 submit
119 )
120'
121
122test_expect_success 'submit with master branch name from argv' '
123 test_when_finished cleanup_git &&
124 git p4 clone --dest="$git" //depot &&
125 (
126 cd "$git" &&
127 test_commit "file6" &&
128 git config git-p4.skipSubmitEdit true &&
129 test_must_fail git p4 submit nobranch &&
130 git branch otherbranch &&
131 git reset --hard HEAD^ &&
132 test_commit "file7" &&
133 git p4 submit otherbranch
134 ) &&
135 (
136 cd "$cli" &&
137 test_path_is_file "file6.t" &&
138 test_path_is_missing "file7.t"
139 )
140'
141
142test_expect_success 'allow submit from branch with same revision but different name' '
143 test_when_finished cleanup_git &&
144 git p4 clone --dest="$git" //depot &&
145 (
146 cd "$git" &&
147 test_commit "file8" &&
148 git checkout -b branch1 &&
149 git checkout -b branch2 &&
150 git config git-p4.skipSubmitEdit true &&
151 git config git-p4.allowSubmit "branch1" &&
152 test_must_fail git p4 submit &&
153 git checkout branch1 &&
154 git p4 submit
155 )
156'
157
158# make two commits, but tell it to apply only one
159
160test_expect_success 'submit --commit one' '
161 test_when_finished cleanup_git &&
162 git p4 clone --dest="$git" //depot &&
163 (
164 cd "$git" &&
165 test_commit "file9" &&
166 test_commit "file10" &&
167 git config git-p4.skipSubmitEdit true &&
168 git p4 submit --commit HEAD
169 ) &&
170 (
171 cd "$cli" &&
172 test_path_is_missing "file9.t" &&
173 test_path_is_file "file10.t"
174 )
175'
176
177# make three commits, but tell it to apply only range
178
179test_expect_success 'submit --commit range' '
180 test_when_finished cleanup_git &&
181 git p4 clone --dest="$git" //depot &&
182 (
183 cd "$git" &&
184 test_commit "file11" &&
185 test_commit "file12" &&
186 test_commit "file13" &&
187 git config git-p4.skipSubmitEdit true &&
188 git p4 submit --commit HEAD~2..HEAD
189 ) &&
190 (
191 cd "$cli" &&
192 test_path_is_missing "file11.t" &&
193 test_path_is_file "file12.t" &&
194 test_path_is_file "file13.t"
195 )
196'
197
198#
199# Basic submit tests, the five handled cases
200#
201
202test_expect_success 'submit modify' '
203 test_when_finished cleanup_git &&
204 git p4 clone --dest="$git" //depot &&
205 (
206 cd "$git" &&
207 git config git-p4.skipSubmitEdit true &&
208 echo line >>file1 &&
209 git add file1 &&
210 git commit -m file1 &&
211 git p4 submit
212 ) &&
213 (
214 cd "$cli" &&
215 test_path_is_file file1 &&
216 test_line_count = 2 file1
217 )
218'
219
220test_expect_success 'submit add' '
221 test_when_finished cleanup_git &&
222 git p4 clone --dest="$git" //depot &&
223 (
224 cd "$git" &&
225 git config git-p4.skipSubmitEdit true &&
226 echo file13 >file13 &&
227 git add file13 &&
228 git commit -m file13 &&
229 git p4 submit
230 ) &&
231 (
232 cd "$cli" &&
233 test_path_is_file file13
234 )
235'
236
237test_expect_success 'submit delete' '
238 test_when_finished cleanup_git &&
239 git p4 clone --dest="$git" //depot &&
240 (
241 cd "$git" &&
242 git config git-p4.skipSubmitEdit true &&
243 git rm file4.t &&
244 git commit -m "delete file4.t" &&
245 git p4 submit
246 ) &&
247 (
248 cd "$cli" &&
249 test_path_is_missing file4.t
250 )
251'
252
253test_expect_success 'submit copy' '
254 test_when_finished cleanup_git &&
255 git p4 clone --dest="$git" //depot &&
256 (
257 cd "$git" &&
258 git config git-p4.skipSubmitEdit true &&
259 git config git-p4.detectCopies true &&
260 git config git-p4.detectCopiesHarder true &&
261 cp file5.t file5.ta &&
262 git add file5.ta &&
263 git commit -m "copy to file5.ta" &&
264 git p4 submit
265 ) &&
266 (
267 cd "$cli" &&
268 test_path_is_file file5.ta &&
269 ! is_cli_file_writeable file5.ta
270 )
271'
272
273test_expect_success 'submit rename' '
274 test_when_finished cleanup_git &&
275 git p4 clone --dest="$git" //depot &&
276 (
277 cd "$git" &&
278 git config git-p4.skipSubmitEdit true &&
279 git config git-p4.detectRenames true &&
280 git mv file6.t file6.ta &&
281 git commit -m "rename file6.t to file6.ta" &&
282 git p4 submit
283 ) &&
284 (
285 cd "$cli" &&
286 test_path_is_missing file6.t &&
287 test_path_is_file file6.ta &&
288 ! is_cli_file_writeable file6.ta
289 )
290'
291
292#
293# Converting git commit message to p4 change description, including
294# parsing out the optional Jobs: line.
295#
296test_expect_success 'simple one-line description' '
297 test_when_finished cleanup_git &&
298 git p4 clone --dest="$git" //depot &&
299 (
300 cd "$git" &&
301 echo desc2 >desc2 &&
302 git add desc2 &&
303 cat >msg <<-EOF &&
304 One-line description line for desc2.
305 EOF
306 git commit -F - <msg &&
307 git config git-p4.skipSubmitEdit true &&
308 git p4 submit &&
309 change=$(p4 -G changes -m 1 //depot/... | \
310 marshal_dump change) &&
311 # marshal_dump always adds a newline
312 p4 -G describe $change | marshal_dump desc | sed \$d >pmsg &&
313 test_cmp msg pmsg
314 )
315'
316
317test_expect_success 'description with odd formatting' '
318 test_when_finished cleanup_git &&
319 git p4 clone --dest="$git" //depot &&
320 (
321 cd "$git" &&
322 echo desc3 >desc3 &&
323 git add desc3 &&
324 (
325 printf "subject line\n\n\tExtra tab\nline.\n\n" &&
326 printf "Description:\n\tBogus description marker\n\n" &&
327 # git commit eats trailing newlines; only use one
328 printf "Files:\n\tBogus descs marker\n"
329 ) >msg &&
330 git commit -F - <msg &&
331 git config git-p4.skipSubmitEdit true &&
332 git p4 submit &&
333 change=$(p4 -G changes -m 1 //depot/... | \
334 marshal_dump change) &&
335 # marshal_dump always adds a newline
336 p4 -G describe $change | marshal_dump desc | sed \$d >pmsg &&
337 test_cmp msg pmsg
338 )
339'
340
341make_job() {
342 name="$1" &&
343 tab="$(printf \\t)" &&
344 p4 job -o | \
345 sed -e "/^Job:/s/.*/Job: $name/" \
346 -e "/^Description/{ n; s/.*/$tab job text/; }" | \
347 p4 job -i
348}
349
350test_expect_success 'description with Jobs section at end' '
351 test_when_finished cleanup_git &&
352 git p4 clone --dest="$git" //depot &&
353 (
354 cd "$git" &&
355 echo desc4 >desc4 &&
356 git add desc4 &&
357 echo 6060842 >jobname &&
358 (
359 printf "subject line\n\n\tExtra tab\nline.\n\n" &&
360 printf "Files:\n\tBogus files marker\n" &&
361 printf "Junk: 3164175\n" &&
362 printf "Jobs: $(cat jobname)\n"
363 ) >msg &&
364 git commit -F - <msg &&
365 git config git-p4.skipSubmitEdit true &&
366 # build a job
367 make_job $(cat jobname) &&
368 git p4 submit &&
369 change=$(p4 -G changes -m 1 //depot/... | \
370 marshal_dump change) &&
371 # marshal_dump always adds a newline
372 p4 -G describe $change | marshal_dump desc | sed \$d >pmsg &&
373 # make sure Jobs line and all following is gone
374 sed "/^Jobs:/,\$d" msg >jmsg &&
375 test_cmp jmsg pmsg &&
376 # make sure p4 knows about job
377 p4 -G describe $change | marshal_dump job0 >job0 &&
378 test_cmp jobname job0
379 )
380'
381
382test_expect_success 'description with Jobs and values on separate lines' '
383 test_when_finished cleanup_git &&
384 git p4 clone --dest="$git" //depot &&
385 (
386 cd "$git" &&
387 echo desc5 >desc5 &&
388 git add desc5 &&
389 echo PROJ-6060842 >jobname1 &&
390 echo PROJ-6060847 >jobname2 &&
391 (
392 printf "subject line\n\n\tExtra tab\nline.\n\n" &&
393 printf "Files:\n\tBogus files marker\n" &&
394 printf "Junk: 3164175\n" &&
395 printf "Jobs:\n" &&
396 printf "\t$(cat jobname1)\n" &&
397 printf "\t$(cat jobname2)\n"
398 ) >msg &&
399 git commit -F - <msg &&
400 git config git-p4.skipSubmitEdit true &&
401 # build two jobs
402 make_job $(cat jobname1) &&
403 make_job $(cat jobname2) &&
404 git p4 submit &&
405 change=$(p4 -G changes -m 1 //depot/... | \
406 marshal_dump change) &&
407 # marshal_dump always adds a newline
408 p4 -G describe $change | marshal_dump desc | sed \$d >pmsg &&
409 # make sure Jobs line and all following is gone
410 sed "/^Jobs:/,\$d" msg >jmsg &&
411 test_cmp jmsg pmsg &&
412 # make sure p4 knows about the two jobs
413 p4 -G describe $change >change &&
414 (
415 marshal_dump job0 <change &&
416 marshal_dump job1 <change
417 ) | sort >jobs &&
418 cat jobname1 jobname2 | sort >expected &&
419 test_cmp expected jobs
420 )
421'
422
423test_expect_success 'description with Jobs section and bogus following text' '
424 test_when_finished cleanup_git &&
425 git p4 clone --dest="$git" //depot &&
426 (
427 cd "$git" &&
428 echo desc6 >desc6 &&
429 git add desc6 &&
430 echo 6060843 >jobname &&
431 (
432 printf "subject line\n\n\tExtra tab\nline.\n\n" &&
433 printf "Files:\n\tBogus files marker\n" &&
434 printf "Junk: 3164175\n" &&
435 printf "Jobs: $(cat jobname)\n" &&
436 printf "MoreJunk: 3711\n"
437 ) >msg &&
438 git commit -F - <msg &&
439 git config git-p4.skipSubmitEdit true &&
440 # build a job
441 make_job $(cat jobname) &&
442 test_must_fail git p4 submit 2>err &&
443 test_i18ngrep "Unknown field name" err
444 ) &&
445 (
446 cd "$cli" &&
447 p4 revert desc6 &&
448 rm -f desc6
449 )
450'
451
452test_expect_success 'submit --prepare-p4-only' '
453 test_when_finished cleanup_git &&
454 git p4 clone --dest="$git" //depot &&
455 (
456 cd "$git" &&
457 echo prep-only-add >prep-only-add &&
458 git add prep-only-add &&
459 git commit -m "prep only add" &&
460 git p4 submit --prepare-p4-only >out &&
461 test_i18ngrep "prepared for submission" out &&
462 test_i18ngrep "must be deleted" out &&
463 test_i18ngrep ! "everything below this line is just the diff" out
464 ) &&
465 (
466 cd "$cli" &&
467 test_path_is_file prep-only-add &&
468 p4 fstat -T action prep-only-add | grep -w add
469 )
470'
471
472test_expect_success 'submit --shelve' '
473 test_when_finished cleanup_git &&
474 git p4 clone --dest="$git" //depot &&
475 (
476 cd "$cli" &&
477 p4 revert ... &&
478 cd "$git" &&
479 git config git-p4.skipSubmitEdit true &&
480 test_commit "shelveme1" &&
481 git p4 submit --origin=HEAD^ &&
482
483 echo 654321 >shelveme2.t &&
484 echo 123456 >>shelveme1.t &&
485 git add shelveme* &&
486 git commit -m"shelvetest" &&
487 git p4 submit --shelve --origin=HEAD^ &&
488
489 test_path_is_file shelveme1.t &&
490 test_path_is_file shelveme2.t
491 ) &&
492 (
493 cd "$cli" &&
494 change=$(p4 -G changes -s shelved -m 1 //depot/... | \
495 marshal_dump change) &&
496 p4 describe -S $change | grep shelveme2 &&
497 p4 describe -S $change | grep 123456 &&
498 test_path_is_file shelveme1.t &&
499 test_path_is_missing shelveme2.t
500 )
501'
502
503last_shelve () {
504 p4 -G changes -s shelved -m 1 //depot/... | marshal_dump change
505}
506
507make_shelved_cl() {
508 test_commit "$1" >/dev/null &&
509 git p4 submit --origin HEAD^ --shelve >/dev/null &&
510 p4 -G changes -s shelved -m 1 | marshal_dump change
511}
512
513# Update existing shelved changelists
514
515test_expect_success 'submit --update-shelve' '
516 test_when_finished cleanup_git &&
517 git p4 clone --dest="$git" //depot &&
518 (
519 cd "$cli" &&
520 p4 revert ... &&
521 cd "$git" &&
522 git config git-p4.skipSubmitEdit true &&
523 shelved_cl0=$(make_shelved_cl "shelved-change-0") &&
524 echo shelved_cl0=$shelved_cl0 &&
525 shelved_cl1=$(make_shelved_cl "shelved-change-1") &&
526
527 echo "updating shelved change lists $shelved_cl0 and $shelved_cl1" &&
528
529 echo "updated-line" >>shelf.t &&
530 echo added-file.t >added-file.t &&
531 git add shelf.t added-file.t &&
532 git rm -f shelved-change-1.t &&
533 git commit --amend -C HEAD &&
534 git show --stat HEAD &&
535 git p4 submit -v --origin HEAD~2 --update-shelve $shelved_cl0 --update-shelve $shelved_cl1 &&
536 echo "done git p4 submit"
537 ) &&
538 (
539 cd "$cli" &&
540 change=$(last_shelve) &&
541 p4 unshelve -c $change -s $change &&
542 grep -q updated-line shelf.t &&
543 p4 describe -S $change | grep added-file.t &&
544 test_path_is_missing shelved-change-1.t &&
545 p4 revert ...
546 )
547'
548
549test_expect_success 'update a shelve involving moved and copied files' '
550 test_when_finished cleanup_git &&
551 (
552 cd "$cli" &&
553 : >file_to_move &&
554 p4 add file_to_move &&
555 p4 submit -d "change1" &&
556 p4 edit file_to_move &&
557 echo change >>file_to_move &&
558 p4 submit -d "change2" &&
559 p4 opened
560 ) &&
561 git p4 clone --dest="$git" //depot &&
562 (
563 cd "$git" &&
564 git config git-p4.detectCopies true &&
565 git config git-p4.detectRenames true &&
566 git config git-p4.skipSubmitEdit true &&
567 mkdir moved &&
568 cp file_to_move copy_of_file &&
569 git add copy_of_file &&
570 git mv file_to_move moved/ &&
571 git commit -m "rename a file" &&
572 git p4 submit -M --shelve --origin HEAD^ &&
573 : >new_file &&
574 git add new_file &&
575 git commit --amend &&
576 git show --stat HEAD &&
577 change=$(last_shelve) &&
578 git p4 submit -M --update-shelve $change --commit HEAD
579 ) &&
580 (
581 cd "$cli" &&
582 change=$(last_shelve) &&
583 echo change=$change &&
584 p4 unshelve -s $change &&
585 p4 submit -d "Testing update-shelve" &&
586 test_path_is_file copy_of_file &&
587 test_path_is_file moved/file_to_move &&
588 test_path_is_missing file_to_move &&
589 test_path_is_file new_file &&
590 echo "unshelved and submitted change $change" &&
591 p4 changes moved/file_to_move | grep "Testing update-shelve" &&
592 p4 changes copy_of_file | grep "Testing update-shelve"
593 )
594'
595
596test_expect_success 'kill p4d' '
597 kill_p4d
598'
599
600test_done