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' '
203 test_expect_success
'checkout gives cache-tree' '
205 git checkout HEAD^ &&
209 test_expect_success
'checkout -b gives cache-tree' '
210 git checkout current &&
211 git checkout -b prev HEAD^ &&
215 test_expect_success
'checkout -B gives cache-tree' '
216 git checkout current &&
217 git checkout -B prev HEAD^ &&
221 test_expect_success
'merge --ff-only maintains cache-tree' '
222 git checkout current &&
223 git checkout -b changes &&
224 test_commit llamas &&
225 test_commit pachyderm &&
227 git checkout current &&
229 git merge --ff-only changes &&
233 test_expect_success
'merge maintains cache-tree' '
234 git checkout current &&
235 git checkout -b changes2 &&
236 test_commit alpacas &&
238 git checkout current &&
239 test_commit struthio &&
241 git merge changes2 &&
245 test_expect_success
'partial commit gives cache-tree' '
246 git checkout -b partial no-children &&
249 echo "some change" >one.t &&
251 echo "some other change" >two.t &&
252 git commit two.t -m partial &&
253 cat <<-\EOF >expected.status &&
256 test_cache_tree expected.status
259 test_expect_success
'no phantom error when switching trees' '
262 git add newdir/one &&
263 git checkout 2>errors &&
264 test_must_be_empty errors
267 test_expect_success
'switching trees does not invalidate shared index' '
269 sane_unset GIT_TEST_SPLIT_INDEX &&
270 git update-index --split-index &&
273 test-tool dump-split-index .git/index | grep -v ^own >before &&
274 git commit -m "as-is" &&
275 test-tool dump-split-index .git/index | grep -v ^own >after &&
276 test_cmp before after