100
103
# test push for failure without push location set
101
104
out = self.run_bzr('push', working_dir='branch_a', retcode=3)
102
self.assertEquals(out,
103
('','bzr: ERROR: No push location known or specified.\n'))
105
self.assertEqual(out,
106
('', 'brz: ERROR: No push location known or specified.\n'))
105
108
# test not remembered if cannot actually push
106
109
self.run_bzr('push path/which/doesnt/exist',
107
110
working_dir='branch_a', retcode=3)
108
111
out = self.run_bzr('push', working_dir='branch_a', retcode=3)
110
('', 'bzr: ERROR: No push location known or specified.\n'),
113
('', 'brz: ERROR: No push location known or specified.\n'),
113
116
# test implicit --remember when no push location set, push fails
114
117
out = self.run_bzr('push ../branch_b',
115
118
working_dir='branch_a', retcode=3)
116
self.assertEquals(out,
117
('','bzr: ERROR: These branches have diverged. '
118
'See "bzr help diverged-branches" for more information.\n'))
119
self.assertEquals(osutils.abspath(branch_a.get_push_location()),
120
osutils.abspath(branch_b.bzrdir.root_transport.base))
119
self.assertEqual(out,
120
('', 'brz: ERROR: These branches have diverged. '
121
'See "brz help diverged-branches" for more information.\n'))
122
# Refresh the branch as 'push' modified it
123
branch_a = branch_a.controldir.open_branch()
124
self.assertEqual(osutils.abspath(branch_a.get_push_location()),
125
osutils.abspath(branch_b.controldir.root_transport.base))
122
127
# test implicit --remember after resolving previous failure
123
128
uncommit.uncommit(branch=branch_b, tree=tree_b)
124
129
transport.delete('branch_b/c')
125
130
out, err = self.run_bzr('push', working_dir='branch_a')
131
# Refresh the branch as 'push' modified it
132
branch_a = branch_a.controldir.open_branch()
126
133
path = branch_a.get_push_location()
127
self.assertEquals(out,
128
'Using saved push location: %s\n'
129
% urlutils.local_path_from_url(path))
130
134
self.assertEqual(err,
135
'Using saved push location: %s\n'
131
136
'All changes applied successfully.\n'
132
'Pushed up to revision 2.\n')
137
'Pushed up to revision 2.\n'
138
% urlutils.local_path_from_url(path))
133
139
self.assertEqual(path,
134
branch_b.bzrdir.root_transport.base)
140
branch_b.controldir.root_transport.base)
135
141
# test explicit --remember
136
142
self.run_bzr('push ../branch_c --remember', working_dir='branch_a')
137
self.assertEquals(branch_a.get_push_location(),
138
branch_c.bzrdir.root_transport.base)
143
# Refresh the branch as 'push' modified it
144
branch_a = branch_a.controldir.open_branch()
145
self.assertEqual(branch_a.get_push_location(),
146
branch_c.controldir.root_transport.base)
140
148
def test_push_without_tree(self):
141
# bzr push from a branch that does not have a checkout should work.
149
# brz push from a branch that does not have a checkout should work.
142
150
b = self.make_branch('.')
143
151
out, err = self.run_bzr('push pushed-location')
144
152
self.assertEqual('', out)
166
202
shared_repo.set_make_working_trees(True)
168
204
def make_shared_tree(path):
169
shared_repo.bzrdir.root_transport.mkdir(path)
170
shared_repo.bzrdir.create_branch_convenience('repo/' + path)
205
shared_repo.controldir.root_transport.mkdir(path)
206
controldir.ControlDir.create_branch_convenience('repo/' + path)
171
207
return workingtree.WorkingTree.open('repo/' + path)
172
208
tree_a = make_shared_tree('a')
173
209
self.build_tree(['repo/a/file'])
174
210
tree_a.add('file')
175
tree_a.commit('commit a-1', rev_id='a-1')
211
tree_a.commit('commit a-1', rev_id=b'a-1')
176
212
f = open('repo/a/file', 'ab')
177
f.write('more stuff\n')
213
f.write(b'more stuff\n')
179
tree_a.commit('commit a-2', rev_id='a-2')
215
tree_a.commit('commit a-2', rev_id=b'a-2')
181
217
tree_b = make_shared_tree('b')
182
218
self.build_tree(['repo/b/file'])
183
219
tree_b.add('file')
184
tree_b.commit('commit b-1', rev_id='b-1')
220
tree_b.commit('commit b-1', rev_id=b'b-1')
186
self.assertTrue(shared_repo.has_revision('a-1'))
187
self.assertTrue(shared_repo.has_revision('a-2'))
188
self.assertTrue(shared_repo.has_revision('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'))
190
226
# Now that we have a repository with shared files, make sure
191
227
# that things aren't copied out by a 'push'
192
228
self.run_bzr('push ../../push-b', working_dir='repo/b')
193
229
pushed_tree = workingtree.WorkingTree.open('push-b')
194
230
pushed_repo = pushed_tree.branch.repository
195
self.assertFalse(pushed_repo.has_revision('a-1'))
196
self.assertFalse(pushed_repo.has_revision('a-2'))
197
self.assertTrue(pushed_repo.has_revision('b-1'))
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'))
199
235
def test_push_funky_id(self):
200
236
t = self.make_branch_and_tree('tree')
201
237
self.build_tree(['tree/filename'])
202
t.add('filename', 'funky-chars<>%&;"\'')
238
t.add('filename', b'funky-chars<>%&;"\'')
203
239
t.commit('commit filename')
204
240
self.run_bzr('push -d tree new-tree')
206
242
def test_push_dash_d(self):
207
243
t = self.make_branch_and_tree('from')
208
244
t.commit(allow_pointless=True,
209
message='first commit')
245
message='first commit')
210
246
self.run_bzr('push -d from to-one')
211
self.failUnlessExists('to-one')
247
self.assertPathExists('to-one')
212
248
self.run_bzr('push -d %s %s'
213
% tuple(map(urlutils.local_path_to_url, ['from', 'to-two'])))
214
self.failUnlessExists('to-two')
216
def test_push_smart_non_stacked_streaming_acceptance(self):
217
self.setup_smart_server_with_call_log()
218
t = self.make_branch_and_tree('from')
219
t.commit(allow_pointless=True, message='first commit')
220
self.reset_smart_call_log()
221
self.run_bzr(['push', self.get_url('to-one')], working_dir='from')
222
# This figure represent the amount of work to perform this use case. It
223
# is entirely ok to reduce this number if a test fails due to rpc_count
224
# being too low. If rpc_count increases, more network roundtrips have
225
# become necessary for this use case. Please do not adjust this number
226
# upwards without agreement from bzr's network support maintainers.
227
self.assertLength(9, self.hpss_calls)
229
def test_push_smart_stacked_streaming_acceptance(self):
230
self.setup_smart_server_with_call_log()
231
parent = self.make_branch_and_tree('parent', format='1.9')
232
parent.commit(message='first commit')
233
local = parent.bzrdir.sprout('local').open_workingtree()
234
local.commit(message='local commit')
235
self.reset_smart_call_log()
236
self.run_bzr(['push', '--stacked', '--stacked-on', '../parent',
237
self.get_url('public')], working_dir='local')
238
# This figure represent the amount of work to perform this use case. It
239
# is entirely ok to reduce this number if a test fails due to rpc_count
240
# being too low. If rpc_count increases, more network roundtrips have
241
# become necessary for this use case. Please do not adjust this number
242
# upwards without agreement from bzr's network support maintainers.
243
self.assertLength(14, self.hpss_calls)
244
remote = branch.Branch.open('public')
245
self.assertEndsWith(remote.get_stacked_on_url(), '/parent')
247
def test_push_smart_tags_streaming_acceptance(self):
248
self.setup_smart_server_with_call_log()
249
t = self.make_branch_and_tree('from')
250
rev_id = t.commit(allow_pointless=True, message='first commit')
251
t.branch.tags.set_tag('new-tag', rev_id)
252
self.reset_smart_call_log()
253
self.run_bzr(['push', self.get_url('to-one')], working_dir='from')
254
# This figure represent the amount of work to perform this use case. It
255
# is entirely ok to reduce this number if a test fails due to rpc_count
256
# being too low. If rpc_count increases, more network roundtrips have
257
# become necessary for this use case. Please do not adjust this number
258
# upwards without agreement from bzr's network support maintainers.
259
self.assertLength(11, self.hpss_calls)
261
def test_push_smart_incremental_acceptance(self):
262
self.setup_smart_server_with_call_log()
263
t = self.make_branch_and_tree('from')
264
rev_id1 = t.commit(allow_pointless=True, message='first commit')
265
rev_id2 = t.commit(allow_pointless=True, message='second commit')
267
['push', self.get_url('to-one'), '-r1'], working_dir='from')
268
self.reset_smart_call_log()
269
self.run_bzr(['push', self.get_url('to-one')], working_dir='from')
270
# This figure represent the amount of work to perform this use case. It
271
# is entirely ok to reduce this number if a test fails due to rpc_count
272
# being too low. If rpc_count increases, more network roundtrips have
273
# become necessary for this use case. Please do not adjust this number
274
# upwards without agreement from bzr's network support maintainers.
275
self.assertLength(11, self.hpss_calls)
249
% tuple(map(urlutils.local_path_to_url, ['from', 'to-two'])))
250
self.assertPathExists('to-two')
252
def test_push_repository_no_branch_doesnt_fetch_all_revs(self):
253
# See https://bugs.launchpad.net/bzr/+bug/465517
254
target_repo = self.make_repository('target')
255
source = self.make_branch_builder('source')
256
source.start_series()
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')
262
source.finish_series()
263
self.run_bzr('push target -d source')
264
self.addCleanup(target_repo.lock_read().unlock)
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()))
277
270
def test_push_smart_with_default_stacking_url_path_segment(self):
278
271
# If the default stacked-on location is a path element then branches
375
368
# TODO: jam 20070109 Maybe it would be better to create the repository
376
369
# if at this point
377
370
tree = self.create_simple_tree()
378
a_bzrdir = self.make_bzrdir('dir')
371
a_controldir = self.make_controldir('dir')
380
373
self.run_bzr_error(['At ../dir you have a valid .bzr control'],
384
377
def test_push_with_revisionspec(self):
385
378
"""We should be able to push a revision older than the tip."""
386
379
tree_from = self.make_branch_and_tree('from')
387
tree_from.commit("One.", rev_id="from-1")
388
tree_from.commit("Two.", rev_id="from-2")
380
tree_from.commit("One.", rev_id=b"from-1")
381
tree_from.commit("Two.", rev_id=b"from-2")
390
383
self.run_bzr('push -r1 ../to', working_dir='from')
392
385
tree_to = workingtree.WorkingTree.open('to')
393
386
repo_to = tree_to.branch.repository
394
self.assertTrue(repo_to.has_revision('from-1'))
395
self.assertFalse(repo_to.has_revision('from-2'))
396
self.assertEqual(tree_to.branch.last_revision_info()[1], 'from-1')
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')
391
tree_to.changes_from(tree_to.basis_tree()).has_changed())
398
393
self.run_bzr_error(
399
['bzr: ERROR: bzr push --revision '
394
['brz: ERROR: brz push --revision '
400
395
'takes exactly one revision identifier\n'],
401
396
'push -r0..2 ../to', working_dir='from')
403
398
def create_trunk_and_feature_branch(self):
404
399
# We have a mainline
405
400
trunk_tree = self.make_branch_and_tree('target',
407
402
trunk_tree.commit('mainline')
408
403
# and a branch from it
409
404
branch_tree = self.make_branch_and_tree('branch',
411
406
branch_tree.pull(trunk_tree.branch)
412
407
branch_tree.branch.set_parent(trunk_tree.branch.base)
413
408
# with some work on it
427
422
trunk_tree, branch_tree = self.create_trunk_and_feature_branch()
428
423
# we publish branch_tree with a reference to the mainline.
429
424
out, err = self.run_bzr(['push', '--stacked-on', trunk_tree.branch.base,
430
self.get_url('published')], working_dir='branch')
431
self.assertEqual('', out)
432
self.assertEqual('Created new stacked branch referring to %s.\n' %
433
trunk_tree.branch.base, err)
434
self.assertPublished(branch_tree.last_revision(),
435
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)
437
451
def test_push_new_branch_stacked_uses_parent_when_no_public_url(self):
438
452
"""When the parent has no public url the parent is used as-is."""
511
526
self.make_repository('repo', shared=True, format='1.6')
512
527
builder = self.make_branch_builder('repo/local', format='pack-0.92')
513
528
builder.start_series()
514
builder.build_snapshot('rev-1', None, [
515
('add', ('', 'root-id', 'directory', '')),
516
('add', ('filename', 'f-id', 'file', 'content\n'))])
517
builder.build_snapshot('rev-2', ['rev-1'], [])
518
builder.build_snapshot('rev-3', ['rev-2'],
519
[('modify', ('f-id', 'new-content\n'))])
529
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')
520
537
builder.finish_series()
521
538
branch = builder.get_branch()
522
539
# Push rev-1 to "trunk", so that we can stack on it.
523
540
self.run_bzr('push -d repo/local trunk -r 1')
524
541
# Set a default stacking policy so that new branches will automatically
525
542
# stack on trunk.
526
self.make_bzrdir('.').get_config().set_default_stack_on('trunk')
543
self.make_controldir('.').get_config().set_default_stack_on('trunk')
527
544
# Push rev-2 to a new branch "remote". It will be stacked on "trunk".
528
545
out, err = self.run_bzr('push -d repo/local remote -r 2')
529
546
self.assertContainsRe(
548
565
def test_push_from_subdir(self):
549
566
t = self.make_branch_and_tree('tree')
550
567
self.build_tree(['tree/dir/', 'tree/dir/file'])
551
t.add('dir', 'dir/file')
568
t.add(['dir', 'dir/file'])
553
570
out, err = self.run_bzr('push ../../pushloc', working_dir='tree/dir')
554
571
self.assertEqual('', out)
555
572
self.assertEqual('Created new branch.\n', err)
574
def test_overwrite_tags(self):
575
"""--overwrite-tags only overwrites tags, not revisions."""
576
from_tree = self.make_branch_and_tree('from')
577
from_tree.branch.tags.set_tag("mytag", b"somerevid")
578
to_tree = self.make_branch_and_tree('to')
579
to_tree.branch.tags.set_tag("mytag", b"anotherrevid")
580
revid1 = to_tree.commit('my commit')
581
out = self.run_bzr(['push', '-d', 'from', 'to'])
582
self.assertEqual(out,
583
('Conflicting tags:\n mytag\n', 'No new revisions to push.\n'))
584
out = self.run_bzr(['push', '-d', 'from', '--overwrite-tags', 'to'])
585
self.assertEqual(out, ('', '1 tag updated.\n'))
586
self.assertEqual(to_tree.branch.tags.lookup_tag('mytag'),
588
self.assertEqual(to_tree.branch.last_revision(), revid1)
558
591
class RedirectingMemoryTransport(memory.MemoryTransport):
646
679
def make_local_branch_and_tree(self):
647
680
self.tree = self.make_branch_and_tree('local')
648
self.build_tree_contents([('local/file', 'initial')])
681
self.build_tree_contents([('local/file', b'initial')])
649
682
self.tree.add('file')
650
self.tree.commit('adding file', rev_id='added')
651
self.build_tree_contents([('local/file', 'modified')])
652
self.tree.commit('modify file', rev_id='modified')
683
self.tree.commit('adding file', rev_id=b'added')
684
self.build_tree_contents([('local/file', b'modified')])
685
self.tree.commit('modify file', rev_id=b'modified')
654
687
def set_config_push_strict(self, value):
655
# set config var (any of bazaar.conf, locations.conf, branch.conf
657
conf = self.tree.branch.get_config()
658
conf.set_user_option('push_strict', value)
688
br = branch.Branch.open('local')
689
br.get_config_stack().set('push_strict', value)
660
691
_default_command = ['push', '../to']
661
692
_default_wd = 'local'
662
693
_default_errors = ['Working tree ".*/local/" has uncommitted '
663
'changes \(See bzr status\)\.',]
694
'changes \\(See brz status\\)\\.', ]
664
695
_default_additional_error = 'Use --no-strict to force the push.\n'
665
696
_default_additional_warning = 'Uncommitted changes will not be pushed.'
668
698
def assertPushFails(self, args):
669
699
out, err = self.run_bzr_error(self._default_errors,
670
700
self._default_command + args,
797
837
def make_dummy_builder(self, relpath):
798
838
builder = self.make_branch_builder(
799
839
relpath, format=test_foreign.DummyForeignVcsDirFormat())
800
builder.build_snapshot('revid', None,
801
[('add', ('', 'TREE_ROOT', 'directory', None)),
802
('add', ('foo', 'fooid', 'file', 'bar'))])
840
builder.build_snapshot(None,
841
[('add', ('', b'TREE_ROOT', 'directory', None)),
842
('add', ('foo', b'fooid', 'file', b'bar'))],
843
revision_id=b'revid')
805
846
def test_no_roundtripping(self):
806
847
target_branch = self.make_dummy_builder('dp').get_branch()
807
848
source_tree = self.make_branch_and_tree("dc")
808
849
output, error = self.run_bzr("push -d dc dp", retcode=3)
809
self.assertEquals("", output)
810
self.assertEquals(error, "bzr: ERROR: It is not possible to losslessly"
811
" push to dummy. You may want to use dpush instead.\n")
850
self.assertEqual("", output)
853
"brz: ERROR: It is not possible to losslessly"
854
" push to dummy. You may want to use --lossy.\n")
857
class TestPushOutput(script.TestCaseWithTransportAndScript):
859
def test_push_log_format(self):
862
Created a standalone tree (format: 2a)
867
$ brz commit -m 'we need some foo'
868
2>Committing to:...trunk/
870
2>Committed revision 1.
871
$ brz init ../feature
872
Created a standalone tree (format: 2a)
873
$ brz push -v ../feature -Olog_format=line
875
1: jrandom@example.com ...we need some foo
876
2>All changes applied successfully.
877
2>Pushed up to revision 1.
880
def test_push_with_revspec(self):
882
$ brz init-shared-repo .
883
Shared repository with trees (format: 2a)
887
Created a repository tree (format: 2a)
888
Using shared repository...
890
$ brz commit -m 'first rev' --unchanged
891
2>Committing to:...trunk/
892
2>Committed revision 1.
896
$ brz commit -m 'we need some foo'
897
2>Committing to:...trunk/
899
2>Committed revision 2.
900
$ brz push -r 1 ../other
901
2>Created new branch.
902
$ brz st ../other # checking that file is not created (#484516)