3a3342e171edd29756a39b0f21518062649eca7a
1#!/bin/sh
2
3test_description="Test whether cache-tree is properly updated
4
5Tests whether various commands properly update and/or rewrite the
6cache-tree extension.
7"
8 . ./test-lib.sh
9
10cmp_cache_tree () {
11 test-dump-cache-tree >actual &&
12 sed "s/$_x40/SHA/" <actual >filtered &&
13 test_cmp "$1" filtered
14}
15
16# We don't bother with actually checking the SHA1:
17# test-dump-cache-tree already verifies that all existing data is
18# correct.
19test_shallow_cache_tree () {
20 printf "SHA (%d entries, 0 subtrees)\n" $(git ls-files|wc -l) >expect &&
21 cmp_cache_tree expect
22}
23
24test_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
29}
30
31test_no_cache_tree () {
32 : >expect &&
33 cmp_cache_tree expect
34}
35
36test_expect_failure 'initial commit has cache-tree' '
37 test_commit foo &&
38 test_shallow_cache_tree
39'
40
41test_expect_success 'read-tree HEAD establishes cache-tree' '
42 git read-tree HEAD &&
43 test_shallow_cache_tree
44'
45
46test_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
51'
52
53test_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
59'
60
61test_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/
70'
71
72test_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
77'
78
79test_expect_success 'write-tree establishes cache-tree' '
80 test-scrap-cache-tree &&
81 git write-tree &&
82 test_shallow_cache_tree
83'
84
85test_expect_success 'test-scrap-cache-tree works' '
86 git read-tree HEAD &&
87 test-scrap-cache-tree &&
88 test_no_cache_tree
89'
90
91test_expect_success 'second commit has cache-tree' '
92 test_commit bar &&
93 test_shallow_cache_tree
94'
95
96test_expect_success 'reset --hard gives cache-tree' '
97 test-scrap-cache-tree &&
98 git reset --hard &&
99 test_shallow_cache_tree
100'
101
102test_expect_success 'reset --hard without index gives cache-tree' '
103 rm -f .git/index &&
104 git reset --hard &&
105 test_shallow_cache_tree
106'
107
108test_expect_success 'checkout gives cache-tree' '
109 git tag current &&
110 git checkout HEAD^ &&
111 test_shallow_cache_tree
112'
113
114test_expect_success 'checkout -b gives cache-tree' '
115 git checkout current &&
116 git checkout -b prev HEAD^ &&
117 test_shallow_cache_tree
118'
119
120test_expect_success 'checkout -B gives cache-tree' '
121 git checkout current &&
122 git checkout -B prev HEAD^ &&
123 test_shallow_cache_tree
124'
125
126test_done