]> git.ipfire.org Git - thirdparty/git.git/blob - t/t2012-checkout-last.sh
repo-settings: rename the traditional default fetch.negotiationAlgorithm
[thirdparty/git.git] / t / t2012-checkout-last.sh
1 #!/bin/sh
2
3 test_description='checkout can switch to last branch and merge base'
4
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
8 . ./test-lib.sh
9
10 test_expect_success 'setup' '
11 test_commit initial world hello &&
12 git branch other &&
13 test_commit --append second world "hello again"
14 '
15
16 test_expect_success '"checkout -" does not work initially' '
17 test_must_fail git checkout -
18 '
19
20 test_expect_success 'first branch switch' '
21 git checkout other
22 '
23
24 test_expect_success '"checkout -" switches back' '
25 git checkout - &&
26 test "z$(git symbolic-ref HEAD)" = "zrefs/heads/main"
27 '
28
29 test_expect_success '"checkout -" switches forth' '
30 git checkout - &&
31 test "z$(git symbolic-ref HEAD)" = "zrefs/heads/other"
32 '
33
34 test_expect_success 'detach HEAD' '
35 git checkout $(git rev-parse HEAD)
36 '
37
38 test_expect_success '"checkout -" attaches again' '
39 git checkout - &&
40 test "z$(git symbolic-ref HEAD)" = "zrefs/heads/other"
41 '
42
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
47 '
48
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
51 do
52 git checkout -b branch$i
53 done
54 '
55
56 more_switches () {
57 for i in 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
58 do
59 git checkout branch$i
60 done
61 }
62
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"
67 '
68
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"
73 '
74
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"
79 '
80
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"
85 '
86
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"
91 '
92
93 test_expect_success 'merge base test setup' '
94 git checkout -b another other &&
95 test_commit --append third world "hello again"
96 '
97
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^)"
102 '
103
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^)"
108 '
109
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^)"
114 '
115
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"
122 '
123
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"
131 '
132
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"
139 '
140
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"
148 '
149
150 test_done