describe: fix matching to actually match all patterns

`git describe --match` with multiple patterns matches only first pattern. If it fails, next patterns are not tried. Fix it, add test cases and update existing test which has wrong expectation. Signed-off-by: Max Kirillov <max@max630.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Max Kirillov committed Sep 16, 2017 at 08:53 UTC da769d2986470931b8e80b8d14afcae3d7cc20d7
2 files changed +11 -4
builtin/describe.c
+6 -3
@@ -151,18 +151,21 @@ static int get_name(const char *path, const struct object_id *oid, int flag, voi
151 * pattern.
152 */
153 if (patterns.nr) {
154 + int found = 0;
155 struct string_list_item *item;
156
157 if (!is_tag)
158 return 0;
159
160 for_each_string_list_item(item, &patterns) {
160 - if (!wildmatch(item->string, path + 10, 0, NULL))
161 + if (!wildmatch(item->string, path + 10, 0, NULL)) {
162 + found = 1;
163 break;
164 + }
165 + }
166
163 - /* If we get here, no pattern matched. */
167 + if (!found)
168 return 0;
165 - }
169 }
170
171 /* Is it annotated? */
t/t6120-describe.sh
+5 -1
@@ -182,10 +182,14 @@ check_describe "test2-lightweight-*" --tags --match="test2-*"
182
183 check_describe "test2-lightweight-*" --long --tags --match="test2-*" HEAD^
184
185 -check_describe "test1-lightweight-*" --long --tags --match="test1-*" --match="test2-*" HEAD^
185 +check_describe "test2-lightweight-*" --long --tags --match="test1-*" --match="test2-*" HEAD^
186
187 check_describe "test2-lightweight-*" --long --tags --match="test1-*" --no-match --match="test2-*" HEAD^
188
189 +check_describe "test1-lightweight-*" --long --tags --match="test1-*" --match="test3-*" HEAD
190 +
191 +check_describe "test1-lightweight-*" --long --tags --match="test3-*" --match="test1-*" HEAD
192 +
193 test_expect_success 'name-rev with exact tags' '
194 echo A >expect &&
195 tag_object=$(git rev-parse refs/tags/A) &&