From ac00128298583bcdd42bffc767393868821b6af6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scharfe?= Date: Sun, 6 Jan 2013 18:47:57 +0100 Subject: [PATCH 1/4] t0024, t5000: clear variable UNZIP, use GIT_UNZIP instead InfoZIP's unzip takes default parameters from the environment variable UNZIP. Unset it in the test library and use GIT_UNZIP for specifying alternate versions of the unzip command instead. t0024 wasn't even using variable for the actual extraction. t5000 was, but when setting it to InfoZIP's unzip it would try to extract from itself (because it treats the contents of $UNZIP as parameters), which failed of course. Signed-off-by: Rene Scharfe Reviewed-by: Jonathan Nieder Signed-off-by: Junio C Hamano --- t/t0024-crlf-archive.sh | 6 +++--- t/t5000-tar-tree.sh | 10 +++++----- t/test-lib.sh | 2 ++ 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/t/t0024-crlf-archive.sh b/t/t0024-crlf-archive.sh index ec6c1b3f8a..080fe5c6dd 100755 --- a/t/t0024-crlf-archive.sh +++ b/t/t0024-crlf-archive.sh @@ -3,7 +3,7 @@ test_description='respect crlf in git archive' . ./test-lib.sh -UNZIP=${UNZIP:-unzip} +GIT_UNZIP=${GIT_UNZIP:-unzip} test_expect_success setup ' @@ -26,7 +26,7 @@ test_expect_success 'tar archive' ' ' -"$UNZIP" -v >/dev/null 2>&1 +"$GIT_UNZIP" -v >/dev/null 2>&1 if [ $? -eq 127 ]; then say "Skipping ZIP test, because unzip was not found" else @@ -37,7 +37,7 @@ test_expect_success UNZIP 'zip archive' ' git archive --format=zip HEAD >test.zip && - ( mkdir unzipped && cd unzipped && unzip ../test.zip ) && + ( mkdir unzipped && cd unzipped && "$GIT_UNZIP" ../test.zip ) && test_cmp sample unzipped/sample diff --git a/t/t5000-tar-tree.sh b/t/t5000-tar-tree.sh index ecf00edab2..1f7593dc7a 100755 --- a/t/t5000-tar-tree.sh +++ b/t/t5000-tar-tree.sh @@ -25,7 +25,7 @@ commit id embedding: ' . ./test-lib.sh -UNZIP=${UNZIP:-unzip} +GIT_UNZIP=${GIT_UNZIP:-unzip} GZIP=${GZIP:-gzip} GUNZIP=${GUNZIP:-gzip -d} @@ -37,9 +37,9 @@ check_zip() { dir=$1 dir_with_prefix=$dir/$2 - test_expect_success UNZIP " extract ZIP archive" " - (mkdir $dir && cd $dir && $UNZIP ../$zipfile) - " + 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 && @@ -201,7 +201,7 @@ test_expect_success \ test_cmp a/substfile2 g/prefix/a/substfile2 ' -$UNZIP -v >/dev/null 2>&1 +"$GIT_UNZIP" -v >/dev/null 2>&1 if [ $? -eq 127 ]; then say "Skipping ZIP tests, because unzip was not found" else diff --git a/t/test-lib.sh b/t/test-lib.sh index 489bc80fc1..c9a6b03953 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -85,6 +85,7 @@ unset VISUAL EMAIL LANGUAGE COLUMNS $("$PERL_PATH" -e ' .*_TEST PROVE VALGRIND + UNZIP PERF_AGGREGATING_LATER )); my @vars = grep(/^GIT_/ && !/^GIT_($ok)/o, @env); @@ -128,6 +129,7 @@ fi unset CDPATH unset GREP_OPTIONS +unset UNZIP case $(echo $GIT_TRACE |tr "[A-Z]" "[a-z]") in 1|2|true) From 25d3d323633dbf3b8e8fbe209c9054196a202cf7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scharfe?= Date: Sun, 6 Jan 2013 18:49:00 +0100 Subject: [PATCH 2/4] t0024, t5000: use test_lazy_prereq for UNZIP This change makes the code smaller and we can put it at the top of the script, its rightful place as setup code. Signed-off-by: Rene Scharfe Reviewed-by: Jonathan Nieder Signed-off-by: Junio C Hamano --- t/t0024-crlf-archive.sh | 12 +++++------- t/t5000-tar-tree.sh | 12 +++++------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/t/t0024-crlf-archive.sh b/t/t0024-crlf-archive.sh index 080fe5c6dd..5378787e1b 100755 --- a/t/t0024-crlf-archive.sh +++ b/t/t0024-crlf-archive.sh @@ -5,6 +5,11 @@ test_description='respect crlf in git archive' . ./test-lib.sh GIT_UNZIP=${GIT_UNZIP:-unzip} +test_lazy_prereq UNZIP ' + "$GIT_UNZIP" -v + test $? -ne 127 +' + test_expect_success setup ' git config core.autocrlf true && @@ -26,13 +31,6 @@ test_expect_success 'tar archive' ' ' -"$GIT_UNZIP" -v >/dev/null 2>&1 -if [ $? -eq 127 ]; then - say "Skipping ZIP test, because unzip was not found" -else - test_set_prereq UNZIP -fi - test_expect_success UNZIP 'zip archive' ' git archive --format=zip HEAD >test.zip && diff --git a/t/t5000-tar-tree.sh b/t/t5000-tar-tree.sh index 1f7593dc7a..2178f14d11 100755 --- a/t/t5000-tar-tree.sh +++ b/t/t5000-tar-tree.sh @@ -31,6 +31,11 @@ GUNZIP=${GUNZIP:-gzip -d} SUBSTFORMAT=%H%n +test_lazy_prereq UNZIP ' + "$GIT_UNZIP" -v + test $? -ne 127 +' + check_zip() { zipfile=$1.zip listfile=$1.lst @@ -201,13 +206,6 @@ test_expect_success \ test_cmp a/substfile2 g/prefix/a/substfile2 ' -"$GIT_UNZIP" -v >/dev/null 2>&1 -if [ $? -eq 127 ]; then - say "Skipping ZIP tests, because unzip was not found" -else - test_set_prereq UNZIP -fi - test_expect_success \ 'git archive --format=zip' \ 'git archive --format=zip HEAD >d.zip' From e9882c80cda6decc2381ecbdd1f99ad6e49b4662 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scharfe?= Date: Sun, 6 Jan 2013 18:51:34 +0100 Subject: [PATCH 3/4] t5000, t5003: move ZIP tests into their own script This makes ZIP specific tweaks easier. Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- t/t5000-tar-tree.sh | 69 ------------------------ t/t5003-archive-zip.sh | 119 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 119 insertions(+), 69 deletions(-) create mode 100755 t/t5003-archive-zip.sh diff --git a/t/t5000-tar-tree.sh b/t/t5000-tar-tree.sh index 2178f14d11..e7c240fc1f 100755 --- a/t/t5000-tar-tree.sh +++ b/t/t5000-tar-tree.sh @@ -25,37 +25,11 @@ commit id embedding: ' . ./test-lib.sh -GIT_UNZIP=${GIT_UNZIP:-unzip} GZIP=${GZIP:-gzip} GUNZIP=${GUNZIP:-gzip -d} SUBSTFORMAT=%H%n -test_lazy_prereq UNZIP ' - "$GIT_UNZIP" -v - test $? -ne 127 -' - -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 - " -} - test_expect_success \ 'populate workdir' \ 'mkdir a b c && @@ -206,54 +180,11 @@ test_expect_success \ test_cmp a/substfile2 g/prefix/a/substfile2 ' -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' \ - 'test_cmp d.zip d1.zip' - -test_expect_success 'git archive --format=zip with --output' \ - 'git archive --format=zip --output=d2.zip HEAD && - test_cmp d.zip d2.zip' - -test_expect_success 'git archive with --output, inferring format' ' - git archive --output=d3.zip HEAD && - test_cmp d.zip d3.zip -' - test_expect_success 'git archive with --output, override inferred format' ' git archive --format=tar --output=d4.zip HEAD && test_cmp b.tar d4.zip ' -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 - test_expect_success \ 'git archive --list outside of a git repo' \ 'GIT_DIR=some/non-existing/directory git archive --list' diff --git a/t/t5003-archive-zip.sh b/t/t5003-archive-zip.sh new file mode 100755 index 0000000000..3c61664c90 --- /dev/null +++ b/t/t5003-archive-zip.sh @@ -0,0 +1,119 @@ +#!/bin/sh + +test_description='git archive --format=zip test' + +. ./test-lib.sh +GIT_UNZIP=${GIT_UNZIP:-unzip} + +SUBSTFORMAT=%H%n + +test_lazy_prereq UNZIP ' + "$GIT_UNZIP" -v + test $? -ne 127 +' + +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 + " +} + +test_expect_success \ + 'populate workdir' \ + 'mkdir a b c && + echo simple textfile >a/a && + mkdir a/bin && + cp /bin/sh a/bin && + printf "A\$Format:%s\$O" "$SUBSTFORMAT" >a/substfile1 && + printf "A not substituted O" >a/substfile2 && + if test_have_prereq SYMLINKS; then + ln -s a a/l1 + else + printf %s a > a/l1 + fi && + (p=long_path_to_a_file && cd a && + for depth in 1 2 3 4 5; do mkdir $p && cd $p; done && + echo text >file_with_long_path) && + (cd a && find .) | sort >a.lst' + +test_expect_success \ + 'add ignored file' \ + 'echo ignore me >a/ignored && + echo ignored export-ignore >.git/info/attributes' + +test_expect_success \ + 'add files to repository' \ + 'find a -type f | xargs git update-index --add && + find a -type l | xargs git update-index --add && + treeid=`git write-tree` && + echo $treeid >treeid && + git update-ref HEAD $(TZ=GMT GIT_COMMITTER_DATE="2005-05-27 22:00:00" \ + git commit-tree $treeid 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' \ + 'test_cmp d.zip d1.zip' + +test_expect_success 'git archive --format=zip with --output' \ + 'git archive --format=zip --output=d2.zip HEAD && + test_cmp d.zip d2.zip' + +test_expect_success 'git archive with --output, inferring format' ' + git archive --output=d3.zip HEAD && + test_cmp d.zip d3.zip +' + +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 + +test_done From 55292ea25dca1f3273b4e59aa37ee66cae4aa343 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scharfe?= Date: Sun, 6 Jan 2013 18:59:39 +0100 Subject: [PATCH 4/4] t5003: check if unzip supports symlinks Only add a symlink to the repository if both the filesystem and unzip support symlinks. To check the latter, add a ZIP file containing a symlink, created like this with InfoZIP zip 3.0: $ echo sample text >textfile $ ln -s textfile symlink $ zip -y infozip-symlinks.zip textfile symlink If we can extract it successfully, we add a symlink to the test repository for git archive --format=zip, or otherwise skip that step. Users can see the skipped test and perhaps run it again with a different unzip version. Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- t/t5003-archive-zip.sh | 26 +++++++++++++++++++------- t/t5003/infozip-symlinks.zip | Bin 0 -> 328 bytes 2 files changed, 19 insertions(+), 7 deletions(-) create mode 100644 t/t5003/infozip-symlinks.zip diff --git a/t/t5003-archive-zip.sh b/t/t5003-archive-zip.sh index 3c61664c90..7cfe9ca3da 100755 --- a/t/t5003-archive-zip.sh +++ b/t/t5003-archive-zip.sh @@ -12,6 +12,15 @@ test_lazy_prereq UNZIP ' test $? -ne 127 ' +test_lazy_prereq UNZIP_SYMLINKS ' + ( + mkdir unzip-symlinks && + cd unzip-symlinks && + "$GIT_UNZIP" "$TEST_DIRECTORY"/t5003/infozip-symlinks.zip && + test -h symlink + ) +' + check_zip() { zipfile=$1.zip listfile=$1.lst @@ -40,15 +49,18 @@ test_expect_success \ cp /bin/sh a/bin && printf "A\$Format:%s\$O" "$SUBSTFORMAT" >a/substfile1 && printf "A not substituted O" >a/substfile2 && - if test_have_prereq SYMLINKS; then - ln -s a a/l1 - else - printf %s a > a/l1 - fi && (p=long_path_to_a_file && cd a && for depth in 1 2 3 4 5; do mkdir $p && cd $p; done && - echo text >file_with_long_path) && - (cd a && find .) | sort >a.lst' + 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 +' test_expect_success \ 'add ignored file' \ diff --git a/t/t5003/infozip-symlinks.zip b/t/t5003/infozip-symlinks.zip new file mode 100644 index 0000000000000000000000000000000000000000..065728c631cf1f7ab20a045a83abc3e08455eeba GIT binary patch literal 328 zcmWIWW@h1H0D(ty)tzkeJdg4K*&xipAj43ST2YdgnUfkC!pXp_F7Y}5gi9;985mh! zFf%Z)qyW_wC*~I9q$+@vas|Lmdj&M@9kbsh4zNiK4D3MDiYs$-GV`**hM5Bm0%0`6 zU={{=Gcw6B<8qh;&`<^jMj&3&2x7r>g@&*~oQY;CvT2wOgO~;~=j}p2APILS&@e1c U4De=U11V+#!r4H2I*7vn0CeC%rvLx| literal 0 HcmV?d00001