]> git.ipfire.org Git - thirdparty/git.git/blob - t/t2012-checkout-last.sh
tests: mark tests relying on the current default for `init.defaultBranch`
[thirdparty/git.git] / t / t2012-checkout-last.sh
1 #!/bin/sh
2
3 test_description='checkout can switch to last branch and merge base'
4
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
8 . ./test-lib.sh
9
10 test_expect_success 'setup' '
11 echo hello >world &&
12 git add world &&
13 git commit -m initial &&
14 git branch other &&
15 echo "hello again" >>world &&
16 git add world &&
17 git commit -m second
18 '
19
20 test_expect_success '"checkout -" does not work initially' '
21 test_must_fail git checkout -
22 '
23
24 test_expect_success 'first branch switch' '
25 git checkout other
26 '
27
28 test_expect_success '"checkout -" switches back' '
29 git checkout - &&
30 test "z$(git symbolic-ref HEAD)" = "zrefs/heads/master"
31 '
32
33 test_expect_success '"checkout -" switches forth' '
34 git checkout - &&
35 test "z$(git symbolic-ref HEAD)" = "zrefs/heads/other"
36 '
37
38 test_expect_success 'detach HEAD' '
39 git checkout $(git rev-parse HEAD)
40 '
41
42 test_expect_success '"checkout -" attaches again' '
43 git checkout - &&
44 test "z$(git symbolic-ref HEAD)" = "zrefs/heads/other"
45 '
46
47 test_expect_success '"checkout -" detaches again' '
48 git checkout - &&
49 test "z$(git rev-parse HEAD)" = "z$(git rev-parse other)" &&
50 test_must_fail git symbolic-ref HEAD
51 '
52
53 test_expect_success 'more switches' '
54 for i in 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
55 do
56 git checkout -b branch$i
57 done
58 '
59
60 more_switches () {
61 for i in 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
62 do
63 git checkout branch$i
64 done
65 }
66
67 test_expect_success 'switch to the last' '
68 more_switches &&
69 git checkout @{-1} &&
70 test "z$(git symbolic-ref HEAD)" = "zrefs/heads/branch2"
71 '
72
73 test_expect_success 'switch to second from the last' '
74 more_switches &&
75 git checkout @{-2} &&
76 test "z$(git symbolic-ref HEAD)" = "zrefs/heads/branch3"
77 '
78
79 test_expect_success 'switch to third from the last' '
80 more_switches &&
81 git checkout @{-3} &&
82 test "z$(git symbolic-ref HEAD)" = "zrefs/heads/branch4"
83 '
84
85 test_expect_success 'switch to fourth from the last' '
86 more_switches &&
87 git checkout @{-4} &&
88 test "z$(git symbolic-ref HEAD)" = "zrefs/heads/branch5"
89 '
90
91 test_expect_success 'switch to twelfth from the last' '
92 more_switches &&
93 git checkout @{-12} &&
94 test "z$(git symbolic-ref HEAD)" = "zrefs/heads/branch13"
95 '
96
97 test_expect_success 'merge base test setup' '
98 git checkout -b another other &&
99 echo "hello again" >>world &&
100 git add world &&
101 git commit -m third
102 '
103
104 test_expect_success 'another...master' '
105 git checkout another &&
106 git checkout another...master &&
107 test "z$(git rev-parse --verify HEAD)" = "z$(git rev-parse --verify master^)"
108 '
109
110 test_expect_success '...master' '
111 git checkout another &&
112 git checkout ...master &&
113 test "z$(git rev-parse --verify HEAD)" = "z$(git rev-parse --verify master^)"
114 '
115
116 test_expect_success 'master...' '
117 git checkout another &&
118 git checkout master... &&
119 test "z$(git rev-parse --verify HEAD)" = "z$(git rev-parse --verify master^)"
120 '
121
122 test_expect_success '"checkout -" works after a rebase A' '
123 git checkout master &&
124 git checkout other &&
125 git rebase master &&
126 git checkout - &&
127 test "z$(git symbolic-ref HEAD)" = "zrefs/heads/master"
128 '
129
130 test_expect_success '"checkout -" works after a rebase A B' '
131 git branch moodle master~1 &&
132 git checkout master &&
133 git checkout other &&
134 git rebase master moodle &&
135 git checkout - &&
136 test "z$(git symbolic-ref HEAD)" = "zrefs/heads/master"
137 '
138
139 test_expect_success '"checkout -" works after a rebase -i A' '
140 git checkout master &&
141 git checkout other &&
142 git rebase -i master &&
143 git checkout - &&
144 test "z$(git symbolic-ref HEAD)" = "zrefs/heads/master"
145 '
146
147 test_expect_success '"checkout -" works after a rebase -i A B' '
148 git branch foodle master~1 &&
149 git checkout master &&
150 git checkout other &&
151 git rebase master foodle &&
152 git checkout - &&
153 test "z$(git symbolic-ref HEAD)" = "zrefs/heads/master"
154 '
155
156 test_done