3 test_description='git p4 submit'
7 test_expect_success 'start p4d' '
11 test_expect_success 'init depot' '
16 p4 submit -d "change 1"
20 test_expect_success 'is_cli_file_writeable function' '
24 is_cli_file_writeable a &&
25 ! is_cli_file_writeable file1 &&
30 test_expect_success 'submit with no client dir' '
31 test_when_finished cleanup_git &&
32 git p4 clone --dest="$git" //depot &&
37 git commit -m "git commit 2" &&
39 git config git-p4.skipSubmitEdit true &&
44 test_path_is_file file1 &&
45 test_path_is_file file2
49 # make two commits, but tell it to apply only from HEAD^
50 test_expect_success 'submit --origin' '
51 test_when_finished cleanup_git &&
52 git p4 clone --dest="$git" //depot &&
55 test_commit "file3" &&
56 test_commit "file4" &&
57 git config git-p4.skipSubmitEdit true &&
58 git p4 submit --origin=HEAD^
62 test_path_is_missing "file3.t" &&
63 test_path_is_file "file4.t"
67 test_expect_success 'submit --dry-run' '
68 test_when_finished cleanup_git &&
69 git p4 clone --dest="$git" //depot &&
72 test_commit "dry-run1" &&
73 test_commit "dry-run2" &&
74 git p4 submit --dry-run >out &&
75 test_i18ngrep "Would apply" out
79 test_path_is_missing "dry-run1.t" &&
80 test_path_is_missing "dry-run2.t"
84 test_expect_success 'submit --dry-run --export-labels' '
85 test_when_finished cleanup_git &&
86 git p4 clone --dest="$git" //depot &&
89 echo dry-run1 >dry-run1 &&
91 git commit -m "dry-run1" dry-run1 &&
92 git config git-p4.skipSubmitEdit true &&
94 echo dry-run2 >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
103 test_path_is_file "dry-run1" &&
104 test_path_is_missing "dry-run2"
108 test_expect_success 'submit with allowSubmit' '
109 test_when_finished cleanup_git &&
110 git p4 clone --dest="$git" //depot &&
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" &&
122 test_expect_success 'submit with master branch name from argv' '
123 test_when_finished cleanup_git &&
124 git p4 clone --dest="$git" //depot &&
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
137 test_path_is_file "file6.t" &&
138 test_path_is_missing "file7.t"
142 test_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 &&
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 &&
159 # Basic submit tests, the five handled cases
162 test_expect_success 'submit modify' '
163 test_when_finished cleanup_git &&
164 git p4 clone --dest="$git" //depot &&
167 git config git-p4.skipSubmitEdit true &&
170 git commit -m file1 &&
175 test_path_is_file file1 &&
176 test_line_count = 2 file1
180 test_expect_success 'submit add' '
181 test_when_finished cleanup_git &&
182 git p4 clone --dest="$git" //depot &&
185 git config git-p4.skipSubmitEdit true &&
186 echo file13 >file13 &&
188 git commit -m file13 &&
193 test_path_is_file file13
197 test_expect_success 'submit delete' '
198 test_when_finished cleanup_git &&
199 git p4 clone --dest="$git" //depot &&
202 git config git-p4.skipSubmitEdit true &&
204 git commit -m "delete file4.t" &&
209 test_path_is_missing file4.t
213 test_expect_success 'submit copy' '
214 test_when_finished cleanup_git &&
215 git p4 clone --dest="$git" //depot &&
218 git config git-p4.skipSubmitEdit true &&
219 git config git-p4.detectCopies true &&
220 git config git-p4.detectCopiesHarder true &&
221 cp file5.t file5.ta &&
223 git commit -m "copy to file5.ta" &&
228 test_path_is_file file5.ta &&
229 ! is_cli_file_writeable file5.ta
233 test_expect_success 'submit rename' '
234 test_when_finished cleanup_git &&
235 git p4 clone --dest="$git" //depot &&
238 git config git-p4.skipSubmitEdit true &&
239 git config git-p4.detectRenames true &&
240 git mv file6.t file6.ta &&
241 git commit -m "rename file6.t to file6.ta" &&
246 test_path_is_missing file6.t &&
247 test_path_is_file file6.ta &&
248 ! is_cli_file_writeable file6.ta
253 # Converting git commit message to p4 change description, including
254 # parsing out the optional Jobs: line.
256 test_expect_success 'simple one-line description' '
257 test_when_finished cleanup_git &&
258 git p4 clone --dest="$git" //depot &&
264 One-line description line for desc2.
266 git commit -F - <msg &&
267 git config git-p4.skipSubmitEdit true &&
269 change=$(p4 -G changes -m 1 //depot/... | \
270 marshal_dump change) &&
271 # marshal_dump always adds a newline
272 p4 -G describe $change | marshal_dump desc | sed \$d >pmsg &&
277 test_expect_success 'description with odd formatting' '
278 test_when_finished cleanup_git &&
279 git p4 clone --dest="$git" //depot &&
285 printf "subject line\n\n\tExtra tab\nline.\n\n" &&
286 printf "Description:\n\tBogus description marker\n\n" &&
287 # git commit eats trailing newlines; only use one
288 printf "Files:\n\tBogus descs marker\n"
290 git commit -F - <msg &&
291 git config git-p4.skipSubmitEdit true &&
293 change=$(p4 -G changes -m 1 //depot/... | \
294 marshal_dump change) &&
295 # marshal_dump always adds a newline
296 p4 -G describe $change | marshal_dump desc | sed \$d >pmsg &&
303 tab="$(printf \\t)" &&
305 sed -e "/^Job:/s/.*/Job: $name/" \
306 -e "/^Description/{ n; s/.*/$tab job text/; }" | \
310 test_expect_success 'description with Jobs section at end' '
311 test_when_finished cleanup_git &&
312 git p4 clone --dest="$git" //depot &&
317 echo 6060842 >jobname &&
319 printf "subject line\n\n\tExtra tab\nline.\n\n" &&
320 printf "Files:\n\tBogus files marker\n" &&
321 printf "Junk: 3164175\n" &&
322 printf "Jobs: $(cat jobname)\n"
324 git commit -F - <msg &&
325 git config git-p4.skipSubmitEdit true &&
327 make_job $(cat jobname) &&
329 change=$(p4 -G changes -m 1 //depot/... | \
330 marshal_dump change) &&
331 # marshal_dump always adds a newline
332 p4 -G describe $change | marshal_dump desc | sed \$d >pmsg &&
333 # make sure Jobs line and all following is gone
334 sed "/^Jobs:/,\$d" msg >jmsg &&
335 test_cmp jmsg pmsg &&
336 # make sure p4 knows about job
337 p4 -G describe $change | marshal_dump job0 >job0 &&
338 test_cmp jobname job0
342 test_expect_success 'description with Jobs and values on separate lines' '
343 test_when_finished cleanup_git &&
344 git p4 clone --dest="$git" //depot &&
349 echo PROJ-6060842 >jobname1 &&
350 echo PROJ-6060847 >jobname2 &&
352 printf "subject line\n\n\tExtra tab\nline.\n\n" &&
353 printf "Files:\n\tBogus files marker\n" &&
354 printf "Junk: 3164175\n" &&
356 printf "\t$(cat jobname1)\n" &&
357 printf "\t$(cat jobname2)\n"
359 git commit -F - <msg &&
360 git config git-p4.skipSubmitEdit true &&
362 make_job $(cat jobname1) &&
363 make_job $(cat jobname2) &&
365 change=$(p4 -G changes -m 1 //depot/... | \
366 marshal_dump change) &&
367 # marshal_dump always adds a newline
368 p4 -G describe $change | marshal_dump desc | sed \$d >pmsg &&
369 # make sure Jobs line and all following is gone
370 sed "/^Jobs:/,\$d" msg >jmsg &&
371 test_cmp jmsg pmsg &&
372 # make sure p4 knows about the two jobs
373 p4 -G describe $change >change &&
375 marshal_dump job0 <change &&
376 marshal_dump job1 <change
378 cat jobname1 jobname2 | sort >expected &&
379 test_cmp expected jobs
383 test_expect_success 'description with Jobs section and bogus following text' '
384 test_when_finished cleanup_git &&
385 git p4 clone --dest="$git" //depot &&
390 echo 6060843 >jobname &&
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: $(cat jobname)\n" &&
396 printf "MoreJunk: 3711\n"
398 git commit -F - <msg &&
399 git config git-p4.skipSubmitEdit true &&
401 make_job $(cat jobname) &&
402 test_must_fail git p4 submit 2>err &&
403 test_i18ngrep "Unknown field name" err
412 test_expect_success 'submit --prepare-p4-only' '
413 test_when_finished cleanup_git &&
414 git p4 clone --dest="$git" //depot &&
417 echo prep-only-add >prep-only-add &&
418 git add prep-only-add &&
419 git commit -m "prep only add" &&
420 git p4 submit --prepare-p4-only >out &&
421 test_i18ngrep "prepared for submission" out &&
422 test_i18ngrep "must be deleted" out &&
423 test_i18ngrep ! "everything below this line is just the diff" out
427 test_path_is_file prep-only-add &&
428 p4 fstat -T action prep-only-add | grep -w add
432 test_expect_success 'submit --shelve' '
433 test_when_finished cleanup_git &&
434 git p4 clone --dest="$git" //depot &&
439 git config git-p4.skipSubmitEdit true &&
440 test_commit "shelveme1" &&
441 git p4 submit --origin=HEAD^ &&
443 echo 654321 >shelveme2.t &&
444 echo 123456 >>shelveme1.t &&
446 git commit -m"shelvetest" &&
447 git p4 submit --shelve --origin=HEAD^ &&
449 test_path_is_file shelveme1.t &&
450 test_path_is_file shelveme2.t
454 change=$(p4 -G changes -s shelved -m 1 //depot/... | \
455 marshal_dump change) &&
456 p4 describe -S $change | grep shelveme2 &&
457 p4 describe -S $change | grep 123456 &&
458 test_path_is_file shelveme1.t &&
459 test_path_is_missing shelveme2.t
463 # Update an existing shelved changelist
465 test_expect_success 'submit --update-shelve' '
466 test_when_finished cleanup_git &&
467 git p4 clone --dest="$git" //depot &&
472 git config git-p4.skipSubmitEdit true &&
473 test_commit "test-update-shelved-change" &&
474 git p4 submit --origin=HEAD^ --shelve &&
476 shelf_cl=$(p4 -G changes -s shelved -m 1 |\
477 marshal_dump change) &&
479 echo "updating shelved change list $shelf_cl" &&
481 echo "updated-line" >>shelf.t &&
482 echo added-file.t >added-file.t &&
483 git add shelf.t added-file.t &&
484 git rm -f test-update-shelved-change.t &&
485 git commit --amend -C HEAD &&
486 git show --stat HEAD &&
487 git p4 submit -v --origin HEAD^ --update-shelve $shelf_cl &&
488 echo "done git p4 submit"
492 change=$(p4 -G changes -s shelved -m 1 //depot/... | \
493 marshal_dump change) &&
494 p4 unshelve -c $change -s $change &&
495 grep -q updated-line shelf.t &&
496 p4 describe -S $change | grep added-file.t &&
497 test_path_is_missing test-update-shelved-change.t
501 test_expect_success 'kill p4d' '