3 test_description
='checkout can switch to last branch and merge base'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=master
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
10 test_expect_success
'setup' '
13 git commit -m initial &&
15 echo "hello again" >>world &&
20 test_expect_success
'"checkout -" does not work initially' '
21 test_must_fail git checkout -
24 test_expect_success
'first branch switch' '
28 test_expect_success
'"checkout -" switches back' '
30 test "z$(git symbolic-ref HEAD)" = "zrefs/heads/master"
33 test_expect_success
'"checkout -" switches forth' '
35 test "z$(git symbolic-ref HEAD)" = "zrefs/heads/other"
38 test_expect_success
'detach HEAD' '
39 git checkout $(git rev-parse HEAD)
42 test_expect_success
'"checkout -" attaches again' '
44 test "z$(git symbolic-ref HEAD)" = "zrefs/heads/other"
47 test_expect_success
'"checkout -" detaches again' '
49 test "z$(git rev-parse HEAD)" = "z$(git rev-parse other)" &&
50 test_must_fail git symbolic-ref HEAD
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
56 git checkout -b branch$i
61 for i
in 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
67 test_expect_success
'switch to the last' '
70 test "z$(git symbolic-ref HEAD)" = "zrefs/heads/branch2"
73 test_expect_success
'switch to second from the last' '
76 test "z$(git symbolic-ref HEAD)" = "zrefs/heads/branch3"
79 test_expect_success
'switch to third from the last' '
82 test "z$(git symbolic-ref HEAD)" = "zrefs/heads/branch4"
85 test_expect_success
'switch to fourth from the last' '
88 test "z$(git symbolic-ref HEAD)" = "zrefs/heads/branch5"
91 test_expect_success
'switch to twelfth from the last' '
93 git checkout @{-12} &&
94 test "z$(git symbolic-ref HEAD)" = "zrefs/heads/branch13"
97 test_expect_success
'merge base test setup' '
98 git checkout -b another other &&
99 echo "hello again" >>world &&
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^)"
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^)"
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^)"
122 test_expect_success
'"checkout -" works after a rebase A' '
123 git checkout master &&
124 git checkout other &&
127 test "z$(git symbolic-ref HEAD)" = "zrefs/heads/master"
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 &&
136 test "z$(git symbolic-ref HEAD)" = "zrefs/heads/master"
139 test_expect_success
'"checkout -" works after a rebase -i A' '
140 git checkout master &&
141 git checkout other &&
142 git rebase -i master &&
144 test "z$(git symbolic-ref HEAD)" = "zrefs/heads/master"
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 &&
153 test "z$(git symbolic-ref HEAD)" = "zrefs/heads/master"