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
136 # Individual atoms inside %(align:...) and %(end) must not be quoted.
138 test_expect_success
'alignment with format quote' "
139 cat >expect <<-\EOF &&
140 |' '\''master| A U Thor'\'' '|
141 |' '\''side| A U Thor'\'' '|
142 |' '\''odd/spot| A U Thor'\'' '|
143 |' '\''double-tag| '\'' '|
144 |' '\''four| A U Thor'\'' '|
145 |' '\''one| A U Thor'\'' '|
146 |' '\''signed-tag| '\'' '|
147 |' '\''three| A U Thor'\'' '|
148 |' '\''two| A U Thor'\'' '|
150 git for-each-ref --shell --format=\"|%(align:30,middle)'%(refname:short)| %(authorname)'%(end)|\" >actual &&
151 test_cmp expect actual
154 test_expect_success
'nested alignment with quote formatting' "
155 cat >expect <<-\EOF &&
166 git for-each-ref --shell --format='|%(align:30,left)%(align:15,right)%(refname:short)%(end)%(end)|' >actual &&
167 test_cmp expect actual
170 test_expect_success
'check `%(contents:lines=1)`' '
171 cat >expect <<-\EOF &&
175 double-tag |Annonated doubly
178 signed-tag |A signed tag message
182 git for-each-ref --format="%(refname:short) |%(contents:lines=1)" >actual &&
183 test_cmp expect actual
186 test_expect_success
'check `%(contents:lines=0)`' '
187 cat >expect <<-\EOF &&
198 git for-each-ref --format="%(refname:short) |%(contents:lines=0)" >actual &&
199 test_cmp expect actual
202 test_expect_success
'check `%(contents:lines=99999)`' '
203 cat >expect <<-\EOF &&
207 double-tag |Annonated doubly
210 signed-tag |A signed tag message
214 git for-each-ref --format="%(refname:short) |%(contents:lines=99999)" >actual &&
215 test_cmp expect actual
218 test_expect_success
'`%(contents:lines=-1)` should fail' '
219 test_must_fail git for-each-ref --format="%(refname:short) |%(contents:lines=-1)"
222 test_expect_success
'setup for version sort' '
223 test_commit foo1.3 &&
224 test_commit foo1.6 &&
228 test_expect_success
'version sort' '
229 git for-each-ref --sort=version:refname --format="%(refname:short)" refs/tags/ | grep "foo" >actual &&
230 cat >expect <<-\EOF &&
235 test_cmp expect actual
238 test_expect_success
'version sort (shortened)' '
239 git for-each-ref --sort=v:refname --format="%(refname:short)" refs/tags/ | grep "foo" >actual &&
240 cat >expect <<-\EOF &&
245 test_cmp expect actual
248 test_expect_success
'reverse version sort' '
249 git for-each-ref --sort=-version:refname --format="%(refname:short)" refs/tags/ | grep "foo" >actual &&
250 cat >expect <<-\EOF &&
255 test_cmp expect actual