~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
20
from bzrlib.tests import per_workingtree
21
22
23
class TestPull(per_workingtree.TestCaseWithWorkingTree):
1563.1.4 by Robert Collins
Fix 'bzr pull' on metadir trees.
24
25
    def get_pullable_trees(self):
26
        self.build_tree(['from/', 'from/file', 'to/'])
27
        tree = self.make_branch_and_tree('from')
28
        tree.add('file')
29
        tree.commit('foo', rev_id='A')
30
        tree_b = self.make_branch_and_tree('to')
31
        return tree, tree_b
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
32
1563.1.4 by Robert Collins
Fix 'bzr pull' on metadir trees.
33
    def test_pull(self):
34
        tree_a, tree_b = self.get_pullable_trees()
35
        tree_b.pull(tree_a.branch)
36
        self.failUnless(tree_b.branch.repository.has_revision('A'))
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
37
        self.assertEqual(['A'], tree_b.get_parent_ids())
1563.1.4 by Robert Collins
Fix 'bzr pull' on metadir trees.
38
39
    def test_pull_overwrites(self):
40
        tree_a, tree_b = self.get_pullable_trees()
41
        tree_b.commit('foo', rev_id='B')
42
        self.assertEqual(['B'], tree_b.branch.revision_history())
43
        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'))
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
46
        self.assertEqual(['A'], tree_b.get_parent_ids())
1563.1.4 by Robert Collins
Fix 'bzr pull' on metadir trees.
47
48
    def test_pull_merges_tree_content(self):
49
        tree_a, tree_b = self.get_pullable_trees()
50
        tree_b.pull(tree_a.branch)
51
        self.assertFileEqual('contents of from/file\n', 'to/file')
52
4634.123.2 by John Arbash Meinel
pull also is broken wrt root-id changes.
53
    def test_pull_changes_root_id(self):
54
        tree = self.make_branch_and_tree('from')
55
        tree.set_root_id('first_root_id')
56
        self.build_tree(['from/file'])
57
        tree.add(['file'])
58
        tree.commit('first')
59
        to_tree = tree.bzrdir.sprout('to').open_workingtree()
60
        self.assertEqual('first_root_id', to_tree.get_root_id())
61
        tree.set_root_id('second_root_id')
62
        tree.commit('second')
63
        to_tree.pull(tree.branch)
64
        self.assertEqual('second_root_id', to_tree.get_root_id())