1
# Copyright (C) 2005 Robey Pointer <robey@lag.net>, Canonical Ltd
1
# Copyright (C) 2005, 2006, 2007, 2009, 2010 Robey Pointer <robey@lag.net>, 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
23
22
from bzrlib import (
26
from bzrlib.branch import Branch
27
from bzrlib.bzrdir import (BzrDir,
32
import bzrlib.errors as errors
33
from bzrlib.tests import TestSkipped
34
from bzrlib.tests import TestCaseWithTransport
35
from bzrlib.transport.local import LocalURLServer
36
from bzrlib.transport.memory import MemoryServer
39
class BoundSFTPBranch(TestCaseWithTransport):
28
from bzrlib.tests import test_server
29
from bzrlib.transport import memory
32
class BoundSFTPBranch(tests.TestCaseWithTransport):
42
TestCaseWithTransport.setUp(self)
43
self.vfs_transport_factory = MemoryServer
44
if self.transport_server is LocalURLServer:
35
tests.TestCaseWithTransport.setUp(self)
36
self.vfs_transport_factory = memory.MemoryServer
37
if self.transport_server is test_server.LocalURLServer:
45
38
self.transport_server = None
47
40
def create_branches(self):
48
41
self.build_tree(['base/', 'base/a', 'base/b'])
49
42
format = bzrdir.format_registry.make_bzrdir('knit')
51
wt_base = BzrDir.create_standalone_workingtree(
44
wt_base = bzrdir.BzrDir.create_standalone_workingtree(
52
45
self.get_url('base'), format=format)
53
46
except errors.NotLocalUrl:
54
raise TestSkipped('Not a local URL')
47
raise tests.TestSkipped('Not a local URL')
56
49
b_base = wt_base.branch
60
53
wt_base.commit('first', rev_id='r@b-1')
62
55
wt_child = b_base.bzrdir.sprout('child').open_workingtree()
63
self.sftp_base = Branch.open(self.get_url('base'))
56
self.sftp_base = branch.Branch.open(self.get_url('base'))
64
57
wt_child.branch.bind(self.sftp_base)
65
58
# check the branch histories are ready for using in tests.
66
59
self.assertEqual(['r@b-1'], b_base.revision_history())
70
63
def test_simple_binding(self):
71
64
self.build_tree(['base/', 'base/a', 'base/b', 'child/'])
73
wt_base = BzrDir.create_standalone_workingtree(self.get_url('base'))
66
wt_base = bzrdir.BzrDir.create_standalone_workingtree(
74
68
except errors.NotLocalUrl:
75
raise TestSkipped('Not a local URL')
69
raise tests.TestSkipped('Not a local URL')
83
77
# may not be bindable-from, and we want to test the side effects etc
85
79
format = bzrdir.format_registry.make_bzrdir('knit')
86
b_child = BzrDir.create_branch_convenience('child', format=format)
80
b_child = bzrdir.BzrDir.create_branch_convenience(
81
'child', format=format)
87
82
self.assertEqual(None, b_child.get_bound_location())
88
83
self.assertEqual(None, b_child.get_master_branch())
90
sftp_b_base = Branch.open(self.get_url('base'))
85
sftp_b_base = branch.Branch.open(self.get_url('base'))
91
86
b_child.bind(sftp_b_base)
92
87
self.assertEqual(sftp_b_base.base, b_child.get_bound_location())
93
88
# the bind must not have given b_child history:
125
120
self.assertRaises(errors.BoundBranchOutOfDate,
126
121
wt_child.commit, 'child', rev_id='r@c-2')
128
sftp_b_base = Branch.open(self.get_url('base'))
123
sftp_b_base = branch.Branch.open(self.get_url('base'))
130
125
# This is all that cmd_update does
131
126
wt_child.pull(sftp_b_base, overwrite=False)
170
165
self.assertEqual(['r@b-1', 'r@c-2'], wt_child.branch.revision_history())
171
166
self.assertEqual(['r@b-1', 'r@b-2'], b_base.revision_history())
173
sftp_b_base = Branch.open(self.get_url('base'))
168
sftp_b_base = branch.Branch.open(self.get_url('base'))
174
169
self.assertRaises(errors.DivergedBranches,
175
170
wt_child.branch.bind, sftp_b_base)
182
177
b_base.bzrdir.sprout('newbase')
184
sftp_b_base = Branch.open(self.get_url('base'))
185
sftp_b_newbase = Branch.open(self.get_url('newbase'))
179
sftp_b_base = branch.Branch.open(self.get_url('base'))
180
sftp_b_newbase = branch.Branch.open(self.get_url('newbase'))
187
182
sftp_b_base.bind(sftp_b_newbase)
208
203
b_base.bzrdir.open_workingtree().commit('base', rev_id='r@b-2')
209
204
self.assertEqual(['r@b-1', 'r@b-2'], b_base.revision_history())
211
sftp_b_base = Branch.open(self.get_url('base'))
206
sftp_b_base = branch.Branch.open(self.get_url('base'))
213
208
self.assertRaises(errors.DivergedBranches,
214
209
wt_child.branch.bind, sftp_b_base)
236
231
self.assertEqual(['r@b-1', 'r@b-2'], b_base.revision_history())
237
232
self.assertEqual(['r@b-1'], wt_child.branch.revision_history())
239
sftp_b_base = Branch.open(self.get_url('base'))
234
sftp_b_base = branch.Branch.open(self.get_url('base'))
240
235
wt_child.branch.bind(sftp_b_base)
242
237
self.assertEqual(['r@b-1'], wt_child.branch.revision_history())
265
260
self.assertEqual(['r@b-1', 'r@c-2'], wt_child.branch.revision_history())
266
261
self.assertEqual(['r@b-1'], b_base.revision_history())
268
sftp_b_base = Branch.open(self.get_url('base'))
263
sftp_b_base = branch.Branch.open(self.get_url('base'))
269
264
wt_child.branch.bind(sftp_b_base)
271
266
self.assertEqual(['r@b-1'], b_base.revision_history())