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