]> git.ipfire.org Git - thirdparty/git.git/blob - t/t5001-archive-attr.sh
Sync with Git 2.45.1
[thirdparty/git.git] / t / t5001-archive-attr.sh
1 #!/bin/sh
2
3 test_description='git archive attribute tests'
4
5 TEST_CREATE_REPO_NO_TEMPLATE=1
6 TEST_PASSES_SANITIZE_LEAK=true
7 . ./test-lib.sh
8
9 SUBSTFORMAT='%H (%h)%n'
10
11 test_expect_exists() {
12 test_expect_${2:-success} " $1 exists" "test -e $1"
13 }
14
15 test_expect_missing() {
16 test_expect_${2:-success} " $1 does not exist" "test ! -e $1"
17 }
18
19 extract_tar_to_dir () {
20 (mkdir "$1" && cd "$1" && "$TAR" xf -) <"$1.tar"
21 }
22
23 test_expect_success 'setup' '
24 echo ignored >ignored &&
25 mkdir .git/info &&
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 &&
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 &&
35
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
43 echo ignored by worktree >ignored-by-worktree &&
44 echo ignored-by-worktree export-ignore >.gitattributes &&
45 git add ignored-by-worktree &&
46
47 mkdir excluded-by-pathspec.d &&
48 >excluded-by-pathspec.d/file &&
49 git add excluded-by-pathspec.d &&
50
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
59 git clone --template= --bare . bare &&
60 mkdir bare/info &&
61 cp .git/info/attributes bare/info/attributes
62 '
63
64 test_expect_success 'git archive' '
65 git archive HEAD >archive.tar &&
66 (mkdir archive && cd archive && "$TAR" xf -) <archive.tar
67 '
68
69 test_expect_missing archive/ignored
70 test_expect_missing archive/ignored-by-tree
71 test_expect_missing archive/ignored-by-tree.d
72 test_expect_missing archive/ignored-by-tree.d/file
73 test_expect_exists archive/ignored-by-worktree
74 test_expect_exists archive/excluded-by-pathspec.d
75 test_expect_exists archive/excluded-by-pathspec.d/file
76
77 test_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
82 test_expect_missing archive-pathspec/ignored
83 test_expect_missing archive-pathspec/ignored-by-tree
84 test_expect_missing archive-pathspec/ignored-by-tree.d
85 test_expect_missing archive-pathspec/ignored-by-tree.d/file
86 test_expect_exists archive-pathspec/ignored-by-worktree
87 test_expect_missing archive-pathspec/excluded-by-pathspec.d
88 test_expect_missing archive-pathspec/excluded-by-pathspec.d/file
89
90 test_expect_success 'git archive with wildcard pathspec' '
91 git archive HEAD ":!excluded-by-p*" >archive-pathspec-wildcard.tar &&
92 extract_tar_to_dir archive-pathspec-wildcard
93 '
94
95 test_expect_missing archive-pathspec-wildcard/ignored
96 test_expect_missing archive-pathspec-wildcard/ignored-by-tree
97 test_expect_missing archive-pathspec-wildcard/ignored-by-tree.d
98 test_expect_missing archive-pathspec-wildcard/ignored-by-tree.d/file
99 test_expect_exists archive-pathspec-wildcard/ignored-by-worktree
100 test_expect_missing archive-pathspec-wildcard/excluded-by-pathspec.d
101 test_expect_missing archive-pathspec-wildcard/excluded-by-pathspec.d/file
102
103 test_expect_success 'git -C subdir archive' '
104 git -C subdir archive HEAD >archive-subdir.tar &&
105 extract_tar_to_dir archive-subdir
106 '
107
108 test_expect_exists archive-subdir/included
109 test_expect_missing archive-subdir/ignored-by-subtree
110 test_expect_missing archive-subdir/ignored-by-tree
111
112 test_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
117 test_expect_missing worktree/ignored
118 test_expect_exists worktree/ignored-by-tree
119 test_expect_missing worktree/ignored-by-worktree
120
121 test_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
126 test_expect_missing worktree2/ignored
127 test_expect_exists worktree2/ignored-by-tree
128 test_expect_missing worktree2/ignored-by-worktree
129
130 test_expect_success 'git archive vs. bare' '
131 (cd bare && git archive HEAD) >bare-archive.tar &&
132 test_cmp_bin archive.tar bare-archive.tar
133 '
134
135 test_expect_success 'git archive with worktree attributes, bare' '
136 (cd bare && git archive --worktree-attributes HEAD) >bare-worktree.tar &&
137 (mkdir bare-worktree && cd bare-worktree && "$TAR" xf -) <bare-worktree.tar
138 '
139
140 test_expect_missing bare-worktree/ignored
141 test_expect_missing bare-worktree/ignored-by-tree
142 test_expect_exists bare-worktree/ignored-by-worktree
143
144 test_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
151 test_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
165 test_done