]> git.ipfire.org Git - thirdparty/git.git/blame - t/t5000-tar-tree.sh
t9100, t9129: Use prerequisite tags for UTF-8 tests
[thirdparty/git.git] / t / t5000-tar-tree.sh
CommitLineData
d3d49c3d
RS
1#!/bin/sh
2#
3# Copyright (C) 2005 Rene Scharfe
4#
5
5be60078 6test_description='git tar-tree and git get-tar-commit-id test
d3d49c3d 7
5b860406
RS
8This test covers the topics of file contents, commit date handling and
9commit id embedding:
d3d49c3d
RS
10
11 The contents of the repository is compared to the extracted tar
12 archive. The repository contains simple text files, symlinks and a
3dff5379 13 binary file (/bin/sh). Only paths shorter than 99 characters are
5b860406 14 used.
d3d49c3d 15
5be60078 16 git tar-tree applies the commit date to every file in the archive it
d3d49c3d
RS
17 creates. The test sets the commit date to a specific value and checks
18 if the tar archive contains that value.
19
5be60078 20 When giving git tar-tree a commit id (in contrast to a tree id) it
d3d49c3d 21 embeds this commit id into the tar archive as a comment. The test
5be60078 22 checks the ability of git get-tar-commit-id to figure it out from the
d3d49c3d
RS
23 tar file.
24
25'
26
27. ./test-lib.sh
62cdce17 28UNZIP=${UNZIP:-unzip}
d3d49c3d 29
38c9c9b7 30SUBSTFORMAT=%H%n
8460b2fc 31
d3d49c3d
RS
32test_expect_success \
33 'populate workdir' \
34 'mkdir a b c &&
d3d49c3d 35 echo simple textfile >a/a &&
d3d49c3d 36 mkdir a/bin &&
5b860406 37 cp /bin/sh a/bin &&
760da960
RS
38 printf "A\$Format:%s\$O" "$SUBSTFORMAT" >a/substfile1 &&
39 printf "A not substituted O" >a/substfile2 &&
d3d49c3d 40 ln -s a a/l1 &&
4c691724
RS
41 (p=long_path_to_a_file && cd a &&
42 for depth in 1 2 3 4 5; do mkdir $p && cd $p; done &&
43 echo text >file_with_long_path) &&
d3d49c3d
RS
44 (cd a && find .) | sort >a.lst'
45
008d896d
RS
46test_expect_success \
47 'add ignored file' \
48 'echo ignore me >a/ignored &&
49 echo ignored export-ignore >.gitattributes'
50
d3d49c3d
RS
51test_expect_success \
52 'add files to repository' \
5be60078
JH
53 'find a -type f | xargs git update-index --add &&
54 find a -type l | xargs git update-index --add &&
55 treeid=`git write-tree` &&
d3d49c3d 56 echo $treeid >treeid &&
5be60078
JH
57 git update-ref HEAD $(TZ=GMT GIT_COMMITTER_DATE="2005-05-27 22:00:00" \
58 git commit-tree $treeid </dev/null)'
d3d49c3d 59
ddff8563
CB
60test_expect_success \
61 'create bare clone' \
62 'git clone --bare . bare.git &&
63 cp .gitattributes bare.git/info/attributes'
64
008d896d
RS
65test_expect_success \
66 'remove ignored file' \
67 'rm a/ignored'
68
8ff21b1a 69test_expect_success \
5be60078
JH
70 'git archive' \
71 'git archive HEAD >b.tar'
8ff21b1a 72
d3d49c3d 73test_expect_success \
5be60078
JH
74 'git tar-tree' \
75 'git tar-tree HEAD >b2.tar'
8ff21b1a
RS
76
77test_expect_success \
5be60078 78 'git archive vs. git tar-tree' \
188c3827 79 'test_cmp b.tar b2.tar'
d3d49c3d 80
ddff8563
CB
81test_expect_success \
82 'git archive in a bare repo' \
83 '(cd bare.git && git archive HEAD) >b3.tar'
84
85test_expect_success \
86 'git archive vs. the same in a bare repo' \
87 'test_cmp b.tar b3.tar'
88
aec0c1bb
CMDV
89test_expect_success 'git archive with --output' \
90 'git archive --output=b4.tar HEAD &&
91 test_cmp b.tar b4.tar'
92
d3d49c3d
RS
93test_expect_success \
94 'validate file modification time' \
30684dfa 95 'mkdir extract &&
bfce5087 96 "$TAR" xf b.tar -C extract a/a &&
111539a3 97 test-chmtime -v +0 extract/a/a |cut -f 1 >b.mtime &&
30684dfa 98 echo "1117231200" >expected.mtime &&
188c3827 99 test_cmp expected.mtime b.mtime'
d3d49c3d
RS
100
101test_expect_success \
5be60078
JH
102 'git get-tar-commit-id' \
103 'git get-tar-commit-id <b.tar >b.commitid &&
188c3827 104 test_cmp .git/$(git symbolic-ref HEAD) b.commitid'
d3d49c3d
RS
105
106test_expect_success \
107 'extract tar archive' \
bfce5087 108 '(cd b && "$TAR" xf -) <b.tar'
d3d49c3d
RS
109
110test_expect_success \
111 'validate filenames' \
112 '(cd b/a && find .) | sort >b.lst &&
188c3827 113 test_cmp a.lst b.lst'
d3d49c3d
RS
114
115test_expect_success \
116 'validate file contents' \
117 'diff -r a b/a'
118
119test_expect_success \
5be60078
JH
120 'git tar-tree with prefix' \
121 'git tar-tree HEAD prefix >c.tar'
d3d49c3d
RS
122
123test_expect_success \
124 'extract tar archive with prefix' \
bfce5087 125 '(cd c && "$TAR" xf -) <c.tar'
d3d49c3d
RS
126
127test_expect_success \
128 'validate filenames with prefix' \
129 '(cd c/prefix/a && find .) | sort >c.lst &&
188c3827 130 test_cmp a.lst c.lst'
d3d49c3d
RS
131
132test_expect_success \
133 'validate file contents with prefix' \
134 'diff -r a c/prefix/a'
135
8460b2fc 136test_expect_success \
ac7fa277 137 'create archives with substfiles' \
760da960 138 'echo "substfile?" export-subst >a/.gitattributes &&
8460b2fc 139 git archive HEAD >f.tar &&
ac7fa277 140 git archive --prefix=prefix/ HEAD >g.tar &&
8460b2fc
RS
141 rm a/.gitattributes'
142
143test_expect_success \
760da960 144 'extract substfiles' \
bfce5087 145 '(mkdir f && cd f && "$TAR" xf -) <f.tar'
8460b2fc
RS
146
147test_expect_success \
38c9c9b7
RS
148 'validate substfile contents' \
149 'git log --max-count=1 "--pretty=format:A${SUBSTFORMAT}O" HEAD \
760da960 150 >f/a/substfile1.expected &&
188c3827
MV
151 test_cmp f/a/substfile1.expected f/a/substfile1 &&
152 test_cmp a/substfile2 f/a/substfile2
760da960 153'
8460b2fc 154
ac7fa277
RS
155test_expect_success \
156 'extract substfiles from archive with prefix' \
bfce5087 157 '(mkdir g && cd g && "$TAR" xf -) <g.tar'
ac7fa277
RS
158
159test_expect_success \
160 'validate substfile contents from archive with prefix' \
161 'git log --max-count=1 "--pretty=format:A${SUBSTFORMAT}O" HEAD \
162 >g/prefix/a/substfile1.expected &&
188c3827
MV
163 test_cmp g/prefix/a/substfile1.expected g/prefix/a/substfile1 &&
164 test_cmp a/substfile2 g/prefix/a/substfile2
ac7fa277
RS
165'
166
62cdce17 167test_expect_success \
5be60078
JH
168 'git archive --format=zip' \
169 'git archive --format=zip HEAD >d.zip'
62cdce17 170
ddff8563
CB
171test_expect_success \
172 'git archive --format=zip in a bare repo' \
173 '(cd bare.git && git archive --format=zip HEAD) >d1.zip'
174
175test_expect_success \
176 'git archive --format=zip vs. the same in a bare repo' \
177 'test_cmp d.zip d1.zip'
178
aec0c1bb
CMDV
179test_expect_success 'git archive --format=zip with --output' \
180 'git archive --format=zip --output=d2.zip HEAD &&
181 test_cmp d.zip d2.zip'
182
27c96c4f 183$UNZIP -v >/dev/null 2>&1
3a86f36b 184if [ $? -eq 127 ]; then
fae74a04 185 say "Skipping ZIP tests, because unzip was not found"
3a86f36b
JS
186 test_done
187 exit
188fi
189
62cdce17
RS
190test_expect_success \
191 'extract ZIP archive' \
192 '(mkdir d && cd d && $UNZIP ../d.zip)'
193
194test_expect_success \
195 'validate filenames' \
196 '(cd d/a && find .) | sort >d.lst &&
188c3827 197 test_cmp a.lst d.lst'
62cdce17
RS
198
199test_expect_success \
200 'validate file contents' \
201 'diff -r a d/a'
202
203test_expect_success \
5be60078
JH
204 'git archive --format=zip with prefix' \
205 'git archive --format=zip --prefix=prefix/ HEAD >e.zip'
62cdce17
RS
206
207test_expect_success \
208 'extract ZIP archive with prefix' \
209 '(mkdir e && cd e && $UNZIP ../e.zip)'
210
211test_expect_success \
212 'validate filenames with prefix' \
213 '(cd e/prefix/a && find .) | sort >e.lst &&
188c3827 214 test_cmp a.lst e.lst'
62cdce17
RS
215
216test_expect_success \
217 'validate file contents with prefix' \
218 'diff -r a e/prefix/a'
219
265d5280 220test_expect_success \
5be60078
JH
221 'git archive --list outside of a git repo' \
222 'GIT_DIR=some/non-existing/directory git archive --list'
265d5280 223
d3d49c3d 224test_done