]> git.ipfire.org Git - thirdparty/git.git/blame - t/t5001-archive-attr.sh
various: add missing clear_pathspec(), fix leaks
[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
RS
35
36 echo ignored by worktree >ignored-by-worktree &&
37 echo ignored-by-worktree export-ignore >.gitattributes &&
38 git add ignored-by-worktree &&
39
bed69a6e
RS
40 mkdir excluded-by-pathspec.d &&
41 >excluded-by-pathspec.d/file &&
42 git add excluded-by-pathspec.d &&
43
8aece7ff
RS
44 printf "A\$Format:%s\$O" "$SUBSTFORMAT" >nosubstfile &&
45 printf "A\$Format:%s\$O" "$SUBSTFORMAT" >substfile1 &&
46 printf "A not substituted O" >substfile2 &&
47 echo "substfile?" export-subst >>.git/info/attributes &&
48 git add nosubstfile substfile1 substfile2 &&
49
50 git commit -m. &&
51
8da0b02d
ÆAB
52 git clone --template= --bare . bare &&
53 mkdir bare/info &&
8aece7ff
RS
54 cp .git/info/attributes bare/info/attributes
55'
56
57test_expect_success 'git archive' '
58 git archive HEAD >archive.tar &&
59 (mkdir archive && cd archive && "$TAR" xf -) <archive.tar
60'
61
62test_expect_missing archive/ignored
63test_expect_missing archive/ignored-by-tree
bed69a6e
RS
64test_expect_missing archive/ignored-by-tree.d
65test_expect_missing archive/ignored-by-tree.d/file
8aece7ff 66test_expect_exists archive/ignored-by-worktree
bed69a6e
RS
67test_expect_exists archive/excluded-by-pathspec.d
68test_expect_exists archive/excluded-by-pathspec.d/file
69
70test_expect_success 'git archive with pathspec' '
71 git archive HEAD ":!excluded-by-pathspec.d" >archive-pathspec.tar &&
72 extract_tar_to_dir archive-pathspec
73'
74
75test_expect_missing archive-pathspec/ignored
76test_expect_missing archive-pathspec/ignored-by-tree
77test_expect_missing archive-pathspec/ignored-by-tree.d
78test_expect_missing archive-pathspec/ignored-by-tree.d/file
79test_expect_exists archive-pathspec/ignored-by-worktree
43180940 80test_expect_missing archive-pathspec/excluded-by-pathspec.d
bed69a6e
RS
81test_expect_missing archive-pathspec/excluded-by-pathspec.d/file
82
5ff247ac 83test_expect_success 'git archive with wildcard pathspec' '
bed69a6e
RS
84 git archive HEAD ":!excluded-by-p*" >archive-pathspec-wildcard.tar &&
85 extract_tar_to_dir archive-pathspec-wildcard
86'
87
88test_expect_missing archive-pathspec-wildcard/ignored
89test_expect_missing archive-pathspec-wildcard/ignored-by-tree
90test_expect_missing archive-pathspec-wildcard/ignored-by-tree.d
91test_expect_missing archive-pathspec-wildcard/ignored-by-tree.d/file
5ff247ac 92test_expect_exists archive-pathspec-wildcard/ignored-by-worktree
bed69a6e
RS
93test_expect_missing archive-pathspec-wildcard/excluded-by-pathspec.d
94test_expect_missing archive-pathspec-wildcard/excluded-by-pathspec.d/file
8aece7ff
RS
95
96test_expect_success 'git archive with worktree attributes' '
97 git archive --worktree-attributes HEAD >worktree.tar &&
98 (mkdir worktree && cd worktree && "$TAR" xf -) <worktree.tar
99'
100
101test_expect_missing worktree/ignored
102test_expect_exists worktree/ignored-by-tree
103test_expect_missing worktree/ignored-by-worktree
104
f858c646
JH
105test_expect_success 'git archive --worktree-attributes option' '
106 git archive --worktree-attributes --worktree-attributes HEAD >worktree.tar &&
107 (mkdir worktree2 && cd worktree2 && "$TAR" xf -) <worktree.tar
108'
109
110test_expect_missing worktree2/ignored
111test_expect_exists worktree2/ignored-by-tree
112test_expect_missing worktree2/ignored-by-worktree
113
8aece7ff
RS
114test_expect_success 'git archive vs. bare' '
115 (cd bare && git archive HEAD) >bare-archive.tar &&
b93e6e36 116 test_cmp_bin archive.tar bare-archive.tar
8aece7ff
RS
117'
118
119test_expect_success 'git archive with worktree attributes, bare' '
120 (cd bare && git archive --worktree-attributes HEAD) >bare-worktree.tar &&
121 (mkdir bare-worktree && cd bare-worktree && "$TAR" xf -) <bare-worktree.tar
122'
123
124test_expect_missing bare-worktree/ignored
125test_expect_exists bare-worktree/ignored-by-tree
126test_expect_exists bare-worktree/ignored-by-worktree
127
128test_expect_success 'export-subst' '
129 git log "--pretty=format:A${SUBSTFORMAT}O" HEAD >substfile1.expected &&
130 test_cmp nosubstfile archive/nosubstfile &&
131 test_cmp substfile1.expected archive/substfile1 &&
132 test_cmp substfile2 archive/substfile2
133'
134
96099726
RS
135test_expect_success 'export-subst expands %(describe) once' '
136 echo "\$Format:%(describe)\$" >substfile3 &&
137 echo "\$Format:%(describe)\$" >>substfile3 &&
138 echo "\$Format:%(describe)${LF}%(describe)\$" >substfile4 &&
139 git add substfile[34] &&
140 git commit -m export-subst-describe &&
141 git tag -m export-subst-describe export-subst-describe &&
142 git archive HEAD >archive-describe.tar &&
143 extract_tar_to_dir archive-describe &&
144 desc=$(git describe) &&
145 grep -F "$desc" archive-describe/substfile[34] >substituted &&
146 test_line_count = 1 substituted
147'
148
8aece7ff 149test_done