Let t0000 pass on Windows again
[git/dscho.git] / t / t5000-tar-tree.sh
blobb3e54e964190885de718e7a4dd4f506ee1e301e0
1 #!/bin/sh
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
9 commit id embedding:
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
14 used.
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
23 tar file.
27 . ./test-lib.sh
28 UNZIP=${UNZIP:-unzip}
30 test "$no_symlinks" && {
31 function ln () {
32 test "$1" = -s && shift
33 date > "$2"
37 SUBSTFORMAT=%H%n
39 test_expect_success \
40 'populate workdir' \
41 'mkdir a b c &&
42 echo simple textfile >a/a &&
43 mkdir a/bin &&
44 cp /bin/sh a/bin &&
45 printf "A\$Format:%s\$O" "$SUBSTFORMAT" >a/substfile1 &&
46 printf "A not substituted O" >a/substfile2 &&
47 ln -s a a/l1 &&
48 (p=long_path_to_a_file && cd a &&
49 for depth in 1 2 3 4 5; do mkdir $p && cd $p; done &&
50 echo text >file_with_long_path) &&
51 (cd a && find .) | sort >a.lst'
53 test_expect_success \
54 'add ignored file' \
55 'echo ignore me >a/ignored &&
56 echo ignored export-ignore >.gitattributes'
58 test_expect_success \
59 'add files to repository' \
60 'find a -type f | xargs git update-index --add &&
61 find a -type l | xargs git update-index --add &&
62 treeid=`git write-tree` &&
63 echo $treeid >treeid &&
64 git update-ref HEAD $(TZ=GMT GIT_COMMITTER_DATE="2005-05-27 22:00:00" \
65 git commit-tree $treeid </dev/null)'
67 test_expect_success \
68 'create bare clone' \
69 'git clone --bare . bare.git &&
70 cp .gitattributes bare.git/info/attributes'
72 test_expect_success \
73 'remove ignored file' \
74 'rm a/ignored'
76 test_expect_success \
77 'git archive' \
78 'git archive HEAD >b.tar'
80 test_expect_success \
81 'git tar-tree' \
82 'git tar-tree HEAD >b2.tar'
84 test_expect_success \
85 'git archive vs. git tar-tree' \
86 'test_cmp b.tar b2.tar'
88 test_expect_success \
89 'git archive in a bare repo' \
90 '(cd bare.git && git archive HEAD) >b3.tar'
92 test_expect_success \
93 'git archive vs. the same in a bare repo' \
94 'test_cmp b.tar b3.tar'
96 test_expect_success 'git archive with --output' \
97 'git archive --output=b4.tar HEAD &&
98 test_cmp b.tar b4.tar'
100 test_expect_success \
101 'validate file modification time' \
102 'mkdir extract &&
103 "$TAR" xf b.tar -C extract a/a &&
104 test-chmtime -v +0 extract/a/a |cut -f 1 >b.mtime &&
105 echo "1117231200" >expected.mtime &&
106 test_cmp expected.mtime b.mtime'
108 test_expect_success \
109 'git get-tar-commit-id' \
110 'git get-tar-commit-id <b.tar >b.commitid &&
111 test_cmp .git/$(git symbolic-ref HEAD) b.commitid'
113 test_expect_success \
114 'extract tar archive' \
115 '(cd b && "$TAR" xf -) <b.tar'
117 test_expect_success \
118 'validate filenames' \
119 '(cd b/a && find .) | sort >b.lst &&
120 test_cmp a.lst b.lst'
122 test_expect_success \
123 'validate file contents' \
124 'diff -r a b/a'
126 test_expect_success \
127 'git tar-tree with prefix' \
128 'git tar-tree HEAD prefix >c.tar'
130 test_expect_success \
131 'extract tar archive with prefix' \
132 '(cd c && "$TAR" xf -) <c.tar'
134 test_expect_success \
135 'validate filenames with prefix' \
136 '(cd c/prefix/a && find .) | sort >c.lst &&
137 test_cmp a.lst c.lst'
139 test_expect_success \
140 'validate file contents with prefix' \
141 'diff -r a c/prefix/a'
143 test_expect_success \
144 'create archives with substfiles' \
145 'echo "substfile?" export-subst >a/.gitattributes &&
146 git archive HEAD >f.tar &&
147 git archive --prefix=prefix/ HEAD >g.tar &&
148 rm a/.gitattributes'
150 test_expect_success \
151 'extract substfiles' \
152 '(mkdir f && cd f && "$TAR" xf -) <f.tar'
154 test_expect_success \
155 'validate substfile contents' \
156 'git log --max-count=1 "--pretty=format:A${SUBSTFORMAT}O" HEAD \
157 >f/a/substfile1.expected &&
158 test_cmp f/a/substfile1.expected f/a/substfile1 &&
159 test_cmp a/substfile2 f/a/substfile2
162 test_expect_success \
163 'extract substfiles from archive with prefix' \
164 '(mkdir g && cd g && "$TAR" xf -) <g.tar'
166 test_expect_success \
167 'validate substfile contents from archive with prefix' \
168 'git log --max-count=1 "--pretty=format:A${SUBSTFORMAT}O" HEAD \
169 >g/prefix/a/substfile1.expected &&
170 test_cmp g/prefix/a/substfile1.expected g/prefix/a/substfile1 &&
171 test_cmp a/substfile2 g/prefix/a/substfile2
174 test_expect_success \
175 'git archive --format=zip' \
176 'git archive --format=zip HEAD >d.zip'
178 test_expect_success \
179 'git archive --format=zip in a bare repo' \
180 '(cd bare.git && git archive --format=zip HEAD) >d1.zip'
182 test_expect_success \
183 'git archive --format=zip vs. the same in a bare repo' \
184 'test_cmp d.zip d1.zip'
186 test_expect_success 'git archive --format=zip with --output' \
187 'git archive --format=zip --output=d2.zip HEAD &&
188 test_cmp d.zip d2.zip'
190 $UNZIP -v >/dev/null 2>&1
191 if [ $? -eq 127 ]; then
192 echo "Skipping ZIP tests, because unzip was not found"
193 test_done
194 exit
197 test_expect_success \
198 'extract ZIP archive' \
199 '(mkdir d && cd d && $UNZIP ../d.zip)'
201 test_expect_success \
202 'validate filenames' \
203 '(cd d/a && find .) | sort >d.lst &&
204 test_cmp a.lst d.lst'
206 test_expect_success \
207 'validate file contents' \
208 'diff -r a d/a'
210 test_expect_success \
211 'git archive --format=zip with prefix' \
212 'git archive --format=zip --prefix=prefix/ HEAD >e.zip'
214 test_expect_success \
215 'extract ZIP archive with prefix' \
216 '(mkdir e && cd e && $UNZIP ../e.zip)'
218 test_expect_success \
219 'validate filenames with prefix' \
220 '(cd e/prefix/a && find .) | sort >e.lst &&
221 test_cmp a.lst e.lst'
223 test_expect_success \
224 'validate file contents with prefix' \
225 'diff -r a e/prefix/a'
227 test_expect_success \
228 'git archive --list outside of a git repo' \
229 'GIT_DIR=some/non-existing/directory git archive --list'
231 test_done