dir: fix treatment of negated pathspecs
[git/raj.git] / t / t2060-switch.sh
blobf9efa29dfb8c7ad762fc502d883db2aaa3f114a2
1 #!/bin/sh
3 test_description='switch basic functionality'
5 . ./test-lib.sh
7 test_expect_success 'setup' '
8 test_commit first &&
9 git branch first-branch &&
10 test_commit second &&
11 test_commit third &&
12 git remote add origin nohost:/nopath &&
13 git update-ref refs/remotes/origin/foo first-branch
16 test_expect_success 'switch branch no arguments' '
17 test_must_fail git switch
20 test_expect_success 'switch branch' '
21 git switch first-branch &&
22 test_path_is_missing second.t
25 test_expect_success 'switch and detach' '
26 test_when_finished git switch master &&
27 test_must_fail git switch master^{commit} &&
28 git switch --detach master^{commit} &&
29 test_must_fail git symbolic-ref HEAD
32 test_expect_success 'switch and detach current branch' '
33 test_when_finished git switch master &&
34 git switch master &&
35 git switch --detach &&
36 test_must_fail git symbolic-ref HEAD
39 test_expect_success 'switch and create branch' '
40 test_when_finished git switch master &&
41 git switch -c temp master^ &&
42 test_cmp_rev master^ refs/heads/temp &&
43 echo refs/heads/temp >expected-branch &&
44 git symbolic-ref HEAD >actual-branch &&
45 test_cmp expected-branch actual-branch
48 test_expect_success 'force create branch from HEAD' '
49 test_when_finished git switch master &&
50 git switch --detach master &&
51 test_must_fail git switch -c temp &&
52 git switch -C temp &&
53 test_cmp_rev master refs/heads/temp &&
54 echo refs/heads/temp >expected-branch &&
55 git symbolic-ref HEAD >actual-branch &&
56 test_cmp expected-branch actual-branch
59 test_expect_success 'new orphan branch from empty' '
60 test_when_finished git switch master &&
61 test_must_fail git switch --orphan new-orphan HEAD &&
62 git switch --orphan new-orphan &&
63 test_commit orphan &&
64 git cat-file commit refs/heads/new-orphan >commit &&
65 ! grep ^parent commit &&
66 git ls-files >tracked-files &&
67 echo orphan.t >expected &&
68 test_cmp expected tracked-files
71 test_expect_success 'switching ignores file of same branch name' '
72 test_when_finished git switch master &&
73 : >first-branch &&
74 git switch first-branch &&
75 echo refs/heads/first-branch >expected &&
76 git symbolic-ref HEAD >actual &&
77 test_cmp expected actual
80 test_expect_success 'guess and create branch ' '
81 test_when_finished git switch master &&
82 test_must_fail git switch --no-guess foo &&
83 git switch foo &&
84 echo refs/heads/foo >expected &&
85 git symbolic-ref HEAD >actual &&
86 test_cmp expected actual
89 test_expect_success 'not switching when something is in progress' '
90 test_when_finished rm -f .git/MERGE_HEAD &&
91 # fake a merge-in-progress
92 cp .git/HEAD .git/MERGE_HEAD &&
93 test_must_fail git switch -d @^
96 test_done