builtin/apply: add 'lock_file' pointer into 'struct apply_state'
[git.git] / t / t6302-for-each-ref-filter.sh
blob70afb44271a38024d89d0e266bafa009961508de
1 #!/bin/sh
3 test_description='test for-each-refs usage of ref-filter APIs'
5 . ./test-lib.sh
6 . "$TEST_DIRECTORY"/lib-gpg.sh
8 test_prepare_expect () {
9 if test_have_prereq GPG
10 then
11 cat
12 else
13 sed '/signed/d'
17 test_expect_success 'setup some history and refs' '
18 test_commit one &&
19 test_commit two &&
20 test_commit three &&
21 git checkout -b side &&
22 test_commit four &&
23 git tag -m "An annotated tag" annotated-tag &&
24 git tag -m "Annonated doubly" doubly-annotated-tag annotated-tag &&
25 if test_have_prereq GPG
26 then
27 git tag -s -m "A signed tag" signed-tag &&
28 git tag -s -m "Signed doubly" doubly-signed-tag signed-tag
29 fi &&
30 git checkout master &&
31 git update-ref refs/odd/spot master
34 test_expect_success 'filtering with --points-at' '
35 cat >expect <<-\EOF &&
36 refs/heads/master
37 refs/odd/spot
38 refs/tags/three
39 EOF
40 git for-each-ref --format="%(refname)" --points-at=master >actual &&
41 test_cmp expect actual
44 test_expect_success 'check signed tags with --points-at' '
45 test_prepare_expect <<-\EOF | sed -e "s/Z$//" >expect &&
46 refs/heads/side Z
47 refs/tags/annotated-tag four
48 refs/tags/four Z
49 refs/tags/signed-tag four
50 EOF
51 git for-each-ref --format="%(refname) %(*subject)" --points-at=side >actual &&
52 test_cmp expect actual
55 test_expect_success 'filtering with --merged' '
56 cat >expect <<-\EOF &&
57 refs/heads/master
58 refs/odd/spot
59 refs/tags/one
60 refs/tags/three
61 refs/tags/two
62 EOF
63 git for-each-ref --format="%(refname)" --merged=master >actual &&
64 test_cmp expect actual
67 test_expect_success 'filtering with --no-merged' '
68 test_prepare_expect >expect <<-\EOF &&
69 refs/heads/side
70 refs/tags/annotated-tag
71 refs/tags/doubly-annotated-tag
72 refs/tags/doubly-signed-tag
73 refs/tags/four
74 refs/tags/signed-tag
75 EOF
76 git for-each-ref --format="%(refname)" --no-merged=master >actual &&
77 test_cmp expect actual
80 test_expect_success 'filtering with --contains' '
81 test_prepare_expect >expect <<-\EOF &&
82 refs/heads/master
83 refs/heads/side
84 refs/odd/spot
85 refs/tags/annotated-tag
86 refs/tags/doubly-annotated-tag
87 refs/tags/doubly-signed-tag
88 refs/tags/four
89 refs/tags/signed-tag
90 refs/tags/three
91 refs/tags/two
92 EOF
93 git for-each-ref --format="%(refname)" --contains=two >actual &&
94 test_cmp expect actual
97 test_expect_success '%(color) must fail' '
98 test_must_fail git for-each-ref --format="%(color)%(refname)"
101 test_expect_success 'left alignment is default' '
102 test_prepare_expect >expect <<-\EOF &&
103 refname is refs/heads/master |refs/heads/master
104 refname is refs/heads/side |refs/heads/side
105 refname is refs/odd/spot |refs/odd/spot
106 refname is refs/tags/annotated-tag|refs/tags/annotated-tag
107 refname is refs/tags/doubly-annotated-tag|refs/tags/doubly-annotated-tag
108 refname is refs/tags/doubly-signed-tag|refs/tags/doubly-signed-tag
109 refname is refs/tags/four |refs/tags/four
110 refname is refs/tags/one |refs/tags/one
111 refname is refs/tags/signed-tag|refs/tags/signed-tag
112 refname is refs/tags/three |refs/tags/three
113 refname is refs/tags/two |refs/tags/two
115 git for-each-ref --format="%(align:30)refname is %(refname)%(end)|%(refname)" >actual &&
116 test_cmp expect actual
119 test_expect_success 'middle alignment' '
120 test_prepare_expect >expect <<-\EOF &&
121 | refname is refs/heads/master |refs/heads/master
122 | refname is refs/heads/side |refs/heads/side
123 | refname is refs/odd/spot |refs/odd/spot
124 |refname is refs/tags/annotated-tag|refs/tags/annotated-tag
125 |refname is refs/tags/doubly-annotated-tag|refs/tags/doubly-annotated-tag
126 |refname is refs/tags/doubly-signed-tag|refs/tags/doubly-signed-tag
127 | refname is refs/tags/four |refs/tags/four
128 | refname is refs/tags/one |refs/tags/one
129 |refname is refs/tags/signed-tag|refs/tags/signed-tag
130 | refname is refs/tags/three |refs/tags/three
131 | refname is refs/tags/two |refs/tags/two
133 git for-each-ref --format="|%(align:middle,30)refname is %(refname)%(end)|%(refname)" >actual &&
134 test_cmp expect actual
137 test_expect_success 'right alignment' '
138 test_prepare_expect >expect <<-\EOF &&
139 | refname is refs/heads/master|refs/heads/master
140 | refname is refs/heads/side|refs/heads/side
141 | refname is refs/odd/spot|refs/odd/spot
142 |refname is refs/tags/annotated-tag|refs/tags/annotated-tag
143 |refname is refs/tags/doubly-annotated-tag|refs/tags/doubly-annotated-tag
144 |refname is refs/tags/doubly-signed-tag|refs/tags/doubly-signed-tag
145 | refname is refs/tags/four|refs/tags/four
146 | refname is refs/tags/one|refs/tags/one
147 |refname is refs/tags/signed-tag|refs/tags/signed-tag
148 | refname is refs/tags/three|refs/tags/three
149 | refname is refs/tags/two|refs/tags/two
151 git for-each-ref --format="|%(align:30,right)refname is %(refname)%(end)|%(refname)" >actual &&
152 test_cmp expect actual
155 test_prepare_expect >expect <<-\EOF
156 | refname is refs/heads/master |refs/heads/master
157 | refname is refs/heads/side |refs/heads/side
158 | refname is refs/odd/spot |refs/odd/spot
159 | refname is refs/tags/annotated-tag |refs/tags/annotated-tag
160 |refname is refs/tags/doubly-annotated-tag |refs/tags/doubly-annotated-tag
161 | refname is refs/tags/doubly-signed-tag |refs/tags/doubly-signed-tag
162 | refname is refs/tags/four |refs/tags/four
163 | refname is refs/tags/one |refs/tags/one
164 | refname is refs/tags/signed-tag |refs/tags/signed-tag
165 | refname is refs/tags/three |refs/tags/three
166 | refname is refs/tags/two |refs/tags/two
169 test_align_permutations() {
170 while read -r option
172 test_expect_success "align:$option" '
173 git for-each-ref --format="|%(align:$option)refname is %(refname)%(end)|%(refname)" >actual &&
174 test_cmp expect actual
176 done
179 test_align_permutations <<-\EOF
180 middle,42
181 42,middle
182 position=middle,42
183 42,position=middle
184 middle,width=42
185 width=42,middle
186 position=middle,width=42
187 width=42,position=middle
190 # Last one wins (silently) when multiple arguments of the same type are given
192 test_align_permutations <<-\EOF
193 32,width=42,middle
194 width=30,42,middle
195 width=42,position=right,middle
196 42,right,position=middle
199 # Individual atoms inside %(align:...) and %(end) must not be quoted.
201 test_expect_success 'alignment with format quote' "
202 test_prepare_expect >expect <<-\EOF &&
203 |' '\''master| A U Thor'\'' '|
204 |' '\''side| A U Thor'\'' '|
205 |' '\''odd/spot| A U Thor'\'' '|
206 |' '\''annotated-tag| '\'' '|
207 |' '\''doubly-annotated-tag| '\'' '|
208 |' '\''doubly-signed-tag| '\'' '|
209 |' '\''four| A U Thor'\'' '|
210 |' '\''one| A U Thor'\'' '|
211 |' '\''signed-tag| '\'' '|
212 |' '\''three| A U Thor'\'' '|
213 |' '\''two| A U Thor'\'' '|
215 git for-each-ref --shell --format=\"|%(align:30,middle)'%(refname:short)| %(authorname)'%(end)|\" >actual &&
216 test_cmp expect actual
219 test_expect_success 'nested alignment with quote formatting' "
220 test_prepare_expect >expect <<-\EOF &&
221 |' master '|
222 |' side '|
223 |' odd/spot '|
224 |' annotated-tag '|
225 |'doubly-annotated-tag '|
226 |'doubly-signed-tag '|
227 |' four '|
228 |' one '|
229 |' signed-tag '|
230 |' three '|
231 |' two '|
233 git for-each-ref --shell --format='|%(align:30,left)%(align:15,right)%(refname:short)%(end)%(end)|' >actual &&
234 test_cmp expect actual
237 test_expect_success 'check `%(contents:lines=1)`' '
238 test_prepare_expect >expect <<-\EOF &&
239 master |three
240 side |four
241 odd/spot |three
242 annotated-tag |An annotated tag
243 doubly-annotated-tag |Annonated doubly
244 doubly-signed-tag |Signed doubly
245 four |four
246 one |one
247 signed-tag |A signed tag
248 three |three
249 two |two
251 git for-each-ref --format="%(refname:short) |%(contents:lines=1)" >actual &&
252 test_cmp expect actual
255 test_expect_success 'check `%(contents:lines=0)`' '
256 test_prepare_expect >expect <<-\EOF &&
257 master |
258 side |
259 odd/spot |
260 annotated-tag |
261 doubly-annotated-tag |
262 doubly-signed-tag |
263 four |
264 one |
265 signed-tag |
266 three |
267 two |
269 git for-each-ref --format="%(refname:short) |%(contents:lines=0)" >actual &&
270 test_cmp expect actual
273 test_expect_success 'check `%(contents:lines=99999)`' '
274 test_prepare_expect >expect <<-\EOF &&
275 master |three
276 side |four
277 odd/spot |three
278 annotated-tag |An annotated tag
279 doubly-annotated-tag |Annonated doubly
280 doubly-signed-tag |Signed doubly
281 four |four
282 one |one
283 signed-tag |A signed tag
284 three |three
285 two |two
287 git for-each-ref --format="%(refname:short) |%(contents:lines=99999)" >actual &&
288 test_cmp expect actual
291 test_expect_success '`%(contents:lines=-1)` should fail' '
292 test_must_fail git for-each-ref --format="%(refname:short) |%(contents:lines=-1)"
295 test_expect_success 'setup for version sort' '
296 test_commit foo1.3 &&
297 test_commit foo1.6 &&
298 test_commit foo1.10
301 test_expect_success 'version sort' '
302 git for-each-ref --sort=version:refname --format="%(refname:short)" refs/tags/ | grep "foo" >actual &&
303 cat >expect <<-\EOF &&
304 foo1.3
305 foo1.6
306 foo1.10
308 test_cmp expect actual
311 test_expect_success 'version sort (shortened)' '
312 git for-each-ref --sort=v:refname --format="%(refname:short)" refs/tags/ | grep "foo" >actual &&
313 cat >expect <<-\EOF &&
314 foo1.3
315 foo1.6
316 foo1.10
318 test_cmp expect actual
321 test_expect_success 'reverse version sort' '
322 git for-each-ref --sort=-version:refname --format="%(refname:short)" refs/tags/ | grep "foo" >actual &&
323 cat >expect <<-\EOF &&
324 foo1.10
325 foo1.6
326 foo1.3
328 test_cmp expect actual
331 test_done