]> git.ipfire.org Git - thirdparty/git.git/blame - t/t2010-checkout-ambiguous.sh
tests: mark tests relying on the current default for `init.defaultBranch`
[thirdparty/git.git] / t / t2010-checkout-ambiguous.sh
CommitLineData
859fdaba
PH
1#!/bin/sh
2
3test_description='checkout and pathspecs/refspecs ambiguities'
4
334afbc7
JS
5GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master
6export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
859fdaba
PH
8. ./test-lib.sh
9
10test_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
18test_expect_success 'reference must be a tree' '
19 test_must_fail git checkout $(git hash-object ./all) --
20'
21
22test_expect_success 'branch switching' '
23 test "refs/heads/master" = "$(git symbolic-ref HEAD)" &&
24 git checkout world -- &&
25 test "refs/heads/world" = "$(git symbolic-ref HEAD)"
26'
27
28test_expect_success 'checkout world from the index' '
29 echo bye > world &&
30 git checkout -- world &&
31 git diff --exit-code --quiet
32'
33
34test_expect_success 'non ambiguous call' '
35 git checkout all
36'
37
38test_expect_success 'allow the most common case' '
39 git checkout world &&
40 test "refs/heads/world" = "$(git symbolic-ref HEAD)"
41'
42
43test_expect_success 'check ambiguity' '
44 test_must_fail git checkout world all
45'
46
b829b943
NTND
47test_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
56test_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
MM
62test_expect_success 'accurate error message with more than one ref' '
63 test_must_fail git checkout HEAD master -- 2>actual &&
1edbaac3 64 test_i18ngrep 2 actual &&
bca39695
MM
65 test_i18ngrep "one reference expected, 2 given" actual
66'
67
859fdaba 68test_done