1
# Copyright (C) 2007-2010 Canonical Ltd
1
# Copyright (C) 2007-2011 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
57
53
mine.merge_from_branch(other.branch)
58
54
mine.commit('merge my change', rev_id='P2')
59
55
result = mine.branch.push(other.branch)
60
self.assertEqual(['P1', 'P2'], other.branch.revision_history())
56
self.assertEqual('P2', other.branch.last_revision())
61
57
# result object contains some structured data
62
58
self.assertEqual(result.old_revid, 'M1')
63
59
self.assertEqual(result.new_revid, 'P2')
82
78
mine.merge_from_branch(other.branch)
83
79
mine.commit('merge other', rev_id='P2')
84
80
mine.branch.push(target.branch)
85
self.assertEqual(['P1', 'P2'], target.branch.revision_history())
81
self.assertEqual('P2', target.branch.last_revision())
87
83
def test_push_to_checkout_updates_master(self):
88
84
"""Pushing into a checkout updates the checkout and the master branch"""
99
95
rev2 = other.commit('other commit')
100
96
# now push, which should update both checkout and master.
101
97
other.branch.push(checkout.branch)
102
self.assertEqual([rev1, rev2], checkout.branch.revision_history())
103
self.assertEqual([rev1, rev2], master_tree.branch.revision_history())
98
self.assertEqual(rev2, checkout.branch.last_revision())
99
self.assertEqual(rev2, master_tree.branch.last_revision())
105
101
def test_push_raises_specific_error_on_master_connection_error(self):
106
102
master_tree = self.make_branch_and_tree('master')
118
114
self.assertRaises(errors.BoundBranchConnectionFailure,
119
115
other.branch.push, checkout.branch)
117
def test_push_new_tag_to_bound_branch(self):
118
master = self.make_branch('master')
119
bound = self.make_branch('bound')
122
except errors.UpgradeRequired:
123
raise tests.TestNotApplicable(
124
'Format does not support bound branches')
125
other = bound.bzrdir.sprout('other').open_branch()
127
other.tags.set_tag('new-tag', 'some-rev')
128
except errors.TagsNotSupported:
129
raise tests.TestNotApplicable('Format does not support tags')
131
self.assertEqual({'new-tag': 'some-rev'}, bound.tags.get_tag_dict())
132
self.assertEqual({'new-tag': 'some-rev'}, master.tags.get_tag_dict())
121
134
def test_push_uses_read_lock(self):
122
135
"""Push should only need a read lock on the source side."""
123
136
source = self.make_branch_and_tree('source')
144
157
except (errors.IncompatibleFormat, errors.UninitializableFormat):
145
158
# This Branch format cannot create shared repositories
160
if not repo._format.supports_nesting_repositories:
147
162
# This is a little bit trickier because make_branch_and_tree will not
148
163
# re-use a shared repository.
149
164
a_bzrdir = self.make_bzrdir('repo/tree')
174
189
self.assertEqual(tree.branch.last_revision(),
175
190
to_branch.last_revision())
192
def test_push_overwrite_with_older_mainline_rev(self):
193
"""Pushing an older mainline revision with overwrite.
195
This was <https://bugs.launchpad.net/bzr/+bug/386576>.
197
source = self.make_branch_and_tree('source')
198
target = self.make_branch('target')
200
source.commit('1st commit')
201
source.commit('2nd commit', rev_id='rev-2')
202
source.commit('3rd commit')
203
source.branch.push(target)
204
source.branch.push(target, stop_revision='rev-2', overwrite=True)
205
self.assertEqual('rev-2', target.last_revision())
177
207
def test_push_overwrite_of_non_tip_with_stop_revision(self):
178
208
"""Combining the stop_revision and overwrite options works.
190
220
source.branch.push(target, stop_revision='rev-2', overwrite=True)
191
221
self.assertEqual('rev-2', target.last_revision())
223
def test_push_repository_no_branch_doesnt_fetch_all_revs(self):
224
# See https://bugs.launchpad.net/bzr/+bug/465517
225
t = self.get_transport('target')
227
bzrdir = self.bzrdir_format.initialize_on_transport(t)
230
except errors.NotBranchError:
233
raise tests.TestNotApplicable('older formats can\'t have a repo'
236
source = self.make_branch_builder('source',
237
format=self.bzrdir_format)
238
except errors.UninitializableFormat:
239
raise tests.TestNotApplicable('cannot initialize this format')
240
source.start_series()
241
source.build_snapshot('A', None, [
242
('add', ('', 'root-id', 'directory', None))])
243
source.build_snapshot('B', ['A'], [])
244
source.build_snapshot('C', ['A'], [])
245
source.finish_series()
246
b = source.get_branch()
247
# Note: We can't read lock the source branch. Some formats take a write
248
# lock to 'set_push_location', which breaks
249
self.addCleanup(b.lock_write().unlock)
250
repo = bzrdir.create_repository()
251
# This means 'push the source branch into this dir'
252
bzrdir.push_branch(b)
253
self.addCleanup(repo.lock_read().unlock)
254
# We should have pushed 'C', but not 'B', since it isn't in the
256
self.assertEqual(['A', 'C'], sorted(repo.all_revision_ids()))
193
258
def test_push_with_default_stacking_does_not_create_broken_branch(self):
194
259
"""Pushing a new standalone branch works even when there's a default
195
260
stacking policy at the destination.
198
263
default for the branch), and will be stacked when the repo format
199
264
allows (which means that the branch format isn't necessarly preserved).
201
if isinstance(self.branch_format, branch.BzrBranchFormat4):
266
if self.bzrdir_format.fixed_components:
202
267
raise tests.TestNotApplicable('Not a metadir format.')
203
268
if isinstance(self.branch_format, branch.BranchReferenceFormat):
204
269
# This test could in principle apply to BranchReferenceFormat, but
339
404
raise tests.TestNotApplicable(
340
405
'Does not apply when remote backing branch is also '
341
406
'a smart branch')
342
if isinstance(self.branch_format, branch.BzrBranchFormat4):
407
if not self.branch_format.supports_leaving_lock():
343
408
raise tests.TestNotApplicable(
344
'Branch format 4 is not usable via HPSS.')
409
'Branch format is not usable via HPSS.')
345
410
super(EmptyPushSmartEffortTests, self).setUp()
346
411
# Create a smart server that publishes whatever the backing VFS server
361
426
def test_empty_branch_api(self):
362
427
"""The branch_obj.push API should make a limited number of HPSS calls.
364
t = transport.get_transport(self.smart_server.get_url()).clone('target')
429
t = transport.get_transport_from_url(self.smart_server.get_url()).clone('target')
365
430
target = branch.Branch.open_from_transport(t)
366
431
self.empty_branch.push(target)
367
432
self.assertEqual(
398
463
def test_lossy_push_raises_same_vcs(self):
399
464
target = self.make_branch('target')
400
465
source = self.make_branch('source')
401
self.assertRaises(errors.LossyPushToSameVCS, source.lossy_push, target)
466
self.assertRaises(errors.LossyPushToSameVCS, source.push, target, lossy=True)