diff --git a/builtin-tag.c b/builtin-tag.c index d6d38ad123cb0f354a6bd7007eddf8fb1b4d126c..348919cff8645c81ac803a34c967ba34f9b982b4 100644 --- a/builtin-tag.c +++ b/builtin-tag.c @@ -123,22 +123,15 @@ static int show_reference(const char *refname, const unsigned char *sha1, static int list_tags(const char *pattern, int lines) { struct tag_filter filter; - char *newpattern; if (pattern == NULL) - pattern = ""; + pattern = "*"; - /* prepend/append * to the shell pattern: */ - newpattern = xmalloc(strlen(pattern) + 3); - sprintf(newpattern, "*%s*", pattern); - - filter.pattern = newpattern; + filter.pattern = pattern; filter.lines = lines; for_each_tag_ref(show_reference, (void *) &filter); - free(newpattern); - return 0; } diff --git a/t/t7004-tag.sh b/t/t7004-tag.sh index c4fa4461f764dd936f231dae3905605b0ed0c28a..606d4f2a2c3e771c188294ae92d58cf2a38e14fb 100755 --- a/t/t7004-tag.sh +++ b/t/t7004-tag.sh @@ -185,18 +185,17 @@ cba EOF test_expect_success \ 'listing tags with substring as pattern must print those matching' ' - git-tag -l a > actual && + git-tag -l "*a*" > actual && git diff expect actual ' cat >expect < actual && + 'listing tags with a suffix as pattern must print those matching' ' + git-tag -l "*.1" > actual && git diff expect actual ' @@ -205,37 +204,36 @@ t210 t211 EOF test_expect_success \ - 'listing tags with substring as pattern must print those matching' ' - git-tag -l t21 > actual && + 'listing tags with a prefix as pattern must print those matching' ' + git-tag -l "t21*" > actual && git diff expect actual ' cat >expect < actual && git diff expect actual ' cat >expect < actual && git diff expect actual ' cat >expect < actual && + git-tag -l "v1.?.?" > actual && git diff expect actual '