Skip to content

Commit da769d2

Browse files
max630gitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 77d21f2 commit da769d2

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

builtin/describe.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,18 +151,21 @@ static int get_name(const char *path, const struct object_id *oid, int flag, voi
151151
* pattern.
152152
*/
153153
if (patterns.nr) {
154+
int found = 0;
154155
struct string_list_item *item;
155156

156157
if (!is_tag)
157158
return 0;
158159

159160
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;
161163
break;
164+
}
165+
}
162166

163-
/* If we get here, no pattern matched. */
167+
if (!found)
164168
return 0;
165-
}
166169
}
167170

168171
/* Is it annotated? */

t/t6120-describe.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,14 @@ check_describe "test2-lightweight-*" --tags --match="test2-*"
182182

183183
check_describe "test2-lightweight-*" --long --tags --match="test2-*" HEAD^
184184

185-
check_describe "test1-lightweight-*" --long --tags --match="test1-*" --match="test2-*" HEAD^
185+
check_describe "test2-lightweight-*" --long --tags --match="test1-*" --match="test2-*" HEAD^
186186

187187
check_describe "test2-lightweight-*" --long --tags --match="test1-*" --no-match --match="test2-*" HEAD^
188188

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+
189193
test_expect_success 'name-rev with exact tags' '
190194
echo A >expect &&
191195
tag_object=$(git rev-parse refs/tags/A) &&

0 commit comments

Comments
 (0)