git p4 test: split up big t9800 test

The original t9800 test code has a mix of assorted topics, some of which are big enough to deserve their own homes. Interdependencies between the topics make it confusing when trying to study one in isolation. And it takes so long to run that debugging an individual test is difficult. Split out three big chunks of tests into their own files: t9812-git-p4-wildcards.sh gets the 8 p4 wildcard tests t9813-git-p4-preserve-users.sh gets the 4 --preserve-user tests t9814-git-p4-rename.sh gets the 2 copy and rename tests Test 9800 execution time drops from 29 sec to 9 sec. The sequential time to run all tests is a slower due to the three extra p4d startup/shutdown sequences, but the overall parallel execution time is about the same, at 52 sec. Signed-off-by: Pete Wyckoff <pw@padd.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Pete Wyckoff committed Jun 27, 2012 at 08:01 UTC 9b6513ac6fde1552a9a3d606be704eb5ded43ac0
4 files changed +506 -397
t/t9800-git-p4-basic.sh
-397
@@ -139,136 +139,6 @@ test_expect_success 'exit when p4 fails to produce marshaled output' '
139 test_must_fail grep -q Traceback errs
140 '
141
142 -test_expect_success 'add p4 files with wildcards in the names' '
143 - (
144 - cd "$cli" &&
145 - echo file-wild-hash >file-wild#hash &&
146 - echo file-wild-star >file-wild\*star &&
147 - echo file-wild-at >file-wild@at &&
148 - echo file-wild-percent >file-wild%percent &&
149 - p4 add -f file-wild* &&
150 - p4 submit -d "file wildcards"
151 - )
152 -'
153 -
154 -test_expect_success 'wildcard files git p4 clone' '
155 - git p4 clone --dest="$git" //depot &&
156 - test_when_finished cleanup_git &&
157 - (
158 - cd "$git" &&
159 - test -f file-wild#hash &&
160 - test -f file-wild\*star &&
161 - test -f file-wild@at &&
162 - test -f file-wild%percent
163 - )
164 -'
165 -
166 -test_expect_success 'wildcard files submit back to p4, add' '
167 - test_when_finished cleanup_git &&
168 - git p4 clone --dest="$git" //depot &&
169 - (
170 - cd "$git" &&
171 - echo git-wild-hash >git-wild#hash &&
172 - echo git-wild-star >git-wild\*star &&
173 - echo git-wild-at >git-wild@at &&
174 - echo git-wild-percent >git-wild%percent &&
175 - git add git-wild* &&
176 - git commit -m "add some wildcard filenames" &&
177 - git config git-p4.skipSubmitEdit true &&
178 - git p4 submit
179 - ) &&
180 - (
181 - cd "$cli" &&
182 - test_path_is_file git-wild#hash &&
183 - test_path_is_file git-wild\*star &&
184 - test_path_is_file git-wild@at &&
185 - test_path_is_file git-wild%percent
186 - )
187 -'
188 -
189 -test_expect_success 'wildcard files submit back to p4, modify' '
190 - test_when_finished cleanup_git &&
191 - git p4 clone --dest="$git" //depot &&
192 - (
193 - cd "$git" &&
194 - echo new-line >>git-wild#hash &&
195 - echo new-line >>git-wild\*star &&
196 - echo new-line >>git-wild@at &&
197 - echo new-line >>git-wild%percent &&
198 - git add git-wild* &&
199 - git commit -m "modify the wildcard files" &&
200 - git config git-p4.skipSubmitEdit true &&
201 - git p4 submit
202 - ) &&
203 - (
204 - cd "$cli" &&
205 - test_line_count = 2 git-wild#hash &&
206 - test_line_count = 2 git-wild\*star &&
207 - test_line_count = 2 git-wild@at &&
208 - test_line_count = 2 git-wild%percent
209 - )
210 -'
211 -
212 -test_expect_success 'wildcard files submit back to p4, copy' '
213 - test_when_finished cleanup_git &&
214 - git p4 clone --dest="$git" //depot &&
215 - (
216 - cd "$git" &&
217 - cp file2 git-wild-cp#hash &&
218 - git add git-wild-cp#hash &&
219 - cp git-wild\*star file-wild-3 &&
220 - git add file-wild-3 &&
221 - git commit -m "wildcard copies" &&
222 - git config git-p4.detectCopies true &&
223 - git config git-p4.detectCopiesHarder true &&
224 - git config git-p4.skipSubmitEdit true &&
225 - git p4 submit
226 - ) &&
227 - (
228 - cd "$cli" &&
229 - test_path_is_file git-wild-cp#hash &&
230 - test_path_is_file file-wild-3
231 - )
232 -'
233 -
234 -test_expect_success 'wildcard files submit back to p4, rename' '
235 - test_when_finished cleanup_git &&
236 - git p4 clone --dest="$git" //depot &&
237 - (
238 - cd "$git" &&
239 - git mv git-wild@at file-wild-4 &&
240 - git mv file-wild-3 git-wild-cp%percent &&
241 - git commit -m "wildcard renames" &&
242 - git config git-p4.detectRenames true &&
243 - git config git-p4.skipSubmitEdit true &&
244 - git p4 submit
245 - ) &&
246 - (
247 - cd "$cli" &&
248 - test_path_is_missing git-wild@at &&
249 - test_path_is_file git-wild-cp%percent
250 - )
251 -'
252 -
253 -test_expect_success 'wildcard files submit back to p4, delete' '
254 - test_when_finished cleanup_git &&
255 - git p4 clone --dest="$git" //depot &&
256 - (
257 - cd "$git" &&
258 - git rm git-wild* &&
259 - git commit -m "delete the wildcard files" &&
260 - git config git-p4.skipSubmitEdit true &&
261 - git p4 submit
262 - ) &&
263 - (
264 - cd "$cli" &&
265 - test_path_is_missing git-wild#hash &&
266 - test_path_is_missing git-wild\*star &&
267 - test_path_is_missing git-wild@at &&
268 - test_path_is_missing git-wild%percent
269 - )
270 -'
271 -
142 test_expect_success 'clone bare' '
143 rm -rf "$git" &&
144 git p4 clone --dest="$git" --bare //depot &&
@@ -281,133 +151,6 @@ test_expect_success 'clone bare' '
151 )
152 '
153
284 -p4_add_user() {
285 - name=$1 fullname=$2 &&
286 - p4 user -f -i <<-EOF &&
287 - User: $name
288 - Email: $name@localhost
289 - FullName: $fullname
290 - EOF
291 - p4 passwd -P secret $name
292 -}
293 -
294 -p4_grant_admin() {
295 - name=$1 &&
296 - {
297 - p4 protect -o &&
298 - echo " admin user $name * //depot/..."
299 - } | p4 protect -i
300 -}
301 -
302 -p4_check_commit_author() {
303 - file=$1 user=$2 &&
304 - p4 changes -m 1 //depot/$file | grep -q $user
305 -}
306 -
307 -make_change_by_user() {
308 - file=$1 name=$2 email=$3 &&
309 - echo "username: a change by $name" >>"$file" &&
310 - git add "$file" &&
311 - git commit --author "$name <$email>" -m "a change by $name"
312 -}
313 -
314 -# Test username support, submitting as user 'alice'
315 -test_expect_success 'preserve users' '
316 - p4_add_user alice Alice &&
317 - p4_add_user bob Bob &&
318 - p4_grant_admin alice &&
319 - git p4 clone --dest="$git" //depot &&
320 - test_when_finished cleanup_git &&
321 - (
322 - cd "$git" &&
323 - echo "username: a change by alice" >>file1 &&
324 - echo "username: a change by bob" >>file2 &&
325 - git commit --author "Alice <alice@localhost>" -m "a change by alice" file1 &&
326 - git commit --author "Bob <bob@localhost>" -m "a change by bob" file2 &&
327 - git config git-p4.skipSubmitEditCheck true &&
328 - P4EDITOR=touch P4USER=alice P4PASSWD=secret git p4 commit --preserve-user &&
329 - p4_check_commit_author file1 alice &&
330 - p4_check_commit_author file2 bob
331 - )
332 -'
333 -
334 -# Test username support, submitting as bob, who lacks admin rights. Should
335 -# not submit change to p4 (git diff should show deltas).
336 -test_expect_success 'refuse to preserve users without perms' '
337 - git p4 clone --dest="$git" //depot &&
338 - test_when_finished cleanup_git &&
339 - (
340 - cd "$git" &&
341 - git config git-p4.skipSubmitEditCheck true &&
342 - echo "username-noperms: a change by alice" >>file1 &&
343 - git commit --author "Alice <alice@localhost>" -m "perms: a change by alice" file1 &&
344 - P4EDITOR=touch P4USER=bob P4PASSWD=secret &&
345 - export P4EDITOR P4USER P4PASSWD &&
346 - test_must_fail git p4 commit --preserve-user &&
347 - ! git diff --exit-code HEAD..p4/master
348 - )
349 -'
350 -
351 -# What happens with unknown author? Without allowMissingP4Users it should fail.
352 -test_expect_success 'preserve user where author is unknown to p4' '
353 - git p4 clone --dest="$git" //depot &&
354 - test_when_finished cleanup_git &&
355 - (
356 - cd "$git" &&
357 - git config git-p4.skipSubmitEditCheck true &&
358 - echo "username-bob: a change by bob" >>file1 &&
359 - git commit --author "Bob <bob@localhost>" -m "preserve: a change by bob" file1 &&
360 - echo "username-unknown: a change by charlie" >>file1 &&
361 - git commit --author "Charlie <charlie@localhost>" -m "preserve: a change by charlie" file1 &&
362 - P4EDITOR=touch P4USER=alice P4PASSWD=secret &&
363 - export P4EDITOR P4USER P4PASSWD &&
364 - test_must_fail git p4 commit --preserve-user &&
365 - ! git diff --exit-code HEAD..p4/master &&
366 -
367 - echo "$0: repeat with allowMissingP4Users enabled" &&
368 - git config git-p4.allowMissingP4Users true &&
369 - git config git-p4.preserveUser true &&
370 - git p4 commit &&
371 - git diff --exit-code HEAD..p4/master &&
372 - p4_check_commit_author file1 alice
373 - )
374 -'
375 -
376 -# If we're *not* using --preserve-user, git p4 should warn if we're submitting
377 -# changes that are not all ours.
378 -# Test: user in p4 and user unknown to p4.
379 -# Test: warning disabled and user is the same.
380 -test_expect_success 'not preserving user with mixed authorship' '
381 - git p4 clone --dest="$git" //depot &&
382 - test_when_finished cleanup_git &&
383 - (
384 - cd "$git" &&
385 - git config git-p4.skipSubmitEditCheck true &&
386 - p4_add_user derek Derek &&
387 -
388 - make_change_by_user usernamefile3 Derek derek@localhost &&
389 - P4EDITOR=cat P4USER=alice P4PASSWD=secret &&
390 - export P4EDITOR P4USER P4PASSWD &&
391 - git p4 commit |\
392 - grep "git author derek@localhost does not match" &&
393 -
394 - make_change_by_user usernamefile3 Charlie charlie@localhost &&
395 - git p4 commit |\
396 - grep "git author charlie@localhost does not match" &&
397 -
398 - make_change_by_user usernamefile3 alice alice@localhost &&
399 - git p4 commit |\
400 - test_must_fail grep "git author.*does not match" &&
401 -
402 - git config git-p4.skipUserNameCheck true &&
403 - make_change_by_user usernamefile3 Charlie charlie@localhost &&
404 - git p4 commit |\
405 - test_must_fail grep "git author.*does not match" &&
406 -
407 - p4_check_commit_author usernamefile3 alice
408 - )
409 -'
410 -
154 marshal_dump() {
155 what=$1
156 "$PYTHON_PATH" -c 'import marshal, sys; d = marshal.load(sys.stdin); print d["'$what'"]'
@@ -430,146 +173,6 @@ test_expect_success 'initial import time from top change time' '
173 )
174 '
175
433 -# Rename a file and confirm that rename is not detected in P4.
434 -# Rename the new file again with detectRenames option enabled and confirm that
435 -# this is detected in P4.
436 -# Rename the new file again adding an extra line, configure a big threshold in
437 -# detectRenames and confirm that rename is not detected in P4.
438 -# Repeat, this time with a smaller threshold and confirm that the rename is
439 -# detected in P4.
440 -test_expect_success 'detect renames' '
441 - git p4 clone --dest="$git" //depot@all &&
442 - test_when_finished cleanup_git &&
443 - (
444 - cd "$git" &&
445 - git config git-p4.skipSubmitEdit true &&
446 -
447 - git mv file1 file4 &&
448 - git commit -a -m "Rename file1 to file4" &&
449 - git diff-tree -r -M HEAD &&
450 - git p4 submit &&
451 - p4 filelog //depot/file4 &&
452 - p4 filelog //depot/file4 | test_must_fail grep -q "branch from" &&
453 -
454 - git mv file4 file5 &&
455 - git commit -a -m "Rename file4 to file5" &&
456 - git diff-tree -r -M HEAD &&
457 - git config git-p4.detectRenames true &&
458 - git p4 submit &&
459 - p4 filelog //depot/file5 &&
460 - p4 filelog //depot/file5 | grep -q "branch from //depot/file4" &&
461 -
462 - git mv file5 file6 &&
463 - echo update >>file6 &&
464 - git add file6 &&
465 - git commit -a -m "Rename file5 to file6 with changes" &&
466 - git diff-tree -r -M HEAD &&
467 - level=$(git diff-tree -r -M HEAD | sed 1d | cut -f1 | cut -d" " -f5 | sed "s/R0*//") &&
468 - test -n "$level" && test "$level" -gt 0 && test "$level" -lt 98 &&
469 - git config git-p4.detectRenames $(($level + 2)) &&
470 - git p4 submit &&
471 - p4 filelog //depot/file6 &&
472 - p4 filelog //depot/file6 | test_must_fail grep -q "branch from" &&
473 -
474 - git mv file6 file7 &&
475 - echo update >>file7 &&
476 - git add file7 &&
477 - git commit -a -m "Rename file6 to file7 with changes" &&
478 - git diff-tree -r -M HEAD &&
479 - level=$(git diff-tree -r -M HEAD | sed 1d | cut -f1 | cut -d" " -f5 | sed "s/R0*//") &&
480 - test -n "$level" && test "$level" -gt 2 && test "$level" -lt 100 &&
481 - git config git-p4.detectRenames $(($level - 2)) &&
482 - git p4 submit &&
483 - p4 filelog //depot/file7 &&
484 - p4 filelog //depot/file7 | grep -q "branch from //depot/file6"
485 - )
486 -'
487 -
488 -# Copy a file and confirm that copy is not detected in P4.
489 -# Copy a file with detectCopies option enabled and confirm that copy is not
490 -# detected in P4.
491 -# Modify and copy a file with detectCopies option enabled and confirm that copy
492 -# is detected in P4.
493 -# Copy a file with detectCopies and detectCopiesHarder options enabled and
494 -# confirm that copy is detected in P4.
495 -# Modify and copy a file, configure a bigger threshold in detectCopies and
496 -# confirm that copy is not detected in P4.
497 -# Modify and copy a file, configure a smaller threshold in detectCopies and
498 -# confirm that copy is detected in P4.
499 -test_expect_success 'detect copies' '
500 - git p4 clone --dest="$git" //depot@all &&
501 - test_when_finished cleanup_git &&
502 - (
503 - cd "$git" &&
504 - git config git-p4.skipSubmitEdit true &&
505 -
506 - cp file2 file8 &&
507 - git add file8 &&
508 - git commit -a -m "Copy file2 to file8" &&
509 - git diff-tree -r -C HEAD &&
510 - git p4 submit &&
511 - p4 filelog //depot/file8 &&
512 - p4 filelog //depot/file8 | test_must_fail grep -q "branch from" &&
513 -
514 - cp file2 file9 &&
515 - git add file9 &&
516 - git commit -a -m "Copy file2 to file9" &&
517 - git diff-tree -r -C HEAD &&
518 - git config git-p4.detectCopies true &&
519 - git p4 submit &&
520 - p4 filelog //depot/file9 &&
521 - p4 filelog //depot/file9 | test_must_fail grep -q "branch from" &&
522 -
523 - echo "file2" >>file2 &&
524 - cp file2 file10 &&
525 - git add file2 file10 &&
526 - git commit -a -m "Modify and copy file2 to file10" &&
527 - git diff-tree -r -C HEAD &&
528 - git p4 submit &&
529 - p4 filelog //depot/file10 &&
530 - p4 filelog //depot/file10 | grep -q "branch from //depot/file" &&
531 -
532 - cp file2 file11 &&
533 - git add file11 &&
534 - git commit -a -m "Copy file2 to file11" &&
535 - git diff-tree -r -C --find-copies-harder HEAD &&
536 - src=$(git diff-tree -r -C --find-copies-harder HEAD | sed 1d | cut -f2) &&
537 - test "$src" = file10 &&
538 - git config git-p4.detectCopiesHarder true &&
539 - git p4 submit &&
540 - p4 filelog //depot/file11 &&
541 - p4 filelog //depot/file11 | grep -q "branch from //depot/file" &&
542 -
543 - cp file2 file12 &&
544 - echo "some text" >>file12 &&
545 - git add file12 &&
546 - git commit -a -m "Copy file2 to file12 with changes" &&
547 - git diff-tree -r -C --find-copies-harder HEAD &&
548 - level=$(git diff-tree -r -C --find-copies-harder HEAD | sed 1d | cut -f1 | cut -d" " -f5 | sed "s/C0*//") &&
549 - test -n "$level" && test "$level" -gt 0 && test "$level" -lt 98 &&
550 - src=$(git diff-tree -r -C --find-copies-harder HEAD | sed 1d | cut -f2) &&
551 - test "$src" = file10 -o "$src" = file11 &&
552 - git config git-p4.detectCopies $(($level + 2)) &&
553 - git p4 submit &&
554 - p4 filelog //depot/file12 &&
555 - p4 filelog //depot/file12 | test_must_fail grep -q "branch from" &&
556 -
557 - cp file2 file13 &&
558 - echo "different text" >>file13 &&
559 - git add file13 &&
560 - git commit -a -m "Copy file2 to file13 with changes" &&
561 - git diff-tree -r -C --find-copies-harder HEAD &&
562 - level=$(git diff-tree -r -C --find-copies-harder HEAD | sed 1d | cut -f1 | cut -d" " -f5 | sed "s/C0*//") &&
563 - test -n "$level" && test "$level" -gt 2 && test "$level" -lt 100 &&
564 - src=$(git diff-tree -r -C --find-copies-harder HEAD | sed 1d | cut -f2) &&
565 - test "$src" = file10 -o "$src" = file11 -o "$src" = file12 &&
566 - git config git-p4.detectCopies $(($level - 2)) &&
567 - git p4 submit &&
568 - p4 filelog //depot/file13 &&
569 - p4 filelog //depot/file13 | grep -q "branch from //depot/file"
570 - )
571 -'
572 -
176 test_expect_success 'kill p4d' '
177 kill_p4d
178 '
t/t9812-git-p4-wildcards.sh new
+147
@@ -0,0 +1,147 @@
1 +#!/bin/sh
2 +
3 +test_description='git p4 wildcards'
4 +
5 +. ./lib-git-p4.sh
6 +
7 +test_expect_success 'start p4d' '
8 + start_p4d
9 +'
10 +
11 +test_expect_success 'add p4 files with wildcards in the names' '
12 + (
13 + cd "$cli" &&
14 + printf "file2\nhas\nsome\nrandom\ntext\n" >file2 &&
15 + p4 add file2 &&
16 + echo file-wild-hash >file-wild#hash &&
17 + echo file-wild-star >file-wild\*star &&
18 + echo file-wild-at >file-wild@at &&
19 + echo file-wild-percent >file-wild%percent &&
20 + p4 add -f file-wild* &&
21 + p4 submit -d "file wildcards"
22 + )
23 +'
24 +
25 +test_expect_success 'wildcard files git p4 clone' '
26 + git p4 clone --dest="$git" //depot &&
27 + test_when_finished cleanup_git &&
28 + (
29 + cd "$git" &&
30 + test -f file-wild#hash &&
31 + test -f file-wild\*star &&
32 + test -f file-wild@at &&
33 + test -f file-wild%percent
34 + )
35 +'
36 +
37 +test_expect_success 'wildcard files submit back to p4, add' '
38 + test_when_finished cleanup_git &&
39 + git p4 clone --dest="$git" //depot &&
40 + (
41 + cd "$git" &&
42 + echo git-wild-hash >git-wild#hash &&
43 + echo git-wild-star >git-wild\*star &&
44 + echo git-wild-at >git-wild@at &&
45 + echo git-wild-percent >git-wild%percent &&
46 + git add git-wild* &&
47 + git commit -m "add some wildcard filenames" &&
48 + git config git-p4.skipSubmitEdit true &&
49 + git p4 submit
50 + ) &&
51 + (
52 + cd "$cli" &&
53 + test_path_is_file git-wild#hash &&
54 + test_path_is_file git-wild\*star &&
55 + test_path_is_file git-wild@at &&
56 + test_path_is_file git-wild%percent
57 + )
58 +'
59 +
60 +test_expect_success 'wildcard files submit back to p4, modify' '
61 + test_when_finished cleanup_git &&
62 + git p4 clone --dest="$git" //depot &&
63 + (
64 + cd "$git" &&
65 + echo new-line >>git-wild#hash &&
66 + echo new-line >>git-wild\*star &&
67 + echo new-line >>git-wild@at &&
68 + echo new-line >>git-wild%percent &&
69 + git add git-wild* &&
70 + git commit -m "modify the wildcard files" &&
71 + git config git-p4.skipSubmitEdit true &&
72 + git p4 submit
73 + ) &&
74 + (
75 + cd "$cli" &&
76 + test_line_count = 2 git-wild#hash &&
77 + test_line_count = 2 git-wild\*star &&
78 + test_line_count = 2 git-wild@at &&
79 + test_line_count = 2 git-wild%percent
80 + )
81 +'
82 +
83 +test_expect_success 'wildcard files submit back to p4, copy' '
84 + test_when_finished cleanup_git &&
85 + git p4 clone --dest="$git" //depot &&
86 + (
87 + cd "$git" &&
88 + cp file2 git-wild-cp#hash &&
89 + git add git-wild-cp#hash &&
90 + cp git-wild\*star file-wild-3 &&
91 + git add file-wild-3 &&
92 + git commit -m "wildcard copies" &&
93 + git config git-p4.detectCopies true &&
94 + git config git-p4.detectCopiesHarder true &&
95 + git config git-p4.skipSubmitEdit true &&
96 + git p4 submit
97 + ) &&
98 + (
99 + cd "$cli" &&
100 + test_path_is_file git-wild-cp#hash &&
101 + test_path_is_file file-wild-3
102 + )
103 +'
104 +
105 +test_expect_success 'wildcard files submit back to p4, rename' '
106 + test_when_finished cleanup_git &&
107 + git p4 clone --dest="$git" //depot &&
108 + (
109 + cd "$git" &&
110 + git mv git-wild@at file-wild-4 &&
111 + git mv file-wild-3 git-wild-cp%percent &&
112 + git commit -m "wildcard renames" &&
113 + git config git-p4.detectRenames true &&
114 + git config git-p4.skipSubmitEdit true &&
115 + git p4 submit
116 + ) &&
117 + (
118 + cd "$cli" &&
119 + test_path_is_missing git-wild@at &&
120 + test_path_is_file git-wild-cp%percent
121 + )
122 +'
123 +
124 +test_expect_success 'wildcard files submit back to p4, delete' '
125 + test_when_finished cleanup_git &&
126 + git p4 clone --dest="$git" //depot &&
127 + (
128 + cd "$git" &&
129 + git rm git-wild* &&
130 + git commit -m "delete the wildcard files" &&
131 + git config git-p4.skipSubmitEdit true &&
132 + git p4 submit
133 + ) &&
134 + (
135 + cd "$cli" &&
136 + test_path_is_missing git-wild#hash &&
137 + test_path_is_missing git-wild\*star &&
138 + test_path_is_missing git-wild@at &&
139 + test_path_is_missing git-wild%percent
140 + )
141 +'
142 +
143 +test_expect_success 'kill p4d' '
144 + kill_p4d
145 +'
146 +
147 +test_done
t/t9813-git-p4-preserve-users.sh new
+153
@@ -0,0 +1,153 @@
1 +#!/bin/sh
2 +
3 +test_description='git p4 preserve users'
4 +
5 +. ./lib-git-p4.sh
6 +
7 +test_expect_success 'start p4d' '
8 + start_p4d
9 +'
10 +
11 +test_expect_success 'create files' '
12 + (
13 + cd "$cli" &&
14 + p4 client -o | sed "/LineEnd/s/:.*/:unix/" | p4 client -i &&
15 + echo file1 >file1 &&
16 + echo file2 >file2 &&
17 + p4 add file1 file2 &&
18 + p4 submit -d "add files"
19 + )
20 +'
21 +
22 +p4_add_user() {
23 + name=$1 fullname=$2 &&
24 + p4 user -f -i <<-EOF &&
25 + User: $name
26 + Email: $name@localhost
27 + FullName: $fullname
28 + EOF
29 + p4 passwd -P secret $name
30 +}
31 +
32 +p4_grant_admin() {
33 + name=$1 &&
34 + {
35 + p4 protect -o &&
36 + echo " admin user $name * //depot/..."
37 + } | p4 protect -i
38 +}
39 +
40 +p4_check_commit_author() {
41 + file=$1 user=$2 &&
42 + p4 changes -m 1 //depot/$file | grep -q $user
43 +}
44 +
45 +make_change_by_user() {
46 + file=$1 name=$2 email=$3 &&
47 + echo "username: a change by $name" >>"$file" &&
48 + git add "$file" &&
49 + git commit --author "$name <$email>" -m "a change by $name"
50 +}
51 +
52 +# Test username support, submitting as user 'alice'
53 +test_expect_success 'preserve users' '
54 + p4_add_user alice Alice &&
55 + p4_add_user bob Bob &&
56 + p4_grant_admin alice &&
57 + git p4 clone --dest="$git" //depot &&
58 + test_when_finished cleanup_git &&
59 + (
60 + cd "$git" &&
61 + echo "username: a change by alice" >>file1 &&
62 + echo "username: a change by bob" >>file2 &&
63 + git commit --author "Alice <alice@localhost>" -m "a change by alice" file1 &&
64 + git commit --author "Bob <bob@localhost>" -m "a change by bob" file2 &&
65 + git config git-p4.skipSubmitEditCheck true &&
66 + P4EDITOR=touch P4USER=alice P4PASSWD=secret git p4 commit --preserve-user &&
67 + p4_check_commit_author file1 alice &&
68 + p4_check_commit_author file2 bob
69 + )
70 +'
71 +
72 +# Test username support, submitting as bob, who lacks admin rights. Should
73 +# not submit change to p4 (git diff should show deltas).
74 +test_expect_success 'refuse to preserve users without perms' '
75 + git p4 clone --dest="$git" //depot &&
76 + test_when_finished cleanup_git &&
77 + (
78 + cd "$git" &&
79 + git config git-p4.skipSubmitEditCheck true &&
80 + echo "username-noperms: a change by alice" >>file1 &&
81 + git commit --author "Alice <alice@localhost>" -m "perms: a change by alice" file1 &&
82 + P4EDITOR=touch P4USER=bob P4PASSWD=secret &&
83 + export P4EDITOR P4USER P4PASSWD &&
84 + test_must_fail git p4 commit --preserve-user &&
85 + ! git diff --exit-code HEAD..p4/master
86 + )
87 +'
88 +
89 +# What happens with unknown author? Without allowMissingP4Users it should fail.
90 +test_expect_success 'preserve user where author is unknown to p4' '
91 + git p4 clone --dest="$git" //depot &&
92 + test_when_finished cleanup_git &&
93 + (
94 + cd "$git" &&
95 + git config git-p4.skipSubmitEditCheck true &&
96 + echo "username-bob: a change by bob" >>file1 &&
97 + git commit --author "Bob <bob@localhost>" -m "preserve: a change by bob" file1 &&
98 + echo "username-unknown: a change by charlie" >>file1 &&
99 + git commit --author "Charlie <charlie@localhost>" -m "preserve: a change by charlie" file1 &&
100 + P4EDITOR=touch P4USER=alice P4PASSWD=secret &&
101 + export P4EDITOR P4USER P4PASSWD &&
102 + test_must_fail git p4 commit --preserve-user &&
103 + ! git diff --exit-code HEAD..p4/master &&
104 +
105 + echo "$0: repeat with allowMissingP4Users enabled" &&
106 + git config git-p4.allowMissingP4Users true &&
107 + git config git-p4.preserveUser true &&
108 + git p4 commit &&
109 + git diff --exit-code HEAD..p4/master &&
110 + p4_check_commit_author file1 alice
111 + )
112 +'
113 +
114 +# If we're *not* using --preserve-user, git-p4 should warn if we're submitting
115 +# changes that are not all ours.
116 +# Test: user in p4 and user unknown to p4.
117 +# Test: warning disabled and user is the same.
118 +test_expect_success 'not preserving user with mixed authorship' '
119 + git p4 clone --dest="$git" //depot &&
120 + test_when_finished cleanup_git &&
121 + (
122 + cd "$git" &&
123 + git config git-p4.skipSubmitEditCheck true &&
124 + p4_add_user derek Derek &&
125 +
126 + make_change_by_user usernamefile3 Derek derek@localhost &&
127 + P4EDITOR=cat P4USER=alice P4PASSWD=secret &&
128 + export P4EDITOR P4USER P4PASSWD &&
129 + git p4 commit |\
130 + grep "git author derek@localhost does not match" &&
131 +
132 + make_change_by_user usernamefile3 Charlie charlie@localhost &&
133 + git p4 commit |\
134 + grep "git author charlie@localhost does not match" &&
135 +
136 + make_change_by_user usernamefile3 alice alice@localhost &&
137 + git p4 commit |\
138 + test_must_fail grep "git author.*does not match" &&
139 +
140 + git config git-p4.skipUserNameCheck true &&
141 + make_change_by_user usernamefile3 Charlie charlie@localhost &&
142 + git p4 commit |\
143 + test_must_fail grep "git author.*does not match" &&
144 +
145 + p4_check_commit_author usernamefile3 alice
146 + )
147 +'
148 +
149 +test_expect_success 'kill p4d' '
150 + kill_p4d
151 +'
152 +
153 +test_done
t/t9814-git-p4-rename.sh new
+206
@@ -0,0 +1,206 @@
1 +#!/bin/sh
2 +
3 +test_description='git p4 rename'
4 +
5 +. ./lib-git-p4.sh
6 +
7 +test_expect_success 'start p4d' '
8 + start_p4d
9 +'
10 +
11 +# We rely on this behavior to detect for p4 move availability.
12 +test_expect_success 'p4 help unknown returns 1' '
13 + (
14 + cd "$cli" &&
15 + (
16 + p4 help client >errs 2>&1
17 + echo $? >retval
18 + )
19 + echo 0 >expected &&
20 + test_cmp expected retval &&
21 + rm retval &&
22 + (
23 + p4 help nosuchcommand >errs 2>&1
24 + echo $? >retval
25 + )
26 + echo 1 >expected &&
27 + test_cmp expected retval &&
28 + rm retval
29 + )
30 +'
31 +
32 +test_expect_success 'create files' '
33 + (
34 + cd "$cli" &&
35 + p4 client -o | sed "/LineEnd/s/:.*/:unix/" | p4 client -i &&
36 + cat >file1 <<-EOF &&
37 + A large block of text
38 + in file1 that will generate
39 + enough context so that rename
40 + and copy detection will find
41 + something interesting to do.
42 + EOF
43 + cat >file2 <<-EOF &&
44 + /*
45 + * This blob looks a bit
46 + * different.
47 + */
48 + int main(int argc, char **argv)
49 + {
50 + char text[200];
51 +
52 + strcpy(text, "copy/rename this");
53 + printf("text is %s\n", text);
54 + return 0;
55 + }
56 + EOF
57 + p4 add file1 file2 &&
58 + p4 submit -d "add files"
59 + )
60 +'
61 +
62 +# Rename a file and confirm that rename is not detected in P4.
63 +# Rename the new file again with detectRenames option enabled and confirm that
64 +# this is detected in P4.
65 +# Rename the new file again adding an extra line, configure a big threshold in
66 +# detectRenames and confirm that rename is not detected in P4.
67 +# Repeat, this time with a smaller threshold and confirm that the rename is
68 +# detected in P4.
69 +test_expect_success 'detect renames' '
70 + git p4 clone --dest="$git" //depot@all &&
71 + test_when_finished cleanup_git &&
72 + (
73 + cd "$git" &&
74 + git config git-p4.skipSubmitEdit true &&
75 +
76 + git mv file1 file4 &&
77 + git commit -a -m "Rename file1 to file4" &&
78 + git diff-tree -r -M HEAD &&
79 + git p4 submit &&
80 + p4 filelog //depot/file4 &&
81 + p4 filelog //depot/file4 | test_must_fail grep -q "branch from" &&
82 +
83 + git mv file4 file5 &&
84 + git commit -a -m "Rename file4 to file5" &&
85 + git diff-tree -r -M HEAD &&
86 + git config git-p4.detectRenames true &&
87 + git p4 submit &&
88 + p4 filelog //depot/file5 &&
89 + p4 filelog //depot/file5 | grep -q "branch from //depot/file4" &&
90 +
91 + git mv file5 file6 &&
92 + echo update >>file6 &&
93 + git add file6 &&
94 + git commit -a -m "Rename file5 to file6 with changes" &&
95 + git diff-tree -r -M HEAD &&
96 + level=$(git diff-tree -r -M HEAD | sed 1d | cut -f1 | cut -d" " -f5 | sed "s/R0*//") &&
97 + test -n "$level" && test "$level" -gt 0 && test "$level" -lt 98 &&
98 + git config git-p4.detectRenames $(($level + 2)) &&
99 + git p4 submit &&
100 + p4 filelog //depot/file6 &&
101 + p4 filelog //depot/file6 | test_must_fail grep -q "branch from" &&
102 +
103 + git mv file6 file7 &&
104 + echo update >>file7 &&
105 + git add file7 &&
106 + git commit -a -m "Rename file6 to file7 with changes" &&
107 + git diff-tree -r -M HEAD &&
108 + level=$(git diff-tree -r -M HEAD | sed 1d | cut -f1 | cut -d" " -f5 | sed "s/R0*//") &&
109 + test -n "$level" && test "$level" -gt 2 && test "$level" -lt 100 &&
110 + git config git-p4.detectRenames $(($level - 2)) &&
111 + git p4 submit &&
112 + p4 filelog //depot/file7 &&
113 + p4 filelog //depot/file7 | grep -q "branch from //depot/file6"
114 + )
115 +'
116 +
117 +# Copy a file and confirm that copy is not detected in P4.
118 +# Copy a file with detectCopies option enabled and confirm that copy is not
119 +# detected in P4.
120 +# Modify and copy a file with detectCopies option enabled and confirm that copy
121 +# is detected in P4.
122 +# Copy a file with detectCopies and detectCopiesHarder options enabled and
123 +# confirm that copy is detected in P4.
124 +# Modify and copy a file, configure a bigger threshold in detectCopies and
125 +# confirm that copy is not detected in P4.
126 +# Modify and copy a file, configure a smaller threshold in detectCopies and
127 +# confirm that copy is detected in P4.
128 +test_expect_success 'detect copies' '
129 + git p4 clone --dest="$git" //depot@all &&
130 + test_when_finished cleanup_git &&
131 + (
132 + cd "$git" &&
133 + git config git-p4.skipSubmitEdit true &&
134 +
135 + cp file2 file8 &&
136 + git add file8 &&
137 + git commit -a -m "Copy file2 to file8" &&
138 + git diff-tree -r -C HEAD &&
139 + git p4 submit &&
140 + p4 filelog //depot/file8 &&
141 + p4 filelog //depot/file8 | test_must_fail grep -q "branch from" &&
142 +
143 + cp file2 file9 &&
144 + git add file9 &&
145 + git commit -a -m "Copy file2 to file9" &&
146 + git diff-tree -r -C HEAD &&
147 + git config git-p4.detectCopies true &&
148 + git p4 submit &&
149 + p4 filelog //depot/file9 &&
150 + p4 filelog //depot/file9 | test_must_fail grep -q "branch from" &&
151 +
152 + echo "file2" >>file2 &&
153 + cp file2 file10 &&
154 + git add file2 file10 &&
155 + git commit -a -m "Modify and copy file2 to file10" &&
156 + git diff-tree -r -C HEAD &&
157 + git p4 submit &&
158 + p4 filelog //depot/file10 &&
159 + p4 filelog //depot/file10 | grep -q "branch from //depot/file" &&
160 +
161 + cp file2 file11 &&
162 + git add file11 &&
163 + git commit -a -m "Copy file2 to file11" &&
164 + git diff-tree -r -C --find-copies-harder HEAD &&
165 + src=$(git diff-tree -r -C --find-copies-harder HEAD | sed 1d | cut -f2) &&
166 + test "$src" = file10 &&
167 + git config git-p4.detectCopiesHarder true &&
168 + git p4 submit &&
169 + p4 filelog //depot/file11 &&
170 + p4 filelog //depot/file11 | grep -q "branch from //depot/file" &&
171 +
172 + cp file2 file12 &&
173 + echo "some text" >>file12 &&
174 + git add file12 &&
175 + git commit -a -m "Copy file2 to file12 with changes" &&
176 + git diff-tree -r -C --find-copies-harder HEAD &&
177 + level=$(git diff-tree -r -C --find-copies-harder HEAD | sed 1d | cut -f1 | cut -d" " -f5 | sed "s/C0*//") &&
178 + test -n "$level" && test "$level" -gt 0 && test "$level" -lt 98 &&
179 + src=$(git diff-tree -r -C --find-copies-harder HEAD | sed 1d | cut -f2) &&
180 + test "$src" = file10 -o "$src" = file11 &&
181 + git config git-p4.detectCopies $(($level + 2)) &&
182 + git p4 submit &&
183 + p4 filelog //depot/file12 &&
184 + p4 filelog //depot/file12 | test_must_fail grep -q "branch from" &&
185 +
186 + cp file2 file13 &&
187 + echo "different text" >>file13 &&
188 + git add file13 &&
189 + git commit -a -m "Copy file2 to file13 with changes" &&
190 + git diff-tree -r -C --find-copies-harder HEAD &&
191 + level=$(git diff-tree -r -C --find-copies-harder HEAD | sed 1d | cut -f1 | cut -d" " -f5 | sed "s/C0*//") &&
192 + test -n "$level" && test "$level" -gt 2 && test "$level" -lt 100 &&
193 + src=$(git diff-tree -r -C --find-copies-harder HEAD | sed 1d | cut -f2) &&
194 + test "$src" = file10 -o "$src" = file11 -o "$src" = file12 &&
195 + git config git-p4.detectCopies $(($level - 2)) &&
196 + git p4 submit &&
197 + p4 filelog //depot/file13 &&
198 + p4 filelog //depot/file13 | grep -q "branch from //depot/file"
199 + )
200 +'
201 +
202 +test_expect_success 'kill p4d' '
203 + kill_p4d
204 +'
205 +
206 +test_done