diff options
author | Max Kirillov <max@max630.net> | 2017-09-20 04:10:10 +0300 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2017-09-20 13:30:10 +0900 |
commit | 6d68b2ab78cb670dd474dd61b1b2ec0a407cb9b8 (patch) | |
tree | 767e2c981f2f7fdef73c53eec910c53a3cad103a /builtin/describe.c | |
parent | 3445c3dd723b222d5ceda07b13d092d73428012e (diff) | |
download | git-6d68b2ab78cb670dd474dd61b1b2ec0a407cb9b8.tar.gz git-6d68b2ab78cb670dd474dd61b1b2ec0a407cb9b8.tar.xz |
describe: teach --match to handle branches and remotes
When `git describe` uses `--match`, it matches only tags, basically
ignoring the `--all` argument even when it is specified.
Fix it by also matching branch name and $remote_name/$remote_branch_name,
for remote-tracking references, with the specified patterns. Update
documentation accordingly and add tests.
Signed-off-by: Max Kirillov <max@max630.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/describe.c')
-rw-r--r-- | builtin/describe.c | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/builtin/describe.c b/builtin/describe.c index 3dc183648..29075dbd0 100644 --- a/builtin/describe.c +++ b/builtin/describe.c @@ -129,13 +129,24 @@ static void add_to_known_names(const char *path, static int get_name(const char *path, const struct object_id *oid, int flag, void *cb_data) { - int is_tag = starts_with(path, "refs/tags/"); + int is_tag = 0; struct object_id peeled; int is_annotated, prio; - - /* Reject anything outside refs/tags/ unless --all */ - if (!all && !is_tag) + const char *path_to_match = NULL; + + if (skip_prefix(path, "refs/tags/", &path_to_match)) { + is_tag = 1; + } else if (all) { + if ((exclude_patterns.nr || patterns.nr) && + !skip_prefix(path, "refs/heads/", &path_to_match) && + !skip_prefix(path, "refs/remotes/", &path_to_match)) { + /* Only accept reference of known type if there are match/exclude patterns */ + return 0; + } + } else { + /* Reject anything outside refs/tags/ unless --all */ return 0; + } /* * If we're given exclude patterns, first exclude any tag which match @@ -144,11 +155,8 @@ static int get_name(const char *path, const struct object_id *oid, int flag, voi if (exclude_patterns.nr) { struct string_list_item *item; - if (!is_tag) - return 0; - for_each_string_list_item(item, &exclude_patterns) { - if (!wildmatch(item->string, path + 10, 0)) + if (!wildmatch(item->string, path_to_match, 0)) return 0; } } @@ -161,11 +169,8 @@ static int get_name(const char *path, const struct object_id *oid, int flag, voi int found = 0; struct string_list_item *item; - if (!is_tag) - return 0; - for_each_string_list_item(item, &patterns) { - if (!wildmatch(item->string, path + 10, 0)) { + if (!wildmatch(item->string, path_to_match, 0)) { found = 1; break; } |