]> git.ipfire.org Git - thirdparty/git.git/blame - t/t2060-switch.sh
t2*: adjust the references to the default branch name "main"
[thirdparty/git.git] / t / t2060-switch.sh
CommitLineData
c479ea36
NTND
1#!/bin/sh
2
3test_description='switch basic functionality'
4
883b98ef 5GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
334afbc7
JS
6export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
c479ea36
NTND
8. ./test-lib.sh
9
10test_expect_success 'setup' '
11 test_commit first &&
12 git branch first-branch &&
13 test_commit second &&
14 test_commit third &&
15 git remote add origin nohost:/nopath &&
16 git update-ref refs/remotes/origin/foo first-branch
17'
18
19test_expect_success 'switch branch no arguments' '
20 test_must_fail git switch
21'
22
23test_expect_success 'switch branch' '
24 git switch first-branch &&
25 test_path_is_missing second.t
26'
27
28test_expect_success 'switch and detach' '
883b98ef
JS
29 test_when_finished git switch main &&
30 test_must_fail git switch main^{commit} &&
31 git switch --detach main^{commit} &&
c479ea36
NTND
32 test_must_fail git symbolic-ref HEAD
33'
34
35test_expect_success 'switch and detach current branch' '
883b98ef
JS
36 test_when_finished git switch main &&
37 git switch main &&
c479ea36
NTND
38 git switch --detach &&
39 test_must_fail git symbolic-ref HEAD
40'
41
42test_expect_success 'switch and create branch' '
883b98ef
JS
43 test_when_finished git switch main &&
44 git switch -c temp main^ &&
45 test_cmp_rev main^ refs/heads/temp &&
c479ea36
NTND
46 echo refs/heads/temp >expected-branch &&
47 git symbolic-ref HEAD >actual-branch &&
48 test_cmp expected-branch actual-branch
49'
50
51test_expect_success 'force create branch from HEAD' '
883b98ef
JS
52 test_when_finished git switch main &&
53 git switch --detach main &&
c479ea36
NTND
54 test_must_fail git switch -c temp &&
55 git switch -C temp &&
883b98ef 56 test_cmp_rev main refs/heads/temp &&
c479ea36
NTND
57 echo refs/heads/temp >expected-branch &&
58 git symbolic-ref HEAD >actual-branch &&
59 test_cmp expected-branch actual-branch
60'
61
62test_expect_success 'new orphan branch from empty' '
883b98ef 63 test_when_finished git switch main &&
c479ea36
NTND
64 test_must_fail git switch --orphan new-orphan HEAD &&
65 git switch --orphan new-orphan &&
66 test_commit orphan &&
67 git cat-file commit refs/heads/new-orphan >commit &&
68 ! grep ^parent commit &&
69 git ls-files >tracked-files &&
70 echo orphan.t >expected &&
71 test_cmp expected tracked-files
72'
73
8d3e33da 74test_expect_success 'orphan branch works with --discard-changes' '
883b98ef 75 test_when_finished git switch main &&
8d3e33da 76 echo foo >foo.txt &&
77 git switch --discard-changes --orphan new-orphan2 &&
78 git ls-files >tracked-files &&
79 test_must_be_empty tracked-files
80'
81
c479ea36 82test_expect_success 'switching ignores file of same branch name' '
883b98ef 83 test_when_finished git switch main &&
c479ea36
NTND
84 : >first-branch &&
85 git switch first-branch &&
86 echo refs/heads/first-branch >expected &&
87 git symbolic-ref HEAD >actual &&
88 test_cmp expected actual
89'
90
64f1f58f 91test_expect_success 'guess and create branch' '
883b98ef 92 test_when_finished git switch main &&
c479ea36 93 test_must_fail git switch --no-guess foo &&
64f1f58f
DL
94 test_config checkout.guess false &&
95 test_must_fail git switch foo &&
96 test_config checkout.guess true &&
c479ea36
NTND
97 git switch foo &&
98 echo refs/heads/foo >expected &&
99 git symbolic-ref HEAD >actual &&
100 test_cmp expected actual
101'
102
103test_expect_success 'not switching when something is in progress' '
104 test_when_finished rm -f .git/MERGE_HEAD &&
105 # fake a merge-in-progress
106 cp .git/HEAD .git/MERGE_HEAD &&
107 test_must_fail git switch -d @^
108'
109
110test_done