Exemplo n.º 1
0
 def test_lca_merge_criss_cross(self):
     tree_a = self.make_branch_and_tree('a')
     self.build_tree_contents([('a/file', 'base-contents\n')])
     tree_a.add('file')
     tree_a.commit('', rev_id='rev1')
     tree_b = tree_a.bzrdir.sprout('b').open_workingtree()
     self.build_tree_contents([('a/file', 'base-contents\nthis-contents\n')
                               ])
     tree_a.commit('', rev_id='rev2a')
     self.build_tree_contents([('b/file', 'base-contents\nother-contents\n')
                               ])
     tree_b.commit('', rev_id='rev2b')
     tree_a.merge_from_branch(tree_b.branch)
     self.build_tree_contents([('a/file', 'base-contents\nthis-contents\n')
                               ])
     tree_a.set_conflicts(conflicts.ConflictList())
     tree_b.merge_from_branch(tree_a.branch)
     self.build_tree_contents([('b/file', 'base-contents\nother-contents\n')
                               ])
     tree_b.set_conflicts(conflicts.ConflictList())
     tree_a.commit('', rev_id='rev3a')
     tree_b.commit('', rev_id='rev3b')
     out, err = self.run_bzr(['merge', '-d', 'a', 'b', '--lca'], retcode=1)
     self.assertFileEqual(
         'base-contents\n<<<<<<< TREE\nthis-contents\n'
         '=======\nother-contents\n>>>>>>> MERGE-SOURCE\n', 'a/file')
Exemplo n.º 2
0
    def test_resolve_conflicts_recursive(self):
        tree = self.make_branch_and_tree('.')
        self.build_tree(['dir/', 'dir/hello'])
        tree.add(['dir', 'dir/hello'])

        dirhello = conflicts.ConflictList(
            [conflicts.TextConflict('dir/hello')])
        tree.set_conflicts(dirhello)

        conflicts.resolve(tree, ['dir'], recursive=False, ignore_misses=True)
        self.assertEqual(dirhello, tree.conflicts())

        conflicts.resolve(tree, ['dir'], recursive=True, ignore_misses=True)
        self.assertEqual(conflicts.ConflictList([]), tree.conflicts())
Exemplo n.º 3
0
 def conflicts(self):
     conflicts = _mod_conflicts.ConflictList()
     for conflicted in self._iter_conflicts():
         text = True
         try:
             if osutils.file_kind(self.abspath(conflicted)) != "file":
                 text = False
         except errors.NoSuchFile:
             text = False
         if text is True:
             for suffix in ('.THIS', '.OTHER'):
                 try:
                     kind = osutils.file_kind(
                         self.abspath(conflicted + suffix))
                     if kind != "file":
                         text = False
                 except errors.NoSuchFile:
                     text = False
                 if text == False:
                     break
         ctype = {True: 'text conflict', False: 'contents conflict'}[text]
         conflicts.append(
             _mod_conflicts.Conflict.factory(
                 ctype, path=conflicted, file_id=self.path2id(conflicted)))
     return conflicts
Exemplo n.º 4
0
 def test_auto_resolve_dir(self):
     tree = self.make_branch_and_tree('tree')
     self.build_tree(['tree/hello/'])
     tree.add('hello', 'hello-id')
     file_conflict = conflicts.TextConflict('file', None, 'hello-id')
     tree.set_conflicts(conflicts.ConflictList([file_conflict]))
     tree.auto_resolve()
Exemplo n.º 5
0
    def test_merge_bundle(self):
        from bzrlib.testament import Testament
        tree_a = self.make_branch_and_tree('branch_a')
        self.build_tree_contents([('branch_a/a', 'hello')])
        tree_a.add('a')
        tree_a.commit('message')

        tree_b = tree_a.bzrdir.sprout('branch_b').open_workingtree()
        self.build_tree_contents([('branch_a/a', 'hey there')])
        tree_a.commit('message')

        self.build_tree_contents([('branch_b/a', 'goodbye')])
        tree_b.commit('message')
        self.run_bzr('bundle ../branch_a -o ../bundle', working_dir='branch_b')
        self.run_bzr('merge ../bundle', retcode=1, working_dir='branch_a')
        testament_a = Testament.from_revision(tree_a.branch.repository,
                                              tree_b.get_parent_ids()[0])
        testament_b = Testament.from_revision(tree_b.branch.repository,
                                              tree_b.get_parent_ids()[0])
        self.assertEqualDiff(testament_a.as_text(), testament_b.as_text())
        tree_a.set_conflicts(conflicts.ConflictList())
        tree_a.commit('message')
        # it is legal to attempt to merge an already-merged bundle
        err = self.run_bzr('merge ../bundle', working_dir='branch_a')[1]
        # but it does nothing
        self.assertFalse(
            tree_a.changes_from(tree_a.basis_tree()).has_changed())
        self.assertEqual('Nothing to do.\n', err)
Exemplo n.º 6
0
 def assertPathConflict(self, c):
     # We create a conflict object as it was created before the fix and
     # inject it into the working tree, the test will exercise the
     # compatibility code.
     old_c = conflicts.PathConflict('<deleted>',
                                    self._item_path,
                                    file_id=None)
     wt.set_conflicts(conflicts.ConflictList([old_c]))
Exemplo n.º 7
0
    def test_no_autodelete_alternate_renamed(self):
        # Test for bug #114615
        tree_a = self.make_branch_and_tree('A')
        self.build_tree(['A/a/', 'A/a/m', 'A/a/n'])
        tree_a.add(['a', 'a/m', 'a/n'], ['a-id', 'm-id', 'n-id'])
        tree_a.commit('init')

        tree_a.lock_read()
        try:
            root_id = tree_a.get_root_id()
        finally:
            tree_a.unlock()

        tree_b = tree_a.bzrdir.sprout('B').open_workingtree()
        self.build_tree(['B/xyz/'])
        tree_b.add(['xyz'], ['xyz-id'])
        tree_b.rename_one('a/m', 'xyz/m')
        osutils.rmtree('B/a')
        tree_b.commit('delete in B')

        paths = [(path, ie.file_id)
                 for path, ie in tree_b.iter_entries_by_dir()]
        self.assertEqual([('', root_id),
                          ('xyz', 'xyz-id'),
                          ('xyz/m', 'm-id'),
                         ], paths)

        self.build_tree_contents([('A/a/n', 'new contents for n\n')])
        tree_a.commit('change n in A')

        # Merging from A should introduce conflicts because 'n' was modified
        # and removed, so 'a' needs to be restored.
        num_conflicts = tree_b.merge_from_branch(tree_a.branch)
        self.assertEqual(3, num_conflicts)
        paths = [(path, ie.file_id)
                 for path, ie in tree_b.iter_entries_by_dir()]
        self.assertEqual([('', root_id),
                          ('a', 'a-id'),
                          ('xyz', 'xyz-id'),
                          ('a/n.OTHER', 'n-id'),
                          ('xyz/m', 'm-id'),
                         ], paths)
        osutils.rmtree('B/a')
        try:
            # bzr resolve --all
            tree_b.set_conflicts(conflicts.ConflictList())
        except errors.UnsupportedOperation:
            # On WT2, set_conflicts is unsupported, but the rmtree has the same
            # effect.
            pass
        tree_b.commit('autoremove a, without touching xyz/m')
        paths = [(path, ie.file_id)
                 for path, ie in tree_b.iter_entries_by_dir()]
        self.assertEqual([('', root_id),
                          ('xyz', 'xyz-id'),
                          ('xyz/m', 'm-id'),
                         ], paths)
Exemplo n.º 8
0
 def test_resolve_conflict_dir(self):
     tree = self.make_branch_and_tree('.')
     self.build_tree_contents([
         ('hello', 'hello world4'),
         ('hello.THIS', 'hello world2'),
         ('hello.BASE', 'hello world1'),
     ])
     os.mkdir('hello.OTHER')
     tree.add('hello', 'q')
     l = conflicts.ConflictList([conflicts.TextConflict('hello')])
     l.remove_files(tree)
Exemplo n.º 9
0
    def test_specific_files_conflicts_xml(self):
        tree = self.make_branch_and_tree('.')
        self.build_tree(['dir2/'])
        tree.add('dir2')
        tree.commit('added dir2')
        tree.set_conflicts(
            conflicts.ConflictList([conflicts.ContentsConflict('foo')]))
        self.assertStatus(create_xml(tree, {}), tree, specific_files=['dir2'])

        tree.set_conflicts(
            conflicts.ConflictList([conflicts.ContentsConflict('dir2')]))
        self.assertStatus(create_xml(
            tree, {'conflicts': [('directory', 'dir2', {})]}),
                          tree,
                          specific_files=['dir2'])

        tree.set_conflicts(
            conflicts.ConflictList([conflicts.ContentsConflict('dir2/file1')]))
        self.assertStatus(create_xml(
            tree, {'conflicts': [('file', 'dir2/file1', {})]}),
                          tree,
                          specific_files=['dir2'])
Exemplo n.º 10
0
    def test_specific_files_conflicts(self):
        tree = self.make_branch_and_tree('.')
        self.build_tree(['dir2/'])
        tree.add('dir2')
        tree.commit('added dir2')
        tree.set_conflicts(
            conflicts.ConflictList([conflicts.ContentsConflict('foo')]))
        tof = StringIO()
        show_tree_status(tree, specific_files=['dir2'], to_file=tof)
        self.assertEqualDiff('', tof.getvalue())
        tree.set_conflicts(
            conflicts.ConflictList([conflicts.ContentsConflict('dir2')]))
        tof = StringIO()
        show_tree_status(tree, specific_files=['dir2'], to_file=tof)
        self.assertEqualDiff('conflicts:\n  Contents conflict in dir2\n',
                             tof.getvalue())

        tree.set_conflicts(
            conflicts.ConflictList([conflicts.ContentsConflict('dir2/file1')]))
        tof = StringIO()
        show_tree_status(tree, specific_files=['dir2'], to_file=tof)
        self.assertEqualDiff('conflicts:\n  Contents conflict in dir2/file1\n',
                             tof.getvalue())
Exemplo n.º 11
0
    def create_merged_trees(self):
        """create 2 trees with merges between them.

        rev-1 --+
         |      |
        rev-2  rev-1_1_1
         |      |
         +------+
         |
        rev-3
        """

        tree1 = self.make_branch_and_tree('tree1')
        self.build_tree_contents([('tree1/a', 'first\n')])
        tree1.add(['a'], ['a-id'])
        tree1.commit('a',
                     rev_id='rev-1',
                     committer="*****@*****.**",
                     timestamp=1166046000.00,
                     timezone=0)

        tree2 = tree1.bzrdir.sprout('tree2').open_workingtree()

        self.build_tree_contents([('tree1/a', 'first\nsecond\n')])
        tree1.commit('b',
                     rev_id='rev-2',
                     committer='*****@*****.**',
                     timestamp=1166046001.00,
                     timezone=0)

        self.build_tree_contents([('tree2/a', 'first\nthird\n')])
        tree2.commit('c',
                     rev_id='rev-1_1_1',
                     committer="*****@*****.**",
                     timestamp=1166046002.00,
                     timezone=0)

        num_conflicts = tree1.merge_from_branch(tree2.branch)
        self.assertEqual(1, num_conflicts)

        self.build_tree_contents([('tree1/a', 'first\nsecond\nthird\n')])
        tree1.set_conflicts(conflicts.ConflictList())
        tree1.commit('merge 2',
                     rev_id='rev-3',
                     committer='*****@*****.**',
                     timestamp=1166046003.00,
                     timezone=0)
        tree1.lock_read()
        self.addCleanup(tree1.unlock)
        return tree1, tree2
Exemplo n.º 12
0
 def test_auto_resolve(self):
     """Text conflicts can be resolved automatically"""
     tree = self.make_branch_and_tree('tree')
     self.build_tree_contents([('tree/file',
                                '<<<<<<<\na\n=======\n>>>>>>>\n')])
     tree.add('file', 'file_id')
     self.assertEqual(tree.kind('file_id'), 'file')
     file_conflict = conflicts.TextConflict('file', file_id='file_id')
     tree.set_conflicts(conflicts.ConflictList([file_conflict]))
     note = self.run_bzr('resolve', retcode=1, working_dir='tree')[1]
     self.assertContainsRe(note, '0 conflicts auto-resolved.')
     self.assertContainsRe(note,
                           'Remaining conflicts:\nText conflict in file')
     self.build_tree_contents([('tree/file', 'a\n')])
     note = self.run_bzr('resolve', working_dir='tree')[1]
     self.assertContainsRe(note, 'All conflicts resolved.')
Exemplo n.º 13
0
 def test_file4_added_then_renamed(self):
     outer, inner = self.make_outer_tree()
     # 1 conflict, because file4 can't be put into the old root
     self.assertEqual(1, outer.merge_from_branch(inner, to_revision='4'))
     try:
         outer.set_conflicts(conflicts.ConflictList())
     except errors.UnsupportedOperation:
         # WT2 doesn't have a separate list of conflicts to clear. It
         # actually says there is a conflict, but happily forgets all about
         # it.
         pass
     outer.commit('added file4')
     # And now file4 gets renamed into an existing dir
     nb_conflicts = outer.merge_from_branch(inner, to_revision='5')
     self.assertEqual(1, nb_conflicts)
     self.assertTreeLayout(['dir-outer',
                            'dir-outer/dir',
                            'dir-outer/dir/file1',
                            'dir-outer/dir/file4',
                            'dir-outer/file3',
                            'foo'],
                           outer)
Exemplo n.º 14
0
# TODO: Test commit with some added, and added-but-missing files
# RBC 20060124 is that not tested in test_commit.py ?

# The order of 'path' here is important - do not let it
# be a sorted list.
# u'\xe5' == a with circle
# '\xc3\xae' == u'\xee' == i with hat
# So these are u'path' and 'id' only with a circle and a hat. (shappo?)
example_conflicts = conflicts.ConflictList([
    conflicts.MissingParent('Not deleting', u'p\xe5thg', '\xc3\xaedg'),
    conflicts.ContentsConflict(u'p\xe5tha', None, '\xc3\xaeda'),
    conflicts.TextConflict(u'p\xe5tha'),
    conflicts.PathConflict(u'p\xe5thb', u'p\xe5thc', '\xc3\xaedb'),
    conflicts.DuplicateID('Unversioned existing file', u'p\xe5thc',
                          u'p\xe5thc2', '\xc3\xaedc', '\xc3\xaedc'),
    conflicts.DuplicateEntry('Moved existing file to', u'p\xe5thdd.moved',
                             u'p\xe5thd', '\xc3\xaedd', None),
    conflicts.ParentLoop('Cancelled move', u'p\xe5the', u'p\xe5th2e', None,
                         '\xc3\xaed2e'),
    conflicts.UnversionedParent('Versioned directory', u'p\xe5thf',
                                '\xc3\xaedf'),
    conflicts.NonDirectoryParent('Created directory', u'p\xe5thg',
                                 '\xc3\xaedg'),
])


def vary_by_conflicts():
    for conflict in example_conflicts:
        yield (conflict.__class__.__name__, {"conflict": conflict})


class TestConflicts(tests.TestCaseWithTransport):