]>
Commit | Line | Data |
---|---|---|
859fdaba PH |
1 | #!/bin/sh |
2 | ||
3 | test_description='checkout and pathspecs/refspecs ambiguities' | |
4 | ||
883b98ef | 5 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
334afbc7 JS |
6 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
7 | ||
859fdaba PH |
8 | . ./test-lib.sh |
9 | ||
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 | |
16 | ' | |
17 | ||
18 | test_expect_success 'reference must be a tree' ' | |
19 | test_must_fail git checkout $(git hash-object ./all) -- | |
20 | ' | |
21 | ||
22 | test_expect_success 'branch switching' ' | |
883b98ef | 23 | test "refs/heads/main" = "$(git symbolic-ref HEAD)" && |
859fdaba PH |
24 | git checkout world -- && |
25 | test "refs/heads/world" = "$(git symbolic-ref HEAD)" | |
26 | ' | |
27 | ||
28 | test_expect_success 'checkout world from the index' ' | |
29 | echo bye > world && | |
30 | git checkout -- world && | |
31 | git diff --exit-code --quiet | |
32 | ' | |
33 | ||
34 | test_expect_success 'non ambiguous call' ' | |
35 | git checkout all | |
36 | ' | |
37 | ||
38 | test_expect_success 'allow the most common case' ' | |
39 | git checkout world && | |
40 | test "refs/heads/world" = "$(git symbolic-ref HEAD)" | |
41 | ' | |
42 | ||
43 | test_expect_success 'check ambiguity' ' | |
44 | test_must_fail git checkout world all | |
45 | ' | |
46 | ||
b829b943 NTND |
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 | |
54 | ' | |
55 | ||
859fdaba PH |
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 | |
60 | ' | |
61 | ||
bca39695 | 62 | test_expect_success 'accurate error message with more than one ref' ' |
883b98ef | 63 | test_must_fail git checkout HEAD main -- 2>actual && |
1edbaac3 | 64 | test_i18ngrep 2 actual && |
bca39695 MM |
65 | test_i18ngrep "one reference expected, 2 given" actual |
66 | ' | |
67 | ||
859fdaba | 68 | test_done |