]>
Commit | Line | Data |
---|---|---|
9f21e97d NS |
1 | #!/bin/sh |
2 | ||
3 | test_description='git rebase --onto A...B' | |
4 | ||
d1c02d93 | 5 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
334afbc7 JS |
6 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
7 | ||
94ad545d | 8 | TEST_PASSES_SANITIZE_LEAK=true |
9f21e97d NS |
9 | . ./test-lib.sh |
10 | . "$TEST_DIRECTORY/lib-rebase.sh" | |
11 | ||
d1c02d93 JS |
12 | # Rebase only the tip commit of "topic" on merge base between "main" |
13 | # and "topic". Cannot do this for "side" with "main" because there | |
9f21e97d NS |
14 | # is no single merge base. |
15 | # | |
16 | # | |
17 | # F---G topic G' | |
18 | # / / | |
d1c02d93 | 19 | # A---B---C---D---E main --> A---B---C---D---E |
9f21e97d NS |
20 | # \ \ / |
21 | # \ x | |
22 | # \ / \ | |
23 | # H---I---J---K side | |
24 | ||
25 | test_expect_success setup ' | |
26 | test_commit A && | |
27 | test_commit B && | |
28 | git branch side && | |
29 | test_commit C && | |
30 | git branch topic && | |
31 | git checkout side && | |
32 | test_commit H && | |
d1c02d93 | 33 | git checkout main && |
9f21e97d NS |
34 | test_tick && |
35 | git merge H && | |
36 | git tag D && | |
37 | test_commit E && | |
38 | git checkout topic && | |
39 | test_commit F && | |
40 | test_commit G && | |
41 | git checkout side && | |
42 | test_tick && | |
43 | git merge C && | |
44 | git tag I && | |
45 | test_commit J && | |
46 | test_commit K | |
47 | ' | |
48 | ||
d1c02d93 | 49 | test_expect_success 'rebase --onto main...topic' ' |
9f21e97d NS |
50 | git reset --hard && |
51 | git checkout topic && | |
52 | git reset --hard G && | |
53 | ||
d1c02d93 | 54 | git rebase --onto main...topic F && |
9f21e97d NS |
55 | git rev-parse HEAD^1 >actual && |
56 | git rev-parse C^0 >expect && | |
57 | test_cmp expect actual | |
58 | ' | |
59 | ||
d1c02d93 | 60 | test_expect_success 'rebase --onto main...' ' |
9f21e97d NS |
61 | git reset --hard && |
62 | git checkout topic && | |
63 | git reset --hard G && | |
64 | ||
d1c02d93 | 65 | git rebase --onto main... F && |
9f21e97d NS |
66 | git rev-parse HEAD^1 >actual && |
67 | git rev-parse C^0 >expect && | |
68 | test_cmp expect actual | |
69 | ' | |
70 | ||
d1c02d93 | 71 | test_expect_success 'rebase --onto main...side' ' |
9f21e97d NS |
72 | git reset --hard && |
73 | git checkout side && | |
74 | git reset --hard K && | |
75 | ||
d1c02d93 | 76 | test_must_fail git rebase --onto main...side J |
9f21e97d NS |
77 | ' |
78 | ||
d1c02d93 | 79 | test_expect_success 'rebase -i --onto main...topic' ' |
230a4566 NS |
80 | git reset --hard && |
81 | git checkout topic && | |
82 | git reset --hard G && | |
05ec4185 PW |
83 | ( |
84 | set_fake_editor && | |
85 | EXPECT_COUNT=1 git rebase -i --onto main...topic F | |
86 | ) && | |
230a4566 NS |
87 | git rev-parse HEAD^1 >actual && |
88 | git rev-parse C^0 >expect && | |
89 | test_cmp expect actual | |
90 | ' | |
91 | ||
d1c02d93 | 92 | test_expect_success 'rebase -i --onto main...' ' |
230a4566 NS |
93 | git reset --hard && |
94 | git checkout topic && | |
95 | git reset --hard G && | |
05ec4185 PW |
96 | ( |
97 | set_fake_editor && | |
98 | EXPECT_COUNT=1 git rebase -i --onto main... F | |
99 | ) && | |
230a4566 NS |
100 | git rev-parse HEAD^1 >actual && |
101 | git rev-parse C^0 >expect && | |
102 | test_cmp expect actual | |
103 | ' | |
104 | ||
96601a26 | 105 | test_expect_success 'rebase --onto main...side requires a single merge-base' ' |
230a4566 NS |
106 | git reset --hard && |
107 | git checkout side && | |
108 | git reset --hard K && | |
109 | ||
96601a26 PW |
110 | test_must_fail git rebase -i --onto main...side J 2>err && |
111 | grep "need exactly one merge base" err | |
230a4566 NS |
112 | ' |
113 | ||
414d924b | 114 | test_expect_success 'rebase --keep-base --onto incompatible' ' |
d1c02d93 | 115 | test_must_fail git rebase --keep-base --onto main... |
414d924b DL |
116 | ' |
117 | ||
118 | test_expect_success 'rebase --keep-base --root incompatible' ' | |
119 | test_must_fail git rebase --keep-base --root | |
120 | ' | |
121 | ||
d1c02d93 | 122 | test_expect_success 'rebase --keep-base main from topic' ' |
414d924b DL |
123 | git reset --hard && |
124 | git checkout topic && | |
125 | git reset --hard G && | |
126 | ||
d1c02d93 | 127 | git rebase --keep-base main && |
414d924b | 128 | git rev-parse C >base.expect && |
d1c02d93 | 129 | git merge-base main HEAD >base.actual && |
414d924b DL |
130 | test_cmp base.expect base.actual && |
131 | ||
132 | git rev-parse HEAD~2 >actual && | |
133 | git rev-parse C^0 >expect && | |
134 | test_cmp expect actual | |
135 | ' | |
136 | ||
9e5ebe96 AH |
137 | test_expect_success 'rebase --keep-base main topic from main' ' |
138 | git checkout main && | |
139 | git branch -f topic G && | |
140 | ||
141 | git rebase --keep-base main topic && | |
142 | git rev-parse C >base.expect && | |
143 | git merge-base main HEAD >base.actual && | |
144 | test_cmp base.expect base.actual && | |
145 | ||
146 | git rev-parse HEAD~2 >actual && | |
147 | git rev-parse C^0 >expect && | |
148 | test_cmp expect actual | |
149 | ' | |
150 | ||
d1c02d93 | 151 | test_expect_success 'rebase --keep-base main from side' ' |
414d924b DL |
152 | git reset --hard && |
153 | git checkout side && | |
154 | git reset --hard K && | |
155 | ||
d1c02d93 | 156 | test_must_fail git rebase --keep-base main |
414d924b DL |
157 | ' |
158 | ||
d1c02d93 | 159 | test_expect_success 'rebase -i --keep-base main from topic' ' |
414d924b DL |
160 | git reset --hard && |
161 | git checkout topic && | |
162 | git reset --hard G && | |
163 | ||
05ec4185 PW |
164 | ( |
165 | set_fake_editor && | |
166 | EXPECT_COUNT=2 git rebase -i --keep-base main | |
167 | ) && | |
414d924b | 168 | git rev-parse C >base.expect && |
d1c02d93 | 169 | git merge-base main HEAD >base.actual && |
414d924b DL |
170 | test_cmp base.expect base.actual && |
171 | ||
172 | git rev-parse HEAD~2 >actual && | |
173 | git rev-parse C^0 >expect && | |
174 | test_cmp expect actual | |
175 | ' | |
176 | ||
9e5ebe96 AH |
177 | test_expect_success 'rebase -i --keep-base main topic from main' ' |
178 | git checkout main && | |
179 | git branch -f topic G && | |
180 | ||
05ec4185 PW |
181 | ( |
182 | set_fake_editor && | |
183 | EXPECT_COUNT=2 git rebase -i --keep-base main topic | |
184 | ) && | |
9e5ebe96 AH |
185 | git rev-parse C >base.expect && |
186 | git merge-base main HEAD >base.actual && | |
187 | test_cmp base.expect base.actual && | |
188 | ||
189 | git rev-parse HEAD~2 >actual && | |
190 | git rev-parse C^0 >expect && | |
191 | test_cmp expect actual | |
192 | ' | |
193 | ||
96601a26 | 194 | test_expect_success 'rebase --keep-base requires a single merge base' ' |
414d924b DL |
195 | git reset --hard && |
196 | git checkout side && | |
197 | git reset --hard K && | |
198 | ||
96601a26 PW |
199 | test_must_fail git rebase -i --keep-base main 2>err && |
200 | grep "need exactly one merge base with branch" err | |
414d924b DL |
201 | ' |
202 | ||
ce5238a6 PW |
203 | test_expect_success 'rebase --keep-base keeps cherry picks' ' |
204 | git checkout -f -B main E && | |
205 | git cherry-pick F && | |
206 | ( | |
207 | set_fake_editor && | |
208 | EXPECT_COUNT=2 git rebase -i --keep-base HEAD G | |
209 | ) && | |
210 | test_cmp_rev HEAD G | |
211 | ' | |
212 | ||
213 | test_expect_success 'rebase --keep-base --no-reapply-cherry-picks' ' | |
214 | git checkout -f -B main E && | |
215 | git cherry-pick F && | |
216 | ( | |
217 | set_fake_editor && | |
218 | EXPECT_COUNT=1 git rebase -i --keep-base \ | |
219 | --no-reapply-cherry-picks HEAD G | |
220 | ) && | |
221 | test_cmp_rev HEAD^ C | |
222 | ' | |
223 | ||
05ec4185 PW |
224 | # This must be the last test in this file |
225 | test_expect_success '$EDITOR and friends are unchanged' ' | |
226 | test_editor_unchanged | |
227 | ' | |
228 | ||
9f21e97d | 229 | test_done |