3 test_description='test for-each-refs usage of ref-filter APIs'
6 . "$TEST_DIRECTORY"/lib-gpg.sh
8 test_expect_success 'setup some history and refs' '
12 git checkout -b side &&
14 git tag -m "An annotated tag" annotated-tag &&
15 git tag -m "Annonated doubly" doubly-annotated-tag annotated-tag &&
17 # Note that these "signed" tags might not actually be signed.
18 # Tests which care about the distinction should be marked
19 # with the GPG prereq.
20 if test_have_prereq GPG
26 git tag $sign -m "A signed tag" signed-tag &&
27 git tag $sign -m "Signed doubly" doubly-signed-tag signed-tag &&
29 git checkout master &&
30 git update-ref refs/odd/spot master
33 test_expect_success 'filtering with --points-at' '
34 cat >expect <<-\EOF &&
39 git for-each-ref --format="%(refname)" --points-at=master >actual &&
40 test_cmp expect actual
43 test_expect_success 'check signed tags with --points-at' '
44 sed -e "s/Z$//" >expect <<-\EOF &&
46 refs/tags/annotated-tag four
48 refs/tags/signed-tag four
50 git for-each-ref --format="%(refname) %(*subject)" --points-at=side >actual &&
51 test_cmp expect actual
54 test_expect_success 'filtering with --merged' '
55 cat >expect <<-\EOF &&
62 git for-each-ref --format="%(refname)" --merged=master >actual &&
63 test_cmp expect actual
66 test_expect_success 'filtering with --no-merged' '
67 cat >expect <<-\EOF &&
69 refs/tags/annotated-tag
70 refs/tags/doubly-annotated-tag
71 refs/tags/doubly-signed-tag
75 git for-each-ref --format="%(refname)" --no-merged=master >actual &&
76 test_cmp expect actual
79 test_expect_success 'filtering with --contains' '
80 cat >expect <<-\EOF &&
84 refs/tags/annotated-tag
85 refs/tags/doubly-annotated-tag
86 refs/tags/doubly-signed-tag
92 git for-each-ref --format="%(refname)" --contains=two >actual &&
93 test_cmp expect actual
96 test_expect_success '%(color) must fail' '
97 test_must_fail git for-each-ref --format="%(color)%(refname)"
100 test_expect_success 'left alignment is default' '
101 cat >expect <<-\EOF &&
102 refname is refs/heads/master |refs/heads/master
103 refname is refs/heads/side |refs/heads/side
104 refname is refs/odd/spot |refs/odd/spot
105 refname is refs/tags/annotated-tag|refs/tags/annotated-tag
106 refname is refs/tags/doubly-annotated-tag|refs/tags/doubly-annotated-tag
107 refname is refs/tags/doubly-signed-tag|refs/tags/doubly-signed-tag
108 refname is refs/tags/four |refs/tags/four
109 refname is refs/tags/one |refs/tags/one
110 refname is refs/tags/signed-tag|refs/tags/signed-tag
111 refname is refs/tags/three |refs/tags/three
112 refname is refs/tags/two |refs/tags/two
114 git for-each-ref --format="%(align:30)refname is %(refname)%(end)|%(refname)" >actual &&
115 test_cmp expect actual
118 test_expect_success 'middle alignment' '
119 cat >expect <<-\EOF &&
120 | refname is refs/heads/master |refs/heads/master
121 | refname is refs/heads/side |refs/heads/side
122 | refname is refs/odd/spot |refs/odd/spot
123 |refname is refs/tags/annotated-tag|refs/tags/annotated-tag
124 |refname is refs/tags/doubly-annotated-tag|refs/tags/doubly-annotated-tag
125 |refname is refs/tags/doubly-signed-tag|refs/tags/doubly-signed-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:middle,30)refname is %(refname)%(end)|%(refname)" >actual &&
133 test_cmp expect actual
136 test_expect_success 'right alignment' '
137 cat >expect <<-\EOF &&
138 | refname is refs/heads/master|refs/heads/master
139 | refname is refs/heads/side|refs/heads/side
140 | refname is refs/odd/spot|refs/odd/spot
141 |refname is refs/tags/annotated-tag|refs/tags/annotated-tag
142 |refname is refs/tags/doubly-annotated-tag|refs/tags/doubly-annotated-tag
143 |refname is refs/tags/doubly-signed-tag|refs/tags/doubly-signed-tag
144 | refname is refs/tags/four|refs/tags/four
145 | refname is refs/tags/one|refs/tags/one
146 |refname is refs/tags/signed-tag|refs/tags/signed-tag
147 | refname is refs/tags/three|refs/tags/three
148 | refname is refs/tags/two|refs/tags/two
150 git for-each-ref --format="|%(align:30,right)refname is %(refname)%(end)|%(refname)" >actual &&
151 test_cmp expect actual
155 | refname is refs/heads/master |refs/heads/master
156 | refname is refs/heads/side |refs/heads/side
157 | refname is refs/odd/spot |refs/odd/spot
158 | refname is refs/tags/annotated-tag |refs/tags/annotated-tag
159 |refname is refs/tags/doubly-annotated-tag |refs/tags/doubly-annotated-tag
160 | refname is refs/tags/doubly-signed-tag |refs/tags/doubly-signed-tag
161 | refname is refs/tags/four |refs/tags/four
162 | refname is refs/tags/one |refs/tags/one
163 | refname is refs/tags/signed-tag |refs/tags/signed-tag
164 | refname is refs/tags/three |refs/tags/three
165 | refname is refs/tags/two |refs/tags/two
168 test_align_permutations() {
171 test_expect_success "align:$option" '
172 git for-each-ref --format="|%(align:$option)refname is %(refname)%(end)|%(refname)" >actual &&
173 test_cmp expect actual
178 test_align_permutations <<-\EOF
185 position=middle,width=42
186 width=42,position=middle
189 # Last one wins (silently) when multiple arguments of the same type are given
191 test_align_permutations <<-\EOF
194 width=42,position=right,middle
195 42,right,position=middle
198 # Individual atoms inside %(align:...) and %(end) must not be quoted.
200 test_expect_success 'alignment with format quote' "
201 cat >expect <<-\EOF &&
202 |' '\''master| A U Thor'\'' '|
203 |' '\''side| A U Thor'\'' '|
204 |' '\''odd/spot| A U Thor'\'' '|
205 |' '\''annotated-tag| '\'' '|
206 |' '\''doubly-annotated-tag| '\'' '|
207 |' '\''doubly-signed-tag| '\'' '|
208 |' '\''four| A U Thor'\'' '|
209 |' '\''one| A U Thor'\'' '|
210 |' '\''signed-tag| '\'' '|
211 |' '\''three| A U Thor'\'' '|
212 |' '\''two| A U Thor'\'' '|
214 git for-each-ref --shell --format=\"|%(align:30,middle)'%(refname:short)| %(authorname)'%(end)|\" >actual &&
215 test_cmp expect actual
218 test_expect_success 'nested alignment with quote formatting' "
219 cat >expect <<-\EOF &&
224 |'doubly-annotated-tag '|
225 |'doubly-signed-tag '|
232 git for-each-ref --shell --format='|%(align:30,left)%(align:15,right)%(refname:short)%(end)%(end)|' >actual &&
233 test_cmp expect actual
236 test_expect_success 'check `%(contents:lines=1)`' '
237 cat >expect <<-\EOF &&
241 annotated-tag |An annotated tag
242 doubly-annotated-tag |Annonated doubly
243 doubly-signed-tag |Signed doubly
246 signed-tag |A signed tag
250 git for-each-ref --format="%(refname:short) |%(contents:lines=1)" >actual &&
251 test_cmp expect actual
254 test_expect_success 'check `%(contents:lines=0)`' '
255 cat >expect <<-\EOF &&
260 doubly-annotated-tag |
268 git for-each-ref --format="%(refname:short) |%(contents:lines=0)" >actual &&
269 test_cmp expect actual
272 test_expect_success 'check `%(contents:lines=99999)`' '
273 cat >expect <<-\EOF &&
277 annotated-tag |An annotated tag
278 doubly-annotated-tag |Annonated doubly
279 doubly-signed-tag |Signed doubly
282 signed-tag |A signed tag
286 git for-each-ref --format="%(refname:short) |%(contents:lines=99999)" >actual &&
287 test_cmp expect actual
290 test_expect_success '`%(contents:lines=-1)` should fail' '
291 test_must_fail git for-each-ref --format="%(refname:short) |%(contents:lines=-1)"
294 test_expect_success 'setup for version sort' '
295 test_commit foo1.3 &&
296 test_commit foo1.6 &&
300 test_expect_success 'version sort' '
301 git for-each-ref --sort=version:refname --format="%(refname:short)" refs/tags/ | grep "foo" >actual &&
302 cat >expect <<-\EOF &&
307 test_cmp expect actual
310 test_expect_success 'version sort (shortened)' '
311 git for-each-ref --sort=v:refname --format="%(refname:short)" refs/tags/ | grep "foo" >actual &&
312 cat >expect <<-\EOF &&
317 test_cmp expect actual
320 test_expect_success 'reverse version sort' '
321 git for-each-ref --sort=-version:refname --format="%(refname:short)" refs/tags/ | grep "foo" >actual &&
322 cat >expect <<-\EOF &&
327 test_cmp expect actual