Report information on branches from remote.h
[alt-git.git] / t / t5000-tar-tree.sh
blob42e28ab758358500183ee8ade35d7052c69ce9e1
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 TAR=${TAR:-tar}
29 UNZIP=${UNZIP:-unzip}
31 SUBSTFORMAT=%H%n
33 test_expect_success \
34 'populate workdir' \
35 'mkdir a b c &&
36 echo simple textfile >a/a &&
37 mkdir a/bin &&
38 cp /bin/sh a/bin &&
39 printf "A\$Format:%s\$O" "$SUBSTFORMAT" >a/substfile &&
40 ln -s a a/l1 &&
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) &&
44 (cd a && find .) | sort >a.lst'
46 test_expect_success \
47 'add files to repository' \
48 'find a -type f | xargs git update-index --add &&
49 find a -type l | xargs git update-index --add &&
50 treeid=`git write-tree` &&
51 echo $treeid >treeid &&
52 git update-ref HEAD $(TZ=GMT GIT_COMMITTER_DATE="2005-05-27 22:00:00" \
53 git commit-tree $treeid </dev/null)'
55 test_expect_success \
56 'git archive' \
57 'git archive HEAD >b.tar'
59 test_expect_success \
60 'git tar-tree' \
61 'git tar-tree HEAD >b2.tar'
63 test_expect_success \
64 'git archive vs. git tar-tree' \
65 'diff b.tar b2.tar'
67 test_expect_success \
68 'validate file modification time' \
69 'TZ=GMT $TAR tvf b.tar a/a |
70 awk \{print\ \$4,\ \(length\(\$5\)\<7\)\ ?\ \$5\":00\"\ :\ \$5\} \
71 >b.mtime &&
72 echo "2005-05-27 22:00:00" >expected.mtime &&
73 diff expected.mtime b.mtime'
75 test_expect_success \
76 'git get-tar-commit-id' \
77 'git get-tar-commit-id <b.tar >b.commitid &&
78 diff .git/$(git symbolic-ref HEAD) b.commitid'
80 test_expect_success \
81 'extract tar archive' \
82 '(cd b && $TAR xf -) <b.tar'
84 test_expect_success \
85 'validate filenames' \
86 '(cd b/a && find .) | sort >b.lst &&
87 diff a.lst b.lst'
89 test_expect_success \
90 'validate file contents' \
91 'diff -r a b/a'
93 test_expect_success \
94 'git tar-tree with prefix' \
95 'git tar-tree HEAD prefix >c.tar'
97 test_expect_success \
98 'extract tar archive with prefix' \
99 '(cd c && $TAR xf -) <c.tar'
101 test_expect_success \
102 'validate filenames with prefix' \
103 '(cd c/prefix/a && find .) | sort >c.lst &&
104 diff a.lst c.lst'
106 test_expect_success \
107 'validate file contents with prefix' \
108 'diff -r a c/prefix/a'
110 test_expect_success \
111 'create an archive with a substfile' \
112 'echo substfile export-subst >a/.gitattributes &&
113 git archive HEAD >f.tar &&
114 rm a/.gitattributes'
116 test_expect_success \
117 'extract substfile' \
118 '(mkdir f && cd f && $TAR xf -) <f.tar'
120 test_expect_success \
121 'validate substfile contents' \
122 'git log --max-count=1 "--pretty=format:A${SUBSTFORMAT}O" HEAD \
123 >f/a/substfile.expected &&
124 diff f/a/substfile.expected f/a/substfile'
126 test_expect_success \
127 'git archive --format=zip' \
128 'git archive --format=zip HEAD >d.zip'
130 $UNZIP -v >/dev/null 2>&1
131 if [ $? -eq 127 ]; then
132 echo "Skipping ZIP tests, because unzip was not found"
133 test_done
134 exit
137 test_expect_success \
138 'extract ZIP archive' \
139 '(mkdir d && cd d && $UNZIP ../d.zip)'
141 test_expect_success \
142 'validate filenames' \
143 '(cd d/a && find .) | sort >d.lst &&
144 diff a.lst d.lst'
146 test_expect_success \
147 'validate file contents' \
148 'diff -r a d/a'
150 test_expect_success \
151 'git archive --format=zip with prefix' \
152 'git archive --format=zip --prefix=prefix/ HEAD >e.zip'
154 test_expect_success \
155 'extract ZIP archive with prefix' \
156 '(mkdir e && cd e && $UNZIP ../e.zip)'
158 test_expect_success \
159 'validate filenames with prefix' \
160 '(cd e/prefix/a && find .) | sort >e.lst &&
161 diff a.lst e.lst'
163 test_expect_success \
164 'validate file contents with prefix' \
165 'diff -r a e/prefix/a'
167 test_expect_success \
168 'git archive --list outside of a git repo' \
169 'GIT_DIR=some/non-existing/directory git archive --list'
171 test_done