@@ -18,13 +18,17 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
18
18
19
19
check_describe () {
20
20
indir= &&
21
+ outcome=success &&
21
22
while test $# ! = 0
22
23
do
23
24
case " $1 " in
24
25
-C)
25
26
indir=" $2 "
26
27
shift
27
28
;;
29
+ --expect-failure)
30
+ outcome=failure
31
+ ;;
28
32
* )
29
33
break
30
34
;;
@@ -35,7 +39,7 @@ check_describe () {
35
39
expect=" $1 "
36
40
shift
37
41
describe_opts=" $@ "
38
- test_expect_success " describe $describe_opts " '
42
+ test_expect_ ${outcome} " describe $describe_opts " '
39
43
git ${indir:+ -C "$indir"} describe $describe_opts >raw &&
40
44
sed -e "s/-g[0-9a-f]*\$/-gHASH/" <raw >actual &&
41
45
echo "$expect" >expect &&
@@ -616,7 +620,7 @@ test_expect_success 'name-rev --annotate-stdin works with commitGraph' '
616
620
617
621
# B
618
622
# o
619
- # \
623
+ # H \
620
624
# o-----o---o----x
621
625
# A
622
626
#
@@ -626,6 +630,7 @@ test_expect_success 'setup: describe commits with disjoint bases' '
626
630
cd disjoint1 &&
627
631
628
632
echo o >> file && git add file && git commit -m o &&
633
+ git tag H -a -m H &&
629
634
echo A >> file && git add file && git commit -m A &&
630
635
git tag A -a -m A &&
631
636
echo o >> file && git add file && git commit -m o &&
@@ -638,8 +643,9 @@ test_expect_success 'setup: describe commits with disjoint bases' '
638
643
'
639
644
640
645
check_describe -C disjoint1 " A-3-gHASH" HEAD
646
+ check_describe -C disjoint1 --expect-failure " A-3-gHASH" --candidates=2 HEAD
641
647
642
- # B
648
+ # H B
643
649
# o---o---o------------.
644
650
# \
645
651
# o---o---x
@@ -657,13 +663,15 @@ test_expect_success 'setup: describe commits with disjoint bases 2' '
657
663
git checkout --orphan branch &&
658
664
echo o >> file2 && git add file2 && GIT_COMMITTER_DATE="2020-01-01 15:00" git commit -m o &&
659
665
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 &&
660
667
echo B >> file2 && git add file2 && GIT_COMMITTER_DATE="2020-01-01 15:02" git commit -m B &&
661
668
git tag B -a -m B &&
662
669
git merge --no-ff --allow-unrelated-histories main -m x
663
670
)
664
671
'
665
672
666
673
check_describe -C disjoint2 " B-3-gHASH" HEAD
674
+ check_describe -C disjoint2 --expect-failure " B-3-gHASH" --candidates=2 HEAD
667
675
668
676
test_expect_success ' setup misleading taggerdates' '
669
677
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' '
707
715
)
708
716
'
709
717
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
+
710
728
test_done
0 commit comments