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
31 test "$no_symlinks" && {
33 test "$1" = -s && shift
43 echo simple textfile >a/a &&
46 printf "A\$Format:%s\$O" "$SUBSTFORMAT" >a/substfile1 &&
47 printf "A not substituted O" >a/substfile2 &&
49 (p=long_path_to_a_file && cd a &&
50 for depth in 1 2 3 4 5; do mkdir $p && cd $p; done &&
51 echo text >file_with_long_path) &&
52 (cd a && find .) | sort >a.lst'
56 'echo ignore me >a/ignored &&
57 echo ignored export-ignore >.gitattributes'
60 'add files to repository' \
61 'find a -type f | xargs git update-index --add &&
62 find a -type l | xargs git update-index --add &&
63 treeid=`git write-tree` &&
64 echo $treeid >treeid &&
65 git update-ref HEAD $(TZ=GMT GIT_COMMITTER_DATE="2005-05-27 22:00:00" \
66 git commit-tree $treeid </dev/null)'
69 'remove ignored file' \
74 'git archive HEAD >b.tar'
78 'git tar-tree HEAD >b2.tar'
81 'git archive vs. git tar-tree' \
85 'validate file modification time' \
87 $TAR xf b.tar -C extract a/a &&
88 perl -e '\''print((stat("extract/a/a"))[9], "\n")'\'' >b.mtime &&
89 echo "1117231200" >expected.mtime &&
90 diff expected.mtime b.mtime'
93 'git get-tar-commit-id' \
94 'git get-tar-commit-id <b.tar >b.commitid &&
95 diff .git/$(git symbolic-ref HEAD) b.commitid'
98 'extract tar archive' \
99 '(cd b && $TAR xf -) <b.tar'
101 test_expect_success \
102 'validate filenames' \
103 '(cd b/a && find .) | sort >b.lst &&
106 test_expect_success \
107 'validate file contents' \
110 test_expect_success \
111 'git tar-tree with prefix' \
112 'git tar-tree HEAD prefix >c.tar'
114 test_expect_success \
115 'extract tar archive with prefix' \
116 '(cd c && $TAR xf -) <c.tar'
118 test_expect_success \
119 'validate filenames with prefix' \
120 '(cd c/prefix/a && find .) | sort >c.lst &&
123 test_expect_success \
124 'validate file contents with prefix' \
125 'diff -r a c/prefix/a'
127 test_expect_success \
128 'create archives with substfiles' \
129 'echo "substfile?" export-subst >a/.gitattributes &&
130 git archive HEAD >f.tar &&
131 git archive --prefix=prefix/ HEAD >g.tar &&
134 test_expect_success \
135 'extract substfiles' \
136 '(mkdir f && cd f && $TAR xf -) <f.tar'
138 test_expect_success \
139 'validate substfile contents' \
140 'git log --max-count=1 "--pretty=format:A${SUBSTFORMAT}O" HEAD \
141 >f/a/substfile1.expected &&
142 diff f/a/substfile1.expected f/a/substfile1 &&
143 diff a/substfile2 f/a/substfile2
146 test_expect_success \
147 'extract substfiles from archive with prefix' \
148 '(mkdir g && cd g && $TAR xf -) <g.tar'
150 test_expect_success \
151 'validate substfile contents from archive with prefix' \
152 'git log --max-count=1 "--pretty=format:A${SUBSTFORMAT}O" HEAD \
153 >g/prefix/a/substfile1.expected &&
154 diff g/prefix/a/substfile1.expected g/prefix/a/substfile1 &&
155 diff a/substfile2 g/prefix/a/substfile2
158 test_expect_success \
159 'git archive --format=zip' \
160 'git archive --format=zip HEAD >d.zip'
162 $UNZIP -v >/dev
/null
2>&1
163 if [ $?
-eq 127 ]; then
164 echo "Skipping ZIP tests, because unzip was not found"
169 test_expect_success \
170 'extract ZIP archive' \
171 '(mkdir d && cd d && $UNZIP ../d.zip)'
173 test_expect_success \
174 'validate filenames' \
175 '(cd d/a && find .) | sort >d.lst &&
178 test_expect_success \
179 'validate file contents' \
182 test_expect_success \
183 'git archive --format=zip with prefix' \
184 'git archive --format=zip --prefix=prefix/ HEAD >e.zip'
186 test_expect_success \
187 'extract ZIP archive with prefix' \
188 '(mkdir e && cd e && $UNZIP ../e.zip)'
190 test_expect_success \
191 'validate filenames with prefix' \
192 '(cd e/prefix/a && find .) | sort >e.lst &&
195 test_expect_success \
196 'validate file contents with prefix' \
197 'diff -r a e/prefix/a'
199 test_expect_success \
200 'git archive --list outside of a git repo' \
201 'GIT_DIR=some/non-existing/directory git archive --list'