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