blob: 0037f63d91a7c11f6599a99e76840a0cdbf4c779 [file] [log] [blame]
Rene Scharfed3d49c32005-06-02 22:50:17 +02001#!/bin/sh
2#
3# Copyright (C) 2005 Rene Scharfe
4#
5
Junio C Hamano5be60072007-07-02 22:52:14 -07006test_description='git tar-tree and git get-tar-commit-id test
Rene Scharfed3d49c32005-06-02 22:50:17 +02007
Rene Scharfe5b860402005-06-03 18:21:23 +02008This test covers the topics of file contents, commit date handling and
9commit id embedding:
Rene Scharfed3d49c32005-06-02 22:50:17 +020010
11 The contents of the repository is compared to the extracted tar
12 archive. The repository contains simple text files, symlinks and a
Pavel Roskin3dff5372007-02-03 23:49:16 -050013 binary file (/bin/sh). Only paths shorter than 99 characters are
Rene Scharfe5b860402005-06-03 18:21:23 +020014 used.
Rene Scharfed3d49c32005-06-02 22:50:17 +020015
Junio C Hamano5be60072007-07-02 22:52:14 -070016 git tar-tree applies the commit date to every file in the archive it
Rene Scharfed3d49c32005-06-02 22:50:17 +020017 creates. The test sets the commit date to a specific value and checks
18 if the tar archive contains that value.
19
Junio C Hamano5be60072007-07-02 22:52:14 -070020 When giving git tar-tree a commit id (in contrast to a tree id) it
Rene Scharfed3d49c32005-06-02 22:50:17 +020021 embeds this commit id into the tar archive as a comment. The test
Junio C Hamano5be60072007-07-02 22:52:14 -070022 checks the ability of git get-tar-commit-id to figure it out from the
Rene Scharfed3d49c32005-06-02 22:50:17 +020023 tar file.
24
25'
26
27. ./test-lib.sh
Rene Scharfe62cdce12006-10-07 01:47:35 +020028UNZIP=${UNZIP:-unzip}
Rene Scharfed3d49c32005-06-02 22:50:17 +020029
René Scharfe38c9c9b2007-09-06 18:51:11 +020030SUBSTFORMAT=%H%n
René Scharfe8460b2f2007-09-03 20:07:01 +020031
Rene Scharfed3d49c32005-06-02 22:50:17 +020032test_expect_success \
33 'populate workdir' \
34 'mkdir a b c &&
Rene Scharfed3d49c32005-06-02 22:50:17 +020035 echo simple textfile >a/a &&
Rene Scharfed3d49c32005-06-02 22:50:17 +020036 mkdir a/bin &&
Rene Scharfe5b860402005-06-03 18:21:23 +020037 cp /bin/sh a/bin &&
René Scharfe760da962007-09-14 00:13:06 +020038 printf "A\$Format:%s\$O" "$SUBSTFORMAT" >a/substfile1 &&
39 printf "A not substituted O" >a/substfile2 &&
Johannes Sixt704a3142009-03-04 22:38:24 +010040 if test_have_prereq SYMLINKS; then
41 ln -s a a/l1
42 else
43 printf %s a > a/l1
44 fi &&
Rene Scharfe4c691722006-03-25 23:21:07 +010045 (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) &&
Rene Scharfed3d49c32005-06-02 22:50:17 +020048 (cd a && find .) | sort >a.lst'
49
50test_expect_success \
René Scharfe008d8962008-06-08 18:42:33 +020051 'add ignored file' \
52 'echo ignore me >a/ignored &&
René Scharfead946572009-04-18 00:17:49 +020053 echo ignored export-ignore >.git/info/attributes'
René Scharfe008d8962008-06-08 18:42:33 +020054
55test_expect_success \
Rene Scharfed3d49c32005-06-02 22:50:17 +020056 'add files to repository' \
Junio C Hamano5be60072007-07-02 22:52:14 -070057 'find a -type f | xargs git update-index --add &&
58 find a -type l | xargs git update-index --add &&
59 treeid=`git write-tree` &&
Rene Scharfed3d49c32005-06-02 22:50:17 +020060 echo $treeid >treeid &&
Junio C Hamano5be60072007-07-02 22:52:14 -070061 git update-ref HEAD $(TZ=GMT GIT_COMMITTER_DATE="2005-05-27 22:00:00" \
62 git commit-tree $treeid </dev/null)'
Rene Scharfed3d49c32005-06-02 22:50:17 +020063
64test_expect_success \
Charles Baileyddff8562008-10-25 11:38:14 -040065 'create bare clone' \
66 'git clone --bare . bare.git &&
René Scharfead946572009-04-18 00:17:49 +020067 cp .git/info/attributes bare.git/info/attributes'
Charles Baileyddff8562008-10-25 11:38:14 -040068
69test_expect_success \
René Scharfe008d8962008-06-08 18:42:33 +020070 'remove ignored file' \
71 'rm a/ignored'
72
73test_expect_success \
Junio C Hamano5be60072007-07-02 22:52:14 -070074 'git archive' \
75 'git archive HEAD >b.tar'
René Scharfe8ff21b12007-04-09 17:12:53 +020076
77test_expect_success \
Junio C Hamano5be60072007-07-02 22:52:14 -070078 'git tar-tree' \
79 'git tar-tree HEAD >b2.tar'
René Scharfe8ff21b12007-04-09 17:12:53 +020080
81test_expect_success \
Junio C Hamano5be60072007-07-02 22:52:14 -070082 'git archive vs. git tar-tree' \
Miklos Vajna188c3822009-03-16 21:18:42 +010083 'test_cmp b.tar b2.tar'
Rene Scharfed3d49c32005-06-02 22:50:17 +020084
85test_expect_success \
Charles Baileyddff8562008-10-25 11:38:14 -040086 'git archive in a bare repo' \
87 '(cd bare.git && git archive HEAD) >b3.tar'
88
89test_expect_success \
90 'git archive vs. the same in a bare repo' \
91 'test_cmp b.tar b3.tar'
92
Carlos Manuel Duclos Vergaraaec0c1b2009-02-16 18:20:25 +010093test_expect_success 'git archive with --output' \
94 'git archive --output=b4.tar HEAD &&
95 test_cmp b.tar b4.tar'
96
Thomas Rast48139262009-06-27 20:47:43 +020097test_expect_success 'git archive --remote' \
98 'git archive --remote=. HEAD >b5.tar &&
99 test_cmp b.tar b5.tar'
100
Charles Baileyddff8562008-10-25 11:38:14 -0400101test_expect_success \
Rene Scharfed3d49c32005-06-02 22:50:17 +0200102 'validate file modification time' \
Jeff King30684df2008-05-13 04:45:32 -0400103 'mkdir extract &&
Junio C Hamanobfce5082008-07-25 12:35:10 -0700104 "$TAR" xf b.tar -C extract a/a &&
Alex Riesen111539a2008-10-30 11:20:27 +0100105 test-chmtime -v +0 extract/a/a |cut -f 1 >b.mtime &&
Jeff King30684df2008-05-13 04:45:32 -0400106 echo "1117231200" >expected.mtime &&
Miklos Vajna188c3822009-03-16 21:18:42 +0100107 test_cmp expected.mtime b.mtime'
Rene Scharfed3d49c32005-06-02 22:50:17 +0200108
109test_expect_success \
Junio C Hamano5be60072007-07-02 22:52:14 -0700110 'git get-tar-commit-id' \
111 'git get-tar-commit-id <b.tar >b.commitid &&
Miklos Vajna188c3822009-03-16 21:18:42 +0100112 test_cmp .git/$(git symbolic-ref HEAD) b.commitid'
Rene Scharfed3d49c32005-06-02 22:50:17 +0200113
114test_expect_success \
115 'extract tar archive' \
Junio C Hamanobfce5082008-07-25 12:35:10 -0700116 '(cd b && "$TAR" xf -) <b.tar'
Rene Scharfed3d49c32005-06-02 22:50:17 +0200117
118test_expect_success \
119 'validate filenames' \
120 '(cd b/a && find .) | sort >b.lst &&
Miklos Vajna188c3822009-03-16 21:18:42 +0100121 test_cmp a.lst b.lst'
Rene Scharfed3d49c32005-06-02 22:50:17 +0200122
123test_expect_success \
124 'validate file contents' \
125 'diff -r a b/a'
126
127test_expect_success \
Junio C Hamano5be60072007-07-02 22:52:14 -0700128 'git tar-tree with prefix' \
129 'git tar-tree HEAD prefix >c.tar'
Rene Scharfed3d49c32005-06-02 22:50:17 +0200130
131test_expect_success \
132 'extract tar archive with prefix' \
Junio C Hamanobfce5082008-07-25 12:35:10 -0700133 '(cd c && "$TAR" xf -) <c.tar'
Rene Scharfed3d49c32005-06-02 22:50:17 +0200134
135test_expect_success \
136 'validate filenames with prefix' \
137 '(cd c/prefix/a && find .) | sort >c.lst &&
Miklos Vajna188c3822009-03-16 21:18:42 +0100138 test_cmp a.lst c.lst'
Rene Scharfed3d49c32005-06-02 22:50:17 +0200139
140test_expect_success \
141 'validate file contents with prefix' \
142 'diff -r a c/prefix/a'
143
Rene Scharfe62cdce12006-10-07 01:47:35 +0200144test_expect_success \
René Scharfeac7fa272008-04-09 23:14:43 +0200145 'create archives with substfiles' \
René Scharfead946572009-04-18 00:17:49 +0200146 'cp .git/info/attributes .git/info/attributes.before &&
147 echo "substfile?" export-subst >>.git/info/attributes &&
René Scharfe8460b2f2007-09-03 20:07:01 +0200148 git archive HEAD >f.tar &&
René Scharfeac7fa272008-04-09 23:14:43 +0200149 git archive --prefix=prefix/ HEAD >g.tar &&
René Scharfead946572009-04-18 00:17:49 +0200150 mv .git/info/attributes.before .git/info/attributes'
René Scharfe8460b2f2007-09-03 20:07:01 +0200151
152test_expect_success \
René Scharfe760da962007-09-14 00:13:06 +0200153 'extract substfiles' \
Junio C Hamanobfce5082008-07-25 12:35:10 -0700154 '(mkdir f && cd f && "$TAR" xf -) <f.tar'
René Scharfe8460b2f2007-09-03 20:07:01 +0200155
156test_expect_success \
René Scharfe38c9c9b2007-09-06 18:51:11 +0200157 'validate substfile contents' \
158 'git log --max-count=1 "--pretty=format:A${SUBSTFORMAT}O" HEAD \
René Scharfe760da962007-09-14 00:13:06 +0200159 >f/a/substfile1.expected &&
Miklos Vajna188c3822009-03-16 21:18:42 +0100160 test_cmp f/a/substfile1.expected f/a/substfile1 &&
161 test_cmp a/substfile2 f/a/substfile2
René Scharfe760da962007-09-14 00:13:06 +0200162'
René Scharfe8460b2f2007-09-03 20:07:01 +0200163
164test_expect_success \
René Scharfeac7fa272008-04-09 23:14:43 +0200165 'extract substfiles from archive with prefix' \
Junio C Hamanobfce5082008-07-25 12:35:10 -0700166 '(mkdir g && cd g && "$TAR" xf -) <g.tar'
René Scharfeac7fa272008-04-09 23:14:43 +0200167
168test_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 &&
Miklos Vajna188c3822009-03-16 21:18:42 +0100172 test_cmp g/prefix/a/substfile1.expected g/prefix/a/substfile1 &&
173 test_cmp a/substfile2 g/prefix/a/substfile2
René Scharfeac7fa272008-04-09 23:14:43 +0200174'
175
176test_expect_success \
Junio C Hamano5be60072007-07-02 22:52:14 -0700177 'git archive --format=zip' \
178 'git archive --format=zip HEAD >d.zip'
Rene Scharfe62cdce12006-10-07 01:47:35 +0200179
Charles Baileyddff8562008-10-25 11:38:14 -0400180test_expect_success \
181 'git archive --format=zip in a bare repo' \
182 '(cd bare.git && git archive --format=zip HEAD) >d1.zip'
183
184test_expect_success \
185 'git archive --format=zip vs. the same in a bare repo' \
186 'test_cmp d.zip d1.zip'
187
Carlos Manuel Duclos Vergaraaec0c1b2009-02-16 18:20:25 +0100188test_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
René Scharfe27c96c42007-06-09 08:31:12 +0200192$UNZIP -v >/dev/null 2>&1
Johannes Schindelin3a86f362007-06-06 19:57:40 +0100193if [ $? -eq 127 ]; then
Johannes Sixtfae74a02009-03-01 19:52:51 +0100194 say "Skipping ZIP tests, because unzip was not found"
Johannes Sixt552a26c2009-03-16 14:44:56 +0100195else
196 test_set_prereq UNZIP
Johannes Schindelin3a86f362007-06-06 19:57:40 +0100197fi
198
Johannes Sixt552a26c2009-03-16 14:44:56 +0100199test_expect_success UNZIP \
Rene Scharfe62cdce12006-10-07 01:47:35 +0200200 'extract ZIP archive' \
201 '(mkdir d && cd d && $UNZIP ../d.zip)'
202
Johannes Sixt552a26c2009-03-16 14:44:56 +0100203test_expect_success UNZIP \
Rene Scharfe62cdce12006-10-07 01:47:35 +0200204 'validate filenames' \
205 '(cd d/a && find .) | sort >d.lst &&
Miklos Vajna188c3822009-03-16 21:18:42 +0100206 test_cmp a.lst d.lst'
Rene Scharfe62cdce12006-10-07 01:47:35 +0200207
Johannes Sixt552a26c2009-03-16 14:44:56 +0100208test_expect_success UNZIP \
Rene Scharfe62cdce12006-10-07 01:47:35 +0200209 'validate file contents' \
210 'diff -r a d/a'
211
212test_expect_success \
Junio C Hamano5be60072007-07-02 22:52:14 -0700213 'git archive --format=zip with prefix' \
214 'git archive --format=zip --prefix=prefix/ HEAD >e.zip'
Rene Scharfe62cdce12006-10-07 01:47:35 +0200215
Johannes Sixt552a26c2009-03-16 14:44:56 +0100216test_expect_success UNZIP \
Rene Scharfe62cdce12006-10-07 01:47:35 +0200217 'extract ZIP archive with prefix' \
218 '(mkdir e && cd e && $UNZIP ../e.zip)'
219
Johannes Sixt552a26c2009-03-16 14:44:56 +0100220test_expect_success UNZIP \
Rene Scharfe62cdce12006-10-07 01:47:35 +0200221 'validate filenames with prefix' \
222 '(cd e/prefix/a && find .) | sort >e.lst &&
Miklos Vajna188c3822009-03-16 21:18:42 +0100223 test_cmp a.lst e.lst'
Rene Scharfe62cdce12006-10-07 01:47:35 +0200224
Johannes Sixt552a26c2009-03-16 14:44:56 +0100225test_expect_success UNZIP \
Rene Scharfe62cdce12006-10-07 01:47:35 +0200226 'validate file contents with prefix' \
227 'diff -r a e/prefix/a'
228
René Scharfe265d5282007-04-05 22:55:43 +0200229test_expect_success \
Junio C Hamano5be60072007-07-02 22:52:14 -0700230 'git archive --list outside of a git repo' \
231 'GIT_DIR=some/non-existing/directory git archive --list'
René Scharfe265d5282007-04-05 22:55:43 +0200232
René Scharfeebfbdb32009-10-08 18:46:54 +0200233test_expect_success 'git-archive --prefix=olde-' '
234 git archive --prefix=olde- >h.tar HEAD &&
235 (
236 mkdir h &&
237 cd h &&
238 "$TAR" xf - <../h.tar
239 ) &&
240 test -d h/olde-a &&
241 test -d h/olde-a/bin &&
242 test -f h/olde-a/bin/sh
243'
244
Rene Scharfed3d49c32005-06-02 22:50:17 +0200245test_done