]> git.ipfire.org Git - thirdparty/git.git/blame - t/t2010-checkout-ambiguous.sh
The third batch
[thirdparty/git.git] / t / t2010-checkout-ambiguous.sh
CommitLineData
859fdaba
PH
1#!/bin/sh
2
3test_description='checkout and pathspecs/refspecs ambiguities'
4
883b98ef 5GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
334afbc7
JS
6export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
9081a421 8TEST_PASSES_SANITIZE_LEAK=true
859fdaba
PH
9. ./test-lib.sh
10
11test_expect_success 'setup' '
12 echo hello >world &&
13 echo hello >all &&
14 git add all world &&
15 git commit -m initial &&
16 git branch world
17'
18
19test_expect_success 'reference must be a tree' '
20 test_must_fail git checkout $(git hash-object ./all) --
21'
22
23test_expect_success 'branch switching' '
883b98ef 24 test "refs/heads/main" = "$(git symbolic-ref HEAD)" &&
859fdaba
PH
25 git checkout world -- &&
26 test "refs/heads/world" = "$(git symbolic-ref HEAD)"
27'
28
29test_expect_success 'checkout world from the index' '
30 echo bye > world &&
31 git checkout -- world &&
32 git diff --exit-code --quiet
33'
34
35test_expect_success 'non ambiguous call' '
36 git checkout all
37'
38
39test_expect_success 'allow the most common case' '
40 git checkout world &&
41 test "refs/heads/world" = "$(git symbolic-ref HEAD)"
42'
43
44test_expect_success 'check ambiguity' '
45 test_must_fail git checkout world all
46'
47
b829b943
NTND
48test_expect_success 'check ambiguity in subdir' '
49 mkdir sub &&
50 # not ambiguous because sub/world does not exist
51 git -C sub checkout world ../all &&
52 echo hello >sub/world &&
53 # ambiguous because sub/world does exist
54 test_must_fail git -C sub checkout world ../all
55'
56
859fdaba
PH
57test_expect_success 'disambiguate checking out from a tree-ish' '
58 echo bye > world &&
59 git checkout world -- world &&
60 git diff --exit-code --quiet
61'
62
bca39695 63test_expect_success 'accurate error message with more than one ref' '
883b98ef 64 test_must_fail git checkout HEAD main -- 2>actual &&
6789275d
JH
65 test_grep 2 actual &&
66 test_grep "one reference expected, 2 given" actual
bca39695
MM
67'
68
859fdaba 69test_done