@@ -30,10 +30,76 @@ GUNZIP=${GUNZIP:-gzip -d}
3030
3131SUBSTFORMAT=%H%n
3232
33+ test_lazy_prereq TAR_NEEDS_PAX_FALLBACK '
34+ (
35+ mkdir pax &&
36+ cd pax &&
37+ "$TAR" xf "$TEST_DIRECTORY"/t5000/pax.tar &&
38+ test -f PaxHeaders.1791/file
39+ )
40+ '
41+
42+ get_pax_header () {
43+ file=$1
44+ header=$2 =
45+
46+ while read len rest
47+ do
48+ if test " $len " = $( echo " $len $rest " | wc -c)
49+ then
50+ case " $rest " in
51+ $header * )
52+ echo " ${rest# $header } "
53+ ;;
54+ esac
55+ fi
56+ done < " $file "
57+ }
58+
59+ check_tar () {
60+ tarfile=$1 .tar
61+ listfile=$1 .lst
62+ dir=$1
63+ dir_with_prefix=$dir /$2
64+
65+ test_expect_success ' extract tar archive' '
66+ (mkdir $dir && cd $dir && "$TAR" xf -) <$tarfile
67+ '
68+
69+ test_expect_success TAR_NEEDS_PAX_FALLBACK ' interpret pax headers' '
70+ (
71+ cd $dir &&
72+ for header in *.paxheader
73+ do
74+ data=${header%.paxheader}.data &&
75+ if test -h $data -o -e $data
76+ then
77+ path=$(get_pax_header $header path) &&
78+ if test -n "$path"
79+ then
80+ mv "$data" "$path"
81+ fi
82+ fi
83+ done
84+ )
85+ '
86+
87+ test_expect_success ' validate filenames' '
88+ (cd ${dir_with_prefix}a && find .) | sort >$listfile &&
89+ test_cmp a.lst $listfile
90+ '
91+
92+ test_expect_success ' validate file contents' '
93+ diff -r a ${dir_with_prefix}a
94+ '
95+ }
96+
3397test_expect_success \
3498 ' populate workdir' \
35- ' mkdir a b c &&
99+ ' mkdir a &&
36100 echo simple textfile >a/a &&
101+ ten=0123456789 && hundred=$ten$ten$ten$ten$ten$ten$ten$ten$ten$ten &&
102+ echo long filename >a/four$hundred &&
37103 mkdir a/bin &&
38104 cp /bin/sh a/bin &&
39105 printf "A\$Format:%s\$O" "$SUBSTFORMAT" >a/substfile1 &&
@@ -62,6 +128,12 @@ test_expect_success \
62128 git update-ref HEAD $(TZ=GMT GIT_COMMITTER_DATE="2005-05-27 22:00:00" \
63129 git commit-tree $treeid </dev/null)'
64130
131+ test_expect_success ' setup export-subst' '
132+ echo "substfile?" export-subst >>.git/info/attributes &&
133+ git log --max-count=1 "--pretty=format:A${SUBSTFORMAT}O" HEAD \
134+ >a/substfile1
135+ '
136+
65137test_expect_success \
66138 ' create bare clone' \
67139 ' git clone --bare . bare.git &&
@@ -75,13 +147,19 @@ test_expect_success \
75147 ' git archive' \
76148 ' git archive HEAD >b.tar'
77149
78- test_expect_success \
79- ' git tar-tree' \
80- ' git tar-tree HEAD >b2.tar'
150+ check_tar b
81151
82- test_expect_success \
83- ' git archive vs. git tar-tree' \
84- ' test_cmp b.tar b2.tar'
152+ test_expect_success ' git archive --prefix=prefix/' '
153+ git archive --prefix=prefix/ HEAD >with_prefix.tar
154+ '
155+
156+ check_tar with_prefix prefix/
157+
158+ test_expect_success ' git-archive --prefix=olde-' '
159+ git archive --prefix=olde- HEAD >with_olde-prefix.tar
160+ '
161+
162+ check_tar with_olde-prefix olde-
85163
86164test_expect_success ' git archive on large files' '
87165 test_config core.bigfilethreshold 1 &&
@@ -118,66 +196,14 @@ test_expect_success \
118196 ' git get-tar-commit-id <b.tar >b.commitid &&
119197 test_cmp .git/$(git symbolic-ref HEAD) b.commitid'
120198
121- test_expect_success \
122- ' extract tar archive' \
123- ' (cd b && "$TAR" xf -) <b.tar'
124-
125- test_expect_success \
126- ' validate filenames' \
127- ' (cd b/a && find .) | sort >b.lst &&
128- test_cmp a.lst b.lst'
129-
130- test_expect_success \
131- ' validate file contents' \
132- ' diff -r a b/a'
133-
134- test_expect_success \
135- ' git tar-tree with prefix' \
136- ' git tar-tree HEAD prefix >c.tar'
137-
138- test_expect_success \
139- ' extract tar archive with prefix' \
140- ' (cd c && "$TAR" xf -) <c.tar'
141-
142- test_expect_success \
143- ' validate filenames with prefix' \
144- ' (cd c/prefix/a && find .) | sort >c.lst &&
145- test_cmp a.lst c.lst'
146-
147- test_expect_success \
148- ' validate file contents with prefix' \
149- ' diff -r a c/prefix/a'
150-
151- test_expect_success \
152- ' create archives with substfiles' \
153- ' cp .git/info/attributes .git/info/attributes.before &&
154- echo "substfile?" export-subst >>.git/info/attributes &&
155- git archive HEAD >f.tar &&
156- git archive --prefix=prefix/ HEAD >g.tar &&
157- mv .git/info/attributes.before .git/info/attributes'
158-
159- test_expect_success \
160- ' extract substfiles' \
161- ' (mkdir f && cd f && "$TAR" xf -) <f.tar'
162-
163- test_expect_success \
164- ' validate substfile contents' \
165- ' git log --max-count=1 "--pretty=format:A${SUBSTFORMAT}O" HEAD \
166- >f/a/substfile1.expected &&
167- test_cmp f/a/substfile1.expected f/a/substfile1 &&
168- test_cmp a/substfile2 f/a/substfile2
199+ test_expect_success ' git tar-tree' '
200+ git tar-tree HEAD >tar-tree.tar &&
201+ test_cmp b.tar tar-tree.tar
169202'
170203
171- test_expect_success \
172- ' extract substfiles from archive with prefix' \
173- ' (mkdir g && cd g && "$TAR" xf -) <g.tar'
174-
175- test_expect_success \
176- ' validate substfile contents from archive with prefix' \
177- ' git log --max-count=1 "--pretty=format:A${SUBSTFORMAT}O" HEAD \
178- >g/prefix/a/substfile1.expected &&
179- test_cmp g/prefix/a/substfile1.expected g/prefix/a/substfile1 &&
180- test_cmp a/substfile2 g/prefix/a/substfile2
204+ test_expect_success ' git tar-tree with prefix' '
205+ git tar-tree HEAD prefix >tar-tree_with_prefix.tar &&
206+ test_cmp with_prefix.tar tar-tree_with_prefix.tar
181207'
182208
183209test_expect_success ' git archive with --output, override inferred format' '
@@ -197,18 +223,6 @@ test_expect_success 'clients cannot access unreachable commits' '
197223 test_must_fail git archive --remote=. $sha1 >remote.tar
198224'
199225
200- test_expect_success ' git-archive --prefix=olde-' '
201- git archive --prefix=olde- >h.tar HEAD &&
202- (
203- mkdir h &&
204- cd h &&
205- "$TAR" xf - <../h.tar
206- ) &&
207- test -d h/olde-a &&
208- test -d h/olde-a/bin &&
209- test -f h/olde-a/bin/sh
210- '
211-
212226test_expect_success ' setup tar filters' '
213227 git config tar.tar.foo.command "tr ab ba" &&
214228 git config tar.bar.command "tr ab ba" &&
0 commit comments