The eleventh batch
[git/gitster.git] / t / t7012-skip-worktree-writing.sh
blobd984200c1733b50ff346e01910e4e3b5a3db331b
1 #!/bin/sh
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
9 . ./test-lib.sh
11 test_expect_success 'setup' '
12 test_commit init &&
13 echo modified >> init.t &&
14 touch added &&
15 git add init.t added &&
16 git commit -m "modified and added" &&
17 git tag top
20 test_expect_success 'read-tree updates worktree, absent case' '
21 git checkout -f top &&
22 git update-index --skip-worktree init.t &&
23 rm 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 &&
42 rm added &&
43 git read-tree -m -u HEAD^ &&
44 test ! -f added
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
57 setup_absent() {
58 test -f 1 && rm 1
59 git update-index --remove 1 &&
60 git update-index --add --cacheinfo 100644 $EMPTY_BLOB 1 &&
61 git update-index --skip-worktree 1
64 setup_dirty() {
65 git update-index --force-remove 1 &&
66 echo dirty > 1 &&
67 git update-index --add --cacheinfo 100644 $EMPTY_BLOB 1 &&
68 git update-index --skip-worktree 1
71 test_dirty() {
72 echo "100644 $EMPTY_BLOB 0 1" > expected &&
73 git ls-files --stage 1 > result &&
74 test_cmp expected result &&
75 echo dirty > expected
76 test_cmp expected 1
79 cat >expected <<EOF
80 S 1
81 H 2
82 H init.t
83 S sub/1
84 H sub/2
85 EOF
87 test_expect_success 'index setup' '
88 git checkout -f init &&
89 mkdir sub &&
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' '
98 setup_dirty &&
99 test_must_fail git rm 1 &&
100 test_dirty
103 cat >expected <<EOF
104 Would remove expected
105 Would remove result
107 test_expect_success 'git-clean, absent case' '
108 setup_absent &&
109 git clean -n > result &&
110 test_cmp expected result
113 test_expect_success 'git-clean, dirty case' '
114 setup_dirty &&
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 &&
122 rm 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 &&
137 cd stash-restore &&
139 mkdir subdir &&
140 echo A >subdir/A &&
141 echo untouched >untouched &&
142 echo removeme >removeme &&
143 echo modified >modified &&
144 git add . &&
145 git commit -m Initial &&
147 echo AA >>subdir/A &&
148 echo addme >addme &&
149 echo tweaked >>modified &&
150 rm removeme &&
151 git add addme &&
153 git stash push &&
155 git sparse-checkout set --no-cone subdir &&
157 # Ensure after sparse-checkout we only have expected files
158 cat >expect <<-EOF &&
159 S modified
160 S removeme
161 H subdir/A
162 S untouched
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
199 test_done