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