blob: 593152817dadaf1804f4a851c51b8bf1cbf52db9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
|
#!/bin/sh
test_description='git p4 submit'
. ./lib-git-p4.sh
test_expect_success 'start p4d' '
start_p4d
'
test_expect_success 'init depot' '
(
cd "$cli" &&
echo file1 >file1 &&
p4 add file1 &&
p4 submit -d "change 1"
)
'
test_expect_success 'is_cli_file_writeable function' '
(
cd "$cli" &&
echo a >a &&
is_cli_file_writeable a &&
! is_cli_file_writeable file1 &&
rm a
)
'
test_expect_success 'submit with no client dir' '
test_when_finished cleanup_git &&
git p4 clone --dest="$git" //depot &&
(
cd "$git" &&
echo file2 >file2 &&
git add file2 &&
git commit -m "git commit 2" &&
rm -rf "$cli" &&
git config git-p4.skipSubmitEdit true &&
git p4 submit
) &&
(
cd "$cli" &&
test_path_is_file file1 &&
test_path_is_file file2
)
'
# make two commits, but tell it to apply only from HEAD^
test_expect_success 'submit --origin' '
test_when_finished cleanup_git &&
git p4 clone --dest="$git" //depot &&
(
cd "$git" &&
test_commit "file3" &&
test_commit "file4" &&
git config git-p4.skipSubmitEdit true &&
git p4 submit --origin=HEAD^
) &&
(
cd "$cli" &&
test_path_is_missing "file3.t" &&
test_path_is_file "file4.t"
)
'
test_expect_success 'submit --dry-run' '
test_when_finished cleanup_git &&
git p4 clone --dest="$git" //depot &&
(
cd "$git" &&
test_commit "dry-run1" &&
test_commit "dry-run2" &&
git p4 submit --dry-run >out &&
test_i18ngrep "Would apply" out
) &&
(
cd "$cli" &&
test_path_is_missing "dry-run1.t" &&
test_path_is_missing "dry-run2.t"
)
'
test_expect_success 'submit --dry-run --export-labels' '
test_when_finished cleanup_git &&
git p4 clone --dest="$git" //depot &&
(
cd "$git" &&
echo dry-run1 >dry-run1 &&
git add dry-run1 &&
git commit -m "dry-run1" dry-run1 &&
git config git-p4.skipSubmitEdit true &&
git p4 submit &&
echo dry-run2 >dry-run2 &&
git add dry-run2 &&
git commit -m "dry-run2" dry-run2 &&
git tag -m "dry-run-tag1" dry-run-tag1 HEAD^ &&
git p4 submit --dry-run --export-labels >out &&
test_i18ngrep "Would create p4 label" out
) &&
(
cd "$cli" &&
test_path_is_file "dry-run1" &&
test_path_is_missing "dry-run2"
)
'
test_expect_success 'submit with allowSubmit' '
test_when_finished cleanup_git &&
git p4 clone --dest="$git" //depot &&
(
cd "$git" &&
test_commit "file5" &&
git config git-p4.skipSubmitEdit true &&
git config git-p4.allowSubmit "nobranch" &&
test_must_fail git p4 submit &&
git config git-p4.allowSubmit "nobranch,master" &&
git p4 submit
)
'
test_expect_success 'submit with master branch name from argv' '
test_when_finished cleanup_git &&
git p4 clone --dest="$git" //depot &&
(
cd "$git" &&
test_commit "file6" &&
git config git-p4.skipSubmitEdit true &&
test_must_fail git p4 submit nobranch &&
git branch otherbranch &&
git reset --hard HEAD^ &&
test_commit "file7" &&
git p4 submit otherbranch
) &&
(
cd "$cli" &&
test_path_is_file "file6.t" &&
test_path_is_missing "file7.t"
)
'
#
# Basic submit tests, the five handled cases
#
test_expect_success 'submit modify' '
test_when_finished cleanup_git &&
git p4 clone --dest="$git" //depot &&
(
cd "$git" &&
git config git-p4.skipSubmitEdit true &&
echo line >>file1 &&
git add file1 &&
git commit -m file1 &&
git p4 submit
) &&
(
cd "$cli" &&
test_path_is_file file1 &&
test_line_count = 2 file1
)
'
test_expect_success 'submit add' '
test_when_finished cleanup_git &&
git p4 clone --dest="$git" //depot &&
(
cd "$git" &&
git config git-p4.skipSubmitEdit true &&
echo file13 >file13 &&
git add file13 &&
git commit -m file13 &&
git p4 submit
) &&
(
cd "$cli" &&
test_path_is_file file13
)
'
test_expect_success 'submit delete' '
test_when_finished cleanup_git &&
git p4 clone --dest="$git" //depot &&
(
cd "$git" &&
git config git-p4.skipSubmitEdit true &&
git rm file4.t &&
git commit -m "delete file4.t" &&
git p4 submit
) &&
(
cd "$cli" &&
test_path_is_missing file4.t
)
'
test_expect_success 'submit copy' '
test_when_finished cleanup_git &&
git p4 clone --dest="$git" //depot &&
(
cd "$git" &&
git config git-p4.skipSubmitEdit true &&
git config git-p4.detectCopies true &&
git config git-p4.detectCopiesHarder true &&
cp file5.t file5.ta &&
git add file5.ta &&
git commit -m "copy to file5.ta" &&
git p4 submit
) &&
(
cd "$cli" &&
test_path_is_file file5.ta &&
! is_cli_file_writeable file5.ta
)
'
test_expect_success 'submit rename' '
test_when_finished cleanup_git &&
git p4 clone --dest="$git" //depot &&
(
cd "$git" &&
git config git-p4.skipSubmitEdit true &&
git config git-p4.detectRenames true &&
git mv file6.t file6.ta &&
git commit -m "rename file6.t to file6.ta" &&
git p4 submit
) &&
(
cd "$cli" &&
test_path_is_missing file6.t &&
test_path_is_file file6.ta &&
! is_cli_file_writeable file6.ta
)
'
#
# Converting git commit message to p4 change description, including
# parsing out the optional Jobs: line.
#
test_expect_success 'simple one-line description' '
test_when_finished cleanup_git &&
git p4 clone --dest="$git" //depot &&
(
cd "$git" &&
echo desc2 >desc2 &&
git add desc2 &&
cat >msg <<-EOF &&
One-line description line for desc2.
EOF
git commit -F - <msg &&
git config git-p4.skipSubmitEdit true &&
git p4 submit &&
change=$(p4 -G changes -m 1 //depot/... | \
marshal_dump change) &&
# marshal_dump always adds a newline
p4 -G describe $change | marshal_dump desc | sed \$d >pmsg &&
test_cmp msg pmsg
)
'
test_expect_success 'description with odd formatting' '
test_when_finished cleanup_git &&
git p4 clone --dest="$git" //depot &&
(
cd "$git" &&
echo desc3 >desc3 &&
git add desc3 &&
(
printf "subject line\n\n\tExtra tab\nline.\n\n" &&
printf "Description:\n\tBogus description marker\n\n" &&
# git commit eats trailing newlines; only use one
printf "Files:\n\tBogus descs marker\n"
) >msg &&
git commit -F - <msg &&
git config git-p4.skipSubmitEdit true &&
git p4 submit &&
change=$(p4 -G changes -m 1 //depot/... | \
marshal_dump change) &&
# marshal_dump always adds a newline
p4 -G describe $change | marshal_dump desc | sed \$d >pmsg &&
test_cmp msg pmsg
)
'
make_job() {
name="$1" &&
tab="$(printf \\t)" &&
p4 job -o | \
sed -e "/^Job:/s/.*/Job: $name/" \
-e "/^Description/{ n; s/.*/$tab job text/; }" | \
p4 job -i
}
test_expect_success 'description with Jobs section at end' '
test_when_finished cleanup_git &&
git p4 clone --dest="$git" //depot &&
(
cd "$git" &&
echo desc4 >desc4 &&
git add desc4 &&
echo 6060842 >jobname &&
(
printf "subject line\n\n\tExtra tab\nline.\n\n" &&
printf "Files:\n\tBogus files marker\n" &&
printf "Junk: 3164175\n" &&
printf "Jobs: $(cat jobname)\n"
) >msg &&
git commit -F - <msg &&
git config git-p4.skipSubmitEdit true &&
# build a job
make_job $(cat jobname) &&
git p4 submit &&
change=$(p4 -G changes -m 1 //depot/... | \
marshal_dump change) &&
# marshal_dump always adds a newline
p4 -G describe $change | marshal_dump desc | sed \$d >pmsg &&
# make sure Jobs line and all following is gone
sed "/^Jobs:/,\$d" msg >jmsg &&
test_cmp jmsg pmsg &&
# make sure p4 knows about job
p4 -G describe $change | marshal_dump job0 >job0 &&
test_cmp jobname job0
)
'
test_expect_success 'description with Jobs and values on separate lines' '
test_when_finished cleanup_git &&
git p4 clone --dest="$git" //depot &&
(
cd "$git" &&
echo desc5 >desc5 &&
git add desc5 &&
echo PROJ-6060842 >jobname1 &&
echo PROJ-6060847 >jobname2 &&
(
printf "subject line\n\n\tExtra tab\nline.\n\n" &&
printf "Files:\n\tBogus files marker\n" &&
printf "Junk: 3164175\n" &&
printf "Jobs:\n" &&
printf "\t$(cat jobname1)\n" &&
printf "\t$(cat jobname2)\n"
) >msg &&
git commit -F - <msg &&
git config git-p4.skipSubmitEdit true &&
# build two jobs
make_job $(cat jobname1) &&
make_job $(cat jobname2) &&
git p4 submit &&
change=$(p4 -G changes -m 1 //depot/... | \
marshal_dump change) &&
# marshal_dump always adds a newline
p4 -G describe $change | marshal_dump desc | sed \$d >pmsg &&
# make sure Jobs line and all following is gone
sed "/^Jobs:/,\$d" msg >jmsg &&
test_cmp jmsg pmsg &&
# make sure p4 knows about the two jobs
p4 -G describe $change >change &&
(
marshal_dump job0 <change &&
marshal_dump job1 <change
) | sort >jobs &&
cat jobname1 jobname2 | sort >expected &&
test_cmp expected jobs
)
'
test_expect_success 'description with Jobs section and bogus following text' '
test_when_finished cleanup_git &&
git p4 clone --dest="$git" //depot &&
(
cd "$git" &&
echo desc6 >desc6 &&
git add desc6 &&
echo 6060843 >jobname &&
(
printf "subject line\n\n\tExtra tab\nline.\n\n" &&
printf "Files:\n\tBogus files marker\n" &&
printf "Junk: 3164175\n" &&
printf "Jobs: $(cat jobname)\n" &&
printf "MoreJunk: 3711\n"
) >msg &&
git commit -F - <msg &&
git config git-p4.skipSubmitEdit true &&
# build a job
make_job $(cat jobname) &&
test_must_fail git p4 submit 2>err &&
test_i18ngrep "Unknown field name" err
) &&
(
cd "$cli" &&
p4 revert desc6 &&
rm -f desc6
)
'
test_expect_success 'submit --prepare-p4-only' '
test_when_finished cleanup_git &&
git p4 clone --dest="$git" //depot &&
(
cd "$git" &&
echo prep-only-add >prep-only-add &&
git add prep-only-add &&
git commit -m "prep only add" &&
git p4 submit --prepare-p4-only >out &&
test_i18ngrep "prepared for submission" out &&
test_i18ngrep "must be deleted" out &&
test_i18ngrep ! "everything below this line is just the diff" out
) &&
(
cd "$cli" &&
test_path_is_file prep-only-add &&
p4 fstat -T action prep-only-add | grep -w add
)
'
test_expect_success 'kill p4d' '
kill_p4d
'
test_done
|