Teach new attribute 'export-ignore' to git-archive
[git/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
cb34882b 28TAR=${TAR:-tar}
62cdce17 29UNZIP=${UNZIP:-unzip}
d3d49c3d 30
38c9c9b7 31SUBSTFORMAT=%H%n
8460b2fc 32
d3d49c3d
RS
33test_expect_success \
34 'populate workdir' \
35 'mkdir a b c &&
d3d49c3d 36 echo simple textfile >a/a &&
d3d49c3d 37 mkdir a/bin &&
5b860406 38 cp /bin/sh a/bin &&
760da960
RS
39 printf "A\$Format:%s\$O" "$SUBSTFORMAT" >a/substfile1 &&
40 printf "A not substituted O" >a/substfile2 &&
d3d49c3d 41 ln -s a a/l1 &&
4c691724
RS
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) &&
d3d49c3d
RS
45 (cd a && find .) | sort >a.lst'
46
008d896d
RS
47test_expect_success \
48 'add ignored file' \
49 'echo ignore me >a/ignored &&
50 echo ignored export-ignore >.gitattributes'
51
d3d49c3d
RS
52test_expect_success \
53 'add files to repository' \
5be60078
JH
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` &&
d3d49c3d 57 echo $treeid >treeid &&
5be60078
JH
58 git update-ref HEAD $(TZ=GMT GIT_COMMITTER_DATE="2005-05-27 22:00:00" \
59 git commit-tree $treeid </dev/null)'
d3d49c3d 60
008d896d
RS
61test_expect_success \
62 'remove ignored file' \
63 'rm a/ignored'
64
8ff21b1a 65test_expect_success \
5be60078
JH
66 'git archive' \
67 'git archive HEAD >b.tar'
8ff21b1a 68
d3d49c3d 69test_expect_success \
5be60078
JH
70 'git tar-tree' \
71 'git tar-tree HEAD >b2.tar'
8ff21b1a
RS
72
73test_expect_success \
5be60078 74 'git archive vs. git tar-tree' \
8ff21b1a 75 'diff b.tar b2.tar'
d3d49c3d
RS
76
77test_expect_success \
78 'validate file modification time' \
30684dfa
JK
79 'mkdir extract &&
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 &&
d3d49c3d
RS
83 diff expected.mtime b.mtime'
84
85test_expect_success \
5be60078
JH
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'
d3d49c3d
RS
89
90test_expect_success \
91 'extract tar archive' \
455a7f32 92 '(cd b && $TAR xf -) <b.tar'
d3d49c3d
RS
93
94test_expect_success \
95 'validate filenames' \
96 '(cd b/a && find .) | sort >b.lst &&
97 diff a.lst b.lst'
98
99test_expect_success \
100 'validate file contents' \
101 'diff -r a b/a'
102
103test_expect_success \
5be60078
JH
104 'git tar-tree with prefix' \
105 'git tar-tree HEAD prefix >c.tar'
d3d49c3d
RS
106
107test_expect_success \
108 'extract tar archive with prefix' \
455a7f32 109 '(cd c && $TAR xf -) <c.tar'
d3d49c3d
RS
110
111test_expect_success \
112 'validate filenames with prefix' \
113 '(cd c/prefix/a && find .) | sort >c.lst &&
114 diff a.lst c.lst'
115
116test_expect_success \
117 'validate file contents with prefix' \
118 'diff -r a c/prefix/a'
119
8460b2fc 120test_expect_success \
ac7fa277 121 'create archives with substfiles' \
760da960 122 'echo "substfile?" export-subst >a/.gitattributes &&
8460b2fc 123 git archive HEAD >f.tar &&
ac7fa277 124 git archive --prefix=prefix/ HEAD >g.tar &&
8460b2fc
RS
125 rm a/.gitattributes'
126
127test_expect_success \
760da960 128 'extract substfiles' \
8460b2fc
RS
129 '(mkdir f && cd f && $TAR xf -) <f.tar'
130
131test_expect_success \
38c9c9b7
RS
132 'validate substfile contents' \
133 'git log --max-count=1 "--pretty=format:A${SUBSTFORMAT}O" HEAD \
760da960
RS
134 >f/a/substfile1.expected &&
135 diff f/a/substfile1.expected f/a/substfile1 &&
136 diff a/substfile2 f/a/substfile2
137'
8460b2fc 138
ac7fa277
RS
139test_expect_success \
140 'extract substfiles from archive with prefix' \
141 '(mkdir g && cd g && $TAR xf -) <g.tar'
142
143test_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
149'
150
62cdce17 151test_expect_success \
5be60078
JH
152 'git archive --format=zip' \
153 'git archive --format=zip HEAD >d.zip'
62cdce17 154
27c96c4f 155$UNZIP -v >/dev/null 2>&1
3a86f36b
JS
156if [ $? -eq 127 ]; then
157 echo "Skipping ZIP tests, because unzip was not found"
158 test_done
159 exit
160fi
161
62cdce17
RS
162test_expect_success \
163 'extract ZIP archive' \
164 '(mkdir d && cd d && $UNZIP ../d.zip)'
165
166test_expect_success \
167 'validate filenames' \
168 '(cd d/a && find .) | sort >d.lst &&
169 diff a.lst d.lst'
170
171test_expect_success \
172 'validate file contents' \
173 'diff -r a d/a'
174
175test_expect_success \
5be60078
JH
176 'git archive --format=zip with prefix' \
177 'git archive --format=zip --prefix=prefix/ HEAD >e.zip'
62cdce17
RS
178
179test_expect_success \
180 'extract ZIP archive with prefix' \
181 '(mkdir e && cd e && $UNZIP ../e.zip)'
182
183test_expect_success \
184 'validate filenames with prefix' \
185 '(cd e/prefix/a && find .) | sort >e.lst &&
186 diff a.lst e.lst'
187
188test_expect_success \
189 'validate file contents with prefix' \
190 'diff -r a e/prefix/a'
191
265d5280 192test_expect_success \
5be60078
JH
193 'git archive --list outside of a git repo' \
194 'GIT_DIR=some/non-existing/directory git archive --list'
265d5280 195
d3d49c3d 196test_done