interplane.Get Omega
Read in your language

git

[Ported from github.com/git/git] Sync with Git 2.56.1

Brought by drakestapleton

branch master Branches Tags History

git / t / t3421-rebase-topology-linear.sh

360 lines · 7834 bytes Raw Blame History
1#!/bin/sh
2
3test_description='basic rebase topology tests'
4
5. ./test-lib.sh
6. "$TEST_DIRECTORY"/lib-rebase.sh
7
8# a---b---c
9# \
10# d---e
11test_expect_success 'setup' '
12 test_commit a &&
13 test_commit b &&
14 test_commit c &&
15 git checkout b &&
16 test_commit d &&
17 test_commit e
18'
19
20test_run_rebase () {
21 result=$1
22 shift
23 test_expect_$result "simple rebase $*" "
24 reset_rebase &&
25 git rebase $* c e &&
26 test_cmp_rev c HEAD~2 &&
27 test_linear_range 'd e' c..
28 "
29}
30test_run_rebase success --apply
31test_run_rebase success -m
32test_run_rebase success -i
33
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
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}
53test_run_rebase success --apply
54test_run_rebase success -m
55test_run_rebase success -i
56
57test_run_rebase () {
58 result=$1
59 shift
60 test_expect_$result "rebase $* -f rewrites even if upstream is an ancestor" "
61 reset_rebase &&
62 git rebase $* -f b e &&
63 test_cmp_rev ! e HEAD &&
64 test_cmp_rev b HEAD~2 &&
65 test_linear_range 'd e' b..
66 "
67}
68test_run_rebase success --apply
69test_run_rebase success --fork-point
70test_run_rebase success -m
71test_run_rebase success -i
72
73test_run_rebase () {
74 result=$1
75 shift
76 test_expect_$result "rebase $* -f rewrites even if remote upstream is an ancestor" "
77 reset_rebase &&
78 git rebase $* -f branch-b branch-e &&
79 test_cmp_rev ! branch-e origin/branch-e &&
80 test_cmp_rev branch-b HEAD~2 &&
81 test_linear_range 'd e' branch-b..
82 "
83}
84test_run_rebase success --apply
85test_run_rebase success --fork-point
86test_run_rebase success -m
87test_run_rebase success -i
88
89test_run_rebase () {
90 result=$1
91 shift
92 test_expect_$result "rebase $* fast-forwards from ancestor of upstream" "
93 reset_rebase &&
94 git rebase $* e b &&
95 test_cmp_rev e HEAD
96 "
97}
98test_run_rebase success --apply
99test_run_rebase success --fork-point
100test_run_rebase success -m
101test_run_rebase success -i
102
103# f
104# /
105# a---b---c---g---h
106# \
107# d---gp--i
108#
109# gp = cherry-picked g
110# h = reverted g
111#
112# Reverted patches are there for tests to be able to check if a commit
113# that introduced the same change as another commit is
114# dropped. Without reverted commits, we could get false positives
115# because applying the patch succeeds, but simply results in no
116# changes.
117test_expect_success 'setup of linear history for range selection tests' '
118 git checkout c &&
119 test_commit g &&
120 revert h g &&
121 git checkout d &&
122 cherry_pick gp g &&
123 test_commit i &&
124 git checkout b &&
125 test_commit f
126'
127
128test_run_rebase () {
129 result=$1
130 shift
131 test_expect_$result "rebase $* drops patches in upstream" "
132 reset_rebase &&
133 git rebase $* h i &&
134 test_cmp_rev h HEAD~2 &&
135 test_linear_range 'd i' h..
136 "
137}
138test_run_rebase success --apply
139test_run_rebase success -m
140test_run_rebase success -i
141
142test_run_rebase () {
143 result=$1
144 shift
145 test_expect_$result "rebase $* can drop last patch if in upstream" "
146 reset_rebase &&
147 git rebase $* h gp &&
148 test_cmp_rev h HEAD^ &&
149 test_linear_range 'd' h..
150 "
151}
152test_run_rebase success --apply
153test_run_rebase success -m
154test_run_rebase success -i
155
156test_run_rebase () {
157 result=$1
158 shift
159 test_expect_$result "rebase $* --onto drops patches in upstream" "
160 reset_rebase &&
161 git rebase $* --onto f h i &&
162 test_cmp_rev f HEAD~2 &&
163 test_linear_range 'd i' f..
164 "
165}
166test_run_rebase success --apply
167test_run_rebase success -m
168test_run_rebase success -i
169
170test_run_rebase () {
171 result=$1
172 shift
173 test_expect_$result "rebase $* --onto does not drop patches in onto" "
174 reset_rebase &&
175 git rebase $* --onto h f i &&
176 test_cmp_rev h HEAD~3 &&
177 test_linear_range 'd gp i' h..
178 "
179}
180test_run_rebase success --apply
181test_run_rebase success -m
182test_run_rebase success -i
183
184# a---b---c---j!
185# \
186# d---k!--l
187#
188# ! = empty
189test_expect_success 'setup of linear history for empty commit tests' '
190 git checkout c &&
191 make_empty j &&
192 git checkout d &&
193 make_empty k &&
194 test_commit l
195'
196
197test_run_rebase () {
198 result=$1
199 shift
200 test_expect_$result "rebase $* keeps begin-empty commits" "
201 reset_rebase &&
202 git rebase $* j l &&
203 test_cmp_rev c HEAD~4 &&
204 test_linear_range 'j d k l' c..
205 "
206}
207test_run_rebase failure --apply
208test_run_rebase success -m
209test_run_rebase success -i
210
211test_run_rebase () {
212 result=$1
213 shift
214 test_expect_$result "rebase $* --no-keep-empty drops begin-empty commits" "
215 reset_rebase &&
216 git rebase $* --no-keep-empty c l &&
217 test_cmp_rev c HEAD~2 &&
218 test_linear_range 'd l' c..
219 "
220}
221test_run_rebase success -m
222test_run_rebase success -i
223
224test_run_rebase () {
225 result=$1
226 shift
227 test_expect_$result "rebase $* --keep-empty keeps empty even if already in upstream" "
228 reset_rebase &&
229 git rebase $* --keep-empty j l &&
230 test_cmp_rev j HEAD~3 &&
231 test_linear_range 'd k l' j..
232 "
233}
234test_run_rebase success -m
235test_run_rebase success -i
236test_run_rebase success --rebase-merges
237
238# m
239# /
240# a---b---c---g
241#
242# x---y---bp
243#
244# bp = cherry-picked b
245# m = reverted b
246#
247# Reverted patches are there for tests to be able to check if a commit
248# that introduced the same change as another commit is
249# dropped. Without reverted commits, we could get false positives
250# because applying the patch succeeds, but simply results in no
251# changes.
252test_expect_success 'setup of linear history for test involving root' '
253 git checkout b &&
254 revert m b &&
255 git checkout --orphan disjoint &&
256 git rm -rf . &&
257 test_commit x &&
258 test_commit y &&
259 cherry_pick bp b
260'
261
262test_run_rebase () {
263 result=$1
264 shift
265 test_expect_$result "rebase $* --onto --root" "
266 reset_rebase &&
267 git rebase $* --onto c --root y &&
268 test_cmp_rev c HEAD~2 &&
269 test_linear_range 'x y' c..
270 "
271}
272test_run_rebase success --apply
273test_run_rebase success -m
274test_run_rebase success -i
275
276test_run_rebase () {
277 result=$1
278 shift
279 test_expect_$result "rebase $* without --onto --root with disjoint history" "
280 reset_rebase &&
281 git rebase $* c y &&
282 test_cmp_rev c HEAD~2 &&
283 test_linear_range 'x y' c..
284 "
285}
286test_run_rebase success --apply
287test_run_rebase success -m
288test_run_rebase success -i
289
290test_run_rebase () {
291 result=$1
292 shift
293 test_expect_$result "rebase $* --onto --root drops patch in onto" "
294 reset_rebase &&
295 git rebase $* --onto m --root bp &&
296 test_cmp_rev m HEAD~2 &&
297 test_linear_range 'x y' m..
298 "
299}
300test_run_rebase success --apply
301test_run_rebase success -m
302test_run_rebase success -i
303
304test_run_rebase () {
305 result=$1
306 shift
307 test_expect_$result "rebase $* --onto --root with merge-base does not go to root" "
308 reset_rebase &&
309 git rebase $* --onto m --root g &&
310 test_cmp_rev m HEAD~2 &&
311 test_linear_range 'c g' m..
312 "
313}
314
315test_run_rebase success --apply
316test_run_rebase success -m
317test_run_rebase success -i
318
319test_run_rebase () {
320 result=$1
321 shift
322 test_expect_$result "rebase $* without --onto --root with disjoint history drops patch in onto" "
323 reset_rebase &&
324 git rebase $* m bp &&
325 test_cmp_rev m HEAD~2 &&
326 test_linear_range 'x y' m..
327 "
328}
329test_run_rebase success --apply
330test_run_rebase success -m
331test_run_rebase success -i
332
333test_run_rebase () {
334 result=$1
335 shift
336 test_expect_$result "rebase $* --root on linear history is a no-op" "
337 reset_rebase &&
338 git rebase $* --root c &&
339 test_cmp_rev c HEAD
340 "
341}
342test_run_rebase success ''
343test_run_rebase success -m
344test_run_rebase success -i
345
346test_run_rebase () {
347 result=$1
348 shift
349 test_expect_$result "rebase $* -f --root on linear history causes re-write" "
350 reset_rebase &&
351 git rebase $* -f --root c &&
352 test_cmp_rev ! a HEAD~2 &&
353 test_linear_range 'a b c' HEAD
354 "
355}
356test_run_rebase success ''
357test_run_rebase success -m
358test_run_rebase success -i
359
360test_done