#!/bin/sh global test_description := ''git archive --format=zip test'' source ./test-lib.sh global SUBSTFORMAT := '%H%n' test_lazy_prereq UNZIP_SYMLINKS ' ( mkdir unzip-symlinks && cd unzip-symlinks && "$GIT_UNZIP" "$TEST_DIRECTORY"/t5003/infozip-symlinks.zip && test -h symlink ) ' proc check_zip { global zipfile := "$1.zip" global listfile := "$1.lst" global dir := $1 global 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 " global dir := "eol_$1" global dir_with_prefix := "$dir/$2" global extracted := "$(dir_with_prefix)a" global original := 'a' test_expect_success UNZIP " extract ZIP archive with EOL conversion" ' (mkdir $dir && cd $dir && "$GIT_UNZIP" -a ../$zipfile) ' test_expect_success UNZIP " validate that text files are converted" " test_cmp_bin $extracted/text.cr $extracted/text.crlf && test_cmp_bin $extracted/text.cr $extracted/text.lf " test_expect_success UNZIP " validate that binary files are unchanged" " 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 " test_expect_success UNZIP " validate that diff files are converted" " test_cmp_bin $extracted/diff.cr $extracted/diff.crlf && test_cmp_bin $extracted/diff.cr $extracted/diff.lf " test_expect_success UNZIP " validate that -diff files are unchanged" " 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 " } test_expect_success \ 'populate workdir' \ 'mkdir a && echo simple textfile >a/a && mkdir a/bin && cp /bin/sh a/bin && 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 && 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 && printf "A\$Format:%s\$O" "$SUBSTFORMAT" >a/substfile1 && printf "A not substituted O" >a/substfile2 && (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) ' 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' \ 'echo ignore me >a/ignored && echo ignored export-ignore >.git/info/attributes' test_expect_success 'add files to repository' ' git add a && GIT_COMMITTER_DATE="2005-05-27 22:00" git commit -m initial ' test_expect_success 'setup export-subst and diff attributes' ' echo "a/nodiff.* -diff" >>.git/info/attributes && echo "a/diff.* diff" >>.git/info/attributes && echo "substfile?" export-subst >>.git/info/attributes && git log --max-count=1 "--pretty=format:A${SUBSTFORMAT}O" HEAD \ >a/substfile1 ' test_expect_success \ 'create bare clone' \ 'git clone --bare . bare.git && cp .git/info/attributes bare.git/info/attributes' 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' \ 'test_cmp_bin d.zip d1.zip' test_expect_success 'git archive --format=zip with --output' \ 'git archive --format=zip --output=d2.zip HEAD && test_cmp_bin d.zip d2.zip' test_expect_success 'git archive with --output, inferring format' ' git archive --output=d3.zip HEAD && test_cmp_bin 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 (CommandList children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:test_description) op: Equal rhs: {(SQ <"git archive --format=zip test">)} spids: [4] ) ] spids: [4] ) (C {(.)} {(./test-lib.sh)}) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:SUBSTFORMAT) op: Equal rhs: {(Lit_Other "%") (H) (Lit_Other "%") (n)} spids: [15] ) ] spids: [15] ) (C {(test_lazy_prereq)} {(UNZIP_SYMLINKS)} { (SQ <"\n"> <"\t(\n"> <"\t\tmkdir unzip-symlinks &&\n"> <"\t\tcd unzip-symlinks &&\n"> <"\t\t\"$GIT_UNZIP\" \"$TEST_DIRECTORY\"/t5003/infozip-symlinks.zip &&\n"> <"\t\ttest -h symlink\n"> <"\t)\n"> ) } ) (FuncDef name: check_zip body: (BraceGroup children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:zipfile) op: Equal rhs: {($ VSub_Number "$1") (.zip)} spids: [44] ) ] spids: [44] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:listfile) op: Equal rhs: {($ VSub_Number "$1") (.lst)} spids: [49] ) ] spids: [49] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:dir) op: Equal rhs: {($ VSub_Number "$1")} spids: [54] ) ] spids: [54] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:dir_with_prefix) op: Equal rhs: {($ VSub_Name "$dir") (/) ($ VSub_Number "$2")} spids: [58] ) ] spids: [58] ) (C {(test_expect_success)} {(UNZIP)} {(DQ (" extract ZIP archive"))} {(SQ <"\n"> <"\t\t(mkdir $dir && cd $dir && \"$GIT_UNZIP\" ../$zipfile)\n"> <"\t">)} ) (C {(test_expect_success)} {(UNZIP)} {(DQ (" validate filenames"))} { (DQ ("\n") ("\t\t(cd ") (${ VSub_Name dir_with_prefix) ("a && find .) | sort >") ($ VSub_Name "$listfile") (" &&\n") ("\t\ttest_cmp a.lst ") ($ VSub_Name "$listfile") ("\n") ("\t") ) } ) (C {(test_expect_success)} {(UNZIP)} {(DQ (" validate file contents"))} {(DQ ("\n") ("\t\tdiff -r a ") (${ VSub_Name dir_with_prefix) ("a\n") ("\t"))} ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:dir) op: Equal rhs: {(eol_) ($ VSub_Number "$1")} spids: [126] ) ] spids: [126] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:dir_with_prefix) op: Equal rhs: {($ VSub_Name "$dir") (/) ($ VSub_Number "$2")} spids: [131] ) ] spids: [131] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:extracted) op: Equal rhs: {(${ VSub_Name dir_with_prefix) (a)} spids: [137] ) ] spids: [137] ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:original) op:Equal rhs:{(a)} spids:[144])] spids: [144] ) (C {(test_expect_success)} {(UNZIP)} {(DQ (" extract ZIP archive with EOL conversion"))} {(SQ <"\n"> <"\t\t(mkdir $dir && cd $dir && \"$GIT_UNZIP\" -a ../$zipfile)\n"> <"\t">)} ) (C {(test_expect_success)} {(UNZIP)} {(DQ (" validate that text files are converted"))} { (DQ ("\n") ("\t\ttest_cmp_bin ") ($ VSub_Name "$extracted") ("/text.cr ") ($ VSub_Name "$extracted") ("/text.crlf &&\n") ("\t\ttest_cmp_bin ") ($ VSub_Name "$extracted") ("/text.cr ") ($ VSub_Name "$extracted") ("/text.lf\n") ("\t") ) } ) (C {(test_expect_success)} {(UNZIP)} {(DQ (" validate that binary files are unchanged"))} { (DQ ("\n") ("\t\ttest_cmp_bin ") ($ VSub_Name "$original") ("/binary.cr ") ($ VSub_Name "$extracted") ("/binary.cr &&\n") ("\t\ttest_cmp_bin ") ($ VSub_Name "$original") ("/binary.crlf ") ($ VSub_Name "$extracted") ("/binary.crlf &&\n") ("\t\ttest_cmp_bin ") ($ VSub_Name "$original") ("/binary.lf ") ($ VSub_Name "$extracted") ("/binary.lf\n") ("\t") ) } ) (C {(test_expect_success)} {(UNZIP)} {(DQ (" validate that diff files are converted"))} { (DQ ("\n") ("\t\ttest_cmp_bin ") ($ VSub_Name "$extracted") ("/diff.cr ") ($ VSub_Name "$extracted") ("/diff.crlf &&\n") ("\t\ttest_cmp_bin ") ($ VSub_Name "$extracted") ("/diff.cr ") ($ VSub_Name "$extracted") ("/diff.lf\n") ("\t") ) } ) (C {(test_expect_success)} {(UNZIP)} {(DQ (" validate that -diff files are unchanged"))} { (DQ ("\n") ("\t\ttest_cmp_bin ") ($ VSub_Name "$original") ("/nodiff.cr ") ($ VSub_Name "$extracted") ("/nodiff.cr &&\n") ("\t\ttest_cmp_bin ") ($ VSub_Name "$original") ("/nodiff.crlf ") ($ VSub_Name "$extracted") ("/nodiff.crlf &&\n") ("\t\ttest_cmp_bin ") ($ VSub_Name "$original") ("/nodiff.lf ") ($ VSub_Name "$extracted") ("/nodiff.lf\n") ("\t") ) } ) ] spids: [41] ) spids: [37 40] ) (C {(test_expect_success)} {(SQ <"populate workdir">)} { (SQ <"mkdir a &&\n"> <" echo simple textfile >a/a &&\n"> <" mkdir a/bin &&\n"> <" cp /bin/sh a/bin &&\n"> <" printf \"text\\r\"\t>a/text.cr &&\n"> <" printf \"text\\r\\n\"\t>a/text.crlf &&\n"> <" printf \"text\\n\"\t>a/text.lf &&\n"> <" printf \"text\\r\"\t>a/nodiff.cr &&\n"> <" printf \"text\\r\\n\"\t>a/nodiff.crlf &&\n"> <" printf \"text\\n\"\t>a/nodiff.lf &&\n"> <" printf \"\\0\\r\"\t>a/binary.cr &&\n"> <" printf \"\\0\\r\\n\"\t>a/binary.crlf &&\n"> <" printf \"\\0\\n\"\t>a/binary.lf &&\n"> <" printf \"\\0\\r\"\t>a/diff.cr &&\n"> <" printf \"\\0\\r\\n\"\t>a/diff.crlf &&\n"> <" printf \"\\0\\n\"\t>a/diff.lf &&\n"> <" printf \"A\\$Format:%s\\$O\" \"$SUBSTFORMAT\" >a/substfile1 &&\n"> <" printf \"A not substituted O\" >a/substfile2 &&\n"> <" (p=long_path_to_a_file && cd a &&\n"> <" for depth in 1 2 3 4 5; do mkdir $p && cd $p; done &&\n"> <" echo text >file_with_long_path)\n"> ) } ) (C {(test_expect_success)} {(SYMLINKS) (Lit_Comma ",") (UNZIP_SYMLINKS)} {(SQ <"add symlink">)} {(SQ <"\n"> <"\tln -s a a/symlink_to_a\n">)} ) (C {(test_expect_success)} {(SQ <"prepare file list">)} {(SQ <"\n"> <"\t(cd a && find .) | sort >a.lst\n">)} ) (C {(test_expect_success)} {(SQ <"add ignored file">)} { (SQ <"echo ignore me >a/ignored &&\n"> <" echo ignored export-ignore >.git/info/attributes"> ) } ) (C {(test_expect_success)} {(SQ <"add files to repository">)} { (SQ <"\n"> <"\tgit add a &&\n"> <"\tGIT_COMMITTER_DATE=\"2005-05-27 22:00\" git commit -m initial\n"> ) } ) (C {(test_expect_success)} {(SQ <"setup export-subst and diff attributes">)} { (SQ <"\n"> <"\techo \"a/nodiff.* -diff\" >>.git/info/attributes &&\n"> <"\techo \"a/diff.* diff\" >>.git/info/attributes &&\n"> <"\techo \"substfile?\" export-subst >>.git/info/attributes &&\n"> <"\tgit log --max-count=1 \"--pretty=format:A${SUBSTFORMAT}O\" HEAD \\\n"> <"\t\t>a/substfile1\n"> ) } ) (C {(test_expect_success)} {(SQ <"create bare clone">)} { (SQ <"git clone --bare . bare.git &&\n"> <" cp .git/info/attributes bare.git/info/attributes"> ) } ) (C {(test_expect_success)} {(SQ <"remove ignored file">)} {(SQ <"rm a/ignored">)}) (C {(test_expect_success)} {(SQ <"git archive --format=zip">)} {(SQ <"git archive --format=zip HEAD >d.zip">)} ) (C {(check_zip)} {(d)}) (C {(test_expect_success)} {(SQ <"git archive --format=zip in a bare repo">)} {(SQ <"(cd bare.git && git archive --format=zip HEAD) >d1.zip">)} ) (C {(test_expect_success)} {(SQ <"git archive --format=zip vs. the same in a bare repo">)} {(SQ <"test_cmp_bin d.zip d1.zip">)} ) (C {(test_expect_success)} {(SQ <"git archive --format=zip with --output">)} {(SQ <"git archive --format=zip --output=d2.zip HEAD &&\n"> <" test_cmp_bin d.zip d2.zip">)} ) (C {(test_expect_success)} {(SQ <"git archive with --output, inferring format">)} {(SQ <"\n"> <"\tgit archive --output=d3.zip HEAD &&\n"> <"\ttest_cmp_bin d.zip d3.zip\n">)} ) (C {(test_expect_success)} {(SQ <"git archive --format=zip with prefix">)} {(SQ <"git archive --format=zip --prefix=prefix/ HEAD >e.zip">)} ) (C {(check_zip)} {(e)} {(prefix/)}) (C {(test_expect_success)} {(SQ <"git archive -0 --format=zip on large files">)} { (SQ <"\n"> <"\ttest_config core.bigfilethreshold 1 &&\n"> <"\tgit archive -0 --format=zip HEAD >large.zip\n"> ) } ) (C {(check_zip)} {(large)}) (C {(test_expect_success)} {(SQ <"git archive --format=zip on large files">)} { (SQ <"\n"> <"\ttest_config core.bigfilethreshold 1 &&\n"> <"\tgit archive --format=zip HEAD >large-compressed.zip\n"> ) } ) (C {(check_zip)} {(large-compressed)}) (C {(test_done)}) ] )