def test_merge_revert(self): from bzrlib.merge import merge_inner this = self.make_branch_and_tree('b1') open('b1/a', 'wb').write('a test\n') this.add('a') open('b1/b', 'wb').write('b test\n') this.add('b') this.commit(message='') base = this.bzrdir.clone('b2').open_workingtree() open('b2/a', 'wb').write('b test\n') other = this.bzrdir.clone('b3').open_workingtree() open('b3/a', 'wb').write('c test\n') open('b3/c', 'wb').write('c test\n') other.add('c') open('b1/b', 'wb').write('q test\n') open('b1/d', 'wb').write('d test\n') merge_inner(this.branch, other, base, this_tree=this) self.assertNotEqual(open('b1/a', 'rb').read(), 'a test\n') this.revert() self.assertEqual(open('b1/a', 'rb').read(), 'a test\n') self.assertIs(os.path.exists('b1/b.~1~'), True) self.assertIs(os.path.exists('b1/c'), False) self.assertIs(os.path.exists('b1/a.~1~'), False) self.assertIs(os.path.exists('b1/d'), True)
def test_rmdir_conflict(self): tree_a = self.make_branch_and_tree('a') self.build_tree(['a/b/']) tree_a.add('b', 'b-id') tree_a.commit('added b') # basis_tree() is only guaranteed to be valid as long as it is actually # the basis tree. This mutates the tree after grabbing basis, so go to # the repository. base_tree = tree_a.branch.repository.revision_tree(tree_a.last_revision()) tree_z = tree_a.bzrdir.sprout('z').open_workingtree() self.build_tree(['a/b/c']) tree_a.add('b/c') tree_a.commit('added c') os.rmdir('z/b') tree_z.commit('removed b') merge_inner(tree_z.branch, tree_a, base_tree, this_tree=tree_z) self.assertEqual([ conflicts.MissingParent('Created directory', 'b', 'b-id'), conflicts.UnversionedParent('Versioned directory', 'b', 'b-id')], tree_z.conflicts()) merge_inner(tree_a.branch, tree_z.basis_tree(), base_tree, this_tree=tree_a) self.assertEqual([ conflicts.DeletingParent('Not deleting', 'b', 'b-id'), conflicts.UnversionedParent('Versioned directory', 'b', 'b-id')], tree_a.conflicts())
def test_merge_revert(self): from bzrlib.merge import merge_inner this = self.make_branch_and_tree('b1') self.build_tree_contents([('b1/a', 'a test\n'), ('b1/b', 'b test\n')]) this.add(['a', 'b']) this.commit(message='') base = this.bzrdir.clone('b2').open_workingtree() self.build_tree_contents([('b2/a', 'b test\n')]) other = this.bzrdir.clone('b3').open_workingtree() self.build_tree_contents([('b3/a', 'c test\n'), ('b3/c', 'c test\n')]) other.add('c') self.build_tree_contents([('b1/b', 'q test\n'), ('b1/d', 'd test\n')]) # Note: If we don't lock this before calling merge_inner, then we get a # lock-contention failure. This probably indicates something # weird going on inside merge_inner. Probably something about # calling bt = this_tree.basis_tree() in one lock, and then # locking both this_tree and bt separately, causing a dirstate # locking race. this.lock_write() self.addCleanup(this.unlock) merge_inner(this.branch, other, base, this_tree=this) a = open('b1/a', 'rb') try: self.assertNotEqual(a.read(), 'a test\n') finally: a.close() this.revert() self.assertFileEqual('a test\n', 'b1/a') self.assertPathExists('b1/b.~1~') self.assertPathDoesNotExist('b1/c') self.assertPathDoesNotExist('b1/a.~1~') self.assertPathExists('b1/d')
def test_merge_with_missing(self): tree_a = self.make_branch_and_tree('tree_a') self.build_tree_contents([('tree_a/file', 'content_1')]) tree_a.add('file') tree_a.commit('commit base') # basis_tree() is only guaranteed to be valid as long as it is actually # the basis tree. This mutates the tree after grabbing basis, so go to # the repository. base_tree = tree_a.branch.repository.revision_tree(tree_a.last_revision()) tree_b = tree_a.bzrdir.sprout('tree_b').open_workingtree() self.build_tree_contents([('tree_a/file', 'content_2')]) tree_a.commit('commit other') other_tree = tree_a.basis_tree() os.unlink('tree_b/file') merge_inner(tree_b.branch, other_tree, base_tree, this_tree=tree_b)
def make_merge_conflicts(self): from bzrlib.merge import merge_inner tree = self.make_branch_and_tree('mine') file('mine/bloo', 'wb').write('one') file('mine/blo', 'wb').write('on') tree.add(['bloo', 'blo']) tree.commit("blah", allow_pointless=False) base = tree.branch.repository.revision_tree(tree.last_revision()) bzrdir.BzrDir.open("mine").sprout("other") file('other/bloo', 'wb').write('two') othertree = WorkingTree.open('other') othertree.commit('blah', allow_pointless=False) file('mine/bloo', 'wb').write('three') tree.commit("blah", allow_pointless=False) merge_inner(tree.branch, othertree, base, this_tree=tree) return tree
def test_revert_merged_dir(self): """Reverting a merge that adds a directory deletes the directory""" source_tree = self.make_branch_and_tree('source') source_tree.commit('empty tree') target_tree = source_tree.bzrdir.sprout('target').open_workingtree() self.build_tree(['source/dir/', 'source/dir/contents']) source_tree.add(['dir', 'dir/contents'], ['dir-id', 'contents-id']) source_tree.commit('added dir') target_tree.lock_write() self.addCleanup(target_tree.unlock) merge.merge_inner(target_tree.branch, source_tree.basis_tree(), target_tree.basis_tree(), this_tree=target_tree) self.failUnlessExists('target/dir') self.failUnlessExists('target/dir/contents') target_tree.revert() self.failIfExists('target/dir/contents') self.failIfExists('target/dir')
def test_ignore_zero_merge_inner(self): # Test that merge_inner's ignore zero parameter is effective tree_a =self.make_branch_and_tree('a') tree_a.commit(message="hello") dir_b = tree_a.bzrdir.sprout('b') tree_b = dir_b.open_workingtree() tree_b.lock_write() self.addCleanup(tree_b.unlock) tree_a.commit(message="hello again") log = StringIO() merge_inner(tree_b.branch, tree_a, tree_b.basis_tree(), this_tree=tree_b, ignore_zero=True) log = self._get_log(keep_log_file=True) self.failUnless('All changes applied successfully.\n' not in log) tree_b.revert() merge_inner(tree_b.branch, tree_a, tree_b.basis_tree(), this_tree=tree_b, ignore_zero=False) log = self._get_log(keep_log_file=True) self.failUnless('All changes applied successfully.\n' in log)
def test_merge_inner_conflicts(self): tree_a = self.make_branch_and_tree('a') tree_a.set_conflicts(ConflictList([TextConflict('patha')])) merge_inner(tree_a.branch, tree_a, tree_a, this_tree=tree_a) self.assertEqual(1, len(tree_a.conflicts()))