/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
5557.1.7 by John Arbash Meinel
Merge in the bzr.dev 5582
1
# Copyright (C) 2005-2011 Canonical Ltd
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
2
#
1185.14.8 by Aaron Bentley
Added test_commit.py
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
7
#
1185.14.8 by Aaron Bentley
Added test_commit.py
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
12
#
1185.14.8 by Aaron Bentley
Added test_commit.py
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1185.14.8 by Aaron Bentley
Added test_commit.py
16
17
18
import os
19
4597.2.2 by Vincent Ladeuil
Cleanup conflict tests.
20
from bzrlib import (
21
    bzrdir,
22
    conflicts,
23
    errors,
4597.3.51 by Vincent Ladeuil
Implement conflicts.ResolveActionOption.
24
    option,
5609.17.1 by Vincent Ladeuil
Reproduce bug #715068.
25
    osutils,
4597.2.2 by Vincent Ladeuil
Cleanup conflict tests.
26
    tests,
27
    )
4597.13.3 by Vincent Ladeuil
Switch to load_tests_apply_scenarios.
28
from bzrlib.tests import (
29
    script,
30
    scenarios,
31
    )
32
33
34
load_tests = scenarios.load_tests_apply_scenarios
4597.2.26 by Vincent Ladeuil
Fix bug #529968 by renaming the kept file on content conflicts.
35
36
1185.14.8 by Aaron Bentley
Added test_commit.py
37
# TODO: Test commit with some added, and added-but-missing files
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
38
# RBC 20060124 is that not tested in test_commit.py ?
1185.14.8 by Aaron Bentley
Added test_commit.py
39
1666.1.4 by Robert Collins
* 'Metadir' is now the default disk format. This improves behaviour in
40
# The order of 'path' here is important - do not let it
41
# be a sorted list.
2309.4.13 by John Arbash Meinel
Conflicts go through Stanza so the need to be aware of utf8 versus unicode file ids.
42
# u'\xe5' == a with circle
43
# '\xc3\xae' == u'\xee' == i with hat
4597.2.2 by Vincent Ladeuil
Cleanup conflict tests.
44
# So these are u'path' and 'id' only with a circle and a hat. (shappo?)
45
example_conflicts = conflicts.ConflictList(
46
    [conflicts.MissingParent('Not deleting', u'p\xe5thg', '\xc3\xaedg'),
47
     conflicts.ContentsConflict(u'p\xe5tha', None, '\xc3\xaeda'),
48
     conflicts.TextConflict(u'p\xe5tha'),
49
     conflicts.PathConflict(u'p\xe5thb', u'p\xe5thc', '\xc3\xaedb'),
50
     conflicts.DuplicateID('Unversioned existing file',
51
                           u'p\xe5thc', u'p\xe5thc2',
52
                           '\xc3\xaedc', '\xc3\xaedc'),
53
    conflicts.DuplicateEntry('Moved existing file to',
54
                             u'p\xe5thdd.moved', u'p\xe5thd',
55
                             '\xc3\xaedd', None),
56
    conflicts.ParentLoop('Cancelled move', u'p\xe5the', u'p\xe5th2e',
57
                         None, '\xc3\xaed2e'),
58
    conflicts.UnversionedParent('Versioned directory',
59
                                u'p\xe5thf', '\xc3\xaedf'),
60
    conflicts.NonDirectoryParent('Created directory',
61
                                 u'p\xe5thg', '\xc3\xaedg'),
1534.10.22 by Aaron Bentley
Got ConflictList implemented
62
])
1534.10.4 by Aaron Bentley
Implemented conflict serialization
63
64
5898.1.1 by Martin
Refactor conflict stanzas tests to use scenarios
65
def vary_by_conflicts():
66
    for conflict in example_conflicts:
67
        yield (conflict.__class__.__name__, {"conflict": conflict})
68
69
4597.2.2 by Vincent Ladeuil
Cleanup conflict tests.
70
class TestConflicts(tests.TestCaseWithTransport):
1185.14.8 by Aaron Bentley
Added test_commit.py
71
1558.12.9 by Aaron Bentley
Handle resolving conflicts with directories properly
72
    def test_resolve_conflict_dir(self):
73
        tree = self.make_branch_and_tree('.')
4597.2.3 by Vincent Ladeuil
More cleanup.
74
        self.build_tree_contents([('hello', 'hello world4'),
75
                                  ('hello.THIS', 'hello world2'),
76
                                  ('hello.BASE', 'hello world1'),
77
                                  ])
78
        os.mkdir('hello.OTHER')
1558.12.9 by Aaron Bentley
Handle resolving conflicts with directories properly
79
        tree.add('hello', 'q')
4597.2.3 by Vincent Ladeuil
More cleanup.
80
        l = conflicts.ConflictList([conflicts.TextConflict('hello')])
1558.12.9 by Aaron Bentley
Handle resolving conflicts with directories properly
81
        l.remove_files(tree)
82
1551.15.58 by Aaron Bentley
Status honours selected paths for conflicts (#127606)
83
    def test_select_conflicts(self):
84
        tree = self.make_branch_and_tree('.')
4597.2.3 by Vincent Ladeuil
More cleanup.
85
        clist = conflicts.ConflictList
86
87
        def check_select(not_selected, selected, paths, **kwargs):
88
            self.assertEqual(
89
                (not_selected, selected),
90
                tree_conflicts.select_conflicts(tree, paths, **kwargs))
91
92
        foo = conflicts.ContentsConflict('foo')
93
        bar = conflicts.ContentsConflict('bar')
94
        tree_conflicts = clist([foo, bar])
95
96
        check_select(clist([bar]), clist([foo]), ['foo'])
97
        check_select(clist(), tree_conflicts,
98
                     [''], ignore_misses=True, recurse=True)
99
100
        foobaz  = conflicts.ContentsConflict('foo/baz')
101
        tree_conflicts = clist([foobaz, bar])
102
103
        check_select(clist([bar]), clist([foobaz]),
104
                     ['foo'], ignore_misses=True, recurse=True)
105
106
        qux = conflicts.PathConflict('qux', 'foo/baz')
107
        tree_conflicts = clist([qux])
108
109
        check_select(clist(), tree_conflicts,
110
                     ['foo'], ignore_misses=True, recurse=True)
111
        check_select (tree_conflicts, clist(), ['foo'], ignore_misses=True)
1551.15.58 by Aaron Bentley
Status honours selected paths for conflicts (#127606)
112
3017.2.1 by Aaron Bentley
Revert now resolves conflicts recursively (#102739)
113
    def test_resolve_conflicts_recursive(self):
114
        tree = self.make_branch_and_tree('.')
115
        self.build_tree(['dir/', 'dir/hello'])
116
        tree.add(['dir', 'dir/hello'])
4597.2.3 by Vincent Ladeuil
More cleanup.
117
118
        dirhello = conflicts.ConflictList([conflicts.TextConflict('dir/hello')])
119
        tree.set_conflicts(dirhello)
120
121
        conflicts.resolve(tree, ['dir'], recursive=False, ignore_misses=True)
122
        self.assertEqual(dirhello, tree.conflicts())
123
124
        conflicts.resolve(tree, ['dir'], recursive=True, ignore_misses=True)
125
        self.assertEqual(conflicts.ConflictList([]), tree.conflicts())
4773.1.1 by Vincent Ladeuil
Cleanup imports in test_conflicts
126
127
5898.1.3 by Martin
Add tests for non-ascii conflict serialisation
128
class TestPerConflict(tests.TestCase):
4597.3.43 by Vincent Ladeuil
Cleanups, ready to record.
129
5898.1.1 by Martin
Refactor conflict stanzas tests to use scenarios
130
    scenarios = scenarios.multiply_scenarios(vary_by_conflicts())
131
5898.1.3 by Martin
Add tests for non-ascii conflict serialisation
132
    def test_stringification(self):
133
        text = unicode(self.conflict)
134
        self.assertContainsString(text, self.conflict.path)
135
        self.assertContainsString(text.lower(), "conflict")
136
        self.assertContainsString(repr(self.conflict),
137
            self.conflict.__class__.__name__)
138
4597.3.43 by Vincent Ladeuil
Cleanups, ready to record.
139
    def test_stanza_roundtrip(self):
5898.1.1 by Martin
Refactor conflict stanzas tests to use scenarios
140
        p = self.conflict
141
        o = conflicts.Conflict.factory(**p.as_stanza().as_dict())
142
        self.assertEqual(o, p)
143
144
        self.assertIsInstance(o.path, unicode)
145
146
        if o.file_id is not None:
147
            self.assertIsInstance(o.file_id, str)
148
149
        conflict_path = getattr(o, 'conflict_path', None)
150
        if conflict_path is not None:
151
            self.assertIsInstance(conflict_path, unicode)
152
153
        conflict_file_id = getattr(o, 'conflict_file_id', None)
154
        if conflict_file_id is not None:
155
            self.assertIsInstance(conflict_file_id, str)
4597.3.43 by Vincent Ladeuil
Cleanups, ready to record.
156
157
    def test_stanzification(self):
5898.1.1 by Martin
Refactor conflict stanzas tests to use scenarios
158
        stanza = self.conflict.as_stanza()
159
        if 'file_id' in stanza:
160
            # In Stanza form, the file_id has to be unicode.
161
            self.assertStartsWith(stanza['file_id'], u'\xeed')
162
        self.assertStartsWith(stanza['path'], u'p\xe5th')
163
        if 'conflict_path' in stanza:
164
            self.assertStartsWith(stanza['conflict_path'], u'p\xe5th')
165
        if 'conflict_file_id' in stanza:
166
            self.assertStartsWith(stanza['conflict_file_id'], u'\xeed')
167
168
5898.1.3 by Martin
Add tests for non-ascii conflict serialisation
169
class TestConflictList(tests.TestCase):
5898.1.1 by Martin
Refactor conflict stanzas tests to use scenarios
170
171
    def test_stanzas_roundtrip(self):
172
        stanzas_iter = example_conflicts.to_stanzas()
173
        processed = conflicts.ConflictList.from_stanzas(stanzas_iter)
174
        self.assertEqual(example_conflicts, processed)
4597.3.43 by Vincent Ladeuil
Cleanups, ready to record.
175
5898.1.3 by Martin
Add tests for non-ascii conflict serialisation
176
    def test_stringification(self):
177
        for text, o in zip(example_conflicts.to_strings(), example_conflicts):
178
            self.assertEqual(text, unicode(o))
179
4597.3.43 by Vincent Ladeuil
Cleanups, ready to record.
180
4597.3.74 by Vincent Ladeuil
Add a FIXME about rewriting shell-like tests into real whitebox tests.
181
# FIXME: The shell-like tests should be converted to real whitebox tests... or
182
# moved to a blackbox module -- vila 20100205
183
4597.7.11 by Vincent Ladeuil
Fix #531967 by creating helpers for PathConflicts when a deletion
184
# FIXME: test missing for multiple conflicts
185
4597.3.31 by Vincent Ladeuil
Implement --interactive for MissingParent.
186
# FIXME: Tests missing for DuplicateID conflict type
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
187
class TestResolveConflicts(script.TestCaseWithTransportAndScript):
188
189
    preamble = None # The setup script set by daughter classes
190
191
    def setUp(self):
192
        super(TestResolveConflicts, self).setUp()
193
        self.run_script(self.preamble)
194
195
4597.10.11 by Vincent Ladeuil
Turn mirror_scenarios into a simple function.
196
def mirror_scenarios(base_scenarios):
197
    """Return a list of mirrored scenarios.
198
199
    Each scenario in base_scenarios is duplicated switching the roles of 'this'
200
    and 'other'
201
    """
202
    scenarios = []
4597.10.14 by Vincent Ladeuil
Some more cleanup and typos.
203
    for common, (lname, ldict), (rname, rdict) in base_scenarios:
4597.10.11 by Vincent Ladeuil
Turn mirror_scenarios into a simple function.
204
        a = tests.multiply_scenarios([(lname, dict(_this=ldict))],
205
                                     [(rname, dict(_other=rdict))])
206
        b = tests.multiply_scenarios([(rname, dict(_this=rdict))],
207
                                     [(lname, dict(_other=ldict))])
208
        # Inject the common parameters in all scenarios
209
        for name, d in a + b:
210
            d.update(common)
211
        scenarios.extend(a + b)
212
    return scenarios
213
214
4597.7.10 by Vincent Ladeuil
Define scenarios by test classes.
215
# FIXME: Get rid of parametrized (in the class name) once we delete
216
# TestResolveConflicts -- vila 20100308
4597.7.4 by Vincent Ladeuil
Abstract the test class some more to address more conflict
217
class TestParametrizedResolveConflicts(tests.TestCaseWithTransport):
4597.7.18 by Vincent Ladeuil
Start addressing Andrew's concerns.
218
    """This class provides a base to test single conflict resolution.
219
4597.10.7 by Vincent Ladeuil
Simplify scenarios mirroring and give a better docstring for TestParametrizedResolveConflicts.
220
    Since all conflict objects are created with specific semantics for their
221
    attributes, each class should implement the necessary functions and
222
    attributes described below.
223
224
    Each class should define the scenarios that create the expected (single)
225
    conflict.
226
227
    Each scenario describes:
228
    * how to create 'base' tree (and revision)
229
    * how to create 'left' tree (and revision, parent rev 'base')
230
    * how to create 'right' tree (and revision, parent rev 'base')
231
    * how to check that changes in 'base'->'left' have been taken
232
    * how to check that changes in 'base'->'right' have been taken
233
234
    From each base scenario, we generate two concrete scenarios where:
235
    * this=left, other=right
236
    * this=right, other=left
237
238
    Then the test case verifies each concrete scenario by:
239
    * creating a branch containing the 'base', 'this' and 'other' revisions
240
    * creating a working tree for the 'this' revision
241
    * performing the merge of 'other' into 'this'
242
    * verifying the expected conflict was generated
243
    * resolving with --take-this or --take-other, and running the corresponding
244
      checks (for either 'base'->'this', or 'base'->'other')
245
246
    :cvar _conflict_type: The expected class of the generated conflict.
247
248
    :cvar _assert_conflict: A method receiving the working tree and the
249
        conflict object and checking its attributes.
250
4597.10.9 by Vincent Ladeuil
More doc.
251
    :cvar _base_actions: The branchbuilder actions to create the 'base'
252
        revision.
253
254
    :cvar _this: The dict related to 'base' -> 'this'. It contains at least:
255
      * 'actions': The branchbuilder actions to create the 'this'
256
          revision.
4597.10.10 by Vincent Ladeuil
Fix typo.
257
      * 'check': how to check the changes after resolution with --take-this.
4597.10.9 by Vincent Ladeuil
More doc.
258
259
    :cvar _other: The dict related to 'base' -> 'other'. It contains at least:
260
      * 'actions': The branchbuilder actions to create the 'other'
261
          revision.
4597.10.10 by Vincent Ladeuil
Fix typo.
262
      * 'check': how to check the changes after resolution with --take-other.
4597.7.18 by Vincent Ladeuil
Start addressing Andrew's concerns.
263
    """
4597.2.23 by Vincent Ladeuil
Start translating blackbox tests into whitebox ones.
264
4597.7.16 by Vincent Ladeuil
Some cleanup.
265
    # Set by daughter classes
266
    _conflict_type = None
267
    _assert_conflict = None
268
4597.2.26 by Vincent Ladeuil
Fix bug #529968 by renaming the kept file on content conflicts.
269
    # Set by load_tests
4597.7.6 by Vincent Ladeuil
Cleanup TestParametrizedResolveConflicts some more.
270
    _base_actions = None
4597.10.7 by Vincent Ladeuil
Simplify scenarios mirroring and give a better docstring for TestParametrizedResolveConflicts.
271
    _this = None
272
    _other = None
4597.7.7 by Vincent Ladeuil
Reproduce bug #531967 on various aspects.
273
4597.13.3 by Vincent Ladeuil
Switch to load_tests_apply_scenarios.
274
    scenarios = []
275
    """The scenario list for the conflict type defined by the class.
276
277
    Each scenario is of the form:
278
    (common, (left_name, left_dict), (right_name, right_dict))
279
280
    * common is a dict
281
282
    * left_name and right_name are the scenario names that will be combined
283
284
    * left_dict and right_dict are the attributes specific to each half of
285
      the scenario. They should include at least 'actions' and 'check' and
286
      will be available as '_this' and '_other' test instance attributes.
287
288
    Daughters classes are free to add their specific attributes as they see
289
    fit in any of the three dicts.
290
291
    This is a class method so that load_tests can find it.
292
293
    '_base_actions' in the common dict, 'actions' and 'check' in the left
294
    and right dicts use names that map to methods in the test classes. Some
295
    prefixes are added to these names to get the correspong methods (see
296
    _get_actions() and _get_check()). The motivation here is to avoid
297
    collisions in the class namespace.
298
    """
4597.7.10 by Vincent Ladeuil
Define scenarios by test classes.
299
4597.2.23 by Vincent Ladeuil
Start translating blackbox tests into whitebox ones.
300
    def setUp(self):
4597.7.4 by Vincent Ladeuil
Abstract the test class some more to address more conflict
301
        super(TestParametrizedResolveConflicts, self).setUp()
4597.2.23 by Vincent Ladeuil
Start translating blackbox tests into whitebox ones.
302
        builder = self.make_branch_builder('trunk')
303
        builder.start_series()
4597.7.6 by Vincent Ladeuil
Cleanup TestParametrizedResolveConflicts some more.
304
4597.2.23 by Vincent Ladeuil
Start translating blackbox tests into whitebox ones.
305
        # Create an empty trunk
306
        builder.build_snapshot('start', None, [
307
                ('add', ('', 'root-id', 'directory', ''))])
308
        # Add a minimal base content
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
309
        base_actions = self._get_actions(self._base_actions)()
4597.10.7 by Vincent Ladeuil
Simplify scenarios mirroring and give a better docstring for TestParametrizedResolveConflicts.
310
        builder.build_snapshot('base', ['start'], base_actions)
4597.2.23 by Vincent Ladeuil
Start translating blackbox tests into whitebox ones.
311
        # Modify the base content in branch
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
312
        actions_other = self._get_actions(self._other['actions'])()
4597.7.10 by Vincent Ladeuil
Define scenarios by test classes.
313
        builder.build_snapshot('other', ['base'], actions_other)
4597.2.23 by Vincent Ladeuil
Start translating blackbox tests into whitebox ones.
314
        # Modify the base content in trunk
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
315
        actions_this = self._get_actions(self._this['actions'])()
4597.7.10 by Vincent Ladeuil
Define scenarios by test classes.
316
        builder.build_snapshot('this', ['base'], actions_this)
4597.7.7 by Vincent Ladeuil
Reproduce bug #531967 on various aspects.
317
        # builder.get_branch() tip is now 'this'
4597.7.6 by Vincent Ladeuil
Cleanup TestParametrizedResolveConflicts some more.
318
4597.2.23 by Vincent Ladeuil
Start translating blackbox tests into whitebox ones.
319
        builder.finish_series()
320
        self.builder = builder
321
4597.2.26 by Vincent Ladeuil
Fix bug #529968 by renaming the kept file on content conflicts.
322
    def _get_actions(self, name):
323
        return getattr(self, 'do_%s' % name)
324
325
    def _get_check(self, name):
326
        return getattr(self, 'check_%s' % name)
327
4597.2.24 by Vincent Ladeuil
Translate one more test.
328
    def _merge_other_into_this(self):
4597.2.23 by Vincent Ladeuil
Start translating blackbox tests into whitebox ones.
329
        b = self.builder.get_branch()
330
        wt = b.bzrdir.sprout('branch').open_workingtree()
331
        wt.merge_from_branch(b, 'other')
4597.2.24 by Vincent Ladeuil
Translate one more test.
332
        return wt
333
4597.8.7 by Vincent Ladeuil
Add whitebox tests for ParentLoop.
334
    def assertConflict(self, wt):
335
        confs = wt.conflicts()
336
        self.assertLength(1, confs)
337
        c = confs[0]
338
        self.assertIsInstance(c, self._conflict_type)
339
        self._assert_conflict(wt, c)
340
341
    def _get_resolve_path_arg(self, wt, action):
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
342
        raise NotImplementedError(self._get_resolve_path_arg)
4597.8.7 by Vincent Ladeuil
Add whitebox tests for ParentLoop.
343
344
    def check_resolved(self, wt, action):
345
        path = self._get_resolve_path_arg(wt, action)
346
        conflicts.resolve(wt, [path], action=action)
347
        # Check that we don't have any conflicts nor unknown left
348
        self.assertLength(0, wt.conflicts())
349
        self.assertLength(0, list(wt.unknowns()))
350
4597.2.24 by Vincent Ladeuil
Translate one more test.
351
    def test_resolve_taking_this(self):
352
        wt = self._merge_other_into_this()
4597.7.7 by Vincent Ladeuil
Reproduce bug #531967 on various aspects.
353
        self.assertConflict(wt)
4597.8.7 by Vincent Ladeuil
Add whitebox tests for ParentLoop.
354
        self.check_resolved(wt, 'take_this')
4597.10.7 by Vincent Ladeuil
Simplify scenarios mirroring and give a better docstring for TestParametrizedResolveConflicts.
355
        check_this = self._get_check(self._this['check'])
4597.2.26 by Vincent Ladeuil
Fix bug #529968 by renaming the kept file on content conflicts.
356
        check_this()
4597.2.24 by Vincent Ladeuil
Translate one more test.
357
358
    def test_resolve_taking_other(self):
359
        wt = self._merge_other_into_this()
4597.7.7 by Vincent Ladeuil
Reproduce bug #531967 on various aspects.
360
        self.assertConflict(wt)
4597.8.7 by Vincent Ladeuil
Add whitebox tests for ParentLoop.
361
        self.check_resolved(wt, 'take_other')
4597.10.7 by Vincent Ladeuil
Simplify scenarios mirroring and give a better docstring for TestParametrizedResolveConflicts.
362
        check_other = self._get_check(self._other['check'])
4597.2.26 by Vincent Ladeuil
Fix bug #529968 by renaming the kept file on content conflicts.
363
        check_other()
4597.3.28 by Vincent Ladeuil
Implement --interactive for ContentsConflict.
364
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
365
4597.14.2 by Vincent Ladeuil
Implements --take-this and --take-other when resolving text conflicts
366
class TestResolveTextConflicts(TestParametrizedResolveConflicts):
367
368
    _conflict_type = conflicts.TextConflict
369
370
    # Set by the scenarios
371
    # path and file-id for the file involved in the conflict
372
    _path = None
373
    _file_id = None
374
375
    scenarios = mirror_scenarios(
376
        [
5609.17.1 by Vincent Ladeuil
Reproduce bug #715068.
377
            # File modified on both sides
4597.14.2 by Vincent Ladeuil
Implements --take-this and --take-other when resolving text conflicts
378
            (dict(_base_actions='create_file',
379
                  _path='file', _file_id='file-id'),
380
             ('filed_modified_A',
381
              dict(actions='modify_file_A', check='file_has_content_A')),
382
             ('file_modified_B',
383
              dict(actions='modify_file_B', check='file_has_content_B')),),
5609.17.1 by Vincent Ladeuil
Reproduce bug #715068.
384
            # File modified on both sides in dir
385
            (dict(_base_actions='create_file_in_dir',
386
                  _path='dir/file', _file_id='file-id'),
387
             ('filed_modified_A_in_dir',
388
              dict(actions='modify_file_A',
389
                   check='file_in_dir_has_content_A')),
390
             ('file_modified_B',
391
              dict(actions='modify_file_B',
392
                   check='file_in_dir_has_content_B')),),
4597.14.2 by Vincent Ladeuil
Implements --take-this and --take-other when resolving text conflicts
393
            ])
394
5609.17.1 by Vincent Ladeuil
Reproduce bug #715068.
395
    def do_create_file(self, path='file'):
396
        return [('add', (path, 'file-id', 'file', 'trunk content\n'))]
4597.14.2 by Vincent Ladeuil
Implements --take-this and --take-other when resolving text conflicts
397
398
    def do_modify_file_A(self):
399
        return [('modify', ('file-id', 'trunk content\nfeature A\n'))]
400
401
    def do_modify_file_B(self):
402
        return [('modify', ('file-id', 'trunk content\nfeature B\n'))]
403
5609.17.1 by Vincent Ladeuil
Reproduce bug #715068.
404
    def check_file_has_content_A(self, path='file'):
405
        self.assertFileEqual('trunk content\nfeature A\n',
406
                             osutils.pathjoin('branch', path))
407
408
    def check_file_has_content_B(self, path='file'):
409
        self.assertFileEqual('trunk content\nfeature B\n',
410
                             osutils.pathjoin('branch', path))
411
412
    def do_create_file_in_dir(self):
413
        return [('add', ('dir', 'dir-id', 'directory', '')),
414
            ] + self.do_create_file('dir/file')
415
416
    def check_file_in_dir_has_content_A(self):
417
        self.check_file_has_content_A('dir/file')
418
419
    def check_file_in_dir_has_content_B(self):
420
        self.check_file_has_content_B('dir/file')
4597.14.2 by Vincent Ladeuil
Implements --take-this and --take-other when resolving text conflicts
421
422
    def _get_resolve_path_arg(self, wt, action):
423
        return self._path
424
425
    def assertTextConflict(self, wt, c):
426
        self.assertEqual(self._file_id, c.file_id)
427
        self.assertEqual(self._path, c.path)
428
    _assert_conflict = assertTextConflict
429
430
4597.7.10 by Vincent Ladeuil
Define scenarios by test classes.
431
class TestResolveContentsConflict(TestParametrizedResolveConflicts):
432
4597.13.3 by Vincent Ladeuil
Switch to load_tests_apply_scenarios.
433
    _conflict_type = conflicts.ContentsConflict
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
434
4597.13.3 by Vincent Ladeuil
Switch to load_tests_apply_scenarios.
435
    # Set by the scenarios
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
436
    # path and file-id for the file involved in the conflict
437
    _path = None
438
    _file_id = None
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
439
4597.13.3 by Vincent Ladeuil
Switch to load_tests_apply_scenarios.
440
    scenarios = mirror_scenarios(
441
        [
4597.10.12 by Vincent Ladeuil
Some more doc.
442
            # File modified/deleted
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
443
            (dict(_base_actions='create_file',
444
                  _path='file', _file_id='file-id'),
4597.10.12 by Vincent Ladeuil
Some more doc.
445
             ('file_modified',
446
              dict(actions='modify_file', check='file_has_more_content')),
447
             ('file_deleted',
448
              dict(actions='delete_file', check='file_doesnt_exist')),),
5050.63.3 by Vincent Ladeuil
Correctly resolve content conflicts for files in subdirs
449
            # File modified/deleted in dir
450
            (dict(_base_actions='create_file_in_dir',
451
                  _path='dir/file', _file_id='file-id'),
452
             ('file_modified_in_dir',
453
              dict(actions='modify_file_in_dir',
454
                   check='file_in_dir_has_more_content')),
455
             ('file_deleted_in_dir',
456
              dict(actions='delete_file',
457
                   check='file_in_dir_doesnt_exist')),),
4597.13.3 by Vincent Ladeuil
Switch to load_tests_apply_scenarios.
458
            ])
4597.7.10 by Vincent Ladeuil
Define scenarios by test classes.
459
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
460
    def do_create_file(self):
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
461
        return [('add', ('file', 'file-id', 'file', 'trunk content\n'))]
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
462
463
    def do_modify_file(self):
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
464
        return [('modify', ('file-id', 'trunk content\nmore content\n'))]
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
465
466
    def check_file_has_more_content(self):
467
        self.assertFileEqual('trunk content\nmore content\n', 'branch/file')
468
469
    def do_delete_file(self):
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
470
        return [('unversion', 'file-id')]
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
471
472
    def check_file_doesnt_exist(self):
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
473
        self.assertPathDoesNotExist('branch/file')
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
474
5050.63.3 by Vincent Ladeuil
Correctly resolve content conflicts for files in subdirs
475
    def do_create_file_in_dir(self):
476
        return [('add', ('dir', 'dir-id', 'directory', '')),
477
                ('add', ('dir/file', 'file-id', 'file', 'trunk content\n'))]
478
479
    def do_modify_file_in_dir(self):
480
        return [('modify', ('file-id', 'trunk content\nmore content\n'))]
481
482
    def check_file_in_dir_has_more_content(self):
483
        self.assertFileEqual('trunk content\nmore content\n', 'branch/dir/file')
484
485
    def check_file_in_dir_doesnt_exist(self):
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
486
        self.assertPathDoesNotExist('branch/dir/file')
5050.63.3 by Vincent Ladeuil
Correctly resolve content conflicts for files in subdirs
487
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
488
    def _get_resolve_path_arg(self, wt, action):
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
489
        return self._path
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
490
4597.7.17 by Vincent Ladeuil
Add a scenario and activate the compatibility tests.
491
    def assertContentsConflict(self, wt, c):
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
492
        self.assertEqual(self._file_id, c.file_id)
493
        self.assertEqual(self._path, c.path)
4597.7.16 by Vincent Ladeuil
Some cleanup.
494
    _assert_conflict = assertContentsConflict
495
4597.7.10 by Vincent Ladeuil
Define scenarios by test classes.
496
497
class TestResolvePathConflict(TestParametrizedResolveConflicts):
498
4597.13.3 by Vincent Ladeuil
Switch to load_tests_apply_scenarios.
499
    _conflict_type = conflicts.PathConflict
4597.7.16 by Vincent Ladeuil
Some cleanup.
500
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
501
    def do_nothing(self):
502
        return []
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
503
4597.13.3 by Vincent Ladeuil
Switch to load_tests_apply_scenarios.
504
    # Each side dict additionally defines:
505
    # - path path involved (can be '<deleted>')
506
    # - file-id involved
507
    scenarios = mirror_scenarios(
508
        [
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
509
            # File renamed/deleted
510
            (dict(_base_actions='create_file'),
511
             ('file_renamed',
512
              dict(actions='rename_file', check='file_renamed',
513
                   path='new-file', file_id='file-id')),
4597.7.17 by Vincent Ladeuil
Add a scenario and activate the compatibility tests.
514
             ('file_deleted',
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
515
              dict(actions='delete_file', check='file_doesnt_exist',
516
                   # PathConflicts deletion handling requires a special
517
                   # hard-coded value
518
                   path='<deleted>', file_id='file-id')),),
5050.63.6 by Vincent Ladeuil
Same fix for path conflicts.
519
            # File renamed/deleted in dir
520
            (dict(_base_actions='create_file_in_dir'),
521
             ('file_renamed_in_dir',
522
              dict(actions='rename_file_in_dir', check='file_in_dir_renamed',
523
                   path='dir/new-file', file_id='file-id')),
524
             ('file_deleted',
525
              dict(actions='delete_file', check='file_in_dir_doesnt_exist',
526
                   # PathConflicts deletion handling requires a special
527
                   # hard-coded value
528
                   path='<deleted>', file_id='file-id')),),
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
529
            # File renamed/renamed differently
530
            (dict(_base_actions='create_file'),
531
             ('file_renamed',
532
              dict(actions='rename_file', check='file_renamed',
533
                   path='new-file', file_id='file-id')),
4597.8.4 by Vincent Ladeuil
Delete PathConflict bloackbox tests.
534
             ('file_renamed2',
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
535
              dict(actions='rename_file2', check='file_renamed2',
536
                   path='new-file2', file_id='file-id')),),
537
            # Dir renamed/deleted
538
            (dict(_base_actions='create_dir'),
539
             ('dir_renamed',
540
              dict(actions='rename_dir', check='dir_renamed',
541
                   path='new-dir', file_id='dir-id')),
4597.7.17 by Vincent Ladeuil
Add a scenario and activate the compatibility tests.
542
             ('dir_deleted',
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
543
              dict(actions='delete_dir', check='dir_doesnt_exist',
544
                   # PathConflicts deletion handling requires a special
545
                   # hard-coded value
546
                   path='<deleted>', file_id='dir-id')),),
547
            # Dir renamed/renamed differently
548
            (dict(_base_actions='create_dir'),
549
             ('dir_renamed',
550
              dict(actions='rename_dir', check='dir_renamed',
551
                   path='new-dir', file_id='dir-id')),
4597.7.17 by Vincent Ladeuil
Add a scenario and activate the compatibility tests.
552
             ('dir_renamed2',
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
553
              dict(actions='rename_dir2', check='dir_renamed2',
554
                   path='new-dir2', file_id='dir-id')),),
4597.13.3 by Vincent Ladeuil
Switch to load_tests_apply_scenarios.
555
            ])
4597.7.17 by Vincent Ladeuil
Add a scenario and activate the compatibility tests.
556
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
557
    def do_create_file(self):
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
558
        return [('add', ('file', 'file-id', 'file', 'trunk content\n'))]
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
559
560
    def do_create_dir(self):
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
561
        return [('add', ('dir', 'dir-id', 'directory', ''))]
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
562
563
    def do_rename_file(self):
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
564
        return [('rename', ('file', 'new-file'))]
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
565
566
    def check_file_renamed(self):
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
567
        self.assertPathDoesNotExist('branch/file')
568
        self.assertPathExists('branch/new-file')
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
569
570
    def do_rename_file2(self):
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
571
        return [('rename', ('file', 'new-file2'))]
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
572
573
    def check_file_renamed2(self):
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
574
        self.assertPathDoesNotExist('branch/file')
575
        self.assertPathExists('branch/new-file2')
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
576
577
    def do_rename_dir(self):
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
578
        return [('rename', ('dir', 'new-dir'))]
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
579
580
    def check_dir_renamed(self):
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
581
        self.assertPathDoesNotExist('branch/dir')
582
        self.assertPathExists('branch/new-dir')
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
583
584
    def do_rename_dir2(self):
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
585
        return [('rename', ('dir', 'new-dir2'))]
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
586
587
    def check_dir_renamed2(self):
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
588
        self.assertPathDoesNotExist('branch/dir')
589
        self.assertPathExists('branch/new-dir2')
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
590
4597.7.17 by Vincent Ladeuil
Add a scenario and activate the compatibility tests.
591
    def do_delete_file(self):
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
592
        return [('unversion', 'file-id')]
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
593
594
    def check_file_doesnt_exist(self):
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
595
        self.assertPathDoesNotExist('branch/file')
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
596
597
    def do_delete_dir(self):
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
598
        return [('unversion', 'dir-id')]
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
599
600
    def check_dir_doesnt_exist(self):
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
601
        self.assertPathDoesNotExist('branch/dir')
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
602
5050.63.6 by Vincent Ladeuil
Same fix for path conflicts.
603
    def do_create_file_in_dir(self):
604
        return [('add', ('dir', 'dir-id', 'directory', '')),
605
                ('add', ('dir/file', 'file-id', 'file', 'trunk content\n'))]
606
607
    def do_rename_file_in_dir(self):
608
        return [('rename', ('dir/file', 'dir/new-file'))]
609
610
    def check_file_in_dir_renamed(self):
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
611
        self.assertPathDoesNotExist('branch/dir/file')
612
        self.assertPathExists('branch/dir/new-file')
5050.63.6 by Vincent Ladeuil
Same fix for path conflicts.
613
614
    def check_file_in_dir_doesnt_exist(self):
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
615
        self.assertPathDoesNotExist('branch/dir/file')
5050.63.6 by Vincent Ladeuil
Same fix for path conflicts.
616
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
617
    def _get_resolve_path_arg(self, wt, action):
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
618
        tpath = self._this['path']
619
        opath = self._other['path']
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
620
        if tpath == '<deleted>':
621
            path = opath
622
        else:
623
            path = tpath
624
        return path
4597.7.17 by Vincent Ladeuil
Add a scenario and activate the compatibility tests.
625
626
    def assertPathConflict(self, wt, c):
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
627
        tpath = self._this['path']
628
        tfile_id = self._this['file_id']
629
        opath = self._other['path']
630
        ofile_id = self._other['file_id']
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
631
        self.assertEqual(tfile_id, ofile_id) # Sanity check
632
        self.assertEqual(tfile_id, c.file_id)
633
        self.assertEqual(tpath, c.path)
634
        self.assertEqual(opath, c.conflict_path)
4597.7.16 by Vincent Ladeuil
Some cleanup.
635
    _assert_conflict = assertPathConflict
4597.7.10 by Vincent Ladeuil
Define scenarios by test classes.
636
637
4597.7.17 by Vincent Ladeuil
Add a scenario and activate the compatibility tests.
638
class TestResolvePathConflictBefore531967(TestResolvePathConflict):
4597.7.10 by Vincent Ladeuil
Define scenarios by test classes.
639
    """Same as TestResolvePathConflict but a specific conflict object.
640
    """
641
4597.7.16 by Vincent Ladeuil
Some cleanup.
642
    def assertPathConflict(self, c):
4597.7.17 by Vincent Ladeuil
Add a scenario and activate the compatibility tests.
643
        # We create a conflict object as it was created before the fix and
644
        # inject it into the working tree, the test will exercise the
645
        # compatibility code.
646
        old_c = conflicts.PathConflict('<deleted>', self._item_path,
647
                                       file_id=None)
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
648
        wt.set_conflicts(conflicts.ConflictList([old_c]))
4597.7.10 by Vincent Ladeuil
Define scenarios by test classes.
649
650
4597.8.5 by Vincent Ladeuil
Replace DuplicateEntry blackbox tests by whitebox ones.
651
class TestResolveDuplicateEntry(TestParametrizedResolveConflicts):
652
4597.13.3 by Vincent Ladeuil
Switch to load_tests_apply_scenarios.
653
    _conflict_type = conflicts.DuplicateEntry
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
654
4597.13.3 by Vincent Ladeuil
Switch to load_tests_apply_scenarios.
655
    scenarios = mirror_scenarios(
656
        [
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
657
            # File created with different file-ids
658
            (dict(_base_actions='nothing'),
659
             ('filea_created',
660
              dict(actions='create_file_a', check='file_content_a',
661
                   path='file', file_id='file-a-id')),
662
             ('fileb_created',
663
              dict(actions='create_file_b', check='file_content_b',
664
                   path='file', file_id='file-b-id')),),
4597.13.3 by Vincent Ladeuil
Switch to load_tests_apply_scenarios.
665
            ])
4597.8.5 by Vincent Ladeuil
Replace DuplicateEntry blackbox tests by whitebox ones.
666
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
667
    def do_nothing(self):
668
        return []
669
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
670
    def do_create_file_a(self):
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
671
        return [('add', ('file', 'file-a-id', 'file', 'file a content\n'))]
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
672
673
    def check_file_content_a(self):
674
        self.assertFileEqual('file a content\n', 'branch/file')
675
676
    def do_create_file_b(self):
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
677
        return [('add', ('file', 'file-b-id', 'file', 'file b content\n'))]
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
678
679
    def check_file_content_b(self):
680
        self.assertFileEqual('file b content\n', 'branch/file')
681
682
    def _get_resolve_path_arg(self, wt, action):
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
683
        return self._this['path']
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
684
4597.8.5 by Vincent Ladeuil
Replace DuplicateEntry blackbox tests by whitebox ones.
685
    def assertDuplicateEntry(self, wt, c):
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
686
        tpath = self._this['path']
687
        tfile_id = self._this['file_id']
688
        opath = self._other['path']
689
        ofile_id = self._other['file_id']
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
690
        self.assertEqual(tpath, opath) # Sanity check
691
        self.assertEqual(tfile_id, c.file_id)
692
        self.assertEqual(tpath + '.moved', c.path)
693
        self.assertEqual(tpath, c.conflict_path)
4597.8.5 by Vincent Ladeuil
Replace DuplicateEntry blackbox tests by whitebox ones.
694
    _assert_conflict = assertDuplicateEntry
4597.3.19 by Vincent Ladeuil
Some failing tests.
695
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
696
697
class TestResolveUnversionedParent(TestResolveConflicts):
698
4597.3.29 by Vincent Ladeuil
Fix bogus tests.
699
    # FIXME: Add the reverse tests: dir deleted in trunk, file added in branch
700
4597.3.30 by Vincent Ladeuil
Light changes learned while starting to understand multiple conflicts on
701
    # FIXME: While this *creates* UnversionedParent conflicts, this really only
702
    # tests MissingParent resolution :-/
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
703
    preamble = """
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
704
$ bzr init trunk
5422.3.4 by Martin Pool
Update test_resolve to pass --quiet or ignore command output it doesn't care about
705
...
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
706
$ cd trunk
4597.3.29 by Vincent Ladeuil
Fix bogus tests.
707
$ mkdir dir
5422.3.4 by Martin Pool
Update test_resolve to pass --quiet or ignore command output it doesn't care about
708
$ bzr add -q dir
709
$ bzr commit -m 'Create trunk' -q
4597.3.29 by Vincent Ladeuil
Fix bogus tests.
710
$ echo 'trunk content' >dir/file
5422.3.4 by Martin Pool
Update test_resolve to pass --quiet or ignore command output it doesn't care about
711
$ bzr add -q dir/file
712
$ bzr commit -q -m 'Add dir/file in trunk'
713
$ bzr branch -q . -r 1 ../branch
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
714
$ cd ../branch
5422.3.4 by Martin Pool
Update test_resolve to pass --quiet or ignore command output it doesn't care about
715
$ bzr rm dir -q
716
$ bzr commit -q -m 'Remove dir in branch'
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
717
$ bzr merge ../trunk
4597.3.29 by Vincent Ladeuil
Fix bogus tests.
718
2>+N  dir/
719
2>+N  dir/file
720
2>Conflict adding files to dir.  Created directory.
721
2>Conflict because dir is not versioned, but has versioned children.  Versioned directory.
722
2>2 conflicts encountered.
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
723
"""
724
4597.3.67 by Vincent Ladeuil
Settle with --take-this and --take-other as action names.
725
    def test_take_this(self):
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
726
        self.run_script("""
5422.3.4 by Martin Pool
Update test_resolve to pass --quiet or ignore command output it doesn't care about
727
$ bzr rm -q dir  --force
4597.3.29 by Vincent Ladeuil
Fix bogus tests.
728
$ bzr resolve dir
4597.9.19 by Vincent Ladeuil
resolve now reports conflicts resolved/remaining.
729
2>2 conflict(s) resolved, 0 remaining
5422.3.4 by Martin Pool
Update test_resolve to pass --quiet or ignore command output it doesn't care about
730
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
731
""")
732
4597.3.67 by Vincent Ladeuil
Settle with --take-this and --take-other as action names.
733
    def test_take_other(self):
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
734
        self.run_script("""
4597.3.29 by Vincent Ladeuil
Fix bogus tests.
735
$ bzr resolve dir
4597.9.19 by Vincent Ladeuil
resolve now reports conflicts resolved/remaining.
736
2>2 conflict(s) resolved, 0 remaining
5422.3.4 by Martin Pool
Update test_resolve to pass --quiet or ignore command output it doesn't care about
737
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
738
""")
739
740
741
class TestResolveMissingParent(TestResolveConflicts):
742
743
    preamble = """
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
744
$ bzr init trunk
5422.3.4 by Martin Pool
Update test_resolve to pass --quiet or ignore command output it doesn't care about
745
...
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
746
$ cd trunk
747
$ mkdir dir
748
$ echo 'trunk content' >dir/file
5422.3.4 by Martin Pool
Update test_resolve to pass --quiet or ignore command output it doesn't care about
749
$ bzr add -q
750
$ bzr commit -m 'Create trunk' -q
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
751
$ echo 'trunk content' >dir/file2
5422.3.4 by Martin Pool
Update test_resolve to pass --quiet or ignore command output it doesn't care about
752
$ bzr add -q dir/file2
753
$ bzr commit -q -m 'Add dir/file2 in branch'
754
$ bzr branch -q . -r 1 ../branch
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
755
$ cd ../branch
5422.3.4 by Martin Pool
Update test_resolve to pass --quiet or ignore command output it doesn't care about
756
$ bzr rm -q dir/file --force
757
$ bzr rm -q dir
758
$ bzr commit -q -m 'Remove dir/file'
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
759
$ bzr merge ../trunk
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
760
2>+N  dir/
761
2>+N  dir/file2
762
2>Conflict adding files to dir.  Created directory.
763
2>Conflict because dir is not versioned, but has versioned children.  Versioned directory.
764
2>2 conflicts encountered.
765
"""
766
767
    def test_keep_them_all(self):
768
        self.run_script("""
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
769
$ bzr resolve dir
4597.9.19 by Vincent Ladeuil
resolve now reports conflicts resolved/remaining.
770
2>2 conflict(s) resolved, 0 remaining
5422.3.4 by Martin Pool
Update test_resolve to pass --quiet or ignore command output it doesn't care about
771
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
772
""")
773
774
    def test_adopt_child(self):
775
        self.run_script("""
5422.3.4 by Martin Pool
Update test_resolve to pass --quiet or ignore command output it doesn't care about
776
$ bzr mv -q dir/file2 file2
777
$ bzr rm -q dir --force
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
778
$ bzr resolve dir
4597.9.19 by Vincent Ladeuil
resolve now reports conflicts resolved/remaining.
779
2>2 conflict(s) resolved, 0 remaining
5422.3.4 by Martin Pool
Update test_resolve to pass --quiet or ignore command output it doesn't care about
780
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
781
""")
782
783
    def test_kill_them_all(self):
784
        self.run_script("""
5422.3.4 by Martin Pool
Update test_resolve to pass --quiet or ignore command output it doesn't care about
785
$ bzr rm -q dir --force
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
786
$ bzr resolve dir
4597.9.19 by Vincent Ladeuil
resolve now reports conflicts resolved/remaining.
787
2>2 conflict(s) resolved, 0 remaining
5422.3.4 by Martin Pool
Update test_resolve to pass --quiet or ignore command output it doesn't care about
788
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
789
""")
790
4597.3.67 by Vincent Ladeuil
Settle with --take-this and --take-other as action names.
791
    def test_resolve_taking_this(self):
4597.3.31 by Vincent Ladeuil
Implement --interactive for MissingParent.
792
        self.run_script("""
4597.3.67 by Vincent Ladeuil
Settle with --take-this and --take-other as action names.
793
$ bzr resolve --take-this dir
5422.3.4 by Martin Pool
Update test_resolve to pass --quiet or ignore command output it doesn't care about
794
2>...
795
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
4597.3.31 by Vincent Ladeuil
Implement --interactive for MissingParent.
796
""")
797
4597.3.67 by Vincent Ladeuil
Settle with --take-this and --take-other as action names.
798
    def test_resolve_taking_other(self):
4597.3.31 by Vincent Ladeuil
Implement --interactive for MissingParent.
799
        self.run_script("""
4597.3.67 by Vincent Ladeuil
Settle with --take-this and --take-other as action names.
800
$ bzr resolve --take-other dir
5422.3.4 by Martin Pool
Update test_resolve to pass --quiet or ignore command output it doesn't care about
801
2>...
802
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
4597.3.31 by Vincent Ladeuil
Implement --interactive for MissingParent.
803
""")
804
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
805
806
class TestResolveDeletingParent(TestResolveConflicts):
807
808
    preamble = """
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
809
$ bzr init trunk
5422.3.4 by Martin Pool
Update test_resolve to pass --quiet or ignore command output it doesn't care about
810
...
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
811
$ cd trunk
812
$ mkdir dir
813
$ echo 'trunk content' >dir/file
5422.3.4 by Martin Pool
Update test_resolve to pass --quiet or ignore command output it doesn't care about
814
$ bzr add -q
815
$ bzr commit -m 'Create trunk' -q
816
$ bzr rm -q dir/file --force
817
$ bzr rm -q dir --force
818
$ bzr commit -q -m 'Remove dir/file'
819
$ bzr branch -q . -r 1 ../branch
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
820
$ cd ../branch
821
$ echo 'branch content' >dir/file2
5422.3.4 by Martin Pool
Update test_resolve to pass --quiet or ignore command output it doesn't care about
822
$ bzr add -q dir/file2
823
$ bzr commit -q -m 'Add dir/file2 in branch'
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
824
$ bzr merge ../trunk
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
825
2>-D  dir/file
826
2>Conflict: can't delete dir because it is not empty.  Not deleting.
827
2>Conflict because dir is not versioned, but has versioned children.  Versioned directory.
828
2>2 conflicts encountered.
829
"""
830
831
    def test_keep_them_all(self):
832
        self.run_script("""
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
833
$ bzr resolve dir
4597.9.19 by Vincent Ladeuil
resolve now reports conflicts resolved/remaining.
834
2>2 conflict(s) resolved, 0 remaining
5422.3.4 by Martin Pool
Update test_resolve to pass --quiet or ignore command output it doesn't care about
835
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
836
""")
837
838
    def test_adopt_child(self):
839
        self.run_script("""
5422.3.4 by Martin Pool
Update test_resolve to pass --quiet or ignore command output it doesn't care about
840
$ bzr mv -q dir/file2 file2
841
$ bzr rm -q dir --force
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
842
$ bzr resolve dir
4597.9.19 by Vincent Ladeuil
resolve now reports conflicts resolved/remaining.
843
2>2 conflict(s) resolved, 0 remaining
5422.3.4 by Martin Pool
Update test_resolve to pass --quiet or ignore command output it doesn't care about
844
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
845
""")
846
847
    def test_kill_them_all(self):
848
        self.run_script("""
5422.3.4 by Martin Pool
Update test_resolve to pass --quiet or ignore command output it doesn't care about
849
$ bzr rm -q dir --force
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
850
$ bzr resolve dir
4597.9.19 by Vincent Ladeuil
resolve now reports conflicts resolved/remaining.
851
2>2 conflict(s) resolved, 0 remaining
5422.3.4 by Martin Pool
Update test_resolve to pass --quiet or ignore command output it doesn't care about
852
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
853
""")
854
4597.3.67 by Vincent Ladeuil
Settle with --take-this and --take-other as action names.
855
    def test_resolve_taking_this(self):
4597.3.32 by Vincent Ladeuil
Implement --interactive for DeletingParent noting the inconsistency.
856
        self.run_script("""
4597.3.67 by Vincent Ladeuil
Settle with --take-this and --take-other as action names.
857
$ bzr resolve --take-this dir
4597.9.19 by Vincent Ladeuil
resolve now reports conflicts resolved/remaining.
858
2>2 conflict(s) resolved, 0 remaining
5422.3.4 by Martin Pool
Update test_resolve to pass --quiet or ignore command output it doesn't care about
859
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
4597.3.32 by Vincent Ladeuil
Implement --interactive for DeletingParent noting the inconsistency.
860
""")
861
4597.3.67 by Vincent Ladeuil
Settle with --take-this and --take-other as action names.
862
    def test_resolve_taking_other(self):
4597.3.32 by Vincent Ladeuil
Implement --interactive for DeletingParent noting the inconsistency.
863
        self.run_script("""
4597.3.67 by Vincent Ladeuil
Settle with --take-this and --take-other as action names.
864
$ bzr resolve --take-other dir
5422.3.4 by Martin Pool
Update test_resolve to pass --quiet or ignore command output it doesn't care about
865
2>deleted dir/file2
866
2>deleted dir
4597.9.19 by Vincent Ladeuil
resolve now reports conflicts resolved/remaining.
867
2>2 conflict(s) resolved, 0 remaining
5422.3.4 by Martin Pool
Update test_resolve to pass --quiet or ignore command output it doesn't care about
868
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
4597.3.32 by Vincent Ladeuil
Implement --interactive for DeletingParent noting the inconsistency.
869
""")
870
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
871
4597.8.7 by Vincent Ladeuil
Add whitebox tests for ParentLoop.
872
class TestResolveParentLoop(TestParametrizedResolveConflicts):
873
4597.13.3 by Vincent Ladeuil
Switch to load_tests_apply_scenarios.
874
    _conflict_type = conflicts.ParentLoop
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
875
876
    _this_args = None
877
    _other_args = None
878
4597.13.3 by Vincent Ladeuil
Switch to load_tests_apply_scenarios.
879
    # Each side dict additionally defines:
880
    # - dir_id: the directory being moved
881
    # - target_id: The target directory
882
    # - xfail: whether the test is expected to fail if the action is
883
    #   involved as 'other'
884
    scenarios = mirror_scenarios(
885
        [
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
886
            # Dirs moved into each other
887
            (dict(_base_actions='create_dir1_dir2'),
888
             ('dir1_into_dir2',
889
              dict(actions='move_dir1_into_dir2', check='dir1_moved',
890
                   dir_id='dir1-id', target_id='dir2-id', xfail=False)),
891
             ('dir2_into_dir1',
892
              dict(actions='move_dir2_into_dir1', check='dir2_moved',
893
                   dir_id='dir2-id', target_id='dir1-id', xfail=False))),
894
            # Subdirs moved into each other
895
            (dict(_base_actions='create_dir1_4'),
896
             ('dir1_into_dir4',
897
              dict(actions='move_dir1_into_dir4', check='dir1_2_moved',
898
                   dir_id='dir1-id', target_id='dir4-id', xfail=True)),
899
             ('dir3_into_dir2',
900
              dict(actions='move_dir3_into_dir2', check='dir3_4_moved',
901
                   dir_id='dir3-id', target_id='dir2-id', xfail=True))),
4597.13.3 by Vincent Ladeuil
Switch to load_tests_apply_scenarios.
902
            ])
4597.8.7 by Vincent Ladeuil
Add whitebox tests for ParentLoop.
903
904
    def do_create_dir1_dir2(self):
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
905
        return [('add', ('dir1', 'dir1-id', 'directory', '')),
906
                ('add', ('dir2', 'dir2-id', 'directory', '')),]
4597.8.7 by Vincent Ladeuil
Add whitebox tests for ParentLoop.
907
4597.8.8 by Vincent Ladeuil
Exhibit bug #537956.
908
    def do_move_dir1_into_dir2(self):
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
909
        return [('rename', ('dir1', 'dir2/dir1'))]
4597.8.7 by Vincent Ladeuil
Add whitebox tests for ParentLoop.
910
911
    def check_dir1_moved(self):
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
912
        self.assertPathDoesNotExist('branch/dir1')
913
        self.assertPathExists('branch/dir2/dir1')
4597.8.7 by Vincent Ladeuil
Add whitebox tests for ParentLoop.
914
4597.8.8 by Vincent Ladeuil
Exhibit bug #537956.
915
    def do_move_dir2_into_dir1(self):
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
916
        return [('rename', ('dir2', 'dir1/dir2'))]
4597.8.7 by Vincent Ladeuil
Add whitebox tests for ParentLoop.
917
918
    def check_dir2_moved(self):
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
919
        self.assertPathDoesNotExist('branch/dir2')
920
        self.assertPathExists('branch/dir1/dir2')
4597.8.7 by Vincent Ladeuil
Add whitebox tests for ParentLoop.
921
4597.8.8 by Vincent Ladeuil
Exhibit bug #537956.
922
    def do_create_dir1_4(self):
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
923
        return [('add', ('dir1', 'dir1-id', 'directory', '')),
924
                ('add', ('dir1/dir2', 'dir2-id', 'directory', '')),
925
                ('add', ('dir3', 'dir3-id', 'directory', '')),
926
                ('add', ('dir3/dir4', 'dir4-id', 'directory', '')),]
4597.8.8 by Vincent Ladeuil
Exhibit bug #537956.
927
928
    def do_move_dir1_into_dir4(self):
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
929
        return [('rename', ('dir1', 'dir3/dir4/dir1'))]
4597.8.8 by Vincent Ladeuil
Exhibit bug #537956.
930
931
    def check_dir1_2_moved(self):
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
932
        self.assertPathDoesNotExist('branch/dir1')
933
        self.assertPathExists('branch/dir3/dir4/dir1')
934
        self.assertPathExists('branch/dir3/dir4/dir1/dir2')
4597.8.8 by Vincent Ladeuil
Exhibit bug #537956.
935
936
    def do_move_dir3_into_dir2(self):
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
937
        return [('rename', ('dir3', 'dir1/dir2/dir3'))]
4597.8.8 by Vincent Ladeuil
Exhibit bug #537956.
938
939
    def check_dir3_4_moved(self):
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
940
        self.assertPathDoesNotExist('branch/dir3')
941
        self.assertPathExists('branch/dir1/dir2/dir3')
942
        self.assertPathExists('branch/dir1/dir2/dir3/dir4')
4597.8.8 by Vincent Ladeuil
Exhibit bug #537956.
943
4597.8.7 by Vincent Ladeuil
Add whitebox tests for ParentLoop.
944
    def _get_resolve_path_arg(self, wt, action):
4597.10.9 by Vincent Ladeuil
More doc.
945
        # ParentLoop says: moving <conflict_path> into <path>. Cancelled move.
4597.8.7 by Vincent Ladeuil
Add whitebox tests for ParentLoop.
946
        # But since <path> doesn't exist in the working tree, we need to use
4597.10.9 by Vincent Ladeuil
More doc.
947
        # <conflict_path> instead, and that, in turn, is given by dir_id. Pfew.
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
948
        return wt.id2path(self._other['dir_id'])
4597.8.7 by Vincent Ladeuil
Add whitebox tests for ParentLoop.
949
950
    def assertParentLoop(self, wt, c):
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
951
        self.assertEqual(self._other['dir_id'], c.file_id)
952
        self.assertEqual(self._other['target_id'], c.conflict_file_id)
4597.8.8 by Vincent Ladeuil
Exhibit bug #537956.
953
        # The conflict paths are irrelevant (they are deterministic but not
954
        # worth checking since they don't provide the needed information
955
        # anyway)
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
956
        if self._other['xfail']:
957
            # It's a bit hackish to raise from here relying on being called for
958
            # both tests but this avoid overriding test_resolve_taking_other
4597.10.4 by Vincent Ladeuil
Handle TestResolveParentLoop expected failures more precisely.
959
            raise tests.KnownFailure(
960
                "ParentLoop doesn't carry enough info to resolve --take-other")
4597.8.7 by Vincent Ladeuil
Add whitebox tests for ParentLoop.
961
    _assert_conflict = assertParentLoop
962
963
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
964
class TestResolveNonDirectoryParent(TestResolveConflicts):
965
966
    preamble = """
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
967
$ bzr init trunk
5422.3.4 by Martin Pool
Update test_resolve to pass --quiet or ignore command output it doesn't care about
968
...
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
969
$ cd trunk
970
$ bzr mkdir foo
5422.3.4 by Martin Pool
Update test_resolve to pass --quiet or ignore command output it doesn't care about
971
...
972
$ bzr commit -m 'Create trunk' -q
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
973
$ echo "Boing" >foo/bar
5422.3.4 by Martin Pool
Update test_resolve to pass --quiet or ignore command output it doesn't care about
974
$ bzr add -q foo/bar
975
$ bzr commit -q -m 'Add foo/bar'
976
$ bzr branch -q . -r 1 ../branch
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
977
$ cd ../branch
978
$ rm -r foo
979
$ echo "Boo!" >foo
5422.3.4 by Martin Pool
Update test_resolve to pass --quiet or ignore command output it doesn't care about
980
$ bzr commit -q -m 'foo is now a file'
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
981
$ bzr merge ../trunk
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
982
2>+N  foo.new/bar
983
2>RK  foo => foo.new/
984
# FIXME: The message is misleading, foo.new *is* a directory when the message
985
# is displayed -- vila 090916
986
2>Conflict: foo.new is not a directory, but has files in it.  Created directory.
987
2>1 conflicts encountered.
988
"""
989
4597.3.67 by Vincent Ladeuil
Settle with --take-this and --take-other as action names.
990
    def test_take_this(self):
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
991
        self.run_script("""
5422.3.4 by Martin Pool
Update test_resolve to pass --quiet or ignore command output it doesn't care about
992
$ bzr rm -q foo.new --force
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
993
# FIXME: Isn't it weird that foo is now unkown even if foo.new has been put
994
# aside ? -- vila 090916
5422.3.4 by Martin Pool
Update test_resolve to pass --quiet or ignore command output it doesn't care about
995
$ bzr add -q foo
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
996
$ bzr resolve foo.new
4597.9.19 by Vincent Ladeuil
resolve now reports conflicts resolved/remaining.
997
2>1 conflict(s) resolved, 0 remaining
5422.3.4 by Martin Pool
Update test_resolve to pass --quiet or ignore command output it doesn't care about
998
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
999
""")
1000
4597.3.67 by Vincent Ladeuil
Settle with --take-this and --take-other as action names.
1001
    def test_take_other(self):
4597.3.35 by Vincent Ladeuil
Implement --interactive for NonDirectoryParent, sort of.
1002
        self.run_script("""
5422.3.4 by Martin Pool
Update test_resolve to pass --quiet or ignore command output it doesn't care about
1003
$ bzr rm -q foo --force
1004
$ bzr mv -q foo.new foo
4597.3.35 by Vincent Ladeuil
Implement --interactive for NonDirectoryParent, sort of.
1005
$ bzr resolve foo
4597.9.19 by Vincent Ladeuil
resolve now reports conflicts resolved/remaining.
1006
2>1 conflict(s) resolved, 0 remaining
5422.3.4 by Martin Pool
Update test_resolve to pass --quiet or ignore command output it doesn't care about
1007
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
4597.3.35 by Vincent Ladeuil
Implement --interactive for NonDirectoryParent, sort of.
1008
""")
1009
4597.3.67 by Vincent Ladeuil
Settle with --take-this and --take-other as action names.
1010
    def test_resolve_taking_this(self):
4597.3.35 by Vincent Ladeuil
Implement --interactive for NonDirectoryParent, sort of.
1011
        self.run_script("""
4597.3.67 by Vincent Ladeuil
Settle with --take-this and --take-other as action names.
1012
$ bzr resolve --take-this foo.new
5422.3.4 by Martin Pool
Update test_resolve to pass --quiet or ignore command output it doesn't care about
1013
2>...
1014
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
4597.3.35 by Vincent Ladeuil
Implement --interactive for NonDirectoryParent, sort of.
1015
""")
1016
4597.3.67 by Vincent Ladeuil
Settle with --take-this and --take-other as action names.
1017
    def test_resolve_taking_other(self):
4597.3.35 by Vincent Ladeuil
Implement --interactive for NonDirectoryParent, sort of.
1018
        self.run_script("""
4597.3.67 by Vincent Ladeuil
Settle with --take-this and --take-other as action names.
1019
$ bzr resolve --take-other foo.new
5422.3.4 by Martin Pool
Update test_resolve to pass --quiet or ignore command output it doesn't care about
1020
2>...
1021
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
4597.3.35 by Vincent Ladeuil
Implement --interactive for NonDirectoryParent, sort of.
1022
""")
1023
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
1024
1025
class TestMalformedTransform(script.TestCaseWithTransportAndScript):
1026
1027
    def test_bug_430129(self):
1028
        # This is nearly like TestResolveNonDirectoryParent but with branch and
1029
        # trunk switched. As such it should certainly produce the same
1030
        # conflict.
1031
        self.run_script("""
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
1032
$ bzr init trunk
5422.3.4 by Martin Pool
Update test_resolve to pass --quiet or ignore command output it doesn't care about
1033
...
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
1034
$ cd trunk
1035
$ bzr mkdir foo
5422.3.4 by Martin Pool
Update test_resolve to pass --quiet or ignore command output it doesn't care about
1036
...
1037
$ bzr commit -m 'Create trunk' -q
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
1038
$ rm -r foo
1039
$ echo "Boo!" >foo
5422.3.4 by Martin Pool
Update test_resolve to pass --quiet or ignore command output it doesn't care about
1040
$ bzr commit -m 'foo is now a file' -q
1041
$ bzr branch -q . -r 1 ../branch -q
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
1042
$ cd ../branch
1043
$ echo "Boing" >foo/bar
5422.3.4 by Martin Pool
Update test_resolve to pass --quiet or ignore command output it doesn't care about
1044
$ bzr add -q foo/bar -q
1045
$ bzr commit -m 'Add foo/bar' -q
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
1046
$ bzr merge ../trunk
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
1047
2>bzr: ERROR: Tree transform is malformed [('unversioned executability', 'new-1')]
1048
""")
4597.3.51 by Vincent Ladeuil
Implement conflicts.ResolveActionOption.
1049
5050.63.2 by Vincent Ladeuil
The file should be in a subdir to reproduce the bug.
1050
4597.3.51 by Vincent Ladeuil
Implement conflicts.ResolveActionOption.
1051
class TestResolveActionOption(tests.TestCase):
1052
1053
    def setUp(self):
1054
        super(TestResolveActionOption, self).setUp()
1055
        self.options = [conflicts.ResolveActionOption()]
1056
        self.parser = option.get_optparser(dict((o.name, o)
1057
                                                for o in self.options))
1058
1059
    def parse(self, args):
1060
        return self.parser.parse_args(args)
1061
1062
    def test_unknown_action(self):
1063
        self.assertRaises(errors.BadOptionValue,
1064
                          self.parse, ['--action', 'take-me-to-the-moon'])
1065
1066
    def test_done(self):
1067
        opts, args = self.parse(['--action', 'done'])
1068
        self.assertEqual({'action':'done'}, opts)
1069
4597.3.67 by Vincent Ladeuil
Settle with --take-this and --take-other as action names.
1070
    def test_take_this(self):
1071
        opts, args = self.parse(['--action', 'take-this'])
1072
        self.assertEqual({'action': 'take_this'}, opts)
1073
        opts, args = self.parse(['--take-this'])
1074
        self.assertEqual({'action': 'take_this'}, opts)
4597.3.51 by Vincent Ladeuil
Implement conflicts.ResolveActionOption.
1075
4597.3.67 by Vincent Ladeuil
Settle with --take-this and --take-other as action names.
1076
    def test_take_other(self):
1077
        opts, args = self.parse(['--action', 'take-other'])
1078
        self.assertEqual({'action': 'take_other'}, opts)
1079
        opts, args = self.parse(['--take-other'])
1080
        self.assertEqual({'action': 'take_other'}, opts)