e9c451cc585dca951e55c51ab25634ad5acd55d4
   1#!/bin/sh
   2
   3test_description='Tests of cwd/prefix/worktree/gitdir setup in all cases'
   4
   5. ./test-lib.sh
   6
   7#
   8# A few rules for repo setup:
   9#
  10# 1. GIT_DIR is relative to user's cwd. --git-dir is equivalent to
  11#    GIT_DIR.
  12#
  13# 2. .git file is relative to parent directory. .git file is basically
  14#    symlink in disguise. The directory where .git file points to will
  15#    become new git_dir.
  16#
  17# 3. core.worktree is relative to git_dir.
  18#
  19# 4. GIT_WORK_TREE is relative to user's cwd. --work-tree is
  20#    equivalent to GIT_WORK_TREE.
  21#
  22# 5. GIT_WORK_TREE/core.worktree is only effective if GIT_DIR is set
  23#    Uneffective worktree settings should be warned.
  24#
  25# 6. Effective GIT_WORK_TREE overrides core.worktree and core.bare
  26#
  27# 7. Effective core.worktree conflicts with core.bare
  28#
  29# 8. If GIT_DIR is set but neither worktree nor bare setting is given,
  30#    original cwd becomes worktree.
  31#
  32# 9. If .git discovery is done inside a repo, the repo becomes a bare
  33#    repo. .git discovery is performed if GIT_DIR is not set.
  34#
  35# 10. If no worktree is available, cwd remains unchanged, prefix is
  36#     NULL.
  37#
  38# 11. When user's cwd is outside worktree, cwd remains unchanged,
  39#     prefix is NULL.
  40#
  41
  42test_repo() {
  43        (
  44        cd "$1" &&
  45        if test -n "$2"; then GIT_DIR="$2" && export GIT_DIR; fi &&
  46        if test -n "$3"; then GIT_WORK_TREE="$3" && export GIT_WORK_TREE; fi &&
  47        rm -f trace &&
  48        GIT_TRACE="`pwd`/trace" git symbolic-ref HEAD >/dev/null &&
  49        grep '^setup: ' trace >result &&
  50        test_cmp expected result
  51        )
  52}
  53
  54# Bit 0 = GIT_WORK_TREE
  55# Bit 1 = GIT_DIR
  56# Bit 2 = core.worktree
  57# Bit 3 = .git is a file
  58# Bit 4 = bare repo
  59# Case# = encoding of the above 5 bits
  60
  61#
  62# Case #0
  63#
  64############################################################
  65#
  66# Input:
  67#
  68#  - GIT_WORK_TREE is not set
  69#  - GIT_DIR is not set
  70#  - core.worktree is not set
  71#  - .git is a directory
  72#  - core.bare is not set, cwd is outside .git
  73#
  74# Output:
  75#
  76#  - worktree is .git's parent directory
  77#  - cwd is at worktree root dir
  78#  - prefix is calculated
  79#  - git_dir is set to ".git"
  80#  - cwd can't be outside worktree
  81
  82test_expect_success '#0: setup' '
  83        sane_unset GIT_DIR GIT_WORK_TREE &&
  84        mkdir 0 0/sub &&
  85        (cd 0 && git init) &&
  86        here=$(pwd)
  87'
  88
  89test_expect_success '#0: at root' '
  90        cat >0/expected <<EOF &&
  91setup: git_dir: .git
  92setup: worktree: $here/0
  93setup: cwd: $here/0
  94setup: prefix: (null)
  95EOF
  96        test_repo 0
  97'
  98
  99test_expect_success '#0: in subdir' '
 100        cat >0/sub/expected <<EOF &&
 101setup: git_dir: .git
 102setup: worktree: $here/0
 103setup: cwd: $here/0
 104setup: prefix: sub/
 105EOF
 106        test_repo 0/sub
 107'
 108
 109#
 110# case #1
 111#
 112############################################################
 113#
 114# Input:
 115#
 116#  - GIT_WORK_TREE is set
 117#  - GIT_DIR is not set
 118#  - core.worktree is not set
 119#  - .git is a directory
 120#  - core.bare is not set, cwd is outside .git
 121#
 122# Output:
 123#
 124# GIT_WORK_TREE is ignored -> #0
 125
 126test_expect_success '#1: setup' '
 127        sane_unset GIT_DIR GIT_WORK_TREE &&
 128        mkdir 1 1/sub 1.wt 1.wt/sub 1/wt 1/wt/sub &&
 129        cd 1 &&
 130        git init &&
 131        GIT_WORK_TREE=non-existent &&
 132        export GIT_WORK_TREE &&
 133        cd ..
 134'
 135
 136test_expect_success '#1: at root' '
 137        cat >1/expected <<EOF &&
 138setup: git_dir: .git
 139setup: worktree: $here/1
 140setup: cwd: $here/1
 141setup: prefix: (null)
 142EOF
 143        test_repo 1
 144'
 145
 146test_expect_success '#1: in subdir' '
 147        cat >1/sub/expected <<EOF &&
 148setup: git_dir: .git
 149setup: worktree: $here/1
 150setup: cwd: $here/1
 151setup: prefix: sub/
 152EOF
 153        test_repo 1/sub
 154'
 155
 156#
 157# case #2
 158#
 159############################################################
 160#
 161# Input:
 162#
 163#  - GIT_WORK_TREE is not set
 164#  - GIT_DIR is set
 165#  - core.worktree is not set
 166#  - .git is a directory
 167#  - core.bare is not set, cwd is outside .git
 168#
 169# Output:
 170#
 171#  - worktree is at original cwd
 172#  - cwd is unchanged
 173#  - prefix is NULL
 174#  - git_dir is set to $GIT_DIR
 175#  - cwd can't be outside worktree
 176
 177test_expect_success '#2: setup' '
 178        sane_unset GIT_DIR GIT_WORK_TREE &&
 179        mkdir 2 2/sub &&
 180        cd 2 && git init && cd ..
 181'
 182
 183test_expect_success '#2: at root' '
 184        cat >2/expected <<EOF &&
 185setup: git_dir: $here/2/.git
 186setup: worktree: $here/2
 187setup: cwd: $here/2
 188setup: prefix: (null)
 189EOF
 190        test_repo 2 "$here/2/.git"
 191'
 192
 193test_expect_success '#2: in subdir' '
 194        cat >2/sub/expected <<EOF &&
 195setup: git_dir: $here/2/.git
 196setup: worktree: $here/2/sub
 197setup: cwd: $here/2/sub
 198setup: prefix: (null)
 199EOF
 200        test_repo 2/sub "$here/2/.git"
 201'
 202
 203test_expect_success '#2: relative GIT_DIR at root' '
 204        cat >2/expected <<EOF &&
 205setup: git_dir: .git
 206setup: worktree: $here/2
 207setup: cwd: $here/2
 208setup: prefix: (null)
 209EOF
 210        test_repo 2 .git
 211'
 212
 213test_expect_success '#2: relative GIT_DIR in subdir' '
 214        cat >2/sub/expected <<EOF &&
 215setup: git_dir: ../.git
 216setup: worktree: $here/2/sub
 217setup: cwd: $here/2/sub
 218setup: prefix: (null)
 219EOF
 220        test_repo 2/sub ../.git
 221'
 222
 223#
 224# case #3
 225#
 226############################################################
 227#
 228# Input:
 229#
 230#  - GIT_WORK_TREE is set
 231#  - GIT_DIR is set
 232#  - core.worktree is not set
 233#  - .git is a directory
 234#  - core.bare is not set, cwd is outside .git
 235#
 236# Output:
 237#
 238#  - worktree is set to $GIT_WORK_TREE
 239#  - cwd is at worktree root
 240#  - prefix is calculated
 241#  - git_dir is set to $GIT_DIR
 242#  - cwd can be outside worktree
 243
 244test_expect_success '#3: setup' '
 245        sane_unset GIT_DIR GIT_WORK_TREE &&
 246        mkdir 3 3/sub 3/sub/sub 3.wt 3.wt/sub 3/wt 3/wt/sub &&
 247        cd 3 && git init && cd ..
 248'
 249
 250test_expect_success '#3: GIT_DIR(rel), GIT_WORK_TREE=root at root' '
 251        cat >3/expected <<EOF &&
 252setup: git_dir: .git
 253setup: worktree: $here/3
 254setup: cwd: $here/3
 255setup: prefix: (null)
 256EOF
 257        test_repo 3 .git "$here/3"
 258'
 259
 260test_expect_success '#3: GIT_DIR(rel), GIT_WORK_TREE=root(rel) at root' '
 261        cat >3/expected <<EOF &&
 262setup: git_dir: .git
 263setup: worktree: $here/3
 264setup: cwd: $here/3
 265setup: prefix: (null)
 266EOF
 267        test_repo 3 .git .
 268'
 269
 270test_expect_success '#3: GIT_DIR, GIT_WORK_TREE=root at root' '
 271        cat >3/expected <<EOF &&
 272setup: git_dir: $here/3/.git
 273setup: worktree: $here/3
 274setup: cwd: $here/3
 275setup: prefix: (null)
 276EOF
 277        test_repo 3 "$here/3/.git" "$here/3"
 278'
 279
 280test_expect_success '#3: GIT_DIR, GIT_WORK_TREE=root(rel) at root' '
 281        cat >3/expected <<EOF &&
 282setup: git_dir: $here/3/.git
 283setup: worktree: $here/3
 284setup: cwd: $here/3
 285setup: prefix: (null)
 286EOF
 287        test_repo 3 "$here/3/.git" .
 288'
 289
 290test_expect_success '#3: GIT_DIR(rel), GIT_WORKTREE=root in subdir' '
 291        cat >3/sub/sub/expected <<EOF &&
 292setup: git_dir: $here/3/.git
 293setup: worktree: $here/3
 294setup: cwd: $here/3
 295setup: prefix: sub/sub/
 296EOF
 297        test_repo 3/sub/sub ../../.git "$here/3"
 298'
 299
 300test_expect_success '#3: GIT_DIR(rel), GIT_WORKTREE=root(rel) in subdir' '
 301        cat >3/sub/sub/expected <<EOF &&
 302setup: git_dir: $here/3/.git
 303setup: worktree: $here/3
 304setup: cwd: $here/3
 305setup: prefix: sub/sub/
 306EOF
 307        test_repo 3/sub/sub ../../.git ../..
 308'
 309
 310test_expect_success '#3: GIT_DIR, GIT_WORKTREE=root in subdir' '
 311        cat >3/sub/expected <<EOF &&
 312setup: git_dir: $here/3/.git
 313setup: worktree: $here/3
 314setup: cwd: $here/3
 315setup: prefix: sub/
 316EOF
 317        test_repo 3/sub "$here/3/.git" "$here/3"
 318'
 319
 320test_expect_success '#3: GIT_DIR, GIT_WORKTREE=root(rel) in subdir' '
 321        cat >3/sub/sub/expected <<EOF &&
 322setup: git_dir: $here/3/.git
 323setup: worktree: $here/3
 324setup: cwd: $here/3
 325setup: prefix: sub/sub/
 326EOF
 327        test_repo 3/sub/sub "$here/3/.git" ../..
 328'
 329
 330test_expect_success '#3: GIT_DIR(rel), GIT_WORK_TREE=wt at root' '
 331        cat >3/expected <<EOF &&
 332setup: git_dir: .git
 333setup: worktree: $here/3/wt
 334setup: cwd: $here/3
 335setup: prefix: (null)
 336EOF
 337        test_repo 3 .git "$here/3/wt"
 338'
 339
 340test_expect_success '#3: GIT_DIR(rel), GIT_WORK_TREE=wt(rel) at root' '
 341        cat >3/expected <<EOF &&
 342setup: git_dir: .git
 343setup: worktree: $here/3/wt
 344setup: cwd: $here/3
 345setup: prefix: (null)
 346EOF
 347        test_repo 3 .git wt
 348'
 349
 350test_expect_success '#3: GIT_DIR, GIT_WORK_TREE=wt(rel) at root' '
 351        cat >3/expected <<EOF &&
 352setup: git_dir: $here/3/.git
 353setup: worktree: $here/3/wt
 354setup: cwd: $here/3
 355setup: prefix: (null)
 356EOF
 357        test_repo 3 "$here/3/.git" wt
 358'
 359
 360test_expect_success '#3: GIT_DIR, GIT_WORK_TREE=wt at root' '
 361        cat >3/expected <<EOF &&
 362setup: git_dir: $here/3/.git
 363setup: worktree: $here/3/wt
 364setup: cwd: $here/3
 365setup: prefix: (null)
 366EOF
 367        test_repo 3 "$here/3/.git" "$here/3/wt"
 368'
 369
 370test_expect_success '#3: GIT_DIR(rel), GIT_WORK_TREE=wt in subdir' '
 371        cat >3/sub/sub/expected <<EOF &&
 372setup: git_dir: ../../.git
 373setup: worktree: $here/3/wt
 374setup: cwd: $here/3/sub/sub
 375setup: prefix: (null)
 376EOF
 377        test_repo 3/sub/sub ../../.git "$here/3/wt"
 378'
 379
 380test_expect_success '#3: GIT_DIR(rel), GIT_WORK_TREE=wt(rel) in subdir' '
 381        cat >3/sub/sub/expected <<EOF &&
 382setup: git_dir: ../../.git
 383setup: worktree: $here/3/wt
 384setup: cwd: $here/3/sub/sub
 385setup: prefix: (null)
 386EOF
 387        test_repo 3/sub/sub ../../.git ../../wt
 388'
 389
 390test_expect_success '#3: GIT_DIR, GIT_WORK_TREE=wt(rel) in subdir' '
 391        cat >3/sub/sub/expected <<EOF &&
 392setup: git_dir: $here/3/.git
 393setup: worktree: $here/3/wt
 394setup: cwd: $here/3/sub/sub
 395setup: prefix: (null)
 396EOF
 397        test_repo 3/sub/sub "$here/3/.git" ../../wt
 398'
 399
 400test_expect_success '#3: GIT_DIR, GIT_WORK_TREE=wt in subdir' '
 401        cat >3/sub/sub/expected <<EOF &&
 402setup: git_dir: $here/3/.git
 403setup: worktree: $here/3/wt
 404setup: cwd: $here/3/sub/sub
 405setup: prefix: (null)
 406EOF
 407        test_repo 3/sub/sub "$here/3/.git" "$here/3/wt"
 408'
 409
 410test_expect_success '#3: GIT_DIR(rel), GIT_WORK_TREE=.. at root' '
 411        cat >3/expected <<EOF &&
 412setup: git_dir: $here/3/.git
 413setup: worktree: $here
 414setup: cwd: $here
 415setup: prefix: 3/
 416EOF
 417        test_repo 3 .git "$here"
 418'
 419
 420test_expect_success '#3: GIT_DIR(rel), GIT_WORK_TREE=..(rel) at root' '
 421        cat >3/expected <<EOF &&
 422setup: git_dir: $here/3/.git
 423setup: worktree: $here
 424setup: cwd: $here
 425setup: prefix: 3/
 426EOF
 427        test_repo 3 .git ..
 428'
 429
 430test_expect_success '#3: GIT_DIR, GIT_WORK_TREE=..(rel) at root' '
 431        cat >3/expected <<EOF &&
 432setup: git_dir: $here/3/.git
 433setup: worktree: $here
 434setup: cwd: $here
 435setup: prefix: 3/
 436EOF
 437        test_repo 3 "$here/3/.git" ..
 438'
 439
 440test_expect_success '#3: GIT_DIR, GIT_WORK_TREE=.. at root' '
 441        cat >3/expected <<EOF &&
 442setup: git_dir: $here/3/.git
 443setup: worktree: $here
 444setup: cwd: $here
 445setup: prefix: 3/
 446EOF
 447        test_repo 3 "$here/3/.git" "$here"
 448'
 449
 450test_expect_success '#3: GIT_DIR(rel), GIT_WORK_TREE=.. in subdir' '
 451        cat >3/sub/sub/expected <<EOF &&
 452setup: git_dir: $here/3/.git
 453setup: worktree: $here
 454setup: cwd: $here
 455setup: prefix: 3/sub/sub/
 456EOF
 457        test_repo 3/sub/sub ../../.git "$here"
 458'
 459
 460test_expect_success '#3: GIT_DIR(rel), GIT_WORK_TREE=..(rel) in subdir' '
 461        cat >3/sub/sub/expected <<EOF &&
 462setup: git_dir: $here/3/.git
 463setup: worktree: $here
 464setup: cwd: $here
 465setup: prefix: 3/sub/sub/
 466EOF
 467        test_repo 3/sub/sub ../../.git ../../..
 468'
 469
 470test_expect_success '#3: GIT_DIR, GIT_WORK_TREE=..(rel) in subdir' '
 471        cat >3/sub/sub/expected <<EOF &&
 472setup: git_dir: $here/3/.git
 473setup: worktree: $here
 474setup: cwd: $here
 475setup: prefix: 3/sub/sub/
 476EOF
 477        test_repo 3/sub/sub "$here/3/.git" ../../../
 478'
 479
 480test_expect_success '#3: GIT_DIR, GIT_WORK_TREE=.. in subdir' '
 481        cat >3/sub/sub/expected <<EOF &&
 482setup: git_dir: $here/3/.git
 483setup: worktree: $here
 484setup: cwd: $here
 485setup: prefix: 3/sub/sub/
 486EOF
 487        test_repo 3/sub/sub "$here/3/.git" "$here"
 488'
 489
 490#
 491# case #4
 492#
 493############################################################
 494#
 495# Input:
 496#
 497#  - GIT_WORK_TREE is not set
 498#  - GIT_DIR is not set
 499#  - core.worktree is set
 500#  - .git is a directory
 501#  - core.bare is not set, cwd is outside .git
 502#
 503# Output:
 504#
 505# core.worktree is ignored -> #0
 506
 507test_expect_success '#4: setup' '
 508        sane_unset GIT_DIR GIT_WORK_TREE &&
 509        mkdir 4 4/sub &&
 510        cd 4 &&
 511        git init &&
 512        git config core.worktree non-existent &&
 513        cd ..
 514'
 515
 516test_expect_success '#4: at root' '
 517        cat >4/expected <<EOF &&
 518setup: git_dir: .git
 519setup: worktree: $here/4
 520setup: cwd: $here/4
 521setup: prefix: (null)
 522EOF
 523        test_repo 4
 524'
 525
 526test_expect_success '#4: in subdir' '
 527        cat >4/sub/expected <<EOF &&
 528setup: git_dir: .git
 529setup: worktree: $here/4
 530setup: cwd: $here/4
 531setup: prefix: sub/
 532EOF
 533        test_repo 4/sub
 534'
 535
 536#
 537# case #5
 538#
 539############################################################
 540#
 541# Input:
 542#
 543#  - GIT_WORK_TREE is set
 544#  - GIT_DIR is not set
 545#  - core.worktree is set
 546#  - .git is a directory
 547#  - core.bare is not set, cwd is outside .git
 548#
 549# Output:
 550#
 551# GIT_WORK_TREE/core.worktree are ignored -> #0
 552
 553test_expect_success '#5: setup' '
 554        sane_unset GIT_DIR GIT_WORK_TREE &&
 555        mkdir 5 5/sub &&
 556        cd 5 &&
 557        git init &&
 558        git config core.worktree non-existent &&
 559        GIT_WORK_TREE=non-existent-too &&
 560        export GIT_WORK_TREE &&
 561        cd ..
 562'
 563
 564test_expect_success '#5: at root' '
 565        cat >5/expected <<EOF &&
 566setup: git_dir: .git
 567setup: worktree: $here/5
 568setup: cwd: $here/5
 569setup: prefix: (null)
 570EOF
 571        test_repo 5
 572'
 573
 574test_expect_success '#5: in subdir' '
 575        cat >5/sub/expected <<EOF &&
 576setup: git_dir: .git
 577setup: worktree: $here/5
 578setup: cwd: $here/5
 579setup: prefix: sub/
 580EOF
 581        test_repo 5/sub
 582'
 583
 584#
 585# case #6
 586#
 587############################################################
 588#
 589# Input:
 590#
 591#  - GIT_WORK_TREE is not set
 592#  - GIT_DIR is set
 593#  - core.worktree is set
 594#  - .git is a directory
 595#  - core.bare is not set, cwd is outside .git
 596#
 597# Output:
 598#
 599#  - worktree is at core.worktree
 600#  - cwd is at worktree root
 601#  - prefix is calculated
 602#  - git_dir is at $GIT_DIR
 603#  - cwd can be outside worktree
 604
 605test_expect_success '#6: setup' '
 606        sane_unset GIT_DIR GIT_WORK_TREE &&
 607        mkdir 6 6/sub 6/sub/sub 6.wt 6.wt/sub 6/wt 6/wt/sub &&
 608        cd 6 && git init && cd ..
 609'
 610
 611test_expect_success '#6: GIT_DIR(rel), core.worktree=.. at root' '
 612        cat >6/expected <<EOF &&
 613setup: git_dir: .git
 614setup: worktree: $here/6
 615setup: cwd: $here/6
 616setup: prefix: (null)
 617EOF
 618        git config --file="$here/6/.git/config" core.worktree "$here/6" &&
 619        test_repo 6 .git
 620'
 621
 622test_expect_success '#6: GIT_DIR(rel), core.worktree=..(rel) at root' '
 623        cat >6/expected <<EOF &&
 624setup: git_dir: .git
 625setup: worktree: $here/6
 626setup: cwd: $here/6
 627setup: prefix: (null)
 628EOF
 629        git config --file="$here/6/.git/config" core.worktree .. &&
 630        test_repo 6 .git
 631'
 632
 633test_expect_success '#6: GIT_DIR, core.worktree=.. at root' '
 634        cat >6/expected <<EOF &&
 635setup: git_dir: $here/6/.git
 636setup: worktree: $here/6
 637setup: cwd: $here/6
 638setup: prefix: (null)
 639EOF
 640        git config --file="$here/6/.git/config" core.worktree "$here/6" &&
 641        test_repo 6 "$here/6/.git"
 642'
 643
 644test_expect_success '#6: GIT_DIR, core.worktree=..(rel) at root' '
 645        cat >6/expected <<EOF &&
 646setup: git_dir: $here/6/.git
 647setup: worktree: $here/6
 648setup: cwd: $here/6
 649setup: prefix: (null)
 650EOF
 651        git config --file="$here/6/.git/config" core.worktree .. &&
 652        test_repo 6 "$here/6/.git"
 653'
 654
 655test_expect_success '#6: GIT_DIR(rel), core.worktree=.. in subdir' '
 656        cat >6/sub/sub/expected <<EOF &&
 657setup: git_dir: $here/6/.git
 658setup: worktree: $here/6
 659setup: cwd: $here/6
 660setup: prefix: sub/sub/
 661EOF
 662        git config --file="$here/6/.git/config" core.worktree "$here/6" &&
 663        test_repo 6/sub/sub ../../.git
 664'
 665
 666test_expect_success '#6: GIT_DIR(rel), core.worktree=..(rel) in subdir' '
 667        cat >6/sub/sub/expected <<EOF &&
 668setup: git_dir: $here/6/.git
 669setup: worktree: $here/6
 670setup: cwd: $here/6
 671setup: prefix: sub/sub/
 672EOF
 673        git config --file="$here/6/.git/config" core.worktree .. &&
 674        test_repo 6/sub/sub ../../.git
 675'
 676
 677test_expect_success '#6: GIT_DIR, core.worktree=.. in subdir' '
 678        cat >6/sub/expected <<EOF &&
 679setup: git_dir: $here/6/.git
 680setup: worktree: $here/6
 681setup: cwd: $here/6
 682setup: prefix: sub/
 683EOF
 684        git config --file="$here/6/.git/config" core.worktree "$here/6" &&
 685        test_repo 6/sub "$here/6/.git"
 686'
 687
 688test_expect_success '#6: GIT_DIR, core.worktree=..(rel) in subdir' '
 689        cat >6/sub/sub/expected <<EOF &&
 690setup: git_dir: $here/6/.git
 691setup: worktree: $here/6
 692setup: cwd: $here/6
 693setup: prefix: sub/sub/
 694EOF
 695        git config --file="$here/6/.git/config" core.worktree .. &&
 696        test_repo 6/sub/sub "$here/6/.git"
 697'
 698
 699test_expect_success '#6: GIT_DIR(rel), core.worktree=../wt at root' '
 700        cat >6/expected <<EOF &&
 701setup: git_dir: .git
 702setup: worktree: $here/6/wt
 703setup: cwd: $here/6
 704setup: prefix: (null)
 705EOF
 706        git config --file="$here/6/.git/config" core.worktree "$here/6/wt" &&
 707        test_repo 6 .git
 708'
 709
 710test_expect_success '#6: GIT_DIR(rel), core.worktree=../wt(rel) at root' '
 711        cat >6/expected <<EOF &&
 712setup: git_dir: .git
 713setup: worktree: $here/6/wt
 714setup: cwd: $here/6
 715setup: prefix: (null)
 716EOF
 717        git config --file="$here/6/.git/config" core.worktree ../wt &&
 718        test_repo 6 .git
 719'
 720
 721test_expect_success '#6: GIT_DIR, core.worktree=../wt(rel) at root' '
 722        cat >6/expected <<EOF &&
 723setup: git_dir: $here/6/.git
 724setup: worktree: $here/6/wt
 725setup: cwd: $here/6
 726setup: prefix: (null)
 727EOF
 728        git config --file="$here/6/.git/config" core.worktree ../wt &&
 729        test_repo 6 "$here/6/.git"
 730'
 731
 732test_expect_success '#6: GIT_DIR, core.worktree=../wt at root' '
 733        cat >6/expected <<EOF &&
 734setup: git_dir: $here/6/.git
 735setup: worktree: $here/6/wt
 736setup: cwd: $here/6
 737setup: prefix: (null)
 738EOF
 739        git config --file="$here/6/.git/config" core.worktree "$here/6/wt" &&
 740        test_repo 6 "$here/6/.git"
 741'
 742
 743test_expect_success '#6: GIT_DIR(rel), core.worktree=../wt in subdir' '
 744        cat >6/sub/sub/expected <<EOF &&
 745setup: git_dir: ../../.git
 746setup: worktree: $here/6/wt
 747setup: cwd: $here/6/sub/sub
 748setup: prefix: (null)
 749EOF
 750        git config --file="$here/6/.git/config" core.worktree "$here/6/wt" &&
 751        test_repo 6/sub/sub ../../.git
 752'
 753
 754test_expect_success '#6: GIT_DIR(rel), core.worktree=../wt(rel) in subdir' '
 755        cat >6/sub/sub/expected <<EOF &&
 756setup: git_dir: ../../.git
 757setup: worktree: $here/6/wt
 758setup: cwd: $here/6/sub/sub
 759setup: prefix: (null)
 760EOF
 761        git config --file="$here/6/.git/config" core.worktree ../wt &&
 762        test_repo 6/sub/sub ../../.git
 763'
 764
 765test_expect_success '#6: GIT_DIR, core.worktree=../wt(rel) in subdir' '
 766        cat >6/sub/sub/expected <<EOF &&
 767setup: git_dir: $here/6/.git
 768setup: worktree: $here/6/wt
 769setup: cwd: $here/6/sub/sub
 770setup: prefix: (null)
 771EOF
 772        git config --file="$here/6/.git/config" core.worktree ../wt &&
 773        test_repo 6/sub/sub "$here/6/.git"
 774'
 775
 776test_expect_success '#6: GIT_DIR, core.worktree=../wt in subdir' '
 777        cat >6/sub/sub/expected <<EOF &&
 778setup: git_dir: $here/6/.git
 779setup: worktree: $here/6/wt
 780setup: cwd: $here/6/sub/sub
 781setup: prefix: (null)
 782EOF
 783        git config --file="$here/6/.git/config" core.worktree "$here/6/wt" &&
 784        test_repo 6/sub/sub "$here/6/.git"
 785'
 786
 787test_expect_success '#6: GIT_DIR(rel), core.worktree=../.. at root' '
 788        cat >6/expected <<EOF &&
 789setup: git_dir: $here/6/.git
 790setup: worktree: $here
 791setup: cwd: $here
 792setup: prefix: 6/
 793EOF
 794        git config --file="$here/6/.git/config" core.worktree "$here" &&
 795        test_repo 6 .git
 796'
 797
 798test_expect_success '#6: GIT_DIR(rel), core.worktree=../..(rel) at root' '
 799        cat >6/expected <<EOF &&
 800setup: git_dir: $here/6/.git
 801setup: worktree: $here
 802setup: cwd: $here
 803setup: prefix: 6/
 804EOF
 805        git config --file="$here/6/.git/config" core.worktree ../../ &&
 806        test_repo 6 .git
 807'
 808
 809test_expect_success '#6: GIT_DIR, core.worktree=../..(rel) at root' '
 810        cat >6/expected <<EOF &&
 811setup: git_dir: $here/6/.git
 812setup: worktree: $here
 813setup: cwd: $here
 814setup: prefix: 6/
 815EOF
 816        git config --file="$here/6/.git/config" core.worktree ../../ &&
 817        test_repo 6 "$here/6/.git"
 818'
 819
 820test_expect_success '#6: GIT_DIR, core.worktree=../.. at root' '
 821        cat >6/expected <<EOF &&
 822setup: git_dir: $here/6/.git
 823setup: worktree: $here
 824setup: cwd: $here
 825setup: prefix: 6/
 826EOF
 827        git config --file="$here/6/.git/config" core.worktree "$here" &&
 828        test_repo 6 "$here/6/.git"
 829'
 830
 831test_expect_success '#6: GIT_DIR(rel), core.worktree=../.. in subdir' '
 832        cat >6/sub/sub/expected <<EOF &&
 833setup: git_dir: $here/6/.git
 834setup: worktree: $here
 835setup: cwd: $here
 836setup: prefix: 6/sub/sub/
 837EOF
 838        git config --file="$here/6/.git/config" core.worktree "$here" &&
 839        test_repo 6/sub/sub ../../.git
 840'
 841
 842test_expect_success '#6: GIT_DIR(rel), core.worktree=../..(rel) in subdir' '
 843        cat >6/sub/sub/expected <<EOF &&
 844setup: git_dir: $here/6/.git
 845setup: worktree: $here
 846setup: cwd: $here
 847setup: prefix: 6/sub/sub/
 848EOF
 849        git config --file="$here/6/.git/config" core.worktree ../.. &&
 850        test_repo 6/sub/sub ../../.git
 851'
 852
 853test_expect_success '#6: GIT_DIR, core.worktree=../..(rel) in subdir' '
 854        cat >6/sub/sub/expected <<EOF &&
 855setup: git_dir: $here/6/.git
 856setup: worktree: $here
 857setup: cwd: $here
 858setup: prefix: 6/sub/sub/
 859EOF
 860        git config --file="$here/6/.git/config" core.worktree ../.. &&
 861        test_repo 6/sub/sub "$here/6/.git"
 862'
 863
 864test_expect_success '#6: GIT_DIR, core.worktree=../.. in subdir' '
 865        cat >6/sub/sub/expected <<EOF &&
 866setup: git_dir: $here/6/.git
 867setup: worktree: $here
 868setup: cwd: $here
 869setup: prefix: 6/sub/sub/
 870EOF
 871        git config --file="$here/6/.git/config" core.worktree "$here" &&
 872        test_repo 6/sub/sub "$here/6/.git"
 873'
 874
 875#
 876# case #7
 877#
 878############################################################
 879#
 880# Input:
 881#
 882#  - GIT_WORK_TREE is set
 883#  - GIT_DIR is set
 884#  - core.worktree is set
 885#  - .git is a directory
 886#  - core.bare is not set, cwd is outside .git
 887#
 888# Output:
 889#
 890# core.worktree is overridden by GIT_WORK_TREE -> #3
 891
 892test_expect_success '#7: setup' '
 893        sane_unset GIT_DIR GIT_WORK_TREE &&
 894        mkdir 7 7/sub 7/sub/sub 7.wt 7.wt/sub 7/wt 7/wt/sub &&
 895        cd 7 &&
 896        git init &&
 897        git config core.worktree non-existent &&
 898        cd ..
 899'
 900
 901test_expect_success '#7: GIT_DIR(rel), GIT_WORK_TREE=root at root' '
 902        cat >7/expected <<EOF &&
 903setup: git_dir: .git
 904setup: worktree: $here/7
 905setup: cwd: $here/7
 906setup: prefix: (null)
 907EOF
 908        test_repo 7 .git "$here/7"
 909'
 910
 911test_expect_success '#7: GIT_DIR(rel), GIT_WORK_TREE=root(rel) at root' '
 912        cat >7/expected <<EOF &&
 913setup: git_dir: .git
 914setup: worktree: $here/7
 915setup: cwd: $here/7
 916setup: prefix: (null)
 917EOF
 918        test_repo 7 .git .
 919'
 920
 921test_expect_success '#7: GIT_DIR, GIT_WORK_TREE=root at root' '
 922        cat >7/expected <<EOF &&
 923setup: git_dir: $here/7/.git
 924setup: worktree: $here/7
 925setup: cwd: $here/7
 926setup: prefix: (null)
 927EOF
 928        test_repo 7 "$here/7/.git" "$here/7"
 929'
 930
 931test_expect_success '#7: GIT_DIR, GIT_WORK_TREE=root(rel) at root' '
 932        cat >7/expected <<EOF &&
 933setup: git_dir: $here/7/.git
 934setup: worktree: $here/7
 935setup: cwd: $here/7
 936setup: prefix: (null)
 937EOF
 938        test_repo 7 "$here/7/.git" .
 939'
 940
 941test_expect_success '#7: GIT_DIR(rel), GIT_WORKTREE=root in subdir' '
 942        cat >7/sub/sub/expected <<EOF &&
 943setup: git_dir: $here/7/.git
 944setup: worktree: $here/7
 945setup: cwd: $here/7
 946setup: prefix: sub/sub/
 947EOF
 948        test_repo 7/sub/sub ../../.git "$here/7"
 949'
 950
 951test_expect_success '#7: GIT_DIR(rel), GIT_WORKTREE=root(rel) in subdir' '
 952        cat >7/sub/sub/expected <<EOF &&
 953setup: git_dir: $here/7/.git
 954setup: worktree: $here/7
 955setup: cwd: $here/7
 956setup: prefix: sub/sub/
 957EOF
 958        test_repo 7/sub/sub ../../.git ../..
 959'
 960
 961test_expect_success '#7: GIT_DIR, GIT_WORKTREE=root in subdir' '
 962        cat >7/sub/expected <<EOF &&
 963setup: git_dir: $here/7/.git
 964setup: worktree: $here/7
 965setup: cwd: $here/7
 966setup: prefix: sub/
 967EOF
 968        test_repo 7/sub "$here/7/.git" "$here/7"
 969'
 970
 971test_expect_success '#7: GIT_DIR, GIT_WORKTREE=root(rel) in subdir' '
 972        cat >7/sub/sub/expected <<EOF &&
 973setup: git_dir: $here/7/.git
 974setup: worktree: $here/7
 975setup: cwd: $here/7
 976setup: prefix: sub/sub/
 977EOF
 978        test_repo 7/sub/sub "$here/7/.git" ../..
 979'
 980
 981test_expect_success '#7: GIT_DIR(rel), GIT_WORK_TREE=wt at root' '
 982        cat >7/expected <<EOF &&
 983setup: git_dir: .git
 984setup: worktree: $here/7/wt
 985setup: cwd: $here/7
 986setup: prefix: (null)
 987EOF
 988        test_repo 7 .git "$here/7/wt"
 989'
 990
 991test_expect_success '#7: GIT_DIR(rel), GIT_WORK_TREE=wt(rel) at root' '
 992        cat >7/expected <<EOF &&
 993setup: git_dir: .git
 994setup: worktree: $here/7/wt
 995setup: cwd: $here/7
 996setup: prefix: (null)
 997EOF
 998        test_repo 7 .git wt
 999'
1000
1001test_expect_success '#7: GIT_DIR, GIT_WORK_TREE=wt(rel) at root' '
1002        cat >7/expected <<EOF &&
1003setup: git_dir: $here/7/.git
1004setup: worktree: $here/7/wt
1005setup: cwd: $here/7
1006setup: prefix: (null)
1007EOF
1008        test_repo 7 "$here/7/.git" wt
1009'
1010
1011test_expect_success '#7: GIT_DIR, GIT_WORK_TREE=wt at root' '
1012        cat >7/expected <<EOF &&
1013setup: git_dir: $here/7/.git
1014setup: worktree: $here/7/wt
1015setup: cwd: $here/7
1016setup: prefix: (null)
1017EOF
1018        test_repo 7 "$here/7/.git" "$here/7/wt"
1019'
1020
1021test_expect_success '#7: GIT_DIR(rel), GIT_WORK_TREE=wt in subdir' '
1022        cat >7/sub/sub/expected <<EOF &&
1023setup: git_dir: ../../.git
1024setup: worktree: $here/7/wt
1025setup: cwd: $here/7/sub/sub
1026setup: prefix: (null)
1027EOF
1028        test_repo 7/sub/sub ../../.git "$here/7/wt"
1029'
1030
1031test_expect_success '#7: GIT_DIR(rel), GIT_WORK_TREE=wt(rel) in subdir' '
1032        cat >7/sub/sub/expected <<EOF &&
1033setup: git_dir: ../../.git
1034setup: worktree: $here/7/wt
1035setup: cwd: $here/7/sub/sub
1036setup: prefix: (null)
1037EOF
1038        test_repo 7/sub/sub ../../.git ../../wt
1039'
1040
1041test_expect_success '#7: GIT_DIR, GIT_WORK_TREE=wt(rel) in subdir' '
1042        cat >7/sub/sub/expected <<EOF &&
1043setup: git_dir: $here/7/.git
1044setup: worktree: $here/7/wt
1045setup: cwd: $here/7/sub/sub
1046setup: prefix: (null)
1047EOF
1048        test_repo 7/sub/sub "$here/7/.git" ../../wt
1049'
1050
1051test_expect_success '#7: GIT_DIR, GIT_WORK_TREE=wt in subdir' '
1052        cat >7/sub/sub/expected <<EOF &&
1053setup: git_dir: $here/7/.git
1054setup: worktree: $here/7/wt
1055setup: cwd: $here/7/sub/sub
1056setup: prefix: (null)
1057EOF
1058        test_repo 7/sub/sub "$here/7/.git" "$here/7/wt"
1059'
1060
1061test_expect_success '#7: GIT_DIR(rel), GIT_WORK_TREE=.. at root' '
1062        cat >7/expected <<EOF &&
1063setup: git_dir: $here/7/.git
1064setup: worktree: $here
1065setup: cwd: $here
1066setup: prefix: 7/
1067EOF
1068        test_repo 7 .git "$here"
1069'
1070
1071test_expect_success '#7: GIT_DIR(rel), GIT_WORK_TREE=..(rel) at root' '
1072        cat >7/expected <<EOF &&
1073setup: git_dir: $here/7/.git
1074setup: worktree: $here
1075setup: cwd: $here
1076setup: prefix: 7/
1077EOF
1078        test_repo 7 .git ..
1079'
1080
1081test_expect_success '#7: GIT_DIR, GIT_WORK_TREE=..(rel) at root' '
1082        cat >7/expected <<EOF &&
1083setup: git_dir: $here/7/.git
1084setup: worktree: $here
1085setup: cwd: $here
1086setup: prefix: 7/
1087EOF
1088        test_repo 7 "$here/7/.git" ..
1089'
1090
1091test_expect_success '#7: GIT_DIR, GIT_WORK_TREE=.. at root' '
1092        cat >7/expected <<EOF &&
1093setup: git_dir: $here/7/.git
1094setup: worktree: $here
1095setup: cwd: $here
1096setup: prefix: 7/
1097EOF
1098        test_repo 7 "$here/7/.git" "$here"
1099'
1100
1101test_expect_success '#7: GIT_DIR(rel), GIT_WORK_TREE=.. in subdir' '
1102        cat >7/sub/sub/expected <<EOF &&
1103setup: git_dir: $here/7/.git
1104setup: worktree: $here
1105setup: cwd: $here
1106setup: prefix: 7/sub/sub/
1107EOF
1108        test_repo 7/sub/sub ../../.git "$here"
1109'
1110
1111test_expect_success '#7: GIT_DIR(rel), GIT_WORK_TREE=..(rel) in subdir' '
1112        cat >7/sub/sub/expected <<EOF &&
1113setup: git_dir: $here/7/.git
1114setup: worktree: $here
1115setup: cwd: $here
1116setup: prefix: 7/sub/sub/
1117EOF
1118        test_repo 7/sub/sub ../../.git ../../..
1119'
1120
1121test_expect_success '#7: GIT_DIR, GIT_WORK_TREE=..(rel) in subdir' '
1122        cat >7/sub/sub/expected <<EOF &&
1123setup: git_dir: $here/7/.git
1124setup: worktree: $here
1125setup: cwd: $here
1126setup: prefix: 7/sub/sub/
1127EOF
1128        test_repo 7/sub/sub "$here/7/.git" ../../../
1129'
1130
1131test_expect_success '#7: GIT_DIR, GIT_WORK_TREE=.. in subdir' '
1132        cat >7/sub/sub/expected <<EOF &&
1133setup: git_dir: $here/7/.git
1134setup: worktree: $here
1135setup: cwd: $here
1136setup: prefix: 7/sub/sub/
1137EOF
1138        test_repo 7/sub/sub "$here/7/.git" "$here"
1139'
1140
1141#
1142# case #8
1143#
1144############################################################
1145#
1146# Input:
1147#
1148#  - GIT_WORK_TREE is not set
1149#  - GIT_DIR is not set
1150#  - core.worktree is not set
1151#  - .git is a file
1152#  - core.bare is not set, cwd is outside .git
1153#
1154# Output:
1155#
1156# #0 except that git_dir is set by .git file
1157
1158test_expect_success '#8: setup' '
1159        sane_unset GIT_DIR GIT_WORK_TREE &&
1160        mkdir 8 8/sub &&
1161        cd 8 &&
1162        git init &&
1163        mv .git ../8.git &&
1164        echo gitdir: ../8.git >.git &&
1165        cd ..
1166'
1167
1168test_expect_success '#8: at root' '
1169        cat >8/expected <<EOF &&
1170setup: git_dir: $here/8.git
1171setup: worktree: $here/8
1172setup: cwd: $here/8
1173setup: prefix: (null)
1174EOF
1175        test_repo 8
1176'
1177
1178test_expect_success '#8: in subdir' '
1179        cat >8/sub/expected <<EOF &&
1180setup: git_dir: $here/8.git
1181setup: worktree: $here/8
1182setup: cwd: $here/8
1183setup: prefix: sub/
1184EOF
1185        test_repo 8/sub
1186'
1187
1188#
1189# case #9
1190#
1191############################################################
1192#
1193# Input:
1194#
1195#  - GIT_WORK_TREE is set
1196#  - GIT_DIR is not set
1197#  - core.worktree is not set
1198#  - .git is a file
1199#  - core.bare is not set, cwd is outside .git
1200#
1201# Output:
1202#
1203# #1 except that git_dir is set by .git file
1204
1205test_expect_success '#9: setup' '
1206        sane_unset GIT_DIR GIT_WORK_TREE &&
1207        mkdir 9 9/sub 9.wt 9.wt/sub 9/wt 9/wt/sub &&
1208        cd 9 &&
1209        git init &&
1210        mv .git ../9.git &&
1211        echo gitdir: ../9.git >.git &&
1212        GIT_WORK_TREE=non-existent &&
1213        export GIT_WORK_TREE &&
1214        cd ..
1215'
1216
1217test_expect_success '#9: at root' '
1218        cat >9/expected <<EOF &&
1219setup: git_dir: $here/9.git
1220setup: worktree: $here/9
1221setup: cwd: $here/9
1222setup: prefix: (null)
1223EOF
1224        test_repo 9
1225'
1226
1227test_expect_success '#9: in subdir' '
1228        cat >9/sub/expected <<EOF &&
1229setup: git_dir: $here/9.git
1230setup: worktree: $here/9
1231setup: cwd: $here/9
1232setup: prefix: sub/
1233EOF
1234        test_repo 9/sub
1235'
1236
1237#
1238# case #10
1239#
1240############################################################
1241#
1242# Input:
1243#
1244#  - GIT_WORK_TREE is not set
1245#  - GIT_DIR is set
1246#  - core.worktree is not set
1247#  - .git is a file
1248#  - core.bare is not set, cwd is outside .git
1249#
1250# Output:
1251#
1252# #2 except that git_dir is set by .git file
1253
1254test_expect_success '#10: setup' '
1255        sane_unset GIT_DIR GIT_WORK_TREE &&
1256        mkdir 10 10/sub &&
1257        cd 10 &&
1258        git init &&
1259        mv .git ../10.git &&
1260        echo gitdir: ../10.git >.git &&
1261        cd ..
1262'
1263
1264test_expect_success '#10: at root' '
1265        cat >10/expected <<EOF &&
1266setup: git_dir: $here/10.git
1267setup: worktree: $here/10
1268setup: cwd: $here/10
1269setup: prefix: (null)
1270EOF
1271        test_repo 10 "$here/10/.git"
1272'
1273
1274test_expect_success '#10: in subdir' '
1275        cat >10/sub/expected <<EOF &&
1276setup: git_dir: $here/10.git
1277setup: worktree: $here/10/sub
1278setup: cwd: $here/10/sub
1279setup: prefix: (null)
1280EOF
1281        test_repo 10/sub "$here/10/.git"
1282'
1283
1284test_expect_success '#10: relative GIT_DIR at root' '
1285        cat >10/expected <<EOF &&
1286setup: git_dir: $here/10.git
1287setup: worktree: $here/10
1288setup: cwd: $here/10
1289setup: prefix: (null)
1290EOF
1291        test_repo 10 .git
1292'
1293
1294test_expect_success '#10: relative GIT_DIR in subdir' '
1295        cat >10/sub/expected <<EOF &&
1296setup: git_dir: $here/10.git
1297setup: worktree: $here/10/sub
1298setup: cwd: $here/10/sub
1299setup: prefix: (null)
1300EOF
1301        test_repo 10/sub ../.git
1302'
1303
1304#
1305# case #11
1306#
1307############################################################
1308#
1309# Input:
1310#
1311#  - GIT_WORK_TREE is set
1312#  - GIT_DIR is set
1313#  - core.worktree is not set
1314#  - .git is a file
1315#  - core.bare is not set, cwd is outside .git
1316#
1317# Output:
1318#
1319# #3 except that git_dir is set by .git file
1320
1321test_expect_success '#11: setup' '
1322        sane_unset GIT_DIR GIT_WORK_TREE &&
1323        mkdir 11 11/sub 11/sub/sub 11.wt 11.wt/sub 11/wt 11/wt/sub &&
1324        cd 11 &&
1325        git init &&
1326        mv .git ../11.git &&
1327        echo gitdir: ../11.git >.git &&
1328        cd ..
1329'
1330
1331test_expect_success '#11: GIT_DIR(rel), GIT_WORK_TREE=root at root' '
1332        cat >11/expected <<EOF &&
1333setup: git_dir: $here/11.git
1334setup: worktree: $here/11
1335setup: cwd: $here/11
1336setup: prefix: (null)
1337EOF
1338        test_repo 11 .git "$here/11"
1339'
1340
1341test_expect_success '#11: GIT_DIR(rel), GIT_WORK_TREE=root(rel) at root' '
1342        cat >11/expected <<EOF &&
1343setup: git_dir: $here/11.git
1344setup: worktree: $here/11
1345setup: cwd: $here/11
1346setup: prefix: (null)
1347EOF
1348        test_repo 11 .git .
1349'
1350
1351test_expect_success '#11: GIT_DIR, GIT_WORK_TREE=root at root' '
1352        cat >11/expected <<EOF &&
1353setup: git_dir: $here/11.git
1354setup: worktree: $here/11
1355setup: cwd: $here/11
1356setup: prefix: (null)
1357EOF
1358        test_repo 11 "$here/11/.git" "$here/11"
1359'
1360
1361test_expect_success '#11: GIT_DIR, GIT_WORK_TREE=root(rel) at root' '
1362        cat >11/expected <<EOF &&
1363setup: git_dir: $here/11.git
1364setup: worktree: $here/11
1365setup: cwd: $here/11
1366setup: prefix: (null)
1367EOF
1368        test_repo 11 "$here/11/.git" .
1369'
1370
1371test_expect_success '#11: GIT_DIR(rel), GIT_WORKTREE=root in subdir' '
1372        cat >11/sub/sub/expected <<EOF &&
1373setup: git_dir: $here/11.git
1374setup: worktree: $here/11
1375setup: cwd: $here/11
1376setup: prefix: sub/sub/
1377EOF
1378        test_repo 11/sub/sub ../../.git "$here/11"
1379'
1380
1381test_expect_success '#11: GIT_DIR(rel), GIT_WORKTREE=root(rel) in subdir' '
1382        cat >11/sub/sub/expected <<EOF &&
1383setup: git_dir: $here/11.git
1384setup: worktree: $here/11
1385setup: cwd: $here/11
1386setup: prefix: sub/sub/
1387EOF
1388        test_repo 11/sub/sub ../../.git ../..
1389'
1390
1391test_expect_success '#11: GIT_DIR, GIT_WORKTREE=root in subdir' '
1392        cat >11/sub/expected <<EOF &&
1393setup: git_dir: $here/11.git
1394setup: worktree: $here/11
1395setup: cwd: $here/11
1396setup: prefix: sub/
1397EOF
1398        test_repo 11/sub "$here/11/.git" "$here/11"
1399'
1400
1401test_expect_success '#11: GIT_DIR, GIT_WORKTREE=root(rel) in subdir' '
1402        cat >11/sub/sub/expected <<EOF &&
1403setup: git_dir: $here/11.git
1404setup: worktree: $here/11
1405setup: cwd: $here/11
1406setup: prefix: sub/sub/
1407EOF
1408        test_repo 11/sub/sub "$here/11/.git" ../..
1409'
1410
1411test_expect_success '#11: GIT_DIR(rel), GIT_WORK_TREE=wt at root' '
1412        cat >11/expected <<EOF &&
1413setup: git_dir: $here/11.git
1414setup: worktree: $here/11/wt
1415setup: cwd: $here/11
1416setup: prefix: (null)
1417EOF
1418        test_repo 11 .git "$here/11/wt"
1419'
1420
1421test_expect_success '#11: GIT_DIR(rel), GIT_WORK_TREE=wt(rel) at root' '
1422        cat >11/expected <<EOF &&
1423setup: git_dir: $here/11.git
1424setup: worktree: $here/11/wt
1425setup: cwd: $here/11
1426setup: prefix: (null)
1427EOF
1428        test_repo 11 .git wt
1429'
1430
1431test_expect_success '#11: GIT_DIR, GIT_WORK_TREE=wt(rel) at root' '
1432        cat >11/expected <<EOF &&
1433setup: git_dir: $here/11.git
1434setup: worktree: $here/11/wt
1435setup: cwd: $here/11
1436setup: prefix: (null)
1437EOF
1438        test_repo 11 "$here/11/.git" wt
1439'
1440
1441test_expect_success '#11: GIT_DIR, GIT_WORK_TREE=wt at root' '
1442        cat >11/expected <<EOF &&
1443setup: git_dir: $here/11.git
1444setup: worktree: $here/11/wt
1445setup: cwd: $here/11
1446setup: prefix: (null)
1447EOF
1448        test_repo 11 "$here/11/.git" "$here/11/wt"
1449'
1450
1451test_expect_success '#11: GIT_DIR(rel), GIT_WORK_TREE=wt in subdir' '
1452        cat >11/sub/sub/expected <<EOF &&
1453setup: git_dir: $here/11.git
1454setup: worktree: $here/11/wt
1455setup: cwd: $here/11/sub/sub
1456setup: prefix: (null)
1457EOF
1458        test_repo 11/sub/sub ../../.git "$here/11/wt"
1459'
1460
1461test_expect_success '#11: GIT_DIR(rel), GIT_WORK_TREE=wt(rel) in subdir' '
1462        cat >11/sub/sub/expected <<EOF &&
1463setup: git_dir: $here/11.git
1464setup: worktree: $here/11/wt
1465setup: cwd: $here/11/sub/sub
1466setup: prefix: (null)
1467EOF
1468        test_repo 11/sub/sub ../../.git ../../wt
1469'
1470
1471test_expect_success '#11: GIT_DIR, GIT_WORK_TREE=wt(rel) in subdir' '
1472        cat >11/sub/sub/expected <<EOF &&
1473setup: git_dir: $here/11.git
1474setup: worktree: $here/11/wt
1475setup: cwd: $here/11/sub/sub
1476setup: prefix: (null)
1477EOF
1478        test_repo 11/sub/sub "$here/11/.git" ../../wt
1479'
1480
1481test_expect_success '#11: GIT_DIR, GIT_WORK_TREE=wt in subdir' '
1482        cat >11/sub/sub/expected <<EOF &&
1483setup: git_dir: $here/11.git
1484setup: worktree: $here/11/wt
1485setup: cwd: $here/11/sub/sub
1486setup: prefix: (null)
1487EOF
1488        test_repo 11/sub/sub "$here/11/.git" "$here/11/wt"
1489'
1490
1491test_expect_success '#11: GIT_DIR(rel), GIT_WORK_TREE=.. at root' '
1492        cat >11/expected <<EOF &&
1493setup: git_dir: $here/11.git
1494setup: worktree: $here
1495setup: cwd: $here
1496setup: prefix: 11/
1497EOF
1498        test_repo 11 .git "$here"
1499'
1500
1501test_expect_success '#11: GIT_DIR(rel), GIT_WORK_TREE=..(rel) at root' '
1502        cat >11/expected <<EOF &&
1503setup: git_dir: $here/11.git
1504setup: worktree: $here
1505setup: cwd: $here
1506setup: prefix: 11/
1507EOF
1508        test_repo 11 .git ..
1509'
1510
1511test_expect_success '#11: GIT_DIR, GIT_WORK_TREE=..(rel) at root' '
1512        cat >11/expected <<EOF &&
1513setup: git_dir: $here/11.git
1514setup: worktree: $here
1515setup: cwd: $here
1516setup: prefix: 11/
1517EOF
1518        test_repo 11 "$here/11/.git" ..
1519'
1520
1521test_expect_success '#11: GIT_DIR, GIT_WORK_TREE=.. at root' '
1522        cat >11/expected <<EOF &&
1523setup: git_dir: $here/11.git
1524setup: worktree: $here
1525setup: cwd: $here
1526setup: prefix: 11/
1527EOF
1528        test_repo 11 "$here/11/.git" "$here"
1529'
1530
1531test_expect_success '#11: GIT_DIR(rel), GIT_WORK_TREE=.. in subdir' '
1532        cat >11/sub/sub/expected <<EOF &&
1533setup: git_dir: $here/11.git
1534setup: worktree: $here
1535setup: cwd: $here
1536setup: prefix: 11/sub/sub/
1537EOF
1538        test_repo 11/sub/sub ../../.git "$here"
1539'
1540
1541test_expect_success '#11: GIT_DIR(rel), GIT_WORK_TREE=..(rel) in subdir' '
1542        cat >11/sub/sub/expected <<EOF &&
1543setup: git_dir: $here/11.git
1544setup: worktree: $here
1545setup: cwd: $here
1546setup: prefix: 11/sub/sub/
1547EOF
1548        test_repo 11/sub/sub ../../.git ../../..
1549'
1550
1551test_expect_success '#11: GIT_DIR, GIT_WORK_TREE=..(rel) in subdir' '
1552        cat >11/sub/sub/expected <<EOF &&
1553setup: git_dir: $here/11.git
1554setup: worktree: $here
1555setup: cwd: $here
1556setup: prefix: 11/sub/sub/
1557EOF
1558        test_repo 11/sub/sub "$here/11/.git" ../../../
1559'
1560
1561test_expect_success '#11: GIT_DIR, GIT_WORK_TREE=.. in subdir' '
1562        cat >11/sub/sub/expected <<EOF &&
1563setup: git_dir: $here/11.git
1564setup: worktree: $here
1565setup: cwd: $here
1566setup: prefix: 11/sub/sub/
1567EOF
1568        test_repo 11/sub/sub "$here/11/.git" "$here"
1569'
1570
1571#
1572# case #12
1573#
1574############################################################
1575#
1576# Input:
1577#
1578#  - GIT_WORK_TREE is not set
1579#  - GIT_DIR is not set
1580#  - core.worktree is set
1581#  - .git is a file
1582#  - core.bare is not set, cwd is outside .git
1583#
1584# Output:
1585#
1586# #4 except that git_dir is set by .git file
1587
1588
1589test_expect_success '#12: setup' '
1590        sane_unset GIT_DIR GIT_WORK_TREE &&
1591        mkdir 12 12/sub 12/sub/sub 12.wt 12.wt/sub 12/wt 12/wt/sub &&
1592        cd 12 &&
1593        git init &&
1594        git config core.worktree non-existent &&
1595        mv .git ../12.git &&
1596        echo gitdir: ../12.git >.git &&
1597        cd ..
1598'
1599
1600test_expect_success '#12: at root' '
1601        cat >12/expected <<EOF &&
1602setup: git_dir: $here/12.git
1603setup: worktree: $here/12
1604setup: cwd: $here/12
1605setup: prefix: (null)
1606EOF
1607        test_repo 12
1608'
1609
1610test_expect_success '#12: in subdir' '
1611        cat >12/sub/expected <<EOF &&
1612setup: git_dir: $here/12.git
1613setup: worktree: $here/12
1614setup: cwd: $here/12
1615setup: prefix: sub/
1616EOF
1617        test_repo 12/sub
1618'
1619
1620#
1621# case #13
1622#
1623############################################################
1624#
1625# Input:
1626#
1627#  - GIT_WORK_TREE is set
1628#  - GIT_DIR is not set
1629#  - core.worktree is set
1630#  - .git is a file
1631#  - core.bare is not set, cwd is outside .git
1632#
1633# Output:
1634#
1635# #5 except that git_dir is set by .git file
1636
1637test_expect_success '#13: setup' '
1638        sane_unset GIT_DIR GIT_WORK_TREE &&
1639        mkdir 13 13/sub 13/sub/sub 13.wt 13.wt/sub 13/wt 13/wt/sub &&
1640        cd 13 &&
1641        git init &&
1642        git config core.worktree non-existent &&
1643        GIT_WORK_TREE=non-existent-too &&
1644        export GIT_WORK_TREE &&
1645        mv .git ../13.git &&
1646        echo gitdir: ../13.git >.git &&
1647        cd ..
1648'
1649
1650test_expect_success '#13: at root' '
1651        cat >13/expected <<EOF &&
1652setup: git_dir: $here/13.git
1653setup: worktree: $here/13
1654setup: cwd: $here/13
1655setup: prefix: (null)
1656EOF
1657        test_repo 13
1658'
1659
1660test_expect_success '#13: in subdir' '
1661        cat >13/sub/expected <<EOF &&
1662setup: git_dir: $here/13.git
1663setup: worktree: $here/13
1664setup: cwd: $here/13
1665setup: prefix: sub/
1666EOF
1667        test_repo 13/sub
1668'
1669
1670#
1671# case #14
1672#
1673############################################################
1674#
1675# Input:
1676#
1677#  - GIT_WORK_TREE is not set
1678#  - GIT_DIR is set
1679#  - core.worktree is set
1680#  - .git is a file
1681#  - core.bare is not set, cwd is outside .git
1682#
1683# Output:
1684#
1685# #6 except that git_dir is set by .git file
1686
1687test_expect_success '#14: setup' '
1688        sane_unset GIT_DIR GIT_WORK_TREE &&
1689        mkdir 14 14/sub 14/sub/sub 14.wt 14.wt/sub 14/wt 14/wt/sub &&
1690        cd 14 &&
1691        git init &&
1692        mv .git ../14.git &&
1693        echo gitdir: ../14.git >.git &&
1694        cd ..
1695'
1696
1697test_expect_success '#14: GIT_DIR(rel), core.worktree=../14 at root' '
1698        cat >14/expected <<EOF &&
1699setup: git_dir: $here/14.git
1700setup: worktree: $here/14
1701setup: cwd: $here/14
1702setup: prefix: (null)
1703EOF
1704        git config --file="$here/14.git/config" core.worktree "$here/14" &&
1705        test_repo 14 .git
1706'
1707
1708test_expect_success '#14: GIT_DIR(rel), core.worktree=../14(rel) at root' '
1709        cat >14/expected <<EOF &&
1710setup: git_dir: $here/14.git
1711setup: worktree: $here/14
1712setup: cwd: $here/14
1713setup: prefix: (null)
1714EOF
1715        git config --file="$here/14.git/config" core.worktree ../14 &&
1716        test_repo 14 .git
1717'
1718
1719test_expect_success '#14: GIT_DIR, core.worktree=../14 at root' '
1720        cat >14/expected <<EOF &&
1721setup: git_dir: $here/14.git
1722setup: worktree: $here/14
1723setup: cwd: $here/14
1724setup: prefix: (null)
1725EOF
1726        git config --file="$here/14.git/config" core.worktree "$here/14" &&
1727        test_repo 14 "$here/14/.git"
1728'
1729
1730test_expect_success '#14: GIT_DIR, core.worktree=../14(rel) at root' '
1731        cat >14/expected <<EOF &&
1732setup: git_dir: $here/14.git
1733setup: worktree: $here/14
1734setup: cwd: $here/14
1735setup: prefix: (null)
1736EOF
1737        git config --file="$here/14.git/config" core.worktree ../14 &&
1738        test_repo 14 "$here/14/.git"
1739'
1740
1741test_expect_success '#14: GIT_DIR(rel), core.worktree=../14 in subdir' '
1742        cat >14/sub/sub/expected <<EOF &&
1743setup: git_dir: $here/14.git
1744setup: worktree: $here/14
1745setup: cwd: $here/14
1746setup: prefix: sub/sub/
1747EOF
1748        git config --file="$here/14.git/config" core.worktree "$here/14" &&
1749        test_repo 14/sub/sub ../../.git
1750'
1751
1752test_expect_success '#14: GIT_DIR(rel), core.worktree=../14(rel) in subdir' '
1753        cat >14/sub/sub/expected <<EOF &&
1754setup: git_dir: $here/14.git
1755setup: worktree: $here/14
1756setup: cwd: $here/14
1757setup: prefix: sub/sub/
1758EOF
1759        git config --file="$here/14.git/config" core.worktree ../14 &&
1760        test_repo 14/sub/sub ../../.git
1761'
1762
1763test_expect_success '#14: GIT_DIR, core.worktree=../14 in subdir' '
1764        cat >14/sub/expected <<EOF &&
1765setup: git_dir: $here/14.git
1766setup: worktree: $here/14
1767setup: cwd: $here/14
1768setup: prefix: sub/
1769EOF
1770        git config --file="$here/14.git/config" core.worktree "$here/14" &&
1771        test_repo 14/sub "$here/14/.git"
1772'
1773
1774test_expect_success '#14: GIT_DIR, core.worktree=../14(rel) in subdir' '
1775        cat >14/sub/sub/expected <<EOF &&
1776setup: git_dir: $here/14.git
1777setup: worktree: $here/14
1778setup: cwd: $here/14
1779setup: prefix: sub/sub/
1780EOF
1781        git config --file="$here/14.git/config" core.worktree ../14 &&
1782        test_repo 14/sub/sub "$here/14/.git"
1783'
1784
1785test_expect_success '#14: GIT_DIR(rel), core.worktree=../14/wt at root' '
1786        cat >14/expected <<EOF &&
1787setup: git_dir: $here/14.git
1788setup: worktree: $here/14/wt
1789setup: cwd: $here/14
1790setup: prefix: (null)
1791EOF
1792        git config --file="$here/14.git/config" core.worktree "$here/14/wt" &&
1793        test_repo 14 .git
1794'
1795
1796test_expect_success '#14: GIT_DIR(rel), core.worktree=../14/wt(rel) at root' '
1797        cat >14/expected <<EOF &&
1798setup: git_dir: $here/14.git
1799setup: worktree: $here/14/wt
1800setup: cwd: $here/14
1801setup: prefix: (null)
1802EOF
1803        git config --file="$here/14.git/config" core.worktree ../14/wt &&
1804        test_repo 14 .git
1805'
1806
1807test_expect_success '#14: GIT_DIR, core.worktree=../14/wt(rel) at root' '
1808        cat >14/expected <<EOF &&
1809setup: git_dir: $here/14.git
1810setup: worktree: $here/14/wt
1811setup: cwd: $here/14
1812setup: prefix: (null)
1813EOF
1814        git config --file="$here/14.git/config" core.worktree ../14/wt &&
1815        test_repo 14 "$here/14/.git"
1816'
1817
1818test_expect_success '#14: GIT_DIR, core.worktree=../14/wt at root' '
1819        cat >14/expected <<EOF &&
1820setup: git_dir: $here/14.git
1821setup: worktree: $here/14/wt
1822setup: cwd: $here/14
1823setup: prefix: (null)
1824EOF
1825        git config --file="$here/14.git/config" core.worktree "$here/14/wt" &&
1826        test_repo 14 "$here/14/.git"
1827'
1828
1829test_expect_success '#14: GIT_DIR(rel), core.worktree=../14/wt in subdir' '
1830        cat >14/sub/sub/expected <<EOF &&
1831setup: git_dir: $here/14.git
1832setup: worktree: $here/14/wt
1833setup: cwd: $here/14/sub/sub
1834setup: prefix: (null)
1835EOF
1836        git config --file="$here/14.git/config" core.worktree "$here/14/wt" &&
1837        test_repo 14/sub/sub ../../.git
1838'
1839
1840test_expect_success '#14: GIT_DIR(rel), core.worktree=../14/wt(rel) in subdir' '
1841        cat >14/sub/sub/expected <<EOF &&
1842setup: git_dir: $here/14.git
1843setup: worktree: $here/14/wt
1844setup: cwd: $here/14/sub/sub
1845setup: prefix: (null)
1846EOF
1847        git config --file="$here/14.git/config" core.worktree ../14/wt &&
1848        test_repo 14/sub/sub ../../.git
1849'
1850
1851test_expect_success '#14: GIT_DIR, core.worktree=../14/wt(rel) in subdir' '
1852        cat >14/sub/sub/expected <<EOF &&
1853setup: git_dir: $here/14.git
1854setup: worktree: $here/14/wt
1855setup: cwd: $here/14/sub/sub
1856setup: prefix: (null)
1857EOF
1858        git config --file="$here/14.git/config" core.worktree ../14/wt &&
1859        test_repo 14/sub/sub "$here/14/.git"
1860'
1861
1862test_expect_success '#14: GIT_DIR, core.worktree=../14/wt in subdir' '
1863        cat >14/sub/sub/expected <<EOF &&
1864setup: git_dir: $here/14.git
1865setup: worktree: $here/14/wt
1866setup: cwd: $here/14/sub/sub
1867setup: prefix: (null)
1868EOF
1869        git config --file="$here/14.git/config" core.worktree "$here/14/wt" &&
1870        test_repo 14/sub/sub "$here/14/.git"
1871'
1872
1873test_expect_success '#14: GIT_DIR(rel), core.worktree=.. at root' '
1874        cat >14/expected <<EOF &&
1875setup: git_dir: $here/14.git
1876setup: worktree: $here
1877setup: cwd: $here
1878setup: prefix: 14/
1879EOF
1880        git config --file="$here/14.git/config" core.worktree "$here" &&
1881        test_repo 14 .git
1882'
1883
1884test_expect_success '#14: GIT_DIR(rel), core.worktree=..(rel) at root' '
1885        cat >14/expected <<EOF &&
1886setup: git_dir: $here/14.git
1887setup: worktree: $here
1888setup: cwd: $here
1889setup: prefix: 14/
1890EOF
1891        git config --file="$here/14.git/config" core.worktree .. &&
1892        test_repo 14 .git
1893'
1894
1895test_expect_success '#14: GIT_DIR, core.worktree=..(rel) at root' '
1896        cat >14/expected <<EOF &&
1897setup: git_dir: $here/14.git
1898setup: worktree: $here
1899setup: cwd: $here
1900setup: prefix: 14/
1901EOF
1902        git config --file="$here/14.git/config" core.worktree .. &&
1903        test_repo 14 "$here/14/.git"
1904'
1905
1906test_expect_success '#14: GIT_DIR, core.worktree=.. at root' '
1907        cat >14/expected <<EOF &&
1908setup: git_dir: $here/14.git
1909setup: worktree: $here
1910setup: cwd: $here
1911setup: prefix: 14/
1912EOF
1913        git config --file="$here/14.git/config" core.worktree "$here" &&
1914        test_repo 14 "$here/14/.git"
1915'
1916
1917test_expect_success '#14: GIT_DIR(rel), core.worktree=.. in subdir' '
1918        cat >14/sub/sub/expected <<EOF &&
1919setup: git_dir: $here/14.git
1920setup: worktree: $here
1921setup: cwd: $here
1922setup: prefix: 14/sub/sub/
1923EOF
1924        git config --file="$here/14.git/config" core.worktree "$here" &&
1925        test_repo 14/sub/sub ../../.git
1926'
1927
1928test_expect_success '#14: GIT_DIR(rel), core.worktree=..(rel) in subdir' '
1929        cat >14/sub/sub/expected <<EOF &&
1930setup: git_dir: $here/14.git
1931setup: worktree: $here
1932setup: cwd: $here
1933setup: prefix: 14/sub/sub/
1934EOF
1935        git config --file="$here/14.git/config" core.worktree .. &&
1936        test_repo 14/sub/sub ../../.git
1937'
1938
1939test_expect_success '#14: GIT_DIR, core.worktree=..(rel) in subdir' '
1940        cat >14/sub/sub/expected <<EOF &&
1941setup: git_dir: $here/14.git
1942setup: worktree: $here
1943setup: cwd: $here
1944setup: prefix: 14/sub/sub/
1945EOF
1946        git config --file="$here/14.git/config" core.worktree .. &&
1947        test_repo 14/sub/sub "$here/14/.git"
1948'
1949
1950test_expect_success '#14: GIT_DIR, core.worktree=.. in subdir' '
1951        cat >14/sub/sub/expected <<EOF &&
1952setup: git_dir: $here/14.git
1953setup: worktree: $here
1954setup: cwd: $here
1955setup: prefix: 14/sub/sub/
1956EOF
1957        git config --file="$here/14.git/config" core.worktree "$here" &&
1958        test_repo 14/sub/sub "$here/14/.git"
1959'
1960
1961#
1962# case #15
1963#
1964############################################################
1965#
1966# Input:
1967#
1968#  - GIT_WORK_TREE is set
1969#  - GIT_DIR is set
1970#  - core.worktree is set
1971#  - .git is a file
1972#  - core.bare is not set, cwd is outside .git
1973#
1974# Output:
1975#
1976# #7 except that git_dir is set by .git file
1977
1978test_expect_success '#15: setup' '
1979        sane_unset GIT_DIR GIT_WORK_TREE &&
1980        mkdir 15 15/sub 15/sub/sub 15.wt 15.wt/sub 15/wt 15/wt/sub &&
1981        cd 15 &&
1982        git init &&
1983        git config core.worktree non-existent &&
1984        mv .git ../15.git &&
1985        echo gitdir: ../15.git >.git &&
1986        cd ..
1987'
1988
1989test_expect_success '#15: GIT_DIR(rel), GIT_WORK_TREE=root at root' '
1990        cat >15/expected <<EOF &&
1991setup: git_dir: $here/15.git
1992setup: worktree: $here/15
1993setup: cwd: $here/15
1994setup: prefix: (null)
1995EOF
1996        test_repo 15 .git "$here/15"
1997'
1998
1999test_expect_success '#15: GIT_DIR(rel), GIT_WORK_TREE=root(rel) at root' '
2000        cat >15/expected <<EOF &&
2001setup: git_dir: $here/15.git
2002setup: worktree: $here/15
2003setup: cwd: $here/15
2004setup: prefix: (null)
2005EOF
2006        test_repo 15 .git .
2007'
2008
2009test_expect_success '#15: GIT_DIR, GIT_WORK_TREE=root at root' '
2010        cat >15/expected <<EOF &&
2011setup: git_dir: $here/15.git
2012setup: worktree: $here/15
2013setup: cwd: $here/15
2014setup: prefix: (null)
2015EOF
2016        test_repo 15 "$here/15/.git" "$here/15"
2017'
2018
2019test_expect_success '#15: GIT_DIR, GIT_WORK_TREE=root(rel) at root' '
2020        cat >15/expected <<EOF &&
2021setup: git_dir: $here/15.git
2022setup: worktree: $here/15
2023setup: cwd: $here/15
2024setup: prefix: (null)
2025EOF
2026        test_repo 15 "$here/15/.git" .
2027'
2028
2029test_expect_success '#15: GIT_DIR(rel), GIT_WORKTREE=root in subdir' '
2030        cat >15/sub/sub/expected <<EOF &&
2031setup: git_dir: $here/15.git
2032setup: worktree: $here/15
2033setup: cwd: $here/15
2034setup: prefix: sub/sub/
2035EOF
2036        test_repo 15/sub/sub ../../.git "$here/15"
2037'
2038
2039test_expect_success '#15: GIT_DIR(rel), GIT_WORKTREE=root(rel) in subdir' '
2040        cat >15/sub/sub/expected <<EOF &&
2041setup: git_dir: $here/15.git
2042setup: worktree: $here/15
2043setup: cwd: $here/15
2044setup: prefix: sub/sub/
2045EOF
2046        test_repo 15/sub/sub ../../.git ../..
2047'
2048
2049test_expect_success '#15: GIT_DIR, GIT_WORKTREE=root in subdir' '
2050        cat >15/sub/expected <<EOF &&
2051setup: git_dir: $here/15.git
2052setup: worktree: $here/15
2053setup: cwd: $here/15
2054setup: prefix: sub/
2055EOF
2056        test_repo 15/sub "$here/15/.git" "$here/15"
2057'
2058
2059test_expect_success '#15: GIT_DIR, GIT_WORKTREE=root(rel) in subdir' '
2060        cat >15/sub/sub/expected <<EOF &&
2061setup: git_dir: $here/15.git
2062setup: worktree: $here/15
2063setup: cwd: $here/15
2064setup: prefix: sub/sub/
2065EOF
2066        test_repo 15/sub/sub "$here/15/.git" ../..
2067'
2068
2069test_expect_success '#15: GIT_DIR(rel), GIT_WORK_TREE=wt at root' '
2070        cat >15/expected <<EOF &&
2071setup: git_dir: $here/15.git
2072setup: worktree: $here/15/wt
2073setup: cwd: $here/15
2074setup: prefix: (null)
2075EOF
2076        test_repo 15 .git "$here/15/wt"
2077'
2078
2079test_expect_success '#15: GIT_DIR(rel), GIT_WORK_TREE=wt(rel) at root' '
2080        cat >15/expected <<EOF &&
2081setup: git_dir: $here/15.git
2082setup: worktree: $here/15/wt
2083setup: cwd: $here/15
2084setup: prefix: (null)
2085EOF
2086        test_repo 15 .git wt
2087'
2088
2089test_expect_success '#15: GIT_DIR, GIT_WORK_TREE=wt(rel) at root' '
2090        cat >15/expected <<EOF &&
2091setup: git_dir: $here/15.git
2092setup: worktree: $here/15/wt
2093setup: cwd: $here/15
2094setup: prefix: (null)
2095EOF
2096        test_repo 15 "$here/15/.git" wt
2097'
2098
2099test_expect_success '#15: GIT_DIR, GIT_WORK_TREE=wt at root' '
2100        cat >15/expected <<EOF &&
2101setup: git_dir: $here/15.git
2102setup: worktree: $here/15/wt
2103setup: cwd: $here/15
2104setup: prefix: (null)
2105EOF
2106        test_repo 15 "$here/15/.git" "$here/15/wt"
2107'
2108
2109test_expect_success '#15: GIT_DIR(rel), GIT_WORK_TREE=wt in subdir' '
2110        cat >15/sub/sub/expected <<EOF &&
2111setup: git_dir: $here/15.git
2112setup: worktree: $here/15/wt
2113setup: cwd: $here/15/sub/sub
2114setup: prefix: (null)
2115EOF
2116        test_repo 15/sub/sub ../../.git "$here/15/wt"
2117'
2118
2119test_expect_success '#15: GIT_DIR(rel), GIT_WORK_TREE=wt(rel) in subdir' '
2120        cat >15/sub/sub/expected <<EOF &&
2121setup: git_dir: $here/15.git
2122setup: worktree: $here/15/wt
2123setup: cwd: $here/15/sub/sub
2124setup: prefix: (null)
2125EOF
2126        test_repo 15/sub/sub ../../.git ../../wt
2127'
2128
2129test_expect_success '#15: GIT_DIR, GIT_WORK_TREE=wt(rel) in subdir' '
2130        cat >15/sub/sub/expected <<EOF &&
2131setup: git_dir: $here/15.git
2132setup: worktree: $here/15/wt
2133setup: cwd: $here/15/sub/sub
2134setup: prefix: (null)
2135EOF
2136        test_repo 15/sub/sub "$here/15/.git" ../../wt
2137'
2138
2139test_expect_success '#15: GIT_DIR, GIT_WORK_TREE=wt in subdir' '
2140        cat >15/sub/sub/expected <<EOF &&
2141setup: git_dir: $here/15.git
2142setup: worktree: $here/15/wt
2143setup: cwd: $here/15/sub/sub
2144setup: prefix: (null)
2145EOF
2146        test_repo 15/sub/sub "$here/15/.git" "$here/15/wt"
2147'
2148
2149test_expect_success '#15: GIT_DIR(rel), GIT_WORK_TREE=.. at root' '
2150        cat >15/expected <<EOF &&
2151setup: git_dir: $here/15.git
2152setup: worktree: $here
2153setup: cwd: $here
2154setup: prefix: 15/
2155EOF
2156        test_repo 15 .git "$here"
2157'
2158
2159test_expect_success '#15: GIT_DIR(rel), GIT_WORK_TREE=..(rel) at root' '
2160        cat >15/expected <<EOF &&
2161setup: git_dir: $here/15.git
2162setup: worktree: $here
2163setup: cwd: $here
2164setup: prefix: 15/
2165EOF
2166        test_repo 15 .git ..
2167'
2168
2169test_expect_success '#15: GIT_DIR, GIT_WORK_TREE=..(rel) at root' '
2170        cat >15/expected <<EOF &&
2171setup: git_dir: $here/15.git
2172setup: worktree: $here
2173setup: cwd: $here
2174setup: prefix: 15/
2175EOF
2176        test_repo 15 "$here/15/.git" ..
2177'
2178
2179test_expect_success '#15: GIT_DIR, GIT_WORK_TREE=.. at root' '
2180        cat >15/expected <<EOF &&
2181setup: git_dir: $here/15.git
2182setup: worktree: $here
2183setup: cwd: $here
2184setup: prefix: 15/
2185EOF
2186        test_repo 15 "$here/15/.git" "$here"
2187'
2188
2189test_expect_success '#15: GIT_DIR(rel), GIT_WORK_TREE=.. in subdir' '
2190        cat >15/sub/sub/expected <<EOF &&
2191setup: git_dir: $here/15.git
2192setup: worktree: $here
2193setup: cwd: $here
2194setup: prefix: 15/sub/sub/
2195EOF
2196        test_repo 15/sub/sub ../../.git "$here"
2197'
2198
2199test_expect_success '#15: GIT_DIR(rel), GIT_WORK_TREE=..(rel) in subdir' '
2200        cat >15/sub/sub/expected <<EOF &&
2201setup: git_dir: $here/15.git
2202setup: worktree: $here
2203setup: cwd: $here
2204setup: prefix: 15/sub/sub/
2205EOF
2206        test_repo 15/sub/sub ../../.git ../../..
2207'
2208
2209test_expect_success '#15: GIT_DIR, GIT_WORK_TREE=..(rel) in subdir' '
2210        cat >15/sub/sub/expected <<EOF &&
2211setup: git_dir: $here/15.git
2212setup: worktree: $here
2213setup: cwd: $here
2214setup: prefix: 15/sub/sub/
2215EOF
2216        test_repo 15/sub/sub "$here/15/.git" ../../../
2217'
2218
2219test_expect_success '#15: GIT_DIR, GIT_WORK_TREE=.. in subdir' '
2220        cat >15/sub/sub/expected <<EOF &&
2221setup: git_dir: $here/15.git
2222setup: worktree: $here
2223setup: cwd: $here
2224setup: prefix: 15/sub/sub/
2225EOF
2226        test_repo 15/sub/sub "$here/15/.git" "$here"
2227'
2228
2229#
2230# case #16.1
2231#
2232############################################################
2233#
2234# Input:
2235#
2236#  - GIT_WORK_TREE is not set
2237#  - GIT_DIR is not set
2238#  - core.worktree is not set
2239#  - .git is a directory
2240#  - cwd is inside .git
2241#
2242# Output:
2243#
2244#  - no worktree
2245#  - cwd is unchanged
2246#  - prefix is NULL
2247#  - git_dir is set
2248#  - cwd can't be outside worktree
2249
2250test_expect_success '#16.1: setup' '
2251        sane_unset GIT_DIR GIT_WORK_TREE &&
2252        mkdir 16 16/sub &&
2253        cd 16 &&
2254        git init &&
2255        mkdir .git/wt .git/wt/sub &&
2256        cd ..
2257'
2258
2259test_expect_success '#16.1: at .git' '
2260        cat >16/.git/expected <<EOF &&
2261setup: git_dir: .
2262setup: worktree: (null)
2263setup: cwd: $here/16/.git
2264setup: prefix: (null)
2265EOF
2266        test_repo 16/.git
2267'
2268
2269test_expect_success '#16.1: in .git/wt' '
2270        cat >16/.git/wt/expected <<EOF &&
2271setup: git_dir: $here/16/.git
2272setup: worktree: (null)
2273setup: cwd: $here/16/.git/wt
2274setup: prefix: (null)
2275EOF
2276        test_repo 16/.git/wt
2277'
2278
2279test_expect_success '#16.1: in .git/wt/sub' '
2280        cat >16/.git/wt/sub/expected <<EOF &&
2281setup: git_dir: $here/16/.git
2282setup: worktree: (null)
2283setup: cwd: $here/16/.git/wt/sub
2284setup: prefix: (null)
2285EOF
2286        test_repo 16/.git/wt/sub
2287'
2288
2289#
2290# case #16.2
2291#
2292############################################################
2293#
2294# Input:
2295#
2296#  - GIT_WORK_TREE is not set
2297#  - GIT_DIR is not set
2298#  - core.worktree is not set
2299#  - .git is a directory
2300#  - core.bare is set
2301#
2302# Output:
2303#
2304#  - no worktree
2305#  - cwd is unchanged
2306#  - prefix is NULL
2307#  - git_dir is set
2308#  - cwd can't be outside worktree
2309
2310test_expect_success '#16.2: setup' '
2311        git config --file="$here/16/.git/config" core.bare true
2312'
2313
2314test_expect_success '#16.2: at .git' '
2315        cat >16/.git/expected <<EOF &&
2316setup: git_dir: .
2317setup: worktree: (null)
2318setup: cwd: $here/16/.git
2319setup: prefix: (null)
2320EOF
2321        test_repo 16/.git
2322'
2323
2324test_expect_success '#16.2: in .git/wt' '
2325        cat >16/.git/wt/expected <<EOF &&
2326setup: git_dir: $here/16/.git
2327setup: worktree: (null)
2328setup: cwd: $here/16/.git/wt
2329setup: prefix: (null)
2330EOF
2331        test_repo 16/.git/wt
2332'
2333
2334test_expect_success '#16.2: in .git/wt/sub' '
2335        cat >16/.git/wt/sub/expected <<EOF &&
2336setup: git_dir: $here/16/.git
2337setup: worktree: (null)
2338setup: cwd: $here/16/.git/wt/sub
2339setup: prefix: (null)
2340EOF
2341        test_repo 16/.git/wt/sub
2342'
2343
2344test_expect_success '#16.2: at root' '
2345        cat >16/expected <<EOF &&
2346setup: git_dir: .git
2347setup: worktree: (null)
2348setup: cwd: $here/16
2349setup: prefix: (null)
2350EOF
2351        test_repo 16
2352'
2353
2354test_expect_success '#16.2: in subdir' '
2355        cat >16/sub/expected <<EOF &&
2356setup: git_dir: $here/16/.git
2357setup: worktree: (null)
2358setup: cwd: $here/16/sub
2359setup: prefix: (null)
2360EOF
2361        test_repo 16/sub
2362'
2363
2364#
2365# case #17.1
2366#
2367############################################################
2368#
2369# Input:
2370#
2371#  - GIT_WORK_TREE is set
2372#  - GIT_DIR is not set
2373#  - core.worktree is not set
2374#  - .git is a directory
2375#  - cwd is inside .git
2376#
2377# Output:
2378#
2379# GIT_WORK_TREE is ignored -> #16.1 (with warnings perhaps)
2380
2381test_expect_success '#17.1: setup' '
2382        sane_unset GIT_DIR GIT_WORK_TREE &&
2383        mkdir 17 17/sub &&
2384        cd 17 &&
2385        git init &&
2386        mkdir .git/wt .git/wt/sub &&
2387        GIT_WORK_TREE=non-existent &&
2388        export GIT_WORK_TREE &&
2389        cd ..
2390'
2391
2392test_expect_success '#17.1: at .git' '
2393        cat >17/.git/expected <<EOF &&
2394setup: git_dir: .
2395setup: worktree: (null)
2396setup: cwd: $here/17/.git
2397setup: prefix: (null)
2398EOF
2399        test_repo 17/.git
2400'
2401
2402test_expect_success '#17.1: in .git/wt' '
2403        cat >17/.git/wt/expected <<EOF &&
2404setup: git_dir: $here/17/.git
2405setup: worktree: (null)
2406setup: cwd: $here/17/.git/wt
2407setup: prefix: (null)
2408EOF
2409        test_repo 17/.git/wt
2410'
2411
2412test_expect_success '#17.1: in .git/wt/sub' '
2413        cat >17/.git/wt/sub/expected <<EOF &&
2414setup: git_dir: $here/17/.git
2415setup: worktree: (null)
2416setup: cwd: $here/17/.git/wt/sub
2417setup: prefix: (null)
2418EOF
2419        test_repo 17/.git/wt/sub
2420'
2421
2422#
2423# case #17.2
2424#
2425############################################################
2426#
2427# Input:
2428#
2429#  - GIT_WORK_TREE is set
2430#  - GIT_DIR is not set
2431#  - core.worktree is not set
2432#  - .git is a directory
2433#  - core.bare is set
2434#
2435# Output:
2436#
2437# GIT_WORK_TREE is ignored -> #16.2 (with warnings perhaps)
2438
2439test_expect_success '#17.2: setup' '
2440        git config --file="$here/17/.git/config" core.bare true
2441'
2442
2443test_expect_success '#17.2: at .git' '
2444        cat >17/.git/expected <<EOF &&
2445setup: git_dir: .
2446setup: worktree: (null)
2447setup: cwd: $here/17/.git
2448setup: prefix: (null)
2449EOF
2450        test_repo 17/.git
2451'
2452
2453test_expect_success '#17.2: in .git/wt' '
2454        cat >17/.git/wt/expected <<EOF &&
2455setup: git_dir: $here/17/.git
2456setup: worktree: (null)
2457setup: cwd: $here/17/.git/wt
2458setup: prefix: (null)
2459EOF
2460        test_repo 17/.git/wt
2461'
2462
2463test_expect_success '#17.2: in .git/wt/sub' '
2464        cat >17/.git/wt/sub/expected <<EOF &&
2465setup: git_dir: $here/17/.git
2466setup: worktree: (null)
2467setup: cwd: $here/17/.git/wt/sub
2468setup: prefix: (null)
2469EOF
2470        test_repo 17/.git/wt/sub
2471'
2472
2473test_expect_success '#17.2: at root' '
2474        cat >17/expected <<EOF &&
2475setup: git_dir: .git
2476setup: worktree: (null)
2477setup: cwd: $here/17
2478setup: prefix: (null)
2479EOF
2480        test_repo 17
2481'
2482
2483test_expect_success '#17.2: in subdir' '
2484        cat >17/sub/expected <<EOF &&
2485setup: git_dir: $here/17/.git
2486setup: worktree: (null)
2487setup: cwd: $here/17/sub
2488setup: prefix: (null)
2489EOF
2490        test_repo 17/sub
2491'
2492
2493#
2494# case #18
2495#
2496############################################################
2497#
2498# Input:
2499#
2500#  - GIT_WORK_TREE is not set
2501#  - GIT_DIR is set
2502#  - core.worktree is not set
2503#  - .git is a directory
2504#  - core.bare is set
2505#
2506# Output:
2507#
2508#  - no worktree (rule #8)
2509#  - cwd is unchanged
2510#  - prefix is NULL
2511#  - git_dir is set to $GIT_DIR
2512#  - cwd can't be outside worktree
2513
2514test_expect_success '#18: setup' '
2515        sane_unset GIT_DIR GIT_WORK_TREE &&
2516        mkdir 18 18/sub &&
2517        cd 18 &&
2518        git init &&
2519        mkdir .git/wt .git/wt/sub &&
2520        git config core.bare true &&
2521        cd ..
2522'
2523
2524test_expect_success '#18: (rel) at root' '
2525        cat >18/expected <<EOF &&
2526setup: git_dir: .git
2527setup: worktree: (null)
2528setup: cwd: $here/18
2529setup: prefix: (null)
2530EOF
2531         test_repo 18 .git
2532'
2533
2534test_expect_success '#18: at root' '
2535        cat >18/expected <<EOF &&
2536setup: git_dir: $here/18/.git
2537setup: worktree: (null)
2538setup: cwd: $here/18
2539setup: prefix: (null)
2540EOF
2541         test_repo 18 "$here/18/.git"
2542'
2543
2544test_expect_success '#18: (rel) in subdir' '
2545        cat >18/sub/expected <<EOF &&
2546setup: git_dir: ../.git
2547setup: worktree: (null)
2548setup: cwd: $here/18/sub
2549setup: prefix: (null)
2550EOF
2551        test_repo 18/sub ../.git
2552'
2553
2554test_expect_success '#18: in subdir' '
2555        cat >18/sub/expected <<EOF &&
2556setup: git_dir: $here/18/.git
2557setup: worktree: (null)
2558setup: cwd: $here/18/sub
2559setup: prefix: (null)
2560EOF
2561        test_repo 18/sub "$here/18/.git"
2562'
2563
2564#
2565# case #19
2566#
2567############################################################
2568#
2569# Input:
2570#
2571#  - GIT_WORK_TREE is set
2572#  - GIT_DIR is set
2573#  - .git is a directory
2574#  - core.worktree is not set
2575#  - core.bare is set
2576#
2577# Output:
2578#
2579# bare repo is overridden by GIT_WORK_TREE -> #3
2580
2581test_expect_success '#19: setup' '
2582        sane_unset GIT_DIR GIT_WORK_TREE &&
2583        mkdir 19 19/sub 19/sub/sub 19.wt 19.wt/sub 19/wt 19/wt/sub &&
2584        cd 19 &&
2585        git init &&
2586        git config core.bare true &&
2587        cd ..
2588'
2589
2590test_expect_success '#19: GIT_DIR(rel), GIT_WORK_TREE=root at root' '
2591        cat >19/expected <<EOF &&
2592setup: git_dir: .git
2593setup: worktree: $here/19
2594setup: cwd: $here/19
2595setup: prefix: (null)
2596EOF
2597        test_repo 19 .git "$here/19"
2598'
2599
2600test_expect_success '#19: GIT_DIR(rel), GIT_WORK_TREE=root(rel) at root' '
2601        cat >19/expected <<EOF &&
2602setup: git_dir: .git
2603setup: worktree: $here/19
2604setup: cwd: $here/19
2605setup: prefix: (null)
2606EOF
2607        test_repo 19 .git .
2608'
2609
2610test_expect_success '#19: GIT_DIR, GIT_WORK_TREE=root at root' '
2611        cat >19/expected <<EOF &&
2612setup: git_dir: $here/19/.git
2613setup: worktree: $here/19
2614setup: cwd: $here/19
2615setup: prefix: (null)
2616EOF
2617        test_repo 19 "$here/19/.git" "$here/19"
2618'
2619
2620test_expect_success '#19: GIT_DIR, GIT_WORK_TREE=root(rel) at root' '
2621        cat >19/expected <<EOF &&
2622setup: git_dir: $here/19/.git
2623setup: worktree: $here/19
2624setup: cwd: $here/19
2625setup: prefix: (null)
2626EOF
2627        test_repo 19 "$here/19/.git" .
2628'
2629
2630test_expect_success '#19: GIT_DIR(rel), GIT_WORKTREE=root in subdir' '
2631        cat >19/sub/sub/expected <<EOF &&
2632setup: git_dir: $here/19/.git
2633setup: worktree: $here/19
2634setup: cwd: $here/19
2635setup: prefix: sub/sub/
2636EOF
2637        test_repo 19/sub/sub ../../.git "$here/19"
2638'
2639
2640test_expect_success '#19: GIT_DIR(rel), GIT_WORKTREE=root(rel) in subdir' '
2641        cat >19/sub/sub/expected <<EOF &&
2642setup: git_dir: $here/19/.git
2643setup: worktree: $here/19
2644setup: cwd: $here/19
2645setup: prefix: sub/sub/
2646EOF
2647        test_repo 19/sub/sub ../../.git ../..
2648'
2649
2650test_expect_success '#19: GIT_DIR, GIT_WORKTREE=root in subdir' '
2651        cat >19/sub/expected <<EOF &&
2652setup: git_dir: $here/19/.git
2653setup: worktree: $here/19
2654setup: cwd: $here/19
2655setup: prefix: sub/
2656EOF
2657        test_repo 19/sub "$here/19/.git" "$here/19"
2658'
2659
2660test_expect_success '#19: GIT_DIR, GIT_WORKTREE=root(rel) in subdir' '
2661        cat >19/sub/sub/expected <<EOF &&
2662setup: git_dir: $here/19/.git
2663setup: worktree: $here/19
2664setup: cwd: $here/19
2665setup: prefix: sub/sub/
2666EOF
2667        test_repo 19/sub/sub "$here/19/.git" ../..
2668'
2669
2670test_expect_success '#19: GIT_DIR(rel), GIT_WORK_TREE=wt at root' '
2671        cat >19/expected <<EOF &&
2672setup: git_dir: .git
2673setup: worktree: $here/19/wt
2674setup: cwd: $here/19
2675setup: prefix: (null)
2676EOF
2677        test_repo 19 .git "$here/19/wt"
2678'
2679
2680test_expect_success '#19: GIT_DIR(rel), GIT_WORK_TREE=wt(rel) at root' '
2681        cat >19/expected <<EOF &&
2682setup: git_dir: .git
2683setup: worktree: $here/19/wt
2684setup: cwd: $here/19
2685setup: prefix: (null)
2686EOF
2687        test_repo 19 .git wt
2688'
2689
2690test_expect_success '#19: GIT_DIR, GIT_WORK_TREE=wt(rel) at root' '
2691        cat >19/expected <<EOF &&
2692setup: git_dir: $here/19/.git
2693setup: worktree: $here/19/wt
2694setup: cwd: $here/19
2695setup: prefix: (null)
2696EOF
2697        test_repo 19 "$here/19/.git" wt
2698'
2699
2700test_expect_success '#19: GIT_DIR, GIT_WORK_TREE=wt at root' '
2701        cat >19/expected <<EOF &&
2702setup: git_dir: $here/19/.git
2703setup: worktree: $here/19/wt
2704setup: cwd: $here/19
2705setup: prefix: (null)
2706EOF
2707        test_repo 19 "$here/19/.git" "$here/19/wt"
2708'
2709
2710test_expect_success '#19: GIT_DIR(rel), GIT_WORK_TREE=wt in subdir' '
2711        cat >19/sub/sub/expected <<EOF &&
2712setup: git_dir: ../../.git
2713setup: worktree: $here/19/wt
2714setup: cwd: $here/19/sub/sub
2715setup: prefix: (null)
2716EOF
2717        test_repo 19/sub/sub ../../.git "$here/19/wt"
2718'
2719
2720test_expect_success '#19: GIT_DIR(rel), GIT_WORK_TREE=wt(rel) in subdir' '
2721        cat >19/sub/sub/expected <<EOF &&
2722setup: git_dir: ../../.git
2723setup: worktree: $here/19/wt
2724setup: cwd: $here/19/sub/sub
2725setup: prefix: (null)
2726EOF
2727        test_repo 19/sub/sub ../../.git ../../wt
2728'
2729
2730test_expect_success '#19: GIT_DIR, GIT_WORK_TREE=wt(rel) in subdir' '
2731        cat >19/sub/sub/expected <<EOF &&
2732setup: git_dir: $here/19/.git
2733setup: worktree: $here/19/wt
2734setup: cwd: $here/19/sub/sub
2735setup: prefix: (null)
2736EOF
2737        test_repo 19/sub/sub "$here/19/.git" ../../wt
2738'
2739
2740test_expect_success '#19: GIT_DIR, GIT_WORK_TREE=wt in subdir' '
2741        cat >19/sub/sub/expected <<EOF &&
2742setup: git_dir: $here/19/.git
2743setup: worktree: $here/19/wt
2744setup: cwd: $here/19/sub/sub
2745setup: prefix: (null)
2746EOF
2747        test_repo 19/sub/sub "$here/19/.git" "$here/19/wt"
2748'
2749
2750test_expect_success '#19: GIT_DIR(rel), GIT_WORK_TREE=.. at root' '
2751        cat >19/expected <<EOF &&
2752setup: git_dir: $here/19/.git
2753setup: worktree: $here
2754setup: cwd: $here
2755setup: prefix: 19/
2756EOF
2757        test_repo 19 .git "$here"
2758'
2759
2760test_expect_success '#19: GIT_DIR(rel), GIT_WORK_TREE=..(rel) at root' '
2761        cat >19/expected <<EOF &&
2762setup: git_dir: $here/19/.git
2763setup: worktree: $here
2764setup: cwd: $here
2765setup: prefix: 19/
2766EOF
2767        test_repo 19 .git ..
2768'
2769
2770test_expect_success '#19: GIT_DIR, GIT_WORK_TREE=..(rel) at root' '
2771        cat >19/expected <<EOF &&
2772setup: git_dir: $here/19/.git
2773setup: worktree: $here
2774setup: cwd: $here
2775setup: prefix: 19/
2776EOF
2777        test_repo 19 "$here/19/.git" ..
2778'
2779
2780test_expect_success '#19: GIT_DIR, GIT_WORK_TREE=.. at root' '
2781        cat >19/expected <<EOF &&
2782setup: git_dir: $here/19/.git
2783setup: worktree: $here
2784setup: cwd: $here
2785setup: prefix: 19/
2786EOF
2787        test_repo 19 "$here/19/.git" "$here"
2788'
2789
2790test_expect_success '#19: GIT_DIR(rel), GIT_WORK_TREE=.. in subdir' '
2791        cat >19/sub/sub/expected <<EOF &&
2792setup: git_dir: $here/19/.git
2793setup: worktree: $here
2794setup: cwd: $here
2795setup: prefix: 19/sub/sub/
2796EOF
2797        test_repo 19/sub/sub ../../.git "$here"
2798'
2799
2800test_expect_success '#19: GIT_DIR(rel), GIT_WORK_TREE=..(rel) in subdir' '
2801        cat >19/sub/sub/expected <<EOF &&
2802setup: git_dir: $here/19/.git
2803setup: worktree: $here
2804setup: cwd: $here
2805setup: prefix: 19/sub/sub/
2806EOF
2807        test_repo 19/sub/sub ../../.git ../../..
2808'
2809
2810test_expect_success '#19: GIT_DIR, GIT_WORK_TREE=..(rel) in subdir' '
2811        cat >19/sub/sub/expected <<EOF &&
2812setup: git_dir: $here/19/.git
2813setup: worktree: $here
2814setup: cwd: $here
2815setup: prefix: 19/sub/sub/
2816EOF
2817        test_repo 19/sub/sub "$here/19/.git" ../../../
2818'
2819
2820test_expect_success '#19: GIT_DIR, GIT_WORK_TREE=.. in subdir' '
2821        cat >19/sub/sub/expected <<EOF &&
2822setup: git_dir: $here/19/.git
2823setup: worktree: $here
2824setup: cwd: $here
2825setup: prefix: 19/sub/sub/
2826EOF
2827        test_repo 19/sub/sub "$here/19/.git" "$here"
2828'
2829
2830#
2831# case #20.1
2832#
2833############################################################
2834#
2835# Input:
2836#
2837#  - GIT_WORK_TREE is not set
2838#  - GIT_DIR is not set
2839#  - core.worktree is set
2840#  - .git is a directory
2841#  - cwd is inside .git
2842#
2843# Output:
2844#
2845# core.worktree is ignored -> #16.1
2846
2847test_expect_success '#20.1: setup' '
2848        sane_unset GIT_DIR GIT_WORK_TREE &&
2849        mkdir 20 20/sub &&
2850        cd 20 &&
2851        git init &&
2852        git config core.worktree non-existent &&
2853        mkdir .git/wt .git/wt/sub &&
2854        cd ..
2855'
2856
2857test_expect_success '#20.1: at .git' '
2858        cat >20/.git/expected <<EOF &&
2859setup: git_dir: .
2860setup: worktree: (null)
2861setup: cwd: $here/20/.git
2862setup: prefix: (null)
2863EOF
2864        test_repo 20/.git
2865'
2866
2867test_expect_success '#20.1: in .git/wt' '
2868        cat >20/.git/wt/expected <<EOF &&
2869setup: git_dir: $here/20/.git
2870setup: worktree: (null)
2871setup: cwd: $here/20/.git/wt
2872setup: prefix: (null)
2873EOF
2874        test_repo 20/.git/wt
2875'
2876
2877test_expect_success '#20.1: in .git/wt/sub' '
2878        cat >20/.git/wt/sub/expected <<EOF &&
2879setup: git_dir: $here/20/.git
2880setup: worktree: (null)
2881setup: cwd: $here/20/.git/wt/sub
2882setup: prefix: (null)
2883EOF
2884        test_repo 20/.git/wt/sub
2885'
2886
2887#
2888# case #20.2
2889#
2890############################################################
2891#
2892# Input:
2893#
2894#  - GIT_WORK_TREE is not set
2895#  - GIT_DIR is not set
2896#  - core.worktree is set
2897#  - .git is a directory
2898#  - core.bare is set
2899#
2900# Output:
2901#
2902# core.worktree is ignored -> #16.2
2903
2904test_expect_success '#20.2: setup' '
2905        git config --file="$here/20/.git/config" core.bare true
2906'
2907
2908test_expect_success '#20.2: at .git' '
2909        cat >20/.git/expected <<EOF &&
2910setup: git_dir: .
2911setup: worktree: (null)
2912setup: cwd: $here/20/.git
2913setup: prefix: (null)
2914EOF
2915        test_repo 20/.git
2916'
2917
2918test_expect_success '#20.2: in .git/wt' '
2919        cat >20/.git/wt/expected <<EOF &&
2920setup: git_dir: $here/20/.git
2921setup: worktree: (null)
2922setup: cwd: $here/20/.git/wt
2923setup: prefix: (null)
2924EOF
2925        test_repo 20/.git/wt
2926'
2927
2928test_expect_success '#20.2: in .git/wt/sub' '
2929        cat >20/.git/wt/sub/expected <<EOF &&
2930setup: git_dir: $here/20/.git
2931setup: worktree: (null)
2932setup: cwd: $here/20/.git/wt/sub
2933setup: prefix: (null)
2934EOF
2935        test_repo 20/.git/wt/sub
2936'
2937
2938test_expect_success '#20.2: at root' '
2939        cat >20/expected <<EOF &&
2940setup: git_dir: .git
2941setup: worktree: (null)
2942setup: cwd: $here/20
2943setup: prefix: (null)
2944EOF
2945        test_repo 20
2946'
2947
2948test_expect_success '#20.2: in subdir' '
2949        cat >20/sub/expected <<EOF &&
2950setup: git_dir: $here/20/.git
2951setup: worktree: (null)
2952setup: cwd: $here/20/sub
2953setup: prefix: (null)
2954EOF
2955        test_repo 20/sub
2956'
2957
2958#
2959# case #21.1
2960#
2961############################################################
2962#
2963# Input:
2964#
2965#  - GIT_WORK_TREE is set
2966#  - GIT_DIR is not set
2967#  - core.worktree is set
2968#  - .git is a directory
2969#  - cwd is inside .git
2970#
2971# Output:
2972#
2973# GIT_WORK_TREE/core.worktree are ignored -> #20.1
2974
2975test_expect_success '#21.1: setup' '
2976        sane_unset GIT_DIR GIT_WORK_TREE &&
2977        mkdir 21 21/sub &&
2978        cd 21 &&
2979        git init &&
2980        git config core.worktree non-existent &&
2981        GIT_WORK_TREE=non-existent-too &&
2982        export GIT_WORK_TREE &&
2983        mkdir .git/wt .git/wt/sub &&
2984        cd ..
2985'
2986
2987test_expect_success '#21.1: at .git' '
2988        cat >21/.git/expected <<EOF &&
2989setup: git_dir: .
2990setup: worktree: (null)
2991setup: cwd: $here/21/.git
2992setup: prefix: (null)
2993EOF
2994        test_repo 21/.git
2995'
2996
2997test_expect_success '#21.1: in .git/wt' '
2998        cat >21/.git/wt/expected <<EOF &&
2999setup: git_dir: $here/21/.git
3000setup: worktree: (null)
3001setup: cwd: $here/21/.git/wt
3002setup: prefix: (null)
3003EOF
3004        test_repo 21/.git/wt
3005'
3006
3007test_expect_success '#21.1: in .git/wt/sub' '
3008        cat >21/.git/wt/sub/expected <<EOF &&
3009setup: git_dir: $here/21/.git
3010setup: worktree: (null)
3011setup: cwd: $here/21/.git/wt/sub
3012setup: prefix: (null)
3013EOF
3014        test_repo 21/.git/wt/sub
3015'
3016
3017#
3018# case #21.2
3019#
3020############################################################
3021#
3022# Input:
3023#
3024#  - GIT_WORK_TREE is set
3025#  - GIT_DIR is not set
3026#  - core.worktree is set
3027#  - .git is a directory
3028#  - core.bare is set
3029#
3030# Output:
3031#
3032# GIT_WORK_TREE/core.worktree are ignored -> #20.2
3033
3034test_expect_success '#21.2: setup' '
3035        git config --file="$here/21/.git/config" core.bare true
3036'
3037
3038test_expect_success '#21.2: at .git' '
3039        cat >21/.git/expected <<EOF &&
3040setup: git_dir: .
3041setup: worktree: (null)
3042setup: cwd: $here/21/.git
3043setup: prefix: (null)
3044EOF
3045        test_repo 21/.git
3046'
3047
3048test_expect_success '#21.2: in .git/wt' '
3049        cat >21/.git/wt/expected <<EOF &&
3050setup: git_dir: $here/21/.git
3051setup: worktree: (null)
3052setup: cwd: $here/21/.git/wt
3053setup: prefix: (null)
3054EOF
3055        test_repo 21/.git/wt
3056'
3057
3058test_expect_success '#21.2: in .git/wt/sub' '
3059        cat >21/.git/wt/sub/expected <<EOF &&
3060setup: git_dir: $here/21/.git
3061setup: worktree: (null)
3062setup: cwd: $here/21/.git/wt/sub
3063setup: prefix: (null)
3064EOF
3065        test_repo 21/.git/wt/sub
3066'
3067
3068test_expect_success '#21.2: at root' '
3069        cat >21/expected <<EOF &&
3070setup: git_dir: .git
3071setup: worktree: (null)
3072setup: cwd: $here/21
3073setup: prefix: (null)
3074EOF
3075        test_repo 21
3076'
3077
3078test_expect_success '#21.2: in subdir' '
3079        cat >21/sub/expected <<EOF &&
3080setup: git_dir: $here/21/.git
3081setup: worktree: (null)
3082setup: cwd: $here/21/sub
3083setup: prefix: (null)
3084EOF
3085        test_repo 21/sub
3086'
3087
3088#
3089# case #22.1
3090#
3091############################################################
3092#
3093# Input:
3094#
3095#  - GIT_WORK_TREE is not set
3096#  - GIT_DIR is set
3097#  - core.worktree is set
3098#  - .git is a directory
3099#  - cwd is inside .git
3100#
3101# Output:
3102#
3103# bare attribute is ignored
3104#
3105#  - worktree is at core.worktree
3106#  - cwd is at worktree root
3107#  - prefix is calculated
3108#  - git_dir is at $GIT_DIR
3109#  - cwd can be outside worktree
3110
3111test_expect_success '#22.1: setup' '
3112        sane_unset GIT_DIR GIT_WORK_TREE &&
3113        mkdir 22 &&
3114        cd 22 &&
3115        git init &&
3116        mkdir .git/sub .git/wt .git/wt/sub &&
3117        cd ..
3118'
3119
3120test_expect_success '#22.1: GIT_DIR(rel), core.worktree=. at .git' '
3121        cat >22/.git/expected <<EOF &&
3122setup: git_dir: .
3123setup: worktree: $here/22/.git
3124setup: cwd: $here/22/.git
3125setup: prefix: (null)
3126EOF
3127        git config --file="$here/22/.git/config" core.worktree "$here/22/.git" &&
3128        test_repo 22/.git .
3129'
3130
3131test_expect_success '#22.1: GIT_DIR(rel), core.worktree=.(rel) at .git' '
3132        cat >22/.git/expected <<EOF &&
3133setup: git_dir: .
3134setup: worktree: $here/22/.git
3135setup: cwd: $here/22/.git
3136setup: prefix: (null)
3137EOF
3138        git config --file="$here/22/.git/config" core.worktree . &&
3139        test_repo 22/.git .
3140'
3141
3142test_expect_success '#22.1: GIT_DIR, core.worktree=. at .git' '
3143        cat >22/.git/expected <<EOF &&
3144setup: git_dir: $here/22/.git
3145setup: worktree: $here/22/.git
3146setup: cwd: $here/22/.git
3147setup: prefix: (null)
3148EOF
3149        git config --file="$here/22/.git/config" core.worktree "$here/22/.git" &&
3150        test_repo 22/.git "$here/22/.git"
3151'
3152
3153test_expect_success '#22.1: GIT_DIR, core.worktree=.(rel) at root' '
3154        cat >22/.git/expected <<EOF &&
3155setup: git_dir: $here/22/.git
3156setup: worktree: $here/22/.git
3157setup: cwd: $here/22/.git
3158setup: prefix: (null)
3159EOF
3160        git config --file="$here/22/.git/config" core.worktree . &&
3161        test_repo 22/.git "$here/22/.git"
3162'
3163
3164test_expect_success '#22.1: GIT_DIR(rel), core.worktree=. in .git/sub' '
3165        cat >22/.git/sub/expected <<EOF &&
3166setup: git_dir: $here/22/.git
3167setup: worktree: $here/22/.git
3168setup: cwd: $here/22/.git
3169setup: prefix: sub/
3170EOF
3171        git config --file="$here/22/.git/config" core.worktree "$here/22/.git" &&
3172        test_repo 22/.git/sub ..
3173'
3174
3175test_expect_success '#22.1: GIT_DIR(rel), core.worktree=.(rel) in .git/sub' '
3176        cat >22/.git/sub/expected <<EOF &&
3177setup: git_dir: $here/22/.git
3178setup: worktree: $here/22/.git
3179setup: cwd: $here/22/.git
3180setup: prefix: sub/
3181EOF
3182        git config --file="$here/22/.git/config" core.worktree . &&
3183        test_repo 22/.git/sub/ ..
3184'
3185
3186test_expect_success '#22.1: GIT_DIR, core.worktree=. in .git/sub' '
3187        cat >22/.git/sub/expected <<EOF &&
3188setup: git_dir: $here/22/.git
3189setup: worktree: $here/22/.git
3190setup: cwd: $here/22/.git
3191setup: prefix: sub/
3192EOF
3193        git config --file="$here/22/.git/config" core.worktree "$here/22/.git" &&
3194        test_repo 22/.git/sub "$here/22/.git"
3195'
3196
3197test_expect_success '#22.1: GIT_DIR, core.worktree=.(rel) in .git/sub' '
3198        cat >22/.git/sub/expected <<EOF &&
3199setup: git_dir: $here/22/.git
3200setup: worktree: $here/22/.git
3201setup: cwd: $here/22/.git
3202setup: prefix: sub/
3203EOF
3204        git config --file="$here/22/.git/config" core.worktree . &&
3205        test_repo 22/.git/sub "$here/22/.git"
3206'
3207
3208test_expect_success '#22.1: GIT_DIR(rel), core.worktree=wt at .git' '
3209        cat >22/.git/expected <<EOF &&
3210setup: git_dir: .
3211setup: worktree: $here/22/.git/wt
3212setup: cwd: $here/22/.git
3213setup: prefix: (null)
3214EOF
3215        git config --file="$here/22/.git/config" core.worktree "$here/22/.git/wt" &&
3216        test_repo 22/.git .
3217'
3218
3219test_expect_success '#22.1: GIT_DIR(rel), core.worktree=wt(rel) at .git' '
3220        cat >22/.git/expected <<EOF &&
3221setup: git_dir: .
3222setup: worktree: $here/22/.git/wt
3223setup: cwd: $here/22/.git
3224setup: prefix: (null)
3225EOF
3226        git config --file="$here/22/.git/config" core.worktree wt &&
3227        test_repo 22/.git .
3228'
3229
3230test_expect_success '#22.1: GIT_DIR, core.worktree=wt(rel) at .git' '
3231        cat >22/.git/expected <<EOF &&
3232setup: git_dir: $here/22/.git
3233setup: worktree: $here/22/.git/wt
3234setup: cwd: $here/22/.git
3235setup: prefix: (null)
3236EOF
3237        git config --file="$here/22/.git/config" core.worktree wt &&
3238        test_repo 22/.git "$here/22/.git"
3239'
3240
3241test_expect_success '#22.1: GIT_DIR, core.worktree=wt at .git' '
3242        cat >22/.git/expected <<EOF &&
3243setup: git_dir: $here/22/.git
3244setup: worktree: $here/22/.git/wt
3245setup: cwd: $here/22/.git
3246setup: prefix: (null)
3247EOF
3248        git config --file="$here/22/.git/config" core.worktree "$here/22/.git/wt" &&
3249        test_repo 22/.git "$here/22/.git"
3250'
3251
3252test_expect_success '#22.1: GIT_DIR(rel), core.worktree=wt in .git/sub' '
3253        cat >22/.git/sub/expected <<EOF &&
3254setup: git_dir: ..
3255setup: worktree: $here/22/.git/wt
3256setup: cwd: $here/22/.git/sub
3257setup: prefix: (null)
3258EOF
3259        git config --file="$here/22/.git/config" core.worktree "$here/22/.git/wt" &&
3260        test_repo 22/.git/sub ..
3261'
3262
3263test_expect_success '#22.1: GIT_DIR(rel), core.worktree=wt(rel) in .git/sub' '
3264        cat >22/.git/sub/expected <<EOF &&
3265setup: git_dir: ..
3266setup: worktree: $here/22/.git/wt
3267setup: cwd: $here/22/.git/sub
3268setup: prefix: (null)
3269EOF
3270        git config --file="$here/22/.git/config" core.worktree wt &&
3271        test_repo 22/.git/sub ..
3272'
3273
3274test_expect_success '#22.1: GIT_DIR, core.worktree=wt(rel) in .git/sub' '
3275        cat >22/.git/sub/expected <<EOF &&
3276setup: git_dir: $here/22/.git
3277setup: worktree: $here/22/.git/wt
3278setup: cwd: $here/22/.git/sub
3279setup: prefix: (null)
3280EOF
3281        git config --file="$here/22/.git/config" core.worktree wt &&
3282        test_repo 22/.git/sub "$here/22/.git"
3283'
3284
3285test_expect_success '#22.1: GIT_DIR, core.worktree=wt in .git/sub' '
3286        cat >22/.git/sub/expected <<EOF &&
3287setup: git_dir: $here/22/.git
3288setup: worktree: $here/22/.git/wt
3289setup: cwd: $here/22/.git/sub
3290setup: prefix: (null)
3291EOF
3292        git config --file="$here/22/.git/config" core.worktree "$here/22/.git/wt" &&
3293        test_repo 22/.git/sub "$here/22/.git"
3294'
3295
3296test_expect_success '#22.1: GIT_DIR(rel), core.worktree=.. at .git' '
3297        cat >22/.git/expected <<EOF &&
3298setup: git_dir: $here/22/.git
3299setup: worktree: $here/22
3300setup: cwd: $here/22
3301setup: prefix: .git/
3302EOF
3303        git config --file="$here/22/.git/config" core.worktree "$here/22" &&
3304        test_repo 22/.git .
3305'
3306
3307test_expect_success '#22.1: GIT_DIR(rel), core.worktree=..(rel) at .git' '
3308        cat >22/.git/expected <<EOF &&
3309setup: git_dir: $here/22/.git
3310setup: worktree: $here/22
3311setup: cwd: $here/22
3312setup: prefix: .git/
3313EOF
3314        git config --file="$here/22/.git/config" core.worktree .. &&
3315        test_repo 22/.git .
3316'
3317
3318test_expect_success '#22.1: GIT_DIR, core.worktree=..(rel) at .git' '
3319        cat >22/.git/expected <<EOF &&
3320setup: git_dir: $here/22/.git
3321setup: worktree: $here/22
3322setup: cwd: $here/22
3323setup: prefix: .git/
3324EOF
3325        git config --file="$here/22/.git/config" core.worktree .. &&
3326        test_repo 22/.git "$here/22/.git"
3327'
3328
3329test_expect_success '#22.1: GIT_DIR, core.worktree=.. at .git' '
3330        cat >22/.git/expected <<EOF &&
3331setup: git_dir: $here/22/.git
3332setup: worktree: $here/22
3333setup: cwd: $here/22
3334setup: prefix: .git/
3335EOF
3336        git config --file="$here/22/.git/config" core.worktree "$here/22" &&
3337        test_repo 22/.git "$here/22/.git"
3338'
3339
3340test_expect_success '#22.1: GIT_DIR(rel), core.worktree=.. in .git/sub' '
3341        cat >22/.git/sub/expected <<EOF &&
3342setup: git_dir: $here/22/.git
3343setup: worktree: $here/22
3344setup: cwd: $here/22
3345setup: prefix: .git/sub/
3346EOF
3347        git config --file="$here/22/.git/config" core.worktree "$here/22" &&
3348        test_repo 22/.git/sub ..
3349'
3350
3351test_expect_success '#22.1: GIT_DIR(rel), core.worktree=..(rel) in .git/sub' '
3352        cat >22/.git/sub/expected <<EOF &&
3353setup: git_dir: $here/22/.git
3354setup: worktree: $here/22
3355setup: cwd: $here/22
3356setup: prefix: .git/sub/
3357EOF
3358        git config --file="$here/22/.git/config" core.worktree .. &&
3359        test_repo 22/.git/sub ..
3360'
3361
3362test_expect_success '#22.1: GIT_DIR, core.worktree=..(rel) in .git/sub' '
3363        cat >22/.git/sub/expected <<EOF &&
3364setup: git_dir: $here/22/.git
3365setup: worktree: $here/22
3366setup: cwd: $here/22
3367setup: prefix: .git/sub/
3368EOF
3369        git config --file="$here/22/.git/config" core.worktree .. &&
3370        test_repo 22/.git/sub "$here/22/.git"
3371'
3372
3373test_expect_success '#22.1: GIT_DIR, core.worktree=.. in .git/sub' '
3374        cat >22/.git/sub/expected <<EOF &&
3375setup: git_dir: $here/22/.git
3376setup: worktree: $here/22
3377setup: cwd: $here/22
3378setup: prefix: .git/sub/
3379EOF
3380        git config --file="$here/22/.git/config" core.worktree "$here/22" &&
3381        test_repo 22/.git/sub "$here/22/.git"
3382'
3383
3384#
3385# case #22.2
3386#
3387############################################################
3388#
3389# Input:
3390#
3391#  - GIT_WORK_TREE is not set
3392#  - GIT_DIR is set
3393#  - core.worktree is set
3394#  - .git is a directory
3395#  - core.bare is set
3396#
3397# Output:
3398#
3399# core.worktree and core.bare conflict, won't fly.
3400
3401test_expect_success '#22.2: setup' '
3402        git config --file="$here/22/.git/config" core.bare true
3403'
3404
3405test_expect_success '#22.2: at .git' '
3406        (
3407        cd 22/.git &&
3408        GIT_DIR=. &&
3409        export GIT_DIR &&
3410        test_must_fail git symbolic-ref HEAD 2>result &&
3411        grep "core.bare and core.worktree do not make sense" result
3412        )
3413'
3414
3415test_expect_success '#22.2: at root' '
3416        (
3417        cd 22 &&
3418        GIT_DIR=.git &&
3419        export GIT_DIR &&
3420        test_must_fail git symbolic-ref HEAD 2>result &&
3421        grep "core.bare and core.worktree do not make sense" result
3422        )
3423'
3424
3425#
3426# case #23
3427#
3428############################################################
3429#
3430# Input:
3431#
3432#  - GIT_WORK_TREE is set
3433#  - GIT_DIR is set
3434#  - core.worktree is set
3435#  - .git is a directory
3436#  - core.bare is set
3437#
3438# Output:
3439#
3440# core.worktree is overridden by GIT_WORK_TREE -> #19
3441
3442test_expect_success '#23: setup' '
3443        sane_unset GIT_DIR GIT_WORK_TREE &&
3444        mkdir 23 23/sub 23/sub/sub 23.wt 23.wt/sub 23/wt 23/wt/sub &&
3445        cd 23 &&
3446        git init &&
3447        git config core.bare true &&
3448        git config core.worktree non-existent &&
3449        cd ..
3450'
3451
3452test_expect_success '#23: GIT_DIR(rel), GIT_WORK_TREE=root at root' '
3453        cat >23/expected <<EOF &&
3454setup: git_dir: .git
3455setup: worktree: $here/23
3456setup: cwd: $here/23
3457setup: prefix: (null)
3458EOF
3459        test_repo 23 .git "$here/23"
3460'
3461
3462test_expect_success '#23: GIT_DIR(rel), GIT_WORK_TREE=root(rel) at root' '
3463        cat >23/expected <<EOF &&
3464setup: git_dir: .git
3465setup: worktree: $here/23
3466setup: cwd: $here/23
3467setup: prefix: (null)
3468EOF
3469        test_repo 23 .git .
3470'
3471
3472test_expect_success '#23: GIT_DIR, GIT_WORK_TREE=root at root' '
3473        cat >23/expected <<EOF &&
3474setup: git_dir: $here/23/.git
3475setup: worktree: $here/23
3476setup: cwd: $here/23
3477setup: prefix: (null)
3478EOF
3479        test_repo 23 "$here/23/.git" "$here/23"
3480'
3481
3482test_expect_success '#23: GIT_DIR, GIT_WORK_TREE=root(rel) at root' '
3483        cat >23/expected <<EOF &&
3484setup: git_dir: $here/23/.git
3485setup: worktree: $here/23
3486setup: cwd: $here/23
3487setup: prefix: (null)
3488EOF
3489        test_repo 23 "$here/23/.git" .
3490'
3491
3492test_expect_success '#23: GIT_DIR(rel), GIT_WORKTREE=root in subdir' '
3493        cat >23/sub/sub/expected <<EOF &&
3494setup: git_dir: $here/23/.git
3495setup: worktree: $here/23
3496setup: cwd: $here/23
3497setup: prefix: sub/sub/
3498EOF
3499        test_repo 23/sub/sub ../../.git "$here/23"
3500'
3501
3502test_expect_success '#23: GIT_DIR(rel), GIT_WORKTREE=root(rel) in subdir' '
3503        cat >23/sub/sub/expected <<EOF &&
3504setup: git_dir: $here/23/.git
3505setup: worktree: $here/23
3506setup: cwd: $here/23
3507setup: prefix: sub/sub/
3508EOF
3509        test_repo 23/sub/sub ../../.git ../..
3510'
3511
3512test_expect_success '#23: GIT_DIR, GIT_WORKTREE=root in subdir' '
3513        cat >23/sub/expected <<EOF &&
3514setup: git_dir: $here/23/.git
3515setup: worktree: $here/23
3516setup: cwd: $here/23
3517setup: prefix: sub/
3518EOF
3519        test_repo 23/sub "$here/23/.git" "$here/23"
3520'
3521
3522test_expect_success '#23: GIT_DIR, GIT_WORKTREE=root(rel) in subdir' '
3523        cat >23/sub/sub/expected <<EOF &&
3524setup: git_dir: $here/23/.git
3525setup: worktree: $here/23
3526setup: cwd: $here/23
3527setup: prefix: sub/sub/
3528EOF
3529        test_repo 23/sub/sub "$here/23/.git" ../..
3530'
3531
3532test_expect_success '#23: GIT_DIR(rel), GIT_WORK_TREE=wt at root' '
3533        cat >23/expected <<EOF &&
3534setup: git_dir: .git
3535setup: worktree: $here/23/wt
3536setup: cwd: $here/23
3537setup: prefix: (null)
3538EOF
3539        test_repo 23 .git "$here/23/wt"
3540'
3541
3542test_expect_success '#23: GIT_DIR(rel), GIT_WORK_TREE=wt(rel) at root' '
3543        cat >23/expected <<EOF &&
3544setup: git_dir: .git
3545setup: worktree: $here/23/wt
3546setup: cwd: $here/23
3547setup: prefix: (null)
3548EOF
3549        test_repo 23 .git wt
3550'
3551
3552test_expect_success '#23: GIT_DIR, GIT_WORK_TREE=wt(rel) at root' '
3553        cat >23/expected <<EOF &&
3554setup: git_dir: $here/23/.git
3555setup: worktree: $here/23/wt
3556setup: cwd: $here/23
3557setup: prefix: (null)
3558EOF
3559        test_repo 23 "$here/23/.git" wt
3560'
3561
3562test_expect_success '#23: GIT_DIR, GIT_WORK_TREE=wt at root' '
3563        cat >23/expected <<EOF &&
3564setup: git_dir: $here/23/.git
3565setup: worktree: $here/23/wt
3566setup: cwd: $here/23
3567setup: prefix: (null)
3568EOF
3569        test_repo 23 "$here/23/.git" "$here/23/wt"
3570'
3571
3572test_expect_success '#23: GIT_DIR(rel), GIT_WORK_TREE=wt in subdir' '
3573        cat >23/sub/sub/expected <<EOF &&
3574setup: git_dir: ../../.git
3575setup: worktree: $here/23/wt
3576setup: cwd: $here/23/sub/sub
3577setup: prefix: (null)
3578EOF
3579        test_repo 23/sub/sub ../../.git "$here/23/wt"
3580'
3581
3582test_expect_success '#23: GIT_DIR(rel), GIT_WORK_TREE=wt(rel) in subdir' '
3583        cat >23/sub/sub/expected <<EOF &&
3584setup: git_dir: ../../.git
3585setup: worktree: $here/23/wt
3586setup: cwd: $here/23/sub/sub
3587setup: prefix: (null)
3588EOF
3589        test_repo 23/sub/sub ../../.git ../../wt
3590'
3591
3592test_expect_success '#23: GIT_DIR, GIT_WORK_TREE=wt(rel) in subdir' '
3593        cat >23/sub/sub/expected <<EOF &&
3594setup: git_dir: $here/23/.git
3595setup: worktree: $here/23/wt
3596setup: cwd: $here/23/sub/sub
3597setup: prefix: (null)
3598EOF
3599        test_repo 23/sub/sub "$here/23/.git" ../../wt
3600'
3601
3602test_expect_success '#23: GIT_DIR, GIT_WORK_TREE=wt in subdir' '
3603        cat >23/sub/sub/expected <<EOF &&
3604setup: git_dir: $here/23/.git
3605setup: worktree: $here/23/wt
3606setup: cwd: $here/23/sub/sub
3607setup: prefix: (null)
3608EOF
3609        test_repo 23/sub/sub "$here/23/.git" "$here/23/wt"
3610'
3611
3612test_expect_success '#23: GIT_DIR(rel), GIT_WORK_TREE=.. at root' '
3613        cat >23/expected <<EOF &&
3614setup: git_dir: $here/23/.git
3615setup: worktree: $here
3616setup: cwd: $here
3617setup: prefix: 23/
3618EOF
3619        test_repo 23 .git "$here"
3620'
3621
3622test_expect_success '#23: GIT_DIR(rel), GIT_WORK_TREE=..(rel) at root' '
3623        cat >23/expected <<EOF &&
3624setup: git_dir: $here/23/.git
3625setup: worktree: $here
3626setup: cwd: $here
3627setup: prefix: 23/
3628EOF
3629        test_repo 23 .git ..
3630'
3631
3632test_expect_success '#23: GIT_DIR, GIT_WORK_TREE=..(rel) at root' '
3633        cat >23/expected <<EOF &&
3634setup: git_dir: $here/23/.git
3635setup: worktree: $here
3636setup: cwd: $here
3637setup: prefix: 23/
3638EOF
3639        test_repo 23 "$here/23/.git" ..
3640'
3641
3642test_expect_success '#23: GIT_DIR, GIT_WORK_TREE=.. at root' '
3643        cat >23/expected <<EOF &&
3644setup: git_dir: $here/23/.git
3645setup: worktree: $here
3646setup: cwd: $here
3647setup: prefix: 23/
3648EOF
3649        test_repo 23 "$here/23/.git" "$here"
3650'
3651
3652test_expect_success '#23: GIT_DIR(rel), GIT_WORK_TREE=.. in subdir' '
3653        cat >23/sub/sub/expected <<EOF &&
3654setup: git_dir: $here/23/.git
3655setup: worktree: $here
3656setup: cwd: $here
3657setup: prefix: 23/sub/sub/
3658EOF
3659        test_repo 23/sub/sub ../../.git "$here"
3660'
3661
3662test_expect_success '#23: GIT_DIR(rel), GIT_WORK_TREE=..(rel) in subdir' '
3663        cat >23/sub/sub/expected <<EOF &&
3664setup: git_dir: $here/23/.git
3665setup: worktree: $here
3666setup: cwd: $here
3667setup: prefix: 23/sub/sub/
3668EOF
3669        test_repo 23/sub/sub ../../.git ../../..
3670'
3671
3672test_expect_success '#23: GIT_DIR, GIT_WORK_TREE=..(rel) in subdir' '
3673        cat >23/sub/sub/expected <<EOF &&
3674setup: git_dir: $here/23/.git
3675setup: worktree: $here
3676setup: cwd: $here
3677setup: prefix: 23/sub/sub/
3678EOF
3679        test_repo 23/sub/sub "$here/23/.git" ../../../
3680'
3681
3682test_expect_success '#23: GIT_DIR, GIT_WORK_TREE=.. in subdir' '
3683        cat >23/sub/sub/expected <<EOF &&
3684setup: git_dir: $here/23/.git
3685setup: worktree: $here
3686setup: cwd: $here
3687setup: prefix: 23/sub/sub/
3688EOF
3689        test_repo 23/sub/sub "$here/23/.git" "$here"
3690'
3691
3692#
3693# case #24
3694#
3695############################################################
3696#
3697# Input:
3698#
3699#  - GIT_WORK_TREE is not set
3700#  - GIT_DIR is not set
3701#  - core.worktree is not set
3702#  - .git is a file
3703#  - core.bare is set
3704#
3705# Output:
3706#
3707# #16.2 except git_dir is set according to .git file
3708
3709test_expect_success '#24: setup' '
3710        sane_unset GIT_DIR GIT_WORK_TREE &&
3711        mkdir 24 24/sub &&
3712        cd 24 &&
3713        git init &&
3714        git config core.bare true &&
3715        mv .git ../24.git &&
3716        echo gitdir: ../24.git >.git &&
3717        cd ..
3718'
3719
3720test_expect_success '#24: at root' '
3721        cat >24/expected <<EOF &&
3722setup: git_dir: $here/24.git
3723setup: worktree: (null)
3724setup: cwd: $here/24
3725setup: prefix: (null)
3726EOF
3727        test_repo 24
3728'
3729
3730test_expect_success '#24: in subdir' '
3731        cat >24/sub/expected <<EOF &&
3732setup: git_dir: $here/24.git
3733setup: worktree: (null)
3734setup: cwd: $here/24/sub
3735setup: prefix: (null)
3736EOF
3737        test_repo 24/sub
3738'
3739
3740#
3741# case #25
3742#
3743############################################################
3744#
3745# Input:
3746#
3747#  - GIT_WORK_TREE is set
3748#  - GIT_DIR is not set
3749#  - core.worktree is not set
3750#  - .git is a file
3751#  - core.bare is set
3752#
3753# Output:
3754#
3755# #17.2 except git_dir is set according to .git file
3756
3757test_expect_success '#25: setup' '
3758        sane_unset GIT_DIR GIT_WORK_TREE &&
3759        mkdir 25 25/sub &&
3760        cd 25 &&
3761        git init &&
3762        git config core.bare true &&
3763        GIT_WORK_TREE=non-existent &&
3764        export GIT_WORK_TREE &&
3765        mv .git ../25.git &&
3766        echo gitdir: ../25.git >.git &&
3767        cd ..
3768'
3769
3770test_expect_success '#25: at root' '
3771        cat >25/expected <<EOF &&
3772setup: git_dir: $here/25.git
3773setup: worktree: (null)
3774setup: cwd: $here/25
3775setup: prefix: (null)
3776EOF
3777        test_repo 25
3778'
3779
3780test_expect_success '#25: in subdir' '
3781        cat >25/sub/expected <<EOF &&
3782setup: git_dir: $here/25.git
3783setup: worktree: (null)
3784setup: cwd: $here/25/sub
3785setup: prefix: (null)
3786EOF
3787        test_repo 25/sub
3788'
3789
3790#
3791# case #26
3792#
3793############################################################
3794#
3795# Input:
3796#
3797#  - GIT_WORK_TREE is not set
3798#  - GIT_DIR is set
3799#  - core.worktree is not set
3800#  - .git is a file
3801#  - core.bare is set
3802#
3803# Output:
3804#
3805# #18 except git_dir is set according to .git file
3806
3807test_expect_success '#26: setup' '
3808        sane_unset GIT_DIR GIT_WORK_TREE &&
3809        mkdir 26 26/sub &&
3810        cd 26 &&
3811        git init &&
3812        git config core.bare true &&
3813        mv .git ../26.git &&
3814        echo gitdir: ../26.git >.git &&
3815        cd ..
3816'
3817
3818test_expect_success '#26: (rel) at root' '
3819        cat >26/expected <<EOF &&
3820setup: git_dir: $here/26.git
3821setup: worktree: (null)
3822setup: cwd: $here/26
3823setup: prefix: (null)
3824EOF
3825         test_repo 26 .git
3826'
3827
3828test_expect_success '#26: at root' '
3829        cat >26/expected <<EOF &&
3830setup: git_dir: $here/26.git
3831setup: worktree: (null)
3832setup: cwd: $here/26
3833setup: prefix: (null)
3834EOF
3835         test_repo 26 "$here/26/.git"
3836'
3837
3838test_expect_success '#26: (rel) in subdir' '
3839        cat >26/sub/expected <<EOF &&
3840setup: git_dir: $here/26.git
3841setup: worktree: (null)
3842setup: cwd: $here/26/sub
3843setup: prefix: (null)
3844EOF
3845        test_repo 26/sub ../.git
3846'
3847
3848test_expect_success '#26: in subdir' '
3849        cat >26/sub/expected <<EOF &&
3850setup: git_dir: $here/26.git
3851setup: worktree: (null)
3852setup: cwd: $here/26/sub
3853setup: prefix: (null)
3854EOF
3855        test_repo 26/sub "$here/26/.git"
3856'
3857
3858#
3859# case #27
3860#
3861############################################################
3862#
3863# Input:
3864#
3865#  - GIT_WORK_TREE is set
3866#  - GIT_DIR is set
3867#  - .git is a file
3868#  - core.worktree is not set
3869#  - core.bare is set
3870#
3871# Output:
3872#
3873# #19 except git_dir is set according to .git file
3874
3875test_expect_success '#27: setup' '
3876        sane_unset GIT_DIR GIT_WORK_TREE &&
3877        mkdir 27 27/sub 27/sub/sub 27.wt 27.wt/sub 27/wt 27/wt/sub &&
3878        cd 27 &&
3879        git init &&
3880        git config core.bare true &&
3881        mv .git ../27.git &&
3882        echo gitdir: ../27.git >.git &&
3883        cd ..
3884'
3885
3886test_expect_success '#27: GIT_DIR(rel), GIT_WORK_TREE=root at root' '
3887        cat >27/expected <<EOF &&
3888setup: git_dir: $here/27.git
3889setup: worktree: $here/27
3890setup: cwd: $here/27
3891setup: prefix: (null)
3892EOF
3893        test_repo 27 .git "$here/27"
3894'
3895
3896test_expect_success '#27: GIT_DIR(rel), GIT_WORK_TREE=root(rel) at root' '
3897        cat >27/expected <<EOF &&
3898setup: git_dir: $here/27.git
3899setup: worktree: $here/27
3900setup: cwd: $here/27
3901setup: prefix: (null)
3902EOF
3903        test_repo 27 .git .
3904'
3905
3906test_expect_success '#27: GIT_DIR, GIT_WORK_TREE=root at root' '
3907        cat >27/expected <<EOF &&
3908setup: git_dir: $here/27.git
3909setup: worktree: $here/27
3910setup: cwd: $here/27
3911setup: prefix: (null)
3912EOF
3913        test_repo 27 "$here/27/.git" "$here/27"
3914'
3915
3916test_expect_success '#27: GIT_DIR, GIT_WORK_TREE=root(rel) at root' '
3917        cat >27/expected <<EOF &&
3918setup: git_dir: $here/27.git
3919setup: worktree: $here/27
3920setup: cwd: $here/27
3921setup: prefix: (null)
3922EOF
3923        test_repo 27 "$here/27/.git" .
3924'
3925
3926test_expect_success '#27: GIT_DIR(rel), GIT_WORKTREE=root in subdir' '
3927        cat >27/sub/sub/expected <<EOF &&
3928setup: git_dir: $here/27.git
3929setup: worktree: $here/27
3930setup: cwd: $here/27
3931setup: prefix: sub/sub/
3932EOF
3933        test_repo 27/sub/sub ../../.git "$here/27"
3934'
3935
3936test_expect_success '#27: GIT_DIR(rel), GIT_WORKTREE=root(rel) in subdir' '
3937        cat >27/sub/sub/expected <<EOF &&
3938setup: git_dir: $here/27.git
3939setup: worktree: $here/27
3940setup: cwd: $here/27
3941setup: prefix: sub/sub/
3942EOF
3943        test_repo 27/sub/sub ../../.git ../..
3944'
3945
3946test_expect_success '#27: GIT_DIR, GIT_WORKTREE=root in subdir' '
3947        cat >27/sub/expected <<EOF &&
3948setup: git_dir: $here/27.git
3949setup: worktree: $here/27
3950setup: cwd: $here/27
3951setup: prefix: sub/
3952EOF
3953        test_repo 27/sub "$here/27/.git" "$here/27"
3954'
3955
3956test_expect_success '#27: GIT_DIR, GIT_WORKTREE=root(rel) in subdir' '
3957        cat >27/sub/sub/expected <<EOF &&
3958setup: git_dir: $here/27.git
3959setup: worktree: $here/27
3960setup: cwd: $here/27
3961setup: prefix: sub/sub/
3962EOF
3963        test_repo 27/sub/sub "$here/27/.git" ../..
3964'
3965
3966test_expect_success '#27: GIT_DIR(rel), GIT_WORK_TREE=wt at root' '
3967        cat >27/expected <<EOF &&
3968setup: git_dir: $here/27.git
3969setup: worktree: $here/27/wt
3970setup: cwd: $here/27
3971setup: prefix: (null)
3972EOF
3973        test_repo 27 .git "$here/27/wt"
3974'
3975
3976test_expect_success '#27: GIT_DIR(rel), GIT_WORK_TREE=wt(rel) at root' '
3977        cat >27/expected <<EOF &&
3978setup: git_dir: $here/27.git
3979setup: worktree: $here/27/wt
3980setup: cwd: $here/27
3981setup: prefix: (null)
3982EOF
3983        test_repo 27 .git wt
3984'
3985
3986test_expect_success '#27: GIT_DIR, GIT_WORK_TREE=wt(rel) at root' '
3987        cat >27/expected <<EOF &&
3988setup: git_dir: $here/27.git
3989setup: worktree: $here/27/wt
3990setup: cwd: $here/27
3991setup: prefix: (null)
3992EOF
3993        test_repo 27 "$here/27/.git" wt
3994'
3995
3996test_expect_success '#27: GIT_DIR, GIT_WORK_TREE=wt at root' '
3997        cat >27/expected <<EOF &&
3998setup: git_dir: $here/27.git
3999setup: worktree: $here/27/wt
4000setup: cwd: $here/27
4001setup: prefix: (null)
4002EOF
4003        test_repo 27 "$here/27/.git" "$here/27/wt"
4004'
4005
4006test_expect_success '#27: GIT_DIR(rel), GIT_WORK_TREE=wt in subdir' '
4007        cat >27/sub/sub/expected <<EOF &&
4008setup: git_dir: $here/27.git
4009setup: worktree: $here/27/wt
4010setup: cwd: $here/27/sub/sub
4011setup: prefix: (null)
4012EOF
4013        test_repo 27/sub/sub ../../.git "$here/27/wt"
4014'
4015
4016test_expect_success '#27: GIT_DIR(rel), GIT_WORK_TREE=wt(rel) in subdir' '
4017        cat >27/sub/sub/expected <<EOF &&
4018setup: git_dir: $here/27.git
4019setup: worktree: $here/27/wt
4020setup: cwd: $here/27/sub/sub
4021setup: prefix: (null)
4022EOF
4023        test_repo 27/sub/sub ../../.git ../../wt
4024'
4025
4026test_expect_success '#27: GIT_DIR, GIT_WORK_TREE=wt(rel) in subdir' '
4027        cat >27/sub/sub/expected <<EOF &&
4028setup: git_dir: $here/27.git
4029setup: worktree: $here/27/wt
4030setup: cwd: $here/27/sub/sub
4031setup: prefix: (null)
4032EOF
4033        test_repo 27/sub/sub "$here/27/.git" ../../wt
4034'
4035
4036test_expect_success '#27: GIT_DIR, GIT_WORK_TREE=wt in subdir' '
4037        cat >27/sub/sub/expected <<EOF &&
4038setup: git_dir: $here/27.git
4039setup: worktree: $here/27/wt
4040setup: cwd: $here/27/sub/sub
4041setup: prefix: (null)
4042EOF
4043        test_repo 27/sub/sub "$here/27/.git" "$here/27/wt"
4044'
4045
4046test_expect_success '#27: GIT_DIR(rel), GIT_WORK_TREE=.. at root' '
4047        cat >27/expected <<EOF &&
4048setup: git_dir: $here/27.git
4049setup: worktree: $here
4050setup: cwd: $here
4051setup: prefix: 27/
4052EOF
4053        test_repo 27 .git "$here"
4054'
4055
4056test_expect_success '#27: GIT_DIR(rel), GIT_WORK_TREE=..(rel) at root' '
4057        cat >27/expected <<EOF &&
4058setup: git_dir: $here/27.git
4059setup: worktree: $here
4060setup: cwd: $here
4061setup: prefix: 27/
4062EOF
4063        test_repo 27 .git ..
4064'
4065
4066test_expect_success '#27: GIT_DIR, GIT_WORK_TREE=..(rel) at root' '
4067        cat >27/expected <<EOF &&
4068setup: git_dir: $here/27.git
4069setup: worktree: $here
4070setup: cwd: $here
4071setup: prefix: 27/
4072EOF
4073        test_repo 27 "$here/27/.git" ..
4074'
4075
4076test_expect_success '#27: GIT_DIR, GIT_WORK_TREE=.. at root' '
4077        cat >27/expected <<EOF &&
4078setup: git_dir: $here/27.git
4079setup: worktree: $here
4080setup: cwd: $here
4081setup: prefix: 27/
4082EOF
4083        test_repo 27 "$here/27/.git" "$here"
4084'
4085
4086test_expect_success '#27: GIT_DIR(rel), GIT_WORK_TREE=.. in subdir' '
4087        cat >27/sub/sub/expected <<EOF &&
4088setup: git_dir: $here/27.git
4089setup: worktree: $here
4090setup: cwd: $here
4091setup: prefix: 27/sub/sub/
4092EOF
4093        test_repo 27/sub/sub ../../.git "$here"
4094'
4095
4096test_expect_success '#27: GIT_DIR(rel), GIT_WORK_TREE=..(rel) in subdir' '
4097        cat >27/sub/sub/expected <<EOF &&
4098setup: git_dir: $here/27.git
4099setup: worktree: $here
4100setup: cwd: $here
4101setup: prefix: 27/sub/sub/
4102EOF
4103        test_repo 27/sub/sub ../../.git ../../..
4104'
4105
4106test_expect_success '#27: GIT_DIR, GIT_WORK_TREE=..(rel) in subdir' '
4107        cat >27/sub/sub/expected <<EOF &&
4108setup: git_dir: $here/27.git
4109setup: worktree: $here
4110setup: cwd: $here
4111setup: prefix: 27/sub/sub/
4112EOF
4113        test_repo 27/sub/sub "$here/27/.git" ../../../
4114'
4115
4116test_expect_success '#27: GIT_DIR, GIT_WORK_TREE=.. in subdir' '
4117        cat >27/sub/sub/expected <<EOF &&
4118setup: git_dir: $here/27.git
4119setup: worktree: $here
4120setup: cwd: $here
4121setup: prefix: 27/sub/sub/
4122EOF
4123        test_repo 27/sub/sub "$here/27/.git" "$here"
4124'
4125
4126#
4127# case #28
4128#
4129############################################################
4130#
4131# Input:
4132#
4133#  - GIT_WORK_TREE is not set
4134#  - GIT_DIR is not set
4135#  - core.worktree is set
4136#  - .git is a file
4137#  - core.bare is set
4138#
4139# Output:
4140#
4141# core.worktree is ignored -> #24
4142
4143test_expect_success '#28: setup' '
4144        sane_unset GIT_DIR GIT_WORK_TREE &&
4145        mkdir 28 28/sub &&
4146        cd 28 &&
4147        git init &&
4148        git config core.bare true &&
4149        git config core.worktree non-existent &&
4150        mv .git ../28.git &&
4151        echo gitdir: ../28.git >.git &&
4152        cd ..
4153'
4154
4155test_expect_success '#28: at root' '
4156        cat >28/expected <<EOF &&
4157setup: git_dir: $here/28.git
4158setup: worktree: (null)
4159setup: cwd: $here/28
4160setup: prefix: (null)
4161EOF
4162        test_repo 28
4163'
4164
4165test_expect_success '#28: in subdir' '
4166        cat >28/sub/expected <<EOF &&
4167setup: git_dir: $here/28.git
4168setup: worktree: (null)
4169setup: cwd: $here/28/sub
4170setup: prefix: (null)
4171EOF
4172        test_repo 28/sub
4173'
4174
4175#
4176# case #29
4177#
4178############################################################
4179#
4180# Input:
4181#
4182#  - GIT_WORK_TREE is set
4183#  - GIT_DIR is not set
4184#  - core.worktree is set
4185#  - .git is a file
4186#  - core.bare is set
4187#
4188# Output:
4189#
4190# GIT_WORK_TREE/core.worktree are ignored -> #28
4191
4192test_expect_success '#29: setup' '
4193        sane_unset GIT_DIR GIT_WORK_TREE &&
4194        mkdir 29 29/sub &&
4195        cd 29 &&
4196        git init &&
4197        git config core.bare true &&
4198        GIT_WORK_TREE=non-existent &&
4199        export GIT_WORK_TREE &&
4200        mv .git ../29.git &&
4201        echo gitdir: ../29.git >.git &&
4202        cd ..
4203'
4204
4205test_expect_success '#29: at root' '
4206        cat >29/expected <<EOF &&
4207setup: git_dir: $here/29.git
4208setup: worktree: (null)
4209setup: cwd: $here/29
4210setup: prefix: (null)
4211EOF
4212        test_repo 29
4213'
4214
4215test_expect_success '#29: in subdir' '
4216        cat >29/sub/expected <<EOF &&
4217setup: git_dir: $here/29.git
4218setup: worktree: (null)
4219setup: cwd: $here/29/sub
4220setup: prefix: (null)
4221EOF
4222        test_repo 29/sub
4223'
4224
4225#
4226# case #30
4227#
4228############################################################
4229#
4230# Input:
4231#
4232#  - GIT_WORK_TREE is not set
4233#  - GIT_DIR is set
4234#  - core.worktree is set
4235#  - .git is a file
4236#  - core.bare is set
4237#
4238# Output:
4239#
4240# core.worktree and core.bare conflict, won't fly.
4241
4242test_expect_success '#30: setup' '
4243        sane_unset GIT_DIR GIT_WORK_TREE &&
4244        mkdir 30 &&
4245        cd 30 &&
4246        git init &&
4247        git config core.bare true &&
4248        git config core.worktree non-existent &&
4249        mv .git ../30.git &&
4250        echo gitdir: ../30.git >.git &&
4251        cd ..
4252'
4253
4254test_expect_success '#30: at root' '
4255        (
4256        cd 30 &&
4257        GIT_DIR=.git &&
4258        export GIT_DIR &&
4259        test_must_fail git symbolic-ref HEAD 2>result &&
4260        grep "core.bare and core.worktree do not make sense" result
4261        )
4262'
4263
4264#
4265# case #31
4266#
4267############################################################
4268#
4269# Input:
4270#
4271#  - GIT_WORK_TREE is set
4272#  - GIT_DIR is set
4273#  - core.worktree is set
4274#  - .git is a file
4275#  - core.bare is set
4276#
4277# Output:
4278#
4279# #23 except git_dir is set according to .git file
4280
4281test_expect_success '#31: setup' '
4282        sane_unset GIT_DIR GIT_WORK_TREE &&
4283        mkdir 31 31/sub 31/sub/sub 31.wt 31.wt/sub 31/wt 31/wt/sub &&
4284        cd 31 &&
4285        git init &&
4286        git config core.bare true &&
4287        git config core.worktree non-existent &&
4288        mv .git ../31.git &&
4289        echo gitdir: ../31.git >.git &&
4290        cd ..
4291'
4292
4293test_expect_success '#31: GIT_DIR(rel), GIT_WORK_TREE=root at root' '
4294        cat >31/expected <<EOF &&
4295setup: git_dir: $here/31.git
4296setup: worktree: $here/31
4297setup: cwd: $here/31
4298setup: prefix: (null)
4299EOF
4300        test_repo 31 .git "$here/31"
4301'
4302
4303test_expect_success '#31: GIT_DIR(rel), GIT_WORK_TREE=root(rel) at root' '
4304        cat >31/expected <<EOF &&
4305setup: git_dir: $here/31.git
4306setup: worktree: $here/31
4307setup: cwd: $here/31
4308setup: prefix: (null)
4309EOF
4310        test_repo 31 .git .
4311'
4312
4313test_expect_success '#31: GIT_DIR, GIT_WORK_TREE=root at root' '
4314        cat >31/expected <<EOF &&
4315setup: git_dir: $here/31.git
4316setup: worktree: $here/31
4317setup: cwd: $here/31
4318setup: prefix: (null)
4319EOF
4320        test_repo 31 "$here/31/.git" "$here/31"
4321'
4322
4323test_expect_success '#31: GIT_DIR, GIT_WORK_TREE=root(rel) at root' '
4324        cat >31/expected <<EOF &&
4325setup: git_dir: $here/31.git
4326setup: worktree: $here/31
4327setup: cwd: $here/31
4328setup: prefix: (null)
4329EOF
4330        test_repo 31 "$here/31/.git" .
4331'
4332
4333test_expect_success '#31: GIT_DIR(rel), GIT_WORKTREE=root in subdir' '
4334        cat >31/sub/sub/expected <<EOF &&
4335setup: git_dir: $here/31.git
4336setup: worktree: $here/31
4337setup: cwd: $here/31
4338setup: prefix: sub/sub/
4339EOF
4340        test_repo 31/sub/sub ../../.git "$here/31"
4341'
4342
4343test_expect_success '#31: GIT_DIR(rel), GIT_WORKTREE=root(rel) in subdir' '
4344        cat >31/sub/sub/expected <<EOF &&
4345setup: git_dir: $here/31.git
4346setup: worktree: $here/31
4347setup: cwd: $here/31
4348setup: prefix: sub/sub/
4349EOF
4350        test_repo 31/sub/sub ../../.git ../..
4351'
4352
4353test_expect_success '#31: GIT_DIR, GIT_WORKTREE=root in subdir' '
4354        cat >31/sub/expected <<EOF &&
4355setup: git_dir: $here/31.git
4356setup: worktree: $here/31
4357setup: cwd: $here/31
4358setup: prefix: sub/
4359EOF
4360        test_repo 31/sub "$here/31/.git" "$here/31"
4361'
4362
4363test_expect_success '#31: GIT_DIR, GIT_WORKTREE=root(rel) in subdir' '
4364        cat >31/sub/sub/expected <<EOF &&
4365setup: git_dir: $here/31.git
4366setup: worktree: $here/31
4367setup: cwd: $here/31
4368setup: prefix: sub/sub/
4369EOF
4370        test_repo 31/sub/sub "$here/31/.git" ../..
4371'
4372
4373test_expect_success '#31: GIT_DIR(rel), GIT_WORK_TREE=wt at root' '
4374        cat >31/expected <<EOF &&
4375setup: git_dir: $here/31.git
4376setup: worktree: $here/31/wt
4377setup: cwd: $here/31
4378setup: prefix: (null)
4379EOF
4380        test_repo 31 .git "$here/31/wt"
4381'
4382
4383test_expect_success '#31: GIT_DIR(rel), GIT_WORK_TREE=wt(rel) at root' '
4384        cat >31/expected <<EOF &&
4385setup: git_dir: $here/31.git
4386setup: worktree: $here/31/wt
4387setup: cwd: $here/31
4388setup: prefix: (null)
4389EOF
4390        test_repo 31 .git wt
4391'
4392
4393test_expect_success '#31: GIT_DIR, GIT_WORK_TREE=wt(rel) at root' '
4394        cat >31/expected <<EOF &&
4395setup: git_dir: $here/31.git
4396setup: worktree: $here/31/wt
4397setup: cwd: $here/31
4398setup: prefix: (null)
4399EOF
4400        test_repo 31 "$here/31/.git" wt
4401'
4402
4403test_expect_success '#31: GIT_DIR, GIT_WORK_TREE=wt at root' '
4404        cat >31/expected <<EOF &&
4405setup: git_dir: $here/31.git
4406setup: worktree: $here/31/wt
4407setup: cwd: $here/31
4408setup: prefix: (null)
4409EOF
4410        test_repo 31 "$here/31/.git" "$here/31/wt"
4411'
4412
4413test_expect_success '#31: GIT_DIR(rel), GIT_WORK_TREE=wt in subdir' '
4414        cat >31/sub/sub/expected <<EOF &&
4415setup: git_dir: $here/31.git
4416setup: worktree: $here/31/wt
4417setup: cwd: $here/31/sub/sub
4418setup: prefix: (null)
4419EOF
4420        test_repo 31/sub/sub ../../.git "$here/31/wt"
4421'
4422
4423test_expect_success '#31: GIT_DIR(rel), GIT_WORK_TREE=wt(rel) in subdir' '
4424        cat >31/sub/sub/expected <<EOF &&
4425setup: git_dir: $here/31.git
4426setup: worktree: $here/31/wt
4427setup: cwd: $here/31/sub/sub
4428setup: prefix: (null)
4429EOF
4430        test_repo 31/sub/sub ../../.git ../../wt
4431'
4432
4433test_expect_success '#31: GIT_DIR, GIT_WORK_TREE=wt(rel) in subdir' '
4434        cat >31/sub/sub/expected <<EOF &&
4435setup: git_dir: $here/31.git
4436setup: worktree: $here/31/wt
4437setup: cwd: $here/31/sub/sub
4438setup: prefix: (null)
4439EOF
4440        test_repo 31/sub/sub "$here/31/.git" ../../wt
4441'
4442
4443test_expect_success '#31: GIT_DIR, GIT_WORK_TREE=wt in subdir' '
4444        cat >31/sub/sub/expected <<EOF &&
4445setup: git_dir: $here/31.git
4446setup: worktree: $here/31/wt
4447setup: cwd: $here/31/sub/sub
4448setup: prefix: (null)
4449EOF
4450        test_repo 31/sub/sub "$here/31/.git" "$here/31/wt"
4451'
4452
4453test_expect_success '#31: GIT_DIR(rel), GIT_WORK_TREE=.. at root' '
4454        cat >31/expected <<EOF &&
4455setup: git_dir: $here/31.git
4456setup: worktree: $here
4457setup: cwd: $here
4458setup: prefix: 31/
4459EOF
4460        test_repo 31 .git "$here"
4461'
4462
4463test_expect_success '#31: GIT_DIR(rel), GIT_WORK_TREE=..(rel) at root' '
4464        cat >31/expected <<EOF &&
4465setup: git_dir: $here/31.git
4466setup: worktree: $here
4467setup: cwd: $here
4468setup: prefix: 31/
4469EOF
4470        test_repo 31 .git ..
4471'
4472
4473test_expect_success '#31: GIT_DIR, GIT_WORK_TREE=..(rel) at root' '
4474        cat >31/expected <<EOF &&
4475setup: git_dir: $here/31.git
4476setup: worktree: $here
4477setup: cwd: $here
4478setup: prefix: 31/
4479EOF
4480        test_repo 31 "$here/31/.git" ..
4481'
4482
4483test_expect_success '#31: GIT_DIR, GIT_WORK_TREE=.. at root' '
4484        cat >31/expected <<EOF &&
4485setup: git_dir: $here/31.git
4486setup: worktree: $here
4487setup: cwd: $here
4488setup: prefix: 31/
4489EOF
4490        test_repo 31 "$here/31/.git" "$here"
4491'
4492
4493test_expect_success '#31: GIT_DIR(rel), GIT_WORK_TREE=.. in subdir' '
4494        cat >31/sub/sub/expected <<EOF &&
4495setup: git_dir: $here/31.git
4496setup: worktree: $here
4497setup: cwd: $here
4498setup: prefix: 31/sub/sub/
4499EOF
4500        test_repo 31/sub/sub ../../.git "$here"
4501'
4502
4503test_expect_success '#31: GIT_DIR(rel), GIT_WORK_TREE=..(rel) in subdir' '
4504        cat >31/sub/sub/expected <<EOF &&
4505setup: git_dir: $here/31.git
4506setup: worktree: $here
4507setup: cwd: $here
4508setup: prefix: 31/sub/sub/
4509EOF
4510        test_repo 31/sub/sub ../../.git ../../..
4511'
4512
4513test_expect_success '#31: GIT_DIR, GIT_WORK_TREE=..(rel) in subdir' '
4514        cat >31/sub/sub/expected <<EOF &&
4515setup: git_dir: $here/31.git
4516setup: worktree: $here
4517setup: cwd: $here
4518setup: prefix: 31/sub/sub/
4519EOF
4520        test_repo 31/sub/sub "$here/31/.git" ../../../
4521'
4522
4523test_expect_success '#31: GIT_DIR, GIT_WORK_TREE=.. in subdir' '
4524        cat >31/sub/sub/expected <<EOF &&
4525setup: git_dir: $here/31.git
4526setup: worktree: $here
4527setup: cwd: $here
4528setup: prefix: 31/sub/sub/
4529EOF
4530        test_repo 31/sub/sub "$here/31/.git" "$here"
4531'
4532
4533test_done