3 test_description
="Test whether cache-tree is properly updated
5 Tests whether various commands properly update and/or rewrite the
9 TEST_PASSES_SANITIZE_LEAK
=true
13 test-tool dump-cache-tree |
sed -e '/#(ref)/d' >actual
&&
14 sed "s/$OID_REGEX/SHA/" <actual
>filtered
&&
15 test_cmp
"$1" filtered
&&
19 # We don't bother with actually checking the SHA1:
20 # test-tool dump-cache-tree already verifies that all existing data is
22 generate_expected_cache_tree
() {
25 git ls-tree
--name-only HEAD
-- "$pathspec" >files
&&
26 git ls-tree
--name-only -d HEAD
-- "$pathspec" >subtrees
&&
27 printf "SHA %s (%d entries, %d subtrees)\n" "$dir" $
(wc -l <files
) $
(wc -l <subtrees
) &&
30 generate_expected_cache_tree
"$pathspec/$subtree/" "$subtree" ||
return 1
35 generate_expected_cache_tree
"." >expect
&&
36 cmp_cache_tree expect
&&
37 rm expect actual files subtrees
&&
38 git status
--porcelain -- ':!status' ':!expected.status' >status
&&
43 test_must_be_empty status
47 test_invalid_cache_tree
() {
48 printf "invalid %s ()\n" "" "$@" >expect
&&
49 test-tool dump-cache-tree |
50 sed -n -e "s/[0-9]* subtrees//" -e '/#(ref)/d' -e '/^invalid /p' >actual
&&
51 test_cmp expect actual
54 test_no_cache_tree
() {
59 test_expect_success
'initial commit has cache-tree' '
64 test_expect_success
'read-tree HEAD establishes cache-tree' '
69 test_expect_success
'git-add invalidates cache-tree' '
70 test_when_finished "git reset --hard; git read-tree HEAD" &&
71 echo "I changed this file" >foo &&
73 test_invalid_cache_tree
76 test_expect_success
'git-add in subdir invalidates cache-tree' '
77 test_when_finished "git reset --hard; git read-tree HEAD" &&
79 echo "I changed this file" >dirx/foo &&
81 test_invalid_cache_tree
84 test_expect_success
'git-add in subdir does not invalidate sibling cache-tree' '
85 git tag no-children &&
86 test_when_finished "git reset --hard no-children; git read-tree HEAD" &&
90 echo "I changed this file" >dir1/a &&
91 test_when_finished "rm before" &&
92 cat >before <<-\EOF &&
93 SHA (3 entries, 2 subtrees)
94 SHA dir1/ (1 entries, 0 subtrees)
95 SHA dir2/ (1 entries, 0 subtrees)
97 cmp_cache_tree before &&
98 echo "I changed this file" >dir1/a &&
100 cat >expect <<-\EOF &&
102 invalid dir1/ (0 subtrees)
103 SHA dir2/ (1 entries, 0 subtrees)
105 cmp_cache_tree expect
108 test_expect_success
'update-index invalidates cache-tree' '
109 test_when_finished "git reset --hard; git read-tree HEAD" &&
110 echo "I changed this file" >foo &&
111 git update-index --add foo &&
112 test_invalid_cache_tree
115 test_expect_success
'write-tree establishes cache-tree' '
116 test-tool scrap-cache-tree &&
121 test_expect_success
'test-tool scrap-cache-tree works' '
122 git read-tree HEAD &&
123 test-tool scrap-cache-tree &&
127 test_expect_success
'second commit has cache-tree' '
132 test_expect_success PERL
'commit --interactive gives cache-tree on partial commit' '
133 test_when_finished "git reset --hard" &&
134 cat <<-\EOT >foo.c &&
145 test_invalid_cache_tree &&
146 git commit -m "add a file" &&
148 cat <<-\EOT >foo.c &&
158 test_write_lines p 1 "" s n y q |
159 git commit --interactive -m foo &&
160 cat <<-\EOF >expected.status &&
163 test_cache_tree expected.status
166 test_expect_success PERL
'commit -p with shrinking cache-tree' '
167 mkdir -p deep/very-long-subdir &&
168 echo content >deep/very-long-subdir/file &&
173 before=$(wc -c <.git/index) &&
174 git commit -m delete -p &&
175 after=$(wc -c <.git/index) &&
177 # double check that the index shrank
178 test $before -gt $after &&
180 # and that our index was not corrupted
184 test_expect_success
'commit in child dir has cache-tree' '
187 git add dir/child.t &&
188 git commit -m dir/child.t &&
192 test_expect_success
'reset --hard gives cache-tree' '
193 test-tool scrap-cache-tree &&
198 test_expect_success
'reset --hard without index gives cache-tree' '
205 test_expect_success
'checkout gives cache-tree' '
207 git checkout HEAD^ &&
211 test_expect_success
'checkout -b gives cache-tree' '
212 git checkout current &&
213 git checkout -b prev HEAD^ &&
217 test_expect_success
'checkout -B gives cache-tree' '
218 git checkout current &&
219 git checkout -B prev HEAD^ &&
223 test_expect_success
'merge --ff-only maintains cache-tree' '
224 git checkout current &&
225 git checkout -b changes &&
226 test_commit llamas &&
227 test_commit pachyderm &&
229 git checkout current &&
231 git merge --ff-only changes &&
235 test_expect_success
'merge maintains cache-tree' '
236 git checkout current &&
237 git checkout -b changes2 &&
238 test_commit alpacas &&
240 git checkout current &&
241 test_commit struthio &&
243 git merge changes2 &&
247 test_expect_success
'partial commit gives cache-tree' '
248 git checkout -b partial no-children &&
251 echo "some change" >one.t &&
253 echo "some other change" >two.t &&
254 git commit two.t -m partial &&
255 cat <<-\EOF >expected.status &&
258 test_cache_tree expected.status
261 test_expect_success
'no phantom error when switching trees' '
264 git add newdir/one &&
265 git checkout 2>errors &&
266 test_must_be_empty errors
269 test_expect_success
'switching trees does not invalidate shared index' '
271 sane_unset GIT_TEST_SPLIT_INDEX &&
272 git update-index --split-index &&
275 test-tool dump-split-index .git/index | grep -v ^own >before &&
276 git commit -m "as-is" &&
277 test-tool dump-split-index .git/index | grep -v ^own >after &&
278 test_cmp before after