~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Martin Pool
  • Date: 2007-02-15 01:23:29 UTC
  • mfrom: (2284 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2309.
  • Revision ID: mbp@sourcefrog.net-20070215012329-blt2xfhup97r6w8h
merge up from bzr.dev to get metadir changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
import os
20
20
 
21
21
from bzrlib.branch import Branch
22
 
from bzrlib.osutils import abspath, realpath
23
 
from bzrlib.tests import TestCaseWithTransport
24
 
 
25
 
 
26
 
class TestPull(TestCaseWithTransport):
 
22
from bzrlib import errors
 
23
from bzrlib.memorytree import MemoryTree
 
24
from bzrlib.revision import NULL_REVISION
 
25
from bzrlib.tests.branch_implementations.test_branch import TestCaseWithBranch
 
26
 
 
27
 
 
28
class TestPull(TestCaseWithBranch):
27
29
 
28
30
    def test_pull_convergence_simple(self):
29
31
        # when revisions are pulled, the left-most accessible parents must 
53
55
        parent.commit('merge other', rev_id='P2')
54
56
        mine.pull(parent.branch)
55
57
        self.assertEqual(['P1', 'P2'], mine.branch.revision_history())
 
58
 
 
59
    def test_pull_updates_checkout_and_master(self):
 
60
        """Pulling into a checkout updates the checkout and the master branch"""
 
61
        master_tree = self.make_branch_and_tree('master')
 
62
        rev1 = master_tree.commit('master')
 
63
        checkout = master_tree.branch.create_checkout('checkout')
 
64
 
 
65
        other = master_tree.branch.bzrdir.sprout('other').open_workingtree()
 
66
        rev2 = other.commit('other commit')
 
67
        # now pull, which should update both checkout and master.
 
68
        checkout.branch.pull(other.branch)
 
69
        self.assertEqual([rev1, rev2], checkout.branch.revision_history())
 
70
        self.assertEqual([rev1, rev2], master_tree.branch.revision_history())
 
71
 
 
72
    def test_pull_raises_specific_error_on_master_connection_error(self):
 
73
        master_tree = self.make_branch_and_tree('master')
 
74
        checkout = master_tree.branch.create_checkout('checkout')
 
75
        other = master_tree.branch.bzrdir.sprout('other').open_workingtree()
 
76
        # move the branch out of the way on disk to cause a connection
 
77
        # error.
 
78
        os.rename('master', 'master_gone')
 
79
        # try to pull, which should raise a BoundBranchConnectionFailure.
 
80
        self.assertRaises(errors.BoundBranchConnectionFailure,
 
81
                checkout.branch.pull, other.branch)
 
82
 
 
83
 
 
84
class TestPullHook(TestCaseWithBranch):
 
85
 
 
86
    def setUp(self):
 
87
        self.hook_calls = []
 
88
        TestCaseWithBranch.setUp(self)
 
89
 
 
90
    def capture_post_pull_hook(self, source, local, master, old_revno,
 
91
        old_revid, new_revno, new_revid):
 
92
        """Capture post pull hook calls to self.hook_calls.
 
93
        
 
94
        The call is logged, as is some state of the two branches.
 
95
        """
 
96
        if local:
 
97
            local_locked = local.is_locked()
 
98
            local_base = local.base
 
99
        else:
 
100
            local_locked = None
 
101
            local_base = None
 
102
        self.hook_calls.append(
 
103
            ('post_pull', source, local_base, master.base, old_revno, old_revid,
 
104
             new_revno, new_revid, source.is_locked(), local_locked,
 
105
             master.is_locked()))
 
106
 
 
107
    def test_post_pull_empty_history(self):
 
108
        target = self.make_branch('target')
 
109
        source = self.make_branch('source')
 
110
        Branch.hooks.install_hook('post_pull', self.capture_post_pull_hook)
 
111
        target.pull(source)
 
112
        # with nothing there we should still get a notification, and
 
113
        # have both branches locked at the notification time.
 
114
        self.assertEqual([
 
115
            ('post_pull', source, None, target.base, 0, NULL_REVISION,
 
116
             0, NULL_REVISION, True, None, True)
 
117
            ],
 
118
            self.hook_calls)
 
119
 
 
120
    def test_post_pull_bound_branch(self):
 
121
        # pulling to a bound branch should pass in the master branch to the
 
122
        # hook, allowing the correct number of emails to be sent, while still
 
123
        # allowing hooks that want to modify the target to do so to both 
 
124
        # instances.
 
125
        target = self.make_branch('target')
 
126
        local = self.make_branch('local')
 
127
        try:
 
128
            local.bind(target)
 
129
        except errors.UpgradeRequired:
 
130
            # cant bind this format, the test is irrelevant.
 
131
            return
 
132
        source = self.make_branch('source')
 
133
        Branch.hooks.install_hook('post_pull', self.capture_post_pull_hook)
 
134
        local.pull(source)
 
135
        # with nothing there we should still get a notification, and
 
136
        # have both branches locked at the notification time.
 
137
        self.assertEqual([
 
138
            ('post_pull', source, local.base, target.base, 0, NULL_REVISION,
 
139
             0, NULL_REVISION, True, True, True)
 
140
            ],
 
141
            self.hook_calls)
 
142
 
 
143
    def test_post_pull_nonempty_history(self):
 
144
        target = self.make_branch_and_memory_tree('target')
 
145
        target.lock_write()
 
146
        target.add('')
 
147
        rev1 = target.commit('rev 1')
 
148
        target.unlock()
 
149
        sourcedir = target.bzrdir.clone(self.get_url('source'))
 
150
        source = MemoryTree.create_on_branch(sourcedir.open_branch())
 
151
        rev2 = source.commit('rev 2')
 
152
        Branch.hooks.install_hook('post_pull', self.capture_post_pull_hook)
 
153
        target.branch.pull(source.branch)
 
154
        # with nothing there we should still get a notification, and
 
155
        # have both branches locked at the notification time.
 
156
        self.assertEqual([
 
157
            ('post_pull', source.branch, None, target.branch.base, 1, rev1,
 
158
             2, rev2, True, None, True)
 
159
            ],
 
160
            self.hook_calls)