1
0
mirror of https://github.com/git/git.git synced 2024-09-28 07:40:44 +02:00
git/t/t0090-cache-tree.sh
Thomas Rast 11c8a74a64 commit: write cache-tree data when writing index anyway
In prepare_index(), we refresh the index, and then write it to disk if
this changed the index data.  After running hooks we re-read the index
and compute the root tree sha1 with the cache-tree machinery.

This gives us a mostly free opportunity to write up-to-date cache-tree
data: we can compute it in prepare_index() immediately before writing
the index to disk.

If we do this, we were going to write the index anyway, and the later
cache-tree update has no further work to do.  If we don't do it, we
don't do any extra work, though we still don't have have cache-tree
data after the commit.

The only case that suffers badly is when the pre-commit hook changes
many trees in the index.  I'm writing this off as highly unusual.

Signed-off-by: Thomas Rast <trast@student.ethz.ch>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-12-06 14:58:53 -08:00

96 lines
2.2 KiB
Bash
Executable File

#!/bin/sh
test_description="Test whether cache-tree is properly updated
Tests whether various commands properly update and/or rewrite the
cache-tree extension.
"
. ./test-lib.sh
cmp_cache_tree () {
test-dump-cache-tree >actual &&
sed "s/$_x40/SHA/" <actual >filtered &&
test_cmp "$1" filtered
}
# We don't bother with actually checking the SHA1:
# test-dump-cache-tree already verifies that all existing data is
# correct.
test_shallow_cache_tree () {
echo "SHA " \
"($(git ls-files|wc -l) entries, 0 subtrees)" >expect &&
cmp_cache_tree expect
}
test_invalid_cache_tree () {
echo "invalid (0 subtrees)" >expect &&
echo "SHA #(ref) " \
"($(git ls-files|wc -l) entries, 0 subtrees)" >>expect &&
cmp_cache_tree expect
}
test_no_cache_tree () {
: >expect &&
cmp_cache_tree expect
}
test_expect_failure 'initial commit has cache-tree' '
test_commit foo &&
test_shallow_cache_tree
'
test_expect_success 'read-tree HEAD establishes cache-tree' '
git read-tree HEAD &&
test_shallow_cache_tree
'
test_expect_success 'git-add invalidates cache-tree' '
test_when_finished "git reset --hard; git read-tree HEAD" &&
echo "I changed this file" > foo &&
git add foo &&
test_invalid_cache_tree
'
test_expect_success 'update-index invalidates cache-tree' '
test_when_finished "git reset --hard; git read-tree HEAD" &&
echo "I changed this file" > foo &&
git update-index --add foo &&
test_invalid_cache_tree
'
test_expect_success 'write-tree establishes cache-tree' '
test-scrap-cache-tree &&
git write-tree &&
test_shallow_cache_tree
'
test_expect_success 'test-scrap-cache-tree works' '
git read-tree HEAD &&
test-scrap-cache-tree &&
test_no_cache_tree
'
test_expect_success 'second commit has cache-tree' '
test_commit bar &&
test_shallow_cache_tree
'
test_expect_failure 'reset --hard gives cache-tree' '
test-scrap-cache-tree &&
git reset --hard &&
test_shallow_cache_tree
'
test_expect_failure 'reset --hard without index gives cache-tree' '
rm -f .git/index &&
git reset --hard &&
test_shallow_cache_tree
'
test_expect_failure 'checkout gives cache-tree' '
git checkout HEAD^ &&
test_shallow_cache_tree
'
test_done