~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
5409.1.1 by Vincent Ladeuil
Cleanup imports (most of them were useless).
18
5409.1.6 by Vincent Ladeuil
Add failing tests for bug #323111.
19
from bzrlib import tests
6243.1.1 by Jelmer Vernooij
Fix WorkingTree.pull(stop_revision='null:', overwrite=True).
20
from bzrlib.revision import NULL_REVISION
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
6243.1.1 by Jelmer Vernooij
Fix WorkingTree.pull(stop_revision='null:', overwrite=True).
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())
39
1563.1.4 by Robert Collins
Fix 'bzr pull' on metadir trees.
40
    def test_pull(self):
41
        tree_a, tree_b = self.get_pullable_trees()
42
        tree_b.pull(tree_a.branch)
5784.1.1 by Martin Pool
Stop using failIf, failUnless, etc
43
        self.assertTrue(tree_b.branch.repository.has_revision('A'))
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
44
        self.assertEqual(['A'], tree_b.get_parent_ids())
1563.1.4 by Robert Collins
Fix 'bzr pull' on metadir trees.
45
46
    def test_pull_overwrites(self):
47
        tree_a, tree_b = self.get_pullable_trees()
48
        tree_b.commit('foo', rev_id='B')
6165.4.7 by Jelmer Vernooij
More fixes.
49
        self.assertEqual('B', tree_b.branch.last_revision())
1563.1.4 by Robert Collins
Fix 'bzr pull' on metadir trees.
50
        tree_b.pull(tree_a.branch, overwrite=True)
5784.1.1 by Martin Pool
Stop using failIf, failUnless, etc
51
        self.assertTrue(tree_b.branch.repository.has_revision('A'))
52
        self.assertTrue(tree_b.branch.repository.has_revision('B'))
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
53
        self.assertEqual(['A'], tree_b.get_parent_ids())
1563.1.4 by Robert Collins
Fix 'bzr pull' on metadir trees.
54
55
    def test_pull_merges_tree_content(self):
56
        tree_a, tree_b = self.get_pullable_trees()
57
        tree_b.pull(tree_a.branch)
58
        self.assertFileEqual('contents of from/file\n', 'to/file')
59
4634.123.2 by John Arbash Meinel
pull also is broken wrt root-id changes.
60
    def test_pull_changes_root_id(self):
61
        tree = self.make_branch_and_tree('from')
62
        tree.set_root_id('first_root_id')
63
        self.build_tree(['from/file'])
64
        tree.add(['file'])
65
        tree.commit('first')
66
        to_tree = tree.bzrdir.sprout('to').open_workingtree()
67
        self.assertEqual('first_root_id', to_tree.get_root_id())
68
        tree.set_root_id('second_root_id')
69
        tree.commit('second')
70
        to_tree.pull(tree.branch)
71
        self.assertEqual('second_root_id', to_tree.get_root_id())
5409.1.6 by Vincent Ladeuil
Add failing tests for bug #323111.
72
73
74
class TestPullWithOrphans(per_workingtree.TestCaseWithWorkingTree):
75
76
    def make_branch_deleting_dir(self, relpath=None):
77
        if relpath is None:
78
            relpath = 'trunk'
79
        builder = self.make_branch_builder(relpath)
80
        builder.start_series()
81
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()
92
93
    def test_pull_orphans(self):
5661.1.1 by Jelmer Vernooij
Add 'WorkingTreeFormat.missing_parent_conflicts' flag to use in tests.
94
        if not self.workingtree_format.missing_parent_conflicts:
5409.1.6 by Vincent Ladeuil
Add failing tests for bug #323111.
95
            raise tests.TestSkipped(
5661.1.1 by Jelmer Vernooij
Add 'WorkingTreeFormat.missing_parent_conflicts' flag to use in tests.
96
                '%r does not support missing parent conflicts' %
97
                    self.workingtree_format)
5409.1.6 by Vincent Ladeuil
Add failing tests for bug #323111.
98
        trunk = self.make_branch_deleting_dir('trunk')
99
        work = trunk.bzrdir.sprout('work', revision_id='2').open_workingtree()
6449.3.2 by Jelmer Vernooij
Use config stack in tests, too.
100
        work.branch.get_config_stack().set(
5409.1.24 by Vincent Ladeuil
Rename bzrlib.transform.orphan_policy to bzr.transform.orphan_policy.
101
            'bzr.transform.orphan_policy', 'move')
5409.7.2 by Vincent Ladeuil
Add NEWS entry, a missing test and some cleanup.
102
        # Add some unversioned files in dir
103
        self.build_tree(['work/dir/foo',
104
                         'work/dir/subdir/',
105
                         'work/dir/subdir/foo'])
5409.1.6 by Vincent Ladeuil
Add failing tests for bug #323111.
106
        work.pull(trunk)
107
        self.assertLength(0, work.conflicts())
5409.7.2 by Vincent Ladeuil
Add NEWS entry, a missing test and some cleanup.
108
        # The directory removal should succeed
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
109
        self.assertPathDoesNotExist('work/dir')