Merge branch 'ab/retire-refs-unused-funcs'
[git/debian.git] / t / t7012-skip-worktree-writing.sh
bloba1080b94e388aef309c958e9ca7d6150e2577b06
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-lib.sh
10 test_expect_success 'setup' '
11 test_commit init &&
12 echo modified >> init.t &&
13 touch added &&
14 git add init.t added &&
15 git commit -m "modified and added" &&
16 git tag top
19 test_expect_success 'read-tree updates worktree, absent case' '
20 git checkout -f top &&
21 git update-index --skip-worktree init.t &&
22 rm 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 &&
41 rm added &&
42 git read-tree -m -u HEAD^ &&
43 test ! -f added
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
56 setup_absent() {
57 test -f 1 && rm 1
58 git update-index --remove 1 &&
59 git update-index --add --cacheinfo 100644 $EMPTY_BLOB 1 &&
60 git update-index --skip-worktree 1
63 setup_dirty() {
64 git update-index --force-remove 1 &&
65 echo dirty > 1 &&
66 git update-index --add --cacheinfo 100644 $EMPTY_BLOB 1 &&
67 git update-index --skip-worktree 1
70 test_dirty() {
71 echo "100644 $EMPTY_BLOB 0 1" > expected &&
72 git ls-files --stage 1 > result &&
73 test_cmp expected result &&
74 echo dirty > expected
75 test_cmp expected 1
78 cat >expected <<EOF
79 S 1
80 H 2
81 H init.t
82 S sub/1
83 H sub/2
84 EOF
86 test_expect_success 'index setup' '
87 git checkout -f init &&
88 mkdir sub &&
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' '
97 setup_dirty &&
98 test_must_fail git rm 1 &&
99 test_dirty
102 cat >expected <<EOF
103 Would remove expected
104 Would remove result
106 test_expect_success 'git-clean, absent case' '
107 setup_absent &&
108 git clean -n > result &&
109 test_cmp expected result
112 test_expect_success 'git-clean, dirty case' '
113 setup_dirty &&
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 &&
121 rm 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 &&
136 cd stash-restore &&
138 mkdir subdir &&
139 echo A >subdir/A &&
140 echo untouched >untouched &&
141 echo removeme >removeme &&
142 echo modified >modified &&
143 git add . &&
144 git commit -m Initial &&
146 echo AA >>subdir/A &&
147 echo addme >addme &&
148 echo tweaked >>modified &&
149 rm removeme &&
150 git add addme &&
152 git stash push &&
154 git sparse-checkout set subdir &&
156 # Ensure after sparse-checkout we only have expected files
157 cat >expect <<-EOF &&
158 S modified
159 S removeme
160 H subdir/A
161 S untouched
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 git stash apply &&
176 # Ensure stash vivifies modifies paths...
177 cat >expect <<-EOF &&
178 H addme
179 H modified
180 H removeme
181 H subdir/A
182 S untouched
184 git ls-files -t >actual &&
185 test_cmp expect actual &&
187 # ...and that the paths show up in status as changed...
188 cat >expect <<-EOF &&
189 A addme
190 M modified
191 D removeme
192 M subdir/A
193 ?? actual
194 ?? expect
195 ?? modified.stash.XXXXXX
197 git status --porcelain | \
198 sed -e s/stash......./stash.XXXXXX/ >actual &&
199 test_cmp expect actual &&
201 # ...and that working directory reflects the files correctly
202 test_path_is_file addme &&
203 test_path_is_file modified &&
204 test_path_is_missing removeme &&
205 test_path_is_file subdir/A &&
206 test_path_is_missing untouched &&
208 # ...including that we have the expected "modified" file...
209 cat >expect <<-EOF &&
210 modified
211 tweaked
213 test_cmp expect modified &&
215 # ...and that the other "modified" file is still present...
216 echo in the way >expect &&
217 test_cmp expect modified.stash.*
221 #TODO test_expect_failure 'git-apply adds file' false
222 #TODO test_expect_failure 'git-apply updates file' false
223 #TODO test_expect_failure 'git-apply removes file' false
224 #TODO test_expect_failure 'git-mv to skip-worktree' false
225 #TODO test_expect_failure 'git-mv from skip-worktree' false
226 #TODO test_expect_failure 'git-checkout' false
228 test_done