3 test_description
='git p4 submit'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
10 test_expect_success
'start p4d' '
14 test_expect_success
'init depot' '
19 p4 submit -d "change 1"
23 test_expect_success
'is_cli_file_writeable function' '
27 is_cli_file_writeable a &&
28 ! is_cli_file_writeable file1 &&
33 test_expect_success
'submit with no client dir' '
34 test_when_finished cleanup_git &&
35 git p4 clone --dest="$git" //depot &&
40 git commit -m "git commit 2" &&
42 git config git-p4.skipSubmitEdit true &&
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 &&
58 test_commit "file3" &&
59 test_commit "file4" &&
60 git config git-p4.skipSubmitEdit true &&
61 git p4 submit --origin=HEAD^
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 &&
75 test_commit "dry-run1" &&
76 test_commit "dry-run2" &&
77 git p4 submit --dry-run >out &&
78 test_i18ngrep "Would apply" out
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 &&
92 echo dry-run1 >dry-run1 &&
94 git commit -m "dry-run1" dry-run1 &&
95 git config git-p4.skipSubmitEdit true &&
97 echo dry-run2 >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_i18ngrep "Would create p4 label" out
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 &&
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" &&
125 test_expect_success
'submit with master branch name from argv' '
126 test_when_finished cleanup_git &&
127 git p4 clone --dest="$git" //depot &&
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
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 &&
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 &&
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 &&
168 test_commit "file9" &&
169 test_commit "file10" &&
170 git config git-p4.skipSubmitEdit true &&
171 git p4 submit --commit HEAD
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 &&
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
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 &&
210 git config git-p4.skipSubmitEdit true &&
213 git commit -m file1 &&
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 &&
228 git config git-p4.skipSubmitEdit true &&
229 echo file13 >file13 &&
231 git commit -m file13 &&
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 &&
245 git config git-p4.skipSubmitEdit true &&
247 git commit -m "delete file4.t" &&
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 &&
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 &&
266 git commit -m "copy to file5.ta" &&
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 &&
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" &&
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 &&
307 One-line description line for desc2.
309 git commit -F - <msg &&
310 git config git-p4.skipSubmitEdit true &&
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 &&
320 test_expect_success
'description with odd formatting' '
321 test_when_finished cleanup_git &&
322 git p4 clone --dest="$git" //depot &&
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"
333 git commit -F - <msg &&
334 git config git-p4.skipSubmitEdit true &&
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 &&
346 tab
="$(printf \\t)" &&
348 sed -e "/^Job:/s/.*/Job: $name/" \
349 -e "/^Description/{ n; s/.*/$tab job text/; }" | \
353 test_expect_success
'description with Jobs section at end' '
354 test_when_finished cleanup_git &&
355 git p4 clone --dest="$git" //depot &&
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"
367 git commit -F - <msg &&
368 git config git-p4.skipSubmitEdit true &&
370 make_job $(cat jobname) &&
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 &&
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" &&
399 printf "\t$(cat jobname1)\n" &&
400 printf "\t$(cat jobname2)\n"
402 git commit -F - <msg &&
403 git config git-p4.skipSubmitEdit true &&
405 make_job $(cat jobname1) &&
406 make_job $(cat jobname2) &&
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
421 cat jobname1 jobname2 | sort >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 &&
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"
441 git commit -F - <msg &&
442 git config git-p4.skipSubmitEdit true &&
444 make_job $(cat jobname) &&
445 test_must_fail git p4 submit 2>err &&
446 test_i18ngrep "Unknown field name" err
455 test_expect_success
'submit --prepare-p4-only' '
456 test_when_finished cleanup_git &&
457 git p4 clone --dest="$git" //depot &&
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_i18ngrep "prepared for submission" out &&
465 test_i18ngrep "must be deleted" out &&
466 test_i18ngrep ! "everything below this line is just the diff" out
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 &&
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 &&
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
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
507 p4
-G changes
-s shelved
-m 1 //depot
/... | marshal_dump change
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 &&
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"
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 &&
552 test_expect_success
'update a shelve involving moved and copied files' '
553 test_when_finished cleanup_git &&
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" &&
564 git p4 clone --dest="$git" //depot &&
567 git config git-p4.detectCopies true &&
568 git config git-p4.detectRenames true &&
569 git config git-p4.skipSubmitEdit true &&
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^ &&
578 git commit --amend &&
579 git show --stat HEAD &&
580 change=$(last_shelve) &&
581 git p4 submit -M --update-shelve $change --commit HEAD
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"