]>
Commit | Line | Data |
---|---|---|
859fdaba PH |
1 | #!/bin/sh |
2 | ||
3 | test_description='checkout and pathspecs/refspecs ambiguities' | |
4 | ||
5 | . ./test-lib.sh | |
6 | ||
7 | test_expect_success 'setup' ' | |
8 | echo hello >world && | |
9 | echo hello >all && | |
10 | git add all world && | |
11 | git commit -m initial && | |
12 | git branch world | |
13 | ' | |
14 | ||
15 | test_expect_success 'reference must be a tree' ' | |
16 | test_must_fail git checkout $(git hash-object ./all) -- | |
17 | ' | |
18 | ||
19 | test_expect_success 'branch switching' ' | |
20 | test "refs/heads/master" = "$(git symbolic-ref HEAD)" && | |
21 | git checkout world -- && | |
22 | test "refs/heads/world" = "$(git symbolic-ref HEAD)" | |
23 | ' | |
24 | ||
25 | test_expect_success 'checkout world from the index' ' | |
26 | echo bye > world && | |
27 | git checkout -- world && | |
28 | git diff --exit-code --quiet | |
29 | ' | |
30 | ||
31 | test_expect_success 'non ambiguous call' ' | |
32 | git checkout all | |
33 | ' | |
34 | ||
35 | test_expect_success 'allow the most common case' ' | |
36 | git checkout world && | |
37 | test "refs/heads/world" = "$(git symbolic-ref HEAD)" | |
38 | ' | |
39 | ||
40 | test_expect_success 'check ambiguity' ' | |
41 | test_must_fail git checkout world all | |
42 | ' | |
43 | ||
b829b943 NTND |
44 | test_expect_success 'check ambiguity in subdir' ' |
45 | mkdir sub && | |
46 | # not ambiguous because sub/world does not exist | |
47 | git -C sub checkout world ../all && | |
48 | echo hello >sub/world && | |
49 | # ambiguous because sub/world does exist | |
50 | test_must_fail git -C sub checkout world ../all | |
51 | ' | |
52 | ||
859fdaba PH |
53 | test_expect_success 'disambiguate checking out from a tree-ish' ' |
54 | echo bye > world && | |
55 | git checkout world -- world && | |
56 | git diff --exit-code --quiet | |
57 | ' | |
58 | ||
bca39695 MM |
59 | test_expect_success 'accurate error message with more than one ref' ' |
60 | test_must_fail git checkout HEAD master -- 2>actual && | |
1edbaac3 | 61 | test_i18ngrep 2 actual && |
bca39695 MM |
62 | test_i18ngrep "one reference expected, 2 given" actual |
63 | ' | |
64 | ||
859fdaba | 65 | test_done |