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