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