Commit | Line | Data |
---|---|---|
696acf45 TR |
1 | #!/bin/sh |
2 | ||
619a644d | 3 | test_description='checkout can switch to last branch and merge base' |
696acf45 TR |
4 | |
5 | . ./test-lib.sh | |
6 | ||
7 | test_expect_success 'setup' ' | |
8 | echo hello >world && | |
9 | git add world && | |
10 | git commit -m initial && | |
11 | git branch other && | |
12 | echo "hello again" >>world && | |
13 | git add world && | |
14 | git commit -m second | |
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_expect_success '"checkout -" switches back' ' | |
26 | git checkout - && | |
27 | test "z$(git symbolic-ref HEAD)" = "zrefs/heads/master" | |
28 | ' | |
29 | ||
30 | test_expect_success '"checkout -" switches forth' ' | |
31 | git checkout - && | |
32 | test "z$(git symbolic-ref HEAD)" = "zrefs/heads/other" | |
33 | ' | |
34 | ||
35 | test_expect_success 'detach HEAD' ' | |
36 | git checkout $(git rev-parse HEAD) | |
37 | ' | |
38 | ||
39 | test_expect_success '"checkout -" attaches again' ' | |
40 | git checkout - && | |
41 | test "z$(git symbolic-ref HEAD)" = "zrefs/heads/other" | |
42 | ' | |
43 | ||
44 | test_expect_success '"checkout -" detaches again' ' | |
45 | git checkout - && | |
46 | test "z$(git rev-parse HEAD)" = "z$(git rev-parse other)" && | |
47 | test_must_fail git symbolic-ref HEAD | |
48 | ' | |
49 | ||
c2883e62 JH |
50 | test_expect_success 'more switches' ' |
51 | for i in 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 | |
52 | do | |
53 | git checkout -b branch$i | |
54 | done | |
55 | ' | |
56 | ||
57 | more_switches () { | |
58 | for i in 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 | |
59 | do | |
60 | git checkout branch$i | |
61 | done | |
62 | } | |
63 | ||
64 | test_expect_success 'switch to the last' ' | |
65 | more_switches && | |
66 | git checkout @{-1} && | |
67 | test "z$(git symbolic-ref HEAD)" = "zrefs/heads/branch2" | |
68 | ' | |
69 | ||
70 | test_expect_success 'switch to second from the last' ' | |
71 | more_switches && | |
72 | git checkout @{-2} && | |
73 | test "z$(git symbolic-ref HEAD)" = "zrefs/heads/branch3" | |
74 | ' | |
75 | ||
76 | test_expect_success 'switch to third from the last' ' | |
77 | more_switches && | |
78 | git checkout @{-3} && | |
79 | test "z$(git symbolic-ref HEAD)" = "zrefs/heads/branch4" | |
80 | ' | |
81 | ||
82 | test_expect_success 'switch to fourth from the last' ' | |
83 | more_switches && | |
84 | git checkout @{-4} && | |
85 | test "z$(git symbolic-ref HEAD)" = "zrefs/heads/branch5" | |
86 | ' | |
87 | ||
88 | test_expect_success 'switch to twelfth from the last' ' | |
89 | more_switches && | |
90 | git checkout @{-12} && | |
91 | test "z$(git symbolic-ref HEAD)" = "zrefs/heads/branch13" | |
92 | ' | |
93 | ||
619a644d JH |
94 | test_expect_success 'merge base test setup' ' |
95 | git checkout -b another other && | |
96 | echo "hello again" >>world && | |
97 | git add world && | |
98 | git commit -m third | |
99 | ' | |
100 | ||
101 | test_expect_success 'another...master' ' | |
102 | git checkout another && | |
103 | git checkout another...master && | |
104 | test "z$(git rev-parse --verify HEAD)" = "z$(git rev-parse --verify master^)" | |
105 | ' | |
106 | ||
107 | test_expect_success '...master' ' | |
108 | git checkout another && | |
109 | git checkout ...master && | |
110 | test "z$(git rev-parse --verify HEAD)" = "z$(git rev-parse --verify master^)" | |
111 | ' | |
112 | ||
113 | test_expect_success 'master...' ' | |
114 | git checkout another && | |
115 | git checkout master... && | |
116 | test "z$(git rev-parse --verify HEAD)" = "z$(git rev-parse --verify master^)" | |
117 | ' | |
118 | ||
3bed291a | 119 | test_expect_success '"checkout -" works after a rebase A' ' |
89f2fea4 RR |
120 | git checkout master && |
121 | git checkout other && | |
122 | git rebase master && | |
123 | git checkout - && | |
124 | test "z$(git symbolic-ref HEAD)" = "zrefs/heads/master" | |
125 | ' | |
126 | ||
3bed291a | 127 | test_expect_success '"checkout -" works after a rebase A B' ' |
89f2fea4 RR |
128 | git branch moodle master~1 && |
129 | git checkout master && | |
130 | git checkout other && | |
131 | git rebase master moodle && | |
132 | git checkout - && | |
133 | test "z$(git symbolic-ref HEAD)" = "zrefs/heads/master" | |
134 | ' | |
135 | ||
3bed291a | 136 | test_expect_success '"checkout -" works after a rebase -i A' ' |
89f2fea4 RR |
137 | git checkout master && |
138 | git checkout other && | |
139 | git rebase -i master && | |
140 | git checkout - && | |
141 | test "z$(git symbolic-ref HEAD)" = "zrefs/heads/master" | |
142 | ' | |
143 | ||
3bed291a | 144 | test_expect_success '"checkout -" works after a rebase -i A B' ' |
89f2fea4 RR |
145 | git branch foodle master~1 && |
146 | git checkout master && | |
147 | git checkout other && | |
148 | git rebase master foodle && | |
149 | git checkout - && | |
150 | test "z$(git symbolic-ref HEAD)" = "zrefs/heads/master" | |
151 | ' | |
152 | ||
696acf45 | 153 | test_done |