blob: e6c9e59b617f4eaaa1148ed29b4ca92116bdf0c2 [file] [log] [blame]
Junio C Hamano5312ab12007-01-13 18:37:32 -08001#!/bin/sh
2
3test_description='test describe
4
5 B
6 .--------------o----o----o----x
7 / / /
8 o----o----o----o----o----. /
9 \ A c /
10 .------------o---o---o
11 D e
12'
13. ./test-lib.sh
14
15check_describe () {
16 expect="$1"
17 shift
Shawn O. Pearce3291fe42008-03-03 20:09:38 -050018 R=$(git describe "$@" 2>err.actual)
Shawn O. Pearcebe7bae02008-03-03 20:09:31 -050019 S=$?
Shawn O. Pearce3291fe42008-03-03 20:09:38 -050020 cat err.actual >&3
Junio C Hamano5312ab12007-01-13 18:37:32 -080021 test_expect_success "describe $*" '
Shawn O. Pearcebe7bae02008-03-03 20:09:31 -050022 test $S = 0 &&
Junio C Hamano5312ab12007-01-13 18:37:32 -080023 case "$R" in
24 $expect) echo happy ;;
25 *) echo "Oops - $R is not $expect";
26 false ;;
27 esac
28 '
29}
30
31test_expect_success setup '
32
33 test_tick &&
Nanako Shiraishi3604e7c2008-09-03 17:59:29 +090034 echo one >file && git add file && git commit -m initial &&
Junio C Hamano5be60072007-07-02 22:52:14 -070035 one=$(git rev-parse HEAD) &&
Junio C Hamano5312ab12007-01-13 18:37:32 -080036
37 test_tick &&
Nanako Shiraishi3604e7c2008-09-03 17:59:29 +090038 echo two >file && git add file && git commit -m second &&
Junio C Hamano5be60072007-07-02 22:52:14 -070039 two=$(git rev-parse HEAD) &&
Junio C Hamano5312ab12007-01-13 18:37:32 -080040
41 test_tick &&
Nanako Shiraishi3604e7c2008-09-03 17:59:29 +090042 echo three >file && git add file && git commit -m third &&
Junio C Hamano5312ab12007-01-13 18:37:32 -080043
44 test_tick &&
Nanako Shiraishi3604e7c2008-09-03 17:59:29 +090045 echo A >file && git add file && git commit -m A &&
Junio C Hamano5312ab12007-01-13 18:37:32 -080046 test_tick &&
Nanako Shiraishi3604e7c2008-09-03 17:59:29 +090047 git tag -a -m A A &&
Junio C Hamano5312ab12007-01-13 18:37:32 -080048
49 test_tick &&
Nanako Shiraishi3604e7c2008-09-03 17:59:29 +090050 echo c >file && git add file && git commit -m c &&
Junio C Hamano5312ab12007-01-13 18:37:32 -080051 test_tick &&
Nanako Shiraishi3604e7c2008-09-03 17:59:29 +090052 git tag c &&
Junio C Hamano5312ab12007-01-13 18:37:32 -080053
54 git reset --hard $two &&
55 test_tick &&
Nanako Shiraishi3604e7c2008-09-03 17:59:29 +090056 echo B >side && git add side && git commit -m B &&
Junio C Hamano5312ab12007-01-13 18:37:32 -080057 test_tick &&
Nanako Shiraishi3604e7c2008-09-03 17:59:29 +090058 git tag -a -m B B &&
Junio C Hamano5312ab12007-01-13 18:37:32 -080059
60 test_tick &&
Nanako Shiraishi3604e7c2008-09-03 17:59:29 +090061 git merge -m Merged c &&
Junio C Hamano5be60072007-07-02 22:52:14 -070062 merged=$(git rev-parse HEAD) &&
Junio C Hamano5312ab12007-01-13 18:37:32 -080063
64 git reset --hard $two &&
65 test_tick &&
Nanako Shiraishi3604e7c2008-09-03 17:59:29 +090066 echo D >another && git add another && git commit -m D &&
Junio C Hamano5312ab12007-01-13 18:37:32 -080067 test_tick &&
Nanako Shiraishi3604e7c2008-09-03 17:59:29 +090068 git tag -a -m D D &&
Junio C Hamano5312ab12007-01-13 18:37:32 -080069
70 test_tick &&
71 echo DD >another && git commit -a -m another &&
72
73 test_tick &&
Nanako Shiraishi3604e7c2008-09-03 17:59:29 +090074 git tag e &&
Junio C Hamano5312ab12007-01-13 18:37:32 -080075
76 test_tick &&
77 echo DDD >another && git commit -a -m "yet another" &&
78
79 test_tick &&
Nanako Shiraishi3604e7c2008-09-03 17:59:29 +090080 git merge -m Merged $merged &&
Junio C Hamano5312ab12007-01-13 18:37:32 -080081
82 test_tick &&
Junio C Hamano5be60072007-07-02 22:52:14 -070083 echo X >file && echo X >side && git add file side &&
Nanako Shiraishi3604e7c2008-09-03 17:59:29 +090084 git commit -m x
Junio C Hamano5312ab12007-01-13 18:37:32 -080085
86'
87
88check_describe A-* HEAD
89check_describe A-* HEAD^
90check_describe D-* HEAD^^
91check_describe A-* HEAD^^2
92check_describe B HEAD^^2^
93
Shawn O. Pearce7e425c42008-10-13 07:39:46 -070094check_describe c-* --tags HEAD
95check_describe c-* --tags HEAD^
96check_describe e-* --tags HEAD^^
97check_describe c-* --tags HEAD^^2
Junio C Hamano5312ab12007-01-13 18:37:32 -080098check_describe B --tags HEAD^^2^
99
Santi Béjar518120e2008-02-25 10:43:33 +0100100check_describe B-0-* --long HEAD^^2^
Junio C Hamano4d4c3e12008-03-03 18:29:51 -0800101check_describe A-3-* --long HEAD^^2
Santi Béjar518120e2008-02-25 10:43:33 +0100102
Shawn O. Pearce3291fe42008-03-03 20:09:38 -0500103test_expect_success 'rename tag A to Q locally' '
104 mv .git/refs/tags/A .git/refs/tags/Q
105'
106cat - >err.expect <<EOF
107warning: tag 'A' is really 'Q' here
108EOF
109check_describe A-* HEAD
110test_expect_success 'warning was displayed for Q' '
Junio C Hamano3af82862008-05-23 22:28:56 -0700111 test_cmp err.expect err.actual
Shawn O. Pearce3291fe42008-03-03 20:09:38 -0500112'
113test_expect_success 'rename tag Q back to A' '
114 mv .git/refs/tags/Q .git/refs/tags/A
115'
116
Shawn O. Pearced1b28f52008-03-03 20:09:35 -0500117test_expect_success 'pack tag refs' 'git pack-refs'
118check_describe A-* HEAD
119
Michael Dressel4ed19a32008-06-04 21:06:31 +0200120test_expect_success 'set-up matching pattern tests' '
121 git tag -a -m test-annotated test-annotated &&
122 echo >>file &&
123 test_tick &&
124 git commit -a -m "one more" &&
125 git tag test1-lightweight &&
126 echo >>file &&
127 test_tick &&
128 git commit -a -m "yet another" &&
129 git tag test2-lightweight &&
130 echo >>file &&
131 test_tick &&
132 git commit -a -m "even more"
133
134'
135
136check_describe "test-annotated-*" --match="test-*"
137
138check_describe "test1-lightweight-*" --tags --match="test1-*"
139
140check_describe "test2-lightweight-*" --tags --match="test2-*"
141
Shawn O. Pearce14d46422008-07-03 02:32:45 +0000142check_describe "test2-lightweight-*" --long --tags --match="test2-*" HEAD^
143
Junio C Hamano5312ab12007-01-13 18:37:32 -0800144test_done