]> git.ipfire.org Git - thirdparty/git.git/blob - t/t2010-checkout-ambiguous.sh
git-add.txt: add missing short option -A to synopsis
[thirdparty/git.git] / t / t2010-checkout-ambiguous.sh
1 #!/bin/sh
2
3 test_description='checkout and pathspecs/refspecs ambiguities'
4
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
8 TEST_PASSES_SANITIZE_LEAK=true
9 . ./test-lib.sh
10
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
17 '
18
19 test_expect_success 'reference must be a tree' '
20 test_must_fail git checkout $(git hash-object ./all) --
21 '
22
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)"
27 '
28
29 test_expect_success 'checkout world from the index' '
30 echo bye > world &&
31 git checkout -- world &&
32 git diff --exit-code --quiet
33 '
34
35 test_expect_success 'non ambiguous call' '
36 git checkout all
37 '
38
39 test_expect_success 'allow the most common case' '
40 git checkout world &&
41 test "refs/heads/world" = "$(git symbolic-ref HEAD)"
42 '
43
44 test_expect_success 'check ambiguity' '
45 test_must_fail git checkout world all
46 '
47
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
55 '
56
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
61 '
62
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
67 '
68
69 test_done