@@ -17,16 +17,29 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
1717. ./test-lib.sh
1818
1919check_describe () {
20+ indir= &&
21+ while test $# ! = 0
22+ do
23+ case " $1 " in
24+ -C)
25+ indir=" $2 "
26+ shift
27+ ;;
28+ * )
29+ break
30+ ;;
31+ esac
32+ shift
33+ done &&
34+ indir=${indir: +" $indir " / } &&
2035 expect=" $1 "
2136 shift
2237 describe_opts=" $@ "
2338 test_expect_success " describe $describe_opts " '
24- R=$(git describe $describe_opts 2>err.actual) &&
25- case "$R" in
26- $expect) echo happy ;;
27- *) echo "Oops - $R is not $expect" &&
28- false ;;
29- esac
39+ git ${indir:+ -C "$indir"} describe $describe_opts >raw &&
40+ sed -e "s/-g[0-9a-f]*\$/-gHASH/" <raw >actual &&
41+ echo "$expect" >expect &&
42+ test_cmp expect actual
3043 '
3144}
3245
@@ -59,29 +72,29 @@ test_expect_success setup '
5972 test_commit --no-tag x file
6073'
6174
62- check_describe A-* HEAD
63- check_describe A-* HEAD^
64- check_describe R-* HEAD^^
65- check_describe A-* HEAD^^2
75+ check_describe A-8-gHASH HEAD
76+ check_describe A-7-gHASH HEAD^
77+ check_describe R-2-gHASH HEAD^^
78+ check_describe A-3-gHASH HEAD^^2
6679check_describe B HEAD^^2^
67- check_describe R-* HEAD^^^
80+ check_describe R-1-gHASH HEAD^^^
6881
69- check_describe c-* --tags HEAD
70- check_describe c-* --tags HEAD^
71- check_describe e-* --tags HEAD^^
72- check_describe c-* --tags HEAD^^2
82+ check_describe c-7-gHASH --tags HEAD
83+ check_describe c-6-gHASH --tags HEAD^
84+ check_describe e-1-gHASH --tags HEAD^^
85+ check_describe c-2-gHASH --tags HEAD^^2
7386check_describe B --tags HEAD^^2^
7487check_describe e --tags HEAD^^^
7588
7689check_describe heads/main --all HEAD
77- check_describe tags/c-* --all HEAD^
90+ check_describe tags/c-6-gHASH --all HEAD^
7891check_describe tags/e --all HEAD^^^
7992
80- check_describe B-0-* --long HEAD^^2^
81- check_describe A-3-* --long HEAD^^2
93+ check_describe B-0-gHASH --long HEAD^^2^
94+ check_describe A-3-gHASH --long HEAD^^2
8295
83- check_describe c-7-* --tags
84- check_describe e-3-* --first-parent --tags
96+ check_describe c-7-gHASH --tags
97+ check_describe e-3-gHASH --first-parent --tags
8598
8699test_expect_success ' describe --contains defaults to HEAD without commit-ish' '
87100 echo "A^0" >expect &&
@@ -92,20 +105,17 @@ test_expect_success 'describe --contains defaults to HEAD without commit-ish' '
92105'
93106
94107check_describe tags/A --all A^0
95- test_expect_success ' no warning was displayed for A' '
96- test_must_be_empty err.actual
97- '
98108
99- test_expect_success ' rename tag A to Q locally' '
100- mv .git/refs/tags/A .git/refs/tags/Q
101- '
102- cat - > err.expect << EOF
103- warning: tag 'Q' is externally known as 'A'
104- EOF
105- check_describe A- * HEAD
106- test_expect_success ' warning was displayed for Q ' '
107- test_cmp err.expect err.actual
108- '
109+ test_expect_success ' renaming tag A to Q locally produces a warning ' "
110+ mv .git/refs/tags/A .git/refs/tags/Q &&
111+ git describe HEAD 2>err >out &&
112+ cat >expected <<-\ EOF &&
113+ warning: tag 'Q' is externally known as 'A'
114+ EOF
115+ test_cmp expected err &&
116+ grep -E '^A-8-g[0-9a-f]+$' out
117+ "
118+
109119test_expect_success ' misnamed annotated tag forces long output' '
110120 description=$(git describe --no-long Q^0) &&
111121 expr "$description" : "A-0-g[0-9a-f]*$" &&
@@ -129,46 +139,46 @@ test_expect_success 'rename tag Q back to A' '
129139'
130140
131141test_expect_success ' pack tag refs' ' git pack-refs'
132- check_describe A-* HEAD
142+ check_describe A-8-gHASH HEAD
133143
134144test_expect_success ' describe works from outside repo using --git-dir' '
135145 git clone --bare "$TRASH_DIRECTORY" "$TRASH_DIRECTORY/bare" &&
136146 git --git-dir "$TRASH_DIRECTORY/bare" describe >out &&
137- grep -E "^A-[1-9][0-9]? -g[0-9a-f]+$" out
147+ grep -E "^A-8 -g[0-9a-f]+$" out
138148'
139149
140- check_describe " A-*[0-9a-f] " --dirty
150+ check_describe " A-8-gHASH " --dirty
141151
142152test_expect_success ' describe --dirty with --work-tree' '
143153 (
144154 cd "$TEST_DIRECTORY" &&
145155 git --git-dir "$TRASH_DIRECTORY/.git" --work-tree "$TRASH_DIRECTORY" describe --dirty >"$TRASH_DIRECTORY/out"
146156 ) &&
147- grep -E "^A-[1-9][0-9]? -g[0-9a-f]+$" out
157+ grep -E "^A-8 -g[0-9a-f]+$" out
148158'
149159
150160test_expect_success ' set-up dirty work tree' '
151161 echo >>file
152162'
153163
154- check_describe " A-*[0-9a-f]-dirty" --dirty
155-
156164test_expect_success ' describe --dirty with --work-tree (dirty)' '
165+ git describe --dirty >expected &&
157166 (
158167 cd "$TEST_DIRECTORY" &&
159168 git --git-dir "$TRASH_DIRECTORY/.git" --work-tree "$TRASH_DIRECTORY" describe --dirty >"$TRASH_DIRECTORY/out"
160169 ) &&
161- grep -E "^A-[1-9][0-9]?-g[0-9a-f]+-dirty$" out
170+ grep -E "^A-8-g[0-9a-f]+-dirty$" out &&
171+ test_cmp expected out
162172'
163173
164- check_describe " A-*[0-9a-f].mod" --dirty=.mod
165-
166174test_expect_success ' describe --dirty=.mod with --work-tree (dirty)' '
175+ git describe --dirty=.mod >expected &&
167176 (
168177 cd "$TEST_DIRECTORY" &&
169178 git --git-dir "$TRASH_DIRECTORY/.git" --work-tree "$TRASH_DIRECTORY" describe --dirty=.mod >"$TRASH_DIRECTORY/out"
170179 ) &&
171- grep -E "^A-[1-9][0-9]?-g[0-9a-f]+.mod$" out
180+ grep -E "^A-8-g[0-9a-f]+.mod$" out &&
181+ test_cmp expected out
172182'
173183
174184test_expect_success ' describe --dirty HEAD' '
@@ -191,21 +201,21 @@ test_expect_success 'set-up matching pattern tests' '
191201
192202'
193203
194- check_describe " test-annotated-* " --match=" test-*"
204+ check_describe " test-annotated-3-gHASH " --match=" test-*"
195205
196- check_describe " test1-lightweight-* " --tags --match=" test1-*"
206+ check_describe " test1-lightweight-2-gHASH " --tags --match=" test1-*"
197207
198- check_describe " test2-lightweight-* " --tags --match=" test2-*"
208+ check_describe " test2-lightweight-1-gHASH " --tags --match=" test2-*"
199209
200- check_describe " test2-lightweight-* " --long --tags --match=" test2-*" HEAD^
210+ check_describe " test2-lightweight-0-gHASH " --long --tags --match=" test2-*" HEAD^
201211
202- check_describe " test2-lightweight-* " --long --tags --match=" test1-*" --match=" test2-*" HEAD^
212+ check_describe " test2-lightweight-0-gHASH " --long --tags --match=" test1-*" --match=" test2-*" HEAD^
203213
204- check_describe " test2-lightweight-* " --long --tags --match=" test1-*" --no-match --match=" test2-*" HEAD^
214+ check_describe " test2-lightweight-0-gHASH " --long --tags --match=" test1-*" --no-match --match=" test2-*" HEAD^
205215
206- check_describe " test1-lightweight-* " --long --tags --match=" test1-*" --match=" test3-*" HEAD
216+ check_describe " test1-lightweight-2-gHASH " --long --tags --match=" test1-*" --match=" test3-*" HEAD
207217
208- check_describe " test1-lightweight-* " --long --tags --match=" test3-*" --match=" test1-*" HEAD
218+ check_describe " test1-lightweight-2-gHASH " --long --tags --match=" test3-*" --match=" test1-*" HEAD
209219
210220test_expect_success ' set-up branches' '
211221 git branch branch_A A &&
@@ -215,11 +225,11 @@ test_expect_success 'set-up branches' '
215225 git update-ref refs/original/original_branch_A test-annotated~2
216226'
217227
218- check_describe " heads/branch_A* " --all --match=" branch_*" --exclude=" branch_C" HEAD
228+ check_describe " heads/branch_A-11-gHASH " --all --match=" branch_*" --exclude=" branch_C" HEAD
219229
220- check_describe " remotes/origin/remote_branch_A* " --all --match=" origin/remote_branch_*" --exclude=" origin/remote_branch_C" HEAD
230+ check_describe " remotes/origin/remote_branch_A-11-gHASH " --all --match=" origin/remote_branch_*" --exclude=" origin/remote_branch_C" HEAD
221231
222- check_describe " original/original_branch_A* " --all test-annotated~1
232+ check_describe " original/original_branch_A-6-gHASH " --all test-annotated~1
223233
224234test_expect_success ' --match does not work for other types' '
225235 test_must_fail git describe --all --match="*original_branch_*" test-annotated~1
@@ -474,7 +484,7 @@ test_expect_success 'name-rev covers all conditions while looking at parents' '
474484# o-----o---o----x
475485# A
476486#
477- test_expect_success ' describe commits with disjoint bases' '
487+ test_expect_success ' setup: describe commits with disjoint bases' '
478488 git init disjoint1 &&
479489 (
480490 cd disjoint1 &&
@@ -487,19 +497,19 @@ test_expect_success 'describe commits with disjoint bases' '
487497 git checkout --orphan branch && rm file &&
488498 echo B > file2 && git add file2 && git commit -m B &&
489499 git tag B -a -m B &&
490- git merge --no-ff --allow-unrelated-histories main -m x &&
491-
492- check_describe "A-3-*" HEAD
500+ git merge --no-ff --allow-unrelated-histories main -m x
493501 )
494502'
495503
504+ check_describe -C disjoint1 " A-3-gHASH" HEAD
505+
496506# B
497507# o---o---o------------.
498508# \
499509# o---o---x
500510# A
501511#
502- test_expect_success ' describe commits with disjoint bases 2' '
512+ test_expect_success ' setup: describe commits with disjoint bases 2' '
503513 git init disjoint2 &&
504514 (
505515 cd disjoint2 &&
@@ -513,10 +523,10 @@ test_expect_success 'describe commits with disjoint bases 2' '
513523 echo o >> file2 && git add file2 && GIT_COMMITTER_DATE="2020-01-01 15:01" git commit -m o &&
514524 echo B >> file2 && git add file2 && GIT_COMMITTER_DATE="2020-01-01 15:02" git commit -m B &&
515525 git tag B -a -m B &&
516- git merge --no-ff --allow-unrelated-histories main -m x &&
517-
518- check_describe "B-3-*" HEAD
526+ git merge --no-ff --allow-unrelated-histories main -m x
519527 )
520528'
521529
530+ check_describe -C disjoint2 " B-3-gHASH" HEAD
531+
522532test_done
0 commit comments