merge-recursive: demonstrate an incorrect conflict with submodule
[git/dscho.git] / t / t1501-worktree.sh
blobbd8b60732b06365fa22585eb8e97a3b1e64fdd05
1 #!/bin/sh
3 test_description='test separate work tree'
4 . ./test-lib.sh
6 test_rev_parse() {
7 name=$1
8 shift
10 test_expect_success "$name: is-bare-repository" \
11 "test '$1' = \"\$(git rev-parse --is-bare-repository)\""
12 shift
13 [ $# -eq 0 ] && return
15 test_expect_success "$name: is-inside-git-dir" \
16 "test '$1' = \"\$(git rev-parse --is-inside-git-dir)\""
17 shift
18 [ $# -eq 0 ] && return
20 test_expect_success "$name: is-inside-work-tree" \
21 "test '$1' = \"\$(git rev-parse --is-inside-work-tree)\""
22 shift
23 [ $# -eq 0 ] && return
25 test_expect_success "$name: prefix" \
26 "test '$1' = \"\$(git rev-parse --show-prefix)\""
27 shift
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"
37 GIT_DIR=repo.git
38 GIT_CONFIG="$(pwd)"/$GIT_DIR/config
39 export GIT_DIR GIT_CONFIG
40 unset GIT_WORK_TREE
41 git config core.worktree ../work
42 test_rev_parse 'outside' false false false
43 cd work || exit 1
44 GIT_DIR=../repo.git
45 GIT_CONFIG="$(pwd)"/$GIT_DIR/config
46 test_rev_parse 'inside' false false true ''
47 cd sub/dir || exit 1
48 GIT_DIR=../../../repo.git
49 GIT_CONFIG="$(pwd)"/$GIT_DIR/config
50 test_rev_parse 'subdirectory' false false true sub/dir/
51 cd ../../.. || exit 1
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
58 cd work2
59 test_rev_parse 'outside2' false false false
60 cd ../work || exit 1
61 test_rev_parse 'inside' false false true ''
62 cd sub/dir || exit 1
63 test_rev_parse 'subdirectory' false false true sub/dir/
64 cd ../../.. || exit 1
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
70 GIT_WORK_TREE=work
71 export GIT_WORK_TREE
72 test_rev_parse 'outside' false false false
73 cd work2
74 test_rev_parse 'outside' false false false
75 cd ../work || exit 1
76 GIT_WORK_TREE=.
77 test_rev_parse 'inside' false false true ''
78 cd sub/dir || exit 1
79 GIT_WORK_TREE=../..
80 test_rev_parse 'subdirectory' false false true sub/dir/
81 cd ../../.. || exit 1
83 mv work repo.git/work
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
91 cd repo.git || exit 1
92 test_rev_parse 'in repo.git' false true false
93 cd objects || exit 1
94 test_rev_parse 'in repo.git/objects' false true false
95 cd ../work2 || exit 1
96 test_rev_parse 'in repo.git/work2' false true false
97 cd ../work || exit 1
98 test_rev_parse 'in repo.git/work' false true true ''
99 cd sub/dir || exit 1
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' '
104 (cd repo.git &&
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 &&
111 : > tracked &&
112 git --git-dir=../../.. add tracked &&
113 cd ../../.. &&
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
150 new file mode 100644
151 index 0000000..5ea2ed4
152 --- /dev/null
153 +++ b/sub/dir/tracked
154 @@ -0,0 +1 @@
155 +changed
157 cat >diff-TREE-cached.expected <<\EOF
158 diff --git a/sub/dir/tracked b/sub/dir/tracked
159 new file mode 100644
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
167 @@ -0,0 +1 @@
168 +changed
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' '
187 cd repo.git &&
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' '
201 : > dummy_file
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
206 test_done