cache-tree: subdirectory tests
[git/mjg.git] / t / t0090-cache-tree.sh
blob3a3342e171edd29756a39b0f21518062649eca7a
1 #!/bin/sh
3 test_description="Test whether cache-tree is properly updated
5 Tests whether various commands properly update and/or rewrite the
6 cache-tree extension.
8 . ./test-lib.sh
10 cmp_cache_tree () {
11 test-dump-cache-tree >actual &&
12 sed "s/$_x40/SHA/" <actual >filtered &&
13 test_cmp "$1" filtered
16 # We don't bother with actually checking the SHA1:
17 # test-dump-cache-tree already verifies that all existing data is
18 # correct.
19 test_shallow_cache_tree () {
20 printf "SHA (%d entries, 0 subtrees)\n" $(git ls-files|wc -l) >expect &&
21 cmp_cache_tree expect
24 test_invalid_cache_tree () {
25 printf "invalid %s ()\n" "" "$@" >expect &&
26 test-dump-cache-tree | \
27 sed -n -e "s/[0-9]* subtrees//" -e '/#(ref)/d' -e '/^invalid /p' >actual &&
28 test_cmp expect actual
31 test_no_cache_tree () {
32 : >expect &&
33 cmp_cache_tree expect
36 test_expect_failure 'initial commit has cache-tree' '
37 test_commit foo &&
38 test_shallow_cache_tree
41 test_expect_success 'read-tree HEAD establishes cache-tree' '
42 git read-tree HEAD &&
43 test_shallow_cache_tree
46 test_expect_success 'git-add invalidates cache-tree' '
47 test_when_finished "git reset --hard; git read-tree HEAD" &&
48 echo "I changed this file" >foo &&
49 git add foo &&
50 test_invalid_cache_tree
53 test_expect_success 'git-add in subdir invalidates cache-tree' '
54 test_when_finished "git reset --hard; git read-tree HEAD" &&
55 mkdir dirx &&
56 echo "I changed this file" >dirx/foo &&
57 git add dirx/foo &&
58 test_invalid_cache_tree
61 test_expect_success 'git-add in subdir does not invalidate sibling cache-tree' '
62 git tag no-children &&
63 test_when_finished "git reset --hard no-children; git read-tree HEAD" &&
64 mkdir dir1 dir2 &&
65 test_commit dir1/a &&
66 test_commit dir2/b &&
67 echo "I changed this file" >dir1/a &&
68 git add dir1/a &&
69 test_invalid_cache_tree dir1/
72 test_expect_success 'update-index invalidates cache-tree' '
73 test_when_finished "git reset --hard; git read-tree HEAD" &&
74 echo "I changed this file" >foo &&
75 git update-index --add foo &&
76 test_invalid_cache_tree
79 test_expect_success 'write-tree establishes cache-tree' '
80 test-scrap-cache-tree &&
81 git write-tree &&
82 test_shallow_cache_tree
85 test_expect_success 'test-scrap-cache-tree works' '
86 git read-tree HEAD &&
87 test-scrap-cache-tree &&
88 test_no_cache_tree
91 test_expect_success 'second commit has cache-tree' '
92 test_commit bar &&
93 test_shallow_cache_tree
96 test_expect_success 'reset --hard gives cache-tree' '
97 test-scrap-cache-tree &&
98 git reset --hard &&
99 test_shallow_cache_tree
102 test_expect_success 'reset --hard without index gives cache-tree' '
103 rm -f .git/index &&
104 git reset --hard &&
105 test_shallow_cache_tree
108 test_expect_success 'checkout gives cache-tree' '
109 git tag current &&
110 git checkout HEAD^ &&
111 test_shallow_cache_tree
114 test_expect_success 'checkout -b gives cache-tree' '
115 git checkout current &&
116 git checkout -b prev HEAD^ &&
117 test_shallow_cache_tree
120 test_expect_success 'checkout -B gives cache-tree' '
121 git checkout current &&
122 git checkout -B prev HEAD^ &&
123 test_shallow_cache_tree
126 test_done