run-command.c: use error_errno()
[git/git-svn.git] / t / t6302-for-each-ref-filter.sh
blobbcf472bf51999f3fd1a043b5d44601156d5c8049
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 if ! test_have_prereq GPG
9 then
10 skip_all="skipping for-each-ref tests, GPG not available"
11 test_done
14 test_expect_success 'setup some history and refs' '
15 test_commit one &&
16 test_commit two &&
17 test_commit three &&
18 git checkout -b side &&
19 test_commit four &&
20 git tag -s -m "A signed tag message" signed-tag &&
21 git tag -s -m "Annonated doubly" double-tag signed-tag &&
22 git checkout master &&
23 git update-ref refs/odd/spot master
26 test_expect_success 'filtering with --points-at' '
27 cat >expect <<-\EOF &&
28 refs/heads/master
29 refs/odd/spot
30 refs/tags/three
31 EOF
32 git for-each-ref --format="%(refname)" --points-at=master >actual &&
33 test_cmp expect actual
36 test_expect_success 'check signed tags with --points-at' '
37 sed -e "s/Z$//" >expect <<-\EOF &&
38 refs/heads/side Z
39 refs/tags/four Z
40 refs/tags/signed-tag four
41 EOF
42 git for-each-ref --format="%(refname) %(*subject)" --points-at=side >actual &&
43 test_cmp expect actual
46 test_expect_success 'filtering with --merged' '
47 cat >expect <<-\EOF &&
48 refs/heads/master
49 refs/odd/spot
50 refs/tags/one
51 refs/tags/three
52 refs/tags/two
53 EOF
54 git for-each-ref --format="%(refname)" --merged=master >actual &&
55 test_cmp expect actual
58 test_expect_success 'filtering with --no-merged' '
59 cat >expect <<-\EOF &&
60 refs/heads/side
61 refs/tags/double-tag
62 refs/tags/four
63 refs/tags/signed-tag
64 EOF
65 git for-each-ref --format="%(refname)" --no-merged=master >actual &&
66 test_cmp expect actual
69 test_expect_success 'filtering with --contains' '
70 cat >expect <<-\EOF &&
71 refs/heads/master
72 refs/heads/side
73 refs/odd/spot
74 refs/tags/double-tag
75 refs/tags/four
76 refs/tags/signed-tag
77 refs/tags/three
78 refs/tags/two
79 EOF
80 git for-each-ref --format="%(refname)" --contains=two >actual &&
81 test_cmp expect actual
84 test_expect_success '%(color) must fail' '
85 test_must_fail git for-each-ref --format="%(color)%(refname)"
88 test_expect_success 'left alignment is default' '
89 cat >expect <<-\EOF &&
90 refname is refs/heads/master |refs/heads/master
91 refname is refs/heads/side |refs/heads/side
92 refname is refs/odd/spot |refs/odd/spot
93 refname is refs/tags/double-tag|refs/tags/double-tag
94 refname is refs/tags/four |refs/tags/four
95 refname is refs/tags/one |refs/tags/one
96 refname is refs/tags/signed-tag|refs/tags/signed-tag
97 refname is refs/tags/three |refs/tags/three
98 refname is refs/tags/two |refs/tags/two
99 EOF
100 git for-each-ref --format="%(align:30)refname is %(refname)%(end)|%(refname)" >actual &&
101 test_cmp expect actual
104 test_expect_success 'middle alignment' '
105 cat >expect <<-\EOF &&
106 | refname is refs/heads/master |refs/heads/master
107 | refname is refs/heads/side |refs/heads/side
108 | refname is refs/odd/spot |refs/odd/spot
109 |refname is refs/tags/double-tag|refs/tags/double-tag
110 | refname is refs/tags/four |refs/tags/four
111 | refname is refs/tags/one |refs/tags/one
112 |refname is refs/tags/signed-tag|refs/tags/signed-tag
113 | refname is refs/tags/three |refs/tags/three
114 | refname is refs/tags/two |refs/tags/two
116 git for-each-ref --format="|%(align:middle,30)refname is %(refname)%(end)|%(refname)" >actual &&
117 test_cmp expect actual
120 test_expect_success 'right alignment' '
121 cat >expect <<-\EOF &&
122 | refname is refs/heads/master|refs/heads/master
123 | refname is refs/heads/side|refs/heads/side
124 | refname is refs/odd/spot|refs/odd/spot
125 |refname is refs/tags/double-tag|refs/tags/double-tag
126 | refname is refs/tags/four|refs/tags/four
127 | refname is refs/tags/one|refs/tags/one
128 |refname is refs/tags/signed-tag|refs/tags/signed-tag
129 | refname is refs/tags/three|refs/tags/three
130 | refname is refs/tags/two|refs/tags/two
132 git for-each-ref --format="|%(align:30,right)refname is %(refname)%(end)|%(refname)" >actual &&
133 test_cmp expect actual
136 cat >expect <<-\EOF
137 | refname is refs/heads/master |refs/heads/master
138 | refname is refs/heads/side |refs/heads/side
139 | refname is refs/odd/spot |refs/odd/spot
140 | refname is refs/tags/double-tag |refs/tags/double-tag
141 | refname is refs/tags/four |refs/tags/four
142 | refname is refs/tags/one |refs/tags/one
143 | refname is refs/tags/signed-tag |refs/tags/signed-tag
144 | refname is refs/tags/three |refs/tags/three
145 | refname is refs/tags/two |refs/tags/two
148 test_align_permutations() {
149 while read -r option
151 test_expect_success "align:$option" '
152 git for-each-ref --format="|%(align:$option)refname is %(refname)%(end)|%(refname)" >actual &&
153 test_cmp expect actual
155 done
158 test_align_permutations <<-\EOF
159 middle,42
160 42,middle
161 position=middle,42
162 42,position=middle
163 middle,width=42
164 width=42,middle
165 position=middle,width=42
166 width=42,position=middle
169 # Last one wins (silently) when multiple arguments of the same type are given
171 test_align_permutations <<-\EOF
172 32,width=42,middle
173 width=30,42,middle
174 width=42,position=right,middle
175 42,right,position=middle
178 # Individual atoms inside %(align:...) and %(end) must not be quoted.
180 test_expect_success 'alignment with format quote' "
181 cat >expect <<-\EOF &&
182 |' '\''master| A U Thor'\'' '|
183 |' '\''side| A U Thor'\'' '|
184 |' '\''odd/spot| A U Thor'\'' '|
185 |' '\''double-tag| '\'' '|
186 |' '\''four| A U Thor'\'' '|
187 |' '\''one| A U Thor'\'' '|
188 |' '\''signed-tag| '\'' '|
189 |' '\''three| A U Thor'\'' '|
190 |' '\''two| A U Thor'\'' '|
192 git for-each-ref --shell --format=\"|%(align:30,middle)'%(refname:short)| %(authorname)'%(end)|\" >actual &&
193 test_cmp expect actual
196 test_expect_success 'nested alignment with quote formatting' "
197 cat >expect <<-\EOF &&
198 |' master '|
199 |' side '|
200 |' odd/spot '|
201 |' double-tag '|
202 |' four '|
203 |' one '|
204 |' signed-tag '|
205 |' three '|
206 |' two '|
208 git for-each-ref --shell --format='|%(align:30,left)%(align:15,right)%(refname:short)%(end)%(end)|' >actual &&
209 test_cmp expect actual
212 test_expect_success 'check `%(contents:lines=1)`' '
213 cat >expect <<-\EOF &&
214 master |three
215 side |four
216 odd/spot |three
217 double-tag |Annonated doubly
218 four |four
219 one |one
220 signed-tag |A signed tag message
221 three |three
222 two |two
224 git for-each-ref --format="%(refname:short) |%(contents:lines=1)" >actual &&
225 test_cmp expect actual
228 test_expect_success 'check `%(contents:lines=0)`' '
229 cat >expect <<-\EOF &&
230 master |
231 side |
232 odd/spot |
233 double-tag |
234 four |
235 one |
236 signed-tag |
237 three |
238 two |
240 git for-each-ref --format="%(refname:short) |%(contents:lines=0)" >actual &&
241 test_cmp expect actual
244 test_expect_success 'check `%(contents:lines=99999)`' '
245 cat >expect <<-\EOF &&
246 master |three
247 side |four
248 odd/spot |three
249 double-tag |Annonated doubly
250 four |four
251 one |one
252 signed-tag |A signed tag message
253 three |three
254 two |two
256 git for-each-ref --format="%(refname:short) |%(contents:lines=99999)" >actual &&
257 test_cmp expect actual
260 test_expect_success '`%(contents:lines=-1)` should fail' '
261 test_must_fail git for-each-ref --format="%(refname:short) |%(contents:lines=-1)"
264 test_expect_success 'setup for version sort' '
265 test_commit foo1.3 &&
266 test_commit foo1.6 &&
267 test_commit foo1.10
270 test_expect_success 'version sort' '
271 git for-each-ref --sort=version:refname --format="%(refname:short)" refs/tags/ | grep "foo" >actual &&
272 cat >expect <<-\EOF &&
273 foo1.3
274 foo1.6
275 foo1.10
277 test_cmp expect actual
280 test_expect_success 'version sort (shortened)' '
281 git for-each-ref --sort=v:refname --format="%(refname:short)" refs/tags/ | grep "foo" >actual &&
282 cat >expect <<-\EOF &&
283 foo1.3
284 foo1.6
285 foo1.10
287 test_cmp expect actual
290 test_expect_success 'reverse version sort' '
291 git for-each-ref --sort=-version:refname --format="%(refname:short)" refs/tags/ | grep "foo" >actual &&
292 cat >expect <<-\EOF &&
293 foo1.10
294 foo1.6
295 foo1.3
297 test_cmp expect actual
300 test_done