3 test_description
='basic rebase topology tests'
5 .
"$TEST_DIRECTORY"/lib-rebase.sh
10 test_expect_success
'setup' '
22 test_expect_
$result "simple rebase $*" "
25 test_cmp_rev c HEAD~2 &&
26 test_linear_range 'd e' c..
29 test_run_rebase success
--apply
30 test_run_rebase success
-m
31 test_run_rebase success
-i
33 test_expect_success
'setup branches and remote tracking' '
35 for tag in $(cat tags)
37 git branch branch-$tag $tag || return 1
39 git remote add origin "file://$PWD" &&
46 test_expect_
$result "rebase $* is no-op if upstream is an ancestor" "
52 test_run_rebase success
--apply
53 test_run_rebase success
-m
54 test_run_rebase success
-i
59 test_expect_
$result "rebase $* -f rewrites even if upstream is an ancestor" "
61 git rebase $* -f b e &&
62 test_cmp_rev ! e HEAD &&
63 test_cmp_rev b HEAD~2 &&
64 test_linear_range 'd e' b..
67 test_run_rebase success
--apply
68 test_run_rebase success
--fork-point
69 test_run_rebase success
-m
70 test_run_rebase success
-i
75 test_expect_
$result "rebase $* -f rewrites even if remote upstream is an ancestor" "
77 git rebase $* -f branch-b branch-e &&
78 test_cmp_rev ! branch-e origin/branch-e &&
79 test_cmp_rev branch-b HEAD~2 &&
80 test_linear_range 'd e' branch-b..
83 test_run_rebase success
--apply
84 test_run_rebase success
--fork-point
85 test_run_rebase success
-m
86 test_run_rebase success
-i
91 test_expect_
$result "rebase $* fast-forwards from ancestor of upstream" "
97 test_run_rebase success
--apply
98 test_run_rebase success
--fork-point
99 test_run_rebase success
-m
100 test_run_rebase success
-i
108 # gp = cherry-picked g
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
116 test_expect_success
'setup of linear history for range selection tests' '
130 test_expect_
$result "rebase $* drops patches in upstream" "
133 test_cmp_rev h HEAD~2 &&
134 test_linear_range 'd i' h..
137 test_run_rebase success
--apply
138 test_run_rebase success
-m
139 test_run_rebase success
-i
144 test_expect_
$result "rebase $* can drop last patch if in upstream" "
146 git rebase $* h gp &&
147 test_cmp_rev h HEAD^ &&
148 test_linear_range 'd' h..
151 test_run_rebase success
--apply
152 test_run_rebase success
-m
153 test_run_rebase success
-i
158 test_expect_
$result "rebase $* --onto drops patches in upstream" "
160 git rebase $* --onto f h i &&
161 test_cmp_rev f HEAD~2 &&
162 test_linear_range 'd i' f..
165 test_run_rebase success
--apply
166 test_run_rebase success
-m
167 test_run_rebase success
-i
172 test_expect_
$result "rebase $* --onto does not drop patches in onto" "
174 git rebase $* --onto h f i &&
175 test_cmp_rev h HEAD~3 &&
176 test_linear_range 'd gp i' h..
179 test_run_rebase success
--apply
180 test_run_rebase success
-m
181 test_run_rebase success
-i
188 test_expect_success
'setup of linear history for empty commit tests' '
199 test_expect_
$result "rebase $* keeps begin-empty commits" "
202 test_cmp_rev c HEAD~4 &&
203 test_linear_range 'j d k l' c..
206 test_run_rebase failure
--apply
207 test_run_rebase success
-m
208 test_run_rebase success
-i
213 test_expect_
$result "rebase $* --no-keep-empty drops begin-empty commits" "
215 git rebase $* --no-keep-empty c l &&
216 test_cmp_rev c HEAD~2 &&
217 test_linear_range 'd l' c..
220 test_run_rebase success
-m
221 test_run_rebase success
-i
226 test_expect_
$result "rebase $* --keep-empty keeps empty even if already in upstream" "
228 git rebase $* --keep-empty j l &&
229 test_cmp_rev j HEAD~3 &&
230 test_linear_range 'd k l' j..
233 test_run_rebase success
-m
234 test_run_rebase success
-i
235 test_run_rebase success
--rebase-merges
243 # bp = cherry-picked b
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
251 test_expect_success
'setup of linear history for test involving root' '
254 git checkout --orphan disjoint &&
264 test_expect_
$result "rebase $* --onto --root" "
266 git rebase $* --onto c --root y &&
267 test_cmp_rev c HEAD~2 &&
268 test_linear_range 'x y' c..
271 test_run_rebase success
--apply
272 test_run_rebase success
-m
273 test_run_rebase success
-i
278 test_expect_
$result "rebase $* without --onto --root with disjoint history" "
281 test_cmp_rev c HEAD~2 &&
282 test_linear_range 'x y' c..
285 test_run_rebase success
--apply
286 test_run_rebase success
-m
287 test_run_rebase success
-i
292 test_expect_
$result "rebase $* --onto --root drops patch in onto" "
294 git rebase $* --onto m --root bp &&
295 test_cmp_rev m HEAD~2 &&
296 test_linear_range 'x y' m..
299 test_run_rebase success
--apply
300 test_run_rebase success
-m
301 test_run_rebase success
-i
306 test_expect_
$result "rebase $* --onto --root with merge-base does not go to root" "
308 git rebase $* --onto m --root g &&
309 test_cmp_rev m HEAD~2 &&
310 test_linear_range 'c g' m..
314 test_run_rebase success
--apply
315 test_run_rebase success
-m
316 test_run_rebase success
-i
321 test_expect_
$result "rebase $* without --onto --root with disjoint history drops patch in onto" "
323 git rebase $* m bp &&
324 test_cmp_rev m HEAD~2 &&
325 test_linear_range 'x y' m..
328 test_run_rebase success
--apply
329 test_run_rebase success
-m
330 test_run_rebase success
-i
335 test_expect_
$result "rebase $* --root on linear history is a no-op" "
337 git rebase $* --root c &&
341 test_run_rebase success
''
342 test_run_rebase success
-m
343 test_run_rebase success
-i
348 test_expect_
$result "rebase $* -f --root on linear history causes re-write" "
350 git rebase $* -f --root c &&
351 test_cmp_rev ! a HEAD~2 &&
352 test_linear_range 'a b c' HEAD
355 test_run_rebase success
''
356 test_run_rebase success
-m
357 test_run_rebase success
-i