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 mkdir
-p work2 ||
exit 1
34 mv .git repo.git ||
exit 1
36 say
"core.worktree = relative path"
38 GIT_CONFIG
="$(pwd)"/$GIT_DIR/config
39 export GIT_DIR GIT_CONFIG
41 git config core.worktree ..
/work
42 test_rev_parse
'outside' false false false
45 GIT_CONFIG
="$(pwd)"/$GIT_DIR/config
46 test_rev_parse
'inside' false false true
''
48 GIT_DIR
=..
/..
/..
/repo.git
49 GIT_CONFIG
="$(pwd)"/$GIT_DIR/config
50 test_rev_parse
'subdirectory' false false true sub
/dir
/
53 say
"core.worktree = absolute path"
54 GIT_DIR
=$
(pwd)/repo.git
55 GIT_CONFIG
=$GIT_DIR/config
56 git config core.worktree
"$(pwd)/work"
57 test_rev_parse
'outside' false false false
59 test_rev_parse
'outside2' false false false
61 test_rev_parse
'inside' false false true
''
63 test_rev_parse
'subdirectory' false false true sub
/dir
/
66 say
"GIT_WORK_TREE=relative path (override core.worktree)"
67 GIT_DIR
=$
(pwd)/repo.git
68 GIT_CONFIG
=$GIT_DIR/config
69 git config core.worktree non-existent
72 test_rev_parse
'outside' false false false
74 test_rev_parse
'outside' false false false
77 test_rev_parse
'inside' false false true
''
80 test_rev_parse
'subdirectory' false false true sub
/dir
/
84 mv work2 repo.git
/work2
86 say
"GIT_WORK_TREE=absolute path, work tree below git dir"
87 GIT_DIR
=$
(pwd)/repo.git
88 GIT_CONFIG
=$GIT_DIR/config
89 GIT_WORK_TREE
=$
(pwd)/repo.git
/work
90 test_rev_parse
'outside' false false false
92 test_rev_parse
'in repo.git' false true false
94 test_rev_parse
'in repo.git/objects' false true false
96 test_rev_parse
'in repo.git/work2' false true false
98 test_rev_parse
'in repo.git/work' false true true
''
100 test_rev_parse
'in repo.git/sub/dir' false true true sub
/dir
/
101 cd ..
/..
/..
/.. ||
exit 1
103 test_expect_success
'repo finds its work tree' '
105 : > work/sub/dir/untracked &&
106 test sub/dir/untracked = "$(git ls-files --others)")
109 test_expect_success
'repo finds its work tree from work tree, too' '
110 (cd repo.git/work/sub/dir &&
112 git --git-dir=../../.. add tracked &&
114 test sub/dir/tracked = "$(git ls-files)")
117 test_expect_success
'_gently() groks relative GIT_DIR & GIT_WORK_TREE' '
118 (cd repo.git/work/sub/dir &&
119 GIT_DIR=../../.. GIT_WORK_TREE=../.. GIT_PAGER= \
120 git diff --exit-code tracked &&
121 echo changed > tracked &&
122 ! GIT_DIR=../../.. GIT_WORK_TREE=../.. GIT_PAGER= \
123 git diff --exit-code tracked)
125 cat > diff-index-cached.expected
<<\EOF
126 :000000 100644 0000000000000000000000000000000000000000 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 A sub
/dir
/tracked
128 cat > diff-index.expected
<<\EOF
129 :000000 100644 0000000000000000000000000000000000000000 0000000000000000000000000000000000000000 A sub
/dir
/tracked
133 test_expect_success
'git diff-index' '
134 GIT_DIR=repo.git GIT_WORK_TREE=repo.git/work git diff-index $EMPTY_TREE > result &&
135 test_cmp diff-index.expected result &&
136 GIT_DIR=repo.git git diff-index --cached $EMPTY_TREE > result &&
137 test_cmp diff-index-cached.expected result
139 cat >diff-files.expected
<<\EOF
140 :100644 100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
0000000000000000000000000000000000000000 M sub
/dir
/tracked
143 test_expect_success
'git diff-files' '
144 GIT_DIR=repo.git GIT_WORK_TREE=repo.git/work git diff-files > result &&
145 test_cmp diff-files.expected result
148 cat >diff-TREE.expected
<<\EOF
149 diff --git a
/sub
/dir
/tracked b
/sub
/dir
/tracked
151 index
0000000.
.5ea2ed4
153 +++ b
/sub
/dir
/tracked
157 cat >diff-TREE-cached.expected
<<\EOF
158 diff --git a
/sub
/dir
/tracked b
/sub
/dir
/tracked
160 index
0000000..e69de29
162 cat >diff-FILES.expected
<<\EOF
163 diff --git a
/sub
/dir
/tracked b
/sub
/dir
/tracked
164 index e69de29.
.5ea2ed4
100644
165 --- a
/sub
/dir
/tracked
166 +++ b
/sub
/dir
/tracked
171 test_expect_success
'git diff' '
172 GIT_DIR=repo.git GIT_WORK_TREE=repo.git/work git diff $EMPTY_TREE > result &&
173 test_cmp diff-TREE.expected result &&
174 GIT_DIR=repo.git git diff --cached $EMPTY_TREE > result &&
175 test_cmp diff-TREE-cached.expected result &&
176 GIT_DIR=repo.git GIT_WORK_TREE=repo.git/work git diff > result &&
177 test_cmp diff-FILES.expected result
180 test_expect_success
'git grep' '
181 (cd repo.git/work/sub &&
182 GIT_DIR=../.. GIT_WORK_TREE=.. git grep -l changed | grep dir/tracked)
185 test_expect_success
'git commit' '
188 GIT_DIR=. GIT_WORK_TREE=work git commit -a -m done
192 test_expect_success
'absolute pathspec should fail gracefully' '
194 cd repo.git || exit 1
195 git config --unset core.worktree
196 test_must_fail git log HEAD -- /home
200 test_expect_success
'make_relative_path handles double slashes in GIT_DIR' '
202 echo git --git-dir="$(pwd)//repo.git" --work-tree="$(pwd)" add dummy_file &&
203 git --git-dir="$(pwd)//repo.git" --work-tree="$(pwd)" add dummy_file