3 # Copyright (c) 2008 Nguyễn Thái Ngọc Duy
6 test_description
='test worktree writing operations when skip-worktree is used'
8 TEST_PASSES_SANITIZE_LEAK
=true
11 test_expect_success
'setup' '
13 echo modified >> init.t &&
15 git add init.t added &&
16 git commit -m "modified and added" &&
20 test_expect_success
'read-tree updates worktree, absent case' '
21 git checkout -f top &&
22 git update-index --skip-worktree init.t &&
24 git read-tree -m -u HEAD^ &&
25 echo init > expected &&
26 test_cmp expected init.t
29 test_expect_success
'read-tree updates worktree, dirty case' '
30 git checkout -f top &&
31 git update-index --skip-worktree init.t &&
32 echo dirty >> init.t &&
33 test_must_fail git read-tree -m -u HEAD^ &&
34 grep -q dirty init.t &&
35 test "$(git ls-files -t init.t)" = "S init.t" &&
36 git update-index --no-skip-worktree init.t
39 test_expect_success
'read-tree removes worktree, absent case' '
40 git checkout -f top &&
41 git update-index --skip-worktree added &&
43 git read-tree -m -u HEAD^ &&
47 test_expect_success
'read-tree removes worktree, dirty case' '
48 git checkout -f top &&
49 git update-index --skip-worktree added &&
50 echo dirty >> added &&
51 test_must_fail git read-tree -m -u HEAD^ &&
52 grep -q dirty added &&
53 test "$(git ls-files -t added)" = "S added" &&
54 git update-index --no-skip-worktree added
59 git update-index
--remove 1 &&
60 git update-index
--add --cacheinfo 100644 $EMPTY_BLOB 1 &&
61 git update-index
--skip-worktree 1
65 git update-index
--force-remove 1 &&
67 git update-index
--add --cacheinfo 100644 $EMPTY_BLOB 1 &&
68 git update-index
--skip-worktree 1
72 echo "100644 $EMPTY_BLOB 0 1" > expected
&&
73 git ls-files
--stage 1 > result
&&
74 test_cmp expected result
&&
87 test_expect_success
'index setup' '
88 git checkout -f init &&
90 touch ./1 ./2 sub/1 sub/2 &&
91 git add 1 2 sub/1 sub/2 &&
92 git update-index --skip-worktree 1 sub/1 &&
93 git ls-files -t > result &&
94 test_cmp expected result
97 test_expect_success
'git-rm fails if worktree is dirty' '
99 test_must_fail git rm 1 &&
104 Would remove expected
107 test_expect_success
'git-clean, absent case' '
109 git clean -n > result &&
110 test_cmp expected result
113 test_expect_success
'git-clean, dirty case' '
115 git clean -n > result &&
116 test_cmp expected result
119 test_expect_success
'--ignore-skip-worktree-entries leaves worktree alone' '
120 test_commit keep-me &&
121 git update-index --skip-worktree keep-me.t &&
124 : ignoring the worktree &&
125 git update-index --remove --ignore-skip-worktree-entries keep-me.t &&
126 git diff-index --cached --exit-code HEAD &&
128 : not ignoring the worktree, a deletion is staged &&
129 git update-index --remove keep-me.t &&
130 test_must_fail git diff-index --cached --exit-code HEAD \
131 --diff-filter=D -- keep-me.t
134 test_expect_success
'stash restore in sparse checkout' '
135 test_create_repo stash-restore &&
141 echo untouched >untouched &&
142 echo removeme >removeme &&
143 echo modified >modified &&
145 git commit -m Initial &&
147 echo AA >>subdir/A &&
149 echo tweaked >>modified &&
155 git sparse-checkout set --no-cone subdir &&
157 # Ensure after sparse-checkout we only have expected files
158 cat >expect <<-EOF &&
164 git ls-files -t >actual &&
165 test_cmp expect actual &&
167 test_path_is_missing addme &&
168 test_path_is_missing modified &&
169 test_path_is_missing removeme &&
170 test_path_is_file subdir/A &&
171 test_path_is_missing untouched &&
173 # Put a file in the working directory in the way
174 echo in the way >modified &&
175 test_must_fail git stash apply 2>error&&
177 grep "changes.*would be overwritten by merge" error &&
179 echo in the way >expect &&
180 test_cmp expect modified &&
181 git diff --quiet HEAD ":!modified" &&
183 # ...and that working directory reflects the files correctly
184 test_path_is_missing addme &&
185 test_path_is_file modified &&
186 test_path_is_missing removeme &&
187 test_path_is_file subdir/A &&
188 test_path_is_missing untouched
192 #TODO test_expect_failure 'git-apply adds file' false
193 #TODO test_expect_failure 'git-apply updates file' false
194 #TODO test_expect_failure 'git-apply removes file' false
195 #TODO test_expect_failure 'git-mv to skip-worktree' false
196 #TODO test_expect_failure 'git-mv from skip-worktree' false
197 #TODO test_expect_failure 'git-checkout' false