/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 bzrlib/tests/test_conflicts.py

  • Committer: Martin von Gagern
  • Date: 2011-06-01 07:01:17 UTC
  • mto: This revision was merged to the branch mainline in revision 5963.
  • Revision ID: martin.vgagern@gmx.net-20110601070117-3b08kqy51062ep0y
Allow -s as shorthand for --log-format=short.

This is implemented by allowing a keyword argument named
short_value_switches for the RegistryOption initializer.  It maps long names
to short names.  The newly added short option affects the commands log and
missing.

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
18
18
import os
19
19
 
20
20
from bzrlib import (
21
 
    branchbuilder,
22
21
    bzrdir,
23
22
    conflicts,
24
23
    errors,
25
24
    option,
 
25
    osutils,
26
26
    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
 
27
    )
 
28
from bzrlib.tests import (
 
29
    script,
 
30
    scenarios,
 
31
    )
 
32
 
 
33
 
 
34
load_tests = scenarios.load_tests_apply_scenarios
49
35
 
50
36
 
51
37
# TODO: Test commit with some added, and added-but-missing files
76
62
])
77
63
 
78
64
 
 
65
def vary_by_conflicts():
 
66
    for conflict in example_conflicts:
 
67
        yield (conflict.__class__.__name__, {"conflict": conflict})
 
68
 
 
69
 
79
70
class TestConflicts(tests.TestCaseWithTransport):
80
71
 
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
72
    def test_resolve_conflict_dir(self):
109
73
        tree = self.make_branch_and_tree('.')
110
74
        self.build_tree_contents([('hello', 'hello world4'),
161
125
        self.assertEqual(conflicts.ConflictList([]), tree.conflicts())
162
126
 
163
127
 
164
 
class TestConflictStanzas(tests.TestCase):
 
128
class TestPerConflict(tests.TestCase):
 
129
 
 
130
    scenarios = scenarios.multiply_scenarios(vary_by_conflicts())
 
131
 
 
132
    def test_stringification(self):
 
133
        text = unicode(self.conflict)
 
134
        self.assertContainsString(text, self.conflict.path)
 
135
        self.assertContainsString(text.lower(), "conflict")
 
136
        self.assertContainsString(repr(self.conflict),
 
137
            self.conflict.__class__.__name__)
165
138
 
166
139
    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)
 
140
        p = self.conflict
 
141
        o = conflicts.Conflict.factory(**p.as_stanza().as_dict())
 
142
        self.assertEqual(o, p)
 
143
 
 
144
        self.assertIsInstance(o.path, unicode)
 
145
 
 
146
        if o.file_id is not None:
 
147
            self.assertIsInstance(o.file_id, str)
 
148
 
 
149
        conflict_path = getattr(o, 'conflict_path', None)
 
150
        if conflict_path is not None:
 
151
            self.assertIsInstance(conflict_path, unicode)
 
152
 
 
153
        conflict_file_id = getattr(o, 'conflict_file_id', None)
 
154
        if conflict_file_id is not None:
 
155
            self.assertIsInstance(conflict_file_id, str)
185
156
 
186
157
    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')
 
158
        stanza = self.conflict.as_stanza()
 
159
        if 'file_id' in stanza:
 
160
            # In Stanza form, the file_id has to be unicode.
 
161
            self.assertStartsWith(stanza['file_id'], u'\xeed')
 
162
        self.assertStartsWith(stanza['path'], u'p\xe5th')
 
163
        if 'conflict_path' in stanza:
 
164
            self.assertStartsWith(stanza['conflict_path'], u'p\xe5th')
 
165
        if 'conflict_file_id' in stanza:
 
166
            self.assertStartsWith(stanza['conflict_file_id'], u'\xeed')
 
167
 
 
168
 
 
169
class TestConflictList(tests.TestCase):
 
170
 
 
171
    def test_stanzas_roundtrip(self):
 
172
        stanzas_iter = example_conflicts.to_stanzas()
 
173
        processed = conflicts.ConflictList.from_stanzas(stanzas_iter)
 
174
        self.assertEqual(example_conflicts, processed)
 
175
 
 
176
    def test_stringification(self):
 
177
        for text, o in zip(example_conflicts.to_strings(), example_conflicts):
 
178
            self.assertEqual(text, unicode(o))
196
179
 
197
180
 
198
181
# FIXME: The shell-like tests should be converted to real whitebox tests... or
210
193
        self.run_script(self.preamble)
211
194
 
212
195
 
213
 
class TestResolveTextConflicts(TestResolveConflicts):
214
 
    # TBC
215
 
    pass
216
 
 
217
 
 
218
196
def mirror_scenarios(base_scenarios):
219
197
    """Return a list of mirrored scenarios.
220
198
 
293
271
    _this = None
294
272
    _other = None
295
273
 
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 []
 
274
    scenarios = []
 
275
    """The scenario list for the conflict type defined by the class.
 
276
 
 
277
    Each scenario is of the form:
 
278
    (common, (left_name, left_dict), (right_name, right_dict))
 
279
 
 
280
    * common is a dict
 
281
 
 
282
    * left_name and right_name are the scenario names that will be combined
 
283
 
 
284
    * left_dict and right_dict are the attributes specific to each half of
 
285
      the scenario. They should include at least 'actions' and 'check' and
 
286
      will be available as '_this' and '_other' test instance attributes.
 
287
 
 
288
    Daughters classes are free to add their specific attributes as they see
 
289
    fit in any of the three dicts.
 
290
 
 
291
    This is a class method so that load_tests can find it.
 
292
 
 
293
    '_base_actions' in the common dict, 'actions' and 'check' in the left
 
294
    and right dicts use names that map to methods in the test classes. Some
 
295
    prefixes are added to these names to get the correspong methods (see
 
296
    _get_actions() and _get_check()). The motivation here is to avoid
 
297
    collisions in the class namespace.
 
298
    """
324
299
 
325
300
    def setUp(self):
326
301
        super(TestParametrizedResolveConflicts, self).setUp()
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 modified/deleted in dir
 
450
            (dict(_base_actions='create_file_in_dir',
 
451
                  _path='dir/file', _file_id='file-id'),
 
452
             ('file_modified_in_dir',
 
453
              dict(actions='modify_file_in_dir',
 
454
                   check='file_in_dir_has_more_content')),
 
455
             ('file_deleted_in_dir',
 
456
              dict(actions='delete_file',
 
457
                   check='file_in_dir_doesnt_exist')),),
 
458
            ])
412
459
 
413
460
    def do_create_file(self):
414
461
        return [('add', ('file', 'file-id', 'file', 'trunk content\n'))]
423
470
        return [('unversion', 'file-id')]
424
471
 
425
472
    def check_file_doesnt_exist(self):
426
 
        self.failIfExists('branch/file')
 
473
        self.assertPathDoesNotExist('branch/file')
 
474
 
 
475
    def do_create_file_in_dir(self):
 
476
        return [('add', ('dir', 'dir-id', 'directory', '')),
 
477
                ('add', ('dir/file', 'file-id', 'file', 'trunk content\n'))]
 
478
 
 
479
    def do_modify_file_in_dir(self):
 
480
        return [('modify', ('file-id', 'trunk content\nmore content\n'))]
 
481
 
 
482
    def check_file_in_dir_has_more_content(self):
 
483
        self.assertFileEqual('trunk content\nmore content\n', 'branch/dir/file')
 
484
 
 
485
    def check_file_in_dir_doesnt_exist(self):
 
486
        self.assertPathDoesNotExist('branch/dir/file')
427
487
 
428
488
    def _get_resolve_path_arg(self, wt, action):
429
489
        return self._path
436
496
 
437
497
class TestResolvePathConflict(TestParametrizedResolveConflicts):
438
498
 
439
 
    _conflict_type = conflicts.PathConflict,
 
499
    _conflict_type = conflicts.PathConflict
440
500
 
441
501
    def do_nothing(self):
442
502
        return []
443
503
 
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 = [
 
504
    # Each side dict additionally defines:
 
505
    # - path path involved (can be '<deleted>')
 
506
    # - file-id involved
 
507
    scenarios = mirror_scenarios(
 
508
        [
450
509
            # File renamed/deleted
451
510
            (dict(_base_actions='create_file'),
452
511
             ('file_renamed',
457
516
                   # PathConflicts deletion handling requires a special
458
517
                   # hard-coded value
459
518
                   path='<deleted>', file_id='file-id')),),
 
519
            # File renamed/deleted in dir
 
520
            (dict(_base_actions='create_file_in_dir'),
 
521
             ('file_renamed_in_dir',
 
522
              dict(actions='rename_file_in_dir', check='file_in_dir_renamed',
 
523
                   path='dir/new-file', file_id='file-id')),
 
524
             ('file_deleted',
 
525
              dict(actions='delete_file', check='file_in_dir_doesnt_exist',
 
526
                   # PathConflicts deletion handling requires a special
 
527
                   # hard-coded value
 
528
                   path='<deleted>', file_id='file-id')),),
460
529
            # File renamed/renamed differently
461
530
            (dict(_base_actions='create_file'),
462
531
             ('file_renamed',
483
552
             ('dir_renamed2',
484
553
              dict(actions='rename_dir2', check='dir_renamed2',
485
554
                   path='new-dir2', file_id='dir-id')),),
486
 
        ]
487
 
        return mirror_scenarios(base_scenarios)
 
555
            ])
488
556
 
489
557
    def do_create_file(self):
490
558
        return [('add', ('file', 'file-id', 'file', 'trunk content\n'))]
496
564
        return [('rename', ('file', 'new-file'))]
497
565
 
498
566
    def check_file_renamed(self):
499
 
        self.failIfExists('branch/file')
500
 
        self.failUnlessExists('branch/new-file')
 
567
        self.assertPathDoesNotExist('branch/file')
 
568
        self.assertPathExists('branch/new-file')
501
569
 
502
570
    def do_rename_file2(self):
503
571
        return [('rename', ('file', 'new-file2'))]
504
572
 
505
573
    def check_file_renamed2(self):
506
 
        self.failIfExists('branch/file')
507
 
        self.failUnlessExists('branch/new-file2')
 
574
        self.assertPathDoesNotExist('branch/file')
 
575
        self.assertPathExists('branch/new-file2')
508
576
 
509
577
    def do_rename_dir(self):
510
578
        return [('rename', ('dir', 'new-dir'))]
511
579
 
512
580
    def check_dir_renamed(self):
513
 
        self.failIfExists('branch/dir')
514
 
        self.failUnlessExists('branch/new-dir')
 
581
        self.assertPathDoesNotExist('branch/dir')
 
582
        self.assertPathExists('branch/new-dir')
515
583
 
516
584
    def do_rename_dir2(self):
517
585
        return [('rename', ('dir', 'new-dir2'))]
518
586
 
519
587
    def check_dir_renamed2(self):
520
 
        self.failIfExists('branch/dir')
521
 
        self.failUnlessExists('branch/new-dir2')
 
588
        self.assertPathDoesNotExist('branch/dir')
 
589
        self.assertPathExists('branch/new-dir2')
522
590
 
523
591
    def do_delete_file(self):
524
592
        return [('unversion', 'file-id')]
525
593
 
526
594
    def check_file_doesnt_exist(self):
527
 
        self.failIfExists('branch/file')
 
595
        self.assertPathDoesNotExist('branch/file')
528
596
 
529
597
    def do_delete_dir(self):
530
598
        return [('unversion', 'dir-id')]
531
599
 
532
600
    def check_dir_doesnt_exist(self):
533
 
        self.failIfExists('branch/dir')
 
601
        self.assertPathDoesNotExist('branch/dir')
 
602
 
 
603
    def do_create_file_in_dir(self):
 
604
        return [('add', ('dir', 'dir-id', 'directory', '')),
 
605
                ('add', ('dir/file', 'file-id', 'file', 'trunk content\n'))]
 
606
 
 
607
    def do_rename_file_in_dir(self):
 
608
        return [('rename', ('dir/file', 'dir/new-file'))]
 
609
 
 
610
    def check_file_in_dir_renamed(self):
 
611
        self.assertPathDoesNotExist('branch/dir/file')
 
612
        self.assertPathExists('branch/dir/new-file')
 
613
 
 
614
    def check_file_in_dir_doesnt_exist(self):
 
615
        self.assertPathDoesNotExist('branch/dir/file')
534
616
 
535
617
    def _get_resolve_path_arg(self, wt, action):
536
618
        tpath = self._this['path']
568
650
 
569
651
class TestResolveDuplicateEntry(TestParametrizedResolveConflicts):
570
652
 
571
 
    _conflict_type = conflicts.DuplicateEntry,
 
653
    _conflict_type = conflicts.DuplicateEntry
572
654
 
573
 
    @staticmethod
574
 
    def scenarios():
575
 
        # Each side dict additionally defines:
576
 
        # - path involved
577
 
        # - file-id involved
578
 
        base_scenarios = [
 
655
    scenarios = mirror_scenarios(
 
656
        [
579
657
            # File created with different file-ids
580
658
            (dict(_base_actions='nothing'),
581
659
             ('filea_created',
584
662
             ('fileb_created',
585
663
              dict(actions='create_file_b', check='file_content_b',
586
664
                   path='file', file_id='file-b-id')),),
587
 
            ]
588
 
        return mirror_scenarios(base_scenarios)
 
665
            ])
589
666
 
590
667
    def do_nothing(self):
591
668
        return []
625
702
    # tests MissingParent resolution :-/
626
703
    preamble = """
627
704
$ bzr init trunk
 
705
...
628
706
$ cd trunk
629
707
$ mkdir dir
630
 
$ bzr add dir
631
 
$ bzr commit -m 'Create trunk'
632
 
 
 
708
$ bzr add -q dir
 
709
$ bzr commit -m 'Create trunk' -q
633
710
$ 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
 
711
$ bzr add -q dir/file
 
712
$ bzr commit -q -m 'Add dir/file in trunk'
 
713
$ bzr branch -q . -r 1 ../branch
638
714
$ cd ../branch
639
 
$ bzr rm dir
640
 
$ bzr commit -m 'Remove dir in branch'
641
 
 
 
715
$ bzr rm dir -q
 
716
$ bzr commit -q -m 'Remove dir in branch'
642
717
$ bzr merge ../trunk
643
718
2>+N  dir/
644
719
2>+N  dir/file
649
724
 
650
725
    def test_take_this(self):
651
726
        self.run_script("""
652
 
$ bzr rm dir  --force
 
727
$ bzr rm -q dir  --force
653
728
$ bzr resolve dir
654
 
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
729
2>2 conflict(s) resolved, 0 remaining
 
730
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
655
731
""")
656
732
 
657
733
    def test_take_other(self):
658
734
        self.run_script("""
659
735
$ bzr resolve dir
660
 
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
736
2>2 conflict(s) resolved, 0 remaining
 
737
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
661
738
""")
662
739
 
663
740
 
665
742
 
666
743
    preamble = """
667
744
$ bzr init trunk
 
745
...
668
746
$ cd trunk
669
747
$ mkdir dir
670
748
$ echo 'trunk content' >dir/file
671
 
$ bzr add
672
 
$ bzr commit -m 'Create trunk'
673
 
 
 
749
$ bzr add -q
 
750
$ bzr commit -m 'Create trunk' -q
674
751
$ 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
 
752
$ bzr add -q dir/file2
 
753
$ bzr commit -q -m 'Add dir/file2 in branch'
 
754
$ bzr branch -q . -r 1 ../branch
679
755
$ cd ../branch
680
 
$ bzr rm dir/file --force
681
 
$ bzr rm dir
682
 
$ bzr commit -m 'Remove dir/file'
683
 
 
 
756
$ bzr rm -q dir/file --force
 
757
$ bzr rm -q dir
 
758
$ bzr commit -q -m 'Remove dir/file'
684
759
$ bzr merge ../trunk
685
760
2>+N  dir/
686
761
2>+N  dir/file2
692
767
    def test_keep_them_all(self):
693
768
        self.run_script("""
694
769
$ bzr resolve dir
695
 
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
770
2>2 conflict(s) resolved, 0 remaining
 
771
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
696
772
""")
697
773
 
698
774
    def test_adopt_child(self):
699
775
        self.run_script("""
700
 
$ bzr mv dir/file2 file2
701
 
$ bzr rm dir --force
 
776
$ bzr mv -q dir/file2 file2
 
777
$ bzr rm -q dir --force
702
778
$ bzr resolve dir
703
 
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
779
2>2 conflict(s) resolved, 0 remaining
 
780
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
704
781
""")
705
782
 
706
783
    def test_kill_them_all(self):
707
784
        self.run_script("""
708
 
$ bzr rm dir --force
 
785
$ bzr rm -q dir --force
709
786
$ bzr resolve dir
710
 
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
787
2>2 conflict(s) resolved, 0 remaining
 
788
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
711
789
""")
712
790
 
713
791
    def test_resolve_taking_this(self):
714
792
        self.run_script("""
715
793
$ bzr resolve --take-this dir
716
 
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
794
2>...
 
795
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
717
796
""")
718
797
 
719
798
    def test_resolve_taking_other(self):
720
799
        self.run_script("""
721
800
$ bzr resolve --take-other dir
722
 
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
801
2>...
 
802
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
723
803
""")
724
804
 
725
805
 
727
807
 
728
808
    preamble = """
729
809
$ bzr init trunk
 
810
...
730
811
$ cd trunk
731
812
$ mkdir dir
732
813
$ 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
 
814
$ bzr add -q
 
815
$ bzr commit -m 'Create trunk' -q
 
816
$ bzr rm -q dir/file --force
 
817
$ bzr rm -q dir --force
 
818
$ bzr commit -q -m 'Remove dir/file'
 
819
$ bzr branch -q . -r 1 ../branch
741
820
$ cd ../branch
742
821
$ echo 'branch content' >dir/file2
743
 
$ bzr add dir/file2
744
 
$ bzr commit -m 'Add dir/file2 in branch'
745
 
 
 
822
$ bzr add -q dir/file2
 
823
$ bzr commit -q -m 'Add dir/file2 in branch'
746
824
$ bzr merge ../trunk
747
825
2>-D  dir/file
748
826
2>Conflict: can't delete dir because it is not empty.  Not deleting.
753
831
    def test_keep_them_all(self):
754
832
        self.run_script("""
755
833
$ bzr resolve dir
756
 
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
834
2>2 conflict(s) resolved, 0 remaining
 
835
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
757
836
""")
758
837
 
759
838
    def test_adopt_child(self):
760
839
        self.run_script("""
761
 
$ bzr mv dir/file2 file2
762
 
$ bzr rm dir --force
 
840
$ bzr mv -q dir/file2 file2
 
841
$ bzr rm -q dir --force
763
842
$ bzr resolve dir
764
 
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
843
2>2 conflict(s) resolved, 0 remaining
 
844
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
765
845
""")
766
846
 
767
847
    def test_kill_them_all(self):
768
848
        self.run_script("""
769
 
$ bzr rm dir --force
 
849
$ bzr rm -q dir --force
770
850
$ bzr resolve dir
771
 
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
851
2>2 conflict(s) resolved, 0 remaining
 
852
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
772
853
""")
773
854
 
774
855
    def test_resolve_taking_this(self):
775
856
        self.run_script("""
776
857
$ bzr resolve --take-this dir
777
 
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
858
2>2 conflict(s) resolved, 0 remaining
 
859
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
778
860
""")
779
861
 
780
862
    def test_resolve_taking_other(self):
781
863
        self.run_script("""
782
864
$ bzr resolve --take-other dir
783
 
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
865
2>deleted dir/file2
 
866
2>deleted dir
 
867
2>2 conflict(s) resolved, 0 remaining
 
868
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
784
869
""")
785
870
 
786
871
 
787
872
class TestResolveParentLoop(TestParametrizedResolveConflicts):
788
873
 
789
 
    _conflict_type = conflicts.ParentLoop,
 
874
    _conflict_type = conflicts.ParentLoop
790
875
 
791
876
    _this_args = None
792
877
    _other_args = None
793
878
 
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 = [
 
879
    # Each side dict additionally defines:
 
880
    # - dir_id: the directory being moved
 
881
    # - target_id: The target directory
 
882
    # - xfail: whether the test is expected to fail if the action is
 
883
    #   involved as 'other'
 
884
    scenarios = mirror_scenarios(
 
885
        [
802
886
            # Dirs moved into each other
803
887
            (dict(_base_actions='create_dir1_dir2'),
804
888
             ('dir1_into_dir2',
815
899
             ('dir3_into_dir2',
816
900
              dict(actions='move_dir3_into_dir2', check='dir3_4_moved',
817
901
                   dir_id='dir3-id', target_id='dir2-id', xfail=True))),
818
 
            ]
819
 
        return mirror_scenarios(base_scenarios)
 
902
            ])
820
903
 
821
904
    def do_create_dir1_dir2(self):
822
905
        return [('add', ('dir1', 'dir1-id', 'directory', '')),
826
909
        return [('rename', ('dir1', 'dir2/dir1'))]
827
910
 
828
911
    def check_dir1_moved(self):
829
 
        self.failIfExists('branch/dir1')
830
 
        self.failUnlessExists('branch/dir2/dir1')
 
912
        self.assertPathDoesNotExist('branch/dir1')
 
913
        self.assertPathExists('branch/dir2/dir1')
831
914
 
832
915
    def do_move_dir2_into_dir1(self):
833
916
        return [('rename', ('dir2', 'dir1/dir2'))]
834
917
 
835
918
    def check_dir2_moved(self):
836
 
        self.failIfExists('branch/dir2')
837
 
        self.failUnlessExists('branch/dir1/dir2')
 
919
        self.assertPathDoesNotExist('branch/dir2')
 
920
        self.assertPathExists('branch/dir1/dir2')
838
921
 
839
922
    def do_create_dir1_4(self):
840
923
        return [('add', ('dir1', 'dir1-id', 'directory', '')),
846
929
        return [('rename', ('dir1', 'dir3/dir4/dir1'))]
847
930
 
848
931
    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')
 
932
        self.assertPathDoesNotExist('branch/dir1')
 
933
        self.assertPathExists('branch/dir3/dir4/dir1')
 
934
        self.assertPathExists('branch/dir3/dir4/dir1/dir2')
852
935
 
853
936
    def do_move_dir3_into_dir2(self):
854
937
        return [('rename', ('dir3', 'dir1/dir2/dir3'))]
855
938
 
856
939
    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')
 
940
        self.assertPathDoesNotExist('branch/dir3')
 
941
        self.assertPathExists('branch/dir1/dir2/dir3')
 
942
        self.assertPathExists('branch/dir1/dir2/dir3/dir4')
860
943
 
861
944
    def _get_resolve_path_arg(self, wt, action):
862
945
        # ParentLoop says: moving <conflict_path> into <path>. Cancelled move.
882
965
 
883
966
    preamble = """
884
967
$ bzr init trunk
 
968
...
885
969
$ cd trunk
886
970
$ bzr mkdir foo
887
 
$ bzr commit -m 'Create trunk'
 
971
...
 
972
$ bzr commit -m 'Create trunk' -q
888
973
$ echo "Boing" >foo/bar
889
 
$ bzr add foo/bar
890
 
$ bzr commit -m 'Add foo/bar'
891
 
 
892
 
$ bzr branch . -r 1 ../branch
 
974
$ bzr add -q foo/bar
 
975
$ bzr commit -q -m 'Add foo/bar'
 
976
$ bzr branch -q . -r 1 ../branch
893
977
$ cd ../branch
894
978
$ rm -r foo
895
979
$ echo "Boo!" >foo
896
 
$ bzr commit -m 'foo is now a file'
897
 
 
 
980
$ bzr commit -q -m 'foo is now a file'
898
981
$ bzr merge ../trunk
899
982
2>+N  foo.new/bar
900
983
2>RK  foo => foo.new/
906
989
 
907
990
    def test_take_this(self):
908
991
        self.run_script("""
909
 
$ bzr rm foo.new --force
 
992
$ bzr rm -q foo.new --force
910
993
# FIXME: Isn't it weird that foo is now unkown even if foo.new has been put
911
994
# aside ? -- vila 090916
912
 
$ bzr add foo
 
995
$ bzr add -q foo
913
996
$ bzr resolve foo.new
914
 
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
997
2>1 conflict(s) resolved, 0 remaining
 
998
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
915
999
""")
916
1000
 
917
1001
    def test_take_other(self):
918
1002
        self.run_script("""
919
 
$ bzr rm foo --force
920
 
$ bzr mv foo.new foo
 
1003
$ bzr rm -q foo --force
 
1004
$ bzr mv -q foo.new foo
921
1005
$ bzr resolve foo
922
 
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
1006
2>1 conflict(s) resolved, 0 remaining
 
1007
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
923
1008
""")
924
1009
 
925
1010
    def test_resolve_taking_this(self):
926
1011
        self.run_script("""
927
1012
$ bzr resolve --take-this foo.new
928
 
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
1013
2>...
 
1014
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
929
1015
""")
930
1016
 
931
1017
    def test_resolve_taking_other(self):
932
1018
        self.run_script("""
933
1019
$ bzr resolve --take-other foo.new
934
 
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
1020
2>...
 
1021
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
935
1022
""")
936
1023
 
937
1024
 
943
1030
        # conflict.
944
1031
        self.run_script("""
945
1032
$ bzr init trunk
 
1033
...
946
1034
$ cd trunk
947
1035
$ bzr mkdir foo
948
 
$ bzr commit -m 'Create trunk'
 
1036
...
 
1037
$ bzr commit -m 'Create trunk' -q
949
1038
$ rm -r foo
950
1039
$ echo "Boo!" >foo
951
 
$ bzr commit -m 'foo is now a file'
952
 
 
953
 
$ bzr branch . -r 1 ../branch
 
1040
$ bzr commit -m 'foo is now a file' -q
 
1041
$ bzr branch -q . -r 1 ../branch -q
954
1042
$ cd ../branch
955
1043
$ echo "Boing" >foo/bar
956
 
$ bzr add foo/bar
957
 
$ bzr commit -m 'Add foo/bar'
958
 
 
 
1044
$ bzr add -q foo/bar -q
 
1045
$ bzr commit -m 'Add foo/bar' -q
959
1046
$ bzr merge ../trunk
960
1047
2>bzr: ERROR: Tree transform is malformed [('unversioned executability', 'new-1')]
961
1048
""")