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
32 test_have_prereq !REBASE_P || test_run_rebase success -p
34 test_expect_success 'setup branches and remote tracking' '
36 for tag in $(cat tags)
38 git branch branch-$tag $tag || return 1
40 git remote add origin "file://$PWD" &&
47 test_expect_$result "rebase $* is no-op if upstream is an ancestor" "
53 test_run_rebase success --apply
54 test_run_rebase success -m
55 test_run_rebase success -i
56 test_have_prereq !REBASE_P || test_run_rebase success -p
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
73 test_have_prereq !REBASE_P || test_run_rebase failure -p
78 test_expect_$result "rebase $* -f rewrites even if remote upstream is an ancestor" "
80 git rebase $* -f branch-b branch-e &&
81 test_cmp_rev ! branch-e origin/branch-e &&
82 test_cmp_rev branch-b HEAD~2 &&
83 test_linear_range 'd e' branch-b..
86 test_run_rebase success --apply
87 test_run_rebase success --fork-point
88 test_run_rebase success -m
89 test_run_rebase success -i
90 test_have_prereq !REBASE_P || test_run_rebase success -p
95 test_expect_$result "rebase $* fast-forwards from ancestor of upstream" "
101 test_run_rebase success --apply
102 test_run_rebase success --fork-point
103 test_run_rebase success -m
104 test_run_rebase success -i
105 test_have_prereq !REBASE_P || test_run_rebase success -p
113 # gp = cherry-picked g
116 # Reverted patches are there for tests to be able to check if a commit
117 # that introduced the same change as another commit is
118 # dropped. Without reverted commits, we could get false positives
119 # because applying the patch succeeds, but simply results in no
121 test_expect_success 'setup of linear history for range selection tests' '
135 test_expect_$result "rebase $* drops patches in upstream" "
138 test_cmp_rev h HEAD~2 &&
139 test_linear_range 'd i' h..
142 test_run_rebase success --apply
143 test_run_rebase success -m
144 test_run_rebase success -i
145 test_have_prereq !REBASE_P || test_run_rebase success -p
150 test_expect_$result "rebase $* can drop last patch if in upstream" "
152 git rebase $* h gp &&
153 test_cmp_rev h HEAD^ &&
154 test_linear_range 'd' h..
157 test_run_rebase success --apply
158 test_run_rebase success -m
159 test_run_rebase success -i
160 test_have_prereq !REBASE_P || test_run_rebase success -p
165 test_expect_$result "rebase $* --onto drops patches in upstream" "
167 git rebase $* --onto f h i &&
168 test_cmp_rev f HEAD~2 &&
169 test_linear_range 'd i' f..
172 test_run_rebase success --apply
173 test_run_rebase success -m
174 test_run_rebase success -i
175 test_have_prereq !REBASE_P || test_run_rebase success -p
180 test_expect_$result "rebase $* --onto does not drop patches in onto" "
182 git rebase $* --onto h f i &&
183 test_cmp_rev h HEAD~3 &&
184 test_linear_range 'd gp i' h..
187 test_run_rebase success --apply
188 test_run_rebase success -m
189 test_run_rebase success -i
190 test_have_prereq !REBASE_P || test_run_rebase success -p
197 test_expect_success 'setup of linear history for empty commit tests' '
208 test_expect_$result "rebase $* keeps begin-empty commits" "
211 test_cmp_rev c HEAD~4 &&
212 test_linear_range 'j d k l' c..
215 test_run_rebase failure --apply
216 test_run_rebase success -m
217 test_run_rebase success -i
218 test_have_prereq !REBASE_P || test_run_rebase failure -p
223 test_expect_$result "rebase $* --no-keep-empty drops begin-empty commits" "
225 git rebase $* --no-keep-empty c l &&
226 test_cmp_rev c HEAD~2 &&
227 test_linear_range 'd l' c..
230 test_run_rebase success -m
231 test_run_rebase success -i
232 test_have_prereq !REBASE_P || test_run_rebase success -p
237 test_expect_$result "rebase $* --keep-empty keeps empty even if already in upstream" "
239 git rebase $* --keep-empty j l &&
240 test_cmp_rev j HEAD~3 &&
241 test_linear_range 'd k l' j..
244 test_run_rebase success -m
245 test_run_rebase success -i
246 test_have_prereq !REBASE_P || test_run_rebase success -p
247 test_run_rebase success --rebase-merges
255 # bp = cherry-picked b
258 # Reverted patches are there for tests to be able to check if a commit
259 # that introduced the same change as another commit is
260 # dropped. Without reverted commits, we could get false positives
261 # because applying the patch succeeds, but simply results in no
263 test_expect_success 'setup of linear history for test involving root' '
266 git checkout --orphan disjoint &&
276 test_expect_$result "rebase $* --onto --root" "
278 git rebase $* --onto c --root y &&
279 test_cmp_rev c HEAD~2 &&
280 test_linear_range 'x y' c..
283 test_run_rebase success --apply
284 test_run_rebase success -m
285 test_run_rebase success -i
286 test_have_prereq !REBASE_P || test_run_rebase success -p
291 test_expect_$result "rebase $* without --onto --root with disjoint history" "
294 test_cmp_rev c HEAD~2 &&
295 test_linear_range 'x y' c..
298 test_run_rebase success --apply
299 test_run_rebase success -m
300 test_run_rebase success -i
301 test_have_prereq !REBASE_P || test_run_rebase failure -p
306 test_expect_$result "rebase $* --onto --root drops patch in onto" "
308 git rebase $* --onto m --root bp &&
309 test_cmp_rev m HEAD~2 &&
310 test_linear_range 'x y' m..
313 test_run_rebase success --apply
314 test_run_rebase success -m
315 test_run_rebase success -i
316 test_have_prereq !REBASE_P || test_run_rebase success -p
321 test_expect_$result "rebase $* --onto --root with merge-base does not go to root" "
323 git rebase $* --onto m --root g &&
324 test_cmp_rev m HEAD~2 &&
325 test_linear_range 'c g' m..
329 test_run_rebase success --apply
330 test_run_rebase success -m
331 test_run_rebase success -i
332 test_have_prereq !REBASE_P || test_run_rebase failure -p
337 test_expect_$result "rebase $* without --onto --root with disjoint history drops patch in onto" "
339 git rebase $* m bp &&
340 test_cmp_rev m HEAD~2 &&
341 test_linear_range 'x y' m..
344 test_run_rebase success --apply
345 test_run_rebase success -m
346 test_run_rebase success -i
347 test_have_prereq !REBASE_P || test_run_rebase failure -p
352 test_expect_$result "rebase $* --root on linear history is a no-op" "
354 git rebase $* --root c &&
358 test_run_rebase success ''
359 test_run_rebase success -m
360 test_run_rebase success -i
361 test_have_prereq !REBASE_P || test_run_rebase failure -p
366 test_expect_$result "rebase $* -f --root on linear history causes re-write" "
368 git rebase $* -f --root c &&
369 test_cmp_rev ! a HEAD~2 &&
370 test_linear_range 'a b c' HEAD
373 test_run_rebase success ''
374 test_run_rebase success -m
375 test_run_rebase success -i
376 test_have_prereq !REBASE_P || test_run_rebase success -p