~bzr-pqm/bzr/bzr.dev

4634.123.2 by John Arbash Meinel
pull also is broken wrt root-id changes.
1
# Copyright (C) 2006, 2007, 2009, 2010 Canonical Ltd
1563.1.4 by Robert Collins
Fix 'bzr pull' on metadir trees.
2
# Authors:  Robert Collins <robert.collins@canonical.com>
3
#
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
8
#
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
4183.7.1 by Sabin Iacob
update FSF mailing address
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1563.1.4 by Robert Collins
Fix 'bzr pull' on metadir trees.
17
18
from cStringIO import StringIO
5409.1.1 by Vincent Ladeuil
Cleanup imports (most of them were useless).
19
5409.1.6 by Vincent Ladeuil
Add failing tests for bug #323111.
20
from bzrlib import tests
5409.1.1 by Vincent Ladeuil
Cleanup imports (most of them were useless).
21
from bzrlib.tests import per_workingtree
22
23
24
class TestPull(per_workingtree.TestCaseWithWorkingTree):
1563.1.4 by Robert Collins
Fix 'bzr pull' on metadir trees.
25
26
    def get_pullable_trees(self):
27
        self.build_tree(['from/', 'from/file', 'to/'])
28
        tree = self.make_branch_and_tree('from')
29
        tree.add('file')
30
        tree.commit('foo', rev_id='A')
31
        tree_b = self.make_branch_and_tree('to')
32
        return tree, tree_b
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
33
1563.1.4 by Robert Collins
Fix 'bzr pull' on metadir trees.
34
    def test_pull(self):
35
        tree_a, tree_b = self.get_pullable_trees()
36
        tree_b.pull(tree_a.branch)
37
        self.failUnless(tree_b.branch.repository.has_revision('A'))
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
38
        self.assertEqual(['A'], tree_b.get_parent_ids())
1563.1.4 by Robert Collins
Fix 'bzr pull' on metadir trees.
39
40
    def test_pull_overwrites(self):
41
        tree_a, tree_b = self.get_pullable_trees()
42
        tree_b.commit('foo', rev_id='B')
43
        self.assertEqual(['B'], tree_b.branch.revision_history())
44
        tree_b.pull(tree_a.branch, overwrite=True)
45
        self.failUnless(tree_b.branch.repository.has_revision('A'))
46
        self.failUnless(tree_b.branch.repository.has_revision('B'))
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
47
        self.assertEqual(['A'], tree_b.get_parent_ids())
1563.1.4 by Robert Collins
Fix 'bzr pull' on metadir trees.
48
49
    def test_pull_merges_tree_content(self):
50
        tree_a, tree_b = self.get_pullable_trees()
51
        tree_b.pull(tree_a.branch)
52
        self.assertFileEqual('contents of from/file\n', 'to/file')
53
4634.123.2 by John Arbash Meinel
pull also is broken wrt root-id changes.
54
    def test_pull_changes_root_id(self):
55
        tree = self.make_branch_and_tree('from')
56
        tree.set_root_id('first_root_id')
57
        self.build_tree(['from/file'])
58
        tree.add(['file'])
59
        tree.commit('first')
60
        to_tree = tree.bzrdir.sprout('to').open_workingtree()
61
        self.assertEqual('first_root_id', to_tree.get_root_id())
62
        tree.set_root_id('second_root_id')
63
        tree.commit('second')
64
        to_tree.pull(tree.branch)
65
        self.assertEqual('second_root_id', to_tree.get_root_id())
5409.1.6 by Vincent Ladeuil
Add failing tests for bug #323111.
66
67
68
class TestPullWithOrphans(per_workingtree.TestCaseWithWorkingTree):
69
70
    def make_branch_deleting_dir(self, relpath=None):
71
        if relpath is None:
72
            relpath = 'trunk'
73
        builder = self.make_branch_builder(relpath)
74
        builder.start_series()
75
76
        # Create an empty trunk
77
        builder.build_snapshot('1', None, [
78
                ('add', ('', 'root-id', 'directory', ''))])
79
        builder.build_snapshot('2', ['1'], [
80
                ('add', ('dir', 'dir-id', 'directory', '')),
81
                ('add', ('file', 'file-id', 'file', 'trunk content\n')),])
82
        builder.build_snapshot('3', ['2'], [
83
                ('unversion', 'dir-id'),])
84
        builder.finish_series()
85
        return builder.get_branch()
86
87
    def test_pull_orphans(self):
88
        from bzrlib import workingtree
89
        if isinstance(self.workingtree_format, workingtree.WorkingTreeFormat2):
90
            raise tests.TestSkipped(
91
                'WorkingTreeFormat2 does not support missing parent conflicts')
92
        trunk = self.make_branch_deleting_dir('trunk')
93
        work = trunk.bzrdir.sprout('work', revision_id='2').open_workingtree()
5409.1.20 by Vincent Ladeuil
Revert to 'conflict' being the default orphaning policy and fix fallouts.
94
        work.branch.get_config().set_user_option(
5409.1.24 by Vincent Ladeuil
Rename bzrlib.transform.orphan_policy to bzr.transform.orphan_policy.
95
            'bzr.transform.orphan_policy', 'move')
5409.7.2 by Vincent Ladeuil
Add NEWS entry, a missing test and some cleanup.
96
        # Add some unversioned files in dir
97
        self.build_tree(['work/dir/foo',
98
                         'work/dir/subdir/',
99
                         'work/dir/subdir/foo'])
5409.1.6 by Vincent Ladeuil
Add failing tests for bug #323111.
100
        work.pull(trunk)
101
        self.assertLength(0, work.conflicts())
5409.7.2 by Vincent Ladeuil
Add NEWS entry, a missing test and some cleanup.
102
        # The directory removal should succeed
103
        self.failIfExists('work/dir')