3 test_description
='basic rebase topology tests'
5 TEST_PASSES_SANITIZE_LEAK
=true
7 .
"$TEST_DIRECTORY"/lib-rebase.sh
12 test_expect_success
'setup' '
24 test_expect_
$result "simple rebase $*" "
27 test_cmp_rev c HEAD~2 &&
28 test_linear_range 'd e' c..
31 test_run_rebase success
--apply
32 test_run_rebase success
-m
33 test_run_rebase success
-i
35 test_expect_success
'setup branches and remote tracking' '
37 for tag in $(cat tags)
39 git branch branch-$tag $tag || return 1
41 git remote add origin "file://$PWD" &&
48 test_expect_
$result "rebase $* is no-op if upstream is an ancestor" "
54 test_run_rebase success
--apply
55 test_run_rebase success
-m
56 test_run_rebase success
-i
61 test_expect_
$result "rebase $* -f rewrites even if upstream is an ancestor" "
63 git rebase $* -f b e &&
64 test_cmp_rev ! e HEAD &&
65 test_cmp_rev b HEAD~2 &&
66 test_linear_range 'd e' b..
69 test_run_rebase success
--apply
70 test_run_rebase success
--fork-point
71 test_run_rebase success
-m
72 test_run_rebase success
-i
77 test_expect_
$result "rebase $* -f rewrites even if remote upstream is an ancestor" "
79 git rebase $* -f branch-b branch-e &&
80 test_cmp_rev ! branch-e origin/branch-e &&
81 test_cmp_rev branch-b HEAD~2 &&
82 test_linear_range 'd e' branch-b..
85 test_run_rebase success
--apply
86 test_run_rebase success
--fork-point
87 test_run_rebase success
-m
88 test_run_rebase success
-i
93 test_expect_
$result "rebase $* fast-forwards from ancestor of upstream" "
99 test_run_rebase success
--apply
100 test_run_rebase success
--fork-point
101 test_run_rebase success
-m
102 test_run_rebase success
-i
110 # gp = cherry-picked g
113 # Reverted patches are there for tests to be able to check if a commit
114 # that introduced the same change as another commit is
115 # dropped. Without reverted commits, we could get false positives
116 # because applying the patch succeeds, but simply results in no
118 test_expect_success
'setup of linear history for range selection tests' '
132 test_expect_
$result "rebase $* drops patches in upstream" "
135 test_cmp_rev h HEAD~2 &&
136 test_linear_range 'd i' h..
139 test_run_rebase success
--apply
140 test_run_rebase success
-m
141 test_run_rebase success
-i
146 test_expect_
$result "rebase $* can drop last patch if in upstream" "
148 git rebase $* h gp &&
149 test_cmp_rev h HEAD^ &&
150 test_linear_range 'd' h..
153 test_run_rebase success
--apply
154 test_run_rebase success
-m
155 test_run_rebase success
-i
160 test_expect_
$result "rebase $* --onto drops patches in upstream" "
162 git rebase $* --onto f h i &&
163 test_cmp_rev f HEAD~2 &&
164 test_linear_range 'd i' f..
167 test_run_rebase success
--apply
168 test_run_rebase success
-m
169 test_run_rebase success
-i
174 test_expect_
$result "rebase $* --onto does not drop patches in onto" "
176 git rebase $* --onto h f i &&
177 test_cmp_rev h HEAD~3 &&
178 test_linear_range 'd gp i' h..
181 test_run_rebase success
--apply
182 test_run_rebase success
-m
183 test_run_rebase success
-i
190 test_expect_success
'setup of linear history for empty commit tests' '
201 test_expect_
$result "rebase $* keeps begin-empty commits" "
204 test_cmp_rev c HEAD~4 &&
205 test_linear_range 'j d k l' c..
208 test_run_rebase failure
--apply
209 test_run_rebase success
-m
210 test_run_rebase success
-i
215 test_expect_
$result "rebase $* --no-keep-empty drops begin-empty commits" "
217 git rebase $* --no-keep-empty c l &&
218 test_cmp_rev c HEAD~2 &&
219 test_linear_range 'd l' c..
222 test_run_rebase success
-m
223 test_run_rebase success
-i
228 test_expect_
$result "rebase $* --keep-empty keeps empty even if already in upstream" "
230 git rebase $* --keep-empty j l &&
231 test_cmp_rev j HEAD~3 &&
232 test_linear_range 'd k l' j..
235 test_run_rebase success
-m
236 test_run_rebase success
-i
237 test_run_rebase success
--rebase-merges
245 # bp = cherry-picked b
248 # Reverted patches are there for tests to be able to check if a commit
249 # that introduced the same change as another commit is
250 # dropped. Without reverted commits, we could get false positives
251 # because applying the patch succeeds, but simply results in no
253 test_expect_success
'setup of linear history for test involving root' '
256 git checkout --orphan disjoint &&
266 test_expect_
$result "rebase $* --onto --root" "
268 git rebase $* --onto c --root y &&
269 test_cmp_rev c HEAD~2 &&
270 test_linear_range 'x y' c..
273 test_run_rebase success
--apply
274 test_run_rebase success
-m
275 test_run_rebase success
-i
280 test_expect_
$result "rebase $* without --onto --root with disjoint history" "
283 test_cmp_rev c HEAD~2 &&
284 test_linear_range 'x y' c..
287 test_run_rebase success
--apply
288 test_run_rebase success
-m
289 test_run_rebase success
-i
294 test_expect_
$result "rebase $* --onto --root drops patch in onto" "
296 git rebase $* --onto m --root bp &&
297 test_cmp_rev m HEAD~2 &&
298 test_linear_range 'x y' m..
301 test_run_rebase success
--apply
302 test_run_rebase success
-m
303 test_run_rebase success
-i
308 test_expect_
$result "rebase $* --onto --root with merge-base does not go to root" "
310 git rebase $* --onto m --root g &&
311 test_cmp_rev m HEAD~2 &&
312 test_linear_range 'c g' m..
316 test_run_rebase success
--apply
317 test_run_rebase success
-m
318 test_run_rebase success
-i
323 test_expect_
$result "rebase $* without --onto --root with disjoint history drops patch in onto" "
325 git rebase $* m bp &&
326 test_cmp_rev m HEAD~2 &&
327 test_linear_range 'x y' m..
330 test_run_rebase success
--apply
331 test_run_rebase success
-m
332 test_run_rebase success
-i
337 test_expect_
$result "rebase $* --root on linear history is a no-op" "
339 git rebase $* --root c &&
343 test_run_rebase success
''
344 test_run_rebase success
-m
345 test_run_rebase success
-i
350 test_expect_
$result "rebase $* -f --root on linear history causes re-write" "
352 git rebase $* -f --root c &&
353 test_cmp_rev ! a HEAD~2 &&
354 test_linear_range 'a b c' HEAD
357 test_run_rebase success
''
358 test_run_rebase success
-m
359 test_run_rebase success
-i