3 test_description
='test separate work tree'
10 test_expect_success
"$name: is-bare-repository" \
11 "test '$1' = \"\$(git rev-parse --is-bare-repository)\""
13 [ $# -eq 0 ] && return
15 test_expect_success
"$name: is-inside-git-dir" \
16 "test '$1' = \"\$(git rev-parse --is-inside-git-dir)\""
18 [ $# -eq 0 ] && return
20 test_expect_success
"$name: is-inside-work-tree" \
21 "test '$1' = \"\$(git rev-parse --is-inside-work-tree)\""
23 [ $# -eq 0 ] && return
25 test_expect_success
"$name: prefix" \
26 "test '$1' = \"\$(git rev-parse --show-prefix)\""
28 [ $# -eq 0 ] && return
31 mkdir
-p work
/sub
/dir ||
exit 1
32 mv .git repo.git ||
exit 1
34 say
"core.worktree = relative path"
35 export GIT_DIR
=repo.git
36 export GIT_CONFIG
="$(pwd)"/$GIT_DIR/config
38 git config core.worktree ..
/work
39 test_rev_parse
'outside' false false false
41 export GIT_DIR
=..
/repo.git
42 export GIT_CONFIG
="$(pwd)"/$GIT_DIR/config
43 test_rev_parse
'inside' false false true
''
45 export GIT_DIR
=..
/..
/..
/repo.git
46 export GIT_CONFIG
="$(pwd)"/$GIT_DIR/config
47 test_rev_parse
'subdirectory' false false true sub
/dir
/
50 say
"core.worktree = absolute path"
51 export GIT_DIR
=$
(pwd)/repo.git
52 export GIT_CONFIG
=$GIT_DIR/config
53 git config core.worktree
"$(pwd)/work"
54 test_rev_parse
'outside' false false false
56 test_rev_parse
'inside' false false true
''
58 test_rev_parse
'subdirectory' false false true sub
/dir
/
61 say
"GIT_WORK_TREE=relative path (override core.worktree)"
62 export GIT_DIR
=$
(pwd)/repo.git
63 export GIT_CONFIG
=$GIT_DIR/config
64 git config core.worktree non-existent
65 export GIT_WORK_TREE
=work
66 test_rev_parse
'outside' false false false
68 export GIT_WORK_TREE
=.
69 test_rev_parse
'inside' false false true
''
71 export GIT_WORK_TREE
=..
/..
72 test_rev_parse
'subdirectory' false false true sub
/dir
/
77 say
"GIT_WORK_TREE=absolute path, work tree below git dir"
78 export GIT_DIR
=$
(pwd)/repo.git
79 export GIT_CONFIG
=$GIT_DIR/config
80 export GIT_WORK_TREE
=$
(pwd)/repo.git
/work
81 test_rev_parse
'outside' false false false
83 test_rev_parse
'in repo.git' false true false
85 test_rev_parse
'in repo.git/objects' false true false
87 test_rev_parse
'in repo.git/work' false true true
''
89 test_rev_parse
'in repo.git/sub/dir' false true true sub
/dir
/
90 cd ..
/..
/..
/.. ||
exit 1
92 test_expect_success
'repo finds its work tree' '
94 : > work/sub/dir/untracked &&
95 test sub/dir/untracked = "$(git ls-files --others)")
98 test_expect_success
'repo finds its work tree from work tree, too' '
99 (cd repo.git/work/sub/dir &&
101 git --git-dir=../../.. add tracked &&
103 test sub/dir/tracked = "$(git ls-files)")
106 test_expect_success
'_gently() groks relative GIT_DIR & GIT_WORK_TREE' '
107 cd repo.git/work/sub/dir &&
108 GIT_DIR=../../.. GIT_WORK_TREE=../.. GIT_PAGER= \
109 git diff --exit-code tracked &&
110 echo changed > tracked &&
111 ! GIT_DIR=../../.. GIT_WORK_TREE=../.. GIT_PAGER= \
112 git diff --exit-code tracked