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_failure
'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"
143 # Basic submit tests, the five handled cases
146 test_expect_success
'submit modify' '
147 test_when_finished cleanup_git &&
148 git p4 clone --dest="$git" //depot &&
151 git config git-p4.skipSubmitEdit true &&
154 git commit -m file1 &&
159 test_path_is_file file1 &&
160 test_line_count = 2 file1
164 test_expect_success
'submit add' '
165 test_when_finished cleanup_git &&
166 git p4 clone --dest="$git" //depot &&
169 git config git-p4.skipSubmitEdit true &&
170 echo file13 >file13 &&
172 git commit -m file13 &&
177 test_path_is_file file13
181 test_expect_success
'submit delete' '
182 test_when_finished cleanup_git &&
183 git p4 clone --dest="$git" //depot &&
186 git config git-p4.skipSubmitEdit true &&
188 git commit -m "delete file4.t" &&
193 test_path_is_missing file4.t
197 test_expect_success
'submit copy' '
198 test_when_finished cleanup_git &&
199 git p4 clone --dest="$git" //depot &&
202 git config git-p4.skipSubmitEdit true &&
203 git config git-p4.detectCopies true &&
204 git config git-p4.detectCopiesHarder true &&
205 cp file5.t file5.ta &&
207 git commit -m "copy to file5.ta" &&
212 test_path_is_file file5.ta &&
213 ! is_cli_file_writeable file5.ta
217 test_expect_success
'submit rename' '
218 test_when_finished cleanup_git &&
219 git p4 clone --dest="$git" //depot &&
222 git config git-p4.skipSubmitEdit true &&
223 git config git-p4.detectRenames true &&
224 git mv file6.t file6.ta &&
225 git commit -m "rename file6.t to file6.ta" &&
230 test_path_is_missing file6.t &&
231 test_path_is_file file6.ta &&
232 ! is_cli_file_writeable file6.ta
237 # Converting git commit message to p4 change description, including
238 # parsing out the optional Jobs: line.
240 test_expect_success
'simple one-line description' '
241 test_when_finished cleanup_git &&
242 git p4 clone --dest="$git" //depot &&
248 One-line description line for desc2.
250 git commit -F - <msg &&
251 git config git-p4.skipSubmitEdit true &&
253 change=$(p4 -G changes -m 1 //depot/... | \
254 marshal_dump change) &&
255 # marshal_dump always adds a newline
256 p4 -G describe $change | marshal_dump desc | sed \$d >pmsg &&
261 test_expect_success
'description with odd formatting' '
262 test_when_finished cleanup_git &&
263 git p4 clone --dest="$git" //depot &&
269 printf "subject line\n\n\tExtra tab\nline.\n\n" &&
270 printf "Description:\n\tBogus description marker\n\n" &&
271 # git commit eats trailing newlines; only use one
272 printf "Files:\n\tBogus descs marker\n"
274 git commit -F - <msg &&
275 git config git-p4.skipSubmitEdit true &&
277 change=$(p4 -G changes -m 1 //depot/... | \
278 marshal_dump change) &&
279 # marshal_dump always adds a newline
280 p4 -G describe $change | marshal_dump desc | sed \$d >pmsg &&
287 tab
="$(printf \\t)" &&
289 sed -e "/^Job:/s/.*/Job: $name/" \
290 -e "/^Description/{ n; s/.*/$tab job text/; }" | \
294 test_expect_success
'description with Jobs section at end' '
295 test_when_finished cleanup_git &&
296 git p4 clone --dest="$git" //depot &&
301 echo 6060842 >jobname &&
303 printf "subject line\n\n\tExtra tab\nline.\n\n" &&
304 printf "Files:\n\tBogus files marker\n" &&
305 printf "Junk: 3164175\n" &&
306 printf "Jobs: $(cat jobname)\n"
308 git commit -F - <msg &&
309 git config git-p4.skipSubmitEdit true &&
311 make_job $(cat jobname) &&
313 change=$(p4 -G changes -m 1 //depot/... | \
314 marshal_dump change) &&
315 # marshal_dump always adds a newline
316 p4 -G describe $change | marshal_dump desc | sed \$d >pmsg &&
317 # make sure Jobs line and all following is gone
318 sed "/^Jobs:/,\$d" msg >jmsg &&
319 test_cmp jmsg pmsg &&
320 # make sure p4 knows about job
321 p4 -G describe $change | marshal_dump job0 >job0 &&
322 test_cmp jobname job0
326 test_expect_success
'description with Jobs and values on separate lines' '
327 test_when_finished cleanup_git &&
328 git p4 clone --dest="$git" //depot &&
333 echo PROJ-6060842 >jobname1 &&
334 echo PROJ-6060847 >jobname2 &&
336 printf "subject line\n\n\tExtra tab\nline.\n\n" &&
337 printf "Files:\n\tBogus files marker\n" &&
338 printf "Junk: 3164175\n" &&
340 printf "\t$(cat jobname1)\n" &&
341 printf "\t$(cat jobname2)\n"
343 git commit -F - <msg &&
344 git config git-p4.skipSubmitEdit true &&
346 make_job $(cat jobname1) &&
347 make_job $(cat jobname2) &&
349 change=$(p4 -G changes -m 1 //depot/... | \
350 marshal_dump change) &&
351 # marshal_dump always adds a newline
352 p4 -G describe $change | marshal_dump desc | sed \$d >pmsg &&
353 # make sure Jobs line and all following is gone
354 sed "/^Jobs:/,\$d" msg >jmsg &&
355 test_cmp jmsg pmsg &&
356 # make sure p4 knows about the two jobs
357 p4 -G describe $change >change &&
359 marshal_dump job0 <change &&
360 marshal_dump job1 <change
362 cat jobname1 jobname2 | sort >expected &&
363 test_cmp expected jobs
367 test_expect_success
'description with Jobs section and bogus following text' '
368 test_when_finished cleanup_git &&
369 git p4 clone --dest="$git" //depot &&
374 echo 6060843 >jobname &&
376 printf "subject line\n\n\tExtra tab\nline.\n\n" &&
377 printf "Files:\n\tBogus files marker\n" &&
378 printf "Junk: 3164175\n" &&
379 printf "Jobs: $(cat jobname)\n" &&
380 printf "MoreJunk: 3711\n"
382 git commit -F - <msg &&
383 git config git-p4.skipSubmitEdit true &&
385 make_job $(cat jobname) &&
386 test_must_fail git p4 submit 2>err &&
387 test_i18ngrep "Unknown field name" err
396 test_expect_success
'submit --prepare-p4-only' '
397 test_when_finished cleanup_git &&
398 git p4 clone --dest="$git" //depot &&
401 echo prep-only-add >prep-only-add &&
402 git add prep-only-add &&
403 git commit -m "prep only add" &&
404 git p4 submit --prepare-p4-only >out &&
405 test_i18ngrep "prepared for submission" out &&
406 test_i18ngrep "must be deleted" out
410 test_path_is_file prep-only-add &&
411 p4 fstat -T action prep-only-add | grep -w add
415 test_expect_success
'kill p4d' '