Skip to content

Commit 12350de

Browse files
committed
Merge branch 'jk/describe-contains-all-match-fix' into jch
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
2 parents 7287d73 + 1891707 commit 12350de

2 files changed

Lines changed: 37 additions & 3 deletions

File tree

builtin/describe.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -712,13 +712,25 @@ int cmd_describe(int argc,
712712
NULL);
713713
if (always)
714714
strvec_push(&args, "--always");
715-
if (!all) {
715+
if (!all)
716716
strvec_push(&args, "--tags");
717+
718+
for_each_string_list_item(item, &patterns)
719+
strvec_pushf(&args, "--refs=refs/tags/%s", item->string);
720+
for_each_string_list_item(item, &exclude_patterns)
721+
strvec_pushf(&args, "--exclude=refs/tags/%s", item->string);
722+
723+
if (all) {
717724
for_each_string_list_item(item, &patterns)
718-
strvec_pushf(&args, "--refs=refs/tags/%s", item->string);
725+
strvec_pushf(&args, "--refs=refs/heads/%s", item->string);
719726
for_each_string_list_item(item, &exclude_patterns)
720-
strvec_pushf(&args, "--exclude=refs/tags/%s", item->string);
727+
strvec_pushf(&args, "--exclude=refs/heads/%s", item->string);
728+
for_each_string_list_item(item, &patterns)
729+
strvec_pushf(&args, "--refs=refs/remotes/%s", item->string);
730+
for_each_string_list_item(item, &exclude_patterns)
731+
strvec_pushf(&args, "--exclude=refs/remotes/%s", item->string);
721732
}
733+
722734
if (argc)
723735
strvec_pushv(&args, argv);
724736
else

t/t6120-describe.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,28 @@ test_expect_success 'describe --contains and --no-match' '
359359
test_cmp expect actual
360360
'
361361

362+
test_expect_success 'describe --contains --all --match no matching commit' '
363+
echo "tags/A^0" >expect &&
364+
tagged_commit=$(git rev-parse "refs/tags/A^0") &&
365+
test_must_fail git describe --contains --all --match="B" $tagged_commit
366+
'
367+
368+
check_describe "tags/A^0" --contains --all --match="A" $(git rev-parse "refs/tags/A^0")
369+
370+
check_describe "branch_A" --contains --all --match="branch*" $(git rev-parse "refs/tags/A^0")
371+
372+
check_describe "branch_C~1" --contains --all --match="branch*" --exclude="branch_A" $(git rev-parse "refs/tags/A^0")
373+
374+
check_describe "branch_A" --contains --all \
375+
--exclude="A" --exclude="c" --exclude="test*" --exclude="origin/remote_branch_A" \
376+
$(git rev-parse "refs/tags/A^0")
377+
378+
check_describe "remotes/origin/remote_branch_A" --contains --all --match="origin/remote*" $(git rev-parse "refs/tags/A^0")
379+
380+
check_describe "remotes/origin/remote_branch_C~1" --contains --all \
381+
--match="origin/remote*" --exclude="origin/remote_branch_A" \
382+
$(git rev-parse "refs/tags/A^0")
383+
362384
test_expect_success 'setup and absorb a submodule' '
363385
test_create_repo sub1 &&
364386
test_commit -C sub1 initial &&

0 commit comments

Comments
 (0)