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_expect_success '"checkout -" switches back' '
26 test "z$(git symbolic-ref HEAD)" = "zrefs/heads/main"
29 test_expect_success '"checkout -" switches forth' '
31 test "z$(git symbolic-ref HEAD)" = "zrefs/heads/other"
34 test_expect_success 'detach HEAD' '
35 git checkout $(git rev-parse HEAD)
38 test_expect_success '"checkout -" attaches again' '
40 test "z$(git symbolic-ref HEAD)" = "zrefs/heads/other"
43 test_expect_success '"checkout -" detaches again' '
45 test "z$(git rev-parse HEAD)" = "z$(git rev-parse other)" &&
46 test_must_fail git symbolic-ref HEAD
49 test_expect_success 'more switches' '
50 for i in 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
52 git checkout -b branch$i
57 for i in 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
63 test_expect_success 'switch to the last' '
66 test "z$(git symbolic-ref HEAD)" = "zrefs/heads/branch2"
69 test_expect_success 'switch to second from the last' '
72 test "z$(git symbolic-ref HEAD)" = "zrefs/heads/branch3"
75 test_expect_success 'switch to third from the last' '
78 test "z$(git symbolic-ref HEAD)" = "zrefs/heads/branch4"
81 test_expect_success 'switch to fourth from the last' '
84 test "z$(git symbolic-ref HEAD)" = "zrefs/heads/branch5"
87 test_expect_success 'switch to twelfth from the last' '
89 git checkout @{-12} &&
90 test "z$(git symbolic-ref HEAD)" = "zrefs/heads/branch13"
93 test_expect_success 'merge base test setup' '
94 git checkout -b another other &&
95 test_commit --append third world "hello again"
98 test_expect_success 'another...main' '
99 git checkout another &&
100 git checkout another...main &&
101 test "z$(git rev-parse --verify HEAD)" = "z$(git rev-parse --verify main^)"
104 test_expect_success '...main' '
105 git checkout another &&
106 git checkout ...main &&
107 test "z$(git rev-parse --verify HEAD)" = "z$(git rev-parse --verify main^)"
110 test_expect_success 'main...' '
111 git checkout another &&
112 git checkout main... &&
113 test "z$(git rev-parse --verify HEAD)" = "z$(git rev-parse --verify main^)"
116 test_expect_success '"checkout -" works after a rebase A' '
118 git checkout other &&
121 test "z$(git symbolic-ref HEAD)" = "zrefs/heads/main"
124 test_expect_success '"checkout -" works after a rebase A B' '
125 git branch moodle main~1 &&
127 git checkout other &&
128 git rebase main moodle &&
130 test "z$(git symbolic-ref HEAD)" = "zrefs/heads/main"
133 test_expect_success '"checkout -" works after a rebase -i A' '
135 git checkout other &&
136 git rebase -i main &&
138 test "z$(git symbolic-ref HEAD)" = "zrefs/heads/main"
141 test_expect_success '"checkout -" works after a rebase -i A B' '
142 git branch foodle main~1 &&
144 git checkout other &&
145 git rebase main foodle &&
147 test "z$(git symbolic-ref HEAD)" = "zrefs/heads/main"