3 test_description
='checkout can switch to last branch and merge base'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
10 test_expect_success
'setup' '
11 test_commit initial world hello &&
13 test_commit --append second world "hello again"
16 test_expect_success
'"checkout -" does not work initially' '
17 test_must_fail git checkout -
20 test_expect_success
'first branch switch' '
24 test_cmp_symbolic_HEAD_ref
() {
25 echo refs
/heads
/"$1" >expect
&&
26 git symbolic-ref HEAD
>actual
&&
27 test_cmp expect actual
30 test_expect_success
'"checkout -" switches back' '
32 test_cmp_symbolic_HEAD_ref main
35 test_expect_success
'"checkout -" switches forth' '
37 test_cmp_symbolic_HEAD_ref other
40 test_expect_success
'detach HEAD' '
41 git checkout $(git rev-parse HEAD)
44 test_expect_success
'"checkout -" attaches again' '
46 test_cmp_symbolic_HEAD_ref other
49 test_expect_success
'"checkout -" detaches again' '
52 git rev-parse other >expect &&
53 git rev-parse HEAD >actual &&
54 test_cmp expect actual &&
56 test_must_fail git symbolic-ref HEAD
59 test_expect_success
'more switches' '
60 for i in 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
62 git checkout -b branch$i || return 1
67 for i
in 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
69 git checkout branch
$i ||
return 1
73 test_expect_success
'switch to the last' '
76 test_cmp_symbolic_HEAD_ref branch2
79 test_expect_success
'switch to second from the last' '
82 test_cmp_symbolic_HEAD_ref branch3
85 test_expect_success
'switch to third from the last' '
88 test_cmp_symbolic_HEAD_ref branch4
91 test_expect_success
'switch to fourth from the last' '
94 test_cmp_symbolic_HEAD_ref branch5
97 test_expect_success
'switch to twelfth from the last' '
99 git checkout @{-12} &&
100 test_cmp_symbolic_HEAD_ref branch13
103 test_expect_success
'merge base test setup' '
104 git checkout -b another other &&
105 test_commit --append third world "hello again"
108 test_expect_success
'another...main' '
109 git checkout another &&
110 git checkout another...main &&
112 git rev-parse --verify main^ >expect &&
113 git rev-parse --verify HEAD >actual &&
114 test_cmp expect actual
117 test_expect_success
'...main' '
118 git checkout another &&
119 git checkout ...main &&
121 git rev-parse --verify main^ >expect &&
122 git rev-parse --verify HEAD >actual &&
123 test_cmp expect actual
126 test_expect_success
'main...' '
127 git checkout another &&
128 git checkout main... &&
130 git rev-parse --verify main^ >expect &&
131 git rev-parse --verify HEAD >actual &&
132 test_cmp expect actual
135 test_expect_success
'"checkout -" works after a rebase A' '
137 git checkout other &&
140 test_cmp_symbolic_HEAD_ref main
143 test_expect_success
'"checkout -" works after a rebase A B' '
144 git branch moodle main~1 &&
146 git checkout other &&
147 git rebase main moodle &&
149 test_cmp_symbolic_HEAD_ref main
152 test_expect_success
'"checkout -" works after a rebase -i A' '
154 git checkout other &&
155 git rebase -i main &&
157 test_cmp_symbolic_HEAD_ref main
160 test_expect_success
'"checkout -" works after a rebase -i A B' '
161 git branch foodle main~1 &&
163 git checkout other &&
164 git rebase main foodle &&
166 test_cmp_symbolic_HEAD_ref main