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"
36 GIT_CONFIG="$(pwd)"/$GIT_DIR/config
37 export GIT_DIR GIT_CONFIG
39 git config core.worktree ../work
40 test_rev_parse 'outside' false false false
43 GIT_CONFIG="$(pwd)"/$GIT_DIR/config
44 test_rev_parse 'inside' false false true ''
46 GIT_DIR=../../../repo.git
47 GIT_CONFIG="$(pwd)"/$GIT_DIR/config
48 test_rev_parse 'subdirectory' false false true sub/dir/
51 say "core.worktree = absolute path"
52 GIT_DIR=$(pwd)/repo.git
53 GIT_CONFIG=$GIT_DIR/config
54 git config core.worktree "$(pwd)/work"
55 test_rev_parse 'outside' false false false
57 test_rev_parse 'inside' false false true ''
59 test_rev_parse 'subdirectory' false false true sub/dir/
62 say "GIT_WORK_TREE=relative path (override core.worktree)"
63 GIT_DIR=$(pwd)/repo.git
64 GIT_CONFIG=$GIT_DIR/config
65 git config core.worktree non-existent
68 test_rev_parse 'outside' false false false
71 test_rev_parse 'inside' false false true ''
74 test_rev_parse 'subdirectory' false false true sub/dir/
79 say "GIT_WORK_TREE=absolute path, work tree below git dir"
80 GIT_DIR=$(pwd)/repo.git
81 GIT_CONFIG=$GIT_DIR/config
82 GIT_WORK_TREE=$(pwd)/repo.git/work
83 test_rev_parse 'outside' false false false
85 test_rev_parse 'in repo.git' false true false
87 test_rev_parse 'in repo.git/objects' false true false
89 test_rev_parse 'in repo.git/work' false true true ''
91 test_rev_parse 'in repo.git/sub/dir' false true true sub/dir/
92 cd ../../../.. || exit 1
94 test_expect_success 'repo finds its work tree' '
96 : > work/sub/dir/untracked &&
97 test sub/dir/untracked = "$(git ls-files --others)")
100 test_expect_success 'repo finds its work tree from work tree, too' '
101 (cd repo.git/work/sub/dir &&
103 git --git-dir=../../.. add tracked &&
105 test sub/dir/tracked = "$(git ls-files)")
108 test_expect_success '_gently() groks relative GIT_DIR & GIT_WORK_TREE' '
109 cd repo.git/work/sub/dir &&
110 GIT_DIR=../../.. GIT_WORK_TREE=../.. GIT_PAGER= \
111 git diff --exit-code tracked &&
112 echo changed > tracked &&
113 ! GIT_DIR=../../.. GIT_WORK_TREE=../.. GIT_PAGER= \
114 git diff --exit-code tracked