Skip to content

Commit 18e32b5

Browse files
jasamplergitster
authored andcommitted
git-tag: Fix -l option to use better shell style globs.
This patch removes certain behaviour of "git tag -l foo", currently listing every tag name having "foo" as a substring. The same thing now could be achieved doing "git tag -l '*foo*'". This feature was added recently when git-tag.sh got the -n option for showing tag annotations, because that commit also replaced the old "grep pattern" behaviour with a more preferable "shell pattern" behaviour (although slightly modified as you can see). Thus, the following builtin-tag.c implemented it in order to ensure that tests were passing unchanged with both programs. Since common "shell patterns" match names with a given substring _only_ when * is inserted before and after (as in "*substring*"), and the "plain" behaviour cannot be achieved easily with the current implementation, this is mostly the right thing to do, in order to make it more flexible and consistent. Tests for "git tag" were also changed to reflect this. Signed-off-by: Carlos Rica <jasampler@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 751eb39 commit 18e32b5

File tree

2 files changed

+11
-20
lines changed

2 files changed

+11
-20
lines changed

builtin-tag.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -123,22 +123,15 @@ static int show_reference(const char *refname, const unsigned char *sha1,
123123
static int list_tags(const char *pattern, int lines)
124124
{
125125
struct tag_filter filter;
126-
char *newpattern;
127126

128127
if (pattern == NULL)
129-
pattern = "";
128+
pattern = "*";
130129

131-
/* prepend/append * to the shell pattern: */
132-
newpattern = xmalloc(strlen(pattern) + 3);
133-
sprintf(newpattern, "*%s*", pattern);
134-
135-
filter.pattern = newpattern;
130+
filter.pattern = pattern;
136131
filter.lines = lines;
137132

138133
for_each_tag_ref(show_reference, (void *) &filter);
139134

140-
free(newpattern);
141-
142135
return 0;
143136
}
144137

t/t7004-tag.sh

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -185,18 +185,17 @@ cba
185185
EOF
186186
test_expect_success \
187187
'listing tags with substring as pattern must print those matching' '
188-
git-tag -l a > actual &&
188+
git-tag -l "*a*" > actual &&
189189
git diff expect actual
190190
'
191191

192192
cat >expect <<EOF
193193
v0.2.1
194194
v1.0.1
195-
v1.1.3
196195
EOF
197196
test_expect_success \
198-
'listing tags with substring as pattern must print those matching' '
199-
git-tag -l .1 > actual &&
197+
'listing tags with a suffix as pattern must print those matching' '
198+
git-tag -l "*.1" > actual &&
200199
git diff expect actual
201200
'
202201

@@ -205,37 +204,36 @@ t210
205204
t211
206205
EOF
207206
test_expect_success \
208-
'listing tags with substring as pattern must print those matching' '
209-
git-tag -l t21 > actual &&
207+
'listing tags with a prefix as pattern must print those matching' '
208+
git-tag -l "t21*" > actual &&
210209
git diff expect actual
211210
'
212211

213212
cat >expect <<EOF
214213
a1
215-
aa1
216214
EOF
217215
test_expect_success \
218-
'listing tags using a name as pattern must print those matching' '
216+
'listing tags using a name as pattern must print that one matching' '
219217
git-tag -l a1 > actual &&
220218
git diff expect actual
221219
'
222220

223221
cat >expect <<EOF
224222
v1.0
225-
v1.0.1
226223
EOF
227224
test_expect_success \
228-
'listing tags using a name as pattern must print those matching' '
225+
'listing tags using a name as pattern must print that one matching' '
229226
git-tag -l v1.0 > actual &&
230227
git diff expect actual
231228
'
232229

233230
cat >expect <<EOF
231+
v1.0.1
234232
v1.1.3
235233
EOF
236234
test_expect_success \
237235
'listing tags with ? in the pattern should print those matching' '
238-
git-tag -l "1.1?" > actual &&
236+
git-tag -l "v1.?.?" > actual &&
239237
git diff expect actual
240238
'
241239

0 commit comments

Comments
 (0)