]> git.ipfire.org Git - thirdparty/git.git/blame - t/t5001-archive-attr.sh
The third batch
[thirdparty/git.git] / t / t5001-archive-attr.sh
CommitLineData
8aece7ff
RS
1#!/bin/sh
2
3test_description='git archive attribute tests'
4
8da0b02d 5TEST_CREATE_REPO_NO_TEMPLATE=1
7615cf94 6TEST_PASSES_SANITIZE_LEAK=true
8aece7ff
RS
7. ./test-lib.sh
8
35039ced 9SUBSTFORMAT='%H (%h)%n'
8aece7ff
RS
10
11test_expect_exists() {
bed69a6e 12 test_expect_${2:-success} " $1 exists" "test -e $1"
8aece7ff
RS
13}
14
15test_expect_missing() {
bed69a6e
RS
16 test_expect_${2:-success} " $1 does not exist" "test ! -e $1"
17}
18
19extract_tar_to_dir () {
20 (mkdir "$1" && cd "$1" && "$TAR" xf -) <"$1.tar"
8aece7ff
RS
21}
22
23test_expect_success 'setup' '
24 echo ignored >ignored &&
8da0b02d 25 mkdir .git/info &&
8aece7ff
RS
26 echo ignored export-ignore >>.git/info/attributes &&
27 git add ignored &&
28
29 echo ignored by tree >ignored-by-tree &&
30 echo ignored-by-tree export-ignore >.gitattributes &&
bed69a6e
RS
31 mkdir ignored-by-tree.d &&
32 >ignored-by-tree.d/file &&
33 echo ignored-by-tree.d export-ignore >>.gitattributes &&
34 git add ignored-by-tree ignored-by-tree.d .gitattributes &&
8aece7ff 35
92b1dd1b
RS
36 mkdir subdir &&
37 >subdir/included &&
38 >subdir/ignored-by-subtree &&
39 >subdir/ignored-by-tree &&
40 echo ignored-by-subtree export-ignore >subdir/.gitattributes &&
41 git add subdir &&
42
8aece7ff
RS
43 echo ignored by worktree >ignored-by-worktree &&
44 echo ignored-by-worktree export-ignore >.gitattributes &&
45 git add ignored-by-worktree &&
46
bed69a6e
RS
47 mkdir excluded-by-pathspec.d &&
48 >excluded-by-pathspec.d/file &&
49 git add excluded-by-pathspec.d &&
50
8aece7ff
RS
51 printf "A\$Format:%s\$O" "$SUBSTFORMAT" >nosubstfile &&
52 printf "A\$Format:%s\$O" "$SUBSTFORMAT" >substfile1 &&
53 printf "A not substituted O" >substfile2 &&
54 echo "substfile?" export-subst >>.git/info/attributes &&
55 git add nosubstfile substfile1 substfile2 &&
56
57 git commit -m. &&
58
8da0b02d
ÆAB
59 git clone --template= --bare . bare &&
60 mkdir bare/info &&
8aece7ff
RS
61 cp .git/info/attributes bare/info/attributes
62'
63
64test_expect_success 'git archive' '
65 git archive HEAD >archive.tar &&
66 (mkdir archive && cd archive && "$TAR" xf -) <archive.tar
67'
68
69test_expect_missing archive/ignored
70test_expect_missing archive/ignored-by-tree
bed69a6e
RS
71test_expect_missing archive/ignored-by-tree.d
72test_expect_missing archive/ignored-by-tree.d/file
8aece7ff 73test_expect_exists archive/ignored-by-worktree
bed69a6e
RS
74test_expect_exists archive/excluded-by-pathspec.d
75test_expect_exists archive/excluded-by-pathspec.d/file
76
77test_expect_success 'git archive with pathspec' '
78 git archive HEAD ":!excluded-by-pathspec.d" >archive-pathspec.tar &&
79 extract_tar_to_dir archive-pathspec
80'
81
82test_expect_missing archive-pathspec/ignored
83test_expect_missing archive-pathspec/ignored-by-tree
84test_expect_missing archive-pathspec/ignored-by-tree.d
85test_expect_missing archive-pathspec/ignored-by-tree.d/file
86test_expect_exists archive-pathspec/ignored-by-worktree
43180940 87test_expect_missing archive-pathspec/excluded-by-pathspec.d
bed69a6e
RS
88test_expect_missing archive-pathspec/excluded-by-pathspec.d/file
89
5ff247ac 90test_expect_success 'git archive with wildcard pathspec' '
bed69a6e
RS
91 git archive HEAD ":!excluded-by-p*" >archive-pathspec-wildcard.tar &&
92 extract_tar_to_dir archive-pathspec-wildcard
93'
94
95test_expect_missing archive-pathspec-wildcard/ignored
96test_expect_missing archive-pathspec-wildcard/ignored-by-tree
97test_expect_missing archive-pathspec-wildcard/ignored-by-tree.d
98test_expect_missing archive-pathspec-wildcard/ignored-by-tree.d/file
5ff247ac 99test_expect_exists archive-pathspec-wildcard/ignored-by-worktree
bed69a6e
RS
100test_expect_missing archive-pathspec-wildcard/excluded-by-pathspec.d
101test_expect_missing archive-pathspec-wildcard/excluded-by-pathspec.d/file
8aece7ff 102
92b1dd1b
RS
103test_expect_success 'git -C subdir archive' '
104 git -C subdir archive HEAD >archive-subdir.tar &&
105 extract_tar_to_dir archive-subdir
106'
107
108test_expect_exists archive-subdir/included
109test_expect_missing archive-subdir/ignored-by-subtree
110test_expect_missing archive-subdir/ignored-by-tree
111
8aece7ff
RS
112test_expect_success 'git archive with worktree attributes' '
113 git archive --worktree-attributes HEAD >worktree.tar &&
114 (mkdir worktree && cd worktree && "$TAR" xf -) <worktree.tar
115'
116
117test_expect_missing worktree/ignored
118test_expect_exists worktree/ignored-by-tree
119test_expect_missing worktree/ignored-by-worktree
120
f858c646
JH
121test_expect_success 'git archive --worktree-attributes option' '
122 git archive --worktree-attributes --worktree-attributes HEAD >worktree.tar &&
123 (mkdir worktree2 && cd worktree2 && "$TAR" xf -) <worktree.tar
124'
125
126test_expect_missing worktree2/ignored
127test_expect_exists worktree2/ignored-by-tree
128test_expect_missing worktree2/ignored-by-worktree
129
8aece7ff
RS
130test_expect_success 'git archive vs. bare' '
131 (cd bare && git archive HEAD) >bare-archive.tar &&
b93e6e36 132 test_cmp_bin archive.tar bare-archive.tar
8aece7ff
RS
133'
134
135test_expect_success 'git archive with worktree attributes, bare' '
51441e64
JH
136 (cd bare &&
137 git -c attr.tree=HEAD archive --worktree-attributes HEAD) >bare-worktree.tar &&
8aece7ff
RS
138 (mkdir bare-worktree && cd bare-worktree && "$TAR" xf -) <bare-worktree.tar
139'
140
141test_expect_missing bare-worktree/ignored
23865355 142test_expect_missing bare-worktree/ignored-by-tree
8aece7ff
RS
143test_expect_exists bare-worktree/ignored-by-worktree
144
145test_expect_success 'export-subst' '
146 git log "--pretty=format:A${SUBSTFORMAT}O" HEAD >substfile1.expected &&
147 test_cmp nosubstfile archive/nosubstfile &&
148 test_cmp substfile1.expected archive/substfile1 &&
149 test_cmp substfile2 archive/substfile2
150'
151
96099726
RS
152test_expect_success 'export-subst expands %(describe) once' '
153 echo "\$Format:%(describe)\$" >substfile3 &&
154 echo "\$Format:%(describe)\$" >>substfile3 &&
155 echo "\$Format:%(describe)${LF}%(describe)\$" >substfile4 &&
156 git add substfile[34] &&
157 git commit -m export-subst-describe &&
158 git tag -m export-subst-describe export-subst-describe &&
159 git archive HEAD >archive-describe.tar &&
160 extract_tar_to_dir archive-describe &&
161 desc=$(git describe) &&
162 grep -F "$desc" archive-describe/substfile[34] >substituted &&
163 test_line_count = 1 substituted
164'
165
8aece7ff 166test_done