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 'submit with no client dir' '
21 test_when_finished cleanup_git &&
22 git p4 clone --dest="$git" //depot &&
27 git commit -m "git commit 2" &&
29 git config git-p4.skipSubmitEdit true &&
34 test_path_is_file file1 &&
35 test_path_is_file file2
39 # make two commits, but tell it to apply only from HEAD^
40 test_expect_success 'submit --origin' '
41 test_when_finished cleanup_git &&
42 git p4 clone --dest="$git" //depot &&
45 test_commit "file3" &&
46 test_commit "file4" &&
47 git config git-p4.skipSubmitEdit true &&
48 git p4 submit --origin=HEAD^
52 test_path_is_missing "file3.t" &&
53 test_path_is_file "file4.t"
57 test_expect_success 'submit --dry-run' '
58 test_when_finished cleanup_git &&
59 git p4 clone --dest="$git" //depot &&
62 test_commit "dry-run1" &&
63 test_commit "dry-run2" &&
64 git p4 submit --dry-run >out &&
65 test_i18ngrep "Would apply" out
69 test_path_is_missing "dry-run1.t" &&
70 test_path_is_missing "dry-run2.t"
74 test_expect_success 'submit --dry-run --export-labels' '
75 test_when_finished cleanup_git &&
76 git p4 clone --dest="$git" //depot &&
79 echo dry-run1 >dry-run1 &&
81 git commit -m "dry-run1" dry-run1 &&
82 git config git-p4.skipSubmitEdit true &&
84 echo dry-run2 >dry-run2 &&
86 git commit -m "dry-run2" dry-run2 &&
87 git tag -m "dry-run-tag1" dry-run-tag1 HEAD^ &&
88 git p4 submit --dry-run --export-labels >out &&
89 test_i18ngrep "Would create p4 label" out
93 test_path_is_file "dry-run1" &&
94 test_path_is_missing "dry-run2"
98 test_expect_success 'submit with allowSubmit' '
99 test_when_finished cleanup_git &&
100 git p4 clone --dest="$git" //depot &&
103 test_commit "file5" &&
104 git config git-p4.skipSubmitEdit true &&
105 git config git-p4.allowSubmit "nobranch" &&
106 test_must_fail git p4 submit &&
107 git config git-p4.allowSubmit "nobranch,master" &&
112 test_expect_success 'submit with master branch name from argv' '
113 test_when_finished cleanup_git &&
114 git p4 clone --dest="$git" //depot &&
117 test_commit "file6" &&
118 git config git-p4.skipSubmitEdit true &&
119 test_must_fail git p4 submit nobranch &&
120 git branch otherbranch &&
121 git reset --hard HEAD^ &&
122 test_commit "file7" &&
123 git p4 submit otherbranch
127 test_path_is_file "file6.t" &&
128 test_path_is_missing "file7.t"
133 # Basic submit tests, the five handled cases
136 test_expect_success 'submit modify' '
137 test_when_finished cleanup_git &&
138 git p4 clone --dest="$git" //depot &&
141 git config git-p4.skipSubmitEdit true &&
144 git commit -m file1 &&
149 test_path_is_file file1 &&
150 test_line_count = 2 file1
154 test_expect_success 'submit add' '
155 test_when_finished cleanup_git &&
156 git p4 clone --dest="$git" //depot &&
159 git config git-p4.skipSubmitEdit true &&
160 echo file13 >file13 &&
162 git commit -m file13 &&
167 test_path_is_file file13
171 test_expect_success 'submit delete' '
172 test_when_finished cleanup_git &&
173 git p4 clone --dest="$git" //depot &&
176 git config git-p4.skipSubmitEdit true &&
178 git commit -m "delete file4.t" &&
183 test_path_is_missing file4.t
187 test_expect_success 'submit copy' '
188 test_when_finished cleanup_git &&
189 git p4 clone --dest="$git" //depot &&
192 git config git-p4.skipSubmitEdit true &&
193 git config git-p4.detectCopies true &&
194 git config git-p4.detectCopiesHarder true &&
195 cp file5.t file5.ta &&
197 git commit -m "copy to file5.ta" &&
202 test_path_is_file file5.ta &&
207 test_expect_success 'submit rename' '
208 test_when_finished cleanup_git &&
209 git p4 clone --dest="$git" //depot &&
212 git config git-p4.skipSubmitEdit true &&
213 git config git-p4.detectRenames true &&
214 git mv file6.t file6.ta &&
215 git commit -m "rename file6.t to file6.ta" &&
220 test_path_is_missing file6.t &&
221 test_path_is_file file6.ta &&
227 # Converting git commit message to p4 change description, including
228 # parsing out the optional Jobs: line.
230 test_expect_success 'simple one-line description' '
231 test_when_finished cleanup_git &&
232 git p4 clone --dest="$git" //depot &&
238 One-line description line for desc2.
240 git commit -F - <msg &&
241 git config git-p4.skipSubmitEdit true &&
243 change=$(p4 -G changes -m 1 //depot/... | \
244 marshal_dump change) &&
245 # marshal_dump always adds a newline
246 p4 -G describe $change | marshal_dump desc | sed \$d >pmsg &&
251 test_expect_success 'description with odd formatting' '
252 test_when_finished cleanup_git &&
253 git p4 clone --dest="$git" //depot &&
259 printf "subject line\n\n\tExtra tab\nline.\n\n" &&
260 printf "Description:\n\tBogus description marker\n\n" &&
261 # git commit eats trailing newlines; only use one
262 printf "Files:\n\tBogus descs marker\n"
264 git commit -F - <msg &&
265 git config git-p4.skipSubmitEdit true &&
267 change=$(p4 -G changes -m 1 //depot/... | \
268 marshal_dump change) &&
269 # marshal_dump always adds a newline
270 p4 -G describe $change | marshal_dump desc | sed \$d >pmsg &&
277 tab="$(printf \\t)" &&
279 sed -e "/^Job:/s/.*/Job: $name/" \
280 -e "/^Description/{ n; s/.*/$tab job text/; }" | \
284 test_expect_success 'description with Jobs section at end' '
285 test_when_finished cleanup_git &&
286 git p4 clone --dest="$git" //depot &&
291 echo 6060842 >jobname &&
293 printf "subject line\n\n\tExtra tab\nline.\n\n" &&
294 printf "Files:\n\tBogus files marker\n" &&
295 printf "Junk: 3164175\n" &&
296 printf "Jobs: $(cat jobname)\n"
298 git commit -F - <msg &&
299 git config git-p4.skipSubmitEdit true &&
301 make_job $(cat jobname) &&
303 change=$(p4 -G changes -m 1 //depot/... | \
304 marshal_dump change) &&
305 # marshal_dump always adds a newline
306 p4 -G describe $change | marshal_dump desc | sed \$d >pmsg &&
307 # make sure Jobs line and all following is gone
308 sed "/^Jobs:/,\$d" msg >jmsg &&
309 test_cmp jmsg pmsg &&
310 # make sure p4 knows about job
311 p4 -G describe $change | marshal_dump job0 >job0 &&
312 test_cmp jobname job0
316 test_expect_success 'description with Jobs and values on separate lines' '
317 test_when_finished cleanup_git &&
318 git p4 clone --dest="$git" //depot &&
323 echo PROJ-6060842 >jobname1 &&
324 echo PROJ-6060847 >jobname2 &&
326 printf "subject line\n\n\tExtra tab\nline.\n\n" &&
327 printf "Files:\n\tBogus files marker\n" &&
328 printf "Junk: 3164175\n" &&
330 printf "\t$(cat jobname1)\n" &&
331 printf "\t$(cat jobname2)\n"
333 git commit -F - <msg &&
334 git config git-p4.skipSubmitEdit true &&
336 make_job $(cat jobname1) &&
337 make_job $(cat jobname2) &&
339 change=$(p4 -G changes -m 1 //depot/... | \
340 marshal_dump change) &&
341 # marshal_dump always adds a newline
342 p4 -G describe $change | marshal_dump desc | sed \$d >pmsg &&
343 # make sure Jobs line and all following is gone
344 sed "/^Jobs:/,\$d" msg >jmsg &&
345 test_cmp jmsg pmsg &&
346 # make sure p4 knows about the two jobs
347 p4 -G describe $change >change &&
349 marshal_dump job0 <change &&
350 marshal_dump job1 <change
352 cat jobname1 jobname2 | sort >expected &&
353 test_cmp expected jobs
357 test_expect_success 'description with Jobs section and bogus following text' '
358 test_when_finished cleanup_git &&
359 git p4 clone --dest="$git" //depot &&
364 echo 6060843 >jobname &&
366 printf "subject line\n\n\tExtra tab\nline.\n\n" &&
367 printf "Files:\n\tBogus files marker\n" &&
368 printf "Junk: 3164175\n" &&
369 printf "Jobs: $(cat jobname)\n" &&
370 printf "MoreJunk: 3711\n"
372 git commit -F - <msg &&
373 git config git-p4.skipSubmitEdit true &&
375 make_job $(cat jobname) &&
376 test_must_fail git p4 submit 2>err &&
377 test_i18ngrep "Unknown field name" err
386 test_expect_success 'submit --prepare-p4-only' '
387 test_when_finished cleanup_git &&
388 git p4 clone --dest="$git" //depot &&
391 echo prep-only-add >prep-only-add &&
392 git add prep-only-add &&
393 git commit -m "prep only add" &&
394 git p4 submit --prepare-p4-only >out &&
395 test_i18ngrep "prepared for submission" out &&
396 test_i18ngrep "must be deleted" out
400 test_path_is_file prep-only-add &&
401 p4 fstat -T action prep-only-add | grep -w add
405 test_expect_success 'kill p4d' '