3 test_description='switch basic functionality'
7 test_expect_success 'setup' '
9 git branch first-branch &&
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 &&
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 &&
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 &&
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 'orphan branch works with --discard-changes' '
72 test_when_finished git switch master &&
74 git switch --discard-changes --orphan new-orphan2 &&
75 git ls-files >tracked-files &&
76 test_must_be_empty tracked-files
79 test_expect_success 'switching ignores file of same branch name' '
80 test_when_finished git switch master &&
82 git switch first-branch &&
83 echo refs/heads/first-branch >expected &&
84 git symbolic-ref HEAD >actual &&
85 test_cmp expected actual
88 test_expect_success 'guess and create branch ' '
89 test_when_finished git switch master &&
90 test_must_fail git switch --no-guess foo &&
92 echo refs/heads/foo >expected &&
93 git symbolic-ref HEAD >actual &&
94 test_cmp expected actual
97 test_expect_success 'not switching when something is in progress' '
98 test_when_finished rm -f .git/MERGE_HEAD &&
99 # fake a merge-in-progress
100 cp .git/HEAD .git/MERGE_HEAD &&
101 test_must_fail git switch -d @^