]>
Commit | Line | Data |
---|---|---|
d3d49c3d RS |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (C) 2005 Rene Scharfe | |
4 | # | |
5 | ||
5be60078 | 6 | test_description='git tar-tree and git get-tar-commit-id test |
d3d49c3d | 7 | |
5b860406 RS |
8 | This test covers the topics of file contents, commit date handling and |
9 | commit id embedding: | |
d3d49c3d RS |
10 | |
11 | The contents of the repository is compared to the extracted tar | |
12 | archive. The repository contains simple text files, symlinks and a | |
3dff5379 | 13 | binary file (/bin/sh). Only paths shorter than 99 characters are |
5b860406 | 14 | used. |
d3d49c3d | 15 | |
5be60078 | 16 | git tar-tree applies the commit date to every file in the archive it |
d3d49c3d RS |
17 | creates. The test sets the commit date to a specific value and checks |
18 | if the tar archive contains that value. | |
19 | ||
5be60078 | 20 | When giving git tar-tree a commit id (in contrast to a tree id) it |
d3d49c3d | 21 | embeds this commit id into the tar archive as a comment. The test |
5be60078 | 22 | checks the ability of git get-tar-commit-id to figure it out from the |
d3d49c3d RS |
23 | tar file. |
24 | ||
25 | ' | |
26 | ||
27 | . ./test-lib.sh | |
62cdce17 | 28 | UNZIP=${UNZIP:-unzip} |
d3d49c3d | 29 | |
38c9c9b7 | 30 | SUBSTFORMAT=%H%n |
8460b2fc | 31 | |
d3d49c3d RS |
32 | test_expect_success \ |
33 | 'populate workdir' \ | |
34 | 'mkdir a b c && | |
d3d49c3d | 35 | echo simple textfile >a/a && |
d3d49c3d | 36 | mkdir a/bin && |
5b860406 | 37 | cp /bin/sh a/bin && |
760da960 RS |
38 | printf "A\$Format:%s\$O" "$SUBSTFORMAT" >a/substfile1 && |
39 | printf "A not substituted O" >a/substfile2 && | |
704a3143 JS |
40 | if test_have_prereq SYMLINKS; then |
41 | ln -s a a/l1 | |
42 | else | |
43 | printf %s a > a/l1 | |
44 | fi && | |
4c691724 RS |
45 | (p=long_path_to_a_file && cd a && |
46 | for depth in 1 2 3 4 5; do mkdir $p && cd $p; done && | |
47 | echo text >file_with_long_path) && | |
d3d49c3d RS |
48 | (cd a && find .) | sort >a.lst' |
49 | ||
008d896d RS |
50 | test_expect_success \ |
51 | 'add ignored file' \ | |
52 | 'echo ignore me >a/ignored && | |
ad94657f | 53 | echo ignored export-ignore >.git/info/attributes' |
008d896d | 54 | |
d3d49c3d RS |
55 | test_expect_success \ |
56 | 'add files to repository' \ | |
5be60078 JH |
57 | 'find a -type f | xargs git update-index --add && |
58 | find a -type l | xargs git update-index --add && | |
59 | treeid=`git write-tree` && | |
d3d49c3d | 60 | echo $treeid >treeid && |
5be60078 JH |
61 | git update-ref HEAD $(TZ=GMT GIT_COMMITTER_DATE="2005-05-27 22:00:00" \ |
62 | git commit-tree $treeid </dev/null)' | |
d3d49c3d | 63 | |
ddff8563 CB |
64 | test_expect_success \ |
65 | 'create bare clone' \ | |
66 | 'git clone --bare . bare.git && | |
ad94657f | 67 | cp .git/info/attributes bare.git/info/attributes' |
ddff8563 | 68 | |
008d896d RS |
69 | test_expect_success \ |
70 | 'remove ignored file' \ | |
71 | 'rm a/ignored' | |
72 | ||
8ff21b1a | 73 | test_expect_success \ |
5be60078 JH |
74 | 'git archive' \ |
75 | 'git archive HEAD >b.tar' | |
8ff21b1a | 76 | |
d3d49c3d | 77 | test_expect_success \ |
5be60078 JH |
78 | 'git tar-tree' \ |
79 | 'git tar-tree HEAD >b2.tar' | |
8ff21b1a RS |
80 | |
81 | test_expect_success \ | |
5be60078 | 82 | 'git archive vs. git tar-tree' \ |
188c3827 | 83 | 'test_cmp b.tar b2.tar' |
d3d49c3d | 84 | |
ddff8563 CB |
85 | test_expect_success \ |
86 | 'git archive in a bare repo' \ | |
87 | '(cd bare.git && git archive HEAD) >b3.tar' | |
88 | ||
89 | test_expect_success \ | |
90 | 'git archive vs. the same in a bare repo' \ | |
91 | 'test_cmp b.tar b3.tar' | |
92 | ||
aec0c1bb CMDV |
93 | test_expect_success 'git archive with --output' \ |
94 | 'git archive --output=b4.tar HEAD && | |
95 | test_cmp b.tar b4.tar' | |
96 | ||
97f2c33a | 97 | test_expect_success NOT_MINGW 'git archive --remote' \ |
48139269 TR |
98 | 'git archive --remote=. HEAD >b5.tar && |
99 | test_cmp b.tar b5.tar' | |
100 | ||
d3d49c3d RS |
101 | test_expect_success \ |
102 | 'validate file modification time' \ | |
30684dfa | 103 | 'mkdir extract && |
bfce5087 | 104 | "$TAR" xf b.tar -C extract a/a && |
111539a3 | 105 | test-chmtime -v +0 extract/a/a |cut -f 1 >b.mtime && |
30684dfa | 106 | echo "1117231200" >expected.mtime && |
188c3827 | 107 | test_cmp expected.mtime b.mtime' |
d3d49c3d RS |
108 | |
109 | test_expect_success \ | |
5be60078 JH |
110 | 'git get-tar-commit-id' \ |
111 | 'git get-tar-commit-id <b.tar >b.commitid && | |
188c3827 | 112 | test_cmp .git/$(git symbolic-ref HEAD) b.commitid' |
d3d49c3d RS |
113 | |
114 | test_expect_success \ | |
115 | 'extract tar archive' \ | |
bfce5087 | 116 | '(cd b && "$TAR" xf -) <b.tar' |
d3d49c3d RS |
117 | |
118 | test_expect_success \ | |
119 | 'validate filenames' \ | |
120 | '(cd b/a && find .) | sort >b.lst && | |
188c3827 | 121 | test_cmp a.lst b.lst' |
d3d49c3d RS |
122 | |
123 | test_expect_success \ | |
124 | 'validate file contents' \ | |
125 | 'diff -r a b/a' | |
126 | ||
127 | test_expect_success \ | |
5be60078 JH |
128 | 'git tar-tree with prefix' \ |
129 | 'git tar-tree HEAD prefix >c.tar' | |
d3d49c3d RS |
130 | |
131 | test_expect_success \ | |
132 | 'extract tar archive with prefix' \ | |
bfce5087 | 133 | '(cd c && "$TAR" xf -) <c.tar' |
d3d49c3d RS |
134 | |
135 | test_expect_success \ | |
136 | 'validate filenames with prefix' \ | |
137 | '(cd c/prefix/a && find .) | sort >c.lst && | |
188c3827 | 138 | test_cmp a.lst c.lst' |
d3d49c3d RS |
139 | |
140 | test_expect_success \ | |
141 | 'validate file contents with prefix' \ | |
142 | 'diff -r a c/prefix/a' | |
143 | ||
8460b2fc | 144 | test_expect_success \ |
ac7fa277 | 145 | 'create archives with substfiles' \ |
ad94657f RS |
146 | 'cp .git/info/attributes .git/info/attributes.before && |
147 | echo "substfile?" export-subst >>.git/info/attributes && | |
8460b2fc | 148 | git archive HEAD >f.tar && |
ac7fa277 | 149 | git archive --prefix=prefix/ HEAD >g.tar && |
ad94657f | 150 | mv .git/info/attributes.before .git/info/attributes' |
8460b2fc RS |
151 | |
152 | test_expect_success \ | |
760da960 | 153 | 'extract substfiles' \ |
bfce5087 | 154 | '(mkdir f && cd f && "$TAR" xf -) <f.tar' |
8460b2fc RS |
155 | |
156 | test_expect_success \ | |
38c9c9b7 RS |
157 | 'validate substfile contents' \ |
158 | 'git log --max-count=1 "--pretty=format:A${SUBSTFORMAT}O" HEAD \ | |
760da960 | 159 | >f/a/substfile1.expected && |
188c3827 MV |
160 | test_cmp f/a/substfile1.expected f/a/substfile1 && |
161 | test_cmp a/substfile2 f/a/substfile2 | |
760da960 | 162 | ' |
8460b2fc | 163 | |
ac7fa277 RS |
164 | test_expect_success \ |
165 | 'extract substfiles from archive with prefix' \ | |
bfce5087 | 166 | '(mkdir g && cd g && "$TAR" xf -) <g.tar' |
ac7fa277 RS |
167 | |
168 | test_expect_success \ | |
169 | 'validate substfile contents from archive with prefix' \ | |
170 | 'git log --max-count=1 "--pretty=format:A${SUBSTFORMAT}O" HEAD \ | |
171 | >g/prefix/a/substfile1.expected && | |
188c3827 MV |
172 | test_cmp g/prefix/a/substfile1.expected g/prefix/a/substfile1 && |
173 | test_cmp a/substfile2 g/prefix/a/substfile2 | |
ac7fa277 RS |
174 | ' |
175 | ||
62cdce17 | 176 | test_expect_success \ |
5be60078 JH |
177 | 'git archive --format=zip' \ |
178 | 'git archive --format=zip HEAD >d.zip' | |
62cdce17 | 179 | |
ddff8563 CB |
180 | test_expect_success \ |
181 | 'git archive --format=zip in a bare repo' \ | |
182 | '(cd bare.git && git archive --format=zip HEAD) >d1.zip' | |
183 | ||
184 | test_expect_success \ | |
185 | 'git archive --format=zip vs. the same in a bare repo' \ | |
186 | 'test_cmp d.zip d1.zip' | |
187 | ||
aec0c1bb CMDV |
188 | test_expect_success 'git archive --format=zip with --output' \ |
189 | 'git archive --format=zip --output=d2.zip HEAD && | |
190 | test_cmp d.zip d2.zip' | |
191 | ||
fe12d8e8 RS |
192 | test_expect_success 'git archive with --output, inferring format' ' |
193 | git archive --output=d3.zip HEAD && | |
194 | test_cmp d.zip d3.zip | |
195 | ' | |
196 | ||
197 | test_expect_success 'git archive with --output, override inferred format' ' | |
198 | git archive --format=tar --output=d4.zip HEAD && | |
199 | test_cmp b.tar d4.zip | |
200 | ' | |
201 | ||
27c96c4f | 202 | $UNZIP -v >/dev/null 2>&1 |
3a86f36b | 203 | if [ $? -eq 127 ]; then |
fae74a04 | 204 | say "Skipping ZIP tests, because unzip was not found" |
552a26c8 JS |
205 | else |
206 | test_set_prereq UNZIP | |
3a86f36b JS |
207 | fi |
208 | ||
552a26c8 | 209 | test_expect_success UNZIP \ |
62cdce17 RS |
210 | 'extract ZIP archive' \ |
211 | '(mkdir d && cd d && $UNZIP ../d.zip)' | |
212 | ||
552a26c8 | 213 | test_expect_success UNZIP \ |
62cdce17 RS |
214 | 'validate filenames' \ |
215 | '(cd d/a && find .) | sort >d.lst && | |
188c3827 | 216 | test_cmp a.lst d.lst' |
62cdce17 | 217 | |
552a26c8 | 218 | test_expect_success UNZIP \ |
62cdce17 RS |
219 | 'validate file contents' \ |
220 | 'diff -r a d/a' | |
221 | ||
222 | test_expect_success \ | |
5be60078 JH |
223 | 'git archive --format=zip with prefix' \ |
224 | 'git archive --format=zip --prefix=prefix/ HEAD >e.zip' | |
62cdce17 | 225 | |
552a26c8 | 226 | test_expect_success UNZIP \ |
62cdce17 RS |
227 | 'extract ZIP archive with prefix' \ |
228 | '(mkdir e && cd e && $UNZIP ../e.zip)' | |
229 | ||
552a26c8 | 230 | test_expect_success UNZIP \ |
62cdce17 RS |
231 | 'validate filenames with prefix' \ |
232 | '(cd e/prefix/a && find .) | sort >e.lst && | |
188c3827 | 233 | test_cmp a.lst e.lst' |
62cdce17 | 234 | |
552a26c8 | 235 | test_expect_success UNZIP \ |
62cdce17 RS |
236 | 'validate file contents with prefix' \ |
237 | 'diff -r a e/prefix/a' | |
238 | ||
265d5280 | 239 | test_expect_success \ |
5be60078 JH |
240 | 'git archive --list outside of a git repo' \ |
241 | 'GIT_DIR=some/non-existing/directory git archive --list' | |
265d5280 | 242 | |
ebfbdb34 RS |
243 | test_expect_success 'git-archive --prefix=olde-' ' |
244 | git archive --prefix=olde- >h.tar HEAD && | |
245 | ( | |
246 | mkdir h && | |
247 | cd h && | |
248 | "$TAR" xf - <../h.tar | |
249 | ) && | |
250 | test -d h/olde-a && | |
251 | test -d h/olde-a/bin && | |
252 | test -f h/olde-a/bin/sh | |
253 | ' | |
254 | ||
d3d49c3d | 255 | test_done |