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 EMPTY_TREE
=$
(git write-tree
)
32 mkdir
-p work
/sub
/dir ||
exit 1
33 mv .git repo.git ||
exit 1
35 say
"core.worktree = relative path"
37 GIT_CONFIG
="$(pwd)"/$GIT_DIR/config
38 export GIT_DIR GIT_CONFIG
40 git config core.worktree ..
/work
41 test_rev_parse
'outside' false false false
44 GIT_CONFIG
="$(pwd)"/$GIT_DIR/config
45 test_rev_parse
'inside' false false true
''
47 GIT_DIR
=..
/..
/..
/repo.git
48 GIT_CONFIG
="$(pwd)"/$GIT_DIR/config
49 test_rev_parse
'subdirectory' false false true sub
/dir
/
52 say
"core.worktree = absolute path"
53 GIT_DIR
=$
(pwd)/repo.git
54 GIT_CONFIG
=$GIT_DIR/config
55 git config core.worktree
"$(pwd)/work"
56 test_rev_parse
'outside' false false false
58 test_rev_parse
'inside' false false true
''
60 test_rev_parse
'subdirectory' false false true sub
/dir
/
63 say
"GIT_WORK_TREE=relative path (override core.worktree)"
64 GIT_DIR
=$
(pwd)/repo.git
65 GIT_CONFIG
=$GIT_DIR/config
66 git config core.worktree non-existent
69 test_rev_parse
'outside' false false false
72 test_rev_parse
'inside' false false true
''
75 test_rev_parse
'subdirectory' false false true sub
/dir
/
80 say
"GIT_WORK_TREE=absolute path, work tree below git dir"
81 GIT_DIR
=$
(pwd)/repo.git
82 GIT_CONFIG
=$GIT_DIR/config
83 GIT_WORK_TREE
=$
(pwd)/repo.git
/work
84 test_rev_parse
'outside' false false false
86 test_rev_parse
'in repo.git' false true false
88 test_rev_parse
'in repo.git/objects' false true false
90 test_rev_parse
'in repo.git/work' false true true
''
92 test_rev_parse
'in repo.git/sub/dir' false true true sub
/dir
/
93 cd ..
/..
/..
/.. ||
exit 1
95 test_expect_success
'detecting gitdir when cwd is in a subdir of gitdir' '
96 (expected=$(pwd)/repo.git &&
99 test "$expected" = "$(git rev-parse --git-dir)")
102 test_expect_success
'repo finds its work tree' '
104 : > work/sub/dir/untracked &&
105 test sub/dir/untracked = "$(git ls-files --others)")
108 test_expect_success
'repo finds its work tree from work tree, too' '
109 (cd repo.git/work/sub/dir &&
111 git --git-dir=../../.. add tracked &&
113 test sub/dir/tracked = "$(git ls-files)")
116 test_expect_success
'_gently() groks relative GIT_DIR & GIT_WORK_TREE' '
117 (cd repo.git/work/sub/dir &&
118 GIT_DIR=../../.. GIT_WORK_TREE=../.. GIT_PAGER= \
119 git diff --exit-code tracked &&
120 echo changed > tracked &&
121 ! GIT_DIR=../../.. GIT_WORK_TREE=../.. GIT_PAGER= \
122 git diff --exit-code tracked)
124 cat > diff-index-cached.expected
<<\EOF
125 :000000 100644 0000000000000000000000000000000000000000 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 A sub
/dir
/tracked
127 cat > diff-index.expected
<<\EOF
128 :000000 100644 0000000000000000000000000000000000000000 0000000000000000000000000000000000000000 A sub
/dir
/tracked
132 test_expect_success
'git diff-index' '
133 GIT_DIR=repo.git GIT_WORK_TREE=repo.git/work git diff-index $EMPTY_TREE > result &&
134 test_cmp diff-index.expected result &&
135 GIT_DIR=repo.git git diff-index --cached $EMPTY_TREE > result &&
136 test_cmp diff-index-cached.expected result
138 cat >diff-files.expected
<<\EOF
139 :100644 100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
0000000000000000000000000000000000000000 M sub
/dir
/tracked
142 test_expect_success
'git diff-files' '
143 GIT_DIR=repo.git GIT_WORK_TREE=repo.git/work git diff-files > result &&
144 test_cmp diff-files.expected result
147 cat >diff-TREE.expected
<<\EOF
148 diff --git a
/sub
/dir
/tracked b
/sub
/dir
/tracked
150 index
0000000.
.5ea2ed4
152 +++ b
/sub
/dir
/tracked
156 cat >diff-TREE-cached.expected
<<\EOF
157 diff --git a
/sub
/dir
/tracked b
/sub
/dir
/tracked
159 index
0000000..e69de29
161 cat >diff-FILES.expected
<<\EOF
162 diff --git a
/sub
/dir
/tracked b
/sub
/dir
/tracked
163 index e69de29.
.5ea2ed4
100644
164 --- a
/sub
/dir
/tracked
165 +++ b
/sub
/dir
/tracked
170 test_expect_success
'git diff' '
171 GIT_DIR=repo.git GIT_WORK_TREE=repo.git/work git diff $EMPTY_TREE > result &&
172 test_cmp diff-TREE.expected result &&
173 GIT_DIR=repo.git git diff --cached $EMPTY_TREE > result &&
174 test_cmp diff-TREE-cached.expected result &&
175 GIT_DIR=repo.git GIT_WORK_TREE=repo.git/work git diff > result &&
176 test_cmp diff-FILES.expected result
179 test_expect_success
'git grep' '
180 (cd repo.git/work/sub &&
181 GIT_DIR=../.. GIT_WORK_TREE=.. git grep -l changed | grep dir/tracked)