3 test_description='test for-each-refs usage of ref-filter APIs'
6 . "$TEST_DIRECTORY"/lib-gpg.sh
8 if ! test_have_prereq GPG
10 skip_all="skipping for-each-ref tests, GPG not available"
14 test_expect_success 'setup some history and refs' '
18 git checkout -b side &&
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 &&
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 &&
40 refs/tags/signed-tag four
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 &&
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 &&
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 &&
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
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
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() {
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
158 test_align_permutations <<-\EOF
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
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 &&
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 &&
217 double-tag |Annonated doubly
220 signed-tag |A signed tag message
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 &&
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 &&
249 double-tag |Annonated doubly
252 signed-tag |A signed tag message
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 &&
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 &&
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 &&
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 &&
297 test_cmp expect actual