[PATCH] git-tar-tree: add a test case
[git.git] / t / t5000-tar-tree.sh
1 #!/bin/sh
2 #
3 # Copyright (C) 2005 Rene Scharfe
4 #
5
6 test_description='git-tar-tree and git-get-tar-commit-id test
7
8 This test covers the topics of long paths, file contents, commit date
9 handling and commit id embedding:
10
11   Paths longer than 100 characters require the use of a pax extended
12   header to store them.  The test creates files with pathes both longer
13   and shorter than 100 chars, and also checks symlinks with long and
14   short pathes both as their own name and as target path.
15
16   The contents of the repository is compared to the extracted tar
17   archive.  The repository contains simple text files, symlinks and a
18   binary file (/bin/sh).
19
20   git-tar-tree applies the commit date to every file in the archive it
21   creates.  The test sets the commit date to a specific value and checks
22   if the tar archive contains that value.
23
24   When giving git-tar-tree a commit id (in contrast to a tree id) it
25   embeds this commit id into the tar archive as a comment.  The test
26   checks the ability of git-get-tar-commit-id to figure it out from the
27   tar file.
28
29 '
30
31 . ./test-lib.sh
32
33 test_expect_success \
34     'populate workdir' \
35     'mkdir a b c &&
36      p48=1.......10........20........30........40......48 &&
37      p50=1.......10........20........30........40........50 &&
38      p98=${p48}${p50} &&
39      echo simple textfile >a/a &&
40      echo 100 chars in path >a/${p98} &&
41      echo 101 chars in path >a/${p98}x &&
42      echo 102 chars in path >a/${p98}xx &&
43      echo 103 chars in path >a/${p98}xxx &&
44      mkdir a/bin &&
45      cp /bin/sh a/bin/sh &&
46      ln -s a a/l1 &&
47      ln -s ${p98}xx a/l100 &&
48      ln -s ${p98}xxx a/l101 &&
49      ln -s ${p98}xxx a/l${p98} &&
50      (cd a && find .) | sort >a.lst'
51
52 test_expect_success \
53     'add files to repository' \
54     'find a -type f | xargs git-update-cache --add &&
55      find a -type l | xargs git-update-cache --add &&
56      treeid=`git-write-tree` &&
57      echo $treeid >treeid &&
58      TZ= GIT_COMMITTER_DATE="2005-05-27 22:00:00" \
59      git-commit-tree $treeid </dev/null >.git/HEAD'
60
61 test_expect_success \
62     'git-tar-tree' \
63     'git-tar-tree HEAD >b.tar'
64
65 test_expect_success \
66     'validate file modification time' \
67     'tar tvf b.tar a/a | awk \{print\ \$4,\$5\} >b.mtime &&
68      echo "2005-05-27 22:00:00" >expected.mtime &&
69      diff expected.mtime b.mtime'
70
71 test_expect_success \
72     'git-get-tar-commit-id' \
73     'git-get-tar-commit-id <b.tar >b.commitid &&
74      diff .git/HEAD b.commitid'
75
76 test_expect_success \
77     'extract tar archive' \
78     '(cd b && tar xf -) <b.tar'
79
80 test_expect_success \
81     'validate filenames' \
82     '(cd b/a && find .) | sort >b.lst &&
83      diff a.lst b.lst'
84
85 test_expect_success \
86     'validate file contents' \
87     'diff -r a b/a'
88
89 test_expect_success \
90     'git-tar-tree with prefix' \
91     'git-tar-tree HEAD prefix >c.tar'
92
93 test_expect_success \
94     'extract tar archive with prefix' \
95     '(cd c && tar xf -) <c.tar'
96
97 test_expect_success \
98     'validate filenames with prefix' \
99     '(cd c/prefix/a && find .) | sort >c.lst &&
100      diff a.lst c.lst'
101
102 test_expect_success \
103     'validate file contents with prefix' \
104     'diff -r a c/prefix/a'
105
106 test_done