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 &&
41 (p=long_path_to_a_file && cd a &&
42 for depth in 1 2 3 4 5; do mkdir $p && cd $p; done &&
43 echo text >file_with_long_path) &&
44 (cd a && find .) | sort >a.lst'
48 'echo ignore me >a/ignored &&
49 echo ignored export-ignore >.gitattributes'
52 'add files to repository' \
53 'find a -type f | xargs git update-index --add &&
54 find a -type l | xargs git update-index --add &&
55 treeid=`git write-tree` &&
56 echo $treeid >treeid &&
57 git update-ref HEAD $(TZ=GMT GIT_COMMITTER_DATE="2005-05-27 22:00:00" \
58 git commit-tree $treeid </dev/null)'
62 'git clone --bare . bare.git &&
63 cp .gitattributes bare.git/info/attributes'
66 'remove ignored file' \
71 'git archive HEAD >b.tar'
75 'git tar-tree HEAD >b2.tar'
78 'git archive vs. git tar-tree' \
82 'git archive in a bare repo' \
83 '(cd bare.git && git archive HEAD) >b3.tar'
86 'git archive vs. the same in a bare repo' \
87 'test_cmp b.tar b3.tar'
89 test_expect_success 'git archive with --output' \
90 'git archive --output=b4.tar HEAD &&
91 test_cmp b.tar b4.tar'
94 'validate file modification time' \
96 "$TAR" xf b.tar -C extract a/a &&
97 test-chmtime -v +0 extract/a/a |cut -f 1 >b.mtime &&
98 echo "1117231200" >expected.mtime &&
99 diff expected.mtime b.mtime'
101 test_expect_success \
102 'git get-tar-commit-id' \
103 'git get-tar-commit-id <b.tar >b.commitid &&
104 diff .git/$(git symbolic-ref HEAD) b.commitid'
106 test_expect_success \
107 'extract tar archive' \
108 '(cd b && "$TAR" xf -) <b.tar'
110 test_expect_success \
111 'validate filenames' \
112 '(cd b/a && find .) | sort >b.lst &&
115 test_expect_success \
116 'validate file contents' \
119 test_expect_success \
120 'git tar-tree with prefix' \
121 'git tar-tree HEAD prefix >c.tar'
123 test_expect_success \
124 'extract tar archive with prefix' \
125 '(cd c && "$TAR" xf -) <c.tar'
127 test_expect_success \
128 'validate filenames with prefix' \
129 '(cd c/prefix/a && find .) | sort >c.lst &&
132 test_expect_success \
133 'validate file contents with prefix' \
134 'diff -r a c/prefix/a'
136 test_expect_success \
137 'create archives with substfiles' \
138 'echo "substfile?" export-subst >a/.gitattributes &&
139 git archive HEAD >f.tar &&
140 git archive --prefix=prefix/ HEAD >g.tar &&
143 test_expect_success \
144 'extract substfiles' \
145 '(mkdir f && cd f && "$TAR" xf -) <f.tar'
147 test_expect_success \
148 'validate substfile contents' \
149 'git log --max-count=1 "--pretty=format:A${SUBSTFORMAT}O" HEAD \
150 >f/a/substfile1.expected &&
151 diff f/a/substfile1.expected f/a/substfile1 &&
152 diff a/substfile2 f/a/substfile2
155 test_expect_success \
156 'extract substfiles from archive with prefix' \
157 '(mkdir g && cd g && "$TAR" xf -) <g.tar'
159 test_expect_success \
160 'validate substfile contents from archive with prefix' \
161 'git log --max-count=1 "--pretty=format:A${SUBSTFORMAT}O" HEAD \
162 >g/prefix/a/substfile1.expected &&
163 diff g/prefix/a/substfile1.expected g/prefix/a/substfile1 &&
164 diff a/substfile2 g/prefix/a/substfile2
167 test_expect_success \
168 'git archive --format=zip' \
169 'git archive --format=zip HEAD >d.zip'
171 test_expect_success \
172 'git archive --format=zip in a bare repo' \
173 '(cd bare.git && git archive --format=zip HEAD) >d1.zip'
175 test_expect_success \
176 'git archive --format=zip vs. the same in a bare repo' \
177 'test_cmp d.zip d1.zip'
179 test_expect_success 'git archive --format=zip with --output' \
180 'git archive --format=zip --output=d2.zip HEAD &&
181 test_cmp d.zip d2.zip'
183 $UNZIP -v >/dev/null 2>&1
184 if [ $? -eq 127 ]; then
185 echo "Skipping ZIP tests, because unzip was not found"
190 test_expect_success \
191 'extract ZIP archive' \
192 '(mkdir d && cd d && $UNZIP ../d.zip)'
194 test_expect_success \
195 'validate filenames' \
196 '(cd d/a && find .) | sort >d.lst &&
199 test_expect_success \
200 'validate file contents' \
203 test_expect_success \
204 'git archive --format=zip with prefix' \
205 'git archive --format=zip --prefix=prefix/ HEAD >e.zip'
207 test_expect_success \
208 'extract ZIP archive with prefix' \
209 '(mkdir e && cd e && $UNZIP ../e.zip)'
211 test_expect_success \
212 'validate filenames with prefix' \
213 '(cd e/prefix/a && find .) | sort >e.lst &&
216 test_expect_success \
217 'validate file contents with prefix' \
218 'diff -r a e/prefix/a'
220 test_expect_success \
221 'git archive --list outside of a git repo' \
222 'GIT_DIR=some/non-existing/directory git archive --list'