]>
Commit | Line | Data |
---|---|---|
c145225a PW |
1 | #!/bin/sh |
2 | ||
6ab1d76c | 3 | test_description='git p4 submit' |
c145225a PW |
4 | |
5 | . ./lib-git-p4.sh | |
6 | ||
7 | test_expect_success 'start p4d' ' | |
8 | start_p4d | |
9 | ' | |
10 | ||
11 | test_expect_success 'init depot' ' | |
12 | ( | |
13 | cd "$cli" && | |
14 | echo file1 >file1 && | |
15 | p4 add file1 && | |
16 | p4 submit -d "change 1" | |
17 | ) | |
18 | ' | |
19 | ||
0577849d | 20 | test_expect_success 'is_cli_file_writeable function' ' |
e9df0f9c PW |
21 | ( |
22 | cd "$cli" && | |
23 | echo a >a && | |
24 | is_cli_file_writeable a && | |
25 | ! is_cli_file_writeable file1 && | |
26 | rm a | |
27 | ) | |
28 | ' | |
29 | ||
c145225a PW |
30 | test_expect_success 'submit with no client dir' ' |
31 | test_when_finished cleanup_git && | |
6ab1d76c | 32 | git p4 clone --dest="$git" //depot && |
c145225a PW |
33 | ( |
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 && | |
6ab1d76c | 40 | git p4 submit |
8d7ec362 PW |
41 | ) && |
42 | ( | |
43 | cd "$cli" && | |
44 | test_path_is_file file1 && | |
45 | test_path_is_file file2 | |
c145225a PW |
46 | ) |
47 | ' | |
48 | ||
28755dba PW |
49 | # make two commits, but tell it to apply only from HEAD^ |
50 | test_expect_success 'submit --origin' ' | |
51 | test_when_finished cleanup_git && | |
6ab1d76c | 52 | git p4 clone --dest="$git" //depot && |
28755dba PW |
53 | ( |
54 | cd "$git" && | |
55 | test_commit "file3" && | |
56 | test_commit "file4" && | |
57 | git config git-p4.skipSubmitEdit true && | |
6ab1d76c | 58 | git p4 submit --origin=HEAD^ |
28755dba PW |
59 | ) && |
60 | ( | |
61 | cd "$cli" && | |
28755dba PW |
62 | test_path_is_missing "file3.t" && |
63 | test_path_is_file "file4.t" | |
64 | ) | |
65 | ' | |
66 | ||
ef739f08 PW |
67 | test_expect_success 'submit --dry-run' ' |
68 | test_when_finished cleanup_git && | |
69 | git p4 clone --dest="$git" //depot && | |
70 | ( | |
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 | ) && | |
77 | ( | |
78 | cd "$cli" && | |
79 | test_path_is_missing "dry-run1.t" && | |
80 | test_path_is_missing "dry-run2.t" | |
81 | ) | |
82 | ' | |
83 | ||
84 | test_expect_success 'submit --dry-run --export-labels' ' | |
85 | test_when_finished cleanup_git && | |
86 | git p4 clone --dest="$git" //depot && | |
87 | ( | |
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 | ) && | |
101 | ( | |
102 | cd "$cli" && | |
103 | test_path_is_file "dry-run1" && | |
104 | test_path_is_missing "dry-run2" | |
105 | ) | |
106 | ' | |
107 | ||
28755dba PW |
108 | test_expect_success 'submit with allowSubmit' ' |
109 | test_when_finished cleanup_git && | |
6ab1d76c | 110 | git p4 clone --dest="$git" //depot && |
28755dba PW |
111 | ( |
112 | cd "$git" && | |
113 | test_commit "file5" && | |
114 | git config git-p4.skipSubmitEdit true && | |
115 | git config git-p4.allowSubmit "nobranch" && | |
6ab1d76c | 116 | test_must_fail git p4 submit && |
28755dba | 117 | git config git-p4.allowSubmit "nobranch,master" && |
6ab1d76c | 118 | git p4 submit |
28755dba PW |
119 | ) |
120 | ' | |
121 | ||
122 | test_expect_success 'submit with master branch name from argv' ' | |
123 | test_when_finished cleanup_git && | |
6ab1d76c | 124 | git p4 clone --dest="$git" //depot && |
28755dba PW |
125 | ( |
126 | cd "$git" && | |
127 | test_commit "file6" && | |
128 | git config git-p4.skipSubmitEdit true && | |
6ab1d76c | 129 | test_must_fail git p4 submit nobranch && |
28755dba PW |
130 | git branch otherbranch && |
131 | git reset --hard HEAD^ && | |
132 | test_commit "file7" && | |
6ab1d76c | 133 | git p4 submit otherbranch |
28755dba PW |
134 | ) && |
135 | ( | |
136 | cd "$cli" && | |
28755dba PW |
137 | test_path_is_file "file6.t" && |
138 | test_path_is_missing "file7.t" | |
139 | ) | |
140 | ' | |
141 | ||
eff45110 | 142 | test_expect_success 'allow submit from branch with same revision but different name' ' |
3d553cce LD |
143 | test_when_finished cleanup_git && |
144 | git p4 clone --dest="$git" //depot && | |
145 | ( | |
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 | |
155 | ) | |
156 | ' | |
157 | ||
0f224e5b PW |
158 | # |
159 | # Basic submit tests, the five handled cases | |
160 | # | |
161 | ||
162 | test_expect_success 'submit modify' ' | |
163 | test_when_finished cleanup_git && | |
164 | git p4 clone --dest="$git" //depot && | |
165 | ( | |
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 | ) && | |
173 | ( | |
174 | cd "$cli" && | |
175 | test_path_is_file file1 && | |
176 | test_line_count = 2 file1 | |
177 | ) | |
178 | ' | |
179 | ||
180 | test_expect_success 'submit add' ' | |
181 | test_when_finished cleanup_git && | |
182 | git p4 clone --dest="$git" //depot && | |
183 | ( | |
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 | ) && | |
191 | ( | |
192 | cd "$cli" && | |
193 | test_path_is_file file13 | |
194 | ) | |
195 | ' | |
196 | ||
197 | test_expect_success 'submit delete' ' | |
198 | test_when_finished cleanup_git && | |
199 | git p4 clone --dest="$git" //depot && | |
200 | ( | |
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 | ) && | |
207 | ( | |
208 | cd "$cli" && | |
209 | test_path_is_missing file4.t | |
210 | ) | |
211 | ' | |
212 | ||
213 | test_expect_success 'submit copy' ' | |
214 | test_when_finished cleanup_git && | |
215 | git p4 clone --dest="$git" //depot && | |
216 | ( | |
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 | ) && | |
226 | ( | |
227 | cd "$cli" && | |
b6ad6dcc | 228 | test_path_is_file file5.ta && |
e9df0f9c | 229 | ! is_cli_file_writeable file5.ta |
0f224e5b PW |
230 | ) |
231 | ' | |
232 | ||
233 | test_expect_success 'submit rename' ' | |
234 | test_when_finished cleanup_git && | |
235 | git p4 clone --dest="$git" //depot && | |
236 | ( | |
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 | ) && | |
244 | ( | |
245 | cd "$cli" && | |
246 | test_path_is_missing file6.t && | |
b6ad6dcc | 247 | test_path_is_file file6.ta && |
e9df0f9c | 248 | ! is_cli_file_writeable file6.ta |
0f224e5b PW |
249 | ) |
250 | ' | |
251 | ||
f19cb0a0 PW |
252 | # |
253 | # Converting git commit message to p4 change description, including | |
254 | # parsing out the optional Jobs: line. | |
255 | # | |
256 | test_expect_success 'simple one-line description' ' | |
257 | test_when_finished cleanup_git && | |
258 | git p4 clone --dest="$git" //depot && | |
259 | ( | |
260 | cd "$git" && | |
261 | echo desc2 >desc2 && | |
262 | git add desc2 && | |
263 | cat >msg <<-EOF && | |
264 | One-line description line for desc2. | |
265 | EOF | |
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 | |
274 | ) | |
275 | ' | |
276 | ||
277 | test_expect_success 'description with odd formatting' ' | |
278 | test_when_finished cleanup_git && | |
279 | git p4 clone --dest="$git" //depot && | |
280 | ( | |
281 | cd "$git" && | |
282 | echo desc3 >desc3 && | |
283 | git add desc3 && | |
284 | ( | |
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 | |
298 | ) | |
299 | ' | |
300 | ||
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 | |
308 | } | |
309 | ||
310 | test_expect_success 'description with Jobs section at end' ' | |
311 | test_when_finished cleanup_git && | |
312 | git p4 clone --dest="$git" //depot && | |
313 | ( | |
314 | cd "$git" && | |
315 | echo desc4 >desc4 && | |
316 | git add desc4 && | |
317 | echo 6060842 >jobname && | |
318 | ( | |
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 | |
339 | ) | |
340 | ' | |
341 | ||
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 && | |
345 | ( | |
346 | cd "$git" && | |
347 | echo desc5 >desc5 && | |
348 | git add desc5 && | |
349 | echo PROJ-6060842 >jobname1 && | |
350 | echo PROJ-6060847 >jobname2 && | |
351 | ( | |
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 && | |
374 | ( | |
375 | marshal_dump job0 <change && | |
376 | marshal_dump job1 <change | |
377 | ) | sort >jobs && | |
378 | cat jobname1 jobname2 | sort >expected && | |
379 | test_cmp expected jobs | |
380 | ) | |
381 | ' | |
382 | ||
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 && | |
386 | ( | |
387 | cd "$git" && | |
388 | echo desc6 >desc6 && | |
389 | git add desc6 && | |
390 | echo 6060843 >jobname && | |
391 | ( | |
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 | |
728b7ad8 PW |
404 | ) && |
405 | ( | |
406 | cd "$cli" && | |
407 | p4 revert desc6 && | |
b7638fed | 408 | rm -f desc6 |
728b7ad8 PW |
409 | ) |
410 | ' | |
411 | ||
412 | test_expect_success 'submit --prepare-p4-only' ' | |
413 | test_when_finished cleanup_git && | |
414 | git p4 clone --dest="$git" //depot && | |
415 | ( | |
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 && | |
b4073bb3 | 422 | test_i18ngrep "must be deleted" out && |
41ca19b6 | 423 | test_i18ngrep ! "everything below this line is just the diff" out |
728b7ad8 PW |
424 | ) && |
425 | ( | |
426 | cd "$cli" && | |
427 | test_path_is_file prep-only-add && | |
428 | p4 fstat -T action prep-only-add | grep -w add | |
f19cb0a0 PW |
429 | ) |
430 | ' | |
431 | ||
b34fa577 VK |
432 | test_expect_success 'submit --shelve' ' |
433 | test_when_finished cleanup_git && | |
434 | git p4 clone --dest="$git" //depot && | |
435 | ( | |
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^ && | |
442 | ||
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^ && | |
448 | ||
449 | test_path_is_file shelveme1.t && | |
450 | test_path_is_file shelveme2.t | |
451 | ) && | |
452 | ( | |
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 | |
460 | ) | |
461 | ' | |
462 | ||
46c609e9 LD |
463 | # Update an existing shelved changelist |
464 | ||
465 | test_expect_success 'submit --update-shelve' ' | |
466 | test_when_finished cleanup_git && | |
467 | git p4 clone --dest="$git" //depot && | |
468 | ( | |
469 | cd "$cli" && | |
470 | p4 revert ... && | |
471 | cd "$git" && | |
472 | git config git-p4.skipSubmitEdit true && | |
473 | test_commit "test-update-shelved-change" && | |
474 | git p4 submit --origin=HEAD^ --shelve && | |
475 | ||
476 | shelf_cl=$(p4 -G changes -s shelved -m 1 |\ | |
477 | marshal_dump change) && | |
478 | test -n $shelf_cl && | |
479 | echo "updating shelved change list $shelf_cl" && | |
480 | ||
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" | |
489 | ) && | |
490 | ( | |
491 | cd "$cli" && | |
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 | |
498 | ) | |
499 | ' | |
500 | ||
c145225a PW |
501 | test_expect_success 'kill p4d' ' |
502 | kill_p4d | |
503 | ' | |
504 | ||
505 | test_done |