t5004-archive-corner-cases.sh [plain text]
#!/bin/sh
test_description='test corner cases of git-archive'
. ./test-lib.sh
test_expect_success 'create commit with empty tree' '
git commit --allow-empty -m foo
'
make_dir() {
mkdir "$1" &&
test_when_finished "rm -rf '$1'"
}
check_dir() {
dir=$1; shift
{
echo "$dir" &&
for i in "$@"; do
echo "$dir/$i"
done
} | sort >expect &&
find "$dir" ! -name pax_global_header -print | sort >actual &&
test_cmp expect actual
}
test_lazy_prereq UNZIP_ZIP64_SUPPORT '
"$GIT_UNZIP" -v | grep ZIP64_SUPPORT
'
if "$TAR" tf "$TEST_DIRECTORY"/t5004/empty-with-pax-header.tar >/dev/null 2>&1
then
test_set_prereq HEADER_ONLY_TAR_OK
fi
test_expect_success HEADER_ONLY_TAR_OK 'tar archive of commit with empty tree' '
git archive --format=tar HEAD >empty-with-pax-header.tar &&
make_dir extract &&
"$TAR" xf empty-with-pax-header.tar -C extract &&
check_dir extract
'
test_expect_success 'tar archive of empty tree is empty' '
git archive --format=tar HEAD: >empty.tar &&
perl -e "print \"\\0\" x 10240" >10knuls.tar &&
test_cmp_bin 10knuls.tar empty.tar
'
test_expect_success 'tar archive of empty tree with prefix' '
git archive --format=tar --prefix=foo/ HEAD >prefix.tar &&
make_dir extract &&
"$TAR" xf prefix.tar -C extract &&
check_dir extract foo
'
test_expect_success UNZIP 'zip archive of empty tree is empty' '
{
"$GIT_UNZIP" "$TEST_DIRECTORY"/t5004/empty.zip
expect_code=$?
} &&
git archive --format=zip HEAD >empty.zip &&
make_dir extract &&
(
cd extract &&
test_expect_code $expect_code "$GIT_UNZIP" ../empty.zip
) &&
check_dir extract
'
test_expect_success UNZIP 'zip archive of empty tree with prefix' '
git archive --format=zip --prefix=foo/ HEAD >prefix.zip &&
make_dir extract &&
(
cd extract &&
"$GIT_UNZIP" ../prefix.zip
) &&
check_dir extract foo
'
test_expect_success 'archive complains about pathspec on empty tree' '
test_must_fail git archive --format=tar HEAD -- foo >/dev/null
'
test_expect_success 'create a commit with an empty subtree' '
empty_tree=$(git hash-object -t tree /dev/null) &&
root_tree=$(printf "040000 tree $empty_tree\tsub\n" | git mktree)
'
test_expect_success 'archive empty subtree with no pathspec' '
git archive --format=tar $root_tree >subtree-all.tar &&
make_dir extract &&
"$TAR" xf subtree-all.tar -C extract &&
check_dir extract
'
test_expect_success 'archive empty subtree by direct pathspec' '
git archive --format=tar $root_tree -- sub >subtree-path.tar &&
make_dir extract &&
"$TAR" xf subtree-path.tar -C extract &&
check_dir extract
'
ZIPINFO=zipinfo
test_lazy_prereq ZIPINFO '
n=$("$ZIPINFO" "$TEST_DIRECTORY"/t5004/empty.zip | sed -n "2s/.* //p")
test "x$n" = "x0"
'
test_expect_success ZIPINFO 'zip archive with many entries' '
mkdir 00 &&
for a in 0 1 2 3 4 5 6 7 8 9 a b c d e f
do
for b in 0 1 2 3 4 5 6 7 8 9 a b c d e f
do
: >00/$a$b
done
done &&
git add 00 &&
git commit -m "256 files in 1 directory" &&
subtree=$(git write-tree --prefix=00/) &&
for c in 0 1 2 3 4 5 6 7 8 9 a b c d e f
do
for d in 0 1 2 3 4 5 6 7 8 9 a b c d e f
do
echo "040000 tree $subtree $c$d"
done
done >tree &&
tree=$(git mktree <tree) &&
git archive -o many.zip $tree &&
expr 65536 + 256 >expect &&
"$ZIPINFO" many.zip | head -2 | sed -n "2s/.* //p" >actual &&
test_cmp expect actual
'
test_expect_success EXPENSIVE,UNZIP,UNZIP_ZIP64_SUPPORT \
'zip archive bigger than 4GB' '
s=0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef &&
s=$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s &&
s=$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s &&
blob=$(echo $s | git hash-object -w --stdin) &&
for i in $(test_seq 1 65500)
do
echo "100644 blob $blob $i"
done >tree &&
tree=$(git mktree <tree) &&
git archive -0 -o many-big.zip $tree &&
"$GIT_UNZIP" -t many-big.zip 9999 65500 &&
"$GIT_UNZIP" -t many-big.zip
'
test_expect_success EXPENSIVE,LONG_IS_64BIT,UNZIP,UNZIP_ZIP64_SUPPORT,ZIPINFO \
'zip archive with files bigger than 4GB' '
mkdir -p .git/objects/pack &&
(
cd .git/objects/pack &&
"$GIT_UNZIP" "$TEST_DIRECTORY"/t5004/big-pack.zip
) &&
blob=754a93d6fada4c6873360e6cb4b209132271ab0e &&
size=$(expr 4100 "*" 1024 "*" 1024) &&
tree=$(echo "100644 blob $blob big-file" | git mktree) &&
git archive -o big.zip $tree &&
"$GIT_UNZIP" -t big.zip &&
"$ZIPINFO" big.zip >big.lst &&
grep $size big.lst
'
test_done