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