Merge branch 'jk/describe-contains-all-match-fix'

The 'git describe --contains --all' command has been fixed to
properly honor the '--match' and '--exclude' options by passing
them down to 'git name-rev' with the appropriate reference
prefixes.

* jk/describe-contains-all-match-fix:
  describe: fix --exclude, --match with --contains and --all
main
Junio C Hamano 2026-06-16 09:01:02 -07:00
commit 7afc0f184b
2 changed files with 37 additions and 3 deletions

View File

@ -712,13 +712,25 @@ int cmd_describe(int argc,
NULL);
if (always)
strvec_push(&args, "--always");
if (!all) {
if (!all)
strvec_push(&args, "--tags");

for_each_string_list_item(item, &patterns)
strvec_pushf(&args, "--refs=refs/tags/%s", item->string);
for_each_string_list_item(item, &exclude_patterns)
strvec_pushf(&args, "--exclude=refs/tags/%s", item->string);

if (all) {
for_each_string_list_item(item, &patterns)
strvec_pushf(&args, "--refs=refs/tags/%s", item->string);
strvec_pushf(&args, "--refs=refs/heads/%s", item->string);
for_each_string_list_item(item, &exclude_patterns)
strvec_pushf(&args, "--exclude=refs/tags/%s", item->string);
strvec_pushf(&args, "--exclude=refs/heads/%s", item->string);
for_each_string_list_item(item, &patterns)
strvec_pushf(&args, "--refs=refs/remotes/%s", item->string);
for_each_string_list_item(item, &exclude_patterns)
strvec_pushf(&args, "--exclude=refs/remotes/%s", item->string);
}

if (argc)
strvec_pushv(&args, argv);
else

View File

@ -359,6 +359,28 @@ test_expect_success 'describe --contains and --no-match' '
test_cmp expect actual
'

test_expect_success 'describe --contains --all --match no matching commit' '
echo "tags/A^0" >expect &&
tagged_commit=$(git rev-parse "refs/tags/A^0") &&
test_must_fail git describe --contains --all --match="B" $tagged_commit
'

check_describe "tags/A^0" --contains --all --match="A" $(git rev-parse "refs/tags/A^0")

check_describe "branch_A" --contains --all --match="branch*" $(git rev-parse "refs/tags/A^0")

check_describe "branch_C~1" --contains --all --match="branch*" --exclude="branch_A" $(git rev-parse "refs/tags/A^0")

check_describe "branch_A" --contains --all \
--exclude="A" --exclude="c" --exclude="test*" --exclude="origin/remote_branch_A" \
$(git rev-parse "refs/tags/A^0")

check_describe "remotes/origin/remote_branch_A" --contains --all --match="origin/remote*" $(git rev-parse "refs/tags/A^0")

check_describe "remotes/origin/remote_branch_C~1" --contains --all \
--match="origin/remote*" --exclude="origin/remote_branch_A" \
$(git rev-parse "refs/tags/A^0")

test_expect_success 'setup and absorb a submodule' '
test_create_repo sub1 &&
test_commit -C sub1 initial &&