blob: c67261e2b68a9d330dc14c92783a485b0f605601 [file] [log] [blame]
Junio C Hamano0cb6ad32011-01-11 15:00:38 -05001#!/bin/sh
2
3test_description='checkout handling of ambiguous (branch/tag) refs'
Ævar Arnfjörð Bjarmason9081a422021-11-16 19:27:38 +01004
5TEST_PASSES_SANITIZE_LEAK=true
Junio C Hamano0cb6ad32011-01-11 15:00:38 -05006. ./test-lib.sh
7
8test_expect_success 'setup ambiguous refs' '
9 test_commit branch file &&
10 git branch ambiguity &&
11 git branch vagueness &&
12 test_commit tag file &&
13 git tag ambiguity &&
14 git tag vagueness HEAD:file &&
15 test_commit other file
16'
17
18test_expect_success 'checkout ambiguous ref succeeds' '
Andrei Rybaka5855fd2023-04-17 21:10:44 +020019 git checkout ambiguity 2>stderr
Junio C Hamano0cb6ad32011-01-11 15:00:38 -050020'
21
22test_expect_success 'checkout produces ambiguity warning' '
23 grep "warning.*ambiguous" stderr
24'
25
26test_expect_success 'checkout chooses branch over tag' '
27 echo refs/heads/ambiguity >expect &&
28 git symbolic-ref HEAD >actual &&
29 test_cmp expect actual &&
30 echo branch >expect &&
31 test_cmp expect file
32'
33
Junio C Hamanod3bd0422011-04-12 16:12:47 -070034test_expect_success 'checkout reports switch to branch' '
Junio C Hamano67892752023-10-31 14:23:30 +090035 test_grep "Switched to branch" stderr &&
36 test_grep ! "^HEAD is now at" stderr
Junio C Hamano0cb6ad32011-01-11 15:00:38 -050037'
38
39test_expect_success 'checkout vague ref succeeds' '
Andrei Rybaka5855fd2023-04-17 21:10:44 +020040 git checkout vagueness 2>stderr &&
Junio C Hamano0cb6ad32011-01-11 15:00:38 -050041 test_set_prereq VAGUENESS_SUCCESS
42'
43
44test_expect_success VAGUENESS_SUCCESS 'checkout produces ambiguity warning' '
45 grep "warning.*ambiguous" stderr
46'
47
48test_expect_success VAGUENESS_SUCCESS 'checkout chooses branch over tag' '
49 echo refs/heads/vagueness >expect &&
50 git symbolic-ref HEAD >actual &&
51 test_cmp expect actual &&
52 echo branch >expect &&
53 test_cmp expect file
54'
55
Junio C Hamanod3bd0422011-04-12 16:12:47 -070056test_expect_success VAGUENESS_SUCCESS 'checkout reports switch to branch' '
Junio C Hamano67892752023-10-31 14:23:30 +090057 test_grep "Switched to branch" stderr &&
58 test_grep ! "^HEAD is now at" stderr
Junio C Hamano0cb6ad32011-01-11 15:00:38 -050059'
60
Junio C Hamano0cb6ad32011-01-11 15:00:38 -050061test_done