3 test_description
='test describe
6 .--------------o----o----o----x
8 o----o----o----o----o----. /
10 .------------o---o---o
18 R
=$
(git describe
"$@" 2>err.actual
)
21 test_expect_success
"describe $*" '
24 $expect) echo happy ;;
25 *) echo "Oops - $R is not $expect";
31 test_expect_success setup
'
34 echo one >file && git add file && git commit -m initial &&
35 one=$(git rev-parse HEAD) &&
37 git describe --always HEAD &&
40 echo two >file && git add file && git commit -m second &&
41 two=$(git rev-parse HEAD) &&
44 echo three >file && git add file && git commit -m third &&
47 echo A >file && git add file && git commit -m A &&
52 echo c >file && git add file && git commit -m c &&
56 git reset --hard $two &&
58 echo B >side && git add side && git commit -m B &&
63 git merge -m Merged c &&
64 merged=$(git rev-parse HEAD) &&
66 git reset --hard $two &&
68 echo D >another && git add another && git commit -m D &&
75 echo DD >another && git commit -a -m another &&
81 echo DDD >another && git commit -a -m "yet another" &&
84 git merge -m Merged $merged &&
87 echo X >file && echo X >side && git add file side &&
92 check_describe A-
* HEAD
93 check_describe A-
* HEAD^
94 check_describe R-
* HEAD^^
95 check_describe A-
* HEAD^^
2
96 check_describe B HEAD^^
2^
97 check_describe R-
* HEAD^^^
99 check_describe c-
* --tags HEAD
100 check_describe c-
* --tags HEAD^
101 check_describe e-
* --tags HEAD^^
102 check_describe c-
* --tags HEAD^^
2
103 check_describe B
--tags HEAD^^
2^
104 check_describe e
--tags HEAD^^^
106 check_describe
heads
/master
--all HEAD
107 check_describe tags
/c-
* --all HEAD^
108 check_describe tags
/e
--all HEAD^^^
110 check_describe B-0-
* --long HEAD^^
2^
111 check_describe A-3-
* --long HEAD^^
2
113 check_describe c-7-
* --tags
114 check_describe e-3-
* --first-parent --tags
116 test_expect_success
'describe --contains defaults to HEAD without commit-ish' '
117 echo "A^0" >expect &&
119 test_when_finished "git checkout -" &&
120 git describe --contains >actual &&
121 test_cmp expect actual
125 check_describe tags
/A
--all A^
0
126 test_expect_success
'no warning was displayed for A' '
127 test_cmp err.expect err.actual
130 test_expect_success
'rename tag A to Q locally' '
131 mv .git/refs/tags/A .git/refs/tags/Q
133 cat - >err.expect
<<EOF
134 warning: tag 'A' is really 'Q' here
136 check_describe A-
* HEAD
137 test_expect_success
'warning was displayed for Q' '
138 test_i18ncmp err.expect err.actual
140 test_expect_success
'rename tag Q back to A' '
141 mv .git/refs/tags/Q .git/refs/tags/A
144 test_expect_success
'pack tag refs' 'git pack-refs'
145 check_describe A-
* HEAD
147 test_expect_success
'describe works from outside repo using --git-dir' '
148 git clone --bare "$TRASH_DIRECTORY" "$TRASH_DIRECTORY/bare" &&
149 git --git-dir "$TRASH_DIRECTORY/bare" describe >out &&
150 grep "^A-[1-9][0-9]\?-g[0-9a-f]\+$" out
153 check_describe
"A-*[0-9a-f]" --dirty
155 test_expect_success
'describe --dirty with --work-tree' '
157 cd "$TEST_DIRECTORY" &&
158 git --git-dir "$TRASH_DIRECTORY/.git" --work-tree "$TRASH_DIRECTORY" describe --dirty >"$TRASH_DIRECTORY/out"
160 grep "^A-[1-9][0-9]\?-g[0-9a-f]\+$" out
163 test_expect_success
'set-up dirty work tree' '
167 check_describe
"A-*[0-9a-f]-dirty" --dirty
169 test_expect_success
'describe --dirty with --work-tree (dirty)' '
171 cd "$TEST_DIRECTORY" &&
172 git --git-dir "$TRASH_DIRECTORY/.git" --work-tree "$TRASH_DIRECTORY" describe --dirty >"$TRASH_DIRECTORY/out"
174 grep "^A-[1-9][0-9]\?-g[0-9a-f]\+-dirty$" out
177 check_describe
"A-*[0-9a-f].mod" --dirty=.mod
179 test_expect_success
'describe --dirty=.mod with --work-tree (dirty)' '
181 cd "$TEST_DIRECTORY" &&
182 git --git-dir "$TRASH_DIRECTORY/.git" --work-tree "$TRASH_DIRECTORY" describe --dirty=.mod >"$TRASH_DIRECTORY/out"
184 grep "^A-[1-9][0-9]\?-g[0-9a-f]\+.mod$" out
187 test_expect_success
'describe --dirty HEAD' '
188 test_must_fail git describe --dirty HEAD
191 test_expect_success
'set-up matching pattern tests' '
192 git tag -a -m test-annotated test-annotated &&
195 git commit -a -m "one more" &&
196 git tag test1-lightweight &&
199 git commit -a -m "yet another" &&
200 git tag test2-lightweight &&
203 git commit -a -m "even more"
207 check_describe
"test-annotated-*" --match="test-*"
209 check_describe
"test1-lightweight-*" --tags --match="test1-*"
211 check_describe
"test2-lightweight-*" --tags --match="test2-*"
213 check_describe
"test2-lightweight-*" --long --tags --match="test2-*" HEAD^
215 check_describe
"test2-lightweight-*" --long --tags --match="test1-*" --match="test2-*" HEAD^
217 check_describe
"test2-lightweight-*" --long --tags --match="test1-*" --no-match --match="test2-*" HEAD^
219 check_describe
"test1-lightweight-*" --long --tags --match="test1-*" --match="test3-*" HEAD
221 check_describe
"test1-lightweight-*" --long --tags --match="test3-*" --match="test1-*" HEAD
223 test_expect_success
'set-up branches' '
224 git branch branch_A A &&
225 git branch branch_C c &&
226 git update-ref refs/remotes/origin/remote_branch_A "A^{commit}" &&
227 git update-ref refs/remotes/origin/remote_branch_C "c^{commit}" &&
228 git update-ref refs/original/original_branch_A test-annotated~2
231 check_describe
"heads/branch_A*" --all --match="branch_*" --exclude="branch_C" HEAD
233 check_describe
"remotes/origin/remote_branch_A*" --all --match="origin/remote_branch_*" --exclude="origin/remote_branch_C" HEAD
235 check_describe
"original/original_branch_A*" --all test-annotated~
1
237 test_expect_success
'--match does not work for other types' '
238 test_must_fail git describe --all --match="*original_branch_*" test-annotated~1
241 test_expect_success
'--exclude does not work for other types' '
242 R=$(git describe --all --exclude="any_pattern_even_not_matching" test-annotated~1) &&
244 *original_branch_A*) echo "fail: Found unknown reference $R with --exclude"
246 *) echo ok: Found some known type;;
250 test_expect_success
'name-rev with exact tags' '
252 tag_object=$(git rev-parse refs/tags/A) &&
253 git name-rev --tags --name-only $tag_object >actual &&
254 test_cmp expect actual &&
256 echo "A^0" >expect &&
257 tagged_commit=$(git rev-parse "refs/tags/A^0") &&
258 git name-rev --tags --name-only $tagged_commit >actual &&
259 test_cmp expect actual
262 test_expect_success
'name-rev --all' '
264 for rev in $(git rev-list --all)
266 git name-rev $rev >>expect.unsorted
268 sort <expect.unsorted >expect &&
269 git name-rev --all >actual.unsorted &&
270 sort <actual.unsorted >actual &&
271 test_cmp expect actual
274 test_expect_success
'name-rev --stdin' '
276 for rev in $(git rev-list --all)
278 name=$(git name-rev --name-only $rev) &&
279 echo "$rev ($name)" >>expect.unsorted
281 sort <expect.unsorted >expect &&
282 git rev-list --all | git name-rev --stdin >actual.unsorted &&
283 sort <actual.unsorted >actual &&
284 test_cmp expect actual
287 test_expect_success
'describe --contains with the exact tags' '
288 echo "A^0" >expect &&
289 tag_object=$(git rev-parse refs/tags/A) &&
290 git describe --contains $tag_object >actual &&
291 test_cmp expect actual &&
293 echo "A^0" >expect &&
294 tagged_commit=$(git rev-parse "refs/tags/A^0") &&
295 git describe --contains $tagged_commit >actual &&
296 test_cmp expect actual
299 test_expect_success
'describe --contains and --match' '
300 echo "A^0" >expect &&
301 tagged_commit=$(git rev-parse "refs/tags/A^0") &&
302 test_must_fail git describe --contains --match="B" $tagged_commit &&
303 git describe --contains --match="B" --match="A" $tagged_commit >actual &&
304 test_cmp expect actual
307 test_expect_success
'describe --exclude' '
308 echo "c~1" >expect &&
309 tagged_commit=$(git rev-parse "refs/tags/A^0") &&
310 test_must_fail git describe --contains --match="B" $tagged_commit &&
311 git describe --contains --match="?" --exclude="A" $tagged_commit >actual &&
312 test_cmp expect actual
315 test_expect_success
'describe --contains and --no-match' '
316 echo "A^0" >expect &&
317 tagged_commit=$(git rev-parse "refs/tags/A^0") &&
318 git describe --contains --match="B" --no-match $tagged_commit >actual &&
319 test_cmp expect actual
322 test_expect_success
'setup and absorb a submodule' '
323 test_create_repo sub1 &&
324 test_commit -C sub1 initial &&
325 git submodule add ./sub1 &&
326 git submodule absorbgitdirs &&
327 git commit -a -m "add submodule" &&
328 git describe --dirty >expect &&
329 git describe --broken >out &&
333 test_expect_success
'describe chokes on severely broken submodules' '
334 mv .git/modules/sub1/ .git/modules/sub_moved &&
335 test_must_fail git describe --dirty
338 test_expect_success
'describe ignoring a broken submodule' '
339 git describe --broken >out &&
343 test_expect_success
'describe with --work-tree ignoring a broken submodule' '
345 cd "$TEST_DIRECTORY" &&
346 git --git-dir "$TRASH_DIRECTORY/.git" --work-tree "$TRASH_DIRECTORY" describe --broken >"$TRASH_DIRECTORY/out"
348 test_when_finished "mv .git/modules/sub_moved .git/modules/sub1" &&
352 test_expect_success
'describe a blob at a directly tagged commit' '
353 echo "make it a unique blob" >file &&
354 git add file && git commit -m "content in file" &&
355 git tag -a -m "latest annotated tag" unique-file &&
356 git describe HEAD:file >actual &&
357 echo "unique-file:file" >expect &&
358 test_cmp expect actual
361 test_expect_success
'describe a blob with its first introduction' '
362 git commit --allow-empty -m "empty commit" &&
364 git commit -m "delete blob" &&
366 git commit --allow-empty -m "empty commit" &&
367 git describe HEAD:file >actual &&
368 echo "unique-file:file" >expect &&
369 test_cmp expect actual
372 test_expect_success
'describe directly tagged blob' '
373 git tag test-blob unique-file:file &&
374 git describe test-blob >actual &&
375 echo "unique-file:file" >expect &&
376 # suboptimal: we rather want to see "test-blob"
377 test_cmp expect actual
380 test_expect_success
'describe tag object' '
381 git tag test-blob-1 -a -m msg unique-file:file &&
382 test_must_fail git describe test-blob-1 2>actual &&
383 test_i18ngrep "fatal: test-blob-1 is neither a commit nor blob" actual
386 test_expect_failure ULIMIT_STACK_SIZE
'name-rev works in a deep repo' '
388 while test $i -lt 8000
390 echo "commit refs/heads/master
391 committer A U Thor <author@example.com> $((1000000000 + $i * 100)) +0200
395 test $i = 1 && echo "from refs/heads/master^0"
397 done | git fast-import &&
398 git checkout master &&
399 git tag far-far-away HEAD^ &&
400 echo "HEAD~4000 tags/far-far-away~3999" >expect &&
401 git name-rev HEAD~4000 >actual &&
402 test_cmp expect actual &&
403 run_with_limited_stack git name-rev HEAD~4000 >actual &&
404 test_cmp expect actual
407 test_expect_success ULIMIT_STACK_SIZE
'describe works in a deep repo' '
408 git tag -f far-far-away HEAD~7999 &&
409 echo "far-far-away" >expect &&
410 git describe --tags --abbrev=0 HEAD~4000 >actual &&
411 test_cmp expect actual &&
412 run_with_limited_stack git describe --tags --abbrev=0 HEAD~4000 >actual &&
413 test_cmp expect actual
416 check_describe tags
/A
--all A
417 check_describe tags
/c
--all c
418 check_describe
heads
/branch_A
--all --match='branch_*' branch_A
420 test_expect_success
'describe complains about tree object' '
421 test_must_fail git describe HEAD^{tree}
424 test_expect_success
'describe complains about missing object' '
425 test_must_fail git describe $ZERO_OID