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
30 test "$no_symlinks" && {
32 test "$1" = -s && shift
42 echo simple textfile >a/a &&
45 printf "A\$Format:%s\$O" "$SUBSTFORMAT" >a/substfile1 &&
46 printf "A not substituted O" >a/substfile2 &&
48 (p=long_path_to_a_file && cd a &&
49 for depth in 1 2 3 4 5; do mkdir $p && cd $p; done &&
50 echo text >file_with_long_path) &&
51 (cd a && find .) | sort >a.lst'
55 'echo ignore me >a/ignored &&
56 echo ignored export-ignore >.gitattributes'
59 'add files to repository' \
60 'find a -type f | xargs git update-index --add &&
61 find a -type l | xargs git update-index --add &&
62 treeid=`git write-tree` &&
63 echo $treeid >treeid &&
64 git update-ref HEAD $(TZ=GMT GIT_COMMITTER_DATE="2005-05-27 22:00:00" \
65 git commit-tree $treeid </dev/null)'
69 'git clone --bare . bare.git &&
70 cp .gitattributes bare.git/info/attributes'
73 'remove ignored file' \
78 'git archive HEAD >b.tar'
82 'git tar-tree HEAD >b2.tar'
85 'git archive vs. git tar-tree' \
89 'git archive in a bare repo' \
90 '(cd bare.git && git archive HEAD) >b3.tar'
93 'git archive vs. the same in a bare repo' \
94 'test_cmp b.tar b3.tar'
97 'validate file modification time' \
99 "$TAR" xf b.tar -C extract a/a &&
100 test-chmtime -v +0 extract/a/a |cut -f 1 >b.mtime &&
101 echo "1117231200" >expected.mtime &&
102 diff expected.mtime b.mtime'
104 test_expect_success \
105 'git get-tar-commit-id' \
106 'git get-tar-commit-id <b.tar >b.commitid &&
107 diff .git/$(git symbolic-ref HEAD) b.commitid'
109 test_expect_success \
110 'extract tar archive' \
111 '(cd b && "$TAR" xf -) <b.tar'
113 test_expect_success \
114 'validate filenames' \
115 '(cd b/a && find .) | sort >b.lst &&
118 test_expect_success \
119 'validate file contents' \
122 test_expect_success \
123 'git tar-tree with prefix' \
124 'git tar-tree HEAD prefix >c.tar'
126 test_expect_success \
127 'extract tar archive with prefix' \
128 '(cd c && "$TAR" xf -) <c.tar'
130 test_expect_success \
131 'validate filenames with prefix' \
132 '(cd c/prefix/a && find .) | sort >c.lst &&
135 test_expect_success \
136 'validate file contents with prefix' \
137 'diff -r a c/prefix/a'
139 test_expect_success \
140 'create archives with substfiles' \
141 'echo "substfile?" export-subst >a/.gitattributes &&
142 git archive HEAD >f.tar &&
143 git archive --prefix=prefix/ HEAD >g.tar &&
146 test_expect_success \
147 'extract substfiles' \
148 '(mkdir f && cd f && "$TAR" xf -) <f.tar'
150 test_expect_success \
151 'validate substfile contents' \
152 'git log --max-count=1 "--pretty=format:A${SUBSTFORMAT}O" HEAD \
153 >f/a/substfile1.expected &&
154 diff f/a/substfile1.expected f/a/substfile1 &&
155 diff a/substfile2 f/a/substfile2
158 test_expect_success \
159 'extract substfiles from archive with prefix' \
160 '(mkdir g && cd g && "$TAR" xf -) <g.tar'
162 test_expect_success \
163 'validate substfile contents from archive with prefix' \
164 'git log --max-count=1 "--pretty=format:A${SUBSTFORMAT}O" HEAD \
165 >g/prefix/a/substfile1.expected &&
166 diff g/prefix/a/substfile1.expected g/prefix/a/substfile1 &&
167 diff a/substfile2 g/prefix/a/substfile2
170 test_expect_success \
171 'git archive --format=zip' \
172 'git archive --format=zip HEAD >d.zip'
174 test_expect_success \
175 'git archive --format=zip in a bare repo' \
176 '(cd bare.git && git archive --format=zip HEAD) >d1.zip'
178 test_expect_success \
179 'git archive --format=zip vs. the same in a bare repo' \
180 'test_cmp d.zip d1.zip'
182 $UNZIP -v >/dev
/null
2>&1
183 if [ $?
-eq 127 ]; then
184 echo "Skipping ZIP tests, because unzip was not found"
189 test_expect_success \
190 'extract ZIP archive' \
191 '(mkdir d && cd d && $UNZIP ../d.zip)'
193 test_expect_success \
194 'validate filenames' \
195 '(cd d/a && find .) | sort >d.lst &&
198 test_expect_success \
199 'validate file contents' \
202 test_expect_success \
203 'git archive --format=zip with prefix' \
204 'git archive --format=zip --prefix=prefix/ HEAD >e.zip'
206 test_expect_success \
207 'extract ZIP archive with prefix' \
208 '(mkdir e && cd e && $UNZIP ../e.zip)'
210 test_expect_success \
211 'validate filenames with prefix' \
212 '(cd e/prefix/a && find .) | sort >e.lst &&
215 test_expect_success \
216 'validate file contents with prefix' \
217 'diff -r a e/prefix/a'
219 test_expect_success \
220 'git archive --list outside of a git repo' \
221 'GIT_DIR=some/non-existing/directory git archive --list'