34
from breezy.bzr import (
37
from breezy.bzr import knitrepo
38
from breezy.tests import (
33
from bzrlib.repofmt import knitrepo
34
from bzrlib.tests import (
44
from breezy.tests.matchers import ContainsNoVfsCalls
45
from breezy.transport import memory
48
load_tests = scenarios.load_tests_apply_scenarios
40
from bzrlib.transport import memory
43
def load_tests(standard_tests, module, loader):
44
"""Multiply tests for the push command."""
45
result = loader.suiteClass()
47
# one for each king of change
48
changes_tests, remaining_tests = tests.split_suite_by_condition(
49
standard_tests, tests.condition_isinstance((
50
TestPushStrictWithChanges,
54
dict(_changes_type= '_uncommitted_changes')),
56
dict(_changes_type= '_pending_merges')),
58
dict(_changes_type= '_out_of_sync_trees')),
60
tests.multiply_tests(changes_tests, changes_scenarios, result)
61
# No parametrization for the remaining tests
62
result.addTests(remaining_tests)
51
67
class TestPush(tests.TestCaseWithTransport):
60
76
['push', public_url],
61
77
working_dir='source')
63
def test_push_suggests_parent_alias(self):
64
"""Push suggests using :parent if there is a known parent branch."""
65
tree_a = self.make_branch_and_tree('a')
66
tree_a.commit('this is a commit')
67
tree_b = self.make_branch_and_tree('b')
69
# If there is no parent location set, :parent isn't mentioned.
70
out = self.run_bzr('push', working_dir='a', retcode=3)
72
('', 'brz: ERROR: No push location known or specified.\n'))
74
# If there is a parent location set, the error suggests :parent.
75
tree_a.branch.set_parent(tree_b.branch.base)
76
out = self.run_bzr('push', working_dir='a', retcode=3)
78
('', 'brz: ERROR: No push location known or specified. '
79
'To push to the parent branch '
80
'(at %s), use \'brz push :parent\'.\n' %
81
urlutils.unescape_for_display(tree_b.branch.base, 'utf-8')))
83
79
def test_push_remember(self):
84
80
"""Push changes from one branch to another and test push location."""
85
81
transport = self.get_transport()
104
100
# test push for failure without push location set
105
101
out = self.run_bzr('push', working_dir='branch_a', retcode=3)
106
self.assertEqual(out,
107
('', 'brz: ERROR: No push location known or specified.\n'))
102
self.assertEquals(out,
103
('','bzr: ERROR: No push location known or specified.\n'))
109
105
# test not remembered if cannot actually push
110
106
self.run_bzr('push path/which/doesnt/exist',
111
107
working_dir='branch_a', retcode=3)
112
108
out = self.run_bzr('push', working_dir='branch_a', retcode=3)
114
('', 'brz: ERROR: No push location known or specified.\n'),
110
('', 'bzr: ERROR: No push location known or specified.\n'),
117
113
# test implicit --remember when no push location set, push fails
118
114
out = self.run_bzr('push ../branch_b',
119
115
working_dir='branch_a', retcode=3)
120
self.assertEqual(out,
121
('', 'brz: ERROR: These branches have diverged. '
122
'See "brz help diverged-branches" for more information.\n'))
123
# Refresh the branch as 'push' modified it
124
branch_a = branch_a.controldir.open_branch()
125
self.assertEqual(osutils.abspath(branch_a.get_push_location()),
126
osutils.abspath(branch_b.controldir.root_transport.base))
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))
128
122
# test implicit --remember after resolving previous failure
129
123
uncommit.uncommit(branch=branch_b, tree=tree_b)
130
124
transport.delete('branch_b/c')
131
125
out, err = self.run_bzr('push', working_dir='branch_a')
132
# Refresh the branch as 'push' modified it
133
branch_a = branch_a.controldir.open_branch()
134
126
path = branch_a.get_push_location()
127
self.assertEquals(out,
128
'Using saved push location: %s\n'
129
% urlutils.local_path_from_url(path))
135
130
self.assertEqual(err,
136
'Using saved push location: %s\n'
137
131
'All changes applied successfully.\n'
138
'Pushed up to revision 2.\n'
139
% urlutils.local_path_from_url(path))
132
'Pushed up to revision 2.\n')
140
133
self.assertEqual(path,
141
branch_b.controldir.root_transport.base)
134
branch_b.bzrdir.root_transport.base)
142
135
# test explicit --remember
143
136
self.run_bzr('push ../branch_c --remember', working_dir='branch_a')
144
# Refresh the branch as 'push' modified it
145
branch_a = branch_a.controldir.open_branch()
146
self.assertEqual(branch_a.get_push_location(),
147
branch_c.controldir.root_transport.base)
137
self.assertEquals(branch_a.get_push_location(),
138
branch_c.bzrdir.root_transport.base)
149
140
def test_push_without_tree(self):
150
# brz push from a branch that does not have a checkout should work.
141
# bzr push from a branch that does not have a checkout should work.
151
142
b = self.make_branch('.')
152
143
out, err = self.run_bzr('push pushed-location')
153
144
self.assertEqual('', out)
155
146
b2 = branch.Branch.open('pushed-location')
156
147
self.assertEndsWith(b2.base, 'pushed-location/')
158
def test_push_no_tree(self):
159
# brz push --no-tree of a branch with working trees
160
b = self.make_branch_and_tree('push-from')
161
self.build_tree(['push-from/file'])
164
out, err = self.run_bzr('push --no-tree -d push-from push-to')
165
self.assertEqual('', out)
166
self.assertEqual('Created new branch.\n', err)
167
self.assertPathDoesNotExist('push-to/file')
169
149
def test_push_new_branch_revision_count(self):
170
# brz push of a branch with revisions to a new location
150
# bzr push of a branch with revisions to a new location
171
151
# should print the number of revisions equal to the length of the
173
153
t = self.make_branch_and_tree('tree')
178
158
self.assertEqual('', out)
179
159
self.assertEqual('Created new branch.\n', err)
181
def test_push_quiet(self):
182
# test that using -q makes output quiet
183
t = self.make_branch_and_tree('tree')
184
self.build_tree(['tree/file'])
187
self.run_bzr('push -d tree pushed-to')
188
# Refresh the branch as 'push' modified it and get the push location
189
push_loc = t.branch.controldir.open_branch().get_push_location()
190
out, err = self.run_bzr('push', working_dir="tree")
191
self.assertEqual('Using saved push location: %s\n'
192
'No new revisions or tags to push.\n' %
193
urlutils.local_path_from_url(push_loc), err)
194
out, err = self.run_bzr('push -q', working_dir="tree")
195
self.assertEqual('', out)
196
self.assertEqual('', err)
198
161
def test_push_only_pushes_history(self):
199
162
# Knit branches should only push the history for the current revision.
200
163
format = bzrdir.BzrDirMetaFormat1()
203
166
shared_repo.set_make_working_trees(True)
205
168
def make_shared_tree(path):
206
shared_repo.controldir.root_transport.mkdir(path)
207
controldir.ControlDir.create_branch_convenience('repo/' + path)
169
shared_repo.bzrdir.root_transport.mkdir(path)
170
shared_repo.bzrdir.create_branch_convenience('repo/' + path)
208
171
return workingtree.WorkingTree.open('repo/' + path)
209
172
tree_a = make_shared_tree('a')
210
173
self.build_tree(['repo/a/file'])
211
174
tree_a.add('file')
212
tree_a.commit('commit a-1', rev_id=b'a-1')
175
tree_a.commit('commit a-1', rev_id='a-1')
213
176
f = open('repo/a/file', 'ab')
214
f.write(b'more stuff\n')
177
f.write('more stuff\n')
216
tree_a.commit('commit a-2', rev_id=b'a-2')
179
tree_a.commit('commit a-2', rev_id='a-2')
218
181
tree_b = make_shared_tree('b')
219
182
self.build_tree(['repo/b/file'])
220
183
tree_b.add('file')
221
tree_b.commit('commit b-1', rev_id=b'b-1')
184
tree_b.commit('commit b-1', rev_id='b-1')
223
self.assertTrue(shared_repo.has_revision(b'a-1'))
224
self.assertTrue(shared_repo.has_revision(b'a-2'))
225
self.assertTrue(shared_repo.has_revision(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'))
227
190
# Now that we have a repository with shared files, make sure
228
191
# that things aren't copied out by a 'push'
229
192
self.run_bzr('push ../../push-b', working_dir='repo/b')
230
193
pushed_tree = workingtree.WorkingTree.open('push-b')
231
194
pushed_repo = pushed_tree.branch.repository
232
self.assertFalse(pushed_repo.has_revision(b'a-1'))
233
self.assertFalse(pushed_repo.has_revision(b'a-2'))
234
self.assertTrue(pushed_repo.has_revision(b'b-1'))
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'))
236
199
def test_push_funky_id(self):
237
200
t = self.make_branch_and_tree('tree')
238
201
self.build_tree(['tree/filename'])
239
t.add('filename', b'funky-chars<>%&;"\'')
202
t.add('filename', 'funky-chars<>%&;"\'')
240
203
t.commit('commit filename')
241
204
self.run_bzr('push -d tree new-tree')
243
206
def test_push_dash_d(self):
244
207
t = self.make_branch_and_tree('from')
245
208
t.commit(allow_pointless=True,
246
message='first commit')
209
message='first commit')
247
210
self.run_bzr('push -d from to-one')
248
self.assertPathExists('to-one')
211
self.failUnlessExists('to-one')
249
212
self.run_bzr('push -d %s %s'
250
% tuple(map(urlutils.local_path_to_url, ['from', 'to-two'])))
251
self.assertPathExists('to-two')
253
def test_push_repository_no_branch_doesnt_fetch_all_revs(self):
254
# See https://bugs.launchpad.net/bzr/+bug/465517
255
target_repo = self.make_repository('target')
256
source = self.make_branch_builder('source')
257
source.start_series()
258
source.build_snapshot(None, [
259
('add', ('', b'root-id', 'directory', None))],
261
source.build_snapshot([b'A'], [], revision_id=b'B')
262
source.build_snapshot([b'A'], [], revision_id=b'C')
263
source.finish_series()
264
self.run_bzr('push target -d source')
265
self.addCleanup(target_repo.lock_read().unlock)
266
# We should have pushed 'C', but not 'B', since it isn't in the
268
self.assertEqual([(b'A',), (b'C',)], sorted(
269
target_repo.revisions.keys()))
213
% tuple(map(urlutils.local_path_to_url, ['from', 'to-two'])))
214
self.failUnlessExists('to-two')
271
216
def test_push_smart_non_stacked_streaming_acceptance(self):
272
217
self.setup_smart_server_with_call_log()
280
225
# become necessary for this use case. Please do not adjust this number
281
226
# upwards without agreement from bzr's network support maintainers.
282
227
self.assertLength(9, self.hpss_calls)
283
self.assertLength(1, self.hpss_connections)
284
self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
286
229
def test_push_smart_stacked_streaming_acceptance(self):
287
230
self.setup_smart_server_with_call_log()
288
231
parent = self.make_branch_and_tree('parent', format='1.9')
289
232
parent.commit(message='first commit')
290
local = parent.controldir.sprout('local').open_workingtree()
233
local = parent.bzrdir.sprout('local').open_workingtree()
291
234
local.commit(message='local commit')
292
235
self.reset_smart_call_log()
293
236
self.run_bzr(['push', '--stacked', '--stacked-on', '../parent',
294
self.get_url('public')], working_dir='local')
237
self.get_url('public')], working_dir='local')
295
238
# This figure represent the amount of work to perform this use case. It
296
239
# is entirely ok to reduce this number if a test fails due to rpc_count
297
240
# being too low. If rpc_count increases, more network roundtrips have
298
241
# become necessary for this use case. Please do not adjust this number
299
242
# upwards without agreement from bzr's network support maintainers.
300
self.assertLength(15, self.hpss_calls)
301
self.assertLength(1, self.hpss_connections)
302
self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
243
self.assertLength(14, self.hpss_calls)
303
244
remote = branch.Branch.open('public')
304
245
self.assertEndsWith(remote.get_stacked_on_url(), '/parent')
365
302
def create_simple_tree(self):
366
303
tree = self.make_branch_and_tree('tree')
367
304
self.build_tree(['tree/a'])
368
tree.add(['a'], [b'a-id'])
369
tree.commit('one', rev_id=b'r1')
305
tree.add(['a'], ['a-id'])
306
tree.commit('one', rev_id='r1')
372
309
def test_push_create_prefix(self):
373
"""'brz push --create-prefix' will create leading directories."""
310
"""'bzr push --create-prefix' will create leading directories."""
374
311
tree = self.create_simple_tree()
376
313
self.run_bzr_error(['Parent directory of ../new/tree does not exist'],
380
317
working_dir='tree')
381
318
new_tree = workingtree.WorkingTree.open('new/tree')
382
319
self.assertEqual(tree.last_revision(), new_tree.last_revision())
383
self.assertPathExists('new/tree/a')
320
self.failUnlessExists('new/tree/a')
385
322
def test_push_use_existing(self):
386
"""'brz push --use-existing-dir' can push into an existing dir.
323
"""'bzr push --use-existing-dir' can push into an existing dir.
388
By default, 'brz push' will not use an existing, non-versioned dir.
325
By default, 'bzr push' will not use an existing, non-versioned dir.
390
327
tree = self.create_simple_tree()
391
328
self.build_tree(['target/'])
393
330
self.run_bzr_error(['Target directory ../target already exists',
394
331
'Supply --use-existing-dir',
396
333
'push ../target', working_dir='tree')
398
335
self.run_bzr('push --use-existing-dir ../target',
438
375
# TODO: jam 20070109 Maybe it would be better to create the repository
439
376
# if at this point
440
377
tree = self.create_simple_tree()
441
a_controldir = self.make_controldir('dir')
378
a_bzrdir = self.make_bzrdir('dir')
443
380
self.run_bzr_error(['At ../dir you have a valid .bzr control'],
447
384
def test_push_with_revisionspec(self):
448
385
"""We should be able to push a revision older than the tip."""
449
386
tree_from = self.make_branch_and_tree('from')
450
tree_from.commit("One.", rev_id=b"from-1")
451
tree_from.commit("Two.", rev_id=b"from-2")
387
tree_from.commit("One.", rev_id="from-1")
388
tree_from.commit("Two.", rev_id="from-2")
453
390
self.run_bzr('push -r1 ../to', working_dir='from')
455
392
tree_to = workingtree.WorkingTree.open('to')
456
393
repo_to = tree_to.branch.repository
457
self.assertTrue(repo_to.has_revision(b'from-1'))
458
self.assertFalse(repo_to.has_revision(b'from-2'))
459
self.assertEqual(tree_to.branch.last_revision_info()[1], b'from-1')
461
tree_to.changes_from(tree_to.basis_tree()).has_changed())
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')
463
398
self.run_bzr_error(
464
['brz: ERROR: brz push --revision '
399
['bzr: ERROR: bzr push --revision '
465
400
'takes exactly one revision identifier\n'],
466
401
'push -r0..2 ../to', working_dir='from')
468
403
def create_trunk_and_feature_branch(self):
469
404
# We have a mainline
470
405
trunk_tree = self.make_branch_and_tree('target',
472
407
trunk_tree.commit('mainline')
473
408
# and a branch from it
474
409
branch_tree = self.make_branch_and_tree('branch',
476
411
branch_tree.pull(trunk_tree.branch)
477
412
branch_tree.branch.set_parent(trunk_tree.branch.base)
478
413
# with some work on it
492
427
trunk_tree, branch_tree = self.create_trunk_and_feature_branch()
493
428
# we publish branch_tree with a reference to the mainline.
494
429
out, err = self.run_bzr(['push', '--stacked-on', trunk_tree.branch.base,
495
self.get_url('published')], working_dir='branch')
496
self.assertEqual('', out)
497
self.assertEqual('Created new stacked branch referring to %s.\n' %
498
trunk_tree.branch.base, err)
499
self.assertPublished(branch_tree.last_revision(),
500
trunk_tree.branch.base)
502
def test_push_new_branch_stacked_on(self):
503
"""Pushing a new branch with --stacked-on can use directory URLs."""
504
trunk_tree, branch_tree = self.create_trunk_and_feature_branch()
505
class FooDirectory(object):
506
def look_up(self, name, url, purpose=None):
508
return trunk_tree.branch.base
510
directory_service.directories.register('foo:', FooDirectory, 'Foo directory')
511
self.addCleanup(directory_service.directories.remove, 'foo:')
512
# we publish branch_tree with a reference to the mainline.
513
out, err = self.run_bzr(['push', '--stacked-on', 'foo:',
514
self.get_url('published')], working_dir='branch')
515
self.assertEqual('', out)
516
self.assertEqual('Created new stacked branch referring to %s.\n' %
517
trunk_tree.branch.base, err)
518
self.assertPublished(branch_tree.last_revision(),
519
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)
521
437
def test_push_new_branch_stacked_uses_parent_when_no_public_url(self):
522
438
"""When the parent has no public url the parent is used as-is."""
524
440
# now we do a stacked push, which should determine the public location
526
442
out, err = self.run_bzr(['push', '--stacked',
527
self.get_url('published')], working_dir='branch')
443
self.get_url('published')], working_dir='branch')
528
444
self.assertEqual('', out)
529
445
self.assertEqual('Created new stacked branch referring to %s.\n' %
530
trunk_tree.branch.base, err)
446
trunk_tree.branch.base, err)
531
447
self.assertPublished(branch_tree.last_revision(),
532
448
trunk_tree.branch.base)
539
455
trunk_public = self.make_branch('public_trunk', format='1.9')
540
456
trunk_public.pull(trunk_tree.branch)
541
457
trunk_public_url = self.get_readonly_url('public_trunk')
542
br = trunk_tree.branch
543
br.set_public_branch(trunk_public_url)
458
trunk_tree.branch.set_public_branch(trunk_public_url)
544
459
# now we do a stacked push, which should determine the public location
546
461
out, err = self.run_bzr(['push', '--stacked',
547
self.get_url('published')], working_dir='branch')
462
self.get_url('published')], working_dir='branch')
548
463
self.assertEqual('', out)
549
464
self.assertEqual('Created new stacked branch referring to %s.\n' %
550
trunk_public_url, err)
465
trunk_public_url, err)
551
466
self.assertPublished(branch_tree.last_revision(), trunk_public_url)
553
468
def test_push_new_branch_stacked_no_parent(self):
557
472
# cannot be determined.
558
473
out, err = self.run_bzr_error(
559
474
['Could not determine branch to refer to\\.'], ['push', '--stacked',
560
self.get_url('published')], working_dir='branch')
475
self.get_url('published')], working_dir='branch')
561
476
self.assertEqual('', out)
562
477
self.assertFalse(self.get_transport('published').has('.'))
564
479
def test_push_notifies_default_stacking(self):
565
480
self.make_branch('stack_on', format='1.6')
566
self.make_controldir('.').get_config().set_default_stack_on('stack_on')
481
self.make_bzrdir('.').get_config().set_default_stack_on('stack_on')
567
482
self.make_branch('from', format='1.6')
568
483
out, err = self.run_bzr('push -d from to')
569
484
self.assertContainsRe(err,
580
495
def test_push_does_not_change_format_with_default_if_target_cannot(self):
581
496
self.make_branch('stack_on', format='pack-0.92')
582
self.make_controldir('.').get_config().set_default_stack_on('stack_on')
497
self.make_bzrdir('.').get_config().set_default_stack_on('stack_on')
583
498
self.make_branch('from', format='pack-0.92')
584
499
out, err = self.run_bzr('push -d from to')
585
500
b = branch.Branch.open('to')
586
self.assertRaises(branch.UnstackableBranchFormat, b.get_stacked_on_url)
501
self.assertRaises(errors.UnstackableBranchFormat, b.get_stacked_on_url)
588
503
def test_push_doesnt_create_broken_branch(self):
589
504
"""Pushing a new standalone branch works even when there's a default
596
511
self.make_repository('repo', shared=True, format='1.6')
597
512
builder = self.make_branch_builder('repo/local', format='pack-0.92')
598
513
builder.start_series()
599
builder.build_snapshot(None, [
600
('add', ('', b'root-id', 'directory', '')),
601
('add', ('filename', b'f-id', 'file', b'content\n'))],
602
revision_id=b'rev-1')
603
builder.build_snapshot([b'rev-1'], [], revision_id=b'rev-2')
604
builder.build_snapshot([b'rev-2'],
605
[('modify', ('filename', b'new-content\n'))],
606
revision_id=b'rev-3')
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'))])
607
520
builder.finish_series()
608
521
branch = builder.get_branch()
609
522
# Push rev-1 to "trunk", so that we can stack on it.
610
523
self.run_bzr('push -d repo/local trunk -r 1')
611
524
# Set a default stacking policy so that new branches will automatically
612
525
# stack on trunk.
613
self.make_controldir('.').get_config().set_default_stack_on('trunk')
526
self.make_bzrdir('.').get_config().set_default_stack_on('trunk')
614
527
# Push rev-2 to a new branch "remote". It will be stacked on "trunk".
615
528
out, err = self.run_bzr('push -d repo/local remote -r 2')
616
529
self.assertContainsRe(
635
548
def test_push_from_subdir(self):
636
549
t = self.make_branch_and_tree('tree')
637
550
self.build_tree(['tree/dir/', 'tree/dir/file'])
638
t.add(['dir', 'dir/file'])
551
t.add('dir', 'dir/file')
640
553
out, err = self.run_bzr('push ../../pushloc', working_dir='tree/dir')
641
554
self.assertEqual('', out)
642
555
self.assertEqual('Created new branch.\n', err)
644
def test_overwrite_tags(self):
645
"""--overwrite-tags only overwrites tags, not revisions."""
646
from_tree = self.make_branch_and_tree('from')
647
from_tree.branch.tags.set_tag("mytag", b"somerevid")
648
to_tree = self.make_branch_and_tree('to')
649
to_tree.branch.tags.set_tag("mytag", b"anotherrevid")
650
revid1 = to_tree.commit('my commit')
651
out = self.run_bzr(['push', '-d', 'from', 'to'])
652
self.assertEqual(out,
653
('Conflicting tags:\n mytag\n', 'No new revisions to push.\n'))
654
out = self.run_bzr(['push', '-d', 'from', '--overwrite-tags', 'to'])
655
self.assertEqual(out, ('', '1 tag updated.\n'))
656
self.assertEqual(to_tree.branch.tags.lookup_tag('mytag'),
658
self.assertEqual(to_tree.branch.last_revision(), revid1)
661
558
class RedirectingMemoryTransport(memory.MemoryTransport):
749
646
def make_local_branch_and_tree(self):
750
647
self.tree = self.make_branch_and_tree('local')
751
self.build_tree_contents([('local/file', b'initial')])
648
self.build_tree_contents([('local/file', 'initial')])
752
649
self.tree.add('file')
753
self.tree.commit('adding file', rev_id=b'added')
754
self.build_tree_contents([('local/file', b'modified')])
755
self.tree.commit('modify file', rev_id=b'modified')
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')
757
654
def set_config_push_strict(self, value):
758
br = branch.Branch.open('local')
759
br.get_config_stack().set('push_strict', 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)
761
660
_default_command = ['push', '../to']
762
661
_default_wd = 'local'
763
662
_default_errors = ['Working tree ".*/local/" has uncommitted '
764
'changes \\(See brz status\\)\\.', ]
663
'changes \(See bzr status\)\.',]
765
664
_default_additional_error = 'Use --no-strict to force the push.\n'
766
665
_default_additional_warning = 'Uncommitted changes will not be pushed.'
768
668
def assertPushFails(self, args):
769
669
out, err = self.run_bzr_error(self._default_errors,
770
670
self._default_command + args,
842
732
def _uncommitted_changes(self):
843
733
self.make_local_branch_and_tree()
844
734
# Make a change without committing it
845
self.build_tree_contents([('local/file', b'in progress')])
735
self.build_tree_contents([('local/file', 'in progress')])
847
737
def _pending_merges(self):
848
738
self.make_local_branch_and_tree()
849
739
# Create 'other' branch containing a new file
850
other_bzrdir = self.tree.controldir.sprout('other')
740
other_bzrdir = self.tree.bzrdir.sprout('other')
851
741
other_tree = other_bzrdir.open_workingtree()
852
self.build_tree_contents([('other/other-file', b'other')])
742
self.build_tree_contents([('other/other-file', 'other')])
853
743
other_tree.add('other-file')
854
other_tree.commit('other commit', rev_id=b'other')
744
other_tree.commit('other commit', rev_id='other')
855
745
# Merge and revert, leaving a pending merge
856
746
self.tree.merge_from_branch(other_tree.branch)
857
747
self.tree.revert(filenames=['other-file'], backups=False)
860
750
self.make_local_branch_and_tree()
861
751
self.run_bzr(['checkout', '--lightweight', 'local', 'checkout'])
862
752
# Make a change and commit it
863
self.build_tree_contents([('local/file', b'modified in local')])
864
self.tree.commit('modify file', rev_id=b'modified-in-local')
753
self.build_tree_contents([('local/file', 'modified in local')])
754
self.tree.commit('modify file', rev_id='modified-in-local')
865
755
# Exercise commands from the checkout directory
866
756
self._default_wd = 'checkout'
867
757
self._default_errors = ["Working tree is out of date, please run"
868
" 'brz update'\\.", ]
870
760
def test_push_default(self):
871
761
self.assertPushSucceeds([], with_warning=True)
873
763
def test_push_with_revision(self):
874
self.assertPushSucceeds(['-r', 'revid:added'], revid_to_push=b'added')
764
self.assertPushSucceeds(['-r', 'revid:added'], revid_to_push='added')
876
766
def test_push_no_strict(self):
877
767
self.assertPushSucceeds(['--no-strict'])
907
797
def make_dummy_builder(self, relpath):
908
798
builder = self.make_branch_builder(
909
799
relpath, format=test_foreign.DummyForeignVcsDirFormat())
910
builder.build_snapshot(None,
911
[('add', ('', b'TREE_ROOT', 'directory', None)),
912
('add', ('foo', b'fooid', 'file', b'bar'))],
913
revision_id=b'revid')
800
builder.build_snapshot('revid', None,
801
[('add', ('', 'TREE_ROOT', 'directory', None)),
802
('add', ('foo', 'fooid', 'file', 'bar'))])
916
805
def test_no_roundtripping(self):
917
806
target_branch = self.make_dummy_builder('dp').get_branch()
918
807
source_tree = self.make_branch_and_tree("dc")
919
808
output, error = self.run_bzr("push -d dc dp", retcode=3)
920
self.assertEqual("", output)
923
"brz: ERROR: It is not possible to losslessly"
924
" push to dummy. You may want to use --lossy.\n")
927
class TestPushOutput(script.TestCaseWithTransportAndScript):
929
def test_push_log_format(self):
932
Created a standalone tree (format: 2a)
937
$ brz commit -m 'we need some foo'
938
2>Committing to:...trunk/
940
2>Committed revision 1.
941
$ brz init ../feature
942
Created a standalone tree (format: 2a)
943
$ brz push -v ../feature -Olog_format=line
945
1: jrandom@example.com ...we need some foo
946
2>All changes applied successfully.
947
2>Pushed up to revision 1.
950
def test_push_with_revspec(self):
952
$ brz init-shared-repo .
953
Shared repository with trees (format: 2a)
957
Created a repository tree (format: 2a)
958
Using shared repository...
960
$ brz commit -m 'first rev' --unchanged
961
2>Committing to:...trunk/
962
2>Committed revision 1.
966
$ brz commit -m 'we need some foo'
967
2>Committing to:...trunk/
969
2>Committed revision 2.
970
$ brz push -r 1 ../other
971
2>Created new branch.
972
$ brz st ../other # checking that file is not created (#484516)
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")