3 # Copyright (c) 2008 Nguyễn Thái Ngọc Duy
6 test_description
='test worktree writing operations when skip-worktree is used'
10 test_expect_success
'setup' '
12 echo modified >> init.t &&
14 git add init.t added &&
15 git commit -m "modified and added" &&
19 test_expect_success
'read-tree updates worktree, absent case' '
20 git checkout -f top &&
21 git update-index --skip-worktree init.t &&
23 git read-tree -m -u HEAD^ &&
24 echo init > expected &&
25 test_cmp expected init.t
28 test_expect_success
'read-tree updates worktree, dirty case' '
29 git checkout -f top &&
30 git update-index --skip-worktree init.t &&
31 echo dirty >> init.t &&
32 test_must_fail git read-tree -m -u HEAD^ &&
33 grep -q dirty init.t &&
34 test "$(git ls-files -t init.t)" = "S init.t" &&
35 git update-index --no-skip-worktree init.t
38 test_expect_success
'read-tree removes worktree, absent case' '
39 git checkout -f top &&
40 git update-index --skip-worktree added &&
42 git read-tree -m -u HEAD^ &&
46 test_expect_success
'read-tree removes worktree, dirty case' '
47 git checkout -f top &&
48 git update-index --skip-worktree added &&
49 echo dirty >> added &&
50 test_must_fail git read-tree -m -u HEAD^ &&
51 grep -q dirty added &&
52 test "$(git ls-files -t added)" = "S added" &&
53 git update-index --no-skip-worktree added
58 git update-index
--remove 1 &&
59 git update-index
--add --cacheinfo 100644 $EMPTY_BLOB 1 &&
60 git update-index
--skip-worktree 1
64 git update-index
--force-remove 1 &&
66 git update-index
--add --cacheinfo 100644 $EMPTY_BLOB 1 &&
67 git update-index
--skip-worktree 1
71 echo "100644 $EMPTY_BLOB 0 1" > expected
&&
72 git ls-files
--stage 1 > result
&&
73 test_cmp expected result
&&
86 test_expect_success
'index setup' '
87 git checkout -f init &&
89 touch ./1 ./2 sub/1 sub/2 &&
90 git add 1 2 sub/1 sub/2 &&
91 git update-index --skip-worktree 1 sub/1 &&
92 git ls-files -t > result &&
93 test_cmp expected result
96 test_expect_success
'git-rm fails if worktree is dirty' '
98 test_must_fail git rm 1 &&
103 Would remove expected
106 test_expect_success
'git-clean, absent case' '
108 git clean -n > result &&
109 test_cmp expected result
112 test_expect_success
'git-clean, dirty case' '
114 git clean -n > result &&
115 test_cmp expected result
118 test_expect_success
'--ignore-skip-worktree-entries leaves worktree alone' '
119 test_commit keep-me &&
120 git update-index --skip-worktree keep-me.t &&
123 : ignoring the worktree &&
124 git update-index --remove --ignore-skip-worktree-entries keep-me.t &&
125 git diff-index --cached --exit-code HEAD &&
127 : not ignoring the worktree, a deletion is staged &&
128 git update-index --remove keep-me.t &&
129 test_must_fail git diff-index --cached --exit-code HEAD \
130 --diff-filter=D -- keep-me.t
133 test_expect_success
'stash restore in sparse checkout' '
134 test_create_repo stash-restore &&
140 echo untouched >untouched &&
141 echo removeme >removeme &&
142 echo modified >modified &&
144 git commit -m Initial &&
146 echo AA >>subdir/A &&
148 echo tweaked >>modified &&
154 git sparse-checkout set --no-cone subdir &&
156 # Ensure after sparse-checkout we only have expected files
157 cat >expect <<-EOF &&
163 git ls-files -t >actual &&
164 test_cmp expect actual &&
166 test_path_is_missing addme &&
167 test_path_is_missing modified &&
168 test_path_is_missing removeme &&
169 test_path_is_file subdir/A &&
170 test_path_is_missing untouched &&
172 # Put a file in the working directory in the way
173 echo in the way >modified &&
174 test_must_fail git stash apply 2>error&&
176 grep "changes.*would be overwritten by merge" error &&
178 echo in the way >expect &&
179 test_cmp expect modified &&
180 git diff --quiet HEAD ":!modified" &&
182 # ...and that working directory reflects the files correctly
183 test_path_is_missing addme &&
184 test_path_is_file modified &&
185 test_path_is_missing removeme &&
186 test_path_is_file subdir/A &&
187 test_path_is_missing untouched
191 #TODO test_expect_failure 'git-apply adds file' false
192 #TODO test_expect_failure 'git-apply updates file' false
193 #TODO test_expect_failure 'git-apply removes file' false
194 #TODO test_expect_failure 'git-mv to skip-worktree' false
195 #TODO test_expect_failure 'git-mv from skip-worktree' false
196 #TODO test_expect_failure 'git-checkout' false