3 test_description
='checkout and pathspecs/refspecs ambiguities'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
8 TEST_PASSES_SANITIZE_LEAK
=true
11 test_expect_success
'setup' '
15 git commit -m initial &&
19 test_expect_success
'reference must be a tree' '
20 test_must_fail git checkout $(git hash-object ./all) --
23 test_expect_success
'branch switching' '
24 test "refs/heads/main" = "$(git symbolic-ref HEAD)" &&
25 git checkout world -- &&
26 test "refs/heads/world" = "$(git symbolic-ref HEAD)"
29 test_expect_success
'checkout world from the index' '
31 git checkout -- world &&
32 git diff --exit-code --quiet
35 test_expect_success
'non ambiguous call' '
39 test_expect_success
'allow the most common case' '
41 test "refs/heads/world" = "$(git symbolic-ref HEAD)"
44 test_expect_success
'check ambiguity' '
45 test_must_fail git checkout world all
48 test_expect_success
'check ambiguity in subdir' '
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
57 test_expect_success
'disambiguate checking out from a tree-ish' '
59 git checkout world -- world &&
60 git diff --exit-code --quiet
63 test_expect_success
'accurate error message with more than one ref' '
64 test_must_fail git checkout HEAD main -- 2>actual &&
65 test_i18ngrep 2 actual &&
66 test_i18ngrep "one reference expected, 2 given" actual