submodule-config.h: remove unused SUBMODULE_INIT macro
[git/debian.git] / t / t2012-checkout-last.sh
blob0e7d47ab318338a211bf444f890176086b9fed5d
1 #!/bin/sh
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-lib.sh
10 test_expect_success 'setup' '
11 test_commit initial world hello &&
12 git branch other &&
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' '
21 git checkout other
24 test_expect_success '"checkout -" switches back' '
25 git checkout - &&
26 test "z$(git symbolic-ref HEAD)" = "zrefs/heads/main"
29 test_expect_success '"checkout -" switches forth' '
30 git checkout - &&
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' '
39 git checkout - &&
40 test "z$(git symbolic-ref HEAD)" = "zrefs/heads/other"
43 test_expect_success '"checkout -" detaches again' '
44 git checkout - &&
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
53 done
56 more_switches () {
57 for i in 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
59 git checkout branch$i
60 done
63 test_expect_success 'switch to the last' '
64 more_switches &&
65 git checkout @{-1} &&
66 test "z$(git symbolic-ref HEAD)" = "zrefs/heads/branch2"
69 test_expect_success 'switch to second from the last' '
70 more_switches &&
71 git checkout @{-2} &&
72 test "z$(git symbolic-ref HEAD)" = "zrefs/heads/branch3"
75 test_expect_success 'switch to third from the last' '
76 more_switches &&
77 git checkout @{-3} &&
78 test "z$(git symbolic-ref HEAD)" = "zrefs/heads/branch4"
81 test_expect_success 'switch to fourth from the last' '
82 more_switches &&
83 git checkout @{-4} &&
84 test "z$(git symbolic-ref HEAD)" = "zrefs/heads/branch5"
87 test_expect_success 'switch to twelfth from the last' '
88 more_switches &&
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' '
117 git checkout main &&
118 git checkout other &&
119 git rebase main &&
120 git checkout - &&
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 &&
126 git checkout main &&
127 git checkout other &&
128 git rebase main moodle &&
129 git checkout - &&
130 test "z$(git symbolic-ref HEAD)" = "zrefs/heads/main"
133 test_expect_success '"checkout -" works after a rebase -i A' '
134 git checkout main &&
135 git checkout other &&
136 git rebase -i main &&
137 git checkout - &&
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 &&
143 git checkout main &&
144 git checkout other &&
145 git rebase main foodle &&
146 git checkout - &&
147 test "z$(git symbolic-ref HEAD)" = "zrefs/heads/main"
150 test_done