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