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
16 # We don't bother with actually checking the SHA1:
17 # test-tool dump-cache-tree already verifies that all existing data is
19 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 subtrees
=$
(git ls-files|
grep /|cut
-d / -f 1|
uniq) &&
25 subtree_count
=$
(echo "$subtrees"|
awk -v c
=0 '$1 != "" {++c} END {print c}') &&
26 entries
=$
(git ls-files|
wc -l) &&
27 printf "SHA $dir (%d entries, %d subtrees)\n" "$entries" "$subtree_count" &&
28 for subtree
in $subtrees
31 generate_expected_cache_tree_rec
"$dir$subtree" "$dir" ||
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
86 SHA
(3 entries
, 2 subtrees
)
87 SHA dir
1/ (1 entries
, 0 subtrees
)
88 SHA dir
2/ (1 entries
, 0 subtrees
)
93 invalid dir
1/ (0 subtrees
)
94 SHA dir
2/ (1 entries
, 0 subtrees
)
97 test_expect_success
'git-add in subdir does not invalidate sibling cache-tree' '
98 git tag no-children &&
99 test_when_finished "git reset --hard no-children; git read-tree HEAD" &&
101 test_commit dir1/a &&
102 test_commit dir2/b &&
103 echo "I changed this file" >dir1/a &&
104 cmp_cache_tree before &&
105 echo "I changed this file" >dir1/a &&
107 cmp_cache_tree expect
110 test_expect_success
'update-index invalidates cache-tree' '
111 test_when_finished "git reset --hard; git read-tree HEAD" &&
112 echo "I changed this file" >foo &&
113 git update-index --add foo &&
114 test_invalid_cache_tree
117 test_expect_success
'write-tree establishes cache-tree' '
118 test-tool scrap-cache-tree &&
123 test_expect_success
'test-tool scrap-cache-tree works' '
124 git read-tree HEAD &&
125 test-tool scrap-cache-tree &&
129 test_expect_success
'second commit has cache-tree' '
134 test_expect_success PERL
'commit --interactive gives cache-tree on partial commit' '
135 cat <<-\EOT >foo.c &&
146 test_invalid_cache_tree &&
147 git commit -m "add a file" &&
149 cat <<-\EOT >foo.c &&
159 (echo p; echo 1; echo; echo s; echo n; echo y; echo q) |
160 git commit --interactive -m foo &&
164 test_expect_success
'commit in child dir has cache-tree' '
167 git add dir/child.t &&
168 git commit -m dir/child.t &&
172 test_expect_success
'reset --hard gives cache-tree' '
173 test-tool scrap-cache-tree &&
178 test_expect_success
'reset --hard without index gives cache-tree' '
184 test_expect_success
'checkout gives cache-tree' '
186 git checkout HEAD^ &&
190 test_expect_success
'checkout -b gives cache-tree' '
191 git checkout current &&
192 git checkout -b prev HEAD^ &&
196 test_expect_success
'checkout -B gives cache-tree' '
197 git checkout current &&
198 git checkout -B prev HEAD^ &&
202 test_expect_success
'merge --ff-only maintains cache-tree' '
203 git checkout current &&
204 git checkout -b changes &&
205 test_commit llamas &&
206 test_commit pachyderm &&
208 git checkout current &&
210 git merge --ff-only changes &&
214 test_expect_success
'merge maintains cache-tree' '
215 git checkout current &&
216 git checkout -b changes2 &&
217 test_commit alpacas &&
219 git checkout current &&
220 test_commit struthio &&
222 git merge changes2 &&
226 test_expect_success
'partial commit gives cache-tree' '
227 git checkout -b partial no-children &&
230 echo "some change" >one.t &&
232 echo "some other change" >two.t &&
233 git commit two.t -m partial &&
237 test_expect_success
'no phantom error when switching trees' '
240 git add newdir/one &&
241 git checkout 2>errors &&
245 test_expect_success
'switching trees does not invalidate shared index' '
246 git update-index --split-index &&
249 test-tool dump-split-index .git/index | grep -v ^own >before &&
250 git commit -m "as-is" &&
251 test-tool dump-split-index .git/index | grep -v ^own >after &&
252 test_cmp before after