Sync with 2.38.5
[git.git] / t / t2010-checkout-ambiguous.sh
blob9d4b37526a326396fc334580350ff3cef3102b1e
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_PASSES_SANITIZE_LEAK=true
9 . ./test-lib.sh
11 test_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
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' '
30 echo bye > world &&
31 git checkout -- world &&
32 git diff --exit-code --quiet
35 test_expect_success 'non ambiguous call' '
36 git checkout all
39 test_expect_success 'allow the most common case' '
40 git checkout world &&
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' '
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
57 test_expect_success 'disambiguate checking out from a tree-ish' '
58 echo bye > world &&
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
69 test_done