bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
7321.2.1
by Jelmer Vernooij
Bundle the quilt plugin. |
1 |
# Copyright (C) 2011 Canonical Ltd
|
|
7321.2.5
by Jelmer Vernooij
Deunicodify my surname. |
2 |
# Copyright (C) 2019 Jelmer Vernooij <jelmer@jelmer.uk>
|
|
7321.2.3
by Jelmer Vernooij
Fix flake8 errors. |
3 |
#
|
4 |
# Breezy is free software; you can redistribute it and/or modify
|
|
|
7321.2.1
by Jelmer Vernooij
Bundle the quilt plugin. |
5 |
# it under the terms of the GNU General Public License as published by
|
6 |
# the Free Software Foundation; either version 2 of the License, or
|
|
7 |
# (at your option) any later version.
|
|
8 |
#
|
|
|
7321.2.3
by Jelmer Vernooij
Fix flake8 errors. |
9 |
# Breezy is distributed in the hope that it will be useful,
|
|
7321.2.1
by Jelmer Vernooij
Bundle the quilt plugin. |
10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 |
# GNU General Public License for more details.
|
|
13 |
#
|
|
14 |
# You should have received a copy of the GNU General Public License
|
|
|
7321.2.3
by Jelmer Vernooij
Fix flake8 errors. |
15 |
# along with Breezy; if not, write to the Free Software
|
|
7321.2.1
by Jelmer Vernooij
Bundle the quilt plugin. |
16 |
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
17 |
#
|
|
18 |
||
19 |
"""Tests for the merge_quilt code."""
|
|
20 |
||
21 |
import os |
|
22 |
import shutil |
|
23 |
||
24 |
from .... import ( |
|
|
7321.2.7
by Jelmer Vernooij
Merge trunk. |
25 |
bedding, |
|
7321.2.1
by Jelmer Vernooij
Bundle the quilt plugin. |
26 |
config, |
27 |
errors, |
|
28 |
trace, |
|
29 |
)
|
|
30 |
from ....merge import Merger |
|
31 |
from ....mutabletree import MutableTree |
|
32 |
||
33 |
from .. import ( |
|
34 |
pre_merge_quilt, |
|
35 |
start_commit_check_quilt, |
|
36 |
post_build_tree_quilt, |
|
37 |
post_merge_quilt_cleanup, |
|
38 |
)
|
|
39 |
from ..quilt import QuiltPatches |
|
40 |
from ..merge import tree_unapply_patches |
|
41 |
||
42 |
from .test_wrapper import quilt_feature |
|
43 |
||
44 |
from ....tests import ( |
|
45 |
TestCaseWithTransport, |
|
46 |
TestSkipped, |
|
47 |
)
|
|
48 |
||
49 |
TRIVIAL_PATCH = """--- /dev/null 2012-01-02 01:09:10.986490031 +0100 |
|
50 |
+++ base/a 2012-01-02 20:03:59.710666215 +0100
|
|
51 |
@@ -0,0 +1 @@
|
|
52 |
+a
|
|
53 |
"""
|
|
54 |
||
55 |
||
56 |
def quilt_push_all(tree): |
|
57 |
QuiltPatches(tree, 'debian/patches').push_all() |
|
58 |
||
59 |
||
60 |
class TestTreeUnapplyPatches(TestCaseWithTransport): |
|
61 |
||
62 |
_test_needs_features = [quilt_feature] |
|
63 |
||
64 |
def test_no_patches(self): |
|
65 |
tree = self.make_branch_and_tree('.') |
|
66 |
new_tree, target_dir = tree_unapply_patches(tree) |
|
67 |
self.assertIs(tree, new_tree) |
|
68 |
self.assertIs(None, target_dir) |
|
69 |
||
70 |
def test_unapply(self): |
|
71 |
orig_tree = self.make_branch_and_tree('source') |
|
72 |
self.build_tree(["source/debian/", "source/debian/patches/"]) |
|
73 |
self.build_tree_contents([ |
|
74 |
("source/debian/patches/series", "patch1.diff\n"), |
|
75 |
("source/debian/patches/patch1.diff", TRIVIAL_PATCH)]) |
|
76 |
quilt_push_all(orig_tree) |
|
77 |
orig_tree.smart_add([orig_tree.basedir]) |
|
78 |
tree, target_dir = tree_unapply_patches(orig_tree) |
|
79 |
self.addCleanup(shutil.rmtree, target_dir) |
|
80 |
self.assertPathExists("source/a") |
|
81 |
self.assertNotEqual(tree.basedir, orig_tree.basedir) |
|
82 |
self.assertPathDoesNotExist(tree.abspath("a")) |
|
83 |
self.assertPathExists(tree.abspath("debian/patches/series")) |
|
84 |
||
85 |
def test_unapply_nothing_applied(self): |
|
86 |
orig_tree = self.make_branch_and_tree('source') |
|
87 |
self.build_tree(["source/debian/", "source/debian/patches/"]) |
|
88 |
self.build_tree_contents([ |
|
89 |
("source/debian/patches/series", "patch1.diff\n"), |
|
90 |
("source/debian/patches/patch1.diff", TRIVIAL_PATCH)]) |
|
91 |
orig_tree.smart_add([orig_tree.basedir]) |
|
92 |
tree, target_dir = tree_unapply_patches(orig_tree) |
|
93 |
self.assertIs(tree, orig_tree) |
|
94 |
self.assertIs(None, target_dir) |
|
95 |
||
96 |
||
97 |
class TestMergeHook(TestCaseWithTransport): |
|
98 |
||
99 |
_test_needs_features = [quilt_feature] |
|
100 |
||
101 |
def enable_hooks(self): |
|
102 |
Merger.hooks.install_named_hook( |
|
103 |
'pre_merge', pre_merge_quilt, |
|
104 |
'Debian quilt patch (un)applying and ancestry fixing') |
|
105 |
Merger.hooks.install_named_hook( |
|
106 |
'post_merge', post_merge_quilt_cleanup, |
|
107 |
'Cleaning up quilt temporary directories') |
|
108 |
MutableTree.hooks.install_named_hook( |
|
109 |
"post_build_tree", post_build_tree_quilt, |
|
110 |
"Apply quilt trees.") |
|
111 |
||
112 |
def test_diverged_patches(self): |
|
113 |
self.enable_hooks() |
|
114 |
||
115 |
tree_a = self.make_branch_and_tree('a') |
|
116 |
self.build_tree( |
|
117 |
['a/debian/', 'a/debian/patches/', 'a/debian/source/', 'a/.pc/']) |
|
118 |
self.build_tree_contents([ |
|
|
7321.2.9
by Jelmer Vernooij
Don't use paths in series environment variable. |
119 |
('a/.pc/.quilt_patches', 'debian/patches\n'), |
120 |
('a/.pc/.version', '2\n'), |
|
|
7321.2.1
by Jelmer Vernooij
Bundle the quilt plugin. |
121 |
('a/debian/source/format', '3.0 (quilt)'), |
122 |
('a/debian/patches/series', 'patch1\n'), |
|
123 |
('a/debian/patches/patch1', TRIVIAL_PATCH)]) |
|
124 |
tree_a.smart_add([tree_a.basedir]) |
|
125 |
tree_a.commit('initial') |
|
126 |
||
127 |
tree_b = tree_a.controldir.sprout('b').open_workingtree() |
|
128 |
self.build_tree_contents([ |
|
129 |
('a/debian/patches/patch1', |
|
130 |
"\n".join(TRIVIAL_PATCH.splitlines()[:-1] + ["+d\n"]))]) |
|
131 |
quilt_push_all(tree_a) |
|
132 |
tree_a.smart_add([tree_a.basedir]) |
|
133 |
tree_a.commit('apply patches') |
|
134 |
self.build_tree_contents([ |
|
135 |
('b/debian/patches/patch1', |
|
136 |
"\n".join(TRIVIAL_PATCH.splitlines()[:-1] + ["+c\n"]))]) |
|
137 |
quilt_push_all(tree_b) |
|
138 |
tree_b.commit('apply patches') |
|
139 |
conflicts = tree_a.merge_from_branch(tree_b.branch) |
|
140 |
self.assertFileEqual("""\ |
|
141 |
--- /dev/null\t2012-01-02 01:09:10.986490031 +0100 |
|
142 |
+++ base/a\t2012-01-02 20:03:59.710666215 +0100 |
|
143 |
@@ -0,0 +1 @@
|
|
144 |
<<<<<<< TREE
|
|
145 |
+d
|
|
146 |
=======
|
|
147 |
+c
|
|
148 |
>>>>>>> MERGE-SOURCE
|
|
149 |
""", "a/debian/patches/patch1") |
|
150 |
# "a" should be unapplied again
|
|
151 |
self.assertPathDoesNotExist("a/a") |
|
152 |
self.assertEquals(1, conflicts) |
|
153 |
||
154 |
def test_auto_apply_patches_after_checkout(self): |
|
155 |
self.enable_hooks() |
|
156 |
||
157 |
tree_a = self.make_branch_and_tree('a') |
|
158 |
||
159 |
self.build_tree(['a/debian/', 'a/debian/patches/']) |
|
160 |
self.build_tree_contents([ |
|
161 |
('a/debian/patches/series', 'patch1\n'), |
|
162 |
('a/debian/patches/patch1', TRIVIAL_PATCH)]) |
|
163 |
tree_a.smart_add([tree_a.basedir]) |
|
164 |
tree_a.commit('initial') |
|
165 |
||
|
7321.2.7
by Jelmer Vernooij
Merge trunk. |
166 |
bedding.ensure_config_dir_exists() |
|
7321.2.1
by Jelmer Vernooij
Bundle the quilt plugin. |
167 |
config.GlobalStack().set('quilt.tree_policy', 'applied') |
168 |
||
169 |
tree_a.branch.create_checkout("b") |
|
170 |
self.assertFileEqual("a\n", "b/a") |
|
171 |
||
172 |
def test_auto_apply_patches_after_update_format_1(self): |
|
173 |
self.enable_hooks() |
|
174 |
||
175 |
tree_a = self.make_branch_and_tree('a') |
|
176 |
tree_b = tree_a.branch.create_checkout("b") |
|
177 |
||
178 |
self.build_tree(['a/debian/', 'a/debian/patches/', 'a/.pc/']) |
|
179 |
self.build_tree_contents([ |
|
|
7321.2.9
by Jelmer Vernooij
Don't use paths in series environment variable. |
180 |
('a/.pc/.quilt_patches', 'debian/patches\n'), |
181 |
('a/.pc/.version', '2\n'), |
|
|
7321.2.1
by Jelmer Vernooij
Bundle the quilt plugin. |
182 |
('a/debian/patches/series', 'patch1\n'), |
183 |
('a/debian/patches/patch1', TRIVIAL_PATCH)]) |
|
184 |
tree_a.smart_add([tree_a.basedir]) |
|
185 |
tree_a.commit('initial') |
|
186 |
||
187 |
self.build_tree(["b/.bzr-builddeb/", "b/debian/", "b/debian/source/"]) |
|
188 |
tree_b.get_config_stack().set('quilt.tree_policy', 'applied') |
|
189 |
self.build_tree_contents([ |
|
190 |
("b/debian/source/format", "1.0")]) |
|
191 |
||
192 |
tree_b.update() |
|
193 |
self.assertFileEqual("a\n", "b/a") |
|
194 |
||
195 |
def test_auto_apply_patches_after_update(self): |
|
196 |
self.enable_hooks() |
|
197 |
||
198 |
tree_a = self.make_branch_and_tree('a') |
|
199 |
tree_b = tree_a.branch.create_checkout("b") |
|
200 |
||
201 |
self.build_tree(['a/debian/', 'a/debian/patches/', 'a/debian/source/', 'a/.pc/']) |
|
202 |
self.build_tree_contents([ |
|
|
7321.2.9
by Jelmer Vernooij
Don't use paths in series environment variable. |
203 |
('a/.pc/.quilt_patches', 'debian/patches\n'), |
204 |
('a/.pc/.version', '2\n'), |
|
|
7321.2.1
by Jelmer Vernooij
Bundle the quilt plugin. |
205 |
('a/debian/source/format', '3.0 (quilt)'), |
206 |
('a/debian/patches/series', 'patch1\n'), |
|
207 |
('a/debian/patches/patch1', TRIVIAL_PATCH)]) |
|
208 |
tree_a.smart_add([tree_a.basedir]) |
|
209 |
tree_a.commit('initial') |
|
210 |
||
211 |
self.build_tree(["b/.bzr-builddeb/", "b/debian/", "b/debian/source/"]) |
|
212 |
tree_b.get_config_stack().set('quilt.tree_policy', 'applied') |
|
213 |
self.build_tree_contents([ |
|
214 |
('b/debian/source/format', '3.0 (quilt)'), |
|
215 |
])
|
|
216 |
||
217 |
tree_b.update() |
|
218 |
self.assertFileEqual("a\n", "b/a") |
|
219 |
||
220 |
def test_auto_unapply_patches_after_update(self): |
|
221 |
self.enable_hooks() |
|
222 |
||
223 |
tree_a = self.make_branch_and_tree('a') |
|
224 |
tree_b = tree_a.branch.create_checkout("b") |
|
225 |
||
226 |
self.build_tree(['a/debian/', 'a/debian/patches/', 'a/debian/source/', 'a/.pc/']) |
|
227 |
self.build_tree_contents([ |
|
|
7321.2.9
by Jelmer Vernooij
Don't use paths in series environment variable. |
228 |
('a/.pc/.quilt_patches', 'debian/patches\n'), |
229 |
('a/.pc/.version', '2\n'), |
|
|
7321.2.1
by Jelmer Vernooij
Bundle the quilt plugin. |
230 |
('a/debian/source/format', '3.0 (quilt)'), |
231 |
('a/debian/patches/series', 'patch1\n'), |
|
232 |
('a/debian/patches/patch1', TRIVIAL_PATCH)]) |
|
233 |
tree_a.smart_add([tree_a.basedir]) |
|
234 |
tree_a.commit('initial') |
|
235 |
||
236 |
self.build_tree(["b/.bzr-builddeb/"]) |
|
237 |
tree_b.get_config_stack().set('quilt.tree_policy', 'unapplied') |
|
238 |
||
239 |
tree_b.update() |
|
240 |
self.assertPathDoesNotExist("b/a") |
|
241 |
||
242 |
def test_disabled_hook(self): |
|
243 |
self.enable_hooks() |
|
244 |
||
245 |
tree_a = self.make_branch_and_tree('a') |
|
246 |
tree_a.get_config_stack().set('quilt.smart_merge', False) |
|
247 |
self.build_tree(['a/debian/', 'a/debian/patches/', 'a/.pc/']) |
|
248 |
self.build_tree_contents([ |
|
|
7321.2.9
by Jelmer Vernooij
Don't use paths in series environment variable. |
249 |
('a/.pc/.quilt_patches', 'debian/patches\n'), |
250 |
('a/.pc/.version', '2\n'), |
|
|
7321.2.1
by Jelmer Vernooij
Bundle the quilt plugin. |
251 |
('a/debian/patches/series', 'patch1\n'), |
252 |
('a/debian/patches/patch1', TRIVIAL_PATCH), |
|
253 |
("a/a", "")]) |
|
254 |
tree_a.smart_add([tree_a.basedir]) |
|
255 |
tree_a.commit('initial') |
|
256 |
||
257 |
tree_b = tree_a.controldir.sprout('b').open_workingtree() |
|
258 |
self.build_tree_contents([ |
|
259 |
('a/debian/patches/patch1', |
|
260 |
"\n".join(TRIVIAL_PATCH.splitlines()[:-1] + ["+d\n"]))]) |
|
261 |
quilt_push_all(tree_a) |
|
262 |
tree_a.smart_add([tree_a.basedir]) |
|
263 |
tree_a.commit('apply patches') |
|
264 |
self.assertFileEqual("d\n", "a/a") |
|
265 |
self.build_tree_contents([ |
|
266 |
('b/debian/patches/patch1', |
|
267 |
"\n".join(TRIVIAL_PATCH.splitlines()[:-1] + ["+c\n"]))]) |
|
268 |
quilt_push_all(tree_b) |
|
269 |
tree_b.commit('apply patches') |
|
270 |
self.assertFileEqual("c\n", "b/a") |
|
271 |
conflicts = tree_a.merge_from_branch(tree_b.branch) |
|
272 |
self.assertFileEqual("""\ |
|
273 |
--- /dev/null\t2012-01-02 01:09:10.986490031 +0100 |
|
274 |
+++ base/a\t2012-01-02 20:03:59.710666215 +0100 |
|
275 |
@@ -0,0 +1 @@
|
|
276 |
<<<<<<< TREE
|
|
277 |
+d
|
|
278 |
=======
|
|
279 |
+c
|
|
280 |
>>>>>>> MERGE-SOURCE
|
|
281 |
""", "a/debian/patches/patch1") |
|
282 |
self.assertFileEqual("""\ |
|
283 |
<<<<<<< TREE
|
|
284 |
d
|
|
285 |
=======
|
|
286 |
c
|
|
287 |
>>>>>>> MERGE-SOURCE
|
|
288 |
""", "a/a") |
|
289 |
self.assertEquals(2, conflicts) |
|
290 |
||
291 |
||
292 |
||
293 |
class StartCommitMergeHookTests(TestCaseWithTransport): |
|
294 |
||
|
7321.2.4
by Jelmer Vernooij
Require quilt for merge tests. |
295 |
_test_needs_features = [quilt_feature] |
296 |
||
|
7321.2.1
by Jelmer Vernooij
Bundle the quilt plugin. |
297 |
def enable_hooks(self): |
298 |
MutableTree.hooks.install_named_hook( |
|
299 |
'start_commit', start_commit_check_quilt, |
|
300 |
'Check for (un)applied quilt patches') |
|
301 |
||
302 |
def test_applied(self): |
|
303 |
self.enable_hooks() |
|
304 |
tree = self.make_branch_and_tree('source') |
|
305 |
tree.get_config_stack().set('quilt.commit_policy', 'applied') |
|
306 |
self.build_tree(['source/debian/', 'source/debian/patches/', |
|
307 |
'source/debian/source/']) |
|
308 |
self.build_tree_contents([ |
|
309 |
('source/debian/source/format', '3.0 (quilt)'), |
|
310 |
('source/debian/patches/series', 'patch1\n'), |
|
311 |
('source/debian/patches/patch1', TRIVIAL_PATCH)]) |
|
312 |
self.assertPathDoesNotExist("source/.pc/applied-patches") |
|
313 |
self.assertPathDoesNotExist("source/a") |
|
314 |
tree.smart_add([tree.basedir]) |
|
315 |
tree.commit("foo") |
|
316 |
self.assertPathExists("source/.pc/applied-patches") |
|
317 |
self.assertPathExists("source/a") |
|
318 |
||
319 |
def test_unapplied(self): |
|
320 |
self.enable_hooks() |
|
321 |
tree = self.make_branch_and_tree('source') |
|
322 |
tree.get_config_stack().set('quilt.commit_policy', 'unapplied') |
|
323 |
self.build_tree( |
|
324 |
['source/debian/', 'source/debian/patches/', |
|
325 |
'source/debian/source/']) |
|
326 |
self.build_tree_contents([ |
|
327 |
('source/debian/patches/series', 'patch1\n'), |
|
328 |
('source/debian/patches/patch1', TRIVIAL_PATCH), |
|
329 |
('source/debian/source/format', '3.0 (quilt)')]) |
|
330 |
quilt_push_all(tree) |
|
331 |
self.assertPathExists("source/.pc/applied-patches") |
|
332 |
self.assertPathExists("source/a") |
|
333 |
tree.smart_add([tree.basedir]) |
|
334 |
tree.commit("foo") |
|
335 |
self.assertPathDoesNotExist("source/.pc/applied-patches") |
|
336 |
self.assertPathDoesNotExist("source/a") |
|
337 |
||
338 |
def test_warning(self): |
|
339 |
self.enable_hooks() |
|
340 |
warnings = [] |
|
341 |
||
342 |
def warning(*args): |
|
343 |
if len(args) > 1: |
|
344 |
warnings.append(args[0] % args[1:]) |
|
345 |
else: |
|
346 |
warnings.append(args[0]) |
|
347 |
_warning = trace.warning |
|
348 |
trace.warning = warning |
|
349 |
self.addCleanup(setattr, trace, "warning", _warning) |
|
350 |
tree = self.make_branch_and_tree('source') |
|
351 |
self.build_tree(['source/debian/', 'source/debian/patches/', |
|
352 |
'source/debian/source/']) |
|
353 |
self.build_tree_contents([ |
|
354 |
('source/debian/patches/series', 'patch1\n'), |
|
355 |
('source/debian/patches/patch1', TRIVIAL_PATCH)]) |
|
356 |
quilt_push_all(tree) |
|
357 |
tree.smart_add([tree.basedir]) |
|
358 |
tree.commit("initial") |
|
359 |
self.assertEquals([], warnings) |
|
360 |
self.assertPathExists("source/.pc/applied-patches") |
|
361 |
self.assertPathExists("source/a") |
|
362 |
self.build_tree_contents([ |
|
363 |
('source/debian/source/format', '3.0 (quilt)'), |
|
364 |
('source/debian/patches/series', 'patch1\npatch2\n'), |
|
365 |
('source/debian/patches/patch2', |
|
366 |
"""--- /dev/null 2012-01-02 01:09:10.986490031 +0100 |
|
367 |
+++ base/b 2012-01-02 20:03:59.710666215 +0100
|
|
368 |
@@ -0,0 +1 @@
|
|
369 |
+a
|
|
370 |
""")]) |
|
371 |
tree.smart_add([tree.basedir]) |
|
372 |
tree.commit("foo") |
|
373 |
self.assertEquals( |
|
374 |
['Committing with 1 patches applied and 1 patches unapplied.'], |
|
375 |
warnings) |
|
376 |
self.assertPathExists("source/.pc/applied-patches") |
|
377 |
self.assertPathExists("source/a") |
|
378 |
self.assertPathDoesNotExist("source/b") |