interplane.Get Omega
Read in your language

git

[Ported from github.com/git/git] Sync with Git 2.56.1

Brought by drakestapleton

branch master Branches Tags History

git / t / t2012-checkout-last.sh

169 lines · 3667 bytes Raw Blame History
1#!/bin/sh
2
3test_description='checkout can switch to last branch and merge base'
4
5GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
8. ./test-lib.sh
9
10test_expect_success 'setup' '
11 test_commit initial world hello &&
12 git branch other &&
13 test_commit --append second world "hello again"
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
24test_cmp_symbolic_HEAD_ref () {
25 echo refs/heads/"$1" >expect &&
26 git symbolic-ref HEAD >actual &&
27 test_cmp expect actual
28}
29
30test_expect_success '"checkout -" switches back' '
31 git checkout - &&
32 test_cmp_symbolic_HEAD_ref main
33'
34
35test_expect_success '"checkout -" switches forth' '
36 git checkout - &&
37 test_cmp_symbolic_HEAD_ref other
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 - &&
46 test_cmp_symbolic_HEAD_ref other
47'
48
49test_expect_success '"checkout -" detaches again' '
50 git checkout - &&
51
52 git rev-parse other >expect &&
53 git rev-parse HEAD >actual &&
54 test_cmp expect actual &&
55
56 test_must_fail git symbolic-ref HEAD
57'
58
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
62 git checkout -b branch$i || return 1
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
69 git checkout branch$i || return 1
70 done
71}
72
73test_expect_success 'switch to the last' '
74 more_switches &&
75 git checkout @{-1} &&
76 test_cmp_symbolic_HEAD_ref branch2
77'
78
79test_expect_success 'switch to second from the last' '
80 more_switches &&
81 git checkout @{-2} &&
82 test_cmp_symbolic_HEAD_ref branch3
83'
84
85test_expect_success 'switch to third from the last' '
86 more_switches &&
87 git checkout @{-3} &&
88 test_cmp_symbolic_HEAD_ref branch4
89'
90
91test_expect_success 'switch to fourth from the last' '
92 more_switches &&
93 git checkout @{-4} &&
94 test_cmp_symbolic_HEAD_ref branch5
95'
96
97test_expect_success 'switch to twelfth from the last' '
98 more_switches &&
99 git checkout @{-12} &&
100 test_cmp_symbolic_HEAD_ref branch13
101'
102
103test_expect_success 'merge base test setup' '
104 git checkout -b another other &&
105 test_commit --append third world "hello again"
106'
107
108test_expect_success 'another...main' '
109 git checkout another &&
110 git checkout another...main &&
111
112 git rev-parse --verify main^ >expect &&
113 git rev-parse --verify HEAD >actual &&
114 test_cmp expect actual
115'
116
117test_expect_success '...main' '
118 git checkout another &&
119 git checkout ...main &&
120
121 git rev-parse --verify main^ >expect &&
122 git rev-parse --verify HEAD >actual &&
123 test_cmp expect actual
124'
125
126test_expect_success 'main...' '
127 git checkout another &&
128 git checkout main... &&
129
130 git rev-parse --verify main^ >expect &&
131 git rev-parse --verify HEAD >actual &&
132 test_cmp expect actual
133'
134
135test_expect_success '"checkout -" works after a rebase A' '
136 git checkout main &&
137 git checkout other &&
138 git rebase main &&
139 git checkout - &&
140 test_cmp_symbolic_HEAD_ref main
141'
142
143test_expect_success '"checkout -" works after a rebase A B' '
144 git branch moodle main~1 &&
145 git checkout main &&
146 git checkout other &&
147 git rebase main moodle &&
148 git checkout - &&
149 test_cmp_symbolic_HEAD_ref main
150'
151
152test_expect_success '"checkout -" works after a rebase -i A' '
153 git checkout main &&
154 git checkout other &&
155 git rebase -i main &&
156 git checkout - &&
157 test_cmp_symbolic_HEAD_ref main
158'
159
160test_expect_success '"checkout -" works after a rebase -i A B' '
161 git branch foodle main~1 &&
162 git checkout main &&
163 git checkout other &&
164 git rebase main foodle &&
165 git checkout - &&
166 test_cmp_symbolic_HEAD_ref main
167'
168
169test_done