Change unpack_trees' 'reset' flag into an enum
[alt-git.git] / t / t2010-checkout-ambiguous.sh
blob6e8757387d15fc88afbc55f41633361875a2fde3
1 #!/bin/sh
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-lib.sh
10 test_expect_success 'setup' '
11 echo hello >world &&
12 echo hello >all &&
13 git add all world &&
14 git commit -m initial &&
15 git branch world
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' '
29 echo bye > world &&
30 git checkout -- world &&
31 git diff --exit-code --quiet
34 test_expect_success 'non ambiguous call' '
35 git checkout all
38 test_expect_success 'allow the most common case' '
39 git checkout world &&
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' '
48 mkdir sub &&
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' '
57 echo bye > world &&
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
68 test_done