setup.c: detect $GIT_COMMON_DIR in is_git_directory()
[git/git-svn.git] / t / t0090-cache-tree.sh
blob158cf4f03b63cf4eb61901dd1e178b3d1d08467a
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 | sed -e '/#(ref)/d' >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 generate_expected_cache_tree_rec () {
20 dir="$1${1:+/}" &&
21 parent="$2" &&
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
30 cd "$subtree"
31 generate_expected_cache_tree_rec "$dir$subtree" "$dir" || return 1
32 cd ..
33 done &&
34 dir=$parent
37 generate_expected_cache_tree () {
39 generate_expected_cache_tree_rec
43 test_cache_tree () {
44 generate_expected_cache_tree >expect &&
45 cmp_cache_tree expect
48 test_invalid_cache_tree () {
49 printf "invalid %s ()\n" "" "$@" >expect &&
50 test-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 () {
56 : >expect &&
57 cmp_cache_tree expect
60 test_expect_success 'initial commit has cache-tree' '
61 test_commit foo &&
62 test_cache_tree
65 test_expect_success 'read-tree HEAD establishes cache-tree' '
66 git read-tree HEAD &&
67 test_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 &&
73 git add 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" &&
79 mkdir dirx &&
80 echo "I changed this file" >dirx/foo &&
81 git add dirx/foo &&
82 test_invalid_cache_tree
85 cat >before <<\EOF
86 SHA (3 entries, 2 subtrees)
87 SHA dir1/ (1 entries, 0 subtrees)
88 SHA dir2/ (1 entries, 0 subtrees)
89 EOF
91 cat >expect <<\EOF
92 invalid (2 subtrees)
93 invalid dir1/ (0 subtrees)
94 SHA dir2/ (1 entries, 0 subtrees)
95 EOF
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" &&
100 mkdir dir1 dir2 &&
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 &&
106 git add 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-scrap-cache-tree &&
119 git write-tree &&
120 test_cache_tree
123 test_expect_success 'test-scrap-cache-tree works' '
124 git read-tree HEAD &&
125 test-scrap-cache-tree &&
126 test_no_cache_tree
129 test_expect_success 'second commit has cache-tree' '
130 test_commit bar &&
131 test_cache_tree
134 test_expect_success 'commit --interactive gives cache-tree on partial commit' '
135 cat <<-\EOT >foo.c &&
136 int foo()
138 return 42;
140 int bar()
142 return 42;
145 git add foo.c &&
146 test_invalid_cache_tree &&
147 git commit -m "add a file" &&
148 test_cache_tree &&
149 cat <<-\EOT >foo.c &&
150 int foo()
152 return 43;
154 int bar()
156 return 44;
159 (echo p; echo 1; echo; echo s; echo n; echo y; echo q) |
160 git commit --interactive -m foo &&
161 test_cache_tree
164 test_expect_success 'commit in child dir has cache-tree' '
165 mkdir dir &&
166 >dir/child.t &&
167 git add dir/child.t &&
168 git commit -m dir/child.t &&
169 test_cache_tree
172 test_expect_success 'reset --hard gives cache-tree' '
173 test-scrap-cache-tree &&
174 git reset --hard &&
175 test_cache_tree
178 test_expect_success 'reset --hard without index gives cache-tree' '
179 rm -f .git/index &&
180 git reset --hard &&
181 test_cache_tree
184 test_expect_success 'checkout gives cache-tree' '
185 git tag current &&
186 git checkout HEAD^ &&
187 test_cache_tree
190 test_expect_success 'checkout -b gives cache-tree' '
191 git checkout current &&
192 git checkout -b prev HEAD^ &&
193 test_cache_tree
196 test_expect_success 'checkout -B gives cache-tree' '
197 git checkout current &&
198 git checkout -B prev HEAD^ &&
199 test_cache_tree
202 test_expect_success 'partial commit gives cache-tree' '
203 git checkout -b partial no-children &&
204 test_commit one &&
205 test_commit two &&
206 echo "some change" >one.t &&
207 git add one.t &&
208 echo "some other change" >two.t &&
209 git commit two.t -m partial &&
210 test_cache_tree
213 test_expect_success 'no phantom error when switching trees' '
214 mkdir newdir &&
215 >newdir/one &&
216 git add newdir/one &&
217 git checkout 2>errors &&
218 ! test -s errors
221 test_done