3 test_description='test for-each-refs usage of ref-filter APIs'
6 . "$TEST_DIRECTORY"/lib-gpg.sh
8 test_prepare_expect () {
9 if test_have_prereq GPG
17 test_expect_success 'setup some history and refs' '
21 git checkout -b side &&
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
27 git tag -s -m "A signed tag" signed-tag &&
28 git tag -s -m "Signed doubly" doubly-signed-tag signed-tag
30 git checkout master &&
31 git update-ref refs/odd/spot master
34 test_expect_success 'filtering with --points-at' '
35 cat >expect <<-\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 &&
47 refs/tags/annotated-tag four
49 refs/tags/signed-tag four
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 &&
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 &&
70 refs/tags/annotated-tag
71 refs/tags/doubly-annotated-tag
72 refs/tags/doubly-signed-tag
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 &&
85 refs/tags/annotated-tag
86 refs/tags/doubly-annotated-tag
87 refs/tags/doubly-signed-tag
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() {
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
179 test_align_permutations <<-\EOF
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
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 &&
225 |'doubly-annotated-tag '|
226 |'doubly-signed-tag '|
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 &&
242 annotated-tag |An annotated tag
243 doubly-annotated-tag |Annonated doubly
244 doubly-signed-tag |Signed doubly
247 signed-tag |A signed tag
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 &&
261 doubly-annotated-tag |
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 &&
278 annotated-tag |An annotated tag
279 doubly-annotated-tag |Annonated doubly
280 doubly-signed-tag |Signed doubly
283 signed-tag |A signed tag
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 &&
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 &&
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 &&
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 &&
328 test_cmp expect actual