@@ -18,13 +18,17 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
1818
1919check_describe () {
2020 indir= &&
21+ outcome=success &&
2122 while test $# ! = 0
2223 do
2324 case " $1 " in
2425 -C)
2526 indir=" $2 "
2627 shift
2728 ;;
29+ --expect-failure)
30+ outcome=failure
31+ ;;
2832 * )
2933 break
3034 ;;
@@ -35,7 +39,7 @@ check_describe () {
3539 expect=" $1 "
3640 shift
3741 describe_opts=" $@ "
38- test_expect_success " describe $describe_opts " '
42+ test_expect_ ${outcome} " describe $describe_opts " '
3943 git ${indir:+ -C "$indir"} describe $describe_opts >raw &&
4044 sed -e "s/-g[0-9a-f]*\$/-gHASH/" <raw >actual &&
4145 echo "$expect" >expect &&
@@ -616,7 +620,7 @@ test_expect_success 'name-rev --annotate-stdin works with commitGraph' '
616620
617621# B
618622# o
619- # \
623+ # H \
620624# o-----o---o----x
621625# A
622626#
@@ -626,6 +630,7 @@ test_expect_success 'setup: describe commits with disjoint bases' '
626630 cd disjoint1 &&
627631
628632 echo o >> file && git add file && git commit -m o &&
633+ git tag H -a -m H &&
629634 echo A >> file && git add file && git commit -m A &&
630635 git tag A -a -m A &&
631636 echo o >> file && git add file && git commit -m o &&
@@ -638,8 +643,9 @@ test_expect_success 'setup: describe commits with disjoint bases' '
638643'
639644
640645check_describe -C disjoint1 " A-3-gHASH" HEAD
646+ check_describe -C disjoint1 --expect-failure " A-3-gHASH" --candidates=2 HEAD
641647
642- # B
648+ # H B
643649# o---o---o------------.
644650# \
645651# o---o---x
@@ -657,13 +663,15 @@ test_expect_success 'setup: describe commits with disjoint bases 2' '
657663 git checkout --orphan branch &&
658664 echo o >> file2 && git add file2 && GIT_COMMITTER_DATE="2020-01-01 15:00" git commit -m o &&
659665 echo o >> file2 && git add file2 && GIT_COMMITTER_DATE="2020-01-01 15:01" git commit -m o &&
666+ git tag H -a -m H &&
660667 echo B >> file2 && git add file2 && GIT_COMMITTER_DATE="2020-01-01 15:02" git commit -m B &&
661668 git tag B -a -m B &&
662669 git merge --no-ff --allow-unrelated-histories main -m x
663670 )
664671'
665672
666673check_describe -C disjoint2 " B-3-gHASH" HEAD
674+ check_describe -C disjoint2 --expect-failure " B-3-gHASH" --candidates=2 HEAD
667675
668676test_expect_success ' setup misleading taggerdates' '
669677 GIT_COMMITTER_DATE="2006-12-12 12:31" git tag -a -m "another tag" newer-tag-older-commit unique-file~1
@@ -707,4 +715,14 @@ test_expect_success 'describe --broken --dirty with a file with changed stat' '
707715 )
708716'
709717
718+ test_expect_success ' --always with no refs falls back to commit hash' '
719+ git rev-parse HEAD >expect &&
720+ git describe --no-abbrev --always --match=no-such-tag >actual &&
721+ test_cmp expect actual
722+ '
723+
724+ test_expect_success ' --exact-match does not show --always fallback' '
725+ test_must_fail git describe --exact-match --always
726+ '
727+
710728test_done
0 commit comments