]> git.ipfire.org Git - thirdparty/git.git/blob - t/t5001-archive-attr.sh
Merge branch 'jk/clone-allow-bare-and-o-together'
[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-lib.sh
7
8 SUBSTFORMAT='%H (%h)%n'
9
10 test_expect_exists() {
11 test_expect_${2:-success} " $1 exists" "test -e $1"
12 }
13
14 test_expect_missing() {
15 test_expect_${2:-success} " $1 does not exist" "test ! -e $1"
16 }
17
18 extract_tar_to_dir () {
19 (mkdir "$1" && cd "$1" && "$TAR" xf -) <"$1.tar"
20 }
21
22 test_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 echo ignored by worktree >ignored-by-worktree &&
36 echo ignored-by-worktree export-ignore >.gitattributes &&
37 git add ignored-by-worktree &&
38
39 mkdir excluded-by-pathspec.d &&
40 >excluded-by-pathspec.d/file &&
41 git add excluded-by-pathspec.d &&
42
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
51 git clone --template= --bare . bare &&
52 mkdir bare/info &&
53 cp .git/info/attributes bare/info/attributes
54 '
55
56 test_expect_success 'git archive' '
57 git archive HEAD >archive.tar &&
58 (mkdir archive && cd archive && "$TAR" xf -) <archive.tar
59 '
60
61 test_expect_missing archive/ignored
62 test_expect_missing archive/ignored-by-tree
63 test_expect_missing archive/ignored-by-tree.d
64 test_expect_missing archive/ignored-by-tree.d/file
65 test_expect_exists archive/ignored-by-worktree
66 test_expect_exists archive/excluded-by-pathspec.d
67 test_expect_exists archive/excluded-by-pathspec.d/file
68
69 test_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
74 test_expect_missing archive-pathspec/ignored
75 test_expect_missing archive-pathspec/ignored-by-tree
76 test_expect_missing archive-pathspec/ignored-by-tree.d
77 test_expect_missing archive-pathspec/ignored-by-tree.d/file
78 test_expect_exists archive-pathspec/ignored-by-worktree
79 test_expect_missing archive-pathspec/excluded-by-pathspec.d
80 test_expect_missing archive-pathspec/excluded-by-pathspec.d/file
81
82 test_expect_success 'git archive with wildcard pathspec' '
83 git archive HEAD ":!excluded-by-p*" >archive-pathspec-wildcard.tar &&
84 extract_tar_to_dir archive-pathspec-wildcard
85 '
86
87 test_expect_missing archive-pathspec-wildcard/ignored
88 test_expect_missing archive-pathspec-wildcard/ignored-by-tree
89 test_expect_missing archive-pathspec-wildcard/ignored-by-tree.d
90 test_expect_missing archive-pathspec-wildcard/ignored-by-tree.d/file
91 test_expect_exists archive-pathspec-wildcard/ignored-by-worktree
92 test_expect_missing archive-pathspec-wildcard/excluded-by-pathspec.d
93 test_expect_missing archive-pathspec-wildcard/excluded-by-pathspec.d/file
94
95 test_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
100 test_expect_missing worktree/ignored
101 test_expect_exists worktree/ignored-by-tree
102 test_expect_missing worktree/ignored-by-worktree
103
104 test_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
109 test_expect_missing worktree2/ignored
110 test_expect_exists worktree2/ignored-by-tree
111 test_expect_missing worktree2/ignored-by-worktree
112
113 test_expect_success 'git archive vs. bare' '
114 (cd bare && git archive HEAD) >bare-archive.tar &&
115 test_cmp_bin archive.tar bare-archive.tar
116 '
117
118 test_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
123 test_expect_missing bare-worktree/ignored
124 test_expect_exists bare-worktree/ignored-by-tree
125 test_expect_exists bare-worktree/ignored-by-worktree
126
127 test_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
134 test_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
148 test_done