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_rec () {
22 # ls-files might have foo/bar, foo/bar/baz, and foo/bar/quux
23 # We want to count only foo because it's the only direct child
24 git ls-files >files &&
25 subtrees=$(grep / files|cut -d / -f 1|uniq) &&
26 subtree_count=$(echo "$subtrees"|awk -v c=0 '$1 != "" {++c} END {print c}') &&
27 entries=$(wc -l <files) &&
28 printf "SHA $dir (%d entries, %d subtrees)\n" "$entries" "$subtree_count" &&
29 for subtree in $subtrees
32 generate_expected_cache_tree_rec "$dir$subtree" || return 1
37 generate_expected_cache_tree () {
39 generate_expected_cache_tree_rec
44 generate_expected_cache_tree >expect &&
48 test_invalid_cache_tree () {
49 printf "invalid %s ()\n" "" "$@" >expect &&
50 test-tool dump-cache-tree |
51 sed -n -e "s/[0-9]* subtrees//" -e '/#(ref)/d' -e '/^invalid /p' >actual &&
52 test_cmp expect actual
55 test_no_cache_tree () {
60 test_expect_success 'initial commit has cache-tree' '
65 test_expect_success 'read-tree HEAD establishes cache-tree' '
70 test_expect_success 'git-add invalidates cache-tree' '
71 test_when_finished "git reset --hard; git read-tree HEAD" &&
72 echo "I changed this file" >foo &&
74 test_invalid_cache_tree
77 test_expect_success 'git-add in subdir invalidates cache-tree' '
78 test_when_finished "git reset --hard; git read-tree HEAD" &&
80 echo "I changed this file" >dirx/foo &&
82 test_invalid_cache_tree
85 test_expect_success 'git-add in subdir does not invalidate sibling cache-tree' '
86 git tag no-children &&
87 test_when_finished "git reset --hard no-children; git read-tree HEAD" &&
91 echo "I changed this file" >dir1/a &&
92 test_when_finished "rm before" &&
93 cat >before <<-\EOF &&
94 SHA (3 entries, 2 subtrees)
95 SHA dir1/ (1 entries, 0 subtrees)
96 SHA dir2/ (1 entries, 0 subtrees)
98 cmp_cache_tree before &&
99 echo "I changed this file" >dir1/a &&
101 cat >expect <<-\EOF &&
103 invalid dir1/ (0 subtrees)
104 SHA dir2/ (1 entries, 0 subtrees)
106 cmp_cache_tree expect
109 test_expect_success 'update-index invalidates cache-tree' '
110 test_when_finished "git reset --hard; git read-tree HEAD" &&
111 echo "I changed this file" >foo &&
112 git update-index --add foo &&
113 test_invalid_cache_tree
116 test_expect_success 'write-tree establishes cache-tree' '
117 test-tool scrap-cache-tree &&
122 test_expect_success 'test-tool scrap-cache-tree works' '
123 git read-tree HEAD &&
124 test-tool scrap-cache-tree &&
128 test_expect_success 'second commit has cache-tree' '
133 test_expect_success PERL 'commit --interactive gives cache-tree on partial commit' '
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 &&
163 test_expect_success PERL 'commit -p with shrinking cache-tree' '
164 mkdir -p deep/very-long-subdir &&
165 echo content >deep/very-long-subdir/file &&
170 before=$(wc -c <.git/index) &&
171 git commit -m delete -p &&
172 after=$(wc -c <.git/index) &&
174 # double check that the index shrank
175 test $before -gt $after &&
177 # and that our index was not corrupted
181 test_expect_success 'commit in child dir has cache-tree' '
184 git add dir/child.t &&
185 git commit -m dir/child.t &&
189 test_expect_success 'reset --hard gives cache-tree' '
190 test-tool scrap-cache-tree &&
195 test_expect_success 'reset --hard without index gives cache-tree' '
201 test_expect_success 'checkout gives cache-tree' '
203 git checkout HEAD^ &&
207 test_expect_success 'checkout -b gives cache-tree' '
208 git checkout current &&
209 git checkout -b prev HEAD^ &&
213 test_expect_success 'checkout -B gives cache-tree' '
214 git checkout current &&
215 git checkout -B prev HEAD^ &&
219 test_expect_success 'merge --ff-only maintains cache-tree' '
220 git checkout current &&
221 git checkout -b changes &&
222 test_commit llamas &&
223 test_commit pachyderm &&
225 git checkout current &&
227 git merge --ff-only changes &&
231 test_expect_success 'merge maintains cache-tree' '
232 git checkout current &&
233 git checkout -b changes2 &&
234 test_commit alpacas &&
236 git checkout current &&
237 test_commit struthio &&
239 git merge changes2 &&
243 test_expect_success 'partial commit gives cache-tree' '
244 git checkout -b partial no-children &&
247 echo "some change" >one.t &&
249 echo "some other change" >two.t &&
250 git commit two.t -m partial &&
254 test_expect_success 'no phantom error when switching trees' '
257 git add newdir/one &&
258 git checkout 2>errors &&
259 test_must_be_empty errors
262 test_expect_success 'switching trees does not invalidate shared index' '
264 sane_unset GIT_TEST_SPLIT_INDEX &&
265 git update-index --split-index &&
268 test-tool dump-split-index .git/index | grep -v ^own >before &&
269 git commit -m "as-is" &&
270 test-tool dump-split-index .git/index | grep -v ^own >after &&
271 test_cmp before after