1#!/bin/sh
23
test_description="Test whether cache-tree is properly updated
45
Tests whether various commands properly update and/or rewrite the
6cache-tree extension.
7"
8. ./test-lib.sh
910
cmp_cache_tree () {
11test-dump-cache-tree >actual &&
12sed "s/$_x40/SHA/" <actual >filtered &&
13test_cmp "$1" filtered
14}
1516
# 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 () {
20printf "SHA (%d entries, 0 subtrees)\n" $(git ls-files|wc -l) >expect &&
21cmp_cache_tree expect
22}
2324
test_invalid_cache_tree () {
25echo "invalid (0 subtrees)" >expect &&
26printf "SHA #(ref) (%d entries, 0 subtrees)\n" $(git ls-files|wc -l) >>expect &&
27cmp_cache_tree expect
28}
2930
test_no_cache_tree () {
31: >expect &&
32cmp_cache_tree expect
33}
3435
test_expect_failure 'initial commit has cache-tree' '
36test_commit foo &&
37test_shallow_cache_tree
38'
3940
test_expect_success 'read-tree HEAD establishes cache-tree' '
41git read-tree HEAD &&
42test_shallow_cache_tree
43'
4445
test_expect_success 'git-add invalidates cache-tree' '
46test_when_finished "git reset --hard; git read-tree HEAD" &&
47echo "I changed this file" >foo &&
48git add foo &&
49test_invalid_cache_tree
50'
5152
test_expect_success 'update-index invalidates cache-tree' '
53test_when_finished "git reset --hard; git read-tree HEAD" &&
54echo "I changed this file" >foo &&
55git update-index --add foo &&
56test_invalid_cache_tree
57'
5859
test_expect_success 'write-tree establishes cache-tree' '
60test-scrap-cache-tree &&
61git write-tree &&
62test_shallow_cache_tree
63'
6465
test_expect_success 'test-scrap-cache-tree works' '
66git read-tree HEAD &&
67test-scrap-cache-tree &&
68test_no_cache_tree
69'
7071
test_expect_success 'second commit has cache-tree' '
72test_commit bar &&
73test_shallow_cache_tree
74'
7576
test_expect_success 'reset --hard gives cache-tree' '
77test-scrap-cache-tree &&
78git reset --hard &&
79test_shallow_cache_tree
80'
8182
test_expect_success 'reset --hard without index gives cache-tree' '
83rm -f .git/index &&
84git reset --hard &&
85test_shallow_cache_tree
86'
8788
test_expect_success 'checkout gives cache-tree' '
89git tag current &&
90git checkout HEAD^ &&
91test_shallow_cache_tree
92'
9394
test_expect_success 'checkout -b gives cache-tree' '
95git checkout current &&
96git checkout -b prev HEAD^ &&
97test_shallow_cache_tree
98'
99100
test_expect_success 'checkout -B gives cache-tree' '
101git checkout current &&
102git checkout -B prev HEAD^ &&
103test_shallow_cache_tree
104'
105106
test_done