]>
Commit | Line | Data |
---|---|---|
52030836 NTND |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2008 Nguyễn Thái Ngọc Duy | |
4 | # | |
5 | ||
6 | test_description='test worktree writing operations when skip-worktree is used' | |
7 | ||
8 | . ./test-lib.sh | |
9 | ||
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 | |
17 | ' | |
18 | ||
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 | |
26 | ' | |
27 | ||
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 | |
36 | ' | |
37 | ||
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 | |
44 | ' | |
45 | ||
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 | |
54 | ' | |
55 | ||
52030836 NTND |
56 | setup_absent() { |
57 | test -f 1 && rm 1 | |
58 | git update-index --remove 1 && | |
378932d3 | 59 | git update-index --add --cacheinfo 100644 $EMPTY_BLOB 1 && |
52030836 NTND |
60 | git update-index --skip-worktree 1 |
61 | } | |
62 | ||
63 | test_absent() { | |
378932d3 | 64 | echo "100644 $EMPTY_BLOB 0 1" > expected && |
52030836 NTND |
65 | git ls-files --stage 1 > result && |
66 | test_cmp expected result && | |
67 | test ! -f 1 | |
68 | } | |
69 | ||
70 | setup_dirty() { | |
71 | git update-index --force-remove 1 && | |
72 | echo dirty > 1 && | |
378932d3 | 73 | git update-index --add --cacheinfo 100644 $EMPTY_BLOB 1 && |
52030836 NTND |
74 | git update-index --skip-worktree 1 |
75 | } | |
76 | ||
77 | test_dirty() { | |
378932d3 | 78 | echo "100644 $EMPTY_BLOB 0 1" > expected && |
52030836 NTND |
79 | git ls-files --stage 1 > result && |
80 | test_cmp expected result && | |
81 | echo dirty > expected | |
82 | test_cmp expected 1 | |
83 | } | |
84 | ||
85 | cat >expected <<EOF | |
86 | S 1 | |
87 | H 2 | |
88 | H init.t | |
89 | S sub/1 | |
90 | H sub/2 | |
91 | EOF | |
92 | ||
93 | test_expect_success 'index setup' ' | |
94 | git checkout -f init && | |
95 | mkdir sub && | |
96 | touch ./1 ./2 sub/1 sub/2 && | |
97 | git add 1 2 sub/1 sub/2 && | |
98 | git update-index --skip-worktree 1 sub/1 && | |
99 | git ls-files -t > result && | |
100 | test_cmp expected result | |
101 | ' | |
102 | ||
103 | test_expect_success 'git-add ignores worktree content' ' | |
104 | setup_absent && | |
105 | git add 1 && | |
106 | test_absent | |
107 | ' | |
108 | ||
109 | test_expect_success 'git-add ignores worktree content' ' | |
110 | setup_dirty && | |
111 | git add 1 && | |
112 | test_dirty | |
113 | ' | |
114 | ||
115 | test_expect_success 'git-rm fails if worktree is dirty' ' | |
116 | setup_dirty && | |
117 | test_must_fail git rm 1 && | |
118 | test_dirty | |
119 | ' | |
120 | ||
121 | cat >expected <<EOF | |
122 | Would remove expected | |
123 | Would remove result | |
124 | EOF | |
b3e1900a | 125 | test_expect_success 'git-clean, absent case' ' |
52030836 NTND |
126 | setup_absent && |
127 | git clean -n > result && | |
1108cea7 | 128 | test_cmp expected result |
52030836 NTND |
129 | ' |
130 | ||
b3e1900a | 131 | test_expect_success 'git-clean, dirty case' ' |
52030836 NTND |
132 | setup_dirty && |
133 | git clean -n > result && | |
1108cea7 | 134 | test_cmp expected result |
52030836 NTND |
135 | ' |
136 | ||
8dfb04ae JS |
137 | test_expect_success '--ignore-skip-worktree-entries leaves worktree alone' ' |
138 | test_commit keep-me && | |
139 | git update-index --skip-worktree keep-me.t && | |
140 | rm keep-me.t && | |
141 | ||
142 | : ignoring the worktree && | |
143 | git update-index --remove --ignore-skip-worktree-entries keep-me.t && | |
144 | git diff-index --cached --exit-code HEAD && | |
145 | ||
146 | : not ignoring the worktree, a deletion is staged && | |
147 | git update-index --remove keep-me.t && | |
148 | test_must_fail git diff-index --cached --exit-code HEAD \ | |
149 | --diff-filter=D -- keep-me.t | |
150 | ' | |
151 | ||
ba359fd5 | 152 | test_expect_success 'stash restore in sparse checkout' ' |
a31e48d3 EN |
153 | test_create_repo stash-restore && |
154 | ( | |
155 | cd stash-restore && | |
156 | ||
157 | mkdir subdir && | |
158 | echo A >subdir/A && | |
159 | echo untouched >untouched && | |
160 | echo removeme >removeme && | |
161 | echo modified >modified && | |
162 | git add . && | |
163 | git commit -m Initial && | |
164 | ||
165 | echo AA >>subdir/A && | |
166 | echo addme >addme && | |
167 | echo tweaked >>modified && | |
168 | rm removeme && | |
169 | git add addme && | |
170 | ||
171 | git stash push && | |
172 | ||
173 | git sparse-checkout set subdir && | |
174 | ||
175 | # Ensure after sparse-checkout we only have expected files | |
176 | cat >expect <<-EOF && | |
177 | S modified | |
178 | S removeme | |
179 | H subdir/A | |
180 | S untouched | |
181 | EOF | |
182 | git ls-files -t >actual && | |
183 | test_cmp expect actual && | |
184 | ||
185 | test_path_is_missing addme && | |
186 | test_path_is_missing modified && | |
187 | test_path_is_missing removeme && | |
188 | test_path_is_file subdir/A && | |
189 | test_path_is_missing untouched && | |
190 | ||
191 | # Put a file in the working directory in the way | |
192 | echo in the way >modified && | |
193 | git stash apply && | |
194 | ||
195 | # Ensure stash vivifies modifies paths... | |
196 | cat >expect <<-EOF && | |
197 | H addme | |
198 | H modified | |
199 | H removeme | |
200 | H subdir/A | |
201 | S untouched | |
202 | EOF | |
203 | git ls-files -t >actual && | |
204 | test_cmp expect actual && | |
205 | ||
206 | # ...and that the paths show up in status as changed... | |
207 | cat >expect <<-EOF && | |
208 | A addme | |
209 | M modified | |
210 | D removeme | |
211 | M subdir/A | |
212 | ?? actual | |
213 | ?? expect | |
214 | ?? modified.stash.XXXXXX | |
215 | EOF | |
216 | git status --porcelain | \ | |
217 | sed -e s/stash......./stash.XXXXXX/ >actual && | |
218 | test_cmp expect actual && | |
219 | ||
220 | # ...and that working directory reflects the files correctly | |
221 | test_path_is_file addme && | |
222 | test_path_is_file modified && | |
223 | test_path_is_missing removeme && | |
224 | test_path_is_file subdir/A && | |
225 | test_path_is_missing untouched && | |
226 | ||
227 | # ...including that we have the expected "modified" file... | |
228 | cat >expect <<-EOF && | |
229 | modified | |
230 | tweaked | |
231 | EOF | |
232 | test_cmp expect modified && | |
233 | ||
234 | # ...and that the other "modified" file is still present... | |
235 | echo in the way >expect && | |
236 | test_cmp expect modified.stash.* | |
237 | ) | |
238 | ' | |
239 | ||
3d816767 MG |
240 | #TODO test_expect_failure 'git-apply adds file' false |
241 | #TODO test_expect_failure 'git-apply updates file' false | |
242 | #TODO test_expect_failure 'git-apply removes file' false | |
243 | #TODO test_expect_failure 'git-mv to skip-worktree' false | |
244 | #TODO test_expect_failure 'git-mv from skip-worktree' false | |
245 | #TODO test_expect_failure 'git-checkout' false | |
52030836 NTND |
246 | |
247 | test_done |