/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
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
20
from .. import (
4597.2.2 by Vincent Ladeuil
Cleanup conflict tests.
21
    conflicts,
22
    errors,
4597.3.51 by Vincent Ladeuil
Implement conflicts.ResolveActionOption.
23
    option,
5609.17.1 by Vincent Ladeuil
Reproduce bug #715068.
24
    osutils,
4597.2.2 by Vincent Ladeuil
Cleanup conflict tests.
25
    tests,
26
    )
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
27
from . import (
4597.13.3 by Vincent Ladeuil
Switch to load_tests_apply_scenarios.
28
    script,
29
    scenarios,
30
    )
31
32
33
load_tests = scenarios.load_tests_apply_scenarios
4597.2.26 by Vincent Ladeuil
Fix bug #529968 by renaming the kept file on content conflicts.
34
35
1185.14.8 by Aaron Bentley
Added test_commit.py
36
# 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.
37
# RBC 20060124 is that not tested in test_commit.py ?
1185.14.8 by Aaron Bentley
Added test_commit.py
38
1666.1.4 by Robert Collins
* 'Metadir' is now the default disk format. This improves behaviour in
39
# The order of 'path' here is important - do not let it
40
# 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.
41
# u'\xe5' == a with circle
42
# '\xc3\xae' == u'\xee' == i with hat
4597.2.2 by Vincent Ladeuil
Cleanup conflict tests.
43
# So these are u'path' and 'id' only with a circle and a hat. (shappo?)
44
example_conflicts = conflicts.ConflictList(
45
    [conflicts.MissingParent('Not deleting', u'p\xe5thg', '\xc3\xaedg'),
46
     conflicts.ContentsConflict(u'p\xe5tha', None, '\xc3\xaeda'),
47
     conflicts.TextConflict(u'p\xe5tha'),
48
     conflicts.PathConflict(u'p\xe5thb', u'p\xe5thc', '\xc3\xaedb'),
49
     conflicts.DuplicateID('Unversioned existing file',
50
                           u'p\xe5thc', u'p\xe5thc2',
51
                           '\xc3\xaedc', '\xc3\xaedc'),
52
    conflicts.DuplicateEntry('Moved existing file to',
53
                             u'p\xe5thdd.moved', u'p\xe5thd',
54
                             '\xc3\xaedd', None),
55
    conflicts.ParentLoop('Cancelled move', u'p\xe5the', u'p\xe5th2e',
56
                         None, '\xc3\xaed2e'),
57
    conflicts.UnversionedParent('Versioned directory',
58
                                u'p\xe5thf', '\xc3\xaedf'),
59
    conflicts.NonDirectoryParent('Created directory',
60
                                 u'p\xe5thg', '\xc3\xaedg'),
1534.10.22 by Aaron Bentley
Got ConflictList implemented
61
])
1534.10.4 by Aaron Bentley
Implemented conflict serialization
62
63
5898.1.1 by Martin
Refactor conflict stanzas tests to use scenarios
64
def vary_by_conflicts():
65
    for conflict in example_conflicts:
66
        yield (conflict.__class__.__name__, {"conflict": conflict})
67
68
4597.2.2 by Vincent Ladeuil
Cleanup conflict tests.
69
class TestConflicts(tests.TestCaseWithTransport):
1185.14.8 by Aaron Bentley
Added test_commit.py
70
1558.12.9 by Aaron Bentley
Handle resolving conflicts with directories properly
71
    def test_resolve_conflict_dir(self):
72
        tree = self.make_branch_and_tree('.')
6855.4.1 by Jelmer Vernooij
Yet more bees.
73
        self.build_tree_contents([('hello', b'hello world4'),
74
                                  ('hello.THIS', b'hello world2'),
75
                                  ('hello.BASE', b'hello world1'),
4597.2.3 by Vincent Ladeuil
More cleanup.
76
                                  ])
77
        os.mkdir('hello.OTHER')
1558.12.9 by Aaron Bentley
Handle resolving conflicts with directories properly
78
        tree.add('hello', 'q')
4597.2.3 by Vincent Ladeuil
More cleanup.
79
        l = conflicts.ConflictList([conflicts.TextConflict('hello')])
1558.12.9 by Aaron Bentley
Handle resolving conflicts with directories properly
80
        l.remove_files(tree)
81
1551.15.58 by Aaron Bentley
Status honours selected paths for conflicts (#127606)
82
    def test_select_conflicts(self):
83
        tree = self.make_branch_and_tree('.')
4597.2.3 by Vincent Ladeuil
More cleanup.
84
        clist = conflicts.ConflictList
85
86
        def check_select(not_selected, selected, paths, **kwargs):
87
            self.assertEqual(
88
                (not_selected, selected),
89
                tree_conflicts.select_conflicts(tree, paths, **kwargs))
90
91
        foo = conflicts.ContentsConflict('foo')
92
        bar = conflicts.ContentsConflict('bar')
93
        tree_conflicts = clist([foo, bar])
94
95
        check_select(clist([bar]), clist([foo]), ['foo'])
96
        check_select(clist(), tree_conflicts,
97
                     [''], ignore_misses=True, recurse=True)
98
99
        foobaz  = conflicts.ContentsConflict('foo/baz')
100
        tree_conflicts = clist([foobaz, bar])
101
102
        check_select(clist([bar]), clist([foobaz]),
103
                     ['foo'], ignore_misses=True, recurse=True)
104
105
        qux = conflicts.PathConflict('qux', 'foo/baz')
106
        tree_conflicts = clist([qux])
107
108
        check_select(clist(), tree_conflicts,
109
                     ['foo'], ignore_misses=True, recurse=True)
110
        check_select (tree_conflicts, clist(), ['foo'], ignore_misses=True)
1551.15.58 by Aaron Bentley
Status honours selected paths for conflicts (#127606)
111
3017.2.1 by Aaron Bentley
Revert now resolves conflicts recursively (#102739)
112
    def test_resolve_conflicts_recursive(self):
113
        tree = self.make_branch_and_tree('.')
114
        self.build_tree(['dir/', 'dir/hello'])
115
        tree.add(['dir', 'dir/hello'])
4597.2.3 by Vincent Ladeuil
More cleanup.
116
117
        dirhello = conflicts.ConflictList([conflicts.TextConflict('dir/hello')])
118
        tree.set_conflicts(dirhello)
119
120
        conflicts.resolve(tree, ['dir'], recursive=False, ignore_misses=True)
121
        self.assertEqual(dirhello, tree.conflicts())
122
123
        conflicts.resolve(tree, ['dir'], recursive=True, ignore_misses=True)
124
        self.assertEqual(conflicts.ConflictList([]), tree.conflicts())
4773.1.1 by Vincent Ladeuil
Cleanup imports in test_conflicts
125
126
5898.1.3 by Martin
Add tests for non-ascii conflict serialisation
127
class TestPerConflict(tests.TestCase):
4597.3.43 by Vincent Ladeuil
Cleanups, ready to record.
128
5898.1.1 by Martin
Refactor conflict stanzas tests to use scenarios
129
    scenarios = scenarios.multiply_scenarios(vary_by_conflicts())
130
5898.1.3 by Martin
Add tests for non-ascii conflict serialisation
131
    def test_stringification(self):
132
        text = unicode(self.conflict)
133
        self.assertContainsString(text, self.conflict.path)
134
        self.assertContainsString(text.lower(), "conflict")
135
        self.assertContainsString(repr(self.conflict),
136
            self.conflict.__class__.__name__)
137
4597.3.43 by Vincent Ladeuil
Cleanups, ready to record.
138
    def test_stanza_roundtrip(self):
5898.1.1 by Martin
Refactor conflict stanzas tests to use scenarios
139
        p = self.conflict
140
        o = conflicts.Conflict.factory(**p.as_stanza().as_dict())
141
        self.assertEqual(o, p)
142
143
        self.assertIsInstance(o.path, unicode)
144
145
        if o.file_id is not None:
146
            self.assertIsInstance(o.file_id, str)
147
148
        conflict_path = getattr(o, 'conflict_path', None)
149
        if conflict_path is not None:
150
            self.assertIsInstance(conflict_path, unicode)
151
152
        conflict_file_id = getattr(o, 'conflict_file_id', None)
153
        if conflict_file_id is not None:
154
            self.assertIsInstance(conflict_file_id, str)
4597.3.43 by Vincent Ladeuil
Cleanups, ready to record.
155
156
    def test_stanzification(self):
5898.1.1 by Martin
Refactor conflict stanzas tests to use scenarios
157
        stanza = self.conflict.as_stanza()
158
        if 'file_id' in stanza:
159
            # In Stanza form, the file_id has to be unicode.
160
            self.assertStartsWith(stanza['file_id'], u'\xeed')
161
        self.assertStartsWith(stanza['path'], u'p\xe5th')
162
        if 'conflict_path' in stanza:
163
            self.assertStartsWith(stanza['conflict_path'], u'p\xe5th')
164
        if 'conflict_file_id' in stanza:
165
            self.assertStartsWith(stanza['conflict_file_id'], u'\xeed')
166
167
5898.1.3 by Martin
Add tests for non-ascii conflict serialisation
168
class TestConflictList(tests.TestCase):
5898.1.1 by Martin
Refactor conflict stanzas tests to use scenarios
169
170
    def test_stanzas_roundtrip(self):
171
        stanzas_iter = example_conflicts.to_stanzas()
172
        processed = conflicts.ConflictList.from_stanzas(stanzas_iter)
173
        self.assertEqual(example_conflicts, processed)
4597.3.43 by Vincent Ladeuil
Cleanups, ready to record.
174
5898.1.3 by Martin
Add tests for non-ascii conflict serialisation
175
    def test_stringification(self):
176
        for text, o in zip(example_conflicts.to_strings(), example_conflicts):
177
            self.assertEqual(text, unicode(o))
178
4597.3.43 by Vincent Ladeuil
Cleanups, ready to record.
179
4597.3.74 by Vincent Ladeuil
Add a FIXME about rewriting shell-like tests into real whitebox tests.
180
# FIXME: The shell-like tests should be converted to real whitebox tests... or
181
# moved to a blackbox module -- vila 20100205
182
4597.7.11 by Vincent Ladeuil
Fix #531967 by creating helpers for PathConflicts when a deletion
183
# FIXME: test missing for multiple conflicts
184
4597.3.31 by Vincent Ladeuil
Implement --interactive for MissingParent.
185
# FIXME: Tests missing for DuplicateID conflict type
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
186
class TestResolveConflicts(script.TestCaseWithTransportAndScript):
187
188
    preamble = None # The setup script set by daughter classes
189
190
    def setUp(self):
191
        super(TestResolveConflicts, self).setUp()
192
        self.run_script(self.preamble)
193
194
4597.10.11 by Vincent Ladeuil
Turn mirror_scenarios into a simple function.
195
def mirror_scenarios(base_scenarios):
196
    """Return a list of mirrored scenarios.
197
198
    Each scenario in base_scenarios is duplicated switching the roles of 'this'
199
    and 'other'
200
    """
201
    scenarios = []
4597.10.14 by Vincent Ladeuil
Some more cleanup and typos.
202
    for common, (lname, ldict), (rname, rdict) in base_scenarios:
4597.10.11 by Vincent Ladeuil
Turn mirror_scenarios into a simple function.
203
        a = tests.multiply_scenarios([(lname, dict(_this=ldict))],
204
                                     [(rname, dict(_other=rdict))])
205
        b = tests.multiply_scenarios([(rname, dict(_this=rdict))],
206
                                     [(lname, dict(_other=ldict))])
207
        # Inject the common parameters in all scenarios
208
        for name, d in a + b:
209
            d.update(common)
210
        scenarios.extend(a + b)
211
    return scenarios
212
213
4597.7.10 by Vincent Ladeuil
Define scenarios by test classes.
214
# FIXME: Get rid of parametrized (in the class name) once we delete
215
# TestResolveConflicts -- vila 20100308
4597.7.4 by Vincent Ladeuil
Abstract the test class some more to address more conflict
216
class TestParametrizedResolveConflicts(tests.TestCaseWithTransport):
4597.7.18 by Vincent Ladeuil
Start addressing Andrew's concerns.
217
    """This class provides a base to test single conflict resolution.
218
4597.10.7 by Vincent Ladeuil
Simplify scenarios mirroring and give a better docstring for TestParametrizedResolveConflicts.
219
    Since all conflict objects are created with specific semantics for their
220
    attributes, each class should implement the necessary functions and
221
    attributes described below.
222
223
    Each class should define the scenarios that create the expected (single)
224
    conflict.
225
226
    Each scenario describes:
227
    * how to create 'base' tree (and revision)
228
    * how to create 'left' tree (and revision, parent rev 'base')
229
    * how to create 'right' tree (and revision, parent rev 'base')
230
    * how to check that changes in 'base'->'left' have been taken
231
    * how to check that changes in 'base'->'right' have been taken
232
233
    From each base scenario, we generate two concrete scenarios where:
234
    * this=left, other=right
235
    * this=right, other=left
236
237
    Then the test case verifies each concrete scenario by:
238
    * creating a branch containing the 'base', 'this' and 'other' revisions
239
    * creating a working tree for the 'this' revision
240
    * performing the merge of 'other' into 'this'
241
    * verifying the expected conflict was generated
242
    * resolving with --take-this or --take-other, and running the corresponding
243
      checks (for either 'base'->'this', or 'base'->'other')
244
245
    :cvar _conflict_type: The expected class of the generated conflict.
246
247
    :cvar _assert_conflict: A method receiving the working tree and the
248
        conflict object and checking its attributes.
249
4597.10.9 by Vincent Ladeuil
More doc.
250
    :cvar _base_actions: The branchbuilder actions to create the 'base'
251
        revision.
252
253
    :cvar _this: The dict related to 'base' -> 'this'. It contains at least:
254
      * 'actions': The branchbuilder actions to create the 'this'
255
          revision.
4597.10.10 by Vincent Ladeuil
Fix typo.
256
      * 'check': how to check the changes after resolution with --take-this.
4597.10.9 by Vincent Ladeuil
More doc.
257
258
    :cvar _other: The dict related to 'base' -> 'other'. It contains at least:
259
      * 'actions': The branchbuilder actions to create the 'other'
260
          revision.
4597.10.10 by Vincent Ladeuil
Fix typo.
261
      * 'check': how to check the changes after resolution with --take-other.
4597.7.18 by Vincent Ladeuil
Start addressing Andrew's concerns.
262
    """
4597.2.23 by Vincent Ladeuil
Start translating blackbox tests into whitebox ones.
263
4597.7.16 by Vincent Ladeuil
Some cleanup.
264
    # Set by daughter classes
265
    _conflict_type = None
266
    _assert_conflict = None
267
4597.2.26 by Vincent Ladeuil
Fix bug #529968 by renaming the kept file on content conflicts.
268
    # Set by load_tests
4597.7.6 by Vincent Ladeuil
Cleanup TestParametrizedResolveConflicts some more.
269
    _base_actions = None
4597.10.7 by Vincent Ladeuil
Simplify scenarios mirroring and give a better docstring for TestParametrizedResolveConflicts.
270
    _this = None
271
    _other = None
4597.7.7 by Vincent Ladeuil
Reproduce bug #531967 on various aspects.
272
4597.13.3 by Vincent Ladeuil
Switch to load_tests_apply_scenarios.
273
    scenarios = []
274
    """The scenario list for the conflict type defined by the class.
275
276
    Each scenario is of the form:
277
    (common, (left_name, left_dict), (right_name, right_dict))
278
279
    * common is a dict
280
281
    * left_name and right_name are the scenario names that will be combined
282
283
    * left_dict and right_dict are the attributes specific to each half of
284
      the scenario. They should include at least 'actions' and 'check' and
285
      will be available as '_this' and '_other' test instance attributes.
286
287
    Daughters classes are free to add their specific attributes as they see
288
    fit in any of the three dicts.
289
290
    This is a class method so that load_tests can find it.
291
292
    '_base_actions' in the common dict, 'actions' and 'check' in the left
293
    and right dicts use names that map to methods in the test classes. Some
294
    prefixes are added to these names to get the correspong methods (see
295
    _get_actions() and _get_check()). The motivation here is to avoid
296
    collisions in the class namespace.
297
    """
4597.7.10 by Vincent Ladeuil
Define scenarios by test classes.
298
4597.2.23 by Vincent Ladeuil
Start translating blackbox tests into whitebox ones.
299
    def setUp(self):
4597.7.4 by Vincent Ladeuil
Abstract the test class some more to address more conflict
300
        super(TestParametrizedResolveConflicts, self).setUp()
4597.2.23 by Vincent Ladeuil
Start translating blackbox tests into whitebox ones.
301
        builder = self.make_branch_builder('trunk')
302
        builder.start_series()
4597.7.6 by Vincent Ladeuil
Cleanup TestParametrizedResolveConflicts some more.
303
4597.2.23 by Vincent Ladeuil
Start translating blackbox tests into whitebox ones.
304
        # Create an empty trunk
6816.2.1 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
305
        builder.build_snapshot(None, [
306
                ('add', ('', 'root-id', 'directory', ''))],
307
                revision_id='start')
4597.2.23 by Vincent Ladeuil
Start translating blackbox tests into whitebox ones.
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)()
6816.2.1 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
310
        builder.build_snapshot(['start'], base_actions, revision_id='base')
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'])()
6816.2.1 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
313
        builder.build_snapshot(['base'], actions_other, revision_id='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'])()
6816.2.1 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
316
        builder.build_snapshot(['base'], actions_this, revision_id='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()
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
330
        wt = b.controldir.sprout('branch').open_workingtree()
4597.2.23 by Vincent Ladeuil
Start translating blackbox tests into whitebox ones.
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',
6883.22.4 by Jelmer Vernooij
Fix some conflict tests.
388
              dict(actions='modify_file_A_in_dir',
5609.17.1 by Vincent Ladeuil
Reproduce bug #715068.
389
                   check='file_in_dir_has_content_A')),
390
             ('file_modified_B',
6883.22.4 by Jelmer Vernooij
Fix some conflict tests.
391
              dict(actions='modify_file_B_in_dir',
5609.17.1 by Vincent Ladeuil
Reproduce bug #715068.
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):
6883.22.4 by Jelmer Vernooij
Fix some conflict tests.
399
        return [('modify', ('file', 'trunk content\nfeature A\n'))]
4597.14.2 by Vincent Ladeuil
Implements --take-this and --take-other when resolving text conflicts
400
401
    def do_modify_file_B(self):
6883.22.4 by Jelmer Vernooij
Fix some conflict tests.
402
        return [('modify', ('file', 'trunk content\nfeature B\n'))]
403
404
    def do_modify_file_A_in_dir(self):
405
        return [('modify', ('dir/file', 'trunk content\nfeature A\n'))]
406
407
    def do_modify_file_B_in_dir(self):
408
        return [('modify', ('dir/file', 'trunk content\nfeature B\n'))]
4597.14.2 by Vincent Ladeuil
Implements --take-this and --take-other when resolving text conflicts
409
5609.17.1 by Vincent Ladeuil
Reproduce bug #715068.
410
    def check_file_has_content_A(self, path='file'):
411
        self.assertFileEqual('trunk content\nfeature A\n',
412
                             osutils.pathjoin('branch', path))
413
414
    def check_file_has_content_B(self, path='file'):
415
        self.assertFileEqual('trunk content\nfeature B\n',
416
                             osutils.pathjoin('branch', path))
417
418
    def do_create_file_in_dir(self):
419
        return [('add', ('dir', 'dir-id', 'directory', '')),
420
            ] + self.do_create_file('dir/file')
421
422
    def check_file_in_dir_has_content_A(self):
423
        self.check_file_has_content_A('dir/file')
424
425
    def check_file_in_dir_has_content_B(self):
426
        self.check_file_has_content_B('dir/file')
4597.14.2 by Vincent Ladeuil
Implements --take-this and --take-other when resolving text conflicts
427
428
    def _get_resolve_path_arg(self, wt, action):
429
        return self._path
430
431
    def assertTextConflict(self, wt, c):
432
        self.assertEqual(self._file_id, c.file_id)
433
        self.assertEqual(self._path, c.path)
434
    _assert_conflict = assertTextConflict
435
436
4597.7.10 by Vincent Ladeuil
Define scenarios by test classes.
437
class TestResolveContentsConflict(TestParametrizedResolveConflicts):
438
4597.13.3 by Vincent Ladeuil
Switch to load_tests_apply_scenarios.
439
    _conflict_type = conflicts.ContentsConflict
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
440
4597.13.3 by Vincent Ladeuil
Switch to load_tests_apply_scenarios.
441
    # Set by the scenarios
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
442
    # path and file-id for the file involved in the conflict
443
    _path = None
444
    _file_id = None
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
445
4597.13.3 by Vincent Ladeuil
Switch to load_tests_apply_scenarios.
446
    scenarios = mirror_scenarios(
447
        [
4597.10.12 by Vincent Ladeuil
Some more doc.
448
            # File modified/deleted
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
449
            (dict(_base_actions='create_file',
450
                  _path='file', _file_id='file-id'),
4597.10.12 by Vincent Ladeuil
Some more doc.
451
             ('file_modified',
452
              dict(actions='modify_file', check='file_has_more_content')),
453
             ('file_deleted',
454
              dict(actions='delete_file', check='file_doesnt_exist')),),
5988.2.1 by Vincent Ladeuil
Do not generate path conflicts if a corresponding content conflict exists
455
            # File renamed-modified/deleted
456
            (dict(_base_actions='create_file',
457
                  _path='new-file', _file_id='file-id'),
458
             ('file_renamed_and_modified',
459
              dict(actions='modify_and_rename_file',
460
                   check='file_renamed_and_more_content')),
461
             ('file_deleted',
462
              dict(actions='delete_file', check='file_doesnt_exist')),),
5050.63.3 by Vincent Ladeuil
Correctly resolve content conflicts for files in subdirs
463
            # File modified/deleted in dir
464
            (dict(_base_actions='create_file_in_dir',
465
                  _path='dir/file', _file_id='file-id'),
466
             ('file_modified_in_dir',
467
              dict(actions='modify_file_in_dir',
468
                   check='file_in_dir_has_more_content')),
469
             ('file_deleted_in_dir',
6883.22.6 by Jelmer Vernooij
Fix some more tests.
470
              dict(actions='delete_file_in_dir',
5050.63.3 by Vincent Ladeuil
Correctly resolve content conflicts for files in subdirs
471
                   check='file_in_dir_doesnt_exist')),),
4597.13.3 by Vincent Ladeuil
Switch to load_tests_apply_scenarios.
472
            ])
4597.7.10 by Vincent Ladeuil
Define scenarios by test classes.
473
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
474
    def do_create_file(self):
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
475
        return [('add', ('file', 'file-id', 'file', 'trunk content\n'))]
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
476
477
    def do_modify_file(self):
6883.22.6 by Jelmer Vernooij
Fix some more tests.
478
        return [('modify', ('file', 'trunk content\nmore content\n'))]
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
479
5988.2.1 by Vincent Ladeuil
Do not generate path conflicts if a corresponding content conflict exists
480
    def do_modify_and_rename_file(self):
6883.22.12 by Jelmer Vernooij
Fix test failure.
481
        return [('modify', ('new-file', 'trunk content\nmore content\n')),
5988.2.1 by Vincent Ladeuil
Do not generate path conflicts if a corresponding content conflict exists
482
                ('rename', ('file', 'new-file'))]
483
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
484
    def check_file_has_more_content(self):
485
        self.assertFileEqual('trunk content\nmore content\n', 'branch/file')
486
5988.2.1 by Vincent Ladeuil
Do not generate path conflicts if a corresponding content conflict exists
487
    def check_file_renamed_and_more_content(self):
488
        self.assertFileEqual('trunk content\nmore content\n', 'branch/new-file')
489
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
490
    def do_delete_file(self):
6883.22.5 by Jelmer Vernooij
Fix more tests.
491
        return [('unversion', 'file')]
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
492
6883.22.6 by Jelmer Vernooij
Fix some more tests.
493
    def do_delete_file_in_dir(self):
494
        return [('unversion', 'dir/file')]
495
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
496
    def check_file_doesnt_exist(self):
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
497
        self.assertPathDoesNotExist('branch/file')
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
498
5050.63.3 by Vincent Ladeuil
Correctly resolve content conflicts for files in subdirs
499
    def do_create_file_in_dir(self):
500
        return [('add', ('dir', 'dir-id', 'directory', '')),
501
                ('add', ('dir/file', 'file-id', 'file', 'trunk content\n'))]
502
503
    def do_modify_file_in_dir(self):
6883.22.6 by Jelmer Vernooij
Fix some more tests.
504
        return [('modify', ('dir/file', 'trunk content\nmore content\n'))]
5050.63.3 by Vincent Ladeuil
Correctly resolve content conflicts for files in subdirs
505
506
    def check_file_in_dir_has_more_content(self):
507
        self.assertFileEqual('trunk content\nmore content\n', 'branch/dir/file')
508
509
    def check_file_in_dir_doesnt_exist(self):
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
510
        self.assertPathDoesNotExist('branch/dir/file')
5050.63.3 by Vincent Ladeuil
Correctly resolve content conflicts for files in subdirs
511
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
512
    def _get_resolve_path_arg(self, wt, action):
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
513
        return self._path
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
514
4597.7.17 by Vincent Ladeuil
Add a scenario and activate the compatibility tests.
515
    def assertContentsConflict(self, wt, c):
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
516
        self.assertEqual(self._file_id, c.file_id)
517
        self.assertEqual(self._path, c.path)
4597.7.16 by Vincent Ladeuil
Some cleanup.
518
    _assert_conflict = assertContentsConflict
519
4597.7.10 by Vincent Ladeuil
Define scenarios by test classes.
520
521
class TestResolvePathConflict(TestParametrizedResolveConflicts):
522
4597.13.3 by Vincent Ladeuil
Switch to load_tests_apply_scenarios.
523
    _conflict_type = conflicts.PathConflict
4597.7.16 by Vincent Ladeuil
Some cleanup.
524
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
525
    def do_nothing(self):
526
        return []
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
527
4597.13.3 by Vincent Ladeuil
Switch to load_tests_apply_scenarios.
528
    # Each side dict additionally defines:
529
    # - path path involved (can be '<deleted>')
530
    # - file-id involved
531
    scenarios = mirror_scenarios(
532
        [
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
533
            # File renamed/deleted
534
            (dict(_base_actions='create_file'),
535
             ('file_renamed',
536
              dict(actions='rename_file', check='file_renamed',
537
                   path='new-file', file_id='file-id')),
4597.7.17 by Vincent Ladeuil
Add a scenario and activate the compatibility tests.
538
             ('file_deleted',
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
539
              dict(actions='delete_file', check='file_doesnt_exist',
540
                   # PathConflicts deletion handling requires a special
541
                   # hard-coded value
542
                   path='<deleted>', file_id='file-id')),),
5050.63.6 by Vincent Ladeuil
Same fix for path conflicts.
543
            # File renamed/deleted in dir
544
            (dict(_base_actions='create_file_in_dir'),
545
             ('file_renamed_in_dir',
546
              dict(actions='rename_file_in_dir', check='file_in_dir_renamed',
547
                   path='dir/new-file', file_id='file-id')),
548
             ('file_deleted',
6883.22.5 by Jelmer Vernooij
Fix more tests.
549
              dict(actions='delete_file_in_dir', check='file_in_dir_doesnt_exist',
5050.63.6 by Vincent Ladeuil
Same fix for path conflicts.
550
                   # PathConflicts deletion handling requires a special
551
                   # hard-coded value
552
                   path='<deleted>', file_id='file-id')),),
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
553
            # File renamed/renamed differently
554
            (dict(_base_actions='create_file'),
555
             ('file_renamed',
556
              dict(actions='rename_file', check='file_renamed',
557
                   path='new-file', file_id='file-id')),
4597.8.4 by Vincent Ladeuil
Delete PathConflict bloackbox tests.
558
             ('file_renamed2',
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
559
              dict(actions='rename_file2', check='file_renamed2',
560
                   path='new-file2', file_id='file-id')),),
561
            # Dir renamed/deleted
562
            (dict(_base_actions='create_dir'),
563
             ('dir_renamed',
564
              dict(actions='rename_dir', check='dir_renamed',
565
                   path='new-dir', file_id='dir-id')),
4597.7.17 by Vincent Ladeuil
Add a scenario and activate the compatibility tests.
566
             ('dir_deleted',
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
567
              dict(actions='delete_dir', check='dir_doesnt_exist',
568
                   # PathConflicts deletion handling requires a special
569
                   # hard-coded value
570
                   path='<deleted>', file_id='dir-id')),),
571
            # Dir renamed/renamed differently
572
            (dict(_base_actions='create_dir'),
573
             ('dir_renamed',
574
              dict(actions='rename_dir', check='dir_renamed',
575
                   path='new-dir', file_id='dir-id')),
4597.7.17 by Vincent Ladeuil
Add a scenario and activate the compatibility tests.
576
             ('dir_renamed2',
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
577
              dict(actions='rename_dir2', check='dir_renamed2',
578
                   path='new-dir2', file_id='dir-id')),),
4597.13.3 by Vincent Ladeuil
Switch to load_tests_apply_scenarios.
579
            ])
4597.7.17 by Vincent Ladeuil
Add a scenario and activate the compatibility tests.
580
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
581
    def do_create_file(self):
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
582
        return [('add', ('file', 'file-id', 'file', 'trunk content\n'))]
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
583
584
    def do_create_dir(self):
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
585
        return [('add', ('dir', 'dir-id', 'directory', ''))]
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
586
587
    def do_rename_file(self):
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
588
        return [('rename', ('file', 'new-file'))]
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
589
590
    def check_file_renamed(self):
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
591
        self.assertPathDoesNotExist('branch/file')
592
        self.assertPathExists('branch/new-file')
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
593
594
    def do_rename_file2(self):
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
595
        return [('rename', ('file', 'new-file2'))]
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
596
597
    def check_file_renamed2(self):
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
598
        self.assertPathDoesNotExist('branch/file')
599
        self.assertPathExists('branch/new-file2')
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
600
601
    def do_rename_dir(self):
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
602
        return [('rename', ('dir', 'new-dir'))]
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
603
604
    def check_dir_renamed(self):
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
605
        self.assertPathDoesNotExist('branch/dir')
606
        self.assertPathExists('branch/new-dir')
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
607
608
    def do_rename_dir2(self):
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
609
        return [('rename', ('dir', 'new-dir2'))]
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
610
611
    def check_dir_renamed2(self):
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
612
        self.assertPathDoesNotExist('branch/dir')
613
        self.assertPathExists('branch/new-dir2')
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
614
4597.7.17 by Vincent Ladeuil
Add a scenario and activate the compatibility tests.
615
    def do_delete_file(self):
6883.22.5 by Jelmer Vernooij
Fix more tests.
616
        return [('unversion', 'file')]
617
618
    def do_delete_file_in_dir(self):
619
        return [('unversion', 'dir/file')]
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
620
621
    def check_file_doesnt_exist(self):
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
622
        self.assertPathDoesNotExist('branch/file')
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
623
624
    def do_delete_dir(self):
6883.22.5 by Jelmer Vernooij
Fix more tests.
625
        return [('unversion', 'dir')]
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
626
627
    def check_dir_doesnt_exist(self):
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
628
        self.assertPathDoesNotExist('branch/dir')
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
629
5050.63.6 by Vincent Ladeuil
Same fix for path conflicts.
630
    def do_create_file_in_dir(self):
631
        return [('add', ('dir', 'dir-id', 'directory', '')),
632
                ('add', ('dir/file', 'file-id', 'file', 'trunk content\n'))]
633
634
    def do_rename_file_in_dir(self):
635
        return [('rename', ('dir/file', 'dir/new-file'))]
636
637
    def check_file_in_dir_renamed(self):
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
638
        self.assertPathDoesNotExist('branch/dir/file')
639
        self.assertPathExists('branch/dir/new-file')
5050.63.6 by Vincent Ladeuil
Same fix for path conflicts.
640
641
    def check_file_in_dir_doesnt_exist(self):
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
642
        self.assertPathDoesNotExist('branch/dir/file')
5050.63.6 by Vincent Ladeuil
Same fix for path conflicts.
643
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
644
    def _get_resolve_path_arg(self, wt, action):
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
645
        tpath = self._this['path']
646
        opath = self._other['path']
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
647
        if tpath == '<deleted>':
648
            path = opath
649
        else:
650
            path = tpath
651
        return path
4597.7.17 by Vincent Ladeuil
Add a scenario and activate the compatibility tests.
652
653
    def assertPathConflict(self, wt, c):
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
654
        tpath = self._this['path']
655
        tfile_id = self._this['file_id']
656
        opath = self._other['path']
657
        ofile_id = self._other['file_id']
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
658
        self.assertEqual(tfile_id, ofile_id) # Sanity check
659
        self.assertEqual(tfile_id, c.file_id)
660
        self.assertEqual(tpath, c.path)
661
        self.assertEqual(opath, c.conflict_path)
4597.7.16 by Vincent Ladeuil
Some cleanup.
662
    _assert_conflict = assertPathConflict
4597.7.10 by Vincent Ladeuil
Define scenarios by test classes.
663
664
4597.7.17 by Vincent Ladeuil
Add a scenario and activate the compatibility tests.
665
class TestResolvePathConflictBefore531967(TestResolvePathConflict):
4597.7.10 by Vincent Ladeuil
Define scenarios by test classes.
666
    """Same as TestResolvePathConflict but a specific conflict object.
667
    """
668
4597.7.16 by Vincent Ladeuil
Some cleanup.
669
    def assertPathConflict(self, c):
4597.7.17 by Vincent Ladeuil
Add a scenario and activate the compatibility tests.
670
        # We create a conflict object as it was created before the fix and
671
        # inject it into the working tree, the test will exercise the
672
        # compatibility code.
673
        old_c = conflicts.PathConflict('<deleted>', self._item_path,
674
                                       file_id=None)
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
675
        wt.set_conflicts(conflicts.ConflictList([old_c]))
4597.7.10 by Vincent Ladeuil
Define scenarios by test classes.
676
677
4597.8.5 by Vincent Ladeuil
Replace DuplicateEntry blackbox tests by whitebox ones.
678
class TestResolveDuplicateEntry(TestParametrizedResolveConflicts):
679
4597.13.3 by Vincent Ladeuil
Switch to load_tests_apply_scenarios.
680
    _conflict_type = conflicts.DuplicateEntry
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
681
4597.13.3 by Vincent Ladeuil
Switch to load_tests_apply_scenarios.
682
    scenarios = mirror_scenarios(
683
        [
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
684
            # File created with different file-ids
685
            (dict(_base_actions='nothing'),
686
             ('filea_created',
687
              dict(actions='create_file_a', check='file_content_a',
688
                   path='file', file_id='file-a-id')),
689
             ('fileb_created',
690
              dict(actions='create_file_b', check='file_content_b',
691
                   path='file', file_id='file-b-id')),),
6015.47.3 by Vincent Ladeuil
Failing tests reproducing bug #880701.
692
            # File created with different file-ids but deleted on one side
693
            (dict(_base_actions='create_file_a'),
694
             ('filea_replaced',
695
              dict(actions='replace_file_a_by_b', check='file_content_b',
696
                   path='file', file_id='file-b-id')),
697
             ('filea_modified',
698
              dict(actions='modify_file_a', check='file_new_content',
699
                   path='file', file_id='file-a-id')),),
4597.13.3 by Vincent Ladeuil
Switch to load_tests_apply_scenarios.
700
            ])
4597.8.5 by Vincent Ladeuil
Replace DuplicateEntry blackbox tests by whitebox ones.
701
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
702
    def do_nothing(self):
703
        return []
704
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
705
    def do_create_file_a(self):
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
706
        return [('add', ('file', 'file-a-id', 'file', 'file a content\n'))]
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
707
708
    def check_file_content_a(self):
709
        self.assertFileEqual('file a content\n', 'branch/file')
710
711
    def do_create_file_b(self):
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
712
        return [('add', ('file', 'file-b-id', 'file', 'file b content\n'))]
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
713
714
    def check_file_content_b(self):
715
        self.assertFileEqual('file b content\n', 'branch/file')
716
6015.47.3 by Vincent Ladeuil
Failing tests reproducing bug #880701.
717
    def do_replace_file_a_by_b(self):
6883.22.6 by Jelmer Vernooij
Fix some more tests.
718
        return [('unversion', 'file'),
6015.47.3 by Vincent Ladeuil
Failing tests reproducing bug #880701.
719
                ('add', ('file', 'file-b-id', 'file', 'file b content\n'))]
720
721
    def do_modify_file_a(self):
6883.22.6 by Jelmer Vernooij
Fix some more tests.
722
        return [('modify', ('file', 'new content\n'))]
6015.47.3 by Vincent Ladeuil
Failing tests reproducing bug #880701.
723
724
    def check_file_new_content(self):
725
        self.assertFileEqual('new content\n', 'branch/file')
726
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
727
    def _get_resolve_path_arg(self, wt, action):
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
728
        return self._this['path']
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
729
4597.8.5 by Vincent Ladeuil
Replace DuplicateEntry blackbox tests by whitebox ones.
730
    def assertDuplicateEntry(self, wt, c):
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
731
        tpath = self._this['path']
732
        tfile_id = self._this['file_id']
733
        opath = self._other['path']
734
        ofile_id = self._other['file_id']
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
735
        self.assertEqual(tpath, opath) # Sanity check
736
        self.assertEqual(tfile_id, c.file_id)
737
        self.assertEqual(tpath + '.moved', c.path)
738
        self.assertEqual(tpath, c.conflict_path)
4597.8.5 by Vincent Ladeuil
Replace DuplicateEntry blackbox tests by whitebox ones.
739
    _assert_conflict = assertDuplicateEntry
4597.3.19 by Vincent Ladeuil
Some failing tests.
740
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
741
742
class TestResolveUnversionedParent(TestResolveConflicts):
743
4597.3.29 by Vincent Ladeuil
Fix bogus tests.
744
    # FIXME: Add the reverse tests: dir deleted in trunk, file added in branch
745
4597.3.30 by Vincent Ladeuil
Light changes learned while starting to understand multiple conflicts on
746
    # FIXME: While this *creates* UnversionedParent conflicts, this really only
747
    # tests MissingParent resolution :-/
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
748
    preamble = """
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
749
$ brz init trunk
5422.3.4 by Martin Pool
Update test_resolve to pass --quiet or ignore command output it doesn't care about
750
...
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
751
$ cd trunk
4597.3.29 by Vincent Ladeuil
Fix bogus tests.
752
$ mkdir dir
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
753
$ brz add -q dir
754
$ brz commit -m 'Create trunk' -q
4597.3.29 by Vincent Ladeuil
Fix bogus tests.
755
$ echo 'trunk content' >dir/file
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
756
$ brz add -q dir/file
757
$ brz commit -q -m 'Add dir/file in trunk'
758
$ brz branch -q . -r 1 ../branch
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
759
$ cd ../branch
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
760
$ brz rm dir -q
761
$ brz commit -q -m 'Remove dir in branch'
762
$ brz merge ../trunk
4597.3.29 by Vincent Ladeuil
Fix bogus tests.
763
2>+N  dir/
764
2>+N  dir/file
765
2>Conflict adding files to dir.  Created directory.
766
2>Conflict because dir is not versioned, but has versioned children.  Versioned directory.
767
2>2 conflicts encountered.
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
768
"""
769
4597.3.67 by Vincent Ladeuil
Settle with --take-this and --take-other as action names.
770
    def test_take_this(self):
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
771
        self.run_script("""
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
772
$ brz rm -q dir --no-backup
773
$ brz resolve dir
6138.3.5 by Jonathan Riddell
make the test suite pass
774
2>2 conflicts resolved, 0 remaining
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
775
$ brz 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.
776
""")
777
4597.3.67 by Vincent Ladeuil
Settle with --take-this and --take-other as action names.
778
    def test_take_other(self):
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
779
        self.run_script("""
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
780
$ brz resolve dir
6138.3.5 by Jonathan Riddell
make the test suite pass
781
2>2 conflicts resolved, 0 remaining
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
782
$ brz 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.
783
""")
784
785
786
class TestResolveMissingParent(TestResolveConflicts):
787
788
    preamble = """
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
789
$ brz init trunk
5422.3.4 by Martin Pool
Update test_resolve to pass --quiet or ignore command output it doesn't care about
790
...
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
791
$ cd trunk
792
$ mkdir dir
793
$ echo 'trunk content' >dir/file
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
794
$ brz add -q
795
$ brz commit -m 'Create trunk' -q
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
796
$ echo 'trunk content' >dir/file2
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
797
$ brz add -q dir/file2
798
$ brz commit -q -m 'Add dir/file2 in branch'
799
$ brz branch -q . -r 1 ../branch
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
800
$ cd ../branch
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
801
$ brz rm -q dir/file --no-backup
802
$ brz rm -q dir
803
$ brz commit -q -m 'Remove dir/file'
804
$ brz merge ../trunk
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
805
2>+N  dir/
806
2>+N  dir/file2
807
2>Conflict adding files to dir.  Created directory.
808
2>Conflict because dir is not versioned, but has versioned children.  Versioned directory.
809
2>2 conflicts encountered.
810
"""
811
812
    def test_keep_them_all(self):
813
        self.run_script("""
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
814
$ brz resolve dir
6138.3.5 by Jonathan Riddell
make the test suite pass
815
2>2 conflicts resolved, 0 remaining
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
816
$ brz 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.
817
""")
818
819
    def test_adopt_child(self):
820
        self.run_script("""
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
821
$ brz mv -q dir/file2 file2
822
$ brz rm -q dir --no-backup
823
$ brz resolve dir
6138.3.5 by Jonathan Riddell
make the test suite pass
824
2>2 conflicts resolved, 0 remaining
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
825
$ brz 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.
826
""")
827
828
    def test_kill_them_all(self):
829
        self.run_script("""
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
830
$ brz rm -q dir --no-backup
831
$ brz resolve dir
6138.3.5 by Jonathan Riddell
make the test suite pass
832
2>2 conflicts resolved, 0 remaining
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
833
$ brz 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.
834
""")
835
4597.3.67 by Vincent Ladeuil
Settle with --take-this and --take-other as action names.
836
    def test_resolve_taking_this(self):
4597.3.31 by Vincent Ladeuil
Implement --interactive for MissingParent.
837
        self.run_script("""
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
838
$ brz 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
839
2>...
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
840
$ brz commit -q --strict -m 'No more conflicts nor unknown files'
4597.3.31 by Vincent Ladeuil
Implement --interactive for MissingParent.
841
""")
842
4597.3.67 by Vincent Ladeuil
Settle with --take-this and --take-other as action names.
843
    def test_resolve_taking_other(self):
4597.3.31 by Vincent Ladeuil
Implement --interactive for MissingParent.
844
        self.run_script("""
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
845
$ brz 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
846
2>...
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
847
$ brz commit -q --strict -m 'No more conflicts nor unknown files'
4597.3.31 by Vincent Ladeuil
Implement --interactive for MissingParent.
848
""")
849
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
850
851
class TestResolveDeletingParent(TestResolveConflicts):
852
853
    preamble = """
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
854
$ brz init trunk
5422.3.4 by Martin Pool
Update test_resolve to pass --quiet or ignore command output it doesn't care about
855
...
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
856
$ cd trunk
857
$ mkdir dir
858
$ echo 'trunk content' >dir/file
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
859
$ brz add -q
860
$ brz commit -m 'Create trunk' -q
861
$ brz rm -q dir/file --no-backup
862
$ brz rm -q dir --no-backup
863
$ brz commit -q -m 'Remove dir/file'
864
$ brz branch -q . -r 1 ../branch
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
865
$ cd ../branch
866
$ echo 'branch content' >dir/file2
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
867
$ brz add -q dir/file2
868
$ brz commit -q -m 'Add dir/file2 in branch'
869
$ brz merge ../trunk
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
870
2>-D  dir/file
871
2>Conflict: can't delete dir because it is not empty.  Not deleting.
872
2>Conflict because dir is not versioned, but has versioned children.  Versioned directory.
873
2>2 conflicts encountered.
874
"""
875
876
    def test_keep_them_all(self):
877
        self.run_script("""
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
878
$ brz resolve dir
6138.3.5 by Jonathan Riddell
make the test suite pass
879
2>2 conflicts resolved, 0 remaining
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
880
$ brz 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.
881
""")
882
883
    def test_adopt_child(self):
884
        self.run_script("""
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
885
$ brz mv -q dir/file2 file2
886
$ brz rm -q dir --no-backup
887
$ brz resolve dir
6138.3.5 by Jonathan Riddell
make the test suite pass
888
2>2 conflicts resolved, 0 remaining
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
889
$ brz 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.
890
""")
891
892
    def test_kill_them_all(self):
893
        self.run_script("""
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
894
$ brz rm -q dir --no-backup
895
$ brz resolve dir
6138.3.5 by Jonathan Riddell
make the test suite pass
896
2>2 conflicts resolved, 0 remaining
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
897
$ brz 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.
898
""")
899
4597.3.67 by Vincent Ladeuil
Settle with --take-this and --take-other as action names.
900
    def test_resolve_taking_this(self):
4597.3.32 by Vincent Ladeuil
Implement --interactive for DeletingParent noting the inconsistency.
901
        self.run_script("""
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
902
$ brz resolve --take-this dir
6138.3.5 by Jonathan Riddell
make the test suite pass
903
2>2 conflicts resolved, 0 remaining
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
904
$ brz commit -q --strict -m 'No more conflicts nor unknown files'
4597.3.32 by Vincent Ladeuil
Implement --interactive for DeletingParent noting the inconsistency.
905
""")
906
4597.3.67 by Vincent Ladeuil
Settle with --take-this and --take-other as action names.
907
    def test_resolve_taking_other(self):
4597.3.32 by Vincent Ladeuil
Implement --interactive for DeletingParent noting the inconsistency.
908
        self.run_script("""
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
909
$ brz 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
910
2>deleted dir/file2
911
2>deleted dir
6138.3.5 by Jonathan Riddell
make the test suite pass
912
2>2 conflicts resolved, 0 remaining
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
913
$ brz commit -q --strict -m 'No more conflicts nor unknown files'
4597.3.32 by Vincent Ladeuil
Implement --interactive for DeletingParent noting the inconsistency.
914
""")
915
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
916
4597.8.7 by Vincent Ladeuil
Add whitebox tests for ParentLoop.
917
class TestResolveParentLoop(TestParametrizedResolveConflicts):
918
4597.13.3 by Vincent Ladeuil
Switch to load_tests_apply_scenarios.
919
    _conflict_type = conflicts.ParentLoop
4597.10.1 by Vincent Ladeuil
Refactor to better handle various conflict types.
920
921
    _this_args = None
922
    _other_args = None
923
4597.13.3 by Vincent Ladeuil
Switch to load_tests_apply_scenarios.
924
    # Each side dict additionally defines:
925
    # - dir_id: the directory being moved
926
    # - target_id: The target directory
927
    # - xfail: whether the test is expected to fail if the action is
928
    #   involved as 'other'
929
    scenarios = mirror_scenarios(
930
        [
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
931
            # Dirs moved into each other
932
            (dict(_base_actions='create_dir1_dir2'),
933
             ('dir1_into_dir2',
934
              dict(actions='move_dir1_into_dir2', check='dir1_moved',
935
                   dir_id='dir1-id', target_id='dir2-id', xfail=False)),
936
             ('dir2_into_dir1',
937
              dict(actions='move_dir2_into_dir1', check='dir2_moved',
938
                   dir_id='dir2-id', target_id='dir1-id', xfail=False))),
939
            # Subdirs moved into each other
940
            (dict(_base_actions='create_dir1_4'),
941
             ('dir1_into_dir4',
942
              dict(actions='move_dir1_into_dir4', check='dir1_2_moved',
943
                   dir_id='dir1-id', target_id='dir4-id', xfail=True)),
944
             ('dir3_into_dir2',
945
              dict(actions='move_dir3_into_dir2', check='dir3_4_moved',
946
                   dir_id='dir3-id', target_id='dir2-id', xfail=True))),
4597.13.3 by Vincent Ladeuil
Switch to load_tests_apply_scenarios.
947
            ])
4597.8.7 by Vincent Ladeuil
Add whitebox tests for ParentLoop.
948
949
    def do_create_dir1_dir2(self):
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
950
        return [('add', ('dir1', 'dir1-id', 'directory', '')),
951
                ('add', ('dir2', 'dir2-id', 'directory', '')),]
4597.8.7 by Vincent Ladeuil
Add whitebox tests for ParentLoop.
952
4597.8.8 by Vincent Ladeuil
Exhibit bug #537956.
953
    def do_move_dir1_into_dir2(self):
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
954
        return [('rename', ('dir1', 'dir2/dir1'))]
4597.8.7 by Vincent Ladeuil
Add whitebox tests for ParentLoop.
955
956
    def check_dir1_moved(self):
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
957
        self.assertPathDoesNotExist('branch/dir1')
958
        self.assertPathExists('branch/dir2/dir1')
4597.8.7 by Vincent Ladeuil
Add whitebox tests for ParentLoop.
959
4597.8.8 by Vincent Ladeuil
Exhibit bug #537956.
960
    def do_move_dir2_into_dir1(self):
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
961
        return [('rename', ('dir2', 'dir1/dir2'))]
4597.8.7 by Vincent Ladeuil
Add whitebox tests for ParentLoop.
962
963
    def check_dir2_moved(self):
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
964
        self.assertPathDoesNotExist('branch/dir2')
965
        self.assertPathExists('branch/dir1/dir2')
4597.8.7 by Vincent Ladeuil
Add whitebox tests for ParentLoop.
966
4597.8.8 by Vincent Ladeuil
Exhibit bug #537956.
967
    def do_create_dir1_4(self):
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
968
        return [('add', ('dir1', 'dir1-id', 'directory', '')),
969
                ('add', ('dir1/dir2', 'dir2-id', 'directory', '')),
970
                ('add', ('dir3', 'dir3-id', 'directory', '')),
971
                ('add', ('dir3/dir4', 'dir4-id', 'directory', '')),]
4597.8.8 by Vincent Ladeuil
Exhibit bug #537956.
972
973
    def do_move_dir1_into_dir4(self):
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
974
        return [('rename', ('dir1', 'dir3/dir4/dir1'))]
4597.8.8 by Vincent Ladeuil
Exhibit bug #537956.
975
976
    def check_dir1_2_moved(self):
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
977
        self.assertPathDoesNotExist('branch/dir1')
978
        self.assertPathExists('branch/dir3/dir4/dir1')
979
        self.assertPathExists('branch/dir3/dir4/dir1/dir2')
4597.8.8 by Vincent Ladeuil
Exhibit bug #537956.
980
981
    def do_move_dir3_into_dir2(self):
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
982
        return [('rename', ('dir3', 'dir1/dir2/dir3'))]
4597.8.8 by Vincent Ladeuil
Exhibit bug #537956.
983
984
    def check_dir3_4_moved(self):
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
985
        self.assertPathDoesNotExist('branch/dir3')
986
        self.assertPathExists('branch/dir1/dir2/dir3')
987
        self.assertPathExists('branch/dir1/dir2/dir3/dir4')
4597.8.8 by Vincent Ladeuil
Exhibit bug #537956.
988
4597.8.7 by Vincent Ladeuil
Add whitebox tests for ParentLoop.
989
    def _get_resolve_path_arg(self, wt, action):
4597.10.9 by Vincent Ladeuil
More doc.
990
        # ParentLoop says: moving <conflict_path> into <path>. Cancelled move.
4597.8.7 by Vincent Ladeuil
Add whitebox tests for ParentLoop.
991
        # But since <path> doesn't exist in the working tree, we need to use
4597.10.9 by Vincent Ladeuil
More doc.
992
        # <conflict_path> instead, and that, in turn, is given by dir_id. Pfew.
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
993
        return wt.id2path(self._other['dir_id'])
4597.8.7 by Vincent Ladeuil
Add whitebox tests for ParentLoop.
994
995
    def assertParentLoop(self, wt, c):
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
996
        self.assertEqual(self._other['dir_id'], c.file_id)
997
        self.assertEqual(self._other['target_id'], c.conflict_file_id)
4597.8.8 by Vincent Ladeuil
Exhibit bug #537956.
998
        # The conflict paths are irrelevant (they are deterministic but not
999
        # worth checking since they don't provide the needed information
1000
        # anyway)
4597.10.8 by Vincent Ladeuil
Separate actions and conflict attributes.
1001
        if self._other['xfail']:
1002
            # It's a bit hackish to raise from here relying on being called for
1003
            # both tests but this avoid overriding test_resolve_taking_other
6050.1.2 by Martin
Make tests raising KnownFailure use the knownFailure method instead
1004
            self.knownFailure(
4597.10.4 by Vincent Ladeuil
Handle TestResolveParentLoop expected failures more precisely.
1005
                "ParentLoop doesn't carry enough info to resolve --take-other")
4597.8.7 by Vincent Ladeuil
Add whitebox tests for ParentLoop.
1006
    _assert_conflict = assertParentLoop
1007
1008
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
1009
class TestResolveNonDirectoryParent(TestResolveConflicts):
1010
1011
    preamble = """
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1012
$ brz init trunk
5422.3.4 by Martin Pool
Update test_resolve to pass --quiet or ignore command output it doesn't care about
1013
...
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
1014
$ cd trunk
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1015
$ brz mkdir foo
5422.3.4 by Martin Pool
Update test_resolve to pass --quiet or ignore command output it doesn't care about
1016
...
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1017
$ brz commit -m 'Create trunk' -q
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
1018
$ echo "Boing" >foo/bar
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1019
$ brz add -q foo/bar
1020
$ brz commit -q -m 'Add foo/bar'
1021
$ brz branch -q . -r 1 ../branch
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
1022
$ cd ../branch
1023
$ rm -r foo
1024
$ echo "Boo!" >foo
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1025
$ brz commit -q -m 'foo is now a file'
1026
$ brz merge ../trunk
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
1027
2>+N  foo.new/bar
1028
2>RK  foo => foo.new/
1029
# FIXME: The message is misleading, foo.new *is* a directory when the message
1030
# is displayed -- vila 090916
1031
2>Conflict: foo.new is not a directory, but has files in it.  Created directory.
1032
2>1 conflicts encountered.
1033
"""
1034
4597.3.67 by Vincent Ladeuil
Settle with --take-this and --take-other as action names.
1035
    def test_take_this(self):
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
1036
        self.run_script("""
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1037
$ brz rm -q foo.new --no-backup
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
1038
# FIXME: Isn't it weird that foo is now unkown even if foo.new has been put
1039
# aside ? -- vila 090916
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1040
$ brz add -q foo
1041
$ brz resolve foo.new
6138.3.5 by Jonathan Riddell
make the test suite pass
1042
2>1 conflict resolved, 0 remaining
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1043
$ brz 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.
1044
""")
1045
4597.3.67 by Vincent Ladeuil
Settle with --take-this and --take-other as action names.
1046
    def test_take_other(self):
4597.3.35 by Vincent Ladeuil
Implement --interactive for NonDirectoryParent, sort of.
1047
        self.run_script("""
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1048
$ brz rm -q foo --no-backup
1049
$ brz mv -q foo.new foo
1050
$ brz resolve foo
6138.3.5 by Jonathan Riddell
make the test suite pass
1051
2>1 conflict resolved, 0 remaining
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1052
$ brz commit -q --strict -m 'No more conflicts nor unknown files'
4597.3.35 by Vincent Ladeuil
Implement --interactive for NonDirectoryParent, sort of.
1053
""")
1054
4597.3.67 by Vincent Ladeuil
Settle with --take-this and --take-other as action names.
1055
    def test_resolve_taking_this(self):
4597.3.35 by Vincent Ladeuil
Implement --interactive for NonDirectoryParent, sort of.
1056
        self.run_script("""
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1057
$ brz 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
1058
2>...
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1059
$ brz commit -q --strict -m 'No more conflicts nor unknown files'
4597.3.35 by Vincent Ladeuil
Implement --interactive for NonDirectoryParent, sort of.
1060
""")
1061
4597.3.67 by Vincent Ladeuil
Settle with --take-this and --take-other as action names.
1062
    def test_resolve_taking_other(self):
4597.3.35 by Vincent Ladeuil
Implement --interactive for NonDirectoryParent, sort of.
1063
        self.run_script("""
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1064
$ brz 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
1065
2>...
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1066
$ brz commit -q --strict -m 'No more conflicts nor unknown files'
4597.3.35 by Vincent Ladeuil
Implement --interactive for NonDirectoryParent, sort of.
1067
""")
1068
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
1069
1070
class TestMalformedTransform(script.TestCaseWithTransportAndScript):
1071
1072
    def test_bug_430129(self):
1073
        # This is nearly like TestResolveNonDirectoryParent but with branch and
1074
        # trunk switched. As such it should certainly produce the same
1075
        # conflict.
6015.47.1 by Vincent Ladeuil
Turn MalformedTransform into an InternalBzrError so users get a traceback.
1076
        self.assertRaises(errors.MalformedTransform,
6809.1.1 by Martin
Apply 2to3 ws_comma fixer
1077
                          self.run_script, """
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1078
$ brz init trunk
5422.3.4 by Martin Pool
Update test_resolve to pass --quiet or ignore command output it doesn't care about
1079
...
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
1080
$ cd trunk
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1081
$ brz mkdir foo
5422.3.4 by Martin Pool
Update test_resolve to pass --quiet or ignore command output it doesn't care about
1082
...
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1083
$ brz commit -m 'Create trunk' -q
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
1084
$ rm -r foo
1085
$ echo "Boo!" >foo
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1086
$ brz commit -m 'foo is now a file' -q
1087
$ brz branch -q . -r 1 ../branch -q
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
1088
$ cd ../branch
1089
$ echo "Boing" >foo/bar
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1090
$ brz add -q foo/bar -q
1091
$ brz commit -m 'Add foo/bar' -q
1092
$ brz merge ../trunk
1093
2>brz: ERROR: Tree transform is malformed [('unversioned executability', 'new-1')]
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
1094
""")
4597.3.51 by Vincent Ladeuil
Implement conflicts.ResolveActionOption.
1095
5050.63.2 by Vincent Ladeuil
The file should be in a subdir to reproduce the bug.
1096
5050.73.6 by Vincent Ladeuil
Reproduce bug #805809.
1097
class TestNoFinalPath(script.TestCaseWithTransportAndScript):
1098
1099
    def test_bug_805809(self):
1100
        self.run_script("""
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1101
$ brz init trunk
5050.73.6 by Vincent Ladeuil
Reproduce bug #805809.
1102
Created a standalone tree (format: 2a)
1103
$ cd trunk
1104
$ echo trunk >file
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1105
$ brz add
5050.73.6 by Vincent Ladeuil
Reproduce bug #805809.
1106
adding file
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1107
$ brz commit -m 'create file on trunk'
5050.73.6 by Vincent Ladeuil
Reproduce bug #805809.
1108
2>Committing to: .../trunk/
1109
2>added file
1110
2>Committed revision 1.
5050.73.7 by Vincent Ladeuil
Slightly simpler test.
1111
# Create a debian branch based on trunk
5050.73.6 by Vincent Ladeuil
Reproduce bug #805809.
1112
$ cd ..
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1113
$ brz branch trunk -r 1 debian
6143.1.4 by Jonathan Riddell
update tests
1114
2>Branched 1 revision.
5050.73.6 by Vincent Ladeuil
Reproduce bug #805809.
1115
$ cd debian
1116
$ mkdir dir
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1117
$ brz add
5050.73.6 by Vincent Ladeuil
Reproduce bug #805809.
1118
adding dir
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1119
$ brz mv file dir
5050.73.6 by Vincent Ladeuil
Reproduce bug #805809.
1120
file => dir/file
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1121
$ brz commit -m 'rename file to dir/file for debian'
5050.73.6 by Vincent Ladeuil
Reproduce bug #805809.
1122
2>Committing to: .../debian/
1123
2>added dir
1124
2>renamed file => dir/file
1125
2>Committed revision 2.
5050.73.7 by Vincent Ladeuil
Slightly simpler test.
1126
# Create an experimental branch with a new root-id
5050.73.6 by Vincent Ladeuil
Reproduce bug #805809.
1127
$ cd ..
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1128
$ brz init experimental
5609.49.2 by Vincent Ladeuil
Fix pqm failure.
1129
Created a standalone tree (format: 2a)
5050.73.6 by Vincent Ladeuil
Reproduce bug #805809.
1130
$ cd experimental
5050.73.13 by Vincent Ladeuil
Fix the test for trunk where merging into an empty branch now behave differently
1131
# Work around merging into empty branch not being supported
1132
# (http://pad.lv/308562)
1133
$ echo something >not-empty
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1134
$ brz add
5050.73.13 by Vincent Ladeuil
Fix the test for trunk where merging into an empty branch now behave differently
1135
adding not-empty
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1136
$ brz commit -m 'Add some content in experimental'
5050.73.13 by Vincent Ladeuil
Fix the test for trunk where merging into an empty branch now behave differently
1137
2>Committing to: .../experimental/
1138
2>added not-empty
1139
2>Committed revision 1.
5050.73.7 by Vincent Ladeuil
Slightly simpler test.
1140
# merge debian even without a common ancestor
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1141
$ brz merge ../debian -r0..2
5050.73.6 by Vincent Ladeuil
Reproduce bug #805809.
1142
2>+N  dir/
1143
2>+N  dir/file
1144
2>All changes applied successfully.
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1145
$ brz commit -m 'merging debian into experimental'
5050.73.6 by Vincent Ladeuil
Reproduce bug #805809.
1146
2>Committing to: .../experimental/
5050.73.13 by Vincent Ladeuil
Fix the test for trunk where merging into an empty branch now behave differently
1147
2>added dir
1148
2>added dir/file
1149
2>Committed revision 2.
5050.73.7 by Vincent Ladeuil
Slightly simpler test.
1150
# Create an ubuntu branch with yet another root-id
5050.73.6 by Vincent Ladeuil
Reproduce bug #805809.
1151
$ cd ..
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1152
$ brz init ubuntu
5609.49.2 by Vincent Ladeuil
Fix pqm failure.
1153
Created a standalone tree (format: 2a)
5050.73.6 by Vincent Ladeuil
Reproduce bug #805809.
1154
$ cd ubuntu
5050.73.13 by Vincent Ladeuil
Fix the test for trunk where merging into an empty branch now behave differently
1155
# Work around merging into empty branch not being supported
1156
# (http://pad.lv/308562)
1157
$ echo something >not-empty-ubuntu
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1158
$ brz add
5050.73.13 by Vincent Ladeuil
Fix the test for trunk where merging into an empty branch now behave differently
1159
adding not-empty-ubuntu
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1160
$ brz commit -m 'Add some content in experimental'
5050.73.13 by Vincent Ladeuil
Fix the test for trunk where merging into an empty branch now behave differently
1161
2>Committing to: .../ubuntu/
1162
2>added not-empty-ubuntu
1163
2>Committed revision 1.
5050.73.7 by Vincent Ladeuil
Slightly simpler test.
1164
# Also merge debian
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1165
$ brz merge ../debian -r0..2
5050.73.6 by Vincent Ladeuil
Reproduce bug #805809.
1166
2>+N  dir/
1167
2>+N  dir/file
1168
2>All changes applied successfully.
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1169
$ brz commit -m 'merging debian'
5050.73.6 by Vincent Ladeuil
Reproduce bug #805809.
1170
2>Committing to: .../ubuntu/
5050.73.13 by Vincent Ladeuil
Fix the test for trunk where merging into an empty branch now behave differently
1171
2>added dir
1172
2>added dir/file
1173
2>Committed revision 2.
5050.73.7 by Vincent Ladeuil
Slightly simpler test.
1174
# Now try to merge experimental
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
1175
$ brz merge ../experimental
5050.73.13 by Vincent Ladeuil
Fix the test for trunk where merging into an empty branch now behave differently
1176
2>+N  not-empty
5050.73.6 by Vincent Ladeuil
Reproduce bug #805809.
1177
2>Path conflict: dir / dir
1178
2>1 conflicts encountered.
1179
""")
1180
1181
4597.3.51 by Vincent Ladeuil
Implement conflicts.ResolveActionOption.
1182
class TestResolveActionOption(tests.TestCase):
1183
1184
    def setUp(self):
1185
        super(TestResolveActionOption, self).setUp()
1186
        self.options = [conflicts.ResolveActionOption()]
1187
        self.parser = option.get_optparser(dict((o.name, o)
1188
                                                for o in self.options))
1189
1190
    def parse(self, args):
1191
        return self.parser.parse_args(args)
1192
1193
    def test_unknown_action(self):
6731.1.4 by Jelmer Vernooij
Move BadOptionValue to breezy.option.
1194
        self.assertRaises(option.BadOptionValue,
4597.3.51 by Vincent Ladeuil
Implement conflicts.ResolveActionOption.
1195
                          self.parse, ['--action', 'take-me-to-the-moon'])
1196
1197
    def test_done(self):
1198
        opts, args = self.parse(['--action', 'done'])
1199
        self.assertEqual({'action':'done'}, opts)
1200
4597.3.67 by Vincent Ladeuil
Settle with --take-this and --take-other as action names.
1201
    def test_take_this(self):
1202
        opts, args = self.parse(['--action', 'take-this'])
1203
        self.assertEqual({'action': 'take_this'}, opts)
1204
        opts, args = self.parse(['--take-this'])
1205
        self.assertEqual({'action': 'take_this'}, opts)
4597.3.51 by Vincent Ladeuil
Implement conflicts.ResolveActionOption.
1206
4597.3.67 by Vincent Ladeuil
Settle with --take-this and --take-other as action names.
1207
    def test_take_other(self):
1208
        opts, args = self.parse(['--action', 'take-other'])
1209
        self.assertEqual({'action': 'take_other'}, opts)
1210
        opts, args = self.parse(['--take-other'])
1211
        self.assertEqual({'action': 'take_other'}, opts)