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