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' \
77 'TZ=GMT $TAR tvf b.tar a/a |
78 awk \{print\ \$4,\ \(length\(\$5\)\<7\)\ ?\ \$5\":00\"\ :\ \$5\} \
80 echo "2005-05-27 22:00:00" >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 an archive with a substfiles' \
120 'echo "substfile?" export-subst >a/.gitattributes &&
121 git archive HEAD >f.tar &&
124 test_expect_success \
125 'extract substfiles' \
126 '(mkdir f && cd f && $TAR xf -) <f.tar'
128 test_expect_success \
129 'validate substfile contents' \
130 'git log --max-count=1 "--pretty=format:A${SUBSTFORMAT}O" HEAD \
131 >f/a/substfile1.expected &&
132 diff f/a/substfile1.expected f/a/substfile1 &&
133 diff a/substfile2 f/a/substfile2
136 test_expect_success \
137 'git archive --format=zip' \
138 'git archive --format=zip HEAD >d.zip'
140 $UNZIP -v >/dev
/null
2>&1
141 if [ $?
-eq 127 ]; then
142 echo "Skipping ZIP tests, because unzip was not found"
147 test_expect_success \
148 'extract ZIP archive' \
149 '(mkdir d && cd d && $UNZIP ../d.zip)'
151 test_expect_success \
152 'validate filenames' \
153 '(cd d/a && find .) | sort >d.lst &&
156 test_expect_success \
157 'validate file contents' \
160 test_expect_success \
161 'git archive --format=zip with prefix' \
162 'git archive --format=zip --prefix=prefix/ HEAD >e.zip'
164 test_expect_success \
165 'extract ZIP archive with prefix' \
166 '(mkdir e && cd e && $UNZIP ../e.zip)'
168 test_expect_success \
169 'validate filenames with prefix' \
170 '(cd e/prefix/a && find .) | sort >e.lst &&
173 test_expect_success \
174 'validate file contents with prefix' \
175 'diff -r a e/prefix/a'
177 test_expect_success \
178 'git archive --list outside of a git repo' \
179 'GIT_DIR=some/non-existing/directory git archive --list'