15
15
# along with this program; if not, write to the Free Software
16
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
from cStringIO import StringIO
19
from bzrlib import tests
20
from bzrlib.revision import NULL_REVISION
20
21
from bzrlib.tests import per_workingtree
30
31
tree_b = self.make_branch_and_tree('to')
31
32
return tree, tree_b
34
def test_pull_null(self):
35
tree_a, tree_b = self.get_pullable_trees()
36
root_id = tree_a.get_root_id()
37
tree_a.pull(tree_b.branch, stop_revision=NULL_REVISION, overwrite=True)
38
self.assertEquals(root_id, tree_a.get_root_id())
33
40
def test_pull(self):
34
41
tree_a, tree_b = self.get_pullable_trees()
35
42
tree_b.pull(tree_a.branch)
36
self.failUnless(tree_b.branch.repository.has_revision('A'))
43
self.assertTrue(tree_b.branch.repository.has_revision('A'))
37
44
self.assertEqual(['A'], tree_b.get_parent_ids())
39
46
def test_pull_overwrites(self):
40
47
tree_a, tree_b = self.get_pullable_trees()
41
48
tree_b.commit('foo', rev_id='B')
42
self.assertEqual(['B'], tree_b.branch.revision_history())
49
self.assertEqual('B', tree_b.branch.last_revision())
43
50
tree_b.pull(tree_a.branch, overwrite=True)
44
self.failUnless(tree_b.branch.repository.has_revision('A'))
45
self.failUnless(tree_b.branch.repository.has_revision('B'))
51
self.assertTrue(tree_b.branch.repository.has_revision('A'))
52
self.assertTrue(tree_b.branch.repository.has_revision('B'))
46
53
self.assertEqual(['A'], tree_b.get_parent_ids())
48
55
def test_pull_merges_tree_content(self):
62
69
tree.commit('second')
63
70
to_tree.pull(tree.branch)
64
71
self.assertEqual('second_root_id', to_tree.get_root_id())
74
class TestPullWithOrphans(per_workingtree.TestCaseWithWorkingTree):
76
def make_branch_deleting_dir(self, relpath=None):
79
builder = self.make_branch_builder(relpath)
80
builder.start_series()
82
# Create an empty trunk
83
builder.build_snapshot('1', None, [
84
('add', ('', 'root-id', 'directory', ''))])
85
builder.build_snapshot('2', ['1'], [
86
('add', ('dir', 'dir-id', 'directory', '')),
87
('add', ('file', 'file-id', 'file', 'trunk content\n')),])
88
builder.build_snapshot('3', ['2'], [
89
('unversion', 'dir-id'),])
90
builder.finish_series()
91
return builder.get_branch()
93
def test_pull_orphans(self):
94
if not self.workingtree_format.missing_parent_conflicts:
95
raise tests.TestSkipped(
96
'%r does not support missing parent conflicts' %
97
self.workingtree_format)
98
trunk = self.make_branch_deleting_dir('trunk')
99
work = trunk.bzrdir.sprout('work', revision_id='2').open_workingtree()
100
work.branch.get_config().set_user_option(
101
'bzr.transform.orphan_policy', 'move')
102
# Add some unversioned files in dir
103
self.build_tree(['work/dir/foo',
105
'work/dir/subdir/foo'])
107
self.assertLength(0, work.conflicts())
108
# The directory removal should succeed
109
self.assertPathDoesNotExist('work/dir')