1
# Copyright (C) 2004, 2005, 2007 Canonical Ltd
1
# Copyright (C) 2006-2010 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
21
from bzrlib.branch import Branch, BzrBranchFormat5
22
from bzrlib.bzrdir import BzrDir
23
from bzrlib import errors
24
from bzrlib.memorytree import MemoryTree
25
from bzrlib.revision import NULL_REVISION
26
from bzrlib.tests.per_branch.test_branch import TestCaseWithBranch
29
class TestPull(TestCaseWithBranch):
28
from bzrlib.tests import per_branch
31
class TestPull(per_branch.TestCaseWithBranch):
31
33
def test_pull_convergence_simple(self):
32
34
# when revisions are pulled, the left-most accessible parents must
96
98
master_tree.branch.pull, other.branch, local = True)
97
99
self.assertEqual([rev1], master_tree.branch.revision_history())
99
def test_pull_raises_specific_error_on_master_connection_error(self):
100
master_tree = self.make_branch_and_tree('master')
101
checkout = master_tree.branch.create_checkout('checkout')
102
other = master_tree.branch.bzrdir.sprout('other').open_workingtree()
103
# move the branch out of the way on disk to cause a connection
105
os.rename('master', 'master_gone')
106
# try to pull, which should raise a BoundBranchConnectionFailure.
107
self.assertRaises(errors.BoundBranchConnectionFailure,
108
checkout.branch.pull, other.branch)
110
101
def test_pull_returns_result(self):
111
102
parent = self.make_branch_and_tree('parent')
112
103
parent.commit('1st post', rev_id='P1')
145
136
tree_a.branch.revision_history())
148
class TestPullHook(TestCaseWithBranch):
139
class TestPullHook(per_branch.TestCaseWithBranch):
151
142
self.hook_calls = []
152
TestCaseWithBranch.setUp(self)
143
super(TestPullHook, self).setUp()
154
145
def capture_post_pull_hook(self, result):
155
146
"""Capture post pull hook calls to self.hook_calls.
173
164
def test_post_pull_empty_history(self):
174
165
target = self.make_branch('target')
175
166
source = self.make_branch('source')
176
Branch.hooks.install_named_hook('post_pull',
177
self.capture_post_pull_hook, None)
167
branch.Branch.hooks.install_named_hook(
168
'post_pull', self.capture_post_pull_hook, None)
178
169
target.pull(source)
179
170
# with nothing there we should still get a notification, and
180
171
# have both branches locked at the notification time.
181
172
self.assertEqual([
182
('post_pull', source, None, target.base, 0, NULL_REVISION,
183
0, NULL_REVISION, True, None, True)
173
('post_pull', source, None, target.base, 0, revision.NULL_REVISION,
174
0, revision.NULL_REVISION, True, None, True)
199
190
# remotebranches can't be bound. Let's instead make a new local
200
191
# branch of the default type, which does allow binding.
201
192
# See https://bugs.launchpad.net/bzr/+bug/112020
202
local = BzrDir.create_branch_convenience('local2')
193
local = bzrdir.BzrDir.create_branch_convenience('local2')
203
194
local.bind(target)
204
195
source = self.make_branch('source')
205
Branch.hooks.install_named_hook('post_pull',
206
self.capture_post_pull_hook, None)
196
branch.Branch.hooks.install_named_hook(
197
'post_pull', self.capture_post_pull_hook, None)
207
198
local.pull(source)
208
199
# with nothing there we should still get a notification, and
209
200
# have both branches locked at the notification time.
210
201
self.assertEqual([
211
('post_pull', source, local.base, target.base, 0, NULL_REVISION,
212
0, NULL_REVISION, True, True, True)
202
('post_pull', source, local.base, target.base, 0,
203
revision.NULL_REVISION, 0, revision.NULL_REVISION,
220
212
rev1 = target.commit('rev 1')
222
214
sourcedir = target.bzrdir.clone(self.get_url('source'))
223
source = MemoryTree.create_on_branch(sourcedir.open_branch())
215
source = memorytree.MemoryTree.create_on_branch(sourcedir.open_branch())
224
216
rev2 = source.commit('rev 2')
225
Branch.hooks.install_named_hook('post_pull',
226
self.capture_post_pull_hook, None)
217
branch.Branch.hooks.install_named_hook(
218
'post_pull', self.capture_post_pull_hook, None)
227
219
target.branch.pull(source.branch)
228
220
# with nothing there we should still get a notification, and
229
221
# have both branches locked at the notification time.