89
89
class RemoteBzrDir(BzrDir, _RpcHelper):
90
90
"""Control directory on a remote server, accessed via bzr:// or similar."""
92
def __init__(self, transport, format, _client=None):
92
def __init__(self, transport, format, _client=None, _force_probe=False):
93
93
"""Construct a RemoteBzrDir.
95
95
:param _client: Private parameter for testing. Disables probing and the
99
99
# this object holds a delegated bzrdir that uses file-level operations
100
100
# to talk to the other side
101
101
self._real_bzrdir = None
102
self._has_working_tree = None
102
103
# 1-shot cache for the call pattern 'create_branch; open_branch' - see
103
104
# create_branch for details.
104
105
self._next_open_branch_result = None
108
109
self._client = client._SmartClient(medium)
110
111
self._client = _client
117
def _probe_bzrdir(self):
118
medium = self._client._medium
113
119
path = self._path_for_remote_call(self._client)
120
if medium._is_remote_before((2, 1)):
124
self._rpc_open_2_1(path)
126
except errors.UnknownSmartMethod:
127
medium._remember_remote_is_before((2, 1))
130
def _rpc_open_2_1(self, path):
131
response = self._call('BzrDir.open_2.1', path)
132
if response == ('no',):
133
raise errors.NotBranchError(path=self.root_transport.base)
134
elif response[0] == 'yes':
135
if response[1] == 'yes':
136
self._has_working_tree = True
137
elif response[1] == 'no':
138
self._has_working_tree = False
140
raise errors.UnexpectedSmartServerResponse(response)
142
raise errors.UnexpectedSmartServerResponse(response)
144
def _rpc_open(self, path):
114
145
response = self._call('BzrDir.open', path)
115
146
if response not in [('yes',), ('no',)]:
116
147
raise errors.UnexpectedSmartServerResponse(response)
117
148
if response == ('no',):
118
raise errors.NotBranchError(path=transport.base)
149
raise errors.NotBranchError(path=self.root_transport.base)
120
151
def _ensure_real(self):
121
152
"""Ensure that there is a _real_bzrdir set.
356
387
raise errors.NoRepositoryPresent(self)
389
def has_workingtree(self):
390
if self._has_working_tree is None:
392
self._has_working_tree = self._real_bzrdir.has_workingtree()
393
return self._has_working_tree
358
395
def open_workingtree(self, recommend_upgrade=True):
360
if self._real_bzrdir.has_workingtree():
396
if self.has_workingtree():
361
397
raise errors.NotLocalUrl(self.root_transport)
363
399
raise errors.NoWorkingTree(self.root_transport.base)