/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/tests/test_conflicts.py

  • Committer: Jelmer Vernooij
  • Date: 2018-02-27 14:36:14 UTC
  • mto: This revision was merged to the branch mainline in revision 6866.
  • Revision ID: jelmer@jelmer.uk-20180227143614-2cuc06ngefq77gke
Move to errors.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 Canonical Ltd
 
1
# Copyright (C) 2005-2011 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
17
17
 
18
18
import os
19
19
 
20
 
from bzrlib import (
21
 
    branchbuilder,
22
 
    bzrdir,
 
20
from .. import (
23
21
    conflicts,
24
22
    errors,
25
23
    option,
 
24
    osutils,
26
25
    tests,
27
 
    workingtree,
28
 
    )
29
 
from bzrlib.tests import script
30
 
 
31
 
 
32
 
def load_tests(standard_tests, module, loader):
33
 
    result = loader.suiteClass()
34
 
 
35
 
    sp_tests, remaining_tests = tests.split_suite_by_condition(
36
 
        standard_tests, tests.condition_isinstance((
37
 
                TestParametrizedResolveConflicts,
38
 
                )))
39
 
    # Each test class defines its own scenarios. This is needed for
40
 
    # TestResolvePathConflictBefore531967 that verifies that the same tests as
41
 
    # TestResolvePathConflict still pass.
42
 
    for test in tests.iter_suite_tests(sp_tests):
43
 
        tests.apply_scenarios(test, test.scenarios(), result)
44
 
 
45
 
    # No parametrization for the remaining tests
46
 
    result.addTests(remaining_tests)
47
 
 
48
 
    return result
 
26
    )
 
27
from . import (
 
28
    script,
 
29
    scenarios,
 
30
    )
 
31
 
 
32
 
 
33
load_tests = scenarios.load_tests_apply_scenarios
49
34
 
50
35
 
51
36
# TODO: Test commit with some added, and added-but-missing files
76
61
])
77
62
 
78
63
 
 
64
def vary_by_conflicts():
 
65
    for conflict in example_conflicts:
 
66
        yield (conflict.__class__.__name__, {"conflict": conflict})
 
67
 
 
68
 
79
69
class TestConflicts(tests.TestCaseWithTransport):
80
70
 
81
 
    def test_conflicts(self):
82
 
        """Conflicts are detected properly"""
83
 
        # Use BzrDirFormat6 so we can fake conflicts
84
 
        tree = self.make_branch_and_tree('.', format=bzrdir.BzrDirFormat6())
85
 
        self.build_tree_contents([('hello', 'hello world4'),
86
 
                                  ('hello.THIS', 'hello world2'),
87
 
                                  ('hello.BASE', 'hello world1'),
88
 
                                  ('hello.OTHER', 'hello world3'),
89
 
                                  ('hello.sploo.BASE', 'yellowworld'),
90
 
                                  ('hello.sploo.OTHER', 'yellowworld2'),
91
 
                                  ])
92
 
        tree.lock_read()
93
 
        self.assertLength(6, list(tree.list_files()))
94
 
        tree.unlock()
95
 
        tree_conflicts = tree.conflicts()
96
 
        self.assertLength(2, tree_conflicts)
97
 
        self.assertTrue('hello' in tree_conflicts[0].path)
98
 
        self.assertTrue('hello.sploo' in tree_conflicts[1].path)
99
 
        conflicts.restore('hello')
100
 
        conflicts.restore('hello.sploo')
101
 
        self.assertLength(0, tree.conflicts())
102
 
        self.assertFileEqual('hello world2', 'hello')
103
 
        self.assertFalse(os.path.lexists('hello.sploo'))
104
 
        self.assertRaises(errors.NotConflicted, conflicts.restore, 'hello')
105
 
        self.assertRaises(errors.NotConflicted,
106
 
                          conflicts.restore, 'hello.sploo')
107
 
 
108
71
    def test_resolve_conflict_dir(self):
109
72
        tree = self.make_branch_and_tree('.')
110
73
        self.build_tree_contents([('hello', 'hello world4'),
161
124
        self.assertEqual(conflicts.ConflictList([]), tree.conflicts())
162
125
 
163
126
 
164
 
class TestConflictStanzas(tests.TestCase):
 
127
class TestPerConflict(tests.TestCase):
 
128
 
 
129
    scenarios = scenarios.multiply_scenarios(vary_by_conflicts())
 
130
 
 
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__)
165
137
 
166
138
    def test_stanza_roundtrip(self):
167
 
        # write and read our example stanza.
168
 
        stanza_iter = example_conflicts.to_stanzas()
169
 
        processed = conflicts.ConflictList.from_stanzas(stanza_iter)
170
 
        for o, p in zip(processed, example_conflicts):
171
 
            self.assertEqual(o, p)
172
 
 
173
 
            self.assertIsInstance(o.path, unicode)
174
 
 
175
 
            if o.file_id is not None:
176
 
                self.assertIsInstance(o.file_id, str)
177
 
 
178
 
            conflict_path = getattr(o, 'conflict_path', None)
179
 
            if conflict_path is not None:
180
 
                self.assertIsInstance(conflict_path, unicode)
181
 
 
182
 
            conflict_file_id = getattr(o, 'conflict_file_id', None)
183
 
            if conflict_file_id is not None:
184
 
                self.assertIsInstance(conflict_file_id, str)
 
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)
185
155
 
186
156
    def test_stanzification(self):
187
 
        for stanza in example_conflicts.to_stanzas():
188
 
            if 'file_id' in stanza:
189
 
                # In Stanza form, the file_id has to be unicode.
190
 
                self.assertStartsWith(stanza['file_id'], u'\xeed')
191
 
            self.assertStartsWith(stanza['path'], u'p\xe5th')
192
 
            if 'conflict_path' in stanza:
193
 
                self.assertStartsWith(stanza['conflict_path'], u'p\xe5th')
194
 
            if 'conflict_file_id' in stanza:
195
 
                self.assertStartsWith(stanza['conflict_file_id'], u'\xeed')
 
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
 
 
168
class TestConflictList(tests.TestCase):
 
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)
 
174
 
 
175
    def test_stringification(self):
 
176
        for text, o in zip(example_conflicts.to_strings(), example_conflicts):
 
177
            self.assertEqual(text, unicode(o))
196
178
 
197
179
 
198
180
# FIXME: The shell-like tests should be converted to real whitebox tests... or
210
192
        self.run_script(self.preamble)
211
193
 
212
194
 
213
 
class TestResolveTextConflicts(TestResolveConflicts):
214
 
    # TBC
215
 
    pass
216
 
 
217
 
 
218
195
def mirror_scenarios(base_scenarios):
219
196
    """Return a list of mirrored scenarios.
220
197
 
293
270
    _this = None
294
271
    _other = None
295
272
 
296
 
    @staticmethod
297
 
    def scenarios():
298
 
        """Return the scenario list for the conflict type defined by the class.
299
 
 
300
 
        Each scenario is of the form:
301
 
        (common, (left_name, left_dict), (right_name, right_dict))
302
 
 
303
 
        * common is a dict
304
 
 
305
 
        * left_name and right_name are the scenario names that will be combined
306
 
 
307
 
        * left_dict and right_dict are the attributes specific to each half of
308
 
          the scenario. They should include at least 'actions' and 'check' and
309
 
          will be available as '_this' and '_other' test instance attributes.
310
 
 
311
 
        Daughters classes are free to add their specific attributes as they see
312
 
        fit in any of the three dicts.
313
 
 
314
 
        This is a class method so that load_tests can find it.
315
 
 
316
 
        '_base_actions' in the common dict, 'actions' and 'check' in the left
317
 
        and right dicts use names that map to methods in the test classes. Some
318
 
        prefixes are added to these names to get the correspong methods (see
319
 
        _get_actions() and _get_check()). The motivation here is to avoid
320
 
        collisions in the class namespace.
321
 
        """
322
 
        # Only concrete classes return actual scenarios
323
 
        return []
 
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
    """
324
298
 
325
299
    def setUp(self):
326
300
        super(TestParametrizedResolveConflicts, self).setUp()
328
302
        builder.start_series()
329
303
 
330
304
        # Create an empty trunk
331
 
        builder.build_snapshot('start', None, [
332
 
                ('add', ('', 'root-id', 'directory', ''))])
 
305
        builder.build_snapshot(None, [
 
306
                ('add', ('', 'root-id', 'directory', ''))],
 
307
                revision_id='start')
333
308
        # Add a minimal base content
334
309
        base_actions = self._get_actions(self._base_actions)()
335
 
        builder.build_snapshot('base', ['start'], base_actions)
 
310
        builder.build_snapshot(['start'], base_actions, revision_id='base')
336
311
        # Modify the base content in branch
337
312
        actions_other = self._get_actions(self._other['actions'])()
338
 
        builder.build_snapshot('other', ['base'], actions_other)
 
313
        builder.build_snapshot(['base'], actions_other, revision_id='other')
339
314
        # Modify the base content in trunk
340
315
        actions_this = self._get_actions(self._this['actions'])()
341
 
        builder.build_snapshot('this', ['base'], actions_this)
 
316
        builder.build_snapshot(['base'], actions_this, revision_id='this')
342
317
        # builder.get_branch() tip is now 'this'
343
318
 
344
319
        builder.finish_series()
352
327
 
353
328
    def _merge_other_into_this(self):
354
329
        b = self.builder.get_branch()
355
 
        wt = b.bzrdir.sprout('branch').open_workingtree()
 
330
        wt = b.controldir.sprout('branch').open_workingtree()
356
331
        wt.merge_from_branch(b, 'other')
357
332
        return wt
358
333
 
388
363
        check_other()
389
364
 
390
365
 
 
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
        [
 
377
            # File modified on both sides
 
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')),),
 
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')),),
 
393
            ])
 
394
 
 
395
    def do_create_file(self, path='file'):
 
396
        return [('add', (path, 'file-id', 'file', 'trunk content\n'))]
 
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
 
 
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')
 
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
 
391
431
class TestResolveContentsConflict(TestParametrizedResolveConflicts):
392
432
 
393
 
    _conflict_type = conflicts.ContentsConflict,
 
433
    _conflict_type = conflicts.ContentsConflict
394
434
 
395
 
    # Set by load_tests from scenarios()
 
435
    # Set by the scenarios
396
436
    # path and file-id for the file involved in the conflict
397
437
    _path = None
398
438
    _file_id = None
399
439
 
400
 
    @staticmethod
401
 
    def scenarios():
402
 
        base_scenarios = [
 
440
    scenarios = mirror_scenarios(
 
441
        [
403
442
            # File modified/deleted
404
443
            (dict(_base_actions='create_file',
405
444
                  _path='file', _file_id='file-id'),
407
446
              dict(actions='modify_file', check='file_has_more_content')),
408
447
             ('file_deleted',
409
448
              dict(actions='delete_file', check='file_doesnt_exist')),),
410
 
            ]
411
 
        return mirror_scenarios(base_scenarios)
 
449
            # File renamed-modified/deleted
 
450
            (dict(_base_actions='create_file',
 
451
                  _path='new-file', _file_id='file-id'),
 
452
             ('file_renamed_and_modified',
 
453
              dict(actions='modify_and_rename_file',
 
454
                   check='file_renamed_and_more_content')),
 
455
             ('file_deleted',
 
456
              dict(actions='delete_file', check='file_doesnt_exist')),),
 
457
            # File modified/deleted in dir
 
458
            (dict(_base_actions='create_file_in_dir',
 
459
                  _path='dir/file', _file_id='file-id'),
 
460
             ('file_modified_in_dir',
 
461
              dict(actions='modify_file_in_dir',
 
462
                   check='file_in_dir_has_more_content')),
 
463
             ('file_deleted_in_dir',
 
464
              dict(actions='delete_file',
 
465
                   check='file_in_dir_doesnt_exist')),),
 
466
            ])
412
467
 
413
468
    def do_create_file(self):
414
469
        return [('add', ('file', 'file-id', 'file', 'trunk content\n'))]
416
471
    def do_modify_file(self):
417
472
        return [('modify', ('file-id', 'trunk content\nmore content\n'))]
418
473
 
 
474
    def do_modify_and_rename_file(self):
 
475
        return [('modify', ('file-id', 'trunk content\nmore content\n')),
 
476
                ('rename', ('file', 'new-file'))]
 
477
 
419
478
    def check_file_has_more_content(self):
420
479
        self.assertFileEqual('trunk content\nmore content\n', 'branch/file')
421
480
 
 
481
    def check_file_renamed_and_more_content(self):
 
482
        self.assertFileEqual('trunk content\nmore content\n', 'branch/new-file')
 
483
 
422
484
    def do_delete_file(self):
423
485
        return [('unversion', 'file-id')]
424
486
 
425
487
    def check_file_doesnt_exist(self):
426
 
        self.failIfExists('branch/file')
 
488
        self.assertPathDoesNotExist('branch/file')
 
489
 
 
490
    def do_create_file_in_dir(self):
 
491
        return [('add', ('dir', 'dir-id', 'directory', '')),
 
492
                ('add', ('dir/file', 'file-id', 'file', 'trunk content\n'))]
 
493
 
 
494
    def do_modify_file_in_dir(self):
 
495
        return [('modify', ('file-id', 'trunk content\nmore content\n'))]
 
496
 
 
497
    def check_file_in_dir_has_more_content(self):
 
498
        self.assertFileEqual('trunk content\nmore content\n', 'branch/dir/file')
 
499
 
 
500
    def check_file_in_dir_doesnt_exist(self):
 
501
        self.assertPathDoesNotExist('branch/dir/file')
427
502
 
428
503
    def _get_resolve_path_arg(self, wt, action):
429
504
        return self._path
436
511
 
437
512
class TestResolvePathConflict(TestParametrizedResolveConflicts):
438
513
 
439
 
    _conflict_type = conflicts.PathConflict,
 
514
    _conflict_type = conflicts.PathConflict
440
515
 
441
516
    def do_nothing(self):
442
517
        return []
443
518
 
444
 
    @staticmethod
445
 
    def scenarios():
446
 
        # Each side dict additionally defines:
447
 
        # - path path involved (can be '<deleted>')
448
 
        # - file-id involved
449
 
        base_scenarios = [
 
519
    # Each side dict additionally defines:
 
520
    # - path path involved (can be '<deleted>')
 
521
    # - file-id involved
 
522
    scenarios = mirror_scenarios(
 
523
        [
450
524
            # File renamed/deleted
451
525
            (dict(_base_actions='create_file'),
452
526
             ('file_renamed',
457
531
                   # PathConflicts deletion handling requires a special
458
532
                   # hard-coded value
459
533
                   path='<deleted>', file_id='file-id')),),
 
534
            # File renamed/deleted in dir
 
535
            (dict(_base_actions='create_file_in_dir'),
 
536
             ('file_renamed_in_dir',
 
537
              dict(actions='rename_file_in_dir', check='file_in_dir_renamed',
 
538
                   path='dir/new-file', file_id='file-id')),
 
539
             ('file_deleted',
 
540
              dict(actions='delete_file', check='file_in_dir_doesnt_exist',
 
541
                   # PathConflicts deletion handling requires a special
 
542
                   # hard-coded value
 
543
                   path='<deleted>', file_id='file-id')),),
460
544
            # File renamed/renamed differently
461
545
            (dict(_base_actions='create_file'),
462
546
             ('file_renamed',
483
567
             ('dir_renamed2',
484
568
              dict(actions='rename_dir2', check='dir_renamed2',
485
569
                   path='new-dir2', file_id='dir-id')),),
486
 
        ]
487
 
        return mirror_scenarios(base_scenarios)
 
570
            ])
488
571
 
489
572
    def do_create_file(self):
490
573
        return [('add', ('file', 'file-id', 'file', 'trunk content\n'))]
496
579
        return [('rename', ('file', 'new-file'))]
497
580
 
498
581
    def check_file_renamed(self):
499
 
        self.failIfExists('branch/file')
500
 
        self.failUnlessExists('branch/new-file')
 
582
        self.assertPathDoesNotExist('branch/file')
 
583
        self.assertPathExists('branch/new-file')
501
584
 
502
585
    def do_rename_file2(self):
503
586
        return [('rename', ('file', 'new-file2'))]
504
587
 
505
588
    def check_file_renamed2(self):
506
 
        self.failIfExists('branch/file')
507
 
        self.failUnlessExists('branch/new-file2')
 
589
        self.assertPathDoesNotExist('branch/file')
 
590
        self.assertPathExists('branch/new-file2')
508
591
 
509
592
    def do_rename_dir(self):
510
593
        return [('rename', ('dir', 'new-dir'))]
511
594
 
512
595
    def check_dir_renamed(self):
513
 
        self.failIfExists('branch/dir')
514
 
        self.failUnlessExists('branch/new-dir')
 
596
        self.assertPathDoesNotExist('branch/dir')
 
597
        self.assertPathExists('branch/new-dir')
515
598
 
516
599
    def do_rename_dir2(self):
517
600
        return [('rename', ('dir', 'new-dir2'))]
518
601
 
519
602
    def check_dir_renamed2(self):
520
 
        self.failIfExists('branch/dir')
521
 
        self.failUnlessExists('branch/new-dir2')
 
603
        self.assertPathDoesNotExist('branch/dir')
 
604
        self.assertPathExists('branch/new-dir2')
522
605
 
523
606
    def do_delete_file(self):
524
607
        return [('unversion', 'file-id')]
525
608
 
526
609
    def check_file_doesnt_exist(self):
527
 
        self.failIfExists('branch/file')
 
610
        self.assertPathDoesNotExist('branch/file')
528
611
 
529
612
    def do_delete_dir(self):
530
613
        return [('unversion', 'dir-id')]
531
614
 
532
615
    def check_dir_doesnt_exist(self):
533
 
        self.failIfExists('branch/dir')
 
616
        self.assertPathDoesNotExist('branch/dir')
 
617
 
 
618
    def do_create_file_in_dir(self):
 
619
        return [('add', ('dir', 'dir-id', 'directory', '')),
 
620
                ('add', ('dir/file', 'file-id', 'file', 'trunk content\n'))]
 
621
 
 
622
    def do_rename_file_in_dir(self):
 
623
        return [('rename', ('dir/file', 'dir/new-file'))]
 
624
 
 
625
    def check_file_in_dir_renamed(self):
 
626
        self.assertPathDoesNotExist('branch/dir/file')
 
627
        self.assertPathExists('branch/dir/new-file')
 
628
 
 
629
    def check_file_in_dir_doesnt_exist(self):
 
630
        self.assertPathDoesNotExist('branch/dir/file')
534
631
 
535
632
    def _get_resolve_path_arg(self, wt, action):
536
633
        tpath = self._this['path']
568
665
 
569
666
class TestResolveDuplicateEntry(TestParametrizedResolveConflicts):
570
667
 
571
 
    _conflict_type = conflicts.DuplicateEntry,
 
668
    _conflict_type = conflicts.DuplicateEntry
572
669
 
573
 
    @staticmethod
574
 
    def scenarios():
575
 
        # Each side dict additionally defines:
576
 
        # - path involved
577
 
        # - file-id involved
578
 
        base_scenarios = [
 
670
    scenarios = mirror_scenarios(
 
671
        [
579
672
            # File created with different file-ids
580
673
            (dict(_base_actions='nothing'),
581
674
             ('filea_created',
584
677
             ('fileb_created',
585
678
              dict(actions='create_file_b', check='file_content_b',
586
679
                   path='file', file_id='file-b-id')),),
587
 
            ]
588
 
        return mirror_scenarios(base_scenarios)
 
680
            # File created with different file-ids but deleted on one side
 
681
            (dict(_base_actions='create_file_a'),
 
682
             ('filea_replaced',
 
683
              dict(actions='replace_file_a_by_b', check='file_content_b',
 
684
                   path='file', file_id='file-b-id')),
 
685
             ('filea_modified',
 
686
              dict(actions='modify_file_a', check='file_new_content',
 
687
                   path='file', file_id='file-a-id')),),
 
688
            ])
589
689
 
590
690
    def do_nothing(self):
591
691
        return []
602
702
    def check_file_content_b(self):
603
703
        self.assertFileEqual('file b content\n', 'branch/file')
604
704
 
 
705
    def do_replace_file_a_by_b(self):
 
706
        return [('unversion', 'file-a-id'),
 
707
                ('add', ('file', 'file-b-id', 'file', 'file b content\n'))]
 
708
 
 
709
    def do_modify_file_a(self):
 
710
        return [('modify', ('file-a-id', 'new content\n'))]
 
711
 
 
712
    def check_file_new_content(self):
 
713
        self.assertFileEqual('new content\n', 'branch/file')
 
714
 
605
715
    def _get_resolve_path_arg(self, wt, action):
606
716
        return self._this['path']
607
717
 
624
734
    # FIXME: While this *creates* UnversionedParent conflicts, this really only
625
735
    # tests MissingParent resolution :-/
626
736
    preamble = """
627
 
$ bzr init trunk
 
737
$ brz init trunk
 
738
...
628
739
$ cd trunk
629
740
$ mkdir dir
630
 
$ bzr add dir
631
 
$ bzr commit -m 'Create trunk'
632
 
 
 
741
$ brz add -q dir
 
742
$ brz commit -m 'Create trunk' -q
633
743
$ echo 'trunk content' >dir/file
634
 
$ bzr add dir/file
635
 
$ bzr commit -m 'Add dir/file in trunk'
636
 
 
637
 
$ bzr branch . -r 1 ../branch
 
744
$ brz add -q dir/file
 
745
$ brz commit -q -m 'Add dir/file in trunk'
 
746
$ brz branch -q . -r 1 ../branch
638
747
$ cd ../branch
639
 
$ bzr rm dir
640
 
$ bzr commit -m 'Remove dir in branch'
641
 
 
642
 
$ bzr merge ../trunk
 
748
$ brz rm dir -q
 
749
$ brz commit -q -m 'Remove dir in branch'
 
750
$ brz merge ../trunk
643
751
2>+N  dir/
644
752
2>+N  dir/file
645
753
2>Conflict adding files to dir.  Created directory.
649
757
 
650
758
    def test_take_this(self):
651
759
        self.run_script("""
652
 
$ bzr rm dir  --force
653
 
$ bzr resolve dir
654
 
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
760
$ brz rm -q dir --no-backup
 
761
$ brz resolve dir
 
762
2>2 conflicts resolved, 0 remaining
 
763
$ brz commit -q --strict -m 'No more conflicts nor unknown files'
655
764
""")
656
765
 
657
766
    def test_take_other(self):
658
767
        self.run_script("""
659
 
$ bzr resolve dir
660
 
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
768
$ brz resolve dir
 
769
2>2 conflicts resolved, 0 remaining
 
770
$ brz commit -q --strict -m 'No more conflicts nor unknown files'
661
771
""")
662
772
 
663
773
 
664
774
class TestResolveMissingParent(TestResolveConflicts):
665
775
 
666
776
    preamble = """
667
 
$ bzr init trunk
 
777
$ brz init trunk
 
778
...
668
779
$ cd trunk
669
780
$ mkdir dir
670
781
$ echo 'trunk content' >dir/file
671
 
$ bzr add
672
 
$ bzr commit -m 'Create trunk'
673
 
 
 
782
$ brz add -q
 
783
$ brz commit -m 'Create trunk' -q
674
784
$ echo 'trunk content' >dir/file2
675
 
$ bzr add dir/file2
676
 
$ bzr commit -m 'Add dir/file2 in branch'
677
 
 
678
 
$ bzr branch . -r 1 ../branch
 
785
$ brz add -q dir/file2
 
786
$ brz commit -q -m 'Add dir/file2 in branch'
 
787
$ brz branch -q . -r 1 ../branch
679
788
$ cd ../branch
680
 
$ bzr rm dir/file --force
681
 
$ bzr rm dir
682
 
$ bzr commit -m 'Remove dir/file'
683
 
 
684
 
$ bzr merge ../trunk
 
789
$ brz rm -q dir/file --no-backup
 
790
$ brz rm -q dir
 
791
$ brz commit -q -m 'Remove dir/file'
 
792
$ brz merge ../trunk
685
793
2>+N  dir/
686
794
2>+N  dir/file2
687
795
2>Conflict adding files to dir.  Created directory.
691
799
 
692
800
    def test_keep_them_all(self):
693
801
        self.run_script("""
694
 
$ bzr resolve dir
695
 
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
802
$ brz resolve dir
 
803
2>2 conflicts resolved, 0 remaining
 
804
$ brz commit -q --strict -m 'No more conflicts nor unknown files'
696
805
""")
697
806
 
698
807
    def test_adopt_child(self):
699
808
        self.run_script("""
700
 
$ bzr mv dir/file2 file2
701
 
$ bzr rm dir --force
702
 
$ bzr resolve dir
703
 
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
809
$ brz mv -q dir/file2 file2
 
810
$ brz rm -q dir --no-backup
 
811
$ brz resolve dir
 
812
2>2 conflicts resolved, 0 remaining
 
813
$ brz commit -q --strict -m 'No more conflicts nor unknown files'
704
814
""")
705
815
 
706
816
    def test_kill_them_all(self):
707
817
        self.run_script("""
708
 
$ bzr rm dir --force
709
 
$ bzr resolve dir
710
 
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
818
$ brz rm -q dir --no-backup
 
819
$ brz resolve dir
 
820
2>2 conflicts resolved, 0 remaining
 
821
$ brz commit -q --strict -m 'No more conflicts nor unknown files'
711
822
""")
712
823
 
713
824
    def test_resolve_taking_this(self):
714
825
        self.run_script("""
715
 
$ bzr resolve --take-this dir
716
 
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
826
$ brz resolve --take-this dir
 
827
2>...
 
828
$ brz commit -q --strict -m 'No more conflicts nor unknown files'
717
829
""")
718
830
 
719
831
    def test_resolve_taking_other(self):
720
832
        self.run_script("""
721
 
$ bzr resolve --take-other dir
722
 
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
833
$ brz resolve --take-other dir
 
834
2>...
 
835
$ brz commit -q --strict -m 'No more conflicts nor unknown files'
723
836
""")
724
837
 
725
838
 
726
839
class TestResolveDeletingParent(TestResolveConflicts):
727
840
 
728
841
    preamble = """
729
 
$ bzr init trunk
 
842
$ brz init trunk
 
843
...
730
844
$ cd trunk
731
845
$ mkdir dir
732
846
$ echo 'trunk content' >dir/file
733
 
$ bzr add
734
 
$ bzr commit -m 'Create trunk'
735
 
 
736
 
$ bzr rm dir/file --force
737
 
$ bzr rm dir --force
738
 
$ bzr commit -m 'Remove dir/file'
739
 
 
740
 
$ bzr branch . -r 1 ../branch
 
847
$ brz add -q
 
848
$ brz commit -m 'Create trunk' -q
 
849
$ brz rm -q dir/file --no-backup
 
850
$ brz rm -q dir --no-backup
 
851
$ brz commit -q -m 'Remove dir/file'
 
852
$ brz branch -q . -r 1 ../branch
741
853
$ cd ../branch
742
854
$ echo 'branch content' >dir/file2
743
 
$ bzr add dir/file2
744
 
$ bzr commit -m 'Add dir/file2 in branch'
745
 
 
746
 
$ bzr merge ../trunk
 
855
$ brz add -q dir/file2
 
856
$ brz commit -q -m 'Add dir/file2 in branch'
 
857
$ brz merge ../trunk
747
858
2>-D  dir/file
748
859
2>Conflict: can't delete dir because it is not empty.  Not deleting.
749
860
2>Conflict because dir is not versioned, but has versioned children.  Versioned directory.
752
863
 
753
864
    def test_keep_them_all(self):
754
865
        self.run_script("""
755
 
$ bzr resolve dir
756
 
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
866
$ brz resolve dir
 
867
2>2 conflicts resolved, 0 remaining
 
868
$ brz commit -q --strict -m 'No more conflicts nor unknown files'
757
869
""")
758
870
 
759
871
    def test_adopt_child(self):
760
872
        self.run_script("""
761
 
$ bzr mv dir/file2 file2
762
 
$ bzr rm dir --force
763
 
$ bzr resolve dir
764
 
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
873
$ brz mv -q dir/file2 file2
 
874
$ brz rm -q dir --no-backup
 
875
$ brz resolve dir
 
876
2>2 conflicts resolved, 0 remaining
 
877
$ brz commit -q --strict -m 'No more conflicts nor unknown files'
765
878
""")
766
879
 
767
880
    def test_kill_them_all(self):
768
881
        self.run_script("""
769
 
$ bzr rm dir --force
770
 
$ bzr resolve dir
771
 
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
882
$ brz rm -q dir --no-backup
 
883
$ brz resolve dir
 
884
2>2 conflicts resolved, 0 remaining
 
885
$ brz commit -q --strict -m 'No more conflicts nor unknown files'
772
886
""")
773
887
 
774
888
    def test_resolve_taking_this(self):
775
889
        self.run_script("""
776
 
$ bzr resolve --take-this dir
777
 
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
890
$ brz resolve --take-this dir
 
891
2>2 conflicts resolved, 0 remaining
 
892
$ brz commit -q --strict -m 'No more conflicts nor unknown files'
778
893
""")
779
894
 
780
895
    def test_resolve_taking_other(self):
781
896
        self.run_script("""
782
 
$ bzr resolve --take-other dir
783
 
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
897
$ brz resolve --take-other dir
 
898
2>deleted dir/file2
 
899
2>deleted dir
 
900
2>2 conflicts resolved, 0 remaining
 
901
$ brz commit -q --strict -m 'No more conflicts nor unknown files'
784
902
""")
785
903
 
786
904
 
787
905
class TestResolveParentLoop(TestParametrizedResolveConflicts):
788
906
 
789
 
    _conflict_type = conflicts.ParentLoop,
 
907
    _conflict_type = conflicts.ParentLoop
790
908
 
791
909
    _this_args = None
792
910
    _other_args = None
793
911
 
794
 
    @staticmethod
795
 
    def scenarios():
796
 
        # Each side dict additionally defines:
797
 
        # - dir_id: the directory being moved
798
 
        # - target_id: The target directory
799
 
        # - xfail: whether the test is expected to fail if the action is
800
 
        #     involved as 'other'
801
 
        base_scenarios = [
 
912
    # Each side dict additionally defines:
 
913
    # - dir_id: the directory being moved
 
914
    # - target_id: The target directory
 
915
    # - xfail: whether the test is expected to fail if the action is
 
916
    #   involved as 'other'
 
917
    scenarios = mirror_scenarios(
 
918
        [
802
919
            # Dirs moved into each other
803
920
            (dict(_base_actions='create_dir1_dir2'),
804
921
             ('dir1_into_dir2',
815
932
             ('dir3_into_dir2',
816
933
              dict(actions='move_dir3_into_dir2', check='dir3_4_moved',
817
934
                   dir_id='dir3-id', target_id='dir2-id', xfail=True))),
818
 
            ]
819
 
        return mirror_scenarios(base_scenarios)
 
935
            ])
820
936
 
821
937
    def do_create_dir1_dir2(self):
822
938
        return [('add', ('dir1', 'dir1-id', 'directory', '')),
826
942
        return [('rename', ('dir1', 'dir2/dir1'))]
827
943
 
828
944
    def check_dir1_moved(self):
829
 
        self.failIfExists('branch/dir1')
830
 
        self.failUnlessExists('branch/dir2/dir1')
 
945
        self.assertPathDoesNotExist('branch/dir1')
 
946
        self.assertPathExists('branch/dir2/dir1')
831
947
 
832
948
    def do_move_dir2_into_dir1(self):
833
949
        return [('rename', ('dir2', 'dir1/dir2'))]
834
950
 
835
951
    def check_dir2_moved(self):
836
 
        self.failIfExists('branch/dir2')
837
 
        self.failUnlessExists('branch/dir1/dir2')
 
952
        self.assertPathDoesNotExist('branch/dir2')
 
953
        self.assertPathExists('branch/dir1/dir2')
838
954
 
839
955
    def do_create_dir1_4(self):
840
956
        return [('add', ('dir1', 'dir1-id', 'directory', '')),
846
962
        return [('rename', ('dir1', 'dir3/dir4/dir1'))]
847
963
 
848
964
    def check_dir1_2_moved(self):
849
 
        self.failIfExists('branch/dir1')
850
 
        self.failUnlessExists('branch/dir3/dir4/dir1')
851
 
        self.failUnlessExists('branch/dir3/dir4/dir1/dir2')
 
965
        self.assertPathDoesNotExist('branch/dir1')
 
966
        self.assertPathExists('branch/dir3/dir4/dir1')
 
967
        self.assertPathExists('branch/dir3/dir4/dir1/dir2')
852
968
 
853
969
    def do_move_dir3_into_dir2(self):
854
970
        return [('rename', ('dir3', 'dir1/dir2/dir3'))]
855
971
 
856
972
    def check_dir3_4_moved(self):
857
 
        self.failIfExists('branch/dir3')
858
 
        self.failUnlessExists('branch/dir1/dir2/dir3')
859
 
        self.failUnlessExists('branch/dir1/dir2/dir3/dir4')
 
973
        self.assertPathDoesNotExist('branch/dir3')
 
974
        self.assertPathExists('branch/dir1/dir2/dir3')
 
975
        self.assertPathExists('branch/dir1/dir2/dir3/dir4')
860
976
 
861
977
    def _get_resolve_path_arg(self, wt, action):
862
978
        # ParentLoop says: moving <conflict_path> into <path>. Cancelled move.
873
989
        if self._other['xfail']:
874
990
            # It's a bit hackish to raise from here relying on being called for
875
991
            # both tests but this avoid overriding test_resolve_taking_other
876
 
            raise tests.KnownFailure(
 
992
            self.knownFailure(
877
993
                "ParentLoop doesn't carry enough info to resolve --take-other")
878
994
    _assert_conflict = assertParentLoop
879
995
 
881
997
class TestResolveNonDirectoryParent(TestResolveConflicts):
882
998
 
883
999
    preamble = """
884
 
$ bzr init trunk
 
1000
$ brz init trunk
 
1001
...
885
1002
$ cd trunk
886
 
$ bzr mkdir foo
887
 
$ bzr commit -m 'Create trunk'
 
1003
$ brz mkdir foo
 
1004
...
 
1005
$ brz commit -m 'Create trunk' -q
888
1006
$ echo "Boing" >foo/bar
889
 
$ bzr add foo/bar
890
 
$ bzr commit -m 'Add foo/bar'
891
 
 
892
 
$ bzr branch . -r 1 ../branch
 
1007
$ brz add -q foo/bar
 
1008
$ brz commit -q -m 'Add foo/bar'
 
1009
$ brz branch -q . -r 1 ../branch
893
1010
$ cd ../branch
894
1011
$ rm -r foo
895
1012
$ echo "Boo!" >foo
896
 
$ bzr commit -m 'foo is now a file'
897
 
 
898
 
$ bzr merge ../trunk
 
1013
$ brz commit -q -m 'foo is now a file'
 
1014
$ brz merge ../trunk
899
1015
2>+N  foo.new/bar
900
1016
2>RK  foo => foo.new/
901
1017
# FIXME: The message is misleading, foo.new *is* a directory when the message
906
1022
 
907
1023
    def test_take_this(self):
908
1024
        self.run_script("""
909
 
$ bzr rm foo.new --force
 
1025
$ brz rm -q foo.new --no-backup
910
1026
# FIXME: Isn't it weird that foo is now unkown even if foo.new has been put
911
1027
# aside ? -- vila 090916
912
 
$ bzr add foo
913
 
$ bzr resolve foo.new
914
 
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
1028
$ brz add -q foo
 
1029
$ brz resolve foo.new
 
1030
2>1 conflict resolved, 0 remaining
 
1031
$ brz commit -q --strict -m 'No more conflicts nor unknown files'
915
1032
""")
916
1033
 
917
1034
    def test_take_other(self):
918
1035
        self.run_script("""
919
 
$ bzr rm foo --force
920
 
$ bzr mv foo.new foo
921
 
$ bzr resolve foo
922
 
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
1036
$ brz rm -q foo --no-backup
 
1037
$ brz mv -q foo.new foo
 
1038
$ brz resolve foo
 
1039
2>1 conflict resolved, 0 remaining
 
1040
$ brz commit -q --strict -m 'No more conflicts nor unknown files'
923
1041
""")
924
1042
 
925
1043
    def test_resolve_taking_this(self):
926
1044
        self.run_script("""
927
 
$ bzr resolve --take-this foo.new
928
 
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
1045
$ brz resolve --take-this foo.new
 
1046
2>...
 
1047
$ brz commit -q --strict -m 'No more conflicts nor unknown files'
929
1048
""")
930
1049
 
931
1050
    def test_resolve_taking_other(self):
932
1051
        self.run_script("""
933
 
$ bzr resolve --take-other foo.new
934
 
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
1052
$ brz resolve --take-other foo.new
 
1053
2>...
 
1054
$ brz commit -q --strict -m 'No more conflicts nor unknown files'
935
1055
""")
936
1056
 
937
1057
 
941
1061
        # This is nearly like TestResolveNonDirectoryParent but with branch and
942
1062
        # trunk switched. As such it should certainly produce the same
943
1063
        # conflict.
944
 
        self.run_script("""
945
 
$ bzr init trunk
 
1064
        self.assertRaises(errors.MalformedTransform,
 
1065
                          self.run_script, """
 
1066
$ brz init trunk
 
1067
...
946
1068
$ cd trunk
947
 
$ bzr mkdir foo
948
 
$ bzr commit -m 'Create trunk'
 
1069
$ brz mkdir foo
 
1070
...
 
1071
$ brz commit -m 'Create trunk' -q
949
1072
$ rm -r foo
950
1073
$ echo "Boo!" >foo
951
 
$ bzr commit -m 'foo is now a file'
952
 
 
953
 
$ bzr branch . -r 1 ../branch
 
1074
$ brz commit -m 'foo is now a file' -q
 
1075
$ brz branch -q . -r 1 ../branch -q
954
1076
$ cd ../branch
955
1077
$ echo "Boing" >foo/bar
956
 
$ bzr add foo/bar
957
 
$ bzr commit -m 'Add foo/bar'
958
 
 
959
 
$ bzr merge ../trunk
960
 
2>bzr: ERROR: Tree transform is malformed [('unversioned executability', 'new-1')]
 
1078
$ brz add -q foo/bar -q
 
1079
$ brz commit -m 'Add foo/bar' -q
 
1080
$ brz merge ../trunk
 
1081
2>brz: ERROR: Tree transform is malformed [('unversioned executability', 'new-1')]
 
1082
""")
 
1083
 
 
1084
 
 
1085
class TestNoFinalPath(script.TestCaseWithTransportAndScript):
 
1086
 
 
1087
    def test_bug_805809(self):
 
1088
        self.run_script("""
 
1089
$ brz init trunk
 
1090
Created a standalone tree (format: 2a)
 
1091
$ cd trunk
 
1092
$ echo trunk >file
 
1093
$ brz add
 
1094
adding file
 
1095
$ brz commit -m 'create file on trunk'
 
1096
2>Committing to: .../trunk/
 
1097
2>added file
 
1098
2>Committed revision 1.
 
1099
# Create a debian branch based on trunk
 
1100
$ cd ..
 
1101
$ brz branch trunk -r 1 debian
 
1102
2>Branched 1 revision.
 
1103
$ cd debian
 
1104
$ mkdir dir
 
1105
$ brz add
 
1106
adding dir
 
1107
$ brz mv file dir
 
1108
file => dir/file
 
1109
$ brz commit -m 'rename file to dir/file for debian'
 
1110
2>Committing to: .../debian/
 
1111
2>added dir
 
1112
2>renamed file => dir/file
 
1113
2>Committed revision 2.
 
1114
# Create an experimental branch with a new root-id
 
1115
$ cd ..
 
1116
$ brz init experimental
 
1117
Created a standalone tree (format: 2a)
 
1118
$ cd experimental
 
1119
# Work around merging into empty branch not being supported
 
1120
# (http://pad.lv/308562)
 
1121
$ echo something >not-empty
 
1122
$ brz add
 
1123
adding not-empty
 
1124
$ brz commit -m 'Add some content in experimental'
 
1125
2>Committing to: .../experimental/
 
1126
2>added not-empty
 
1127
2>Committed revision 1.
 
1128
# merge debian even without a common ancestor
 
1129
$ brz merge ../debian -r0..2
 
1130
2>+N  dir/
 
1131
2>+N  dir/file
 
1132
2>All changes applied successfully.
 
1133
$ brz commit -m 'merging debian into experimental'
 
1134
2>Committing to: .../experimental/
 
1135
2>added dir
 
1136
2>added dir/file
 
1137
2>Committed revision 2.
 
1138
# Create an ubuntu branch with yet another root-id
 
1139
$ cd ..
 
1140
$ brz init ubuntu
 
1141
Created a standalone tree (format: 2a)
 
1142
$ cd ubuntu
 
1143
# Work around merging into empty branch not being supported
 
1144
# (http://pad.lv/308562)
 
1145
$ echo something >not-empty-ubuntu
 
1146
$ brz add
 
1147
adding not-empty-ubuntu
 
1148
$ brz commit -m 'Add some content in experimental'
 
1149
2>Committing to: .../ubuntu/
 
1150
2>added not-empty-ubuntu
 
1151
2>Committed revision 1.
 
1152
# Also merge debian
 
1153
$ brz merge ../debian -r0..2
 
1154
2>+N  dir/
 
1155
2>+N  dir/file
 
1156
2>All changes applied successfully.
 
1157
$ brz commit -m 'merging debian'
 
1158
2>Committing to: .../ubuntu/
 
1159
2>added dir
 
1160
2>added dir/file
 
1161
2>Committed revision 2.
 
1162
# Now try to merge experimental
 
1163
$ brz merge ../experimental
 
1164
2>+N  not-empty
 
1165
2>Path conflict: dir / dir
 
1166
2>1 conflicts encountered.
961
1167
""")
962
1168
 
963
1169
 
973
1179
        return self.parser.parse_args(args)
974
1180
 
975
1181
    def test_unknown_action(self):
976
 
        self.assertRaises(errors.BadOptionValue,
 
1182
        self.assertRaises(option.BadOptionValue,
977
1183
                          self.parse, ['--action', 'take-me-to-the-moon'])
978
1184
 
979
1185
    def test_done(self):