3 test_description
='git archive attribute tests'
5 TEST_CREATE_REPO_NO_TEMPLATE
=1
6 TEST_PASSES_SANITIZE_LEAK
=true
9 SUBSTFORMAT
='%H (%h)%n'
11 test_expect_exists
() {
12 test_expect_
${2:-success} " $1 exists" "test -e $1"
15 test_expect_missing
() {
16 test_expect_
${2:-success} " $1 does not exist" "test ! -e $1"
19 extract_tar_to_dir
() {
20 (mkdir
"$1" && cd "$1" && "$TAR" xf
-) <"$1.tar"
23 test_expect_success
'setup' '
24 echo ignored >ignored &&
26 echo ignored export-ignore >>.git/info/attributes &&
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 &&
38 >subdir/ignored-by-subtree &&
39 >subdir/ignored-by-tree &&
40 echo ignored-by-subtree export-ignore >subdir/.gitattributes &&
43 echo ignored by worktree >ignored-by-worktree &&
44 echo ignored-by-worktree export-ignore >.gitattributes &&
45 git add ignored-by-worktree &&
47 mkdir excluded-by-pathspec.d &&
48 >excluded-by-pathspec.d/file &&
49 git add excluded-by-pathspec.d &&
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 &&
59 git clone --template= --bare . bare &&
61 cp .git/info/attributes bare/info/attributes
64 test_expect_success
'git archive' '
65 git archive HEAD >archive.tar &&
66 (mkdir archive && cd archive && "$TAR" xf -) <archive.tar
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
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
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
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
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
103 test_expect_success
'git -C subdir archive' '
104 git -C subdir archive HEAD >archive-subdir.tar &&
105 extract_tar_to_dir archive-subdir
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
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
117 test_expect_missing worktree
/ignored
118 test_expect_exists worktree
/ignored-by-tree
119 test_expect_missing worktree
/ignored-by-worktree
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
126 test_expect_missing worktree
2/ignored
127 test_expect_exists worktree
2/ignored-by-tree
128 test_expect_missing worktree
2/ignored-by-worktree
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
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
140 test_expect_missing bare-worktree
/ignored
141 test_expect_exists bare-worktree
/ignored-by-tree
142 test_expect_exists bare-worktree
/ignored-by-worktree
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
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