~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/per_workingtree/test_pull.py

  • Committer: Patch Queue Manager
  • Date: 2016-04-21 04:10:52 UTC
  • mfrom: (6616.1.1 fix-en-user-guide)
  • Revision ID: pqm@pqm.ubuntu.com-20160421041052-clcye7ns1qcl2n7w
(richard-wilbur) Ensure build of English use guide always uses English text
 even when user's locale specifies a different language. (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006, 2007, 2009, 2010 Canonical Ltd
 
1
# Copyright (C) 2006, 2007, 2009-2012, 2016 Canonical Ltd
2
2
# Authors:  Robert Collins <robert.collins@canonical.com>
3
3
#
4
4
# This program is free software; you can redistribute it and/or modify
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
17
17
 
18
 
from cStringIO import StringIO
19
 
import os
20
 
 
21
 
from bzrlib import errors
22
 
from bzrlib.errors import NotBranchError, NotVersionedError
23
 
from bzrlib.osutils import basename
24
 
from bzrlib.tests.per_workingtree import TestCaseWithWorkingTree
25
 
from bzrlib.trace import mutter
26
 
 
27
 
 
28
 
class TestPull(TestCaseWithWorkingTree):
 
18
 
 
19
from bzrlib import tests
 
20
from bzrlib.revision import NULL_REVISION
 
21
from bzrlib.tests import per_workingtree
 
22
 
 
23
 
 
24
class TestPull(per_workingtree.TestCaseWithWorkingTree):
29
25
 
30
26
    def get_pullable_trees(self):
31
27
        self.build_tree(['from/', 'from/file', 'to/'])
35
31
        tree_b = self.make_branch_and_tree('to')
36
32
        return tree, tree_b
37
33
 
 
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.assertEqual(root_id, tree_a.get_root_id())
 
39
 
38
40
    def test_pull(self):
39
41
        tree_a, tree_b = self.get_pullable_trees()
40
42
        tree_b.pull(tree_a.branch)
41
 
        self.failUnless(tree_b.branch.repository.has_revision('A'))
 
43
        self.assertTrue(tree_b.branch.repository.has_revision('A'))
42
44
        self.assertEqual(['A'], tree_b.get_parent_ids())
43
45
 
44
46
    def test_pull_overwrites(self):
45
47
        tree_a, tree_b = self.get_pullable_trees()
46
48
        tree_b.commit('foo', rev_id='B')
47
 
        self.assertEqual(['B'], tree_b.branch.revision_history())
 
49
        self.assertEqual('B', tree_b.branch.last_revision())
48
50
        tree_b.pull(tree_a.branch, overwrite=True)
49
 
        self.failUnless(tree_b.branch.repository.has_revision('A'))
50
 
        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'))
51
53
        self.assertEqual(['A'], tree_b.get_parent_ids())
52
54
 
53
55
    def test_pull_merges_tree_content(self):
67
69
        tree.commit('second')
68
70
        to_tree.pull(tree.branch)
69
71
        self.assertEqual('second_root_id', to_tree.get_root_id())
 
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):
 
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_stack().set(
 
101
            'bzr.transform.orphan_policy', 'move')
 
102
        # Add some unversioned files in dir
 
103
        self.build_tree(['work/dir/foo',
 
104
                         'work/dir/subdir/',
 
105
                         'work/dir/subdir/foo'])
 
106
        work.pull(trunk)
 
107
        self.assertLength(0, work.conflicts())
 
108
        # The directory removal should succeed
 
109
        self.assertPathDoesNotExist('work/dir')