]> git.ipfire.org Git - thirdparty/git.git/blame - t/t9807-git-p4-submit.sh
Sync with Git 2.45.1
[thirdparty/git.git] / t / t9807-git-p4-submit.sh
CommitLineData
c145225a
PW
1#!/bin/sh
2
6ab1d76c 3test_description='git p4 submit'
c145225a 4
46a29020 5GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
334afbc7
JS
6export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
c145225a
PW
8. ./lib-git-p4.sh
9
10test_expect_success 'start p4d' '
11 start_p4d
12'
13
14test_expect_success 'init depot' '
15 (
16 cd "$cli" &&
17 echo file1 >file1 &&
18 p4 add file1 &&
19 p4 submit -d "change 1"
20 )
21'
22
0577849d 23test_expect_success 'is_cli_file_writeable function' '
e9df0f9c
PW
24 (
25 cd "$cli" &&
26 echo a >a &&
27 is_cli_file_writeable a &&
28 ! is_cli_file_writeable file1 &&
29 rm a
30 )
31'
32
c145225a
PW
33test_expect_success 'submit with no client dir' '
34 test_when_finished cleanup_git &&
6ab1d76c 35 git p4 clone --dest="$git" //depot &&
c145225a
PW
36 (
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 &&
6ab1d76c 43 git p4 submit
8d7ec362
PW
44 ) &&
45 (
46 cd "$cli" &&
47 test_path_is_file file1 &&
48 test_path_is_file file2
c145225a
PW
49 )
50'
51
28755dba
PW
52# make two commits, but tell it to apply only from HEAD^
53test_expect_success 'submit --origin' '
54 test_when_finished cleanup_git &&
6ab1d76c 55 git p4 clone --dest="$git" //depot &&
28755dba
PW
56 (
57 cd "$git" &&
58 test_commit "file3" &&
59 test_commit "file4" &&
60 git config git-p4.skipSubmitEdit true &&
6ab1d76c 61 git p4 submit --origin=HEAD^
28755dba
PW
62 ) &&
63 (
64 cd "$cli" &&
28755dba
PW
65 test_path_is_missing "file3.t" &&
66 test_path_is_file "file4.t"
67 )
68'
69
ef739f08
PW
70test_expect_success 'submit --dry-run' '
71 test_when_finished cleanup_git &&
72 git p4 clone --dest="$git" //depot &&
73 (
74 cd "$git" &&
75 test_commit "dry-run1" &&
76 test_commit "dry-run2" &&
77 git p4 submit --dry-run >out &&
6789275d 78 test_grep "Would apply" out
ef739f08
PW
79 ) &&
80 (
81 cd "$cli" &&
82 test_path_is_missing "dry-run1.t" &&
83 test_path_is_missing "dry-run2.t"
84 )
85'
86
87test_expect_success 'submit --dry-run --export-labels' '
88 test_when_finished cleanup_git &&
89 git p4 clone --dest="$git" //depot &&
90 (
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 &&
6789275d 102 test_grep "Would create p4 label" out
ef739f08
PW
103 ) &&
104 (
105 cd "$cli" &&
106 test_path_is_file "dry-run1" &&
107 test_path_is_missing "dry-run2"
108 )
109'
110
28755dba
PW
111test_expect_success 'submit with allowSubmit' '
112 test_when_finished cleanup_git &&
6ab1d76c 113 git p4 clone --dest="$git" //depot &&
28755dba
PW
114 (
115 cd "$git" &&
116 test_commit "file5" &&
117 git config git-p4.skipSubmitEdit true &&
118 git config git-p4.allowSubmit "nobranch" &&
6ab1d76c 119 test_must_fail git p4 submit &&
46a29020 120 git config git-p4.allowSubmit "nobranch,main" &&
6ab1d76c 121 git p4 submit
28755dba
PW
122 )
123'
124
125test_expect_success 'submit with master branch name from argv' '
126 test_when_finished cleanup_git &&
6ab1d76c 127 git p4 clone --dest="$git" //depot &&
28755dba
PW
128 (
129 cd "$git" &&
130 test_commit "file6" &&
131 git config git-p4.skipSubmitEdit true &&
6ab1d76c 132 test_must_fail git p4 submit nobranch &&
28755dba
PW
133 git branch otherbranch &&
134 git reset --hard HEAD^ &&
135 test_commit "file7" &&
6ab1d76c 136 git p4 submit otherbranch
28755dba
PW
137 ) &&
138 (
139 cd "$cli" &&
28755dba
PW
140 test_path_is_file "file6.t" &&
141 test_path_is_missing "file7.t"
142 )
143'
144
eff45110 145test_expect_success 'allow submit from branch with same revision but different name' '
3d553cce
LD
146 test_when_finished cleanup_git &&
147 git p4 clone --dest="$git" //depot &&
148 (
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
158 )
159'
160
f55b87c1
RM
161# make two commits, but tell it to apply only one
162
163test_expect_success 'submit --commit one' '
164 test_when_finished cleanup_git &&
165 git p4 clone --dest="$git" //depot &&
166 (
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 ) &&
173 (
174 cd "$cli" &&
175 test_path_is_missing "file9.t" &&
176 test_path_is_file "file10.t"
177 )
178'
179
180# make three commits, but tell it to apply only range
181
182test_expect_success 'submit --commit range' '
183 test_when_finished cleanup_git &&
184 git p4 clone --dest="$git" //depot &&
185 (
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 ) &&
193 (
194 cd "$cli" &&
195 test_path_is_missing "file11.t" &&
196 test_path_is_file "file12.t" &&
197 test_path_is_file "file13.t"
198 )
199'
200
0f224e5b
PW
201#
202# Basic submit tests, the five handled cases
203#
204
205test_expect_success 'submit modify' '
206 test_when_finished cleanup_git &&
207 git p4 clone --dest="$git" //depot &&
208 (
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 ) &&
216 (
217 cd "$cli" &&
218 test_path_is_file file1 &&
219 test_line_count = 2 file1
220 )
221'
222
223test_expect_success 'submit add' '
224 test_when_finished cleanup_git &&
225 git p4 clone --dest="$git" //depot &&
226 (
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 ) &&
234 (
235 cd "$cli" &&
236 test_path_is_file file13
237 )
238'
239
240test_expect_success 'submit delete' '
241 test_when_finished cleanup_git &&
242 git p4 clone --dest="$git" //depot &&
243 (
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 ) &&
250 (
251 cd "$cli" &&
252 test_path_is_missing file4.t
253 )
254'
255
256test_expect_success 'submit copy' '
257 test_when_finished cleanup_git &&
258 git p4 clone --dest="$git" //depot &&
259 (
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 ) &&
269 (
270 cd "$cli" &&
b6ad6dcc 271 test_path_is_file file5.ta &&
e9df0f9c 272 ! is_cli_file_writeable file5.ta
0f224e5b
PW
273 )
274'
275
276test_expect_success 'submit rename' '
277 test_when_finished cleanup_git &&
278 git p4 clone --dest="$git" //depot &&
279 (
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 ) &&
287 (
288 cd "$cli" &&
289 test_path_is_missing file6.t &&
b6ad6dcc 290 test_path_is_file file6.ta &&
e9df0f9c 291 ! is_cli_file_writeable file6.ta
0f224e5b
PW
292 )
293'
294
f19cb0a0
PW
295#
296# Converting git commit message to p4 change description, including
297# parsing out the optional Jobs: line.
298#
299test_expect_success 'simple one-line description' '
300 test_when_finished cleanup_git &&
301 git p4 clone --dest="$git" //depot &&
302 (
303 cd "$git" &&
304 echo desc2 >desc2 &&
305 git add desc2 &&
306 cat >msg <<-EOF &&
307 One-line description line for desc2.
308 EOF
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
317 )
318'
319
320test_expect_success 'description with odd formatting' '
321 test_when_finished cleanup_git &&
322 git p4 clone --dest="$git" //depot &&
323 (
324 cd "$git" &&
325 echo desc3 >desc3 &&
326 git add desc3 &&
327 (
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
341 )
342'
343
344make_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
351}
352
353test_expect_success 'description with Jobs section at end' '
354 test_when_finished cleanup_git &&
355 git p4 clone --dest="$git" //depot &&
356 (
357 cd "$git" &&
358 echo desc4 >desc4 &&
359 git add desc4 &&
360 echo 6060842 >jobname &&
361 (
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
382 )
383'
384
385test_expect_success 'description with Jobs and values on separate lines' '
386 test_when_finished cleanup_git &&
387 git p4 clone --dest="$git" //depot &&
388 (
389 cd "$git" &&
390 echo desc5 >desc5 &&
391 git add desc5 &&
392 echo PROJ-6060842 >jobname1 &&
393 echo PROJ-6060847 >jobname2 &&
394 (
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 &&
417 (
418 marshal_dump job0 <change &&
419 marshal_dump job1 <change
420 ) | sort >jobs &&
af7dd8bd 421 sort jobname1 jobname2 >expected &&
f19cb0a0
PW
422 test_cmp expected jobs
423 )
424'
425
426test_expect_success 'description with Jobs section and bogus following text' '
427 test_when_finished cleanup_git &&
428 git p4 clone --dest="$git" //depot &&
429 (
430 cd "$git" &&
431 echo desc6 >desc6 &&
432 git add desc6 &&
433 echo 6060843 >jobname &&
434 (
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 &&
6789275d 446 test_grep "Unknown field name" err
728b7ad8
PW
447 ) &&
448 (
449 cd "$cli" &&
450 p4 revert desc6 &&
b7638fed 451 rm -f desc6
728b7ad8
PW
452 )
453'
454
455test_expect_success 'submit --prepare-p4-only' '
456 test_when_finished cleanup_git &&
457 git p4 clone --dest="$git" //depot &&
458 (
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 &&
6789275d
JH
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
728b7ad8
PW
467 ) &&
468 (
469 cd "$cli" &&
470 test_path_is_file prep-only-add &&
471 p4 fstat -T action prep-only-add | grep -w add
f19cb0a0
PW
472 )
473'
474
b34fa577
VK
475test_expect_success 'submit --shelve' '
476 test_when_finished cleanup_git &&
477 git p4 clone --dest="$git" //depot &&
478 (
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^ &&
485
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^ &&
491
492 test_path_is_file shelveme1.t &&
493 test_path_is_file shelveme2.t
494 ) &&
495 (
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
503 )
504'
505
7a10bb3a
LD
506last_shelve () {
507 p4 -G changes -s shelved -m 1 //depot/... | marshal_dump change
508}
509
8cf422db
LD
510make_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
514}
515
516# Update existing shelved changelists
46c609e9
LD
517
518test_expect_success 'submit --update-shelve' '
519 test_when_finished cleanup_git &&
520 git p4 clone --dest="$git" //depot &&
521 (
522 cd "$cli" &&
523 p4 revert ... &&
524 cd "$git" &&
525 git config git-p4.skipSubmitEdit true &&
8cf422db
LD
526 shelved_cl0=$(make_shelved_cl "shelved-change-0") &&
527 echo shelved_cl0=$shelved_cl0 &&
528 shelved_cl1=$(make_shelved_cl "shelved-change-1") &&
46c609e9 529
8cf422db 530 echo "updating shelved change lists $shelved_cl0 and $shelved_cl1" &&
46c609e9
LD
531
532 echo "updated-line" >>shelf.t &&
533 echo added-file.t >added-file.t &&
534 git add shelf.t added-file.t &&
8cf422db 535 git rm -f shelved-change-1.t &&
46c609e9
LD
536 git commit --amend -C HEAD &&
537 git show --stat HEAD &&
8cf422db 538 git p4 submit -v --origin HEAD~2 --update-shelve $shelved_cl0 --update-shelve $shelved_cl1 &&
46c609e9
LD
539 echo "done git p4 submit"
540 ) &&
541 (
542 cd "$cli" &&
7a10bb3a 543 change=$(last_shelve) &&
46c609e9
LD
544 p4 unshelve -c $change -s $change &&
545 grep -q updated-line shelf.t &&
546 p4 describe -S $change | grep added-file.t &&
7a10bb3a
LD
547 test_path_is_missing shelved-change-1.t &&
548 p4 revert ...
549 )
550'
551
7a10946a 552test_expect_success 'update a shelve involving moved and copied files' '
7a10bb3a
LD
553 test_when_finished cleanup_git &&
554 (
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 &&
565 (
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 ) &&
583 (
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"
46c609e9
LD
596 )
597'
598
c145225a 599test_done