68
68
# If there is no parent location set, :parent isn't mentioned.
69
69
out = self.run_bzr('push', working_dir='a', retcode=3)
70
70
self.assertEqual(out,
71
('', 'brz: ERROR: No push location known or specified.\n'))
71
('', 'brz: ERROR: No push location known or specified.\n'))
73
73
# If there is a parent location set, the error suggests :parent.
74
74
tree_a.branch.set_parent(tree_b.branch.base)
75
75
out = self.run_bzr('push', working_dir='a', retcode=3)
76
76
self.assertEqual(out,
77
('', 'brz: ERROR: No push location known or specified. '
78
'To push to the parent branch '
79
'(at %s), use \'brz push :parent\'.\n' %
80
urlutils.unescape_for_display(tree_b.branch.base, 'utf-8')))
77
('', 'brz: ERROR: No push location known or specified. '
78
'To push to the parent branch '
79
'(at %s), use \'brz push :parent\'.\n' %
80
urlutils.unescape_for_display(tree_b.branch.base, 'utf-8')))
82
82
def test_push_remember(self):
83
83
"""Push changes from one branch to another and test push location."""
103
103
# test push for failure without push location set
104
104
out = self.run_bzr('push', working_dir='branch_a', retcode=3)
105
105
self.assertEqual(out,
106
('', 'brz: ERROR: No push location known or specified.\n'))
106
('', 'brz: ERROR: No push location known or specified.\n'))
108
108
# test not remembered if cannot actually push
109
109
self.run_bzr('push path/which/doesnt/exist',
110
110
working_dir='branch_a', retcode=3)
111
111
out = self.run_bzr('push', working_dir='branch_a', retcode=3)
112
112
self.assertEqual(
113
('', 'brz: ERROR: No push location known or specified.\n'),
113
('', 'brz: ERROR: No push location known or specified.\n'),
116
116
# test implicit --remember when no push location set, push fails
117
117
out = self.run_bzr('push ../branch_b',
118
118
working_dir='branch_a', retcode=3)
119
119
self.assertEqual(out,
120
('', 'brz: ERROR: These branches have diverged. '
121
'See "brz help diverged-branches" for more information.\n'))
120
('', 'brz: ERROR: These branches have diverged. '
121
'See "brz help diverged-branches" for more information.\n'))
122
122
# Refresh the branch as 'push' modified it
123
123
branch_a = branch_a.controldir.open_branch()
124
124
self.assertEqual(osutils.abspath(branch_a.get_push_location()),
125
osutils.abspath(branch_b.controldir.root_transport.base))
125
osutils.abspath(branch_b.controldir.root_transport.base))
127
127
# test implicit --remember after resolving previous failure
128
128
uncommit.uncommit(branch=branch_b, tree=tree_b)
208
208
tree_a = make_shared_tree('a')
209
209
self.build_tree(['repo/a/file'])
210
210
tree_a.add('file')
211
tree_a.commit('commit a-1', rev_id=b'a-1')
211
tree_a.commit('commit a-1', rev_id='a-1')
212
212
f = open('repo/a/file', 'ab')
213
f.write(b'more stuff\n')
213
f.write('more stuff\n')
215
tree_a.commit('commit a-2', rev_id=b'a-2')
215
tree_a.commit('commit a-2', rev_id='a-2')
217
217
tree_b = make_shared_tree('b')
218
218
self.build_tree(['repo/b/file'])
219
219
tree_b.add('file')
220
tree_b.commit('commit b-1', rev_id=b'b-1')
220
tree_b.commit('commit b-1', rev_id='b-1')
222
self.assertTrue(shared_repo.has_revision(b'a-1'))
223
self.assertTrue(shared_repo.has_revision(b'a-2'))
224
self.assertTrue(shared_repo.has_revision(b'b-1'))
222
self.assertTrue(shared_repo.has_revision('a-1'))
223
self.assertTrue(shared_repo.has_revision('a-2'))
224
self.assertTrue(shared_repo.has_revision('b-1'))
226
226
# Now that we have a repository with shared files, make sure
227
227
# that things aren't copied out by a 'push'
228
228
self.run_bzr('push ../../push-b', working_dir='repo/b')
229
229
pushed_tree = workingtree.WorkingTree.open('push-b')
230
230
pushed_repo = pushed_tree.branch.repository
231
self.assertFalse(pushed_repo.has_revision(b'a-1'))
232
self.assertFalse(pushed_repo.has_revision(b'a-2'))
233
self.assertTrue(pushed_repo.has_revision(b'b-1'))
231
self.assertFalse(pushed_repo.has_revision('a-1'))
232
self.assertFalse(pushed_repo.has_revision('a-2'))
233
self.assertTrue(pushed_repo.has_revision('b-1'))
235
235
def test_push_funky_id(self):
236
236
t = self.make_branch_and_tree('tree')
237
237
self.build_tree(['tree/filename'])
238
t.add('filename', b'funky-chars<>%&;"\'')
238
t.add('filename', 'funky-chars<>%&;"\'')
239
239
t.commit('commit filename')
240
240
self.run_bzr('push -d tree new-tree')
242
242
def test_push_dash_d(self):
243
243
t = self.make_branch_and_tree('from')
244
244
t.commit(allow_pointless=True,
245
message='first commit')
245
message='first commit')
246
246
self.run_bzr('push -d from to-one')
247
247
self.assertPathExists('to-one')
248
248
self.run_bzr('push -d %s %s'
249
% tuple(map(urlutils.local_path_to_url, ['from', 'to-two'])))
249
% tuple(map(urlutils.local_path_to_url, ['from', 'to-two'])))
250
250
self.assertPathExists('to-two')
252
252
def test_push_repository_no_branch_doesnt_fetch_all_revs(self):
255
255
source = self.make_branch_builder('source')
256
256
source.start_series()
257
257
source.build_snapshot(None, [
258
('add', ('', b'root-id', 'directory', None))],
260
source.build_snapshot([b'A'], [], revision_id=b'B')
261
source.build_snapshot([b'A'], [], revision_id=b'C')
258
('add', ('', 'root-id', 'directory', None))],
260
source.build_snapshot(['A'], [], revision_id='B')
261
source.build_snapshot(['A'], [], revision_id='C')
262
262
source.finish_series()
263
263
self.run_bzr('push target -d source')
264
264
self.addCleanup(target_repo.lock_read().unlock)
265
265
# We should have pushed 'C', but not 'B', since it isn't in the
267
self.assertEqual([(b'A',), (b'C',)], sorted(
268
target_repo.revisions.keys()))
267
self.assertEqual([('A',), ('C',)], sorted(target_repo.revisions.keys()))
269
def test_push_smart_non_stacked_streaming_acceptance(self):
270
self.setup_smart_server_with_call_log()
271
t = self.make_branch_and_tree('from')
272
t.commit(allow_pointless=True, message='first commit')
273
self.reset_smart_call_log()
274
self.run_bzr(['push', self.get_url('to-one')], working_dir='from')
275
# This figure represent the amount of work to perform this use case. It
276
# is entirely ok to reduce this number if a test fails due to rpc_count
277
# being too low. If rpc_count increases, more network roundtrips have
278
# become necessary for this use case. Please do not adjust this number
279
# upwards without agreement from bzr's network support maintainers.
280
self.assertLength(9, self.hpss_calls)
281
self.assertLength(1, self.hpss_connections)
282
self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
284
def test_push_smart_stacked_streaming_acceptance(self):
285
self.setup_smart_server_with_call_log()
286
parent = self.make_branch_and_tree('parent', format='1.9')
287
parent.commit(message='first commit')
288
local = parent.controldir.sprout('local').open_workingtree()
289
local.commit(message='local commit')
290
self.reset_smart_call_log()
291
self.run_bzr(['push', '--stacked', '--stacked-on', '../parent',
292
self.get_url('public')], working_dir='local')
293
# This figure represent the amount of work to perform this use case. It
294
# is entirely ok to reduce this number if a test fails due to rpc_count
295
# being too low. If rpc_count increases, more network roundtrips have
296
# become necessary for this use case. Please do not adjust this number
297
# upwards without agreement from bzr's network support maintainers.
298
self.assertLength(15, self.hpss_calls)
299
self.assertLength(1, self.hpss_connections)
300
self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
301
remote = branch.Branch.open('public')
302
self.assertEndsWith(remote.get_stacked_on_url(), '/parent')
304
def test_push_smart_tags_streaming_acceptance(self):
305
self.setup_smart_server_with_call_log()
306
t = self.make_branch_and_tree('from')
307
rev_id = t.commit(allow_pointless=True, message='first commit')
308
t.branch.tags.set_tag('new-tag', rev_id)
309
self.reset_smart_call_log()
310
self.run_bzr(['push', self.get_url('to-one')], working_dir='from')
311
# This figure represent the amount of work to perform this use case. It
312
# is entirely ok to reduce this number if a test fails due to rpc_count
313
# being too low. If rpc_count increases, more network roundtrips have
314
# become necessary for this use case. Please do not adjust this number
315
# upwards without agreement from bzr's network support maintainers.
316
self.assertLength(11, self.hpss_calls)
317
self.assertLength(1, self.hpss_connections)
318
self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
320
def test_push_smart_incremental_acceptance(self):
321
self.setup_smart_server_with_call_log()
322
t = self.make_branch_and_tree('from')
323
rev_id1 = t.commit(allow_pointless=True, message='first commit')
324
rev_id2 = t.commit(allow_pointless=True, message='second commit')
326
['push', self.get_url('to-one'), '-r1'], working_dir='from')
327
self.reset_smart_call_log()
328
self.run_bzr(['push', self.get_url('to-one')], working_dir='from')
329
# This figure represent the amount of work to perform this use case. It
330
# is entirely ok to reduce this number if a test fails due to rpc_count
331
# being too low. If rpc_count increases, more network roundtrips have
332
# become necessary for this use case. Please do not adjust this number
333
# upwards without agreement from bzr's network support maintainers.
334
self.assertLength(11, self.hpss_calls)
335
self.assertLength(1, self.hpss_connections)
336
self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
270
338
def test_push_smart_with_default_stacking_url_path_segment(self):
271
339
# If the default stacked-on location is a path element then branches
371
439
a_controldir = self.make_controldir('dir')
373
441
self.run_bzr_error(['At ../dir you have a valid .bzr control'],
377
445
def test_push_with_revisionspec(self):
378
446
"""We should be able to push a revision older than the tip."""
379
447
tree_from = self.make_branch_and_tree('from')
380
tree_from.commit("One.", rev_id=b"from-1")
381
tree_from.commit("Two.", rev_id=b"from-2")
448
tree_from.commit("One.", rev_id="from-1")
449
tree_from.commit("Two.", rev_id="from-2")
383
451
self.run_bzr('push -r1 ../to', working_dir='from')
385
453
tree_to = workingtree.WorkingTree.open('to')
386
454
repo_to = tree_to.branch.repository
387
self.assertTrue(repo_to.has_revision(b'from-1'))
388
self.assertFalse(repo_to.has_revision(b'from-2'))
389
self.assertEqual(tree_to.branch.last_revision_info()[1], b'from-1')
455
self.assertTrue(repo_to.has_revision('from-1'))
456
self.assertFalse(repo_to.has_revision('from-2'))
457
self.assertEqual(tree_to.branch.last_revision_info()[1], 'from-1')
390
458
self.assertFalse(
391
459
tree_to.changes_from(tree_to.basis_tree()).has_changed())
422
490
trunk_tree, branch_tree = self.create_trunk_and_feature_branch()
423
491
# we publish branch_tree with a reference to the mainline.
424
492
out, err = self.run_bzr(['push', '--stacked-on', trunk_tree.branch.base,
425
self.get_url('published')], working_dir='branch')
426
self.assertEqual('', out)
427
self.assertEqual('Created new stacked branch referring to %s.\n' %
428
trunk_tree.branch.base, err)
429
self.assertPublished(branch_tree.last_revision(),
430
trunk_tree.branch.base)
432
def test_push_new_branch_stacked_on(self):
433
"""Pushing a new branch with --stacked-on can use directory URLs."""
434
trunk_tree, branch_tree = self.create_trunk_and_feature_branch()
435
class FooDirectory(object):
436
def look_up(self, name, url, purpose=None):
438
return trunk_tree.branch.base
440
directory_service.directories.register('foo:', FooDirectory, 'Foo directory')
441
self.addCleanup(directory_service.directories.remove, 'foo:')
442
# we publish branch_tree with a reference to the mainline.
443
out, err = self.run_bzr(['push', '--stacked-on', 'foo:',
444
self.get_url('published')], working_dir='branch')
445
self.assertEqual('', out)
446
self.assertEqual('Created new stacked branch referring to %s.\n' %
447
trunk_tree.branch.base, err)
448
self.assertPublished(branch_tree.last_revision(),
449
trunk_tree.branch.base)
493
self.get_url('published')], working_dir='branch')
494
self.assertEqual('', out)
495
self.assertEqual('Created new stacked branch referring to %s.\n' %
496
trunk_tree.branch.base, err)
497
self.assertPublished(branch_tree.last_revision(),
498
trunk_tree.branch.base)
451
500
def test_push_new_branch_stacked_uses_parent_when_no_public_url(self):
452
501
"""When the parent has no public url the parent is used as-is."""
527
576
builder = self.make_branch_builder('repo/local', format='pack-0.92')
528
577
builder.start_series()
529
578
builder.build_snapshot(None, [
530
('add', ('', b'root-id', 'directory', '')),
531
('add', ('filename', b'f-id', 'file', b'content\n'))],
532
revision_id=b'rev-1')
533
builder.build_snapshot([b'rev-1'], [], revision_id=b'rev-2')
534
builder.build_snapshot([b'rev-2'],
535
[('modify', ('filename', b'new-content\n'))],
536
revision_id=b'rev-3')
579
('add', ('', 'root-id', 'directory', '')),
580
('add', ('filename', 'f-id', 'file', 'content\n'))],
582
builder.build_snapshot(['rev-1'], [], revision_id='rev-2')
583
builder.build_snapshot(['rev-2'],
584
[('modify', ('f-id', 'new-content\n'))],
537
586
builder.finish_series()
538
587
branch = builder.get_branch()
539
588
# Push rev-1 to "trunk", so that we can stack on it.
574
623
def test_overwrite_tags(self):
575
624
"""--overwrite-tags only overwrites tags, not revisions."""
576
625
from_tree = self.make_branch_and_tree('from')
577
from_tree.branch.tags.set_tag("mytag", b"somerevid")
626
from_tree.branch.tags.set_tag("mytag", "somerevid")
578
627
to_tree = self.make_branch_and_tree('to')
579
to_tree.branch.tags.set_tag("mytag", b"anotherrevid")
628
to_tree.branch.tags.set_tag("mytag", "anotherrevid")
580
629
revid1 = to_tree.commit('my commit')
581
630
out = self.run_bzr(['push', '-d', 'from', 'to'])
582
631
self.assertEqual(out,
583
('Conflicting tags:\n mytag\n', 'No new revisions to push.\n'))
632
('Conflicting tags:\n mytag\n', 'No new revisions to push.\n'))
584
633
out = self.run_bzr(['push', '-d', 'from', '--overwrite-tags', 'to'])
585
634
self.assertEqual(out, ('', '1 tag updated.\n'))
586
635
self.assertEqual(to_tree.branch.tags.lookup_tag('mytag'),
588
637
self.assertEqual(to_tree.branch.last_revision(), revid1)
772
823
def _uncommitted_changes(self):
773
824
self.make_local_branch_and_tree()
774
825
# Make a change without committing it
775
self.build_tree_contents([('local/file', b'in progress')])
826
self.build_tree_contents([('local/file', 'in progress')])
777
828
def _pending_merges(self):
778
829
self.make_local_branch_and_tree()
779
830
# Create 'other' branch containing a new file
780
831
other_bzrdir = self.tree.controldir.sprout('other')
781
832
other_tree = other_bzrdir.open_workingtree()
782
self.build_tree_contents([('other/other-file', b'other')])
833
self.build_tree_contents([('other/other-file', 'other')])
783
834
other_tree.add('other-file')
784
other_tree.commit('other commit', rev_id=b'other')
835
other_tree.commit('other commit', rev_id='other')
785
836
# Merge and revert, leaving a pending merge
786
837
self.tree.merge_from_branch(other_tree.branch)
787
838
self.tree.revert(filenames=['other-file'], backups=False)
790
841
self.make_local_branch_and_tree()
791
842
self.run_bzr(['checkout', '--lightweight', 'local', 'checkout'])
792
843
# Make a change and commit it
793
self.build_tree_contents([('local/file', b'modified in local')])
794
self.tree.commit('modify file', rev_id=b'modified-in-local')
844
self.build_tree_contents([('local/file', 'modified in local')])
845
self.tree.commit('modify file', rev_id='modified-in-local')
795
846
# Exercise commands from the checkout directory
796
847
self._default_wd = 'checkout'
797
848
self._default_errors = ["Working tree is out of date, please run"
798
" 'brz update'\\.", ]
800
851
def test_push_default(self):
801
852
self.assertPushSucceeds([], with_warning=True)
803
854
def test_push_with_revision(self):
804
self.assertPushSucceeds(['-r', 'revid:added'], revid_to_push=b'added')
855
self.assertPushSucceeds(['-r', 'revid:added'], revid_to_push='added')
806
857
def test_push_no_strict(self):
807
858
self.assertPushSucceeds(['--no-strict'])