sha1_name: use bsearch_pack() in unique_in_pack()
[alt-git.git] / t / t9807-git-p4-submit.sh
blob71cae2874d935e16b951160c9a3fa0014fe2db27
1 #!/bin/sh
3 test_description='git p4 submit'
5 . ./lib-git-p4.sh
7 test_expect_success 'start p4d' '
8 start_p4d
11 test_expect_success 'init depot' '
13 cd "$cli" &&
14 echo file1 >file1 &&
15 p4 add file1 &&
16 p4 submit -d "change 1"
20 test_expect_success 'is_cli_file_writeable function' '
22 cd "$cli" &&
23 echo a >a &&
24 is_cli_file_writeable a &&
25 ! is_cli_file_writeable file1 &&
26 rm a
30 test_expect_success 'submit with no client dir' '
31 test_when_finished cleanup_git &&
32 git p4 clone --dest="$git" //depot &&
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 ) &&
43 cd "$cli" &&
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 &&
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 ) &&
61 cd "$cli" &&
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 &&
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 ) &&
78 cd "$cli" &&
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 &&
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 ) &&
102 cd "$cli" &&
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 &&
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
122 test_expect_success 'submit with master branch name from argv' '
123 test_when_finished cleanup_git &&
124 git p4 clone --dest="$git" //depot &&
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 ) &&
136 cd "$cli" &&
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 &&
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
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 &&
166 cd "$git" &&
167 git config git-p4.skipSubmitEdit true &&
168 echo line >>file1 &&
169 git add file1 &&
170 git commit -m file1 &&
171 git p4 submit
172 ) &&
174 cd "$cli" &&
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 &&
184 cd "$git" &&
185 git config git-p4.skipSubmitEdit true &&
186 echo file13 >file13 &&
187 git add file13 &&
188 git commit -m file13 &&
189 git p4 submit
190 ) &&
192 cd "$cli" &&
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 &&
201 cd "$git" &&
202 git config git-p4.skipSubmitEdit true &&
203 git rm file4.t &&
204 git commit -m "delete file4.t" &&
205 git p4 submit
206 ) &&
208 cd "$cli" &&
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 &&
217 cd "$git" &&
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 &&
222 git add file5.ta &&
223 git commit -m "copy to file5.ta" &&
224 git p4 submit
225 ) &&
227 cd "$cli" &&
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 &&
237 cd "$git" &&
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" &&
242 git p4 submit
243 ) &&
245 cd "$cli" &&
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 &&
260 cd "$git" &&
261 echo desc2 >desc2 &&
262 git add desc2 &&
263 cat >msg <<-EOF &&
264 One-line description line for desc2.
266 git commit -F - <msg &&
267 git config git-p4.skipSubmitEdit true &&
268 git p4 submit &&
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 &&
273 test_cmp msg pmsg
277 test_expect_success 'description with odd formatting' '
278 test_when_finished cleanup_git &&
279 git p4 clone --dest="$git" //depot &&
281 cd "$git" &&
282 echo desc3 >desc3 &&
283 git add desc3 &&
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"
289 ) >msg &&
290 git commit -F - <msg &&
291 git config git-p4.skipSubmitEdit true &&
292 git p4 submit &&
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 &&
297 test_cmp msg pmsg
301 make_job() {
302 name="$1" &&
303 tab="$(printf \\t)" &&
304 p4 job -o | \
305 sed -e "/^Job:/s/.*/Job: $name/" \
306 -e "/^Description/{ n; s/.*/$tab job text/; }" | \
307 p4 job -i
310 test_expect_success 'description with Jobs section at end' '
311 test_when_finished cleanup_git &&
312 git p4 clone --dest="$git" //depot &&
314 cd "$git" &&
315 echo desc4 >desc4 &&
316 git add desc4 &&
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"
323 ) >msg &&
324 git commit -F - <msg &&
325 git config git-p4.skipSubmitEdit true &&
326 # build a job
327 make_job $(cat jobname) &&
328 git p4 submit &&
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 &&
346 cd "$git" &&
347 echo desc5 >desc5 &&
348 git add desc5 &&
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" &&
355 printf "Jobs:\n" &&
356 printf "\t$(cat jobname1)\n" &&
357 printf "\t$(cat jobname2)\n"
358 ) >msg &&
359 git commit -F - <msg &&
360 git config git-p4.skipSubmitEdit true &&
361 # build two jobs
362 make_job $(cat jobname1) &&
363 make_job $(cat jobname2) &&
364 git p4 submit &&
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
377 ) | sort >jobs &&
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 &&
387 cd "$git" &&
388 echo desc6 >desc6 &&
389 git add desc6 &&
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"
397 ) >msg &&
398 git commit -F - <msg &&
399 git config git-p4.skipSubmitEdit true &&
400 # build a job
401 make_job $(cat jobname) &&
402 test_must_fail git p4 submit 2>err &&
403 test_i18ngrep "Unknown field name" err
404 ) &&
406 cd "$cli" &&
407 p4 revert desc6 &&
408 rm -f desc6
412 test_expect_success 'submit --prepare-p4-only' '
413 test_when_finished cleanup_git &&
414 git p4 clone --dest="$git" //depot &&
416 cd "$git" &&
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
424 ) &&
426 cd "$cli" &&
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 &&
436 cd "$cli" &&
437 p4 revert ... &&
438 cd "$git" &&
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 &&
445 git add shelveme* &&
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
451 ) &&
453 cd "$cli" &&
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 make_shelved_cl() {
464 test_commit "$1" >/dev/null &&
465 git p4 submit --origin HEAD^ --shelve >/dev/null &&
466 p4 -G changes -s shelved -m 1 | marshal_dump change
469 # Update existing shelved changelists
471 test_expect_success 'submit --update-shelve' '
472 test_when_finished cleanup_git &&
473 git p4 clone --dest="$git" //depot &&
475 cd "$cli" &&
476 p4 revert ... &&
477 cd "$git" &&
478 git config git-p4.skipSubmitEdit true &&
479 shelved_cl0=$(make_shelved_cl "shelved-change-0") &&
480 echo shelved_cl0=$shelved_cl0 &&
481 shelved_cl1=$(make_shelved_cl "shelved-change-1") &&
483 echo "updating shelved change lists $shelved_cl0 and $shelved_cl1" &&
485 echo "updated-line" >>shelf.t &&
486 echo added-file.t >added-file.t &&
487 git add shelf.t added-file.t &&
488 git rm -f shelved-change-1.t &&
489 git commit --amend -C HEAD &&
490 git show --stat HEAD &&
491 git p4 submit -v --origin HEAD~2 --update-shelve $shelved_cl0 --update-shelve $shelved_cl1 &&
492 echo "done git p4 submit"
493 ) &&
495 cd "$cli" &&
496 change=$(p4 -G changes -s shelved -m 1 //depot/... | \
497 marshal_dump change) &&
498 p4 unshelve -c $change -s $change &&
499 grep -q updated-line shelf.t &&
500 p4 describe -S $change | grep added-file.t &&
501 test_path_is_missing shelved-change-1.t
505 test_expect_success 'kill p4d' '
506 kill_p4d
509 test_done