t / t9809-git-p4-client-view.shon commit Integrate wildmatch to git (feabcc1)
   1#!/bin/sh
   2
   3test_description='git p4 client view'
   4
   5. ./lib-git-p4.sh
   6
   7test_expect_success 'start p4d' '
   8        start_p4d
   9'
  10
  11#
  12# Construct a client with this list of View lines
  13#
  14client_view() {
  15        (
  16                cat <<-EOF &&
  17                Client: client
  18                Description: client
  19                Root: $cli
  20                View:
  21                EOF
  22                for arg ; do
  23                        printf "\t$arg\n"
  24                done
  25        ) | p4 client -i
  26}
  27
  28#
  29# Verify these files exist, exactly.  Caller creates
  30# a list of files in file "files".
  31#
  32check_files_exist() {
  33        ok=0 &&
  34        num=$# &&
  35        for arg ; do
  36                test_path_is_file "$arg" &&
  37                ok=$(($ok + 1))
  38        done &&
  39        test $ok -eq $num &&
  40        test_line_count = $num files
  41}
  42
  43#
  44# Sync up the p4 client, make sure the given files (and only
  45# those) exist.
  46#
  47client_verify() {
  48        (
  49                cd "$cli" &&
  50                p4 sync &&
  51                find . -type f ! -name files >files &&
  52                check_files_exist "$@"
  53        )
  54}
  55
  56#
  57# Make sure the named files, exactly, exist.
  58#
  59git_verify() {
  60        (
  61                cd "$git" &&
  62                git ls-files >files &&
  63                check_files_exist "$@"
  64        )
  65}
  66
  67# //depot
  68#   - dir1
  69#     - file11
  70#     - file12
  71#   - dir2
  72#     - file21
  73#     - file22
  74init_depot() {
  75        for d in 1 2 ; do
  76                mkdir -p dir$d &&
  77                for f in 1 2 ; do
  78                        echo dir$d/file$d$f >dir$d/file$d$f &&
  79                        p4 add dir$d/file$d$f &&
  80                        p4 submit -d "dir$d/file$d$f"
  81                done
  82        done &&
  83        find . -type f ! -name files >files &&
  84        check_files_exist dir1/file11 dir1/file12 \
  85                          dir2/file21 dir2/file22
  86}
  87
  88test_expect_success 'init depot' '
  89        (
  90                cd "$cli" &&
  91                init_depot
  92        )
  93'
  94
  95# double % for printf
  96test_expect_success 'unsupported view wildcard %%n' '
  97        client_view "//depot/%%%%1/sub/... //client/sub/%%%%1/..." &&
  98        test_when_finished cleanup_git &&
  99        test_must_fail git p4 clone --use-client-spec --dest="$git" //depot
 100'
 101
 102test_expect_success 'unsupported view wildcard *' '
 103        client_view "//depot/*/bar/... //client/*/bar/..." &&
 104        test_when_finished cleanup_git &&
 105        test_must_fail git p4 clone --use-client-spec --dest="$git" //depot
 106'
 107
 108test_expect_success 'wildcard ... only supported at end of spec 1' '
 109        client_view "//depot/.../file11 //client/.../file11" &&
 110        test_when_finished cleanup_git &&
 111        test_must_fail git p4 clone --use-client-spec --dest="$git" //depot
 112'
 113
 114test_expect_success 'wildcard ... only supported at end of spec 2' '
 115        client_view "//depot/.../a/... //client/.../a/..." &&
 116        test_when_finished cleanup_git &&
 117        test_must_fail git p4 clone --use-client-spec --dest="$git" //depot
 118'
 119
 120test_expect_success 'basic map' '
 121        client_view "//depot/dir1/... //client/cli1/..." &&
 122        files="cli1/file11 cli1/file12" &&
 123        client_verify $files &&
 124        test_when_finished cleanup_git &&
 125        git p4 clone --use-client-spec --dest="$git" //depot &&
 126        git_verify $files
 127'
 128
 129test_expect_success 'client view with no mappings' '
 130        client_view &&
 131        client_verify &&
 132        test_when_finished cleanup_git &&
 133        git p4 clone --use-client-spec --dest="$git" //depot &&
 134        git_verify
 135'
 136
 137test_expect_success 'single file map' '
 138        client_view "//depot/dir1/file11 //client/file11" &&
 139        files="file11" &&
 140        client_verify $files &&
 141        test_when_finished cleanup_git &&
 142        git p4 clone --use-client-spec --dest="$git" //depot &&
 143        git_verify $files
 144'
 145
 146test_expect_success 'later mapping takes precedence (entire repo)' '
 147        client_view "//depot/dir1/... //client/cli1/..." \
 148                    "//depot/... //client/cli2/..." &&
 149        files="cli2/dir1/file11 cli2/dir1/file12
 150               cli2/dir2/file21 cli2/dir2/file22" &&
 151        client_verify $files &&
 152        test_when_finished cleanup_git &&
 153        git p4 clone --use-client-spec --dest="$git" //depot &&
 154        git_verify $files
 155'
 156
 157test_expect_success 'later mapping takes precedence (partial repo)' '
 158        client_view "//depot/dir1/... //client/..." \
 159                    "//depot/dir2/... //client/..." &&
 160        files="file21 file22" &&
 161        client_verify $files &&
 162        test_when_finished cleanup_git &&
 163        git p4 clone --use-client-spec --dest="$git" //depot &&
 164        git_verify $files
 165'
 166
 167# Reading the view backwards,
 168#   dir2 goes to cli12
 169#   dir1 cannot go to cli12 since it was filled by dir2
 170#   dir1 also does not go to cli3, since the second rule
 171#     noticed that it matched, but was already filled
 172test_expect_success 'depot path matching rejected client path' '
 173        client_view "//depot/dir1/... //client/cli3/..." \
 174                    "//depot/dir1/... //client/cli12/..." \
 175                    "//depot/dir2/... //client/cli12/..." &&
 176        files="cli12/file21 cli12/file22" &&
 177        client_verify $files &&
 178        test_when_finished cleanup_git &&
 179        git p4 clone --use-client-spec --dest="$git" //depot &&
 180        git_verify $files
 181'
 182
 183# since both have the same //client/..., the exclusion
 184# rule keeps everything out
 185test_expect_success 'exclusion wildcard, client rhs same (odd)' '
 186        client_view "//depot/... //client/..." \
 187                    "-//depot/dir2/... //client/..." &&
 188        client_verify &&
 189        test_when_finished cleanup_git &&
 190        git p4 clone --use-client-spec --dest="$git" //depot &&
 191        git_verify
 192'
 193
 194test_expect_success 'exclusion wildcard, client rhs different (normal)' '
 195        client_view "//depot/... //client/..." \
 196                    "-//depot/dir2/... //client/dir2/..." &&
 197        files="dir1/file11 dir1/file12" &&
 198        client_verify $files &&
 199        test_when_finished cleanup_git &&
 200        git p4 clone --use-client-spec --dest="$git" //depot &&
 201        git_verify $files
 202'
 203
 204test_expect_success 'exclusion single file' '
 205        client_view "//depot/... //client/..." \
 206                    "-//depot/dir2/file22 //client/file22" &&
 207        files="dir1/file11 dir1/file12 dir2/file21" &&
 208        client_verify $files &&
 209        test_when_finished cleanup_git &&
 210        git p4 clone --use-client-spec --dest="$git" //depot &&
 211        git_verify $files
 212'
 213
 214test_expect_success 'overlay wildcard' '
 215        client_view "//depot/dir1/... //client/cli/..." \
 216                    "+//depot/dir2/... //client/cli/...\n" &&
 217        files="cli/file11 cli/file12 cli/file21 cli/file22" &&
 218        client_verify $files &&
 219        test_when_finished cleanup_git &&
 220        git p4 clone --use-client-spec --dest="$git" //depot &&
 221        git_verify $files
 222'
 223
 224test_expect_success 'overlay single file' '
 225        client_view "//depot/dir1/... //client/cli/..." \
 226                    "+//depot/dir2/file21 //client/cli/file21" &&
 227        files="cli/file11 cli/file12 cli/file21" &&
 228        client_verify $files &&
 229        test_when_finished cleanup_git &&
 230        git p4 clone --use-client-spec --dest="$git" //depot &&
 231        git_verify $files
 232'
 233
 234test_expect_success 'exclusion with later inclusion' '
 235        client_view "//depot/... //client/..." \
 236                    "-//depot/dir2/... //client/dir2/..." \
 237                    "//depot/dir2/... //client/dir2incl/..." &&
 238        files="dir1/file11 dir1/file12 dir2incl/file21 dir2incl/file22" &&
 239        client_verify $files &&
 240        test_when_finished cleanup_git &&
 241        git p4 clone --use-client-spec --dest="$git" //depot &&
 242        git_verify $files
 243'
 244
 245test_expect_success 'quotes on rhs only' '
 246        client_view "//depot/dir1/... \"//client/cdir 1/...\"" &&
 247        client_verify "cdir 1/file11" "cdir 1/file12" &&
 248        test_when_finished cleanup_git &&
 249        git p4 clone --use-client-spec --dest="$git" //depot &&
 250        git_verify "cdir 1/file11" "cdir 1/file12"
 251'
 252
 253#
 254# Submit tests
 255#
 256
 257# clone sets variable
 258test_expect_success 'clone --use-client-spec sets useClientSpec' '
 259        client_view "//depot/... //client/..." &&
 260        test_when_finished cleanup_git &&
 261        git p4 clone --use-client-spec --dest="$git" //depot &&
 262        (
 263                cd "$git" &&
 264                git config --bool git-p4.useClientSpec >actual &&
 265                echo true >true &&
 266                test_cmp actual true
 267        )
 268'
 269
 270# clone just a subdir of the client spec
 271test_expect_success 'subdir clone' '
 272        client_view "//depot/... //client/..." &&
 273        files="dir1/file11 dir1/file12 dir2/file21 dir2/file22" &&
 274        client_verify $files &&
 275        test_when_finished cleanup_git &&
 276        git p4 clone --use-client-spec --dest="$git" //depot/dir1 &&
 277        git_verify dir1/file11 dir1/file12
 278'
 279
 280#
 281# submit back, see what happens:  five cases
 282#
 283test_expect_success 'subdir clone, submit modify' '
 284        client_view "//depot/... //client/..." &&
 285        test_when_finished cleanup_git &&
 286        git p4 clone --use-client-spec --dest="$git" //depot/dir1 &&
 287        (
 288                cd "$git" &&
 289                git config git-p4.skipSubmitEdit true &&
 290                echo line >>dir1/file12 &&
 291                git add dir1/file12 &&
 292                git commit -m dir1/file12 &&
 293                git p4 submit
 294        ) &&
 295        (
 296                cd "$cli" &&
 297                test_path_is_file dir1/file12 &&
 298                test_line_count = 2 dir1/file12
 299        )
 300'
 301
 302test_expect_success 'subdir clone, submit add' '
 303        client_view "//depot/... //client/..." &&
 304        test_when_finished cleanup_git &&
 305        git p4 clone --use-client-spec --dest="$git" //depot/dir1 &&
 306        (
 307                cd "$git" &&
 308                git config git-p4.skipSubmitEdit true &&
 309                echo file13 >dir1/file13 &&
 310                git add dir1/file13 &&
 311                git commit -m dir1/file13 &&
 312                git p4 submit
 313        ) &&
 314        (
 315                cd "$cli" &&
 316                test_path_is_file dir1/file13
 317        )
 318'
 319
 320test_expect_success 'subdir clone, submit delete' '
 321        client_view "//depot/... //client/..." &&
 322        test_when_finished cleanup_git &&
 323        git p4 clone --use-client-spec --dest="$git" //depot/dir1 &&
 324        (
 325                cd "$git" &&
 326                git config git-p4.skipSubmitEdit true &&
 327                git rm dir1/file12 &&
 328                git commit -m "delete dir1/file12" &&
 329                git p4 submit
 330        ) &&
 331        (
 332                cd "$cli" &&
 333                test_path_is_missing dir1/file12
 334        )
 335'
 336
 337test_expect_success 'subdir clone, submit copy' '
 338        client_view "//depot/... //client/..." &&
 339        test_when_finished cleanup_git &&
 340        git p4 clone --use-client-spec --dest="$git" //depot/dir1 &&
 341        (
 342                cd "$git" &&
 343                git config git-p4.skipSubmitEdit true &&
 344                git config git-p4.detectCopies true &&
 345                cp dir1/file11 dir1/file11a &&
 346                git add dir1/file11a &&
 347                git commit -m "copy to dir1/file11a" &&
 348                git p4 submit
 349        ) &&
 350        (
 351                cd "$cli" &&
 352                test_path_is_file dir1/file11a &&
 353                test ! -w dir1/file11a
 354        )
 355'
 356
 357test_expect_success 'subdir clone, submit rename' '
 358        client_view "//depot/... //client/..." &&
 359        test_when_finished cleanup_git &&
 360        git p4 clone --use-client-spec --dest="$git" //depot/dir1 &&
 361        (
 362                cd "$git" &&
 363                git config git-p4.skipSubmitEdit true &&
 364                git config git-p4.detectRenames true &&
 365                git mv dir1/file13 dir1/file13a &&
 366                git commit -m "rename dir1/file13 to dir1/file13a" &&
 367                git p4 submit
 368        ) &&
 369        (
 370                cd "$cli" &&
 371                test_path_is_missing dir1/file13 &&
 372                test_path_is_file dir1/file13a &&
 373                test ! -w dir1/file13a
 374        )
 375'
 376
 377# see t9800 for the non-client-spec case, and the rest of the wildcard tests
 378test_expect_success 'wildcard files submit back to p4, client-spec case' '
 379        client_view "//depot/... //client/..." &&
 380        test_when_finished cleanup_git &&
 381        git p4 clone --use-client-spec --dest="$git" //depot/dir1 &&
 382        (
 383                cd "$git" &&
 384                echo git-wild-hash >dir1/git-wild#hash &&
 385                echo git-wild-star >dir1/git-wild\*star &&
 386                echo git-wild-at >dir1/git-wild@at &&
 387                echo git-wild-percent >dir1/git-wild%percent &&
 388                git add dir1/git-wild* &&
 389                git commit -m "add some wildcard filenames" &&
 390                git config git-p4.skipSubmitEditCheck true &&
 391                git p4 submit
 392        ) &&
 393        (
 394                cd "$cli" &&
 395                test_path_is_file dir1/git-wild#hash &&
 396                test_path_is_file dir1/git-wild\*star &&
 397                test_path_is_file dir1/git-wild@at &&
 398                test_path_is_file dir1/git-wild%percent
 399        ) &&
 400        (
 401                # delete these carefully, cannot just do "p4 delete"
 402                # on files with wildcards; but git-p4 knows how
 403                cd "$git" &&
 404                git rm dir1/git-wild* &&
 405                git commit -m "clean up the wildcards" &&
 406                git p4 submit
 407        )
 408'
 409
 410test_expect_success 'reinit depot' '
 411        (
 412                cd "$cli" &&
 413                rm files &&
 414                p4 delete */* &&
 415                p4 submit -d "delete all files" &&
 416                init_depot
 417        )
 418'
 419
 420#
 421# What happens when two files of the same name are overlayed together?
 422# The last-listed file should take preference.
 423#
 424# //depot
 425#   - dir1
 426#     - file11
 427#     - file12
 428#     - filecollide
 429#   - dir2
 430#     - file21
 431#     - file22
 432#     - filecollide
 433#
 434test_expect_success 'overlay collision setup' '
 435        client_view "//depot/... //client/..." &&
 436        (
 437                cd "$cli" &&
 438                p4 sync &&
 439                echo dir1/filecollide >dir1/filecollide &&
 440                p4 add dir1/filecollide &&
 441                p4 submit -d dir1/filecollide &&
 442                echo dir2/filecollide >dir2/filecollide &&
 443                p4 add dir2/filecollide &&
 444                p4 submit -d dir2/filecollide
 445        )
 446'
 447
 448test_expect_success 'overlay collision 1 to 2' '
 449        client_view "//depot/dir1/... //client/..." \
 450                    "+//depot/dir2/... //client/..." &&
 451        files="file11 file12 file21 file22 filecollide" &&
 452        echo dir2/filecollide >actual &&
 453        client_verify $files &&
 454        test_cmp actual "$cli"/filecollide &&
 455        test_when_finished cleanup_git &&
 456        git p4 clone --use-client-spec --dest="$git" //depot &&
 457        git_verify $files &&
 458        test_cmp actual "$git"/filecollide
 459'
 460
 461test_expect_failure 'overlay collision 2 to 1' '
 462        client_view "//depot/dir2/... //client/..." \
 463                    "+//depot/dir1/... //client/..." &&
 464        files="file11 file12 file21 file22 filecollide" &&
 465        echo dir1/filecollide >actual &&
 466        client_verify $files &&
 467        test_cmp actual "$cli"/filecollide &&
 468        test_when_finished cleanup_git &&
 469        git p4 clone --use-client-spec --dest="$git" //depot &&
 470        git_verify $files &&
 471        test_cmp actual "$git"/filecollide
 472'
 473
 474test_expect_success 'overlay collision delete 2' '
 475        client_view "//depot/... //client/..." &&
 476        (
 477                cd "$cli" &&
 478                p4 sync &&
 479                p4 delete dir2/filecollide &&
 480                p4 submit -d "remove dir2/filecollide"
 481        )
 482'
 483
 484# no filecollide, got deleted with dir2
 485test_expect_failure 'overlay collision 1 to 2, but 2 deleted' '
 486        client_view "//depot/dir1/... //client/..." \
 487                    "+//depot/dir2/... //client/..." &&
 488        files="file11 file12 file21 file22" &&
 489        client_verify $files &&
 490        test_when_finished cleanup_git &&
 491        git p4 clone --use-client-spec --dest="$git" //depot &&
 492        git_verify $files
 493'
 494
 495test_expect_success 'overlay collision update 1' '
 496        client_view "//depot/dir1/... //client/dir1/..." &&
 497        (
 498                cd "$cli" &&
 499                p4 sync &&
 500                p4 open dir1/filecollide &&
 501                echo dir1/filecollide update >dir1/filecollide &&
 502                p4 submit -d "update dir1/filecollide"
 503        )
 504'
 505
 506# still no filecollide, dir2 still wins with the deletion even though the
 507# change to dir1 is more recent
 508test_expect_failure 'overlay collision 1 to 2, but 2 deleted, then 1 updated' '
 509        client_view "//depot/dir1/... //client/..." \
 510                    "+//depot/dir2/... //client/..." &&
 511        files="file11 file12 file21 file22" &&
 512        client_verify $files &&
 513        test_when_finished cleanup_git &&
 514        git p4 clone --use-client-spec --dest="$git" //depot &&
 515        git_verify $files
 516'
 517
 518test_expect_success 'overlay collision delete filecollides' '
 519        client_view "//depot/... //client/..." &&
 520        (
 521                cd "$cli" &&
 522                p4 sync &&
 523                p4 delete dir1/filecollide dir2/filecollide &&
 524                p4 submit -d "remove filecollides"
 525        )
 526'
 527
 528#
 529# Overlays as part of sync, rather than initial checkout:
 530#   1.  add a file in dir1
 531#   2.  sync to include it
 532#   3.  add same file in dir2
 533#   4.  sync, make sure content switches as dir2 has priority
 534#   5.  add another file in dir1
 535#   6.  sync
 536#   7.  add/delete same file in dir2
 537#   8.  sync, make sure it disappears, again dir2 wins
 538#   9.  cleanup
 539#
 540# //depot
 541#   - dir1
 542#     - file11
 543#     - file12
 544#     - colA
 545#     - colB
 546#   - dir2
 547#     - file21
 548#     - file22
 549#     - colA
 550#     - colB
 551#
 552test_expect_success 'overlay sync: add colA in dir1' '
 553        client_view "//depot/dir1/... //client/dir1/..." &&
 554        (
 555                cd "$cli" &&
 556                p4 sync &&
 557                echo dir1/colA >dir1/colA &&
 558                p4 add dir1/colA &&
 559                p4 submit -d dir1/colA
 560        )
 561'
 562
 563test_expect_success 'overlay sync: initial git checkout' '
 564        client_view "//depot/dir1/... //client/..." \
 565                    "+//depot/dir2/... //client/..." &&
 566        files="file11 file12 file21 file22 colA" &&
 567        echo dir1/colA >actual &&
 568        client_verify $files &&
 569        test_cmp actual "$cli"/colA &&
 570        git p4 clone --use-client-spec --dest="$git" //depot &&
 571        git_verify $files &&
 572        test_cmp actual "$git"/colA
 573'
 574
 575test_expect_success 'overlay sync: add colA in dir2' '
 576        client_view "//depot/dir2/... //client/dir2/..." &&
 577        (
 578                cd "$cli" &&
 579                p4 sync &&
 580                echo dir2/colA >dir2/colA &&
 581                p4 add dir2/colA &&
 582                p4 submit -d dir2/colA
 583        )
 584'
 585
 586test_expect_success 'overlay sync: colA content switch' '
 587        client_view "//depot/dir1/... //client/..." \
 588                    "+//depot/dir2/... //client/..." &&
 589        files="file11 file12 file21 file22 colA" &&
 590        echo dir2/colA >actual &&
 591        client_verify $files &&
 592        test_cmp actual "$cli"/colA &&
 593        (
 594                cd "$git" &&
 595                git p4 sync --use-client-spec &&
 596                git merge --ff-only p4/master
 597        ) &&
 598        git_verify $files &&
 599        test_cmp actual "$git"/colA
 600'
 601
 602test_expect_success 'overlay sync: add colB in dir1' '
 603        client_view "//depot/dir1/... //client/dir1/..." &&
 604        (
 605                cd "$cli" &&
 606                p4 sync &&
 607                echo dir1/colB >dir1/colB &&
 608                p4 add dir1/colB &&
 609                p4 submit -d dir1/colB
 610        )
 611'
 612
 613test_expect_success 'overlay sync: colB appears' '
 614        client_view "//depot/dir1/... //client/..." \
 615                    "+//depot/dir2/... //client/..." &&
 616        files="file11 file12 file21 file22 colA colB" &&
 617        echo dir1/colB >actual &&
 618        client_verify $files &&
 619        test_cmp actual "$cli"/colB &&
 620        (
 621                cd "$git" &&
 622                git p4 sync --use-client-spec &&
 623                git merge --ff-only p4/master
 624        ) &&
 625        git_verify $files &&
 626        test_cmp actual "$git"/colB
 627'
 628
 629test_expect_success 'overlay sync: add/delete colB in dir2' '
 630        client_view "//depot/dir2/... //client/dir2/..." &&
 631        (
 632                cd "$cli" &&
 633                p4 sync &&
 634                echo dir2/colB >dir2/colB &&
 635                p4 add dir2/colB &&
 636                p4 submit -d dir2/colB &&
 637                p4 delete dir2/colB &&
 638                p4 submit -d "delete dir2/colB"
 639        )
 640'
 641
 642test_expect_success 'overlay sync: colB disappears' '
 643        client_view "//depot/dir1/... //client/..." \
 644                    "+//depot/dir2/... //client/..." &&
 645        files="file11 file12 file21 file22 colA" &&
 646        client_verify $files &&
 647        test_when_finished cleanup_git &&
 648        (
 649                cd "$git" &&
 650                git p4 sync --use-client-spec &&
 651                git merge --ff-only p4/master
 652        ) &&
 653        git_verify $files
 654'
 655
 656test_expect_success 'overlay sync: cleanup' '
 657        client_view "//depot/... //client/..." &&
 658        (
 659                cd "$cli" &&
 660                p4 sync &&
 661                p4 delete dir1/colA dir2/colA dir1/colB &&
 662                p4 submit -d "remove overlay sync files"
 663        )
 664'
 665
 666#
 667# Overlay tests again, but swapped so dir1 has priority.
 668#   1.  add a file in dir1
 669#   2.  sync to include it
 670#   3.  add same file in dir2
 671#   4.  sync, make sure content does not switch
 672#   5.  add another file in dir1
 673#   6.  sync
 674#   7.  add/delete same file in dir2
 675#   8.  sync, make sure it is still there
 676#   9.  cleanup
 677#
 678# //depot
 679#   - dir1
 680#     - file11
 681#     - file12
 682#     - colA
 683#     - colB
 684#   - dir2
 685#     - file21
 686#     - file22
 687#     - colA
 688#     - colB
 689#
 690test_expect_success 'overlay sync swap: add colA in dir1' '
 691        client_view "//depot/dir1/... //client/dir1/..." &&
 692        (
 693                cd "$cli" &&
 694                p4 sync &&
 695                echo dir1/colA >dir1/colA &&
 696                p4 add dir1/colA &&
 697                p4 submit -d dir1/colA
 698        )
 699'
 700
 701test_expect_success 'overlay sync swap: initial git checkout' '
 702        client_view "//depot/dir2/... //client/..." \
 703                    "+//depot/dir1/... //client/..." &&
 704        files="file11 file12 file21 file22 colA" &&
 705        echo dir1/colA >actual &&
 706        client_verify $files &&
 707        test_cmp actual "$cli"/colA &&
 708        git p4 clone --use-client-spec --dest="$git" //depot &&
 709        git_verify $files &&
 710        test_cmp actual "$git"/colA
 711'
 712
 713test_expect_success 'overlay sync swap: add colA in dir2' '
 714        client_view "//depot/dir2/... //client/dir2/..." &&
 715        (
 716                cd "$cli" &&
 717                p4 sync &&
 718                echo dir2/colA >dir2/colA &&
 719                p4 add dir2/colA &&
 720                p4 submit -d dir2/colA
 721        )
 722'
 723
 724test_expect_failure 'overlay sync swap: colA no content switch' '
 725        client_view "//depot/dir2/... //client/..." \
 726                    "+//depot/dir1/... //client/..." &&
 727        files="file11 file12 file21 file22 colA" &&
 728        echo dir1/colA >actual &&
 729        client_verify $files &&
 730        test_cmp actual "$cli"/colA &&
 731        (
 732                cd "$git" &&
 733                git p4 sync --use-client-spec &&
 734                git merge --ff-only p4/master
 735        ) &&
 736        git_verify $files &&
 737        test_cmp actual "$git"/colA
 738'
 739
 740test_expect_success 'overlay sync swap: add colB in dir1' '
 741        client_view "//depot/dir1/... //client/dir1/..." &&
 742        (
 743                cd "$cli" &&
 744                p4 sync &&
 745                echo dir1/colB >dir1/colB &&
 746                p4 add dir1/colB &&
 747                p4 submit -d dir1/colB
 748        )
 749'
 750
 751test_expect_success 'overlay sync swap: colB appears' '
 752        client_view "//depot/dir2/... //client/..." \
 753                    "+//depot/dir1/... //client/..." &&
 754        files="file11 file12 file21 file22 colA colB" &&
 755        echo dir1/colB >actual &&
 756        client_verify $files &&
 757        test_cmp actual "$cli"/colB &&
 758        (
 759                cd "$git" &&
 760                git p4 sync --use-client-spec &&
 761                git merge --ff-only p4/master
 762        ) &&
 763        git_verify $files &&
 764        test_cmp actual "$git"/colB
 765'
 766
 767test_expect_success 'overlay sync swap: add/delete colB in dir2' '
 768        client_view "//depot/dir2/... //client/dir2/..." &&
 769        (
 770                cd "$cli" &&
 771                p4 sync &&
 772                echo dir2/colB >dir2/colB &&
 773                p4 add dir2/colB &&
 774                p4 submit -d dir2/colB &&
 775                p4 delete dir2/colB &&
 776                p4 submit -d "delete dir2/colB"
 777        )
 778'
 779
 780test_expect_failure 'overlay sync swap: colB no change' '
 781        client_view "//depot/dir2/... //client/..." \
 782                    "+//depot/dir1/... //client/..." &&
 783        files="file11 file12 file21 file22 colA colB" &&
 784        echo dir1/colB >actual &&
 785        client_verify $files &&
 786        test_cmp actual "$cli"/colB &&
 787        test_when_finished cleanup_git &&
 788        (
 789                cd "$git" &&
 790                git p4 sync --use-client-spec &&
 791                git merge --ff-only p4/master
 792        ) &&
 793        git_verify $files &&
 794        test_cmp actual "$cli"/colB
 795'
 796
 797test_expect_success 'overlay sync swap: cleanup' '
 798        client_view "//depot/... //client/..." &&
 799        (
 800                cd "$cli" &&
 801                p4 sync &&
 802                p4 delete dir1/colA dir2/colA dir1/colB &&
 803                p4 submit -d "remove overlay sync files"
 804        )
 805'
 806
 807#
 808# Rename directories to test quoting in depot-side mappings
 809# //depot
 810#    - "dir 1"
 811#       - file11
 812#       - file12
 813#    - "dir 2"
 814#       - file21
 815#       - file22
 816#
 817test_expect_success 'rename files to introduce spaces' '
 818        client_view "//depot/... //client/..." &&
 819        client_verify dir1/file11 dir1/file12 \
 820                      dir2/file21 dir2/file22 &&
 821        (
 822                cd "$cli" &&
 823                p4 open dir1/... &&
 824                p4 move dir1/... "dir 1"/... &&
 825                p4 open dir2/... &&
 826                p4 move dir2/... "dir 2"/... &&
 827                p4 submit -d "rename with spaces"
 828        ) &&
 829        client_verify "dir 1/file11" "dir 1/file12" \
 830                      "dir 2/file21" "dir 2/file22"
 831'
 832
 833test_expect_success 'quotes on lhs only' '
 834        client_view "\"//depot/dir 1/...\" //client/cdir1/..." &&
 835        files="cdir1/file11 cdir1/file12" &&
 836        client_verify $files &&
 837        test_when_finished cleanup_git &&
 838        git p4 clone --use-client-spec --dest="$git" //depot &&
 839        client_verify $files
 840'
 841
 842test_expect_success 'quotes on both sides' '
 843        client_view "\"//depot/dir 1/...\" \"//client/cdir 1/...\"" &&
 844        client_verify "cdir 1/file11" "cdir 1/file12" &&
 845        test_when_finished cleanup_git &&
 846        git p4 clone --use-client-spec --dest="$git" //depot &&
 847        git_verify "cdir 1/file11" "cdir 1/file12"
 848'
 849
 850test_expect_success 'kill p4d' '
 851        kill_p4d
 852'
 853
 854test_done