2013-01-07 01:51:34 +08:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
test_description='git archive --format=zip test'
|
|
|
|
|
|
|
|
. ./test-lib.sh
|
|
|
|
|
|
|
|
SUBSTFORMAT=%H%n
|
|
|
|
|
2013-01-07 01:59:39 +08:00
|
|
|
test_lazy_prereq UNZIP_SYMLINKS '
|
2020-03-25 23:06:16 +08:00
|
|
|
"$GIT_UNZIP" "$TEST_DIRECTORY"/t5003/infozip-symlinks.zip &&
|
|
|
|
test -h symlink
|
2013-01-07 01:59:39 +08:00
|
|
|
'
|
|
|
|
|
2020-03-25 23:06:17 +08:00
|
|
|
test_lazy_prereq UNZIP_CONVERT '
|
|
|
|
"$GIT_UNZIP" -a "$TEST_DIRECTORY"/t5003/infozip-symlinks.zip
|
|
|
|
'
|
|
|
|
|
2013-01-07 01:51:34 +08:00
|
|
|
check_zip() {
|
|
|
|
zipfile=$1.zip
|
|
|
|
listfile=$1.lst
|
|
|
|
dir=$1
|
|
|
|
dir_with_prefix=$dir/$2
|
|
|
|
|
|
|
|
test_expect_success UNZIP " extract ZIP archive" '
|
|
|
|
(mkdir $dir && cd $dir && "$GIT_UNZIP" ../$zipfile)
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success UNZIP " validate filenames" "
|
|
|
|
(cd ${dir_with_prefix}a && find .) | sort >$listfile &&
|
|
|
|
test_cmp a.lst $listfile
|
|
|
|
"
|
|
|
|
|
|
|
|
test_expect_success UNZIP " validate file contents" "
|
|
|
|
diff -r a ${dir_with_prefix}a
|
|
|
|
"
|
2015-03-06 03:06:02 +08:00
|
|
|
|
|
|
|
dir=eol_$1
|
|
|
|
dir_with_prefix=$dir/$2
|
|
|
|
extracted=${dir_with_prefix}a
|
|
|
|
original=a
|
|
|
|
|
2020-03-25 23:06:17 +08:00
|
|
|
test_expect_success UNZIP_CONVERT " extract ZIP archive with EOL conversion" '
|
2015-03-06 03:06:02 +08:00
|
|
|
(mkdir $dir && cd $dir && "$GIT_UNZIP" -a ../$zipfile)
|
|
|
|
'
|
|
|
|
|
2020-03-25 23:06:17 +08:00
|
|
|
test_expect_success UNZIP_CONVERT " validate that text files are converted" "
|
2015-03-06 03:06:02 +08:00
|
|
|
test_cmp_bin $extracted/text.cr $extracted/text.crlf &&
|
|
|
|
test_cmp_bin $extracted/text.cr $extracted/text.lf
|
|
|
|
"
|
|
|
|
|
2020-03-25 23:06:17 +08:00
|
|
|
test_expect_success UNZIP_CONVERT " validate that binary files are unchanged" "
|
2015-03-06 03:06:02 +08:00
|
|
|
test_cmp_bin $original/binary.cr $extracted/binary.cr &&
|
|
|
|
test_cmp_bin $original/binary.crlf $extracted/binary.crlf &&
|
|
|
|
test_cmp_bin $original/binary.lf $extracted/binary.lf
|
|
|
|
"
|
|
|
|
|
2020-03-25 23:06:17 +08:00
|
|
|
test_expect_success UNZIP_CONVERT " validate that diff files are converted" "
|
2015-03-06 03:06:02 +08:00
|
|
|
test_cmp_bin $extracted/diff.cr $extracted/diff.crlf &&
|
|
|
|
test_cmp_bin $extracted/diff.cr $extracted/diff.lf
|
|
|
|
"
|
|
|
|
|
2020-03-25 23:06:17 +08:00
|
|
|
test_expect_success UNZIP_CONVERT " validate that -diff files are unchanged" "
|
2015-03-06 03:06:02 +08:00
|
|
|
test_cmp_bin $original/nodiff.cr $extracted/nodiff.cr &&
|
|
|
|
test_cmp_bin $original/nodiff.crlf $extracted/nodiff.crlf &&
|
|
|
|
test_cmp_bin $original/nodiff.lf $extracted/nodiff.lf
|
|
|
|
"
|
2017-01-03 06:25:09 +08:00
|
|
|
|
2020-03-25 23:06:17 +08:00
|
|
|
test_expect_success UNZIP_CONVERT " validate that custom diff is unchanged " "
|
2017-01-03 06:25:09 +08:00
|
|
|
test_cmp_bin $original/custom.cr $extracted/custom.cr &&
|
|
|
|
test_cmp_bin $original/custom.crlf $extracted/custom.crlf &&
|
|
|
|
test_cmp_bin $original/custom.lf $extracted/custom.lf
|
|
|
|
"
|
2013-01-07 01:51:34 +08:00
|
|
|
}
|
|
|
|
|
2020-09-20 05:23:42 +08:00
|
|
|
check_added() {
|
|
|
|
dir=$1
|
|
|
|
path_in_fs=$2
|
|
|
|
path_in_archive=$3
|
|
|
|
|
|
|
|
test_expect_success UNZIP " validate extra file $path_in_archive" '
|
|
|
|
diff -r $path_in_fs $dir/$path_in_archive
|
|
|
|
'
|
|
|
|
}
|
|
|
|
|
2013-01-07 01:51:34 +08:00
|
|
|
test_expect_success \
|
|
|
|
'populate workdir' \
|
2013-05-20 17:58:25 +08:00
|
|
|
'mkdir a &&
|
2013-01-07 01:51:34 +08:00
|
|
|
echo simple textfile >a/a &&
|
|
|
|
mkdir a/bin &&
|
|
|
|
cp /bin/sh a/bin &&
|
2015-03-06 03:06:02 +08:00
|
|
|
printf "text\r" >a/text.cr &&
|
|
|
|
printf "text\r\n" >a/text.crlf &&
|
|
|
|
printf "text\n" >a/text.lf &&
|
|
|
|
printf "text\r" >a/nodiff.cr &&
|
|
|
|
printf "text\r\n" >a/nodiff.crlf &&
|
|
|
|
printf "text\n" >a/nodiff.lf &&
|
2017-01-03 06:25:09 +08:00
|
|
|
printf "text\r" >a/custom.cr &&
|
|
|
|
printf "text\r\n" >a/custom.crlf &&
|
|
|
|
printf "text\n" >a/custom.lf &&
|
2015-03-06 03:06:02 +08:00
|
|
|
printf "\0\r" >a/binary.cr &&
|
|
|
|
printf "\0\r\n" >a/binary.crlf &&
|
|
|
|
printf "\0\n" >a/binary.lf &&
|
|
|
|
printf "\0\r" >a/diff.cr &&
|
|
|
|
printf "\0\r\n" >a/diff.crlf &&
|
|
|
|
printf "\0\n" >a/diff.lf &&
|
2013-01-07 01:51:34 +08:00
|
|
|
printf "A\$Format:%s\$O" "$SUBSTFORMAT" >a/substfile1 &&
|
|
|
|
printf "A not substituted O" >a/substfile2 &&
|
|
|
|
(p=long_path_to_a_file && cd a &&
|
2021-12-09 13:11:14 +08:00
|
|
|
for depth in 1 2 3 4 5; do mkdir $p && cd $p || exit 1; done &&
|
2013-01-07 01:59:39 +08:00
|
|
|
echo text >file_with_long_path)
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success SYMLINKS,UNZIP_SYMLINKS 'add symlink' '
|
|
|
|
ln -s a a/symlink_to_a
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'prepare file list' '
|
|
|
|
(cd a && find .) | sort >a.lst
|
|
|
|
'
|
2013-01-07 01:51:34 +08:00
|
|
|
|
|
|
|
test_expect_success \
|
|
|
|
'add ignored file' \
|
|
|
|
'echo ignore me >a/ignored &&
|
|
|
|
echo ignored export-ignore >.git/info/attributes'
|
|
|
|
|
2014-07-06 03:35:01 +08:00
|
|
|
test_expect_success 'add files to repository' '
|
|
|
|
git add a &&
|
|
|
|
GIT_COMMITTER_DATE="2005-05-27 22:00" git commit -m initial
|
|
|
|
'
|
2013-01-07 01:51:34 +08:00
|
|
|
|
2015-03-06 03:06:02 +08:00
|
|
|
test_expect_success 'setup export-subst and diff attributes' '
|
|
|
|
echo "a/nodiff.* -diff" >>.git/info/attributes &&
|
|
|
|
echo "a/diff.* diff" >>.git/info/attributes &&
|
2017-01-03 06:25:09 +08:00
|
|
|
echo "a/custom.* diff=custom" >>.git/info/attributes &&
|
|
|
|
git config diff.custom.binary true &&
|
2013-02-27 18:20:21 +08:00
|
|
|
echo "substfile?" export-subst >>.git/info/attributes &&
|
|
|
|
git log --max-count=1 "--pretty=format:A${SUBSTFORMAT}O" HEAD \
|
|
|
|
>a/substfile1
|
|
|
|
'
|
|
|
|
|
2017-01-03 06:25:09 +08:00
|
|
|
test_expect_success 'create bare clone' '
|
|
|
|
git clone --bare . bare.git &&
|
|
|
|
cp .git/info/attributes bare.git/info/attributes &&
|
|
|
|
# Recreate our changes to .git/config rather than just copying it, as
|
|
|
|
# we do not want to clobber core.bare or other settings.
|
|
|
|
git -C bare.git config diff.custom.binary true
|
|
|
|
'
|
2013-01-07 01:51:34 +08:00
|
|
|
|
|
|
|
test_expect_success \
|
|
|
|
'remove ignored file' \
|
|
|
|
'rm a/ignored'
|
|
|
|
|
|
|
|
test_expect_success \
|
|
|
|
'git archive --format=zip' \
|
|
|
|
'git archive --format=zip HEAD >d.zip'
|
|
|
|
|
|
|
|
check_zip d
|
|
|
|
|
|
|
|
test_expect_success \
|
|
|
|
'git archive --format=zip in a bare repo' \
|
|
|
|
'(cd bare.git && git archive --format=zip HEAD) >d1.zip'
|
|
|
|
|
|
|
|
test_expect_success \
|
|
|
|
'git archive --format=zip vs. the same in a bare repo' \
|
2014-06-04 23:57:52 +08:00
|
|
|
'test_cmp_bin d.zip d1.zip'
|
2013-01-07 01:51:34 +08:00
|
|
|
|
|
|
|
test_expect_success 'git archive --format=zip with --output' \
|
|
|
|
'git archive --format=zip --output=d2.zip HEAD &&
|
2014-06-04 23:57:52 +08:00
|
|
|
test_cmp_bin d.zip d2.zip'
|
2013-01-07 01:51:34 +08:00
|
|
|
|
2018-10-26 04:32:14 +08:00
|
|
|
test_expect_success 'git archive with --output, inferring format (local)' '
|
2013-01-07 01:51:34 +08:00
|
|
|
git archive --output=d3.zip HEAD &&
|
2014-06-04 23:57:52 +08:00
|
|
|
test_cmp_bin d.zip d3.zip
|
2013-01-07 01:51:34 +08:00
|
|
|
'
|
|
|
|
|
2018-10-26 04:32:14 +08:00
|
|
|
test_expect_success 'git archive with --output, inferring format (remote)' '
|
|
|
|
git archive --remote=. --output=d4.zip HEAD &&
|
|
|
|
test_cmp_bin d.zip d4.zip
|
|
|
|
'
|
|
|
|
|
2013-01-07 01:51:34 +08:00
|
|
|
test_expect_success \
|
|
|
|
'git archive --format=zip with prefix' \
|
|
|
|
'git archive --format=zip --prefix=prefix/ HEAD >e.zip'
|
|
|
|
|
|
|
|
check_zip e prefix/
|
|
|
|
|
|
|
|
test_expect_success 'git archive -0 --format=zip on large files' '
|
|
|
|
test_config core.bigfilethreshold 1 &&
|
|
|
|
git archive -0 --format=zip HEAD >large.zip
|
|
|
|
'
|
|
|
|
|
|
|
|
check_zip large
|
|
|
|
|
|
|
|
test_expect_success 'git archive --format=zip on large files' '
|
|
|
|
test_config core.bigfilethreshold 1 &&
|
|
|
|
git archive --format=zip HEAD >large-compressed.zip
|
|
|
|
'
|
|
|
|
|
|
|
|
check_zip large-compressed
|
|
|
|
|
2020-09-20 05:23:42 +08:00
|
|
|
test_expect_success 'git archive --format=zip --add-file' '
|
|
|
|
echo untracked >untracked &&
|
|
|
|
git archive --format=zip --add-file=untracked HEAD >with_untracked.zip
|
|
|
|
'
|
|
|
|
|
|
|
|
check_zip with_untracked
|
|
|
|
check_added with_untracked untracked untracked
|
|
|
|
|
2022-05-29 07:11:12 +08:00
|
|
|
test_expect_success UNZIP 'git archive --format=zip --add-virtual-file' '
|
2022-05-29 07:11:13 +08:00
|
|
|
if test_have_prereq FUNNYNAMES
|
|
|
|
then
|
|
|
|
PATHNAME="pathname with : colon"
|
|
|
|
else
|
|
|
|
PATHNAME="pathname without colon"
|
|
|
|
fi &&
|
2022-05-29 07:11:12 +08:00
|
|
|
git archive --format=zip >with_file_with_content.zip \
|
2022-05-29 07:11:13 +08:00
|
|
|
--add-virtual-file=\""$PATHNAME"\": \
|
2022-05-29 07:11:12 +08:00
|
|
|
--add-virtual-file=hello:world $EMPTY_TREE &&
|
|
|
|
test_when_finished "rm -rf tmp-unpack" &&
|
|
|
|
mkdir tmp-unpack && (
|
|
|
|
cd tmp-unpack &&
|
|
|
|
"$GIT_UNZIP" ../with_file_with_content.zip &&
|
|
|
|
test_path_is_file hello &&
|
2022-05-29 07:11:13 +08:00
|
|
|
test_path_is_file "$PATHNAME" &&
|
2022-05-29 07:11:12 +08:00
|
|
|
test world = $(cat hello)
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2020-09-20 05:23:42 +08:00
|
|
|
test_expect_success 'git archive --format=zip --add-file twice' '
|
|
|
|
echo untracked >untracked &&
|
|
|
|
git archive --format=zip --prefix=one/ --add-file=untracked \
|
|
|
|
--prefix=two/ --add-file=untracked \
|
|
|
|
--prefix= HEAD >with_untracked2.zip
|
|
|
|
'
|
|
|
|
check_zip with_untracked2
|
|
|
|
check_added with_untracked2 untracked one/untracked
|
|
|
|
check_added with_untracked2 untracked two/untracked
|
|
|
|
|
2013-01-07 01:51:34 +08:00
|
|
|
test_done
|