Git fork
1#!/bin/sh
2
3test_description='test describe'
4
5# o---o-----o----o----o-------o----x
6# \ D,R e /
7# \---o-------------o-'
8# \ B /
9# `-o----o----o-'
10# A c
11#
12# First parent of a merge commit is on the same line, second parent below.
13
14GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
15export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
16
17. ./test-lib.sh
18
19check_describe () {
20 indir= &&
21 outcome=success &&
22 while test $# != 0
23 do
24 case "$1" in
25 -C)
26 indir="$2"
27 shift
28 ;;
29 --expect-failure)
30 outcome=failure
31 ;;
32 *)
33 break
34 ;;
35 esac
36 shift
37 done &&
38 indir=${indir:+"$indir"/} &&
39 expect="$1"
40 shift
41 describe_opts="$@"
42 test_expect_${outcome} "describe $describe_opts" '
43 git ${indir:+ -C "$indir"} describe $describe_opts >raw &&
44 sed -e "s/-g[0-9a-f]*\$/-gHASH/" <raw >actual &&
45 echo "$expect" >expect &&
46 test_cmp expect actual
47 '
48}
49
50test_expect_success setup '
51 test_commit initial file one &&
52 test_commit second file two &&
53 test_commit third file three &&
54 test_commit --annotate A file A &&
55 test_commit c file c &&
56
57 git reset --hard second &&
58 test_commit --annotate B side B &&
59
60 test_tick &&
61 git merge -m Merged c &&
62 merged=$(git rev-parse HEAD) &&
63
64 git reset --hard second &&
65 test_commit --no-tag D another D &&
66
67 test_tick &&
68 git tag -a -m R R &&
69
70 test_commit e another DD &&
71 test_commit --no-tag "yet another" another DDD &&
72
73 test_tick &&
74 git merge -m Merged $merged &&
75
76 test_commit --no-tag x file
77'
78
79check_describe A-8-gHASH HEAD
80check_describe A-7-gHASH HEAD^
81check_describe R-2-gHASH HEAD^^
82check_describe A-3-gHASH HEAD^^2
83check_describe B HEAD^^2^
84check_describe R-1-gHASH HEAD^^^
85check_describe R-1-gHASH R-1-g$(git rev-parse --short HEAD^^)~1
86
87check_describe c-7-gHASH --tags HEAD
88check_describe c-6-gHASH --tags HEAD^
89check_describe e-1-gHASH --tags HEAD^^
90check_describe c-2-gHASH --tags HEAD^^2
91check_describe c-2-gHASH --tags c-2-g$(git rev-parse --short HEAD^^2)^0
92check_describe B --tags HEAD^^2^
93check_describe e --tags HEAD^^^
94check_describe e --tags --exact-match HEAD^^^
95
96check_describe heads/main --all HEAD
97check_describe tags/c-6-gHASH --all HEAD^
98check_describe tags/e --all HEAD^^^
99
100check_describe B-0-gHASH --long HEAD^^2^
101check_describe A-3-gHASH --long HEAD^^2
102
103check_describe c-7-gHASH --tags
104check_describe e-3-gHASH --first-parent --tags
105
106check_describe c-7-gHASH --tags --no-exact-match HEAD
107check_describe e-3-gHASH --first-parent --tags --no-exact-match HEAD
108
109test_expect_success '--exact-match failure' '
110 test_must_fail git describe --exact-match HEAD 2>err
111'
112
113test_expect_success 'describe --contains defaults to HEAD without commit-ish' '
114 echo "A^0" >expect &&
115 git checkout A &&
116 test_when_finished "git checkout -" &&
117 git describe --contains >actual &&
118 test_cmp expect actual
119'
120
121check_describe tags/A --all A^0
122
123test_expect_success 'renaming tag A to Q locally produces a warning' "
124 git update-ref refs/tags/Q $(git rev-parse refs/tags/A) &&
125 git update-ref -d refs/tags/A &&
126 git describe HEAD 2>err >out &&
127 cat >expected <<-\EOF &&
128 warning: tag 'Q' is externally known as 'A'
129 EOF
130 test_cmp expected err &&
131 grep -E '^A-8-g[0-9a-f]+$' out
132"
133
134test_expect_success 'misnamed annotated tag forces long output' '
135 description=$(git describe --no-long Q^0) &&
136 expr "$description" : "A-0-g[0-9a-f]*$" &&
137 git rev-parse --verify "$description" >actual &&
138 git rev-parse --verify Q^0 >expect &&
139 test_cmp expect actual
140'
141
142test_expect_success 'abbrev=0 will not break misplaced tag (1)' '
143 description=$(git describe --abbrev=0 Q^0) &&
144 expr "$description" : "A-0-g[0-9a-f]*$"
145'
146
147test_expect_success 'abbrev=0 will not break misplaced tag (2)' '
148 description=$(git describe --abbrev=0 c^0) &&
149 expr "$description" : "A-1-g[0-9a-f]*$"
150'
151
152test_expect_success 'rename tag Q back to A' '
153 git update-ref refs/tags/A $(git rev-parse refs/tags/Q) &&
154 git update-ref -d refs/tags/Q
155'
156
157test_expect_success 'pack tag refs' 'git pack-refs'
158check_describe A-8-gHASH HEAD
159
160test_expect_success 'describe works from outside repo using --git-dir' '
161 git clone --bare "$TRASH_DIRECTORY" "$TRASH_DIRECTORY/bare" &&
162 git --git-dir "$TRASH_DIRECTORY/bare" describe >out &&
163 grep -E "^A-8-g[0-9a-f]+$" out
164'
165
166check_describe "A-8-gHASH" --dirty
167
168test_expect_success 'describe --dirty with --work-tree' '
169 (
170 cd "$TEST_DIRECTORY" &&
171 git --git-dir "$TRASH_DIRECTORY/.git" --work-tree "$TRASH_DIRECTORY" describe --dirty >"$TRASH_DIRECTORY/out"
172 ) &&
173 grep -E "^A-8-g[0-9a-f]+$" out
174'
175
176test_expect_success 'set-up dirty work tree' '
177 echo >>file
178'
179
180test_expect_success 'describe --dirty with --work-tree (dirty)' '
181 git describe --dirty >expected &&
182 (
183 cd "$TEST_DIRECTORY" &&
184 git --git-dir "$TRASH_DIRECTORY/.git" --work-tree "$TRASH_DIRECTORY" describe --dirty >"$TRASH_DIRECTORY/out"
185 ) &&
186 grep -E "^A-8-g[0-9a-f]+-dirty$" out &&
187 test_cmp expected out
188'
189
190test_expect_success 'describe --dirty=.mod with --work-tree (dirty)' '
191 git describe --dirty=.mod >expected &&
192 (
193 cd "$TEST_DIRECTORY" &&
194 git --git-dir "$TRASH_DIRECTORY/.git" --work-tree "$TRASH_DIRECTORY" describe --dirty=.mod >"$TRASH_DIRECTORY/out"
195 ) &&
196 grep -E "^A-8-g[0-9a-f]+.mod$" out &&
197 test_cmp expected out
198'
199
200test_expect_success 'describe --dirty HEAD' '
201 test_must_fail git describe --dirty HEAD
202'
203
204test_expect_success 'set-up matching pattern tests' '
205 git tag -a -m test-annotated test-annotated &&
206 echo >>file &&
207 test_tick &&
208 git commit -a -m "one more" &&
209 git tag test1-lightweight &&
210 echo >>file &&
211 test_tick &&
212 git commit -a -m "yet another" &&
213 git tag test2-lightweight &&
214 echo >>file &&
215 test_tick &&
216 git commit -a -m "even more"
217
218'
219
220check_describe "test-annotated-3-gHASH" --match="test-*"
221
222check_describe "test1-lightweight-2-gHASH" --tags --match="test1-*"
223
224check_describe "test2-lightweight-1-gHASH" --tags --match="test2-*"
225
226check_describe "test2-lightweight-0-gHASH" --long --tags --match="test2-*" HEAD^
227
228check_describe "test2-lightweight-0-gHASH" --long --tags --match="test1-*" --match="test2-*" HEAD^
229
230check_describe "test2-lightweight-0-gHASH" --long --tags --match="test1-*" --no-match --match="test2-*" HEAD^
231
232check_describe "test1-lightweight-2-gHASH" --long --tags --match="test1-*" --match="test3-*" HEAD
233
234check_describe "test1-lightweight-2-gHASH" --long --tags --match="test3-*" --match="test1-*" HEAD
235
236test_expect_success 'set-up branches' '
237 git branch branch_A A &&
238 git branch branch_C c &&
239 git update-ref refs/remotes/origin/remote_branch_A "A^{commit}" &&
240 git update-ref refs/remotes/origin/remote_branch_C "c^{commit}" &&
241 git update-ref refs/original/original_branch_A test-annotated~2
242'
243
244check_describe "heads/branch_A-11-gHASH" --all --match="branch_*" --exclude="branch_C" HEAD
245
246check_describe "remotes/origin/remote_branch_A-11-gHASH" --all --match="origin/remote_branch_*" --exclude="origin/remote_branch_C" HEAD
247
248check_describe "original/original_branch_A-6-gHASH" --all test-annotated~1
249
250test_expect_success '--match does not work for other types' '
251 test_must_fail git describe --all --match="*original_branch_*" test-annotated~1
252'
253
254test_expect_success '--exclude does not work for other types' '
255 R=$(git describe --all --exclude="any_pattern_even_not_matching" test-annotated~1) &&
256 case "$R" in
257 *original_branch_A*) echo "fail: Found unknown reference $R with --exclude"
258 false;;
259 *) echo ok: Found some known type;;
260 esac
261'
262
263test_expect_success 'name-rev with exact tags' '
264 echo A >expect &&
265 tag_object=$(git rev-parse refs/tags/A) &&
266 git name-rev --tags --name-only $tag_object >actual &&
267 test_cmp expect actual &&
268
269 echo "A^0" >expect &&
270 tagged_commit=$(git rev-parse "refs/tags/A^0") &&
271 git name-rev --tags --name-only $tagged_commit >actual &&
272 test_cmp expect actual
273'
274
275test_expect_success 'name-rev --all' '
276 >expect.unsorted &&
277 for rev in $(git rev-list --all)
278 do
279 git name-rev $rev >>expect.unsorted || return 1
280 done &&
281 sort <expect.unsorted >expect &&
282 git name-rev --all >actual.unsorted &&
283 sort <actual.unsorted >actual &&
284 test_cmp expect actual
285'
286
287test_expect_success 'name-rev --annotate-stdin' '
288 >expect.unsorted &&
289 for rev in $(git rev-list --all)
290 do
291 name=$(git name-rev --name-only $rev) &&
292 echo "$rev ($name)" >>expect.unsorted || return 1
293 done &&
294 sort <expect.unsorted >expect &&
295 git rev-list --all >list &&
296 git name-rev --annotate-stdin <list >actual.unsorted &&
297 sort <actual.unsorted >actual &&
298 test_cmp expect actual
299'
300
301test_expect_success 'name-rev --stdin deprecated' '
302 git rev-list --all >list &&
303 if ! test_have_prereq WITH_BREAKING_CHANGES
304 then
305 git name-rev --stdin <list 2>actual &&
306 test_grep "warning: --stdin is deprecated" actual
307 else
308 test_must_fail git name-rev --stdin <list 2>actual &&
309 test_grep "unknown option .stdin." actual
310 fi
311'
312
313test_expect_success 'describe --contains with the exact tags' '
314 echo "A^0" >expect &&
315 tag_object=$(git rev-parse refs/tags/A) &&
316 git describe --contains $tag_object >actual &&
317 test_cmp expect actual &&
318
319 echo "A^0" >expect &&
320 tagged_commit=$(git rev-parse "refs/tags/A^0") &&
321 git describe --contains $tagged_commit >actual &&
322 test_cmp expect actual
323'
324
325test_expect_success 'describe --contains and --match' '
326 echo "A^0" >expect &&
327 tagged_commit=$(git rev-parse "refs/tags/A^0") &&
328 test_must_fail git describe --contains --match="B" $tagged_commit &&
329 git describe --contains --match="B" --match="A" $tagged_commit >actual &&
330 test_cmp expect actual
331'
332
333test_expect_success 'describe --exclude' '
334 echo "c~1" >expect &&
335 tagged_commit=$(git rev-parse "refs/tags/A^0") &&
336 test_must_fail git describe --contains --match="B" $tagged_commit &&
337 git describe --contains --match="?" --exclude="A" $tagged_commit >actual &&
338 test_cmp expect actual
339'
340
341test_expect_success 'describe --contains and --no-match' '
342 echo "A^0" >expect &&
343 tagged_commit=$(git rev-parse "refs/tags/A^0") &&
344 git describe --contains --match="B" --no-match $tagged_commit >actual &&
345 test_cmp expect actual
346'
347
348test_expect_success 'setup and absorb a submodule' '
349 test_create_repo sub1 &&
350 test_commit -C sub1 initial &&
351 git submodule add ./sub1 &&
352 git submodule absorbgitdirs &&
353 git commit -a -m "add submodule" &&
354 git describe --dirty >expect &&
355 git describe --broken >out &&
356 test_cmp expect out
357'
358
359test_expect_success 'describe chokes on severely broken submodules' '
360 mv .git/modules/sub1/ .git/modules/sub_moved &&
361 test_must_fail git describe --dirty
362'
363
364test_expect_success 'describe ignoring a broken submodule' '
365 git describe --broken >out &&
366 grep broken out
367'
368
369test_expect_success 'describe with --work-tree ignoring a broken submodule' '
370 (
371 cd "$TEST_DIRECTORY" &&
372 git --git-dir "$TRASH_DIRECTORY/.git" --work-tree "$TRASH_DIRECTORY" describe --broken >"$TRASH_DIRECTORY/out"
373 ) &&
374 test_when_finished "mv .git/modules/sub_moved .git/modules/sub1" &&
375 grep broken out
376'
377
378test_expect_success 'describe a blob at a directly tagged commit' '
379 echo "make it a unique blob" >file &&
380 git add file && git commit -m "content in file" &&
381 git tag -a -m "latest annotated tag" unique-file &&
382 git describe HEAD:file >actual &&
383 echo "unique-file:file" >expect &&
384 test_cmp expect actual
385'
386
387test_expect_success 'describe a blob with its first introduction' '
388 git commit --allow-empty -m "empty commit" &&
389 git rm file &&
390 git commit -m "delete blob" &&
391 git revert HEAD &&
392 git commit --allow-empty -m "empty commit" &&
393 git describe HEAD:file >actual &&
394 echo "unique-file:file" >expect &&
395 test_cmp expect actual
396'
397
398test_expect_success 'describe directly tagged blob' '
399 git tag test-blob unique-file:file &&
400 git describe test-blob >actual &&
401 echo "unique-file:file" >expect &&
402 # suboptimal: we rather want to see "test-blob"
403 test_cmp expect actual
404'
405
406test_expect_success 'describe tag object' '
407 git tag test-blob-1 -a -m msg unique-file:file &&
408 test_must_fail git describe test-blob-1 2>actual &&
409 test_grep "fatal: test-blob-1 is neither a commit nor blob" actual
410'
411
412test_expect_success 'describe an unreachable blob' '
413 blob=$(echo not-found-anywhere | git hash-object -w --stdin) &&
414 test_must_fail git describe $blob 2>actual &&
415 test_grep "blob .$blob. not reachable from HEAD" actual
416'
417
418test_expect_success 'describe blob on an unborn branch' '
419 oldbranch=$(git symbolic-ref HEAD) &&
420 test_when_finished "git symbolic-ref HEAD $oldbranch" &&
421 git symbolic-ref HEAD refs/heads/does-not-exist &&
422 test_must_fail git describe test-blob 2>actual &&
423 test_grep "cannot search .* on an unborn branch" actual
424'
425
426# This test creates a repository state that we generally try to disallow: HEAD
427# is pointing to an object that is not a commit. The ref update code forbids
428# non-commit writes directly to HEAD or to any branch in refs/heads/. But we
429# can use the loophole of pointing HEAD to another non-branch ref (something we
430# should forbid, but don't for historical reasons).
431#
432# Do not take this test as an endorsement of the loophole! If we ever tighten
433# it, it is reasonable to just drop this test entirely.
434test_expect_success 'describe blob on a non-commit HEAD' '
435 oldbranch=$(git symbolic-ref HEAD) &&
436 test_when_finished "git symbolic-ref HEAD $oldbranch" &&
437 git symbolic-ref HEAD refs/tags/test-blob &&
438 test_must_fail git describe test-blob 2>actual &&
439 test_grep "blob .* not reachable from HEAD" actual
440'
441
442test_expect_success ULIMIT_STACK_SIZE 'name-rev works in a deep repo' '
443 i=1 &&
444 while test $i -lt 8000
445 do
446 echo "commit refs/heads/main
447committer A U Thor <author@example.com> $((1000000000 + $i * 100)) +0200
448data <<EOF
449commit #$i
450EOF" &&
451 if test $i = 1
452 then
453 echo "from refs/heads/main^0"
454 fi &&
455 i=$(($i + 1)) || return 1
456 done | git fast-import &&
457 git checkout main &&
458 git tag far-far-away HEAD^ &&
459 echo "HEAD~4000 tags/far-far-away~3999" >expect &&
460 git name-rev HEAD~4000 >actual &&
461 test_cmp expect actual &&
462 run_with_limited_stack git name-rev HEAD~4000 >actual &&
463 test_cmp expect actual
464'
465
466test_expect_success ULIMIT_STACK_SIZE 'describe works in a deep repo' '
467 git tag -f far-far-away HEAD~7999 &&
468 echo "far-far-away" >expect &&
469 git describe --tags --abbrev=0 HEAD~4000 >actual &&
470 test_cmp expect actual &&
471 run_with_limited_stack git describe --tags --abbrev=0 HEAD~4000 >actual &&
472 test_cmp expect actual
473'
474
475check_describe tags/A --all A
476check_describe tags/c --all c
477check_describe heads/branch_A --all --match='branch_*' branch_A
478
479test_expect_success 'describe complains about tree object' '
480 test_must_fail git describe HEAD^{tree}
481'
482
483test_expect_success 'describe complains about missing object' '
484 test_must_fail git describe $ZERO_OID
485'
486
487test_expect_success 'name-rev a rev shortly after epoch' '
488 test_when_finished "git checkout main" &&
489
490 git checkout --orphan no-timestamp-underflow &&
491 # Any date closer to epoch than the CUTOFF_DATE_SLOP constant
492 # in builtin/name-rev.c.
493 GIT_COMMITTER_DATE="@1234 +0000" \
494 git commit -m "committer date shortly after epoch" &&
495 old_commit_oid=$(git rev-parse HEAD) &&
496
497 echo "$old_commit_oid no-timestamp-underflow" >expect &&
498 git name-rev $old_commit_oid >actual &&
499 test_cmp expect actual
500'
501
502# A--------------main
503# \ /
504# \----------M2
505# \ /
506# \---M1-C
507# \ /
508# B
509test_expect_success 'name-rev covers all conditions while looking at parents' '
510 git init repo &&
511 (
512 cd repo &&
513
514 echo A >file &&
515 git add file &&
516 git commit -m A &&
517 A=$(git rev-parse HEAD) &&
518
519 git checkout --detach &&
520 echo B >file &&
521 git commit -m B file &&
522 B=$(git rev-parse HEAD) &&
523
524 git checkout $A &&
525 git merge --no-ff $B && # M1
526
527 echo C >file &&
528 git commit -m C file &&
529
530 git checkout $A &&
531 git merge --no-ff HEAD@{1} && # M2
532
533 git checkout main &&
534 git merge --no-ff HEAD@{1} &&
535
536 echo "$B main^2^2~1^2" >expect &&
537 git name-rev $B >actual &&
538
539 test_cmp expect actual
540 )
541'
542
543# A-B-C-D-E-main
544#
545# Where C has a non-monotonically increasing commit timestamp w.r.t. other
546# commits
547test_expect_success 'non-monotonic commit dates setup' '
548 UNIX_EPOCH_ZERO="@0 +0000" &&
549 git init non-monotonic &&
550 test_commit -C non-monotonic A &&
551 test_commit -C non-monotonic --no-tag B &&
552 test_commit -C non-monotonic --no-tag --date "$UNIX_EPOCH_ZERO" C &&
553 test_commit -C non-monotonic D &&
554 test_commit -C non-monotonic E
555'
556
557test_expect_success 'name-rev with commitGraph handles non-monotonic timestamps' '
558 test_config -C non-monotonic core.commitGraph true &&
559 (
560 cd non-monotonic &&
561
562 git commit-graph write --reachable &&
563
564 echo "main~3 tags/D~2" >expect &&
565 git name-rev --tags main~3 >actual &&
566
567 test_cmp expect actual
568 )
569'
570
571test_expect_success 'name-rev --all works with non-monotonic timestamps' '
572 test_config -C non-monotonic core.commitGraph false &&
573 (
574 cd non-monotonic &&
575
576 rm -rf .git/info/commit-graph* &&
577
578 cat >tags <<-\EOF &&
579 tags/E
580 tags/D
581 tags/D~1
582 tags/D~2
583 tags/A
584 EOF
585
586 git log --pretty=%H >revs &&
587
588 paste -d" " revs tags | sort >expect &&
589
590 git name-rev --tags --all | sort >actual &&
591 test_cmp expect actual
592 )
593'
594
595test_expect_success 'name-rev --annotate-stdin works with non-monotonic timestamps' '
596 test_config -C non-monotonic core.commitGraph false &&
597 (
598 cd non-monotonic &&
599
600 rm -rf .git/info/commit-graph* &&
601
602 cat >expect <<-\EOF &&
603 E
604 D
605 D~1
606 D~2
607 A
608 EOF
609
610 git log --pretty=%H >revs &&
611 git name-rev --tags --annotate-stdin --name-only <revs >actual &&
612 test_cmp expect actual
613 )
614'
615
616test_expect_success 'name-rev --all works with commitGraph' '
617 test_config -C non-monotonic core.commitGraph true &&
618 (
619 cd non-monotonic &&
620
621 git commit-graph write --reachable &&
622
623 cat >tags <<-\EOF &&
624 tags/E
625 tags/D
626 tags/D~1
627 tags/D~2
628 tags/A
629 EOF
630
631 git log --pretty=%H >revs &&
632
633 paste -d" " revs tags | sort >expect &&
634
635 git name-rev --tags --all | sort >actual &&
636 test_cmp expect actual
637 )
638'
639
640test_expect_success 'name-rev --annotate-stdin works with commitGraph' '
641 test_config -C non-monotonic core.commitGraph true &&
642 (
643 cd non-monotonic &&
644
645 git commit-graph write --reachable &&
646
647 cat >expect <<-\EOF &&
648 E
649 D
650 D~1
651 D~2
652 A
653 EOF
654
655 git log --pretty=%H >revs &&
656 git name-rev --tags --annotate-stdin --name-only <revs >actual &&
657 test_cmp expect actual
658 )
659'
660
661# B
662# o
663# H \
664# o-----o---o----x
665# A
666#
667test_expect_success 'setup: describe commits with disjoint bases' '
668 git init disjoint1 &&
669 (
670 cd disjoint1 &&
671
672 echo o >> file && git add file && git commit -m o &&
673 git tag H -a -m H &&
674 echo A >> file && git add file && git commit -m A &&
675 git tag A -a -m A &&
676 echo o >> file && git add file && git commit -m o &&
677
678 git checkout --orphan branch && rm file &&
679 echo B > file2 && git add file2 && git commit -m B &&
680 git tag B -a -m B &&
681 git merge --no-ff --allow-unrelated-histories main -m x
682 )
683'
684
685check_describe -C disjoint1 "A-3-gHASH" HEAD
686check_describe -C disjoint1 --expect-failure "A-3-gHASH" --candidates=2 HEAD
687
688# H B
689# o---o---o------------.
690# \
691# o---o---x
692# A
693#
694test_expect_success 'setup: describe commits with disjoint bases 2' '
695 git init disjoint2 &&
696 (
697 cd disjoint2 &&
698
699 echo A >> file && git add file && GIT_COMMITTER_DATE="2020-01-01 18:00" git commit -m A &&
700 git tag A -a -m A &&
701 echo o >> file && git add file && GIT_COMMITTER_DATE="2020-01-01 18:01" git commit -m o &&
702
703 git checkout --orphan branch &&
704 echo o >> file2 && git add file2 && GIT_COMMITTER_DATE="2020-01-01 15:00" git commit -m o &&
705 echo o >> file2 && git add file2 && GIT_COMMITTER_DATE="2020-01-01 15:01" git commit -m o &&
706 git tag H -a -m H &&
707 echo B >> file2 && git add file2 && GIT_COMMITTER_DATE="2020-01-01 15:02" git commit -m B &&
708 git tag B -a -m B &&
709 git merge --no-ff --allow-unrelated-histories main -m x
710 )
711'
712
713check_describe -C disjoint2 "B-3-gHASH" HEAD
714check_describe -C disjoint2 --expect-failure "B-3-gHASH" --candidates=2 HEAD
715
716test_expect_success 'setup misleading taggerdates' '
717 GIT_COMMITTER_DATE="2006-12-12 12:31" git tag -a -m "another tag" newer-tag-older-commit unique-file~1
718'
719
720check_describe newer-tag-older-commit~1 --contains unique-file~2
721
722test_expect_success 'describe --dirty with a file with changed stat' '
723 test_when_finished "rm -fr stat-dirty" &&
724 git init stat-dirty &&
725 (
726 cd stat-dirty &&
727
728 echo A >file &&
729 git add file &&
730 git commit -m A &&
731 git tag A -a -m A &&
732 echo "A" >expect &&
733
734 test-tool chmtime -10 file &&
735 git describe --dirty >actual &&
736 test_cmp expect actual
737 )
738'
739
740test_expect_success 'describe --broken --dirty with a file with changed stat' '
741 test_when_finished "rm -fr stat-dirty" &&
742 git init stat-dirty &&
743 (
744 cd stat-dirty &&
745
746 echo A >file &&
747 git add file &&
748 git commit -m A &&
749 git tag A -a -m A &&
750 echo "A" >expect &&
751
752 test-tool chmtime -10 file &&
753 git describe --dirty --broken >actual &&
754 test_cmp expect actual
755 )
756'
757
758test_expect_success '--always with no refs falls back to commit hash' '
759 git rev-parse HEAD >expect &&
760 git describe --no-abbrev --always --match=no-such-tag >actual &&
761 test_cmp expect actual
762'
763
764test_expect_success '--exact-match does not show --always fallback' '
765 test_must_fail git describe --exact-match --always
766'
767
768test_expect_success 'avoid being fooled by describe-like filename' '
769 test_when_finished rm out &&
770
771 git rev-parse --short HEAD >out &&
772 FILENAME=filename-g$(cat out) &&
773 touch $FILENAME &&
774 git add $FILENAME &&
775 git commit -m "Add $FILENAME" &&
776
777 git cat-file -t HEAD:$FILENAME >actual &&
778
779 echo blob >expect &&
780 test_cmp expect actual
781'
782
783test_expect_success 'do not be fooled by invalid describe format ' '
784 test_when_finished rm out &&
785
786 git rev-parse --short HEAD >out &&
787 test_must_fail git cat-file -t "refs/tags/super-invalid/./../...../ ~^:/?*[////\\\\\\&}/busted.lock-42-g"$(cat out)
788'
789
790test_done