range-diff: combine all options in a single data structure
[alt-git.git] / t / t2060-switch.sh
blob68c9101b02f32d943ec5c167d7a726747f5970e4
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 'orphan branch works with --discard-changes' '
72 test_when_finished git switch master &&
73 echo foo >foo.txt &&
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 &&
81 : >first-branch &&
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 &&
91 test_config checkout.guess false &&
92 test_must_fail git switch foo &&
93 test_config checkout.guess true &&
94 git switch foo &&
95 echo refs/heads/foo >expected &&
96 git symbolic-ref HEAD >actual &&
97 test_cmp expected actual
100 test_expect_success 'not switching when something is in progress' '
101 test_when_finished rm -f .git/MERGE_HEAD &&
102 # fake a merge-in-progress
103 cp .git/HEAD .git/MERGE_HEAD &&
104 test_must_fail git switch -d @^
107 test_done