t9809-git-p4-client-view.sh 21.2 KB
Newer Older
1 2
#!/bin/sh

3
test_description='git p4 client view'
4 5 6 7 8 9 10 11 12 13 14 15 16

. ./lib-git-p4.sh

test_expect_success 'start p4d' '
	start_p4d
'

#
# Verify these files exist, exactly.  Caller creates
# a list of files in file "files".
#
check_files_exist() {
	ok=0 &&
17
	num=$# &&
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
	for arg ; do
		test_path_is_file "$arg" &&
		ok=$(($ok + 1))
	done &&
	test $ok -eq $num &&
	test_line_count = $num files
}

#
# Sync up the p4 client, make sure the given files (and only
# those) exist.
#
client_verify() {
	(
		cd "$cli" &&
		p4 sync &&
		find . -type f ! -name files >files &&
		check_files_exist "[email protected]"
	)
}

#
# Make sure the named files, exactly, exist.
#
git_verify() {
	(
		cd "$git" &&
		git ls-files >files &&
		check_files_exist "[email protected]"
	)
}

# //depot
#   - dir1
#     - file11
#     - file12
#   - dir2
#     - file21
#     - file22
57 58 59 60 61 62 63 64 65 66 67 68 69 70
init_depot() {
	for d in 1 2 ; do
		mkdir -p dir$d &&
		for f in 1 2 ; do
			echo dir$d/file$d$f >dir$d/file$d$f &&
			p4 add dir$d/file$d$f &&
			p4 submit -d "dir$d/file$d$f"
		done
	done &&
	find . -type f ! -name files >files &&
	check_files_exist dir1/file11 dir1/file12 \
			  dir2/file21 dir2/file22
}

71 72 73
test_expect_success 'init depot' '
	(
		cd "$cli" &&
74
		init_depot
75 76 77 78
	)
'

# double % for printf
79
test_expect_success 'view wildcard %%n' '
80 81
	client_view "//depot/%%%%1/sub/... //client/sub/%%%%1/..." &&
	test_when_finished cleanup_git &&
82
	git p4 clone --use-client-spec --dest="$git" //depot
83 84
'

85
test_expect_success 'view wildcard *' '
86 87
	client_view "//depot/*/bar/... //client/*/bar/..." &&
	test_when_finished cleanup_git &&
88
	git p4 clone --use-client-spec --dest="$git" //depot
89 90
'

91
test_expect_success 'wildcard ... in the middle' '
92 93
	client_view "//depot/.../file11 //client/.../file11" &&
	test_when_finished cleanup_git &&
94
	git p4 clone --use-client-spec --dest="$git" //depot
95 96
'

97
test_expect_success 'wildcard ... in the middle and at the end' '
98 99
	client_view "//depot/.../a/... //client/.../a/..." &&
	test_when_finished cleanup_git &&
100
	git p4 clone --use-client-spec --dest="$git" //depot
101 102
'

Pete Wyckoff's avatar
Pete Wyckoff committed
103
test_expect_success 'basic map' '
104 105 106 107
	client_view "//depot/dir1/... //client/cli1/..." &&
	files="cli1/file11 cli1/file12" &&
	client_verify $files &&
	test_when_finished cleanup_git &&
108
	git p4 clone --use-client-spec --dest="$git" //depot &&
109 110 111
	git_verify $files
'

Pete Wyckoff's avatar
Pete Wyckoff committed
112
test_expect_success 'client view with no mappings' '
113 114 115
	client_view &&
	client_verify &&
	test_when_finished cleanup_git &&
116
	git p4 clone --use-client-spec --dest="$git" //depot &&
117 118 119
	git_verify
'

Pete Wyckoff's avatar
Pete Wyckoff committed
120
test_expect_success 'single file map' '
121 122 123 124
	client_view "//depot/dir1/file11 //client/file11" &&
	files="file11" &&
	client_verify $files &&
	test_when_finished cleanup_git &&
125
	git p4 clone --use-client-spec --dest="$git" //depot &&
126 127 128
	git_verify $files
'

129
test_expect_success 'later mapping takes precedence (entire repo)' '
130 131 132 133 134 135
	client_view "//depot/dir1/... //client/cli1/..." \
		    "//depot/... //client/cli2/..." &&
	files="cli2/dir1/file11 cli2/dir1/file12
	       cli2/dir2/file21 cli2/dir2/file22" &&
	client_verify $files &&
	test_when_finished cleanup_git &&
136
	git p4 clone --use-client-spec --dest="$git" //depot &&
137 138 139
	git_verify $files
'

Pete Wyckoff's avatar
Pete Wyckoff committed
140
test_expect_success 'later mapping takes precedence (partial repo)' '
141 142 143 144 145
	client_view "//depot/dir1/... //client/..." \
		    "//depot/dir2/... //client/..." &&
	files="file21 file22" &&
	client_verify $files &&
	test_when_finished cleanup_git &&
146
	git p4 clone --use-client-spec --dest="$git" //depot &&
147 148 149 150 151 152 153 154
	git_verify $files
'

# Reading the view backwards,
#   dir2 goes to cli12
#   dir1 cannot go to cli12 since it was filled by dir2
#   dir1 also does not go to cli3, since the second rule
#     noticed that it matched, but was already filled
Pete Wyckoff's avatar
Pete Wyckoff committed
155
test_expect_success 'depot path matching rejected client path' '
156 157 158 159 160 161
	client_view "//depot/dir1/... //client/cli3/..." \
		    "//depot/dir1/... //client/cli12/..." \
		    "//depot/dir2/... //client/cli12/..." &&
	files="cli12/file21 cli12/file22" &&
	client_verify $files &&
	test_when_finished cleanup_git &&
162
	git p4 clone --use-client-spec --dest="$git" //depot &&
163 164 165 166 167
	git_verify $files
'

# since both have the same //client/..., the exclusion
# rule keeps everything out
Pete Wyckoff's avatar
Pete Wyckoff committed
168
test_expect_success 'exclusion wildcard, client rhs same (odd)' '
169 170 171 172
	client_view "//depot/... //client/..." \
		    "-//depot/dir2/... //client/..." &&
	client_verify &&
	test_when_finished cleanup_git &&
173
	git p4 clone --use-client-spec --dest="$git" //depot &&
174 175 176 177 178 179 180 181 182
	git_verify
'

test_expect_success 'exclusion wildcard, client rhs different (normal)' '
	client_view "//depot/... //client/..." \
		    "-//depot/dir2/... //client/dir2/..." &&
	files="dir1/file11 dir1/file12" &&
	client_verify $files &&
	test_when_finished cleanup_git &&
183
	git p4 clone --use-client-spec --dest="$git" //depot &&
184 185 186
	git_verify $files
'

187
test_expect_success 'exclusion single file' '
188 189 190 191 192
	client_view "//depot/... //client/..." \
		    "-//depot/dir2/file22 //client/file22" &&
	files="dir1/file11 dir1/file12 dir2/file21" &&
	client_verify $files &&
	test_when_finished cleanup_git &&
193
	git p4 clone --use-client-spec --dest="$git" //depot &&
194 195 196
	git_verify $files
'

Pete Wyckoff's avatar
Pete Wyckoff committed
197
test_expect_success 'overlay wildcard' '
198
	client_view "//depot/dir1/... //client/cli/..." \
199
		    "+//depot/dir2/... //client/cli/..." &&
200 201 202
	files="cli/file11 cli/file12 cli/file21 cli/file22" &&
	client_verify $files &&
	test_when_finished cleanup_git &&
203
	git p4 clone --use-client-spec --dest="$git" //depot &&
204 205 206
	git_verify $files
'

Pete Wyckoff's avatar
Pete Wyckoff committed
207
test_expect_success 'overlay single file' '
208 209 210 211 212
	client_view "//depot/dir1/... //client/cli/..." \
		    "+//depot/dir2/file21 //client/cli/file21" &&
	files="cli/file11 cli/file12 cli/file21" &&
	client_verify $files &&
	test_when_finished cleanup_git &&
213
	git p4 clone --use-client-spec --dest="$git" //depot &&
214 215 216
	git_verify $files
'

Pete Wyckoff's avatar
Pete Wyckoff committed
217
test_expect_success 'exclusion with later inclusion' '
218 219 220 221 222 223
	client_view "//depot/... //client/..." \
		    "-//depot/dir2/... //client/dir2/..." \
		    "//depot/dir2/... //client/dir2incl/..." &&
	files="dir1/file11 dir1/file12 dir2incl/file21 dir2incl/file22" &&
	client_verify $files &&
	test_when_finished cleanup_git &&
224
	git p4 clone --use-client-spec --dest="$git" //depot &&
225 226 227
	git_verify $files
'

Pete Wyckoff's avatar
Pete Wyckoff committed
228
test_expect_success 'quotes on rhs only' '
229 230 231
	client_view "//depot/dir1/... \"//client/cdir 1/...\"" &&
	client_verify "cdir 1/file11" "cdir 1/file12" &&
	test_when_finished cleanup_git &&
232
	git p4 clone --use-client-spec --dest="$git" //depot &&
233 234 235
	git_verify "cdir 1/file11" "cdir 1/file12"
'

236 237 238 239 240 241 242 243
#
# Submit tests
#

# clone sets variable
test_expect_success 'clone --use-client-spec sets useClientSpec' '
	client_view "//depot/... //client/..." &&
	test_when_finished cleanup_git &&
244
	git p4 clone --use-client-spec --dest="$git" //depot &&
245 246 247 248 249 250 251 252
	(
		cd "$git" &&
		git config --bool git-p4.useClientSpec >actual &&
		echo true >true &&
		test_cmp actual true
	)
'

253 254 255 256 257 258
# clone just a subdir of the client spec
test_expect_success 'subdir clone' '
	client_view "//depot/... //client/..." &&
	files="dir1/file11 dir1/file12 dir2/file21 dir2/file22" &&
	client_verify $files &&
	test_when_finished cleanup_git &&
259
	git p4 clone --use-client-spec --dest="$git" //depot/dir1 &&
260 261 262 263 264 265 266 267 268
	git_verify dir1/file11 dir1/file12
'

#
# submit back, see what happens:  five cases
#
test_expect_success 'subdir clone, submit modify' '
	client_view "//depot/... //client/..." &&
	test_when_finished cleanup_git &&
269
	git p4 clone --use-client-spec --dest="$git" //depot/dir1 &&
270 271 272 273 274 275
	(
		cd "$git" &&
		git config git-p4.skipSubmitEdit true &&
		echo line >>dir1/file12 &&
		git add dir1/file12 &&
		git commit -m dir1/file12 &&
276
		git p4 submit
277 278 279 280 281 282 283 284 285 286 287
	) &&
	(
		cd "$cli" &&
		test_path_is_file dir1/file12 &&
		test_line_count = 2 dir1/file12
	)
'

test_expect_success 'subdir clone, submit add' '
	client_view "//depot/... //client/..." &&
	test_when_finished cleanup_git &&
288
	git p4 clone --use-client-spec --dest="$git" //depot/dir1 &&
289 290 291 292 293 294
	(
		cd "$git" &&
		git config git-p4.skipSubmitEdit true &&
		echo file13 >dir1/file13 &&
		git add dir1/file13 &&
		git commit -m dir1/file13 &&
295
		git p4 submit
296 297 298 299 300 301 302 303 304 305
	) &&
	(
		cd "$cli" &&
		test_path_is_file dir1/file13
	)
'

test_expect_success 'subdir clone, submit delete' '
	client_view "//depot/... //client/..." &&
	test_when_finished cleanup_git &&
306
	git p4 clone --use-client-spec --dest="$git" //depot/dir1 &&
307 308 309 310 311
	(
		cd "$git" &&
		git config git-p4.skipSubmitEdit true &&
		git rm dir1/file12 &&
		git commit -m "delete dir1/file12" &&
312
		git p4 submit
313 314 315 316 317 318 319 320 321 322
	) &&
	(
		cd "$cli" &&
		test_path_is_missing dir1/file12
	)
'

test_expect_success 'subdir clone, submit copy' '
	client_view "//depot/... //client/..." &&
	test_when_finished cleanup_git &&
323
	git p4 clone --use-client-spec --dest="$git" //depot/dir1 &&
324 325 326 327 328 329 330
	(
		cd "$git" &&
		git config git-p4.skipSubmitEdit true &&
		git config git-p4.detectCopies true &&
		cp dir1/file11 dir1/file11a &&
		git add dir1/file11a &&
		git commit -m "copy to dir1/file11a" &&
331
		git p4 submit
332 333 334
	) &&
	(
		cd "$cli" &&
335
		test_path_is_file dir1/file11a &&
336
		! is_cli_file_writeable dir1/file11a
337 338 339 340 341 342
	)
'

test_expect_success 'subdir clone, submit rename' '
	client_view "//depot/... //client/..." &&
	test_when_finished cleanup_git &&
343
	git p4 clone --use-client-spec --dest="$git" //depot/dir1 &&
344 345 346 347 348 349
	(
		cd "$git" &&
		git config git-p4.skipSubmitEdit true &&
		git config git-p4.detectRenames true &&
		git mv dir1/file13 dir1/file13a &&
		git commit -m "rename dir1/file13 to dir1/file13a" &&
350
		git p4 submit
351 352 353 354
	) &&
	(
		cd "$cli" &&
		test_path_is_missing dir1/file13 &&
355
		test_path_is_file dir1/file13a &&
356
		! is_cli_file_writeable dir1/file13a
357 358 359
	)
'

360 361 362 363 364 365 366 367
# see t9800 for the non-client-spec case, and the rest of the wildcard tests
test_expect_success 'wildcard files submit back to p4, client-spec case' '
	client_view "//depot/... //client/..." &&
	test_when_finished cleanup_git &&
	git p4 clone --use-client-spec --dest="$git" //depot/dir1 &&
	(
		cd "$git" &&
		echo git-wild-hash >dir1/git-wild#hash &&
368
		if test_have_prereq !MINGW,!CYGWIN
369 370 371
		then
			echo git-wild-star >dir1/git-wild\*star
		fi &&
372 373 374 375 376 377 378 379 380 381
		echo git-wild-at >dir1/[email protected] &&
		echo git-wild-percent >dir1/git-wild%percent &&
		git add dir1/git-wild* &&
		git commit -m "add some wildcard filenames" &&
		git config git-p4.skipSubmitEditCheck true &&
		git p4 submit
	) &&
	(
		cd "$cli" &&
		test_path_is_file dir1/git-wild#hash &&
382
		if test_have_prereq !MINGW,!CYGWIN
383 384 385
		then
			test_path_is_file dir1/git-wild\*star
		fi &&
386 387 388 389 390 391 392 393 394 395 396 397 398
		test_path_is_file dir1/[email protected] &&
		test_path_is_file dir1/git-wild%percent
	) &&
	(
		# delete these carefully, cannot just do "p4 delete"
		# on files with wildcards; but git-p4 knows how
		cd "$git" &&
		git rm dir1/git-wild* &&
		git commit -m "clean up the wildcards" &&
		git p4 submit
	)
'

399 400 401 402 403 404 405 406 407 408
test_expect_success 'reinit depot' '
	(
		cd "$cli" &&
		rm files &&
		p4 delete */* &&
		p4 submit -d "delete all files" &&
		init_depot
	)
'

409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444
#
# What happens when two files of the same name are overlayed together?
# The last-listed file should take preference.
#
# //depot
#   - dir1
#     - file11
#     - file12
#     - filecollide
#   - dir2
#     - file21
#     - file22
#     - filecollide
#
test_expect_success 'overlay collision setup' '
	client_view "//depot/... //client/..." &&
	(
		cd "$cli" &&
		p4 sync &&
		echo dir1/filecollide >dir1/filecollide &&
		p4 add dir1/filecollide &&
		p4 submit -d dir1/filecollide &&
		echo dir2/filecollide >dir2/filecollide &&
		p4 add dir2/filecollide &&
		p4 submit -d dir2/filecollide
	)
'

test_expect_success 'overlay collision 1 to 2' '
	client_view "//depot/dir1/... //client/..." \
		    "+//depot/dir2/... //client/..." &&
	files="file11 file12 file21 file22 filecollide" &&
	echo dir2/filecollide >actual &&
	client_verify $files &&
	test_cmp actual "$cli"/filecollide &&
	test_when_finished cleanup_git &&
445
	git p4 clone --use-client-spec --dest="$git" //depot &&
446 447 448 449 450 451 452 453 454 455 456 457
	git_verify $files &&
	test_cmp actual "$git"/filecollide
'

test_expect_failure 'overlay collision 2 to 1' '
	client_view "//depot/dir2/... //client/..." \
		    "+//depot/dir1/... //client/..." &&
	files="file11 file12 file21 file22 filecollide" &&
	echo dir1/filecollide >actual &&
	client_verify $files &&
	test_cmp actual "$cli"/filecollide &&
	test_when_finished cleanup_git &&
458
	git p4 clone --use-client-spec --dest="$git" //depot &&
459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479
	git_verify $files &&
	test_cmp actual "$git"/filecollide
'

test_expect_success 'overlay collision delete 2' '
	client_view "//depot/... //client/..." &&
	(
		cd "$cli" &&
		p4 sync &&
		p4 delete dir2/filecollide &&
		p4 submit -d "remove dir2/filecollide"
	)
'

# no filecollide, got deleted with dir2
test_expect_failure 'overlay collision 1 to 2, but 2 deleted' '
	client_view "//depot/dir1/... //client/..." \
		    "+//depot/dir2/... //client/..." &&
	files="file11 file12 file21 file22" &&
	client_verify $files &&
	test_when_finished cleanup_git &&
480
	git p4 clone --use-client-spec --dest="$git" //depot &&
481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502
	git_verify $files
'

test_expect_success 'overlay collision update 1' '
	client_view "//depot/dir1/... //client/dir1/..." &&
	(
		cd "$cli" &&
		p4 sync &&
		p4 open dir1/filecollide &&
		echo dir1/filecollide update >dir1/filecollide &&
		p4 submit -d "update dir1/filecollide"
	)
'

# still no filecollide, dir2 still wins with the deletion even though the
# change to dir1 is more recent
test_expect_failure 'overlay collision 1 to 2, but 2 deleted, then 1 updated' '
	client_view "//depot/dir1/... //client/..." \
		    "+//depot/dir2/... //client/..." &&
	files="file11 file12 file21 file22" &&
	client_verify $files &&
	test_when_finished cleanup_git &&
503
	git p4 clone --use-client-spec --dest="$git" //depot &&
504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558
	git_verify $files
'

test_expect_success 'overlay collision delete filecollides' '
	client_view "//depot/... //client/..." &&
	(
		cd "$cli" &&
		p4 sync &&
		p4 delete dir1/filecollide dir2/filecollide &&
		p4 submit -d "remove filecollides"
	)
'

#
# Overlays as part of sync, rather than initial checkout:
#   1.  add a file in dir1
#   2.  sync to include it
#   3.  add same file in dir2
#   4.  sync, make sure content switches as dir2 has priority
#   5.  add another file in dir1
#   6.  sync
#   7.  add/delete same file in dir2
#   8.  sync, make sure it disappears, again dir2 wins
#   9.  cleanup
#
# //depot
#   - dir1
#     - file11
#     - file12
#     - colA
#     - colB
#   - dir2
#     - file21
#     - file22
#     - colA
#     - colB
#
test_expect_success 'overlay sync: add colA in dir1' '
	client_view "//depot/dir1/... //client/dir1/..." &&
	(
		cd "$cli" &&
		p4 sync &&
		echo dir1/colA >dir1/colA &&
		p4 add dir1/colA &&
		p4 submit -d dir1/colA
	)
'

test_expect_success 'overlay sync: initial git checkout' '
	client_view "//depot/dir1/... //client/..." \
		    "+//depot/dir2/... //client/..." &&
	files="file11 file12 file21 file22 colA" &&
	echo dir1/colA >actual &&
	client_verify $files &&
	test_cmp actual "$cli"/colA &&
559
	git p4 clone --use-client-spec --dest="$git" //depot &&
560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583
	git_verify $files &&
	test_cmp actual "$git"/colA
'

test_expect_success 'overlay sync: add colA in dir2' '
	client_view "//depot/dir2/... //client/dir2/..." &&
	(
		cd "$cli" &&
		p4 sync &&
		echo dir2/colA >dir2/colA &&
		p4 add dir2/colA &&
		p4 submit -d dir2/colA
	)
'

test_expect_success 'overlay sync: colA content switch' '
	client_view "//depot/dir1/... //client/..." \
		    "+//depot/dir2/... //client/..." &&
	files="file11 file12 file21 file22 colA" &&
	echo dir2/colA >actual &&
	client_verify $files &&
	test_cmp actual "$cli"/colA &&
	(
		cd "$git" &&
584
		git p4 sync --use-client-spec &&
585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610
		git merge --ff-only p4/master
	) &&
	git_verify $files &&
	test_cmp actual "$git"/colA
'

test_expect_success 'overlay sync: add colB in dir1' '
	client_view "//depot/dir1/... //client/dir1/..." &&
	(
		cd "$cli" &&
		p4 sync &&
		echo dir1/colB >dir1/colB &&
		p4 add dir1/colB &&
		p4 submit -d dir1/colB
	)
'

test_expect_success 'overlay sync: colB appears' '
	client_view "//depot/dir1/... //client/..." \
		    "+//depot/dir2/... //client/..." &&
	files="file11 file12 file21 file22 colA colB" &&
	echo dir1/colB >actual &&
	client_verify $files &&
	test_cmp actual "$cli"/colB &&
	(
		cd "$git" &&
611
		git p4 sync --use-client-spec &&
612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638
		git merge --ff-only p4/master
	) &&
	git_verify $files &&
	test_cmp actual "$git"/colB
'

test_expect_success 'overlay sync: add/delete colB in dir2' '
	client_view "//depot/dir2/... //client/dir2/..." &&
	(
		cd "$cli" &&
		p4 sync &&
		echo dir2/colB >dir2/colB &&
		p4 add dir2/colB &&
		p4 submit -d dir2/colB &&
		p4 delete dir2/colB &&
		p4 submit -d "delete dir2/colB"
	)
'

test_expect_success 'overlay sync: colB disappears' '
	client_view "//depot/dir1/... //client/..." \
		    "+//depot/dir2/... //client/..." &&
	files="file11 file12 file21 file22 colA" &&
	client_verify $files &&
	test_when_finished cleanup_git &&
	(
		cd "$git" &&
639
		git p4 sync --use-client-spec &&
640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696
		git merge --ff-only p4/master
	) &&
	git_verify $files
'

test_expect_success 'overlay sync: cleanup' '
	client_view "//depot/... //client/..." &&
	(
		cd "$cli" &&
		p4 sync &&
		p4 delete dir1/colA dir2/colA dir1/colB &&
		p4 submit -d "remove overlay sync files"
	)
'

#
# Overlay tests again, but swapped so dir1 has priority.
#   1.  add a file in dir1
#   2.  sync to include it
#   3.  add same file in dir2
#   4.  sync, make sure content does not switch
#   5.  add another file in dir1
#   6.  sync
#   7.  add/delete same file in dir2
#   8.  sync, make sure it is still there
#   9.  cleanup
#
# //depot
#   - dir1
#     - file11
#     - file12
#     - colA
#     - colB
#   - dir2
#     - file21
#     - file22
#     - colA
#     - colB
#
test_expect_success 'overlay sync swap: add colA in dir1' '
	client_view "//depot/dir1/... //client/dir1/..." &&
	(
		cd "$cli" &&
		p4 sync &&
		echo dir1/colA >dir1/colA &&
		p4 add dir1/colA &&
		p4 submit -d dir1/colA
	)
'

test_expect_success 'overlay sync swap: initial git checkout' '
	client_view "//depot/dir2/... //client/..." \
		    "+//depot/dir1/... //client/..." &&
	files="file11 file12 file21 file22 colA" &&
	echo dir1/colA >actual &&
	client_verify $files &&
	test_cmp actual "$cli"/colA &&
697
	git p4 clone --use-client-spec --dest="$git" //depot &&
698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721
	git_verify $files &&
	test_cmp actual "$git"/colA
'

test_expect_success 'overlay sync swap: add colA in dir2' '
	client_view "//depot/dir2/... //client/dir2/..." &&
	(
		cd "$cli" &&
		p4 sync &&
		echo dir2/colA >dir2/colA &&
		p4 add dir2/colA &&
		p4 submit -d dir2/colA
	)
'

test_expect_failure 'overlay sync swap: colA no content switch' '
	client_view "//depot/dir2/... //client/..." \
		    "+//depot/dir1/... //client/..." &&
	files="file11 file12 file21 file22 colA" &&
	echo dir1/colA >actual &&
	client_verify $files &&
	test_cmp actual "$cli"/colA &&
	(
		cd "$git" &&
722
		git p4 sync --use-client-spec &&
723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748
		git merge --ff-only p4/master
	) &&
	git_verify $files &&
	test_cmp actual "$git"/colA
'

test_expect_success 'overlay sync swap: add colB in dir1' '
	client_view "//depot/dir1/... //client/dir1/..." &&
	(
		cd "$cli" &&
		p4 sync &&
		echo dir1/colB >dir1/colB &&
		p4 add dir1/colB &&
		p4 submit -d dir1/colB
	)
'

test_expect_success 'overlay sync swap: colB appears' '
	client_view "//depot/dir2/... //client/..." \
		    "+//depot/dir1/... //client/..." &&
	files="file11 file12 file21 file22 colA colB" &&
	echo dir1/colB >actual &&
	client_verify $files &&
	test_cmp actual "$cli"/colB &&
	(
		cd "$git" &&
749
		git p4 sync --use-client-spec &&
750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778
		git merge --ff-only p4/master
	) &&
	git_verify $files &&
	test_cmp actual "$git"/colB
'

test_expect_success 'overlay sync swap: add/delete colB in dir2' '
	client_view "//depot/dir2/... //client/dir2/..." &&
	(
		cd "$cli" &&
		p4 sync &&
		echo dir2/colB >dir2/colB &&
		p4 add dir2/colB &&
		p4 submit -d dir2/colB &&
		p4 delete dir2/colB &&
		p4 submit -d "delete dir2/colB"
	)
'

test_expect_failure 'overlay sync swap: colB no change' '
	client_view "//depot/dir2/... //client/..." \
		    "+//depot/dir1/... //client/..." &&
	files="file11 file12 file21 file22 colA colB" &&
	echo dir1/colB >actual &&
	client_verify $files &&
	test_cmp actual "$cli"/colB &&
	test_when_finished cleanup_git &&
	(
		cd "$git" &&
779
		git p4 sync --use-client-spec &&
780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795
		git merge --ff-only p4/master
	) &&
	git_verify $files &&
	test_cmp actual "$cli"/colB
'

test_expect_success 'overlay sync swap: cleanup' '
	client_view "//depot/... //client/..." &&
	(
		cd "$cli" &&
		p4 sync &&
		p4 delete dir1/colA dir2/colA dir1/colB &&
		p4 submit -d "remove overlay sync files"
	)
'

796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821
#
# Rename directories to test quoting in depot-side mappings
# //depot
#    - "dir 1"
#       - file11
#       - file12
#    - "dir 2"
#       - file21
#       - file22
#
test_expect_success 'rename files to introduce spaces' '
	client_view "//depot/... //client/..." &&
	client_verify dir1/file11 dir1/file12 \
		      dir2/file21 dir2/file22 &&
	(
		cd "$cli" &&
		p4 open dir1/... &&
		p4 move dir1/... "dir 1"/... &&
		p4 open dir2/... &&
		p4 move dir2/... "dir 2"/... &&
		p4 submit -d "rename with spaces"
	) &&
	client_verify "dir 1/file11" "dir 1/file12" \
		      "dir 2/file21" "dir 2/file22"
'

Pete Wyckoff's avatar
Pete Wyckoff committed
822
test_expect_success 'quotes on lhs only' '
823 824 825 826
	client_view "\"//depot/dir 1/...\" //client/cdir1/..." &&
	files="cdir1/file11 cdir1/file12" &&
	client_verify $files &&
	test_when_finished cleanup_git &&
827
	git p4 clone --use-client-spec --dest="$git" //depot &&
828 829 830
	client_verify $files
'

Pete Wyckoff's avatar
Pete Wyckoff committed
831
test_expect_success 'quotes on both sides' '
832 833 834
	client_view "\"//depot/dir 1/...\" \"//client/cdir 1/...\"" &&
	client_verify "cdir 1/file11" "cdir 1/file12" &&
	test_when_finished cleanup_git &&
835
	git p4 clone --use-client-spec --dest="$git" //depot &&
836 837 838 839 840 841 842 843
	git_verify "cdir 1/file11" "cdir 1/file12"
'

test_expect_success 'kill p4d' '
	kill_p4d
'

test_done