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
36 echo simple textfile >a/a &&
39 printf "A\$Format:%s\$O" "$SUBSTFORMAT" >a/substfile1 &&
40 printf "A not substituted O" >a/substfile2 &&
42 (p=long_path_to_a_file && cd a &&
43 for depth in 1 2 3 4 5; do mkdir $p && cd $p; done &&
44 echo text >file_with_long_path) &&
45 (cd a && find .) | sort >a.lst'
49 'echo ignore me >a/ignored &&
50 echo ignored export-ignore >.gitattributes'
53 'add files to repository' \
54 'find a -type f | xargs git update-index --add &&
55 find a -type l | xargs git update-index --add &&
56 treeid=`git write-tree` &&
57 echo $treeid >treeid &&
58 git update-ref HEAD $(TZ=GMT GIT_COMMITTER_DATE="2005-05-27 22:00:00" \
59 git commit-tree $treeid </dev/null)'
62 'remove ignored file' \
67 'git archive HEAD >b.tar'
71 'git tar-tree HEAD >b2.tar'
74 'git archive vs. git tar-tree' \
78 'validate file modification time' \
80 $TAR xf b.tar -C extract a/a &&
81 perl -e '\''print((stat("extract/a/a"))[9], "\n")'\'' >b.mtime &&
82 echo "1117231200" >expected.mtime &&
83 diff expected.mtime b.mtime'
86 'git get-tar-commit-id' \
87 'git get-tar-commit-id <b.tar >b.commitid &&
88 diff .git/$(git symbolic-ref HEAD) b.commitid'
91 'extract tar archive' \
92 '(cd b && $TAR xf -) <b.tar'
95 'validate filenames' \
96 '(cd b/a && find .) | sort >b.lst &&
100 'validate file contents' \
103 test_expect_success \
104 'git tar-tree with prefix' \
105 'git tar-tree HEAD prefix >c.tar'
107 test_expect_success \
108 'extract tar archive with prefix' \
109 '(cd c && $TAR xf -) <c.tar'
111 test_expect_success \
112 'validate filenames with prefix' \
113 '(cd c/prefix/a && find .) | sort >c.lst &&
116 test_expect_success \
117 'validate file contents with prefix' \
118 'diff -r a c/prefix/a'
120 test_expect_success \
121 'create archives with substfiles' \
122 'echo "substfile?" export-subst >a/.gitattributes &&
123 git archive HEAD >f.tar &&
124 git archive --prefix=prefix/ HEAD >g.tar &&
127 test_expect_success \
128 'extract substfiles' \
129 '(mkdir f && cd f && $TAR xf -) <f.tar'
131 test_expect_success \
132 'validate substfile contents' \
133 'git log --max-count=1 "--pretty=format:A${SUBSTFORMAT}O" HEAD \
134 >f/a/substfile1.expected &&
135 diff f/a/substfile1.expected f/a/substfile1 &&
136 diff a/substfile2 f/a/substfile2
139 test_expect_success \
140 'extract substfiles from archive with prefix' \
141 '(mkdir g && cd g && $TAR xf -) <g.tar'
143 test_expect_success \
144 'validate substfile contents from archive with prefix' \
145 'git log --max-count=1 "--pretty=format:A${SUBSTFORMAT}O" HEAD \
146 >g/prefix/a/substfile1.expected &&
147 diff g/prefix/a/substfile1.expected g/prefix/a/substfile1 &&
148 diff a/substfile2 g/prefix/a/substfile2
151 test_expect_success \
152 'git archive --format=zip' \
153 'git archive --format=zip HEAD >d.zip'
155 $UNZIP -v >/dev/null 2>&1
156 if [ $? -eq 127 ]; then
157 echo "Skipping ZIP tests, because unzip was not found"
162 test_expect_success \
163 'extract ZIP archive' \
164 '(mkdir d && cd d && $UNZIP ../d.zip)'
166 test_expect_success \
167 'validate filenames' \
168 '(cd d/a && find .) | sort >d.lst &&
171 test_expect_success \
172 'validate file contents' \
175 test_expect_success \
176 'git archive --format=zip with prefix' \
177 'git archive --format=zip --prefix=prefix/ HEAD >e.zip'
179 test_expect_success \
180 'extract ZIP archive with prefix' \
181 '(mkdir e && cd e && $UNZIP ../e.zip)'
183 test_expect_success \
184 'validate filenames with prefix' \
185 '(cd e/prefix/a && find .) | sort >e.lst &&
188 test_expect_success \
189 'validate file contents with prefix' \
190 'diff -r a e/prefix/a'
192 test_expect_success \
193 'git archive --list outside of a git repo' \
194 'GIT_DIR=some/non-existing/directory git archive --list'