3 test_description
="Test whether cache-tree is properly updated
5 Tests whether various commands properly update and/or rewrite the
11 test-tool dump-cache-tree |
sed -e '/#(ref)/d' >actual
&&
12 sed "s/$OID_REGEX/SHA/" <actual
>filtered
&&
13 test_cmp
"$1" filtered
&&
17 # We don't bother with actually checking the SHA1:
18 # test-tool dump-cache-tree already verifies that all existing data is
20 generate_expected_cache_tree
() {
23 git ls-tree
--name-only HEAD
-- "$pathspec" >files
&&
24 git ls-tree
--name-only -d HEAD
-- "$pathspec" >subtrees
&&
25 printf "SHA %s (%d entries, %d subtrees)\n" "$dir" $
(wc -l <files
) $
(wc -l <subtrees
) &&
28 generate_expected_cache_tree
"$pathspec/$subtree/" "$subtree" ||
return 1
33 generate_expected_cache_tree
"." >expect
&&
34 cmp_cache_tree expect
&&
35 rm expect actual files subtrees
&&
36 git status
--porcelain -- ':!status' ':!expected.status' >status
&&
41 test_must_be_empty status
45 test_invalid_cache_tree
() {
46 printf "invalid %s ()\n" "" "$@" >expect
&&
47 test-tool dump-cache-tree |
48 sed -n -e "s/[0-9]* subtrees//" -e '/#(ref)/d' -e '/^invalid /p' >actual
&&
49 test_cmp expect actual
52 test_no_cache_tree
() {
57 test_expect_success
'initial commit has cache-tree' '
62 test_expect_success
'read-tree HEAD establishes cache-tree' '
67 test_expect_success
'git-add invalidates cache-tree' '
68 test_when_finished "git reset --hard; git read-tree HEAD" &&
69 echo "I changed this file" >foo &&
71 test_invalid_cache_tree
74 test_expect_success
'git-add in subdir invalidates cache-tree' '
75 test_when_finished "git reset --hard; git read-tree HEAD" &&
77 echo "I changed this file" >dirx/foo &&
79 test_invalid_cache_tree
82 test_expect_success
'git-add in subdir does not invalidate sibling cache-tree' '
83 git tag no-children &&
84 test_when_finished "git reset --hard no-children; git read-tree HEAD" &&
88 echo "I changed this file" >dir1/a &&
89 test_when_finished "rm before" &&
90 cat >before <<-\EOF &&
91 SHA (3 entries, 2 subtrees)
92 SHA dir1/ (1 entries, 0 subtrees)
93 SHA dir2/ (1 entries, 0 subtrees)
95 cmp_cache_tree before &&
96 echo "I changed this file" >dir1/a &&
98 cat >expect <<-\EOF &&
100 invalid dir1/ (0 subtrees)
101 SHA dir2/ (1 entries, 0 subtrees)
103 cmp_cache_tree expect
106 test_expect_success
'update-index invalidates cache-tree' '
107 test_when_finished "git reset --hard; git read-tree HEAD" &&
108 echo "I changed this file" >foo &&
109 git update-index --add foo &&
110 test_invalid_cache_tree
113 test_expect_success
'write-tree establishes cache-tree' '
114 test-tool scrap-cache-tree &&
119 test_expect_success
'test-tool scrap-cache-tree works' '
120 git read-tree HEAD &&
121 test-tool scrap-cache-tree &&
125 test_expect_success
'second commit has cache-tree' '
130 test_expect_success PERL
'commit --interactive gives cache-tree on partial commit' '
131 test_when_finished "git reset --hard" &&
132 cat <<-\EOT >foo.c &&
143 test_invalid_cache_tree &&
144 git commit -m "add a file" &&
146 cat <<-\EOT >foo.c &&
156 test_write_lines p 1 "" s n y q |
157 git commit --interactive -m foo &&
158 cat <<-\EOF >expected.status &&
161 test_cache_tree expected.status
164 test_expect_success PERL
'commit -p with shrinking cache-tree' '
165 mkdir -p deep/very-long-subdir &&
166 echo content >deep/very-long-subdir/file &&
171 before=$(wc -c <.git/index) &&
172 git commit -m delete -p &&
173 after=$(wc -c <.git/index) &&
175 # double check that the index shrank
176 test $before -gt $after &&
178 # and that our index was not corrupted
182 test_expect_success
'commit in child dir has cache-tree' '
185 git add dir/child.t &&
186 git commit -m dir/child.t &&
190 test_expect_success
'reset --hard gives cache-tree' '
191 test-tool scrap-cache-tree &&
196 test_expect_success
'reset --hard without index gives cache-tree' '
202 test_expect_success
'checkout gives cache-tree' '
204 git checkout HEAD^ &&
208 test_expect_success
'checkout -b gives cache-tree' '
209 git checkout current &&
210 git checkout -b prev HEAD^ &&
214 test_expect_success
'checkout -B gives cache-tree' '
215 git checkout current &&
216 git checkout -B prev HEAD^ &&
220 test_expect_success
'merge --ff-only maintains cache-tree' '
221 git checkout current &&
222 git checkout -b changes &&
223 test_commit llamas &&
224 test_commit pachyderm &&
226 git checkout current &&
228 git merge --ff-only changes &&
232 test_expect_success
'merge maintains cache-tree' '
233 git checkout current &&
234 git checkout -b changes2 &&
235 test_commit alpacas &&
237 git checkout current &&
238 test_commit struthio &&
240 git merge changes2 &&
244 test_expect_success
'partial commit gives cache-tree' '
245 git checkout -b partial no-children &&
248 echo "some change" >one.t &&
250 echo "some other change" >two.t &&
251 git commit two.t -m partial &&
252 cat <<-\EOF >expected.status &&
255 test_cache_tree expected.status
258 test_expect_success
'no phantom error when switching trees' '
261 git add newdir/one &&
262 git checkout 2>errors &&
263 test_must_be_empty errors
266 test_expect_success
'switching trees does not invalidate shared index' '
268 sane_unset GIT_TEST_SPLIT_INDEX &&
269 git update-index --split-index &&
272 test-tool dump-split-index .git/index | grep -v ^own >before &&
273 git commit -m "as-is" &&
274 test-tool dump-split-index .git/index | grep -v ^own >after &&
275 test_cmp before after