33
from breezy.bzr import (
36
from breezy.bzr import knitrepo
37
from breezy.tests import (
34
from bzrlib.repofmt import knitrepo
35
from bzrlib.tests import (
43
from breezy.tests.matchers import ContainsNoVfsCalls
44
from breezy.transport import memory
41
from bzrlib.tests.matchers import ContainsNoVfsCalls
42
from bzrlib.transport import memory
47
45
load_tests = scenarios.load_tests_apply_scenarios
68
66
# If there is no parent location set, :parent isn't mentioned.
69
67
out = self.run_bzr('push', working_dir='a', retcode=3)
71
('', 'brz: ERROR: No push location known or specified.\n'))
68
self.assertEquals(out,
69
('','bzr: ERROR: No push location known or specified.\n'))
73
71
# If there is a parent location set, the error suggests :parent.
74
72
tree_a.branch.set_parent(tree_b.branch.base)
75
73
out = self.run_bzr('push', working_dir='a', retcode=3)
77
('', 'brz: ERROR: No push location known or specified. '
74
self.assertEquals(out,
75
('','bzr: ERROR: No push location known or specified. '
78
76
'To push to the parent branch '
79
'(at %s), use \'brz push :parent\'.\n' %
77
'(at %s), use \'bzr push :parent\'.\n' %
80
78
urlutils.unescape_for_display(tree_b.branch.base, 'utf-8')))
82
80
def test_push_remember(self):
87
85
self.build_tree(['branch_a/a'])
89
87
tree_a.commit('commit a')
90
tree_b = branch_a.controldir.sprout('branch_b').open_workingtree()
88
tree_b = branch_a.bzrdir.sprout('branch_b').open_workingtree()
91
89
branch_b = tree_b.branch
92
tree_c = branch_a.controldir.sprout('branch_c').open_workingtree()
90
tree_c = branch_a.bzrdir.sprout('branch_c').open_workingtree()
93
91
branch_c = tree_c.branch
94
92
self.build_tree(['branch_a/b'])
103
101
# test push for failure without push location set
104
102
out = self.run_bzr('push', working_dir='branch_a', retcode=3)
105
self.assertEqual(out,
106
('', 'brz: ERROR: No push location known or specified.\n'))
103
self.assertEquals(out,
104
('','bzr: ERROR: No push location known or specified.\n'))
108
106
# test not remembered if cannot actually push
109
107
self.run_bzr('push path/which/doesnt/exist',
110
108
working_dir='branch_a', retcode=3)
111
109
out = self.run_bzr('push', working_dir='branch_a', retcode=3)
113
('', 'brz: ERROR: No push location known or specified.\n'),
111
('', 'bzr: ERROR: No push location known or specified.\n'),
116
114
# test implicit --remember when no push location set, push fails
117
115
out = self.run_bzr('push ../branch_b',
118
116
working_dir='branch_a', retcode=3)
119
self.assertEqual(out,
120
('', 'brz: ERROR: These branches have diverged. '
121
'See "brz help diverged-branches" for more information.\n'))
117
self.assertEquals(out,
118
('','bzr: ERROR: These branches have diverged. '
119
'See "bzr help diverged-branches" for more information.\n'))
122
120
# 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))
121
branch_a = branch_a.bzrdir.open_branch()
122
self.assertEquals(osutils.abspath(branch_a.get_push_location()),
123
osutils.abspath(branch_b.bzrdir.root_transport.base))
127
125
# test implicit --remember after resolving previous failure
128
126
uncommit.uncommit(branch=branch_b, tree=tree_b)
129
127
transport.delete('branch_b/c')
130
128
out, err = self.run_bzr('push', working_dir='branch_a')
131
129
# Refresh the branch as 'push' modified it
132
branch_a = branch_a.controldir.open_branch()
130
branch_a = branch_a.bzrdir.open_branch()
133
131
path = branch_a.get_push_location()
134
132
self.assertEqual(err,
135
133
'Using saved push location: %s\n'
137
135
'Pushed up to revision 2.\n'
138
136
% urlutils.local_path_from_url(path))
139
137
self.assertEqual(path,
140
branch_b.controldir.root_transport.base)
138
branch_b.bzrdir.root_transport.base)
141
139
# test explicit --remember
142
140
self.run_bzr('push ../branch_c --remember', working_dir='branch_a')
143
141
# 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)
142
branch_a = branch_a.bzrdir.open_branch()
143
self.assertEquals(branch_a.get_push_location(),
144
branch_c.bzrdir.root_transport.base)
148
146
def test_push_without_tree(self):
149
# brz push from a branch that does not have a checkout should work.
147
# bzr push from a branch that does not have a checkout should work.
150
148
b = self.make_branch('.')
151
149
out, err = self.run_bzr('push pushed-location')
152
150
self.assertEqual('', out)
155
153
self.assertEndsWith(b2.base, 'pushed-location/')
157
155
def test_push_no_tree(self):
158
# brz push --no-tree of a branch with working trees
156
# bzr push --no-tree of a branch with working trees
159
157
b = self.make_branch_and_tree('push-from')
160
158
self.build_tree(['push-from/file'])
166
164
self.assertPathDoesNotExist('push-to/file')
168
166
def test_push_new_branch_revision_count(self):
169
# brz push of a branch with revisions to a new location
167
# bzr push of a branch with revisions to a new location
170
168
# should print the number of revisions equal to the length of the
172
170
t = self.make_branch_and_tree('tree')
185
183
t.commit('commit 1')
186
184
self.run_bzr('push -d tree pushed-to')
187
185
# Refresh the branch as 'push' modified it and get the push location
188
push_loc = t.branch.controldir.open_branch().get_push_location()
186
push_loc = t.branch.bzrdir.open_branch().get_push_location()
189
187
out, err = self.run_bzr('push', working_dir="tree")
190
188
self.assertEqual('Using saved push location: %s\n'
191
189
'No new revisions or tags to push.\n' %
202
200
shared_repo.set_make_working_trees(True)
204
202
def make_shared_tree(path):
205
shared_repo.controldir.root_transport.mkdir(path)
203
shared_repo.bzrdir.root_transport.mkdir(path)
206
204
controldir.ControlDir.create_branch_convenience('repo/' + path)
207
205
return workingtree.WorkingTree.open('repo/' + path)
208
206
tree_a = make_shared_tree('a')
209
207
self.build_tree(['repo/a/file'])
210
208
tree_a.add('file')
211
tree_a.commit('commit a-1', rev_id=b'a-1')
209
tree_a.commit('commit a-1', rev_id='a-1')
212
210
f = open('repo/a/file', 'ab')
213
211
f.write('more stuff\n')
215
tree_a.commit('commit a-2', rev_id=b'a-2')
213
tree_a.commit('commit a-2', rev_id='a-2')
217
215
tree_b = make_shared_tree('b')
218
216
self.build_tree(['repo/b/file'])
219
217
tree_b.add('file')
220
tree_b.commit('commit b-1', rev_id=b'b-1')
218
tree_b.commit('commit b-1', rev_id='b-1')
222
220
self.assertTrue(shared_repo.has_revision('a-1'))
223
221
self.assertTrue(shared_repo.has_revision('a-2'))
254
252
target_repo = self.make_repository('target')
255
253
source = self.make_branch_builder('source')
256
254
source.start_series()
257
source.build_snapshot(None, [
258
('add', ('', 'root-id', 'directory', None))],
260
source.build_snapshot(['A'], [], revision_id=b'B')
261
source.build_snapshot(['A'], [], revision_id=b'C')
255
source.build_snapshot('A', None, [
256
('add', ('', 'root-id', 'directory', None))])
257
source.build_snapshot('B', ['A'], [])
258
source.build_snapshot('C', ['A'], [])
262
259
source.finish_series()
263
260
self.run_bzr('push target -d source')
264
261
self.addCleanup(target_repo.lock_read().unlock)
285
282
self.setup_smart_server_with_call_log()
286
283
parent = self.make_branch_and_tree('parent', format='1.9')
287
284
parent.commit(message='first commit')
288
local = parent.controldir.sprout('local').open_workingtree()
285
local = parent.bzrdir.sprout('local').open_workingtree()
289
286
local.commit(message='local commit')
290
287
self.reset_smart_call_log()
291
288
self.run_bzr(['push', '--stacked', '--stacked-on', '../parent',
341
338
# stacked_on_url is that exact path segment. Added to nail bug 385132.
342
339
self.setup_smart_server_with_call_log()
343
340
self.make_branch('stack-on', format='1.9')
344
self.make_controldir('.').get_config().set_default_stack_on(
341
self.make_bzrdir('.').get_config().set_default_stack_on(
346
343
self.make_branch('from', format='1.9')
347
344
out, err = self.run_bzr(['push', '-d', 'from', self.get_url('to')])
354
351
# stacked_on_url is a relative path. Added to nail bug 385132.
355
352
self.setup_smart_server_with_call_log()
356
353
self.make_branch('stack-on', format='1.9')
357
self.make_controldir('.').get_config().set_default_stack_on('stack-on')
354
self.make_bzrdir('.').get_config().set_default_stack_on('stack-on')
358
355
self.make_branch('from', format='1.9')
359
356
out, err = self.run_bzr(['push', '-d', 'from', self.get_url('to')])
360
357
b = branch.Branch.open(self.get_url('to'))
363
360
def create_simple_tree(self):
364
361
tree = self.make_branch_and_tree('tree')
365
362
self.build_tree(['tree/a'])
366
tree.add(['a'], [b'a-id'])
367
tree.commit('one', rev_id=b'r1')
363
tree.add(['a'], ['a-id'])
364
tree.commit('one', rev_id='r1')
370
367
def test_push_create_prefix(self):
371
"""'brz push --create-prefix' will create leading directories."""
368
"""'bzr push --create-prefix' will create leading directories."""
372
369
tree = self.create_simple_tree()
374
371
self.run_bzr_error(['Parent directory of ../new/tree does not exist'],
381
378
self.assertPathExists('new/tree/a')
383
380
def test_push_use_existing(self):
384
"""'brz push --use-existing-dir' can push into an existing dir.
381
"""'bzr push --use-existing-dir' can push into an existing dir.
386
By default, 'brz push' will not use an existing, non-versioned dir.
383
By default, 'bzr push' will not use an existing, non-versioned dir.
388
385
tree = self.create_simple_tree()
389
386
self.build_tree(['target/'])
413
410
'push ../target --use-existing-dir', working_dir='tree')
415
412
def test_push_onto_repo(self):
416
"""We should be able to 'brz push' into an existing bzrdir."""
413
"""We should be able to 'bzr push' into an existing bzrdir."""
417
414
tree = self.create_simple_tree()
418
415
repo = self.make_repository('repo', shared=True)
436
433
# TODO: jam 20070109 Maybe it would be better to create the repository
437
434
# if at this point
438
435
tree = self.create_simple_tree()
439
a_controldir = self.make_controldir('dir')
436
a_bzrdir = self.make_bzrdir('dir')
441
438
self.run_bzr_error(['At ../dir you have a valid .bzr control'],
459
456
tree_to.changes_from(tree_to.basis_tree()).has_changed())
461
458
self.run_bzr_error(
462
['brz: ERROR: brz push --revision '
459
['bzr: ERROR: bzr push --revision '
463
460
'takes exactly one revision identifier\n'],
464
461
'push -r0..2 ../to', working_dir='from')
543
540
def test_push_notifies_default_stacking(self):
544
541
self.make_branch('stack_on', format='1.6')
545
self.make_controldir('.').get_config().set_default_stack_on('stack_on')
542
self.make_bzrdir('.').get_config().set_default_stack_on('stack_on')
546
543
self.make_branch('from', format='1.6')
547
544
out, err = self.run_bzr('push -d from to')
548
545
self.assertContainsRe(err,
551
548
def test_push_stacks_with_default_stacking_if_target_is_stackable(self):
552
549
self.make_branch('stack_on', format='1.6')
553
self.make_controldir('.').get_config().set_default_stack_on('stack_on')
550
self.make_bzrdir('.').get_config().set_default_stack_on('stack_on')
554
551
self.make_branch('from', format='pack-0.92')
555
552
out, err = self.run_bzr('push -d from to')
556
553
b = branch.Branch.open('to')
559
556
def test_push_does_not_change_format_with_default_if_target_cannot(self):
560
557
self.make_branch('stack_on', format='pack-0.92')
561
self.make_controldir('.').get_config().set_default_stack_on('stack_on')
558
self.make_bzrdir('.').get_config().set_default_stack_on('stack_on')
562
559
self.make_branch('from', format='pack-0.92')
563
560
out, err = self.run_bzr('push -d from to')
564
561
b = branch.Branch.open('to')
565
self.assertRaises(branch.UnstackableBranchFormat, b.get_stacked_on_url)
562
self.assertRaises(errors.UnstackableBranchFormat, b.get_stacked_on_url)
567
564
def test_push_doesnt_create_broken_branch(self):
568
565
"""Pushing a new standalone branch works even when there's a default
575
572
self.make_repository('repo', shared=True, format='1.6')
576
573
builder = self.make_branch_builder('repo/local', format='pack-0.92')
577
574
builder.start_series()
578
builder.build_snapshot(None, [
575
builder.build_snapshot('rev-1', None, [
579
576
('add', ('', 'root-id', 'directory', '')),
580
('add', ('filename', 'f-id', 'file', 'content\n'))],
581
revision_id=b'rev-1')
582
builder.build_snapshot([b'rev-1'], [], revision_id=b'rev-2')
583
builder.build_snapshot([b'rev-2'],
584
[('modify', ('filename', b'new-content\n'))],
585
revision_id=b'rev-3')
577
('add', ('filename', 'f-id', 'file', 'content\n'))])
578
builder.build_snapshot('rev-2', ['rev-1'], [])
579
builder.build_snapshot('rev-3', ['rev-2'],
580
[('modify', ('f-id', 'new-content\n'))])
586
581
builder.finish_series()
587
582
branch = builder.get_branch()
588
583
# Push rev-1 to "trunk", so that we can stack on it.
589
584
self.run_bzr('push -d repo/local trunk -r 1')
590
585
# Set a default stacking policy so that new branches will automatically
591
586
# stack on trunk.
592
self.make_controldir('.').get_config().set_default_stack_on('trunk')
587
self.make_bzrdir('.').get_config().set_default_stack_on('trunk')
593
588
# Push rev-2 to a new branch "remote". It will be stacked on "trunk".
594
589
out, err = self.run_bzr('push -d repo/local remote -r 2')
595
590
self.assertContainsRe(
628
623
to_tree.branch.tags.set_tag("mytag", "anotherrevid")
629
624
revid1 = to_tree.commit('my commit')
630
625
out = self.run_bzr(['push', '-d', 'from', 'to'])
631
self.assertEqual(out,
626
self.assertEquals(out,
632
627
('Conflicting tags:\n mytag\n', 'No new revisions to push.\n'))
633
628
out = self.run_bzr(['push', '-d', 'from', '--overwrite-tags', 'to'])
634
self.assertEqual(out, ('', '1 tag updated.\n'))
635
self.assertEqual(to_tree.branch.tags.lookup_tag('mytag'),
629
self.assertEquals(out, ('', '1 tag updated.\n'))
630
self.assertEquals(to_tree.branch.tags.lookup_tag('mytag'),
637
self.assertEqual(to_tree.branch.last_revision(), revid1)
632
self.assertEquals(to_tree.branch.last_revision(), revid1)
640
635
class RedirectingMemoryTransport(memory.MemoryTransport):
728
723
def make_local_branch_and_tree(self):
729
724
self.tree = self.make_branch_and_tree('local')
730
self.build_tree_contents([('local/file', b'initial')])
725
self.build_tree_contents([('local/file', 'initial')])
731
726
self.tree.add('file')
732
self.tree.commit('adding file', rev_id=b'added')
733
self.build_tree_contents([('local/file', b'modified')])
734
self.tree.commit('modify file', rev_id=b'modified')
727
self.tree.commit('adding file', rev_id='added')
728
self.build_tree_contents([('local/file', 'modified')])
729
self.tree.commit('modify file', rev_id='modified')
736
731
def set_config_push_strict(self, value):
737
732
br = branch.Branch.open('local')
740
735
_default_command = ['push', '../to']
741
736
_default_wd = 'local'
742
737
_default_errors = ['Working tree ".*/local/" has uncommitted '
743
'changes \\(See brz status\\)\\.',]
738
'changes \(See bzr status\)\.',]
744
739
_default_additional_error = 'Use --no-strict to force the push.\n'
745
740
_default_additional_warning = 'Uncommitted changes will not be pushed.'
823
818
def _uncommitted_changes(self):
824
819
self.make_local_branch_and_tree()
825
820
# Make a change without committing it
826
self.build_tree_contents([('local/file', b'in progress')])
821
self.build_tree_contents([('local/file', 'in progress')])
828
823
def _pending_merges(self):
829
824
self.make_local_branch_and_tree()
830
825
# Create 'other' branch containing a new file
831
other_bzrdir = self.tree.controldir.sprout('other')
826
other_bzrdir = self.tree.bzrdir.sprout('other')
832
827
other_tree = other_bzrdir.open_workingtree()
833
self.build_tree_contents([('other/other-file', b'other')])
828
self.build_tree_contents([('other/other-file', 'other')])
834
829
other_tree.add('other-file')
835
other_tree.commit('other commit', rev_id=b'other')
830
other_tree.commit('other commit', rev_id='other')
836
831
# Merge and revert, leaving a pending merge
837
832
self.tree.merge_from_branch(other_tree.branch)
838
833
self.tree.revert(filenames=['other-file'], backups=False)
841
836
self.make_local_branch_and_tree()
842
837
self.run_bzr(['checkout', '--lightweight', 'local', 'checkout'])
843
838
# Make a change and commit it
844
self.build_tree_contents([('local/file', b'modified in local')])
845
self.tree.commit('modify file', rev_id=b'modified-in-local')
839
self.build_tree_contents([('local/file', 'modified in local')])
840
self.tree.commit('modify file', rev_id='modified-in-local')
846
841
# Exercise commands from the checkout directory
847
842
self._default_wd = 'checkout'
848
843
self._default_errors = ["Working tree is out of date, please run"
851
846
def test_push_default(self):
852
847
self.assertPushSucceeds([], with_warning=True)
888
883
def make_dummy_builder(self, relpath):
889
884
builder = self.make_branch_builder(
890
885
relpath, format=test_foreign.DummyForeignVcsDirFormat())
891
builder.build_snapshot(None,
892
[('add', ('', b'TREE_ROOT', 'directory', None)),
893
('add', ('foo', b'fooid', 'file', 'bar'))],
894
revision_id=b'revid')
886
builder.build_snapshot('revid', None,
887
[('add', ('', 'TREE_ROOT', 'directory', None)),
888
('add', ('foo', 'fooid', 'file', 'bar'))])
897
891
def test_no_roundtripping(self):
898
892
target_branch = self.make_dummy_builder('dp').get_branch()
899
893
source_tree = self.make_branch_and_tree("dc")
900
894
output, error = self.run_bzr("push -d dc dp", retcode=3)
901
self.assertEqual("", output)
902
self.assertEqual(error, "brz: ERROR: It is not possible to losslessly"
895
self.assertEquals("", output)
896
self.assertEquals(error, "bzr: ERROR: It is not possible to losslessly"
903
897
" push to dummy. You may want to use dpush instead.\n")
908
902
def test_push_log_format(self):
909
903
self.run_script("""
911
905
Created a standalone tree (format: 2a)
913
907
$ echo foo > file
916
$ brz commit -m 'we need some foo'
910
$ bzr commit -m 'we need some foo'
917
911
2>Committing to:...trunk/
919
913
2>Committed revision 1.
920
$ brz init ../feature
914
$ bzr init ../feature
921
915
Created a standalone tree (format: 2a)
922
$ brz push -v ../feature -Olog_format=line
916
$ bzr push -v ../feature -Olog_format=line
924
918
1: jrandom@example.com ...we need some foo
925
919
2>All changes applied successfully.
929
923
def test_push_with_revspec(self):
930
924
self.run_script("""
932
926
Shared repository with trees (format: 2a)
934
928
shared repository: .
936
930
Created a repository tree (format: 2a)
937
931
Using shared repository...
939
$ brz commit -m 'first rev' --unchanged
933
$ bzr commit -m 'first rev' --unchanged
940
934
2>Committing to:...trunk/
941
935
2>Committed revision 1.
942
936
$ echo foo > file
945
$ brz commit -m 'we need some foo'
939
$ bzr commit -m 'we need some foo'
946
940
2>Committing to:...trunk/
948
942
2>Committed revision 2.
949
$ brz push -r 1 ../other
943
$ bzr push -r 1 ../other
950
944
2>Created new branch.
951
$ brz st ../other # checking that file is not created (#484516)
945
$ bzr st ../other # checking that file is not created (#484516)