3 test_description='checkout and pathspecs/refspecs ambiguities'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
10 test_expect_success 'setup' '
14 git commit -m initial &&
18 test_expect_success 'reference must be a tree' '
19 test_must_fail git checkout $(git hash-object ./all) --
22 test_expect_success 'branch switching' '
23 test "refs/heads/main" = "$(git symbolic-ref HEAD)" &&
24 git checkout world -- &&
25 test "refs/heads/world" = "$(git symbolic-ref HEAD)"
28 test_expect_success 'checkout world from the index' '
30 git checkout -- world &&
31 git diff --exit-code --quiet
34 test_expect_success 'non ambiguous call' '
38 test_expect_success 'allow the most common case' '
40 test "refs/heads/world" = "$(git symbolic-ref HEAD)"
43 test_expect_success 'check ambiguity' '
44 test_must_fail git checkout world all
47 test_expect_success 'check ambiguity in subdir' '
49 # not ambiguous because sub/world does not exist
50 git -C sub checkout world ../all &&
51 echo hello >sub/world &&
52 # ambiguous because sub/world does exist
53 test_must_fail git -C sub checkout world ../all
56 test_expect_success 'disambiguate checking out from a tree-ish' '
58 git checkout world -- world &&
59 git diff --exit-code --quiet
62 test_expect_success 'accurate error message with more than one ref' '
63 test_must_fail git checkout HEAD main -- 2>actual &&
64 test_i18ngrep 2 actual &&
65 test_i18ngrep "one reference expected, 2 given" actual