86
86
mine = self.make_from_branch_and_tree('mine')
87
87
p1 = mine.commit('1st post', allow_pointless=True)
89
target = self.sprout_to(mine.controldir, 'target').open_workingtree()
89
target = self.sprout_to(
90
mine.controldir, 'target').open_workingtree()
90
91
except errors.NoRoundtrippingSupport:
91
92
raise tests.TestNotApplicable(
92
93
'lossless push between %r and %r not supported' %
117
118
rev1 = checkout.commit('master')
120
other_bzrdir = self.sprout_from(master_tree.branch.controldir, 'other')
121
other_bzrdir = self.sprout_from(
122
master_tree.branch.controldir, 'other')
121
123
except errors.NoRoundtrippingSupport:
122
124
raise tests.TestNotApplicable(
123
125
'lossless push between %r and %r not supported' %
144
146
master_tree.controldir.destroy_branch()
145
147
# try to push, which should raise a BoundBranchConnectionFailure.
146
148
self.assertRaises(errors.BoundBranchConnectionFailure,
147
other.branch.push, checkout.branch)
149
other.branch.push, checkout.branch)
149
151
def test_push_uses_read_lock(self):
150
152
"""Push should only need a read lock on the source side."""
159
161
with source.branch.lock_read(), target.lock_write():
160
source.branch.push(target, stop_revision=source.last_revision())
163
target, stop_revision=source.last_revision())
161
164
except errors.NoRoundtrippingSupport:
162
165
raise tests.TestNotApplicable(
163
166
'lossless push between %r and %r not supported' %
176
179
with source.branch.lock_read(), target.lock_write():
177
source.branch.push(target, stop_revision=source.last_revision(), lossy=True)
181
target, stop_revision=source.last_revision(), lossy=True)
178
182
except errors.LossyPushToSameVCS:
179
183
raise tests.TestNotApplicable(
180
184
'push between branches of same format')
186
def test_between_colocated(self):
187
"""Pushing from one colocated branch to another doesn't change the active branch."""
188
source = self.make_from_branch_and_tree('source')
189
target = self.make_to_branch('target')
191
self.build_tree(['source/a'])
193
revid1 = source.commit('a')
195
self.build_tree(['source/b'])
197
revid2 = source.commit('b')
199
source_colo = source.controldir.create_branch('colo')
200
source_colo.generate_revision_history(revid1)
202
source_colo.push(target)
203
except errors.NoRoundtrippingSupport:
204
raise tests.TestNotApplicable(
205
'push between branches of different format')
206
self.assertEqual(source_colo.last_revision(), revid1)
207
self.assertEqual(source.last_revision(), revid2)
208
self.assertEqual(target.last_revision(), revid1)
182
210
def test_push_within_repository(self):
183
211
"""Push from one branch to another inside the same repository."""
202
230
if self.vfs_transport_factory is test_server.LocalURLServer:
203
231
# the branch is colocated on disk, we cannot create a checkout.
204
232
# hopefully callers will expect this.
205
local_controldir = controldir.ControlDir.open(self.get_vfs_only_url('repo/tree'))
233
local_controldir = controldir.ControlDir.open(
234
self.get_vfs_only_url('repo/tree'))
206
235
tree = local_controldir.create_workingtree()
208
237
tree = a_branch.create_checkout('repo/tree', lightweight=True)
270
299
('add', ('filename', None, 'file', b'content\n'))])
271
300
revid2 = builder.build_snapshot([revid1], [])
272
301
revid3 = builder.build_snapshot([revid2],
273
[('modify', ('filename', b'new-content\n'))])
302
[('modify', ('filename', b'new-content\n'))])
274
303
builder.finish_series()
275
304
trunk = builder.get_branch()
276
305
# Sprout rev-1 to "trunk", so that we can stack on it.
336
365
[b'Repository.insert_stream_1.19', b'Repository.insert_stream_1.19',
337
366
b'Branch.set_last_revision_info', b'get', b'Branch.unlock'])
338
367
self.assertThat(calls_after_insert_stream,
339
MatchesAny(bzr_core_trace, bzr_loom_trace))
368
MatchesAny(bzr_core_trace, bzr_loom_trace))
341
370
def disableOptimisticGetParentMap(self):
342
371
# Tweak some class variables to stop remote get_parent_map calls asking
344
373
self.overrideAttr(vf_repository.InterVersionedFileRepository,
345
374
'_walk_to_common_revisions_batch_size', 1)
346
375
self.overrideAttr(SmartServerRepositoryGetParentMap,
347
'no_extra_results', True)
376
'no_extra_results', True)
350
379
class TestPushHook(TestCaseWithInterBranch):