]>
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 | ||
696acf45 TR |
8 | . ./test-lib.sh |
9 | ||
10 | test_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 | ||
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 - && | |
883b98ef | 26 | test "z$(git symbolic-ref HEAD)" = "zrefs/heads/main" |
696acf45 TR |
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 | ||
c2883e62 JH |
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 | |
db5875aa | 52 | git checkout -b branch$i || return 1 |
c2883e62 JH |
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 | |
db5875aa | 59 | git checkout branch$i || return 1 |
c2883e62 JH |
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 | ||
619a644d JH |
93 | test_expect_success 'merge base test setup' ' |
94 | git checkout -b another other && | |
f5d79bf7 | 95 | test_commit --append third world "hello again" |
619a644d JH |
96 | ' |
97 | ||
883b98ef | 98 | test_expect_success 'another...main' ' |
619a644d | 99 | git checkout another && |
883b98ef JS |
100 | git checkout another...main && |
101 | test "z$(git rev-parse --verify HEAD)" = "z$(git rev-parse --verify main^)" | |
619a644d JH |
102 | ' |
103 | ||
883b98ef | 104 | test_expect_success '...main' ' |
619a644d | 105 | git checkout another && |
883b98ef JS |
106 | git checkout ...main && |
107 | test "z$(git rev-parse --verify HEAD)" = "z$(git rev-parse --verify main^)" | |
619a644d JH |
108 | ' |
109 | ||
883b98ef | 110 | test_expect_success 'main...' ' |
619a644d | 111 | git checkout another && |
883b98ef JS |
112 | git checkout main... && |
113 | test "z$(git rev-parse --verify HEAD)" = "z$(git rev-parse --verify main^)" | |
619a644d JH |
114 | ' |
115 | ||
3bed291a | 116 | test_expect_success '"checkout -" works after a rebase A' ' |
883b98ef | 117 | git checkout main && |
89f2fea4 | 118 | git checkout other && |
883b98ef | 119 | git rebase main && |
89f2fea4 | 120 | git checkout - && |
883b98ef | 121 | test "z$(git symbolic-ref HEAD)" = "zrefs/heads/main" |
89f2fea4 RR |
122 | ' |
123 | ||
3bed291a | 124 | test_expect_success '"checkout -" works after a rebase A B' ' |
883b98ef JS |
125 | git branch moodle main~1 && |
126 | git checkout main && | |
89f2fea4 | 127 | git checkout other && |
883b98ef | 128 | git rebase main moodle && |
89f2fea4 | 129 | git checkout - && |
883b98ef | 130 | test "z$(git symbolic-ref HEAD)" = "zrefs/heads/main" |
89f2fea4 RR |
131 | ' |
132 | ||
3bed291a | 133 | test_expect_success '"checkout -" works after a rebase -i A' ' |
883b98ef | 134 | git checkout main && |
89f2fea4 | 135 | git checkout other && |
883b98ef | 136 | git rebase -i main && |
89f2fea4 | 137 | git checkout - && |
883b98ef | 138 | test "z$(git symbolic-ref HEAD)" = "zrefs/heads/main" |
89f2fea4 RR |
139 | ' |
140 | ||
3bed291a | 141 | test_expect_success '"checkout -" works after a rebase -i A B' ' |
883b98ef JS |
142 | git branch foodle main~1 && |
143 | git checkout main && | |
89f2fea4 | 144 | git checkout other && |
883b98ef | 145 | git rebase main foodle && |
89f2fea4 | 146 | git checkout - && |
883b98ef | 147 | test "z$(git symbolic-ref HEAD)" = "zrefs/heads/main" |
89f2fea4 RR |
148 | ' |
149 | ||
696acf45 | 150 | test_done |