mirror of
https://github.com/git/git
synced 2024-08-28 20:20:07 +00:00
Merge branch 'mk/describe-match-with-all'
"git describe --match <pattern>" has been taught to play well with the "--all" option. * mk/describe-match-with-all: describe: teach --match to handle branches and remotes
This commit is contained in:
commit
8c1bc7c244
|
@ -87,19 +87,23 @@ OPTIONS
|
||||||
|
|
||||||
--match <pattern>::
|
--match <pattern>::
|
||||||
Only consider tags matching the given `glob(7)` pattern,
|
Only consider tags matching the given `glob(7)` pattern,
|
||||||
excluding the "refs/tags/" prefix. This can be used to avoid
|
excluding the "refs/tags/" prefix. If used with `--all`, it also
|
||||||
leaking private tags from the repository. If given multiple times, a
|
considers local branches and remote-tracking references matching the
|
||||||
list of patterns will be accumulated, and tags matching any of the
|
pattern, excluding respectively "refs/heads/" and "refs/remotes/"
|
||||||
patterns will be considered. Use `--no-match` to clear and reset the
|
prefix; references of other types are never considered. If given
|
||||||
list of patterns.
|
multiple times, a list of patterns will be accumulated, and tags
|
||||||
|
matching any of the patterns will be considered. Use `--no-match` to
|
||||||
|
clear and reset the list of patterns.
|
||||||
|
|
||||||
--exclude <pattern>::
|
--exclude <pattern>::
|
||||||
Do not consider tags matching the given `glob(7)` pattern, excluding
|
Do not consider tags matching the given `glob(7)` pattern, excluding
|
||||||
the "refs/tags/" prefix. This can be used to narrow the tag space and
|
the "refs/tags/" prefix. If used with `--all`, it also does not consider
|
||||||
find only tags matching some meaningful criteria. If given multiple
|
local branches and remote-tracking references matching the pattern,
|
||||||
times, a list of patterns will be accumulated and tags matching any
|
excluding respectively "refs/heads/" and "refs/remotes/" prefix;
|
||||||
of the patterns will be excluded. When combined with --match a tag will
|
references of other types are never considered. If given multiple times,
|
||||||
be considered when it matches at least one --match pattern and does not
|
a list of patterns will be accumulated and tags matching any of the
|
||||||
|
patterns will be excluded. When combined with --match a tag will be
|
||||||
|
considered when it matches at least one --match pattern and does not
|
||||||
match any of the --exclude patterns. Use `--no-exclude` to clear and
|
match any of the --exclude patterns. Use `--no-exclude` to clear and
|
||||||
reset the list of patterns.
|
reset the list of patterns.
|
||||||
|
|
||||||
|
|
|
@ -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)
|
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;
|
struct object_id peeled;
|
||||||
int is_annotated, prio;
|
int is_annotated, prio;
|
||||||
|
const char *path_to_match = NULL;
|
||||||
|
|
||||||
/* Reject anything outside refs/tags/ unless --all */
|
if (skip_prefix(path, "refs/tags/", &path_to_match)) {
|
||||||
if (!all && !is_tag)
|
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;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If we're given exclude patterns, first exclude any tag which match
|
* 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) {
|
if (exclude_patterns.nr) {
|
||||||
struct string_list_item *item;
|
struct string_list_item *item;
|
||||||
|
|
||||||
if (!is_tag)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
for_each_string_list_item(item, &exclude_patterns) {
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -161,11 +169,8 @@ static int get_name(const char *path, const struct object_id *oid, int flag, voi
|
||||||
int found = 0;
|
int found = 0;
|
||||||
struct string_list_item *item;
|
struct string_list_item *item;
|
||||||
|
|
||||||
if (!is_tag)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
for_each_string_list_item(item, &patterns) {
|
for_each_string_list_item(item, &patterns) {
|
||||||
if (!wildmatch(item->string, path + 10, 0)) {
|
if (!wildmatch(item->string, path_to_match, 0)) {
|
||||||
found = 1;
|
found = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -190,6 +190,33 @@ check_describe "test1-lightweight-*" --long --tags --match="test1-*" --match="te
|
||||||
|
|
||||||
check_describe "test1-lightweight-*" --long --tags --match="test3-*" --match="test1-*" HEAD
|
check_describe "test1-lightweight-*" --long --tags --match="test3-*" --match="test1-*" HEAD
|
||||||
|
|
||||||
|
test_expect_success 'set-up branches' '
|
||||||
|
git branch branch_A A &&
|
||||||
|
git branch branch_C c &&
|
||||||
|
git update-ref refs/remotes/origin/remote_branch_A "A^{commit}" &&
|
||||||
|
git update-ref refs/remotes/origin/remote_branch_C "c^{commit}" &&
|
||||||
|
git update-ref refs/original/original_branch_A test-annotated~2
|
||||||
|
'
|
||||||
|
|
||||||
|
check_describe "heads/branch_A*" --all --match="branch_*" --exclude="branch_C" HEAD
|
||||||
|
|
||||||
|
check_describe "remotes/origin/remote_branch_A*" --all --match="origin/remote_branch_*" --exclude="origin/remote_branch_C" HEAD
|
||||||
|
|
||||||
|
check_describe "original/original_branch_A*" --all test-annotated~1
|
||||||
|
|
||||||
|
test_expect_success '--match does not work for other types' '
|
||||||
|
test_must_fail git describe --all --match="*original_branch_*" test-annotated~1
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success '--exclude does not work for other types' '
|
||||||
|
R=$(git describe --all --exclude="any_pattern_even_not_matching" test-annotated~1) &&
|
||||||
|
case "$R" in
|
||||||
|
*original_branch_A*) echo "fail: Found unknown reference $R with --exclude"
|
||||||
|
false;;
|
||||||
|
*) echo ok: Found some known type;;
|
||||||
|
esac
|
||||||
|
'
|
||||||
|
|
||||||
test_expect_success 'name-rev with exact tags' '
|
test_expect_success 'name-rev with exact tags' '
|
||||||
echo A >expect &&
|
echo A >expect &&
|
||||||
tag_object=$(git rev-parse refs/tags/A) &&
|
tag_object=$(git rev-parse refs/tags/A) &&
|
||||||
|
|
Loading…
Reference in a new issue