revision: fix leaking parents when simplifying commits
[git/gitster.git] / t / t3421-rebase-topology-linear.sh
blob737af80bb3dbb205346a3b6ccedf6cbb34fbfab2
1 #!/bin/sh
3 test_description='basic rebase topology tests'
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
7 . "$TEST_DIRECTORY"/lib-rebase.sh
9 # a---b---c
10 # \
11 # d---e
12 test_expect_success 'setup' '
13 test_commit a &&
14 test_commit b &&
15 test_commit c &&
16 git checkout b &&
17 test_commit d &&
18 test_commit e
21 test_run_rebase () {
22 result=$1
23 shift
24 test_expect_$result "simple rebase $*" "
25 reset_rebase &&
26 git rebase $* c e &&
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' '
36 git tag -l >tags &&
37 for tag in $(cat tags)
39 git branch branch-$tag $tag || return 1
40 done &&
41 git remote add origin "file://$PWD" &&
42 git fetch origin
45 test_run_rebase () {
46 result=$1
47 shift
48 test_expect_$result "rebase $* is no-op if upstream is an ancestor" "
49 reset_rebase &&
50 git rebase $* b e &&
51 test_cmp_rev e HEAD
54 test_run_rebase success --apply
55 test_run_rebase success -m
56 test_run_rebase success -i
58 test_run_rebase () {
59 result=$1
60 shift
61 test_expect_$result "rebase $* -f rewrites even if upstream is an ancestor" "
62 reset_rebase &&
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
74 test_run_rebase () {
75 result=$1
76 shift
77 test_expect_$result "rebase $* -f rewrites even if remote upstream is an ancestor" "
78 reset_rebase &&
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
90 test_run_rebase () {
91 result=$1
92 shift
93 test_expect_$result "rebase $* fast-forwards from ancestor of upstream" "
94 reset_rebase &&
95 git rebase $* e b &&
96 test_cmp_rev e HEAD
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
106 # a---b---c---g---h
108 # d---gp--i
110 # gp = cherry-picked g
111 # h = reverted 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
117 # changes.
118 test_expect_success 'setup of linear history for range selection tests' '
119 git checkout c &&
120 test_commit g &&
121 revert h g &&
122 git checkout d &&
123 cherry_pick gp g &&
124 test_commit i &&
125 git checkout b &&
126 test_commit f
129 test_run_rebase () {
130 result=$1
131 shift
132 test_expect_$result "rebase $* drops patches in upstream" "
133 reset_rebase &&
134 git rebase $* h i &&
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
143 test_run_rebase () {
144 result=$1
145 shift
146 test_expect_$result "rebase $* can drop last patch if in upstream" "
147 reset_rebase &&
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
157 test_run_rebase () {
158 result=$1
159 shift
160 test_expect_$result "rebase $* --onto drops patches in upstream" "
161 reset_rebase &&
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
171 test_run_rebase () {
172 result=$1
173 shift
174 test_expect_$result "rebase $* --onto does not drop patches in onto" "
175 reset_rebase &&
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
185 # a---b---c---j!
187 # d---k!--l
189 # ! = empty
190 test_expect_success 'setup of linear history for empty commit tests' '
191 git checkout c &&
192 make_empty j &&
193 git checkout d &&
194 make_empty k &&
195 test_commit l
198 test_run_rebase () {
199 result=$1
200 shift
201 test_expect_$result "rebase $* keeps begin-empty commits" "
202 reset_rebase &&
203 git rebase $* j l &&
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
212 test_run_rebase () {
213 result=$1
214 shift
215 test_expect_$result "rebase $* --no-keep-empty drops begin-empty commits" "
216 reset_rebase &&
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
225 test_run_rebase () {
226 result=$1
227 shift
228 test_expect_$result "rebase $* --keep-empty keeps empty even if already in upstream" "
229 reset_rebase &&
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
241 # a---b---c---g
243 # x---y---bp
245 # bp = cherry-picked b
246 # m = reverted 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
252 # changes.
253 test_expect_success 'setup of linear history for test involving root' '
254 git checkout b &&
255 revert m b &&
256 git checkout --orphan disjoint &&
257 git rm -rf . &&
258 test_commit x &&
259 test_commit y &&
260 cherry_pick bp b
263 test_run_rebase () {
264 result=$1
265 shift
266 test_expect_$result "rebase $* --onto --root" "
267 reset_rebase &&
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
277 test_run_rebase () {
278 result=$1
279 shift
280 test_expect_$result "rebase $* without --onto --root with disjoint history" "
281 reset_rebase &&
282 git rebase $* c y &&
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
291 test_run_rebase () {
292 result=$1
293 shift
294 test_expect_$result "rebase $* --onto --root drops patch in onto" "
295 reset_rebase &&
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
305 test_run_rebase () {
306 result=$1
307 shift
308 test_expect_$result "rebase $* --onto --root with merge-base does not go to root" "
309 reset_rebase &&
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
320 test_run_rebase () {
321 result=$1
322 shift
323 test_expect_$result "rebase $* without --onto --root with disjoint history drops patch in onto" "
324 reset_rebase &&
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
334 test_run_rebase () {
335 result=$1
336 shift
337 test_expect_$result "rebase $* --root on linear history is a no-op" "
338 reset_rebase &&
339 git rebase $* --root c &&
340 test_cmp_rev c HEAD
343 test_run_rebase success ''
344 test_run_rebase success -m
345 test_run_rebase success -i
347 test_run_rebase () {
348 result=$1
349 shift
350 test_expect_$result "rebase $* -f --root on linear history causes re-write" "
351 reset_rebase &&
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
361 test_done