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
145
147
tree_a.branch.revision_history())
148
class TestPullHook(TestCaseWithBranch):
150
class TestPullHook(per_branch.TestCaseWithBranch):
151
153
self.hook_calls = []
152
TestCaseWithBranch.setUp(self)
154
super(TestPullHook, self).setUp()
154
156
def capture_post_pull_hook(self, result):
155
157
"""Capture post pull hook calls to self.hook_calls.
173
175
def test_post_pull_empty_history(self):
174
176
target = self.make_branch('target')
175
177
source = self.make_branch('source')
176
Branch.hooks.install_named_hook('post_pull',
177
self.capture_post_pull_hook, None)
178
branch.Branch.hooks.install_named_hook(
179
'post_pull', self.capture_post_pull_hook, None)
178
180
target.pull(source)
179
181
# with nothing there we should still get a notification, and
180
182
# have both branches locked at the notification time.
181
183
self.assertEqual([
182
('post_pull', source, None, target.base, 0, NULL_REVISION,
183
0, NULL_REVISION, True, None, True)
184
('post_pull', source, None, target.base, 0, revision.NULL_REVISION,
185
0, revision.NULL_REVISION, True, None, True)
199
201
# remotebranches can't be bound. Let's instead make a new local
200
202
# branch of the default type, which does allow binding.
201
203
# See https://bugs.launchpad.net/bzr/+bug/112020
202
local = BzrDir.create_branch_convenience('local2')
204
local = bzrdir.BzrDir.create_branch_convenience('local2')
203
205
local.bind(target)
204
206
source = self.make_branch('source')
205
Branch.hooks.install_named_hook('post_pull',
206
self.capture_post_pull_hook, None)
207
branch.Branch.hooks.install_named_hook(
208
'post_pull', self.capture_post_pull_hook, None)
207
209
local.pull(source)
208
210
# with nothing there we should still get a notification, and
209
211
# have both branches locked at the notification time.
210
212
self.assertEqual([
211
('post_pull', source, local.base, target.base, 0, NULL_REVISION,
212
0, NULL_REVISION, True, True, True)
213
('post_pull', source, local.base, target.base, 0,
214
revision.NULL_REVISION, 0, revision.NULL_REVISION,
220
223
rev1 = target.commit('rev 1')
222
225
sourcedir = target.bzrdir.clone(self.get_url('source'))
223
source = MemoryTree.create_on_branch(sourcedir.open_branch())
226
source = memorytree.MemoryTree.create_on_branch(sourcedir.open_branch())
224
227
rev2 = source.commit('rev 2')
225
Branch.hooks.install_named_hook('post_pull',
226
self.capture_post_pull_hook, None)
228
branch.Branch.hooks.install_named_hook(
229
'post_pull', self.capture_post_pull_hook, None)
227
230
target.branch.pull(source.branch)
228
231
# with nothing there we should still get a notification, and
229
232
# have both branches locked at the notification time.