]>
Commit | Line | Data |
---|---|---|
2aad7cac MZ |
1 | #!/bin/sh |
2 | ||
3 | test_description='basic rebase topology tests' | |
4 | . ./test-lib.sh | |
5 | . "$TEST_DIRECTORY"/lib-rebase.sh | |
6 | ||
7 | # a---b---c | |
8 | # \ | |
9 | # d---e | |
10 | test_expect_success 'setup' ' | |
11 | test_commit a && | |
12 | test_commit b && | |
13 | test_commit c && | |
14 | git checkout b && | |
15 | test_commit d && | |
16 | test_commit e | |
17 | ' | |
18 | ||
19 | test_run_rebase () { | |
20 | result=$1 | |
21 | shift | |
22 | test_expect_$result "simple rebase $*" " | |
23 | reset_rebase && | |
24 | git rebase $* c e && | |
25 | test_cmp_rev c HEAD~2 && | |
26 | test_linear_range 'd e' c.. | |
27 | " | |
28 | } | |
10cdb9f3 | 29 | test_run_rebase success --apply |
2aad7cac MZ |
30 | test_run_rebase success -m |
31 | test_run_rebase success -i | |
2aad7cac | 32 | |
6330209d ÆAB |
33 | test_expect_success 'setup branches and remote tracking' ' |
34 | git tag -l >tags && | |
35 | for tag in $(cat tags) | |
36 | do | |
37 | git branch branch-$tag $tag || return 1 | |
38 | done && | |
39 | git remote add origin "file://$PWD" && | |
40 | git fetch origin | |
41 | ' | |
42 | ||
2aad7cac MZ |
43 | test_run_rebase () { |
44 | result=$1 | |
45 | shift | |
46 | test_expect_$result "rebase $* is no-op if upstream is an ancestor" " | |
47 | reset_rebase && | |
48 | git rebase $* b e && | |
49 | test_cmp_rev e HEAD | |
50 | " | |
51 | } | |
10cdb9f3 | 52 | test_run_rebase success --apply |
2aad7cac MZ |
53 | test_run_rebase success -m |
54 | test_run_rebase success -i | |
2aad7cac MZ |
55 | |
56 | test_run_rebase () { | |
57 | result=$1 | |
58 | shift | |
59 | test_expect_$result "rebase $* -f rewrites even if upstream is an ancestor" " | |
60 | reset_rebase && | |
61 | git rebase $* -f b e && | |
2c9e125b | 62 | test_cmp_rev ! e HEAD && |
2aad7cac MZ |
63 | test_cmp_rev b HEAD~2 && |
64 | test_linear_range 'd e' b.. | |
65 | " | |
66 | } | |
10cdb9f3 | 67 | test_run_rebase success --apply |
6330209d | 68 | test_run_rebase success --fork-point |
2aad7cac MZ |
69 | test_run_rebase success -m |
70 | test_run_rebase success -i | |
2aad7cac | 71 | |
6330209d ÆAB |
72 | test_run_rebase () { |
73 | result=$1 | |
74 | shift | |
75 | test_expect_$result "rebase $* -f rewrites even if remote upstream is an ancestor" " | |
76 | reset_rebase && | |
77 | git rebase $* -f branch-b branch-e && | |
2c9e125b | 78 | test_cmp_rev ! branch-e origin/branch-e && |
6330209d ÆAB |
79 | test_cmp_rev branch-b HEAD~2 && |
80 | test_linear_range 'd e' branch-b.. | |
81 | " | |
82 | } | |
10cdb9f3 | 83 | test_run_rebase success --apply |
6330209d ÆAB |
84 | test_run_rebase success --fork-point |
85 | test_run_rebase success -m | |
86 | test_run_rebase success -i | |
6330209d | 87 | |
2aad7cac MZ |
88 | test_run_rebase () { |
89 | result=$1 | |
90 | shift | |
91 | test_expect_$result "rebase $* fast-forwards from ancestor of upstream" " | |
92 | reset_rebase && | |
93 | git rebase $* e b && | |
94 | test_cmp_rev e HEAD | |
95 | " | |
96 | } | |
10cdb9f3 | 97 | test_run_rebase success --apply |
6330209d | 98 | test_run_rebase success --fork-point |
2aad7cac MZ |
99 | test_run_rebase success -m |
100 | test_run_rebase success -i | |
2aad7cac | 101 | |
5b5e1c7c MZ |
102 | # f |
103 | # / | |
104 | # a---b---c---g---h | |
105 | # \ | |
984f78d2 | 106 | # d---gp--i |
5b5e1c7c | 107 | # |
984f78d2 | 108 | # gp = cherry-picked g |
5b5e1c7c MZ |
109 | # h = reverted g |
110 | # | |
111 | # Reverted patches are there for tests to be able to check if a commit | |
112 | # that introduced the same change as another commit is | |
113 | # dropped. Without reverted commits, we could get false positives | |
114 | # because applying the patch succeeds, but simply results in no | |
115 | # changes. | |
116 | test_expect_success 'setup of linear history for range selection tests' ' | |
117 | git checkout c && | |
118 | test_commit g && | |
119 | revert h g && | |
120 | git checkout d && | |
984f78d2 | 121 | cherry_pick gp g && |
5b5e1c7c MZ |
122 | test_commit i && |
123 | git checkout b && | |
124 | test_commit f | |
125 | ' | |
126 | ||
127 | test_run_rebase () { | |
128 | result=$1 | |
129 | shift | |
130 | test_expect_$result "rebase $* drops patches in upstream" " | |
131 | reset_rebase && | |
132 | git rebase $* h i && | |
133 | test_cmp_rev h HEAD~2 && | |
134 | test_linear_range 'd i' h.. | |
135 | " | |
136 | } | |
10cdb9f3 | 137 | test_run_rebase success --apply |
68aa495b | 138 | test_run_rebase success -m |
5b5e1c7c | 139 | test_run_rebase success -i |
5b5e1c7c MZ |
140 | |
141 | test_run_rebase () { | |
142 | result=$1 | |
143 | shift | |
144 | test_expect_$result "rebase $* can drop last patch if in upstream" " | |
145 | reset_rebase && | |
984f78d2 | 146 | git rebase $* h gp && |
5b5e1c7c MZ |
147 | test_cmp_rev h HEAD^ && |
148 | test_linear_range 'd' h.. | |
149 | " | |
150 | } | |
10cdb9f3 | 151 | test_run_rebase success --apply |
68aa495b | 152 | test_run_rebase success -m |
5b5e1c7c | 153 | test_run_rebase success -i |
5b5e1c7c MZ |
154 | |
155 | test_run_rebase () { | |
156 | result=$1 | |
157 | shift | |
158 | test_expect_$result "rebase $* --onto drops patches in upstream" " | |
159 | reset_rebase && | |
160 | git rebase $* --onto f h i && | |
161 | test_cmp_rev f HEAD~2 && | |
162 | test_linear_range 'd i' f.. | |
163 | " | |
164 | } | |
10cdb9f3 | 165 | test_run_rebase success --apply |
68aa495b | 166 | test_run_rebase success -m |
5b5e1c7c | 167 | test_run_rebase success -i |
5b5e1c7c MZ |
168 | |
169 | test_run_rebase () { | |
170 | result=$1 | |
171 | shift | |
172 | test_expect_$result "rebase $* --onto does not drop patches in onto" " | |
173 | reset_rebase && | |
174 | git rebase $* --onto h f i && | |
175 | test_cmp_rev h HEAD~3 && | |
984f78d2 | 176 | test_linear_range 'd gp i' h.. |
5b5e1c7c MZ |
177 | " |
178 | } | |
10cdb9f3 | 179 | test_run_rebase success --apply |
5b5e1c7c MZ |
180 | test_run_rebase success -m |
181 | test_run_rebase success -i | |
5b5e1c7c | 182 | |
00b8be5a MZ |
183 | # a---b---c---j! |
184 | # \ | |
185 | # d---k!--l | |
186 | # | |
187 | # ! = empty | |
188 | test_expect_success 'setup of linear history for empty commit tests' ' | |
189 | git checkout c && | |
190 | make_empty j && | |
191 | git checkout d && | |
192 | make_empty k && | |
193 | test_commit l | |
194 | ' | |
195 | ||
196 | test_run_rebase () { | |
197 | result=$1 | |
198 | shift | |
d48e5e21 | 199 | test_expect_$result "rebase $* keeps begin-empty commits" " |
00b8be5a | 200 | reset_rebase && |
d48e5e21 EN |
201 | git rebase $* j l && |
202 | test_cmp_rev c HEAD~4 && | |
203 | test_linear_range 'j d k l' c.. | |
00b8be5a MZ |
204 | " |
205 | } | |
10cdb9f3 | 206 | test_run_rebase failure --apply |
00b8be5a MZ |
207 | test_run_rebase success -m |
208 | test_run_rebase success -i | |
00b8be5a MZ |
209 | |
210 | test_run_rebase () { | |
211 | result=$1 | |
212 | shift | |
b9cbd295 | 213 | test_expect_$result "rebase $* --no-keep-empty drops begin-empty commits" " |
00b8be5a | 214 | reset_rebase && |
b9cbd295 EN |
215 | git rebase $* --no-keep-empty c l && |
216 | test_cmp_rev c HEAD~2 && | |
217 | test_linear_range 'd l' c.. | |
00b8be5a MZ |
218 | " |
219 | } | |
da27a6fb | 220 | test_run_rebase success -m |
00b8be5a | 221 | test_run_rebase success -i |
00b8be5a MZ |
222 | |
223 | test_run_rebase () { | |
224 | result=$1 | |
225 | shift | |
226 | test_expect_$result "rebase $* --keep-empty keeps empty even if already in upstream" " | |
227 | reset_rebase && | |
228 | git rebase $* --keep-empty j l && | |
229 | test_cmp_rev j HEAD~3 && | |
230 | test_linear_range 'd k l' j.. | |
231 | " | |
232 | } | |
da27a6fb | 233 | test_run_rebase success -m |
76ea2358 | 234 | test_run_rebase success -i |
24293359 | 235 | test_run_rebase success --rebase-merges |
00b8be5a | 236 | |
6a6bc5bd MZ |
237 | # m |
238 | # / | |
239 | # a---b---c---g | |
240 | # | |
984f78d2 | 241 | # x---y---bp |
6a6bc5bd | 242 | # |
984f78d2 | 243 | # bp = cherry-picked b |
6a6bc5bd MZ |
244 | # m = reverted b |
245 | # | |
246 | # Reverted patches are there for tests to be able to check if a commit | |
247 | # that introduced the same change as another commit is | |
248 | # dropped. Without reverted commits, we could get false positives | |
249 | # because applying the patch succeeds, but simply results in no | |
250 | # changes. | |
251 | test_expect_success 'setup of linear history for test involving root' ' | |
252 | git checkout b && | |
253 | revert m b && | |
254 | git checkout --orphan disjoint && | |
255 | git rm -rf . && | |
256 | test_commit x && | |
257 | test_commit y && | |
984f78d2 | 258 | cherry_pick bp b |
6a6bc5bd MZ |
259 | ' |
260 | ||
261 | test_run_rebase () { | |
262 | result=$1 | |
263 | shift | |
264 | test_expect_$result "rebase $* --onto --root" " | |
265 | reset_rebase && | |
266 | git rebase $* --onto c --root y && | |
267 | test_cmp_rev c HEAD~2 && | |
268 | test_linear_range 'x y' c.. | |
269 | " | |
270 | } | |
10cdb9f3 | 271 | test_run_rebase success --apply |
79f43447 | 272 | test_run_rebase success -m |
6a6bc5bd | 273 | test_run_rebase success -i |
6a6bc5bd MZ |
274 | |
275 | test_run_rebase () { | |
276 | result=$1 | |
277 | shift | |
278 | test_expect_$result "rebase $* without --onto --root with disjoint history" " | |
279 | reset_rebase && | |
280 | git rebase $* c y && | |
281 | test_cmp_rev c HEAD~2 && | |
282 | test_linear_range 'x y' c.. | |
283 | " | |
284 | } | |
10cdb9f3 | 285 | test_run_rebase success --apply |
79f43447 | 286 | test_run_rebase success -m |
6a6bc5bd | 287 | test_run_rebase success -i |
6a6bc5bd MZ |
288 | |
289 | test_run_rebase () { | |
290 | result=$1 | |
291 | shift | |
292 | test_expect_$result "rebase $* --onto --root drops patch in onto" " | |
293 | reset_rebase && | |
984f78d2 | 294 | git rebase $* --onto m --root bp && |
6a6bc5bd MZ |
295 | test_cmp_rev m HEAD~2 && |
296 | test_linear_range 'x y' m.. | |
297 | " | |
298 | } | |
10cdb9f3 | 299 | test_run_rebase success --apply |
68aa495b | 300 | test_run_rebase success -m |
6a6bc5bd | 301 | test_run_rebase success -i |
6a6bc5bd MZ |
302 | |
303 | test_run_rebase () { | |
304 | result=$1 | |
305 | shift | |
306 | test_expect_$result "rebase $* --onto --root with merge-base does not go to root" " | |
307 | reset_rebase && | |
308 | git rebase $* --onto m --root g && | |
309 | test_cmp_rev m HEAD~2 && | |
310 | test_linear_range 'c g' m.. | |
311 | " | |
312 | } | |
313 | ||
10cdb9f3 | 314 | test_run_rebase success --apply |
6a6bc5bd MZ |
315 | test_run_rebase success -m |
316 | test_run_rebase success -i | |
6a6bc5bd MZ |
317 | |
318 | test_run_rebase () { | |
319 | result=$1 | |
320 | shift | |
321 | test_expect_$result "rebase $* without --onto --root with disjoint history drops patch in onto" " | |
322 | reset_rebase && | |
984f78d2 | 323 | git rebase $* m bp && |
6a6bc5bd MZ |
324 | test_cmp_rev m HEAD~2 && |
325 | test_linear_range 'x y' m.. | |
326 | " | |
327 | } | |
10cdb9f3 | 328 | test_run_rebase success --apply |
68aa495b | 329 | test_run_rebase success -m |
6a6bc5bd | 330 | test_run_rebase success -i |
6a6bc5bd MZ |
331 | |
332 | test_run_rebase () { | |
333 | result=$1 | |
334 | shift | |
335 | test_expect_$result "rebase $* --root on linear history is a no-op" " | |
336 | reset_rebase && | |
337 | git rebase $* --root c && | |
338 | test_cmp_rev c HEAD | |
339 | " | |
340 | } | |
21d0764c JS |
341 | test_run_rebase success '' |
342 | test_run_rebase success -m | |
343 | test_run_rebase success -i | |
6a6bc5bd MZ |
344 | |
345 | test_run_rebase () { | |
346 | result=$1 | |
347 | shift | |
348 | test_expect_$result "rebase $* -f --root on linear history causes re-write" " | |
349 | reset_rebase && | |
350 | git rebase $* -f --root c && | |
2c9e125b | 351 | test_cmp_rev ! a HEAD~2 && |
6a6bc5bd MZ |
352 | test_linear_range 'a b c' HEAD |
353 | " | |
354 | } | |
355 | test_run_rebase success '' | |
356 | test_run_rebase success -m | |
357 | test_run_rebase success -i | |
6a6bc5bd | 358 | |
2aad7cac | 359 | test_done |