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'
55 'add files to repository' \
56 'find a -type f | xargs git update-index --add &&
57 find a -type l | xargs git update-index --add &&
58 treeid=`git write-tree` &&
59 echo $treeid >treeid &&
60 git update-ref HEAD $(TZ=GMT GIT_COMMITTER_DATE="2005-05-27 22:00:00" \
61 git commit-tree $treeid </dev/null)'
65 'git archive HEAD >b.tar'
69 'git tar-tree HEAD >b2.tar'
72 'git archive vs. git tar-tree' \
76 'validate file modification time' \
78 $TAR xf b.tar -C extract a/a &&
79 perl -e '\''print((stat("extract/a/a"))[9], "\n")'\'' >b.mtime &&
80 echo "1117231200" >expected.mtime &&
81 diff expected.mtime b.mtime'
84 'git get-tar-commit-id' \
85 'git get-tar-commit-id <b.tar >b.commitid &&
86 diff .git/$(git symbolic-ref HEAD) b.commitid'
89 'extract tar archive' \
90 '(cd b && $TAR xf -) <b.tar'
93 'validate filenames' \
94 '(cd b/a && find .) | sort >b.lst &&
98 'validate file contents' \
101 test_expect_success \
102 'git tar-tree with prefix' \
103 'git tar-tree HEAD prefix >c.tar'
105 test_expect_success \
106 'extract tar archive with prefix' \
107 '(cd c && $TAR xf -) <c.tar'
109 test_expect_success \
110 'validate filenames with prefix' \
111 '(cd c/prefix/a && find .) | sort >c.lst &&
114 test_expect_success \
115 'validate file contents with prefix' \
116 'diff -r a c/prefix/a'
118 test_expect_success \
119 'create archives with substfiles' \
120 'echo "substfile?" export-subst >a/.gitattributes &&
121 git archive HEAD >f.tar &&
122 git archive --prefix=prefix/ HEAD >g.tar &&
125 test_expect_success \
126 'extract substfiles' \
127 '(mkdir f && cd f && $TAR xf -) <f.tar'
129 test_expect_success \
130 'validate substfile contents' \
131 'git log --max-count=1 "--pretty=format:A${SUBSTFORMAT}O" HEAD \
132 >f/a/substfile1.expected &&
133 diff f/a/substfile1.expected f/a/substfile1 &&
134 diff a/substfile2 f/a/substfile2
137 test_expect_success \
138 'extract substfiles from archive with prefix' \
139 '(mkdir g && cd g && $TAR xf -) <g.tar'
141 test_expect_success \
142 'validate substfile contents from archive with prefix' \
143 'git log --max-count=1 "--pretty=format:A${SUBSTFORMAT}O" HEAD \
144 >g/prefix/a/substfile1.expected &&
145 diff g/prefix/a/substfile1.expected g/prefix/a/substfile1 &&
146 diff a/substfile2 g/prefix/a/substfile2
149 test_expect_success \
150 'git archive --format=zip' \
151 'git archive --format=zip HEAD >d.zip'
153 $UNZIP -v >/dev
/null
2>&1
154 if [ $?
-eq 127 ]; then
155 echo "Skipping ZIP tests, because unzip was not found"
160 test_expect_success \
161 'extract ZIP archive' \
162 '(mkdir d && cd d && $UNZIP ../d.zip)'
164 test_expect_success \
165 'validate filenames' \
166 '(cd d/a && find .) | sort >d.lst &&
169 test_expect_success \
170 'validate file contents' \
173 test_expect_success \
174 'git archive --format=zip with prefix' \
175 'git archive --format=zip --prefix=prefix/ HEAD >e.zip'
177 test_expect_success \
178 'extract ZIP archive with prefix' \
179 '(mkdir e && cd e && $UNZIP ../e.zip)'
181 test_expect_success \
182 'validate filenames with prefix' \
183 '(cd e/prefix/a && find .) | sort >e.lst &&
186 test_expect_success \
187 'validate file contents with prefix' \
188 'diff -r a e/prefix/a'
190 test_expect_success \
191 'git archive --list outside of a git repo' \
192 'GIT_DIR=some/non-existing/directory git archive --list'