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
8 TEST_PASSES_SANITIZE_LEAK
=true
11 test_expect_success
'setup' '
12 test_commit initial world hello &&
14 test_commit --append second world "hello again"
17 test_expect_success
'"checkout -" does not work initially' '
18 test_must_fail git checkout -
21 test_expect_success
'first branch switch' '
25 test_cmp_symbolic_HEAD_ref
() {
26 echo refs
/heads
/"$1" >expect
&&
27 git symbolic-ref HEAD
>actual
&&
28 test_cmp expect actual
31 test_expect_success
'"checkout -" switches back' '
33 test_cmp_symbolic_HEAD_ref main
36 test_expect_success
'"checkout -" switches forth' '
38 test_cmp_symbolic_HEAD_ref other
41 test_expect_success
'detach HEAD' '
42 git checkout $(git rev-parse HEAD)
45 test_expect_success
'"checkout -" attaches again' '
47 test_cmp_symbolic_HEAD_ref other
50 test_expect_success
'"checkout -" detaches again' '
53 git rev-parse other >expect &&
54 git rev-parse HEAD >actual &&
55 test_cmp expect actual &&
57 test_must_fail git symbolic-ref HEAD
60 test_expect_success
'more switches' '
61 for i in 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
63 git checkout -b branch$i || return 1
68 for i
in 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
70 git checkout branch
$i ||
return 1
74 test_expect_success
'switch to the last' '
77 test_cmp_symbolic_HEAD_ref branch2
80 test_expect_success
'switch to second from the last' '
83 test_cmp_symbolic_HEAD_ref branch3
86 test_expect_success
'switch to third from the last' '
89 test_cmp_symbolic_HEAD_ref branch4
92 test_expect_success
'switch to fourth from the last' '
95 test_cmp_symbolic_HEAD_ref branch5
98 test_expect_success
'switch to twelfth from the last' '
100 git checkout @{-12} &&
101 test_cmp_symbolic_HEAD_ref branch13
104 test_expect_success
'merge base test setup' '
105 git checkout -b another other &&
106 test_commit --append third world "hello again"
109 test_expect_success
'another...main' '
110 git checkout another &&
111 git checkout another...main &&
113 git rev-parse --verify main^ >expect &&
114 git rev-parse --verify HEAD >actual &&
115 test_cmp expect actual
118 test_expect_success
'...main' '
119 git checkout another &&
120 git checkout ...main &&
122 git rev-parse --verify main^ >expect &&
123 git rev-parse --verify HEAD >actual &&
124 test_cmp expect actual
127 test_expect_success
'main...' '
128 git checkout another &&
129 git checkout main... &&
131 git rev-parse --verify main^ >expect &&
132 git rev-parse --verify HEAD >actual &&
133 test_cmp expect actual
136 test_expect_success
'"checkout -" works after a rebase A' '
138 git checkout other &&
141 test_cmp_symbolic_HEAD_ref main
144 test_expect_success
'"checkout -" works after a rebase A B' '
145 git branch moodle main~1 &&
147 git checkout other &&
148 git rebase main moodle &&
150 test_cmp_symbolic_HEAD_ref main
153 test_expect_success
'"checkout -" works after a rebase -i A' '
155 git checkout other &&
156 git rebase -i main &&
158 test_cmp_symbolic_HEAD_ref main
161 test_expect_success
'"checkout -" works after a rebase -i A B' '
162 git branch foodle main~1 &&
164 git checkout other &&
165 git rebase main foodle &&
167 test_cmp_symbolic_HEAD_ref main