diffcore-break: don't divide by zero
[git/jnareb-git.git] / t / t9807-git-p4-submit.sh
blob0ae048f29f548eac6cfa37fbabcd9b7f80440515
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 'submit with no client dir' '
21 test_when_finished cleanup_git &&
22 git p4 clone --dest="$git" //depot &&
24 cd "$git" &&
25 echo file2 >file2 &&
26 git add file2 &&
27 git commit -m "git commit 2" &&
28 rm -rf "$cli" &&
29 git config git-p4.skipSubmitEdit true &&
30 git p4 submit
31 ) &&
33 cd "$cli" &&
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 &&
44 cd "$git" &&
45 test_commit "file3" &&
46 test_commit "file4" &&
47 git config git-p4.skipSubmitEdit true &&
48 git p4 submit --origin=HEAD^
49 ) &&
51 cd "$cli" &&
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 &&
61 cd "$git" &&
62 test_commit "dry-run1" &&
63 test_commit "dry-run2" &&
64 git p4 submit --dry-run >out &&
65 test_i18ngrep "Would apply" out
66 ) &&
68 cd "$cli" &&
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 &&
78 cd "$git" &&
79 echo dry-run1 >dry-run1 &&
80 git add dry-run1 &&
81 git commit -m "dry-run1" dry-run1 &&
82 git config git-p4.skipSubmitEdit true &&
83 git p4 submit &&
84 echo dry-run2 >dry-run2 &&
85 git add 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
90 ) &&
92 cd "$cli" &&
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 &&
102 cd "$git" &&
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" &&
108 git p4 submit
112 test_expect_success 'submit with master branch name from argv' '
113 test_when_finished cleanup_git &&
114 git p4 clone --dest="$git" //depot &&
116 cd "$git" &&
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
124 ) &&
126 cd "$cli" &&
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 &&
140 cd "$git" &&
141 git config git-p4.skipSubmitEdit true &&
142 echo line >>file1 &&
143 git add file1 &&
144 git commit -m file1 &&
145 git p4 submit
146 ) &&
148 cd "$cli" &&
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 &&
158 cd "$git" &&
159 git config git-p4.skipSubmitEdit true &&
160 echo file13 >file13 &&
161 git add file13 &&
162 git commit -m file13 &&
163 git p4 submit
164 ) &&
166 cd "$cli" &&
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 &&
175 cd "$git" &&
176 git config git-p4.skipSubmitEdit true &&
177 git rm file4.t &&
178 git commit -m "delete file4.t" &&
179 git p4 submit
180 ) &&
182 cd "$cli" &&
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 &&
191 cd "$git" &&
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 &&
196 git add file5.ta &&
197 git commit -m "copy to file5.ta" &&
198 git p4 submit
199 ) &&
201 cd "$cli" &&
202 test_path_is_file file5.ta &&
203 test ! -w file5.ta
207 test_expect_success 'submit rename' '
208 test_when_finished cleanup_git &&
209 git p4 clone --dest="$git" //depot &&
211 cd "$git" &&
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" &&
216 git p4 submit
217 ) &&
219 cd "$cli" &&
220 test_path_is_missing file6.t &&
221 test_path_is_file file6.ta &&
222 test ! -w 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 &&
234 cd "$git" &&
235 echo desc2 >desc2 &&
236 git add desc2 &&
237 cat >msg <<-EOF &&
238 One-line description line for desc2.
240 git commit -F - <msg &&
241 git config git-p4.skipSubmitEdit true &&
242 git p4 submit &&
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 &&
247 test_cmp msg pmsg
251 test_expect_success 'description with odd formatting' '
252 test_when_finished cleanup_git &&
253 git p4 clone --dest="$git" //depot &&
255 cd "$git" &&
256 echo desc3 >desc3 &&
257 git add desc3 &&
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"
263 ) >msg &&
264 git commit -F - <msg &&
265 git config git-p4.skipSubmitEdit true &&
266 git p4 submit &&
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 &&
271 test_cmp msg pmsg
275 make_job() {
276 name="$1" &&
277 tab="$(printf \\t)" &&
278 p4 job -o | \
279 sed -e "/^Job:/s/.*/Job: $name/" \
280 -e "/^Description/{ n; s/.*/$tab job text/; }" | \
281 p4 job -i
284 test_expect_success 'description with Jobs section at end' '
285 test_when_finished cleanup_git &&
286 git p4 clone --dest="$git" //depot &&
288 cd "$git" &&
289 echo desc4 >desc4 &&
290 git add desc4 &&
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"
297 ) >msg &&
298 git commit -F - <msg &&
299 git config git-p4.skipSubmitEdit true &&
300 # build a job
301 make_job $(cat jobname) &&
302 git p4 submit &&
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 &&
320 cd "$git" &&
321 echo desc5 >desc5 &&
322 git add desc5 &&
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" &&
329 printf "Jobs:\n" &&
330 printf "\t$(cat jobname1)\n" &&
331 printf "\t$(cat jobname2)\n"
332 ) >msg &&
333 git commit -F - <msg &&
334 git config git-p4.skipSubmitEdit true &&
335 # build two jobs
336 make_job $(cat jobname1) &&
337 make_job $(cat jobname2) &&
338 git p4 submit &&
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
351 ) | sort >jobs &&
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 &&
361 cd "$git" &&
362 echo desc6 >desc6 &&
363 git add desc6 &&
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"
371 ) >msg &&
372 git commit -F - <msg &&
373 git config git-p4.skipSubmitEdit true &&
374 # build a job
375 make_job $(cat jobname) &&
376 test_must_fail git p4 submit 2>err &&
377 test_i18ngrep "Unknown field name" err
378 ) &&
380 cd "$cli" &&
381 p4 revert desc6 &&
382 rm desc6
386 test_expect_success 'submit --prepare-p4-only' '
387 test_when_finished cleanup_git &&
388 git p4 clone --dest="$git" //depot &&
390 cd "$git" &&
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
397 ) &&
399 cd "$cli" &&
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' '
406 kill_p4d
409 test_done