blob: c0e5b2a6275df2d92172327b2d629cc73720423e [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
Shawn O. Pearce03e8b542010-04-12 16:25:29 -070011 D,R e
Junio C Hamano5312ab12007-01-13 18:37:32 -080012'
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
Junio C Hamano024ab972009-10-23 11:42:39 -070037 git describe --always HEAD &&
38
Junio C Hamano5312ab12007-01-13 18:37:32 -080039 test_tick &&
Nanako Shiraishi3604e7c2008-09-03 17:59:29 +090040 echo two >file && git add file && git commit -m second &&
Junio C Hamano5be60072007-07-02 22:52:14 -070041 two=$(git rev-parse HEAD) &&
Junio C Hamano5312ab12007-01-13 18:37:32 -080042
43 test_tick &&
Nanako Shiraishi3604e7c2008-09-03 17:59:29 +090044 echo three >file && git add file && git commit -m third &&
Junio C Hamano5312ab12007-01-13 18:37:32 -080045
46 test_tick &&
Nanako Shiraishi3604e7c2008-09-03 17:59:29 +090047 echo A >file && git add file && git commit -m A &&
Junio C Hamano5312ab12007-01-13 18:37:32 -080048 test_tick &&
Nanako Shiraishi3604e7c2008-09-03 17:59:29 +090049 git tag -a -m A A &&
Junio C Hamano5312ab12007-01-13 18:37:32 -080050
51 test_tick &&
Nanako Shiraishi3604e7c2008-09-03 17:59:29 +090052 echo c >file && git add file && git commit -m c &&
Junio C Hamano5312ab12007-01-13 18:37:32 -080053 test_tick &&
Nanako Shiraishi3604e7c2008-09-03 17:59:29 +090054 git tag c &&
Junio C Hamano5312ab12007-01-13 18:37:32 -080055
56 git reset --hard $two &&
57 test_tick &&
Nanako Shiraishi3604e7c2008-09-03 17:59:29 +090058 echo B >side && git add side && git commit -m B &&
Junio C Hamano5312ab12007-01-13 18:37:32 -080059 test_tick &&
Nanako Shiraishi3604e7c2008-09-03 17:59:29 +090060 git tag -a -m B B &&
Junio C Hamano5312ab12007-01-13 18:37:32 -080061
62 test_tick &&
Nanako Shiraishi3604e7c2008-09-03 17:59:29 +090063 git merge -m Merged c &&
Junio C Hamano5be60072007-07-02 22:52:14 -070064 merged=$(git rev-parse HEAD) &&
Junio C Hamano5312ab12007-01-13 18:37:32 -080065
66 git reset --hard $two &&
67 test_tick &&
Nanako Shiraishi3604e7c2008-09-03 17:59:29 +090068 echo D >another && git add another && git commit -m D &&
Junio C Hamano5312ab12007-01-13 18:37:32 -080069 test_tick &&
Nanako Shiraishi3604e7c2008-09-03 17:59:29 +090070 git tag -a -m D D &&
Shawn O. Pearce03e8b542010-04-12 16:25:29 -070071 test_tick &&
72 git tag -a -m R R &&
Junio C Hamano5312ab12007-01-13 18:37:32 -080073
74 test_tick &&
75 echo DD >another && git commit -a -m another &&
76
77 test_tick &&
Nanako Shiraishi3604e7c2008-09-03 17:59:29 +090078 git tag e &&
Junio C Hamano5312ab12007-01-13 18:37:32 -080079
80 test_tick &&
81 echo DDD >another && git commit -a -m "yet another" &&
82
83 test_tick &&
Nanako Shiraishi3604e7c2008-09-03 17:59:29 +090084 git merge -m Merged $merged &&
Junio C Hamano5312ab12007-01-13 18:37:32 -080085
86 test_tick &&
Junio C Hamano5be60072007-07-02 22:52:14 -070087 echo X >file && echo X >side && git add file side &&
Nanako Shiraishi3604e7c2008-09-03 17:59:29 +090088 git commit -m x
Junio C Hamano5312ab12007-01-13 18:37:32 -080089
90'
91
92check_describe A-* HEAD
93check_describe A-* HEAD^
Shawn O. Pearce03e8b542010-04-12 16:25:29 -070094check_describe R-* HEAD^^
Junio C Hamano5312ab12007-01-13 18:37:32 -080095check_describe A-* HEAD^^2
96check_describe B HEAD^^2^
Shawn O. Pearce03e8b542010-04-12 16:25:29 -070097check_describe R-* HEAD^^^
Junio C Hamano5312ab12007-01-13 18:37:32 -080098
Shawn O. Pearce7e425c42008-10-13 07:39:46 -070099check_describe c-* --tags HEAD
100check_describe c-* --tags HEAD^
101check_describe e-* --tags HEAD^^
102check_describe c-* --tags HEAD^^2
Junio C Hamano5312ab12007-01-13 18:37:32 -0800103check_describe B --tags HEAD^^2^
Thomas Rast7a0d61b2009-11-18 14:32:26 +0100104check_describe e --tags HEAD^^^
105
106check_describe heads/master --all HEAD
107check_describe tags/c-* --all HEAD^
108check_describe tags/e --all HEAD^^^
Junio C Hamano5312ab12007-01-13 18:37:32 -0800109
Santi Béjar518120e2008-02-25 10:43:33 +0100110check_describe B-0-* --long HEAD^^2^
Junio C Hamano4d4c3e12008-03-03 18:29:51 -0800111check_describe A-3-* --long HEAD^^2
Santi Béjar518120e2008-02-25 10:43:33 +0100112
Mike Crowee00dd1e2013-05-17 21:56:18 +0100113check_describe c-7-* --tags
114check_describe e-3-* --first-parent --tags
115
Shawn O. Pearce81dc2232008-12-26 14:02:01 -0800116: >err.expect
117check_describe A --all A^0
118test_expect_success 'no warning was displayed for A' '
119 test_cmp err.expect err.actual
120'
121
Shawn O. Pearce3291fe42008-03-03 20:09:38 -0500122test_expect_success 'rename tag A to Q locally' '
123 mv .git/refs/tags/A .git/refs/tags/Q
124'
125cat - >err.expect <<EOF
126warning: tag 'A' is really 'Q' here
127EOF
128check_describe A-* HEAD
Junio C Hamanob3e19002011-04-12 16:33:39 -0700129test_expect_success 'warning was displayed for Q' '
130 test_i18ncmp err.expect err.actual
Shawn O. Pearce3291fe42008-03-03 20:09:38 -0500131'
132test_expect_success 'rename tag Q back to A' '
133 mv .git/refs/tags/Q .git/refs/tags/A
134'
135
Shawn O. Pearced1b28f52008-03-03 20:09:35 -0500136test_expect_success 'pack tag refs' 'git pack-refs'
137check_describe A-* HEAD
138
Jean Privat9f67d2e2009-10-21 09:35:22 -0400139check_describe "A-*[0-9a-f]" --dirty
140
141test_expect_success 'set-up dirty work tree' '
142 echo >>file
143'
144
145check_describe "A-*[0-9a-f]-dirty" --dirty
146
147check_describe "A-*[0-9a-f].mod" --dirty=.mod
148
149test_expect_success 'describe --dirty HEAD' '
150 test_must_fail git describe --dirty HEAD
151'
152
Michael Dressel4ed19a32008-06-04 21:06:31 +0200153test_expect_success 'set-up matching pattern tests' '
154 git tag -a -m test-annotated test-annotated &&
155 echo >>file &&
156 test_tick &&
157 git commit -a -m "one more" &&
158 git tag test1-lightweight &&
159 echo >>file &&
160 test_tick &&
161 git commit -a -m "yet another" &&
162 git tag test2-lightweight &&
163 echo >>file &&
164 test_tick &&
165 git commit -a -m "even more"
166
167'
168
169check_describe "test-annotated-*" --match="test-*"
170
171check_describe "test1-lightweight-*" --tags --match="test1-*"
172
173check_describe "test2-lightweight-*" --tags --match="test2-*"
174
Shawn O. Pearce14d46422008-07-03 02:32:45 +0000175check_describe "test2-lightweight-*" --long --tags --match="test2-*" HEAD^
176
Junio C Hamano118aa4a2013-07-18 14:11:35 -0700177test_expect_success 'name-rev with exact tags' '
178 echo A >expect &&
179 tag_object=$(git rev-parse refs/tags/A) &&
180 git name-rev --tags --name-only $tag_object >actual &&
181 test_cmp expect actual &&
182
183 echo "A^0" >expect &&
184 tagged_commit=$(git rev-parse "refs/tags/A^0") &&
185 git name-rev --tags --name-only $tagged_commit >actual &&
186 test_cmp expect actual
187'
188
Junio C Hamanoadfc1852013-07-18 14:46:51 -0700189test_expect_success 'describe --contains with the exact tags' '
190 echo "A^0" >expect &&
191 tag_object=$(git rev-parse refs/tags/A) &&
192 git describe --contains $tag_object >actual &&
193 test_cmp expect actual &&
194
195 echo "A^0" >expect &&
196 tagged_commit=$(git rev-parse "refs/tags/A^0") &&
197 git describe --contains $tagged_commit >actual &&
198 test_cmp expect actual
199'
200
Junio C Hamano5312ab12007-01-13 18:37:32 -0800201test_done