aboutsummaryrefslogtreecommitdiff
path: root/t/t5003-archive-zip.sh
blob: 14744b2a4b1e646890176ec53970d36de6f8ec3b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#!/bin/sh

test_description='git archive --format=zip test'

. ./test-lib.sh

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
	)
'

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
	"

	dir=eol_$1
	dir_with_prefix=$dir/$2
	extracted=${dir_with_prefix}a
	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