list-objects: pass full pathname to callbacks
[git] / t / t9807-git-p4-submit.sh
1 #!/bin/sh
2
3 test_description='git p4 submit'
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
20 test_expect_success 'is_cli_file_writeable function' '
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
30 test_expect_success 'submit with no client dir' '
31         test_when_finished cleanup_git &&
32         git p4 clone --dest="$git" //depot &&
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 &&
40                 git p4 submit
41         ) &&
42         (
43                 cd "$cli" &&
44                 test_path_is_file file1 &&
45                 test_path_is_file file2
46         )
47 '
48
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 &&
53         (
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         ) &&
60         (
61                 cd "$cli" &&
62                 test_path_is_missing "file3.t" &&
63                 test_path_is_file "file4.t"
64         )
65 '
66
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
108 test_expect_success 'submit with allowSubmit' '
109         test_when_finished cleanup_git &&
110         git p4 clone --dest="$git" //depot &&
111         (
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
119         )
120 '
121
122 test_expect_success 'submit with master branch name from argv' '
123         test_when_finished cleanup_git &&
124         git p4 clone --dest="$git" //depot &&
125         (
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         ) &&
135         (
136                 cd "$cli" &&
137                 test_path_is_file "file6.t" &&
138                 test_path_is_missing "file7.t"
139         )
140 '
141
142 #
143 # Basic submit tests, the five handled cases
144 #
145
146 test_expect_success 'submit modify' '
147         test_when_finished cleanup_git &&
148         git p4 clone --dest="$git" //depot &&
149         (
150                 cd "$git" &&
151                 git config git-p4.skipSubmitEdit true &&
152                 echo line >>file1 &&
153                 git add file1 &&
154                 git commit -m file1 &&
155                 git p4 submit
156         ) &&
157         (
158                 cd "$cli" &&
159                 test_path_is_file file1 &&
160                 test_line_count = 2 file1
161         )
162 '
163
164 test_expect_success 'submit add' '
165         test_when_finished cleanup_git &&
166         git p4 clone --dest="$git" //depot &&
167         (
168                 cd "$git" &&
169                 git config git-p4.skipSubmitEdit true &&
170                 echo file13 >file13 &&
171                 git add file13 &&
172                 git commit -m file13 &&
173                 git p4 submit
174         ) &&
175         (
176                 cd "$cli" &&
177                 test_path_is_file file13
178         )
179 '
180
181 test_expect_success 'submit delete' '
182         test_when_finished cleanup_git &&
183         git p4 clone --dest="$git" //depot &&
184         (
185                 cd "$git" &&
186                 git config git-p4.skipSubmitEdit true &&
187                 git rm file4.t &&
188                 git commit -m "delete file4.t" &&
189                 git p4 submit
190         ) &&
191         (
192                 cd "$cli" &&
193                 test_path_is_missing file4.t
194         )
195 '
196
197 test_expect_success 'submit copy' '
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 config git-p4.detectCopies true &&
204                 git config git-p4.detectCopiesHarder true &&
205                 cp file5.t file5.ta &&
206                 git add file5.ta &&
207                 git commit -m "copy to file5.ta" &&
208                 git p4 submit
209         ) &&
210         (
211                 cd "$cli" &&
212                 test_path_is_file file5.ta &&
213                 ! is_cli_file_writeable file5.ta
214         )
215 '
216
217 test_expect_success 'submit rename' '
218         test_when_finished cleanup_git &&
219         git p4 clone --dest="$git" //depot &&
220         (
221                 cd "$git" &&
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" &&
226                 git p4 submit
227         ) &&
228         (
229                 cd "$cli" &&
230                 test_path_is_missing file6.t &&
231                 test_path_is_file file6.ta &&
232                 ! is_cli_file_writeable file6.ta
233         )
234 '
235
236 #
237 # Converting git commit message to p4 change description, including
238 # parsing out the optional Jobs: line.
239 #
240 test_expect_success 'simple one-line description' '
241         test_when_finished cleanup_git &&
242         git p4 clone --dest="$git" //depot &&
243         (
244                 cd "$git" &&
245                 echo desc2 >desc2 &&
246                 git add desc2 &&
247                 cat >msg <<-EOF &&
248                 One-line description line for desc2.
249                 EOF
250                 git commit -F - <msg &&
251                 git config git-p4.skipSubmitEdit true &&
252                 git p4 submit &&
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 &&
257                 test_cmp msg pmsg
258         )
259 '
260
261 test_expect_success 'description with odd formatting' '
262         test_when_finished cleanup_git &&
263         git p4 clone --dest="$git" //depot &&
264         (
265                 cd "$git" &&
266                 echo desc3 >desc3 &&
267                 git add desc3 &&
268                 (
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"
273                 ) >msg &&
274                 git commit -F - <msg &&
275                 git config git-p4.skipSubmitEdit true &&
276                 git p4 submit &&
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 &&
281                 test_cmp msg pmsg
282         )
283 '
284
285 make_job() {
286         name="$1" &&
287         tab="$(printf \\t)" &&
288         p4 job -o | \
289         sed -e "/^Job:/s/.*/Job: $name/" \
290             -e "/^Description/{ n; s/.*/$tab job text/; }" | \
291         p4 job -i
292 }
293
294 test_expect_success 'description with Jobs section at end' '
295         test_when_finished cleanup_git &&
296         git p4 clone --dest="$git" //depot &&
297         (
298                 cd "$git" &&
299                 echo desc4 >desc4 &&
300                 git add desc4 &&
301                 echo 6060842 >jobname &&
302                 (
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"
307                 ) >msg &&
308                 git commit -F - <msg &&
309                 git config git-p4.skipSubmitEdit true &&
310                 # build a job
311                 make_job $(cat jobname) &&
312                 git p4 submit &&
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
323         )
324 '
325
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 &&
329         (
330                 cd "$git" &&
331                 echo desc5 >desc5 &&
332                 git add desc5 &&
333                 echo PROJ-6060842 >jobname1 &&
334                 echo PROJ-6060847 >jobname2 &&
335                 (
336                         printf "subject line\n\n\tExtra tab\nline.\n\n" &&
337                         printf "Files:\n\tBogus files marker\n" &&
338                         printf "Junk: 3164175\n" &&
339                         printf "Jobs:\n" &&
340                         printf "\t$(cat jobname1)\n" &&
341                         printf "\t$(cat jobname2)\n"
342                 ) >msg &&
343                 git commit -F - <msg &&
344                 git config git-p4.skipSubmitEdit true &&
345                 # build two jobs
346                 make_job $(cat jobname1) &&
347                 make_job $(cat jobname2) &&
348                 git p4 submit &&
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 &&
358                 (
359                         marshal_dump job0 <change &&
360                         marshal_dump job1 <change
361                 ) | sort >jobs &&
362                 cat jobname1 jobname2 | sort >expected &&
363                 test_cmp expected jobs
364         )
365 '
366
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 &&
370         (
371                 cd "$git" &&
372                 echo desc6 >desc6 &&
373                 git add desc6 &&
374                 echo 6060843 >jobname &&
375                 (
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"
381                 ) >msg &&
382                 git commit -F - <msg &&
383                 git config git-p4.skipSubmitEdit true &&
384                 # build a job
385                 make_job $(cat jobname) &&
386                 test_must_fail git p4 submit 2>err &&
387                 test_i18ngrep "Unknown field name" err
388         ) &&
389         (
390                 cd "$cli" &&
391                 p4 revert desc6 &&
392                 rm desc6
393         )
394 '
395
396 test_expect_success 'submit --prepare-p4-only' '
397         test_when_finished cleanup_git &&
398         git p4 clone --dest="$git" //depot &&
399         (
400                 cd "$git" &&
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 &&
407                 test_i18ngrep ! "everything below this line is just the diff" out
408         ) &&
409         (
410                 cd "$cli" &&
411                 test_path_is_file prep-only-add &&
412                 p4 fstat -T action prep-only-add | grep -w add
413         )
414 '
415
416 test_expect_success 'kill p4d' '
417         kill_p4d
418 '
419
420 test_done