3 # Copyright (C) 2005 Rene Scharfe
6 test_description
='git tar-tree and git get-tar-commit-id test
8 This test covers the topics of file contents, commit date handling and
11 The contents of the repository is compared to the extracted tar
12 archive. The repository contains simple text files, symlinks and a
13 binary file (/bin/sh). Only paths shorter than 99 characters are
16 git tar-tree applies the commit date to every file in the archive it
17 creates. The test sets the commit date to a specific value and checks
18 if the tar archive contains that value.
20 When giving git tar-tree a commit id (in contrast to a tree id) it
21 embeds this commit id into the tar archive as a comment. The test
22 checks the ability of git get-tar-commit-id to figure it out from the
35 echo simple textfile >a/a &&
38 printf "A\$Format:%s\$O" "$SUBSTFORMAT" >a/substfile1 &&
39 printf "A not substituted O" >a/substfile2 &&
40 if test_have_prereq SYMLINKS; then
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) &&
48 (cd a && find .) | sort >a.lst'
52 'echo ignore me >a/ignored &&
53 echo ignored export-ignore >.gitattributes'
56 'add files to repository' \
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` &&
60 echo $treeid >treeid &&
61 git update-ref HEAD $(TZ=GMT GIT_COMMITTER_DATE="2005-05-27 22:00:00" \
62 git commit-tree $treeid </dev/null)'
66 'git clone --bare . bare.git &&
67 cp .gitattributes bare.git/info/attributes'
70 'remove ignored file' \
75 'git archive HEAD >b.tar'
79 'git tar-tree HEAD >b2.tar'
82 'git archive vs. git tar-tree' \
83 'test_cmp b.tar b2.tar'
86 'git archive in a bare repo' \
87 '(cd bare.git && git archive HEAD) >b3.tar'
90 'git archive vs. the same in a bare repo' \
91 'test_cmp b.tar b3.tar'
93 test_expect_success
'git archive with --output' \
94 'git archive --output=b4.tar HEAD &&
95 test_cmp b.tar b4.tar'
98 'validate file modification time' \
100 "$TAR" xf b.tar -C extract a/a &&
101 test-chmtime -v +0 extract/a/a |cut -f 1 >b.mtime &&
102 echo "1117231200" >expected.mtime &&
103 test_cmp expected.mtime b.mtime'
105 test_expect_success \
106 'git get-tar-commit-id' \
107 'git get-tar-commit-id <b.tar >b.commitid &&
108 test_cmp .git/$(git symbolic-ref HEAD) b.commitid'
110 test_expect_success \
111 'extract tar archive' \
112 '(cd b && "$TAR" xf -) <b.tar'
114 test_expect_success \
115 'validate filenames' \
116 '(cd b/a && find .) | sort >b.lst &&
117 test_cmp a.lst b.lst'
119 test_expect_success \
120 'validate file contents' \
123 test_expect_success \
124 'git tar-tree with prefix' \
125 'git tar-tree HEAD prefix >c.tar'
127 test_expect_success \
128 'extract tar archive with prefix' \
129 '(cd c && "$TAR" xf -) <c.tar'
131 test_expect_success \
132 'validate filenames with prefix' \
133 '(cd c/prefix/a && find .) | sort >c.lst &&
134 test_cmp a.lst c.lst'
136 test_expect_success \
137 'validate file contents with prefix' \
138 'diff -r a c/prefix/a'
140 test_expect_success \
141 'create archives with substfiles' \
142 'echo "substfile?" export-subst >a/.gitattributes &&
143 git archive HEAD >f.tar &&
144 git archive --prefix=prefix/ HEAD >g.tar &&
147 test_expect_success \
148 'extract substfiles' \
149 '(mkdir f && cd f && "$TAR" xf -) <f.tar'
151 test_expect_success \
152 'validate substfile contents' \
153 'git log --max-count=1 "--pretty=format:A${SUBSTFORMAT}O" HEAD \
154 >f/a/substfile1.expected &&
155 test_cmp f/a/substfile1.expected f/a/substfile1 &&
156 test_cmp a/substfile2 f/a/substfile2
159 test_expect_success \
160 'extract substfiles from archive with prefix' \
161 '(mkdir g && cd g && "$TAR" xf -) <g.tar'
163 test_expect_success \
164 'validate substfile contents from archive with prefix' \
165 'git log --max-count=1 "--pretty=format:A${SUBSTFORMAT}O" HEAD \
166 >g/prefix/a/substfile1.expected &&
167 test_cmp g/prefix/a/substfile1.expected g/prefix/a/substfile1 &&
168 test_cmp a/substfile2 g/prefix/a/substfile2
171 test_expect_success \
172 'git archive --format=zip' \
173 'git archive --format=zip HEAD >d.zip'
175 test_expect_success \
176 'git archive --format=zip in a bare repo' \
177 '(cd bare.git && git archive --format=zip HEAD) >d1.zip'
179 test_expect_success \
180 'git archive --format=zip vs. the same in a bare repo' \
181 'test_cmp d.zip d1.zip'
183 test_expect_success
'git archive --format=zip with --output' \
184 'git archive --format=zip --output=d2.zip HEAD &&
185 test_cmp d.zip d2.zip'
187 $UNZIP -v >/dev
/null
2>&1
188 if [ $?
-eq 127 ]; then
189 say
"Skipping ZIP tests, because unzip was not found"
191 test_set_prereq UNZIP
194 test_expect_success UNZIP \
195 'extract ZIP archive' \
196 '(mkdir d && cd d && $UNZIP ../d.zip)'
198 test_expect_success UNZIP \
199 'validate filenames' \
200 '(cd d/a && find .) | sort >d.lst &&
201 test_cmp a.lst d.lst'
203 test_expect_success UNZIP \
204 'validate file contents' \
207 test_expect_success \
208 'git archive --format=zip with prefix' \
209 'git archive --format=zip --prefix=prefix/ HEAD >e.zip'
211 test_expect_success UNZIP \
212 'extract ZIP archive with prefix' \
213 '(mkdir e && cd e && $UNZIP ../e.zip)'
215 test_expect_success UNZIP \
216 'validate filenames with prefix' \
217 '(cd e/prefix/a && find .) | sort >e.lst &&
218 test_cmp a.lst e.lst'
220 test_expect_success UNZIP \
221 'validate file contents with prefix' \
222 'diff -r a e/prefix/a'
224 test_expect_success \
225 'git archive --list outside of a git repo' \
226 'GIT_DIR=some/non-existing/directory git archive --list'