]> git.ipfire.org Git - thirdparty/git.git/blob - t/t2012-checkout-last.sh
The third batch
[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_PASSES_SANITIZE_LEAK=true
9 . ./test-lib.sh
10
11 test_expect_success 'setup' '
12 test_commit initial world hello &&
13 git branch other &&
14 test_commit --append second world "hello again"
15 '
16
17 test_expect_success '"checkout -" does not work initially' '
18 test_must_fail git checkout -
19 '
20
21 test_expect_success 'first branch switch' '
22 git checkout other
23 '
24
25 test_cmp_symbolic_HEAD_ref () {
26 echo refs/heads/"$1" >expect &&
27 git symbolic-ref HEAD >actual &&
28 test_cmp expect actual
29 }
30
31 test_expect_success '"checkout -" switches back' '
32 git checkout - &&
33 test_cmp_symbolic_HEAD_ref main
34 '
35
36 test_expect_success '"checkout -" switches forth' '
37 git checkout - &&
38 test_cmp_symbolic_HEAD_ref other
39 '
40
41 test_expect_success 'detach HEAD' '
42 git checkout $(git rev-parse HEAD)
43 '
44
45 test_expect_success '"checkout -" attaches again' '
46 git checkout - &&
47 test_cmp_symbolic_HEAD_ref other
48 '
49
50 test_expect_success '"checkout -" detaches again' '
51 git checkout - &&
52
53 git rev-parse other >expect &&
54 git rev-parse HEAD >actual &&
55 test_cmp expect actual &&
56
57 test_must_fail git symbolic-ref HEAD
58 '
59
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
62 do
63 git checkout -b branch$i || return 1
64 done
65 '
66
67 more_switches () {
68 for i in 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
69 do
70 git checkout branch$i || return 1
71 done
72 }
73
74 test_expect_success 'switch to the last' '
75 more_switches &&
76 git checkout @{-1} &&
77 test_cmp_symbolic_HEAD_ref branch2
78 '
79
80 test_expect_success 'switch to second from the last' '
81 more_switches &&
82 git checkout @{-2} &&
83 test_cmp_symbolic_HEAD_ref branch3
84 '
85
86 test_expect_success 'switch to third from the last' '
87 more_switches &&
88 git checkout @{-3} &&
89 test_cmp_symbolic_HEAD_ref branch4
90 '
91
92 test_expect_success 'switch to fourth from the last' '
93 more_switches &&
94 git checkout @{-4} &&
95 test_cmp_symbolic_HEAD_ref branch5
96 '
97
98 test_expect_success 'switch to twelfth from the last' '
99 more_switches &&
100 git checkout @{-12} &&
101 test_cmp_symbolic_HEAD_ref branch13
102 '
103
104 test_expect_success 'merge base test setup' '
105 git checkout -b another other &&
106 test_commit --append third world "hello again"
107 '
108
109 test_expect_success 'another...main' '
110 git checkout another &&
111 git checkout another...main &&
112
113 git rev-parse --verify main^ >expect &&
114 git rev-parse --verify HEAD >actual &&
115 test_cmp expect actual
116 '
117
118 test_expect_success '...main' '
119 git checkout another &&
120 git checkout ...main &&
121
122 git rev-parse --verify main^ >expect &&
123 git rev-parse --verify HEAD >actual &&
124 test_cmp expect actual
125 '
126
127 test_expect_success 'main...' '
128 git checkout another &&
129 git checkout main... &&
130
131 git rev-parse --verify main^ >expect &&
132 git rev-parse --verify HEAD >actual &&
133 test_cmp expect actual
134 '
135
136 test_expect_success '"checkout -" works after a rebase A' '
137 git checkout main &&
138 git checkout other &&
139 git rebase main &&
140 git checkout - &&
141 test_cmp_symbolic_HEAD_ref main
142 '
143
144 test_expect_success '"checkout -" works after a rebase A B' '
145 git branch moodle main~1 &&
146 git checkout main &&
147 git checkout other &&
148 git rebase main moodle &&
149 git checkout - &&
150 test_cmp_symbolic_HEAD_ref main
151 '
152
153 test_expect_success '"checkout -" works after a rebase -i A' '
154 git checkout main &&
155 git checkout other &&
156 git rebase -i main &&
157 git checkout - &&
158 test_cmp_symbolic_HEAD_ref main
159 '
160
161 test_expect_success '"checkout -" works after a rebase -i A B' '
162 git branch foodle main~1 &&
163 git checkout main &&
164 git checkout other &&
165 git rebase main foodle &&
166 git checkout - &&
167 test_cmp_symbolic_HEAD_ref main
168 '
169
170 test_done