33
34
from bzrlib.repofmt import knitrepo
34
35
from bzrlib.tests import (
41
from bzrlib.tests.matchers import ContainsNoVfsCalls
40
42
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)
45
load_tests = scenarios.load_tests_apply_scenarios
67
48
class TestPush(tests.TestCaseWithTransport):
76
57
['push', public_url],
77
58
working_dir='source')
60
def test_push_suggests_parent_alias(self):
61
"""Push suggests using :parent if there is a known parent branch."""
62
tree_a = self.make_branch_and_tree('a')
63
tree_a.commit('this is a commit')
64
tree_b = self.make_branch_and_tree('b')
66
# If there is no parent location set, :parent isn't mentioned.
67
out = self.run_bzr('push', working_dir='a', retcode=3)
69
('','bzr: ERROR: No push location known or specified.\n'))
71
# If there is a parent location set, the error suggests :parent.
72
tree_a.branch.set_parent(tree_b.branch.base)
73
out = self.run_bzr('push', working_dir='a', retcode=3)
75
('','bzr: ERROR: No push location known or specified. '
76
'To push to the parent branch '
77
'(at %s), use \'bzr push :parent\'.\n' %
78
urlutils.unescape_for_display(tree_b.branch.base, 'utf-8')))
79
80
def test_push_remember(self):
80
81
"""Push changes from one branch to another and test push location."""
81
82
transport = self.get_transport()
100
101
# test push for failure without push location set
101
102
out = self.run_bzr('push', working_dir='branch_a', retcode=3)
102
self.assertEquals(out,
103
self.assertEqual(out,
103
104
('','bzr: ERROR: No push location known or specified.\n'))
105
106
# test not remembered if cannot actually push
106
107
self.run_bzr('push path/which/doesnt/exist',
107
108
working_dir='branch_a', retcode=3)
108
109
out = self.run_bzr('push', working_dir='branch_a', retcode=3)
110
111
('', 'bzr: ERROR: No push location known or specified.\n'),
113
114
# test implicit --remember when no push location set, push fails
114
115
out = self.run_bzr('push ../branch_b',
115
116
working_dir='branch_a', retcode=3)
116
self.assertEquals(out,
117
self.assertEqual(out,
117
118
('','bzr: ERROR: These branches have diverged. '
118
119
'See "bzr help diverged-branches" for more information.\n'))
119
self.assertEquals(osutils.abspath(branch_a.get_push_location()),
120
# Refresh the branch as 'push' modified it
121
branch_a = branch_a.bzrdir.open_branch()
122
self.assertEqual(osutils.abspath(branch_a.get_push_location()),
120
123
osutils.abspath(branch_b.bzrdir.root_transport.base))
122
125
# test implicit --remember after resolving previous failure
123
126
uncommit.uncommit(branch=branch_b, tree=tree_b)
124
127
transport.delete('branch_b/c')
125
128
out, err = self.run_bzr('push', working_dir='branch_a')
129
# Refresh the branch as 'push' modified it
130
branch_a = branch_a.bzrdir.open_branch()
126
131
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
132
self.assertEqual(err,
133
'Using saved push location: %s\n'
131
134
'All changes applied successfully.\n'
132
'Pushed up to revision 2.\n')
135
'Pushed up to revision 2.\n'
136
% urlutils.local_path_from_url(path))
133
137
self.assertEqual(path,
134
138
branch_b.bzrdir.root_transport.base)
135
139
# test explicit --remember
136
140
self.run_bzr('push ../branch_c --remember', working_dir='branch_a')
137
self.assertEquals(branch_a.get_push_location(),
141
# Refresh the branch as 'push' modified it
142
branch_a = branch_a.bzrdir.open_branch()
143
self.assertEqual(branch_a.get_push_location(),
138
144
branch_c.bzrdir.root_transport.base)
140
146
def test_push_without_tree(self):
146
152
b2 = branch.Branch.open('pushed-location')
147
153
self.assertEndsWith(b2.base, 'pushed-location/')
155
def test_push_no_tree(self):
156
# bzr push --no-tree of a branch with working trees
157
b = self.make_branch_and_tree('push-from')
158
self.build_tree(['push-from/file'])
161
out, err = self.run_bzr('push --no-tree -d push-from push-to')
162
self.assertEqual('', out)
163
self.assertEqual('Created new branch.\n', err)
164
self.assertPathDoesNotExist('push-to/file')
149
166
def test_push_new_branch_revision_count(self):
150
167
# bzr push of a branch with revisions to a new location
151
168
# should print the number of revisions equal to the length of the
158
175
self.assertEqual('', out)
159
176
self.assertEqual('Created new branch.\n', err)
178
def test_push_quiet(self):
179
# test that using -q makes output quiet
180
t = self.make_branch_and_tree('tree')
181
self.build_tree(['tree/file'])
184
self.run_bzr('push -d tree pushed-to')
185
# Refresh the branch as 'push' modified it and get the push location
186
push_loc = t.branch.bzrdir.open_branch().get_push_location()
187
out, err = self.run_bzr('push', working_dir="tree")
188
self.assertEqual('Using saved push location: %s\n'
189
'No new revisions or tags to push.\n' %
190
urlutils.local_path_from_url(push_loc), err)
191
out, err = self.run_bzr('push -q', working_dir="tree")
192
self.assertEqual('', out)
193
self.assertEqual('', err)
161
195
def test_push_only_pushes_history(self):
162
196
# Knit branches should only push the history for the current revision.
163
197
format = bzrdir.BzrDirMetaFormat1()
208
242
t.commit(allow_pointless=True,
209
243
message='first commit')
210
244
self.run_bzr('push -d from to-one')
211
self.failUnlessExists('to-one')
245
self.assertPathExists('to-one')
212
246
self.run_bzr('push -d %s %s'
213
247
% tuple(map(urlutils.local_path_to_url, ['from', 'to-two'])))
214
self.failUnlessExists('to-two')
248
self.assertPathExists('to-two')
250
def test_push_repository_no_branch_doesnt_fetch_all_revs(self):
251
# See https://bugs.launchpad.net/bzr/+bug/465517
252
target_repo = self.make_repository('target')
253
source = self.make_branch_builder('source')
254
source.start_series()
255
source.build_snapshot('A', None, [
256
('add', ('', 'root-id', 'directory', None))])
257
source.build_snapshot('B', ['A'], [])
258
source.build_snapshot('C', ['A'], [])
259
source.finish_series()
260
self.run_bzr('push target -d source')
261
self.addCleanup(target_repo.lock_read().unlock)
262
# We should have pushed 'C', but not 'B', since it isn't in the
264
self.assertEqual([('A',), ('C',)], sorted(target_repo.revisions.keys()))
216
266
def test_push_smart_non_stacked_streaming_acceptance(self):
217
267
self.setup_smart_server_with_call_log()
225
275
# become necessary for this use case. Please do not adjust this number
226
276
# upwards without agreement from bzr's network support maintainers.
227
277
self.assertLength(9, self.hpss_calls)
278
self.assertLength(1, self.hpss_connections)
279
self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
229
281
def test_push_smart_stacked_streaming_acceptance(self):
230
282
self.setup_smart_server_with_call_log()
240
292
# being too low. If rpc_count increases, more network roundtrips have
241
293
# become necessary for this use case. Please do not adjust this number
242
294
# upwards without agreement from bzr's network support maintainers.
243
self.assertLength(14, self.hpss_calls)
295
self.assertLength(15, self.hpss_calls)
296
self.assertLength(1, self.hpss_connections)
297
self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
244
298
remote = branch.Branch.open('public')
245
299
self.assertEndsWith(remote.get_stacked_on_url(), '/parent')
257
311
# become necessary for this use case. Please do not adjust this number
258
312
# upwards without agreement from bzr's network support maintainers.
259
313
self.assertLength(11, self.hpss_calls)
314
self.assertLength(1, self.hpss_connections)
315
self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
261
317
def test_push_smart_incremental_acceptance(self):
262
318
self.setup_smart_server_with_call_log()
273
329
# become necessary for this use case. Please do not adjust this number
274
330
# upwards without agreement from bzr's network support maintainers.
275
331
self.assertLength(11, self.hpss_calls)
332
self.assertLength(1, self.hpss_connections)
333
self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
277
335
def test_push_smart_with_default_stacking_url_path_segment(self):
278
336
# If the default stacked-on location is a path element then branches
455
515
trunk_public = self.make_branch('public_trunk', format='1.9')
456
516
trunk_public.pull(trunk_tree.branch)
457
517
trunk_public_url = self.get_readonly_url('public_trunk')
458
trunk_tree.branch.set_public_branch(trunk_public_url)
518
br = trunk_tree.branch
519
br.set_public_branch(trunk_public_url)
459
520
# now we do a stacked push, which should determine the public location
461
522
out, err = self.run_bzr(['push', '--stacked',
554
615
self.assertEqual('', out)
555
616
self.assertEqual('Created new branch.\n', err)
618
def test_overwrite_tags(self):
619
"""--overwrite-tags only overwrites tags, not revisions."""
620
from_tree = self.make_branch_and_tree('from')
621
from_tree.branch.tags.set_tag("mytag", "somerevid")
622
to_tree = self.make_branch_and_tree('to')
623
to_tree.branch.tags.set_tag("mytag", "anotherrevid")
624
revid1 = to_tree.commit('my commit')
625
out = self.run_bzr(['push', '-d', 'from', 'to'])
626
self.assertEqual(out,
627
('Conflicting tags:\n mytag\n', 'No new revisions to push.\n'))
628
out = self.run_bzr(['push', '-d', 'from', '--overwrite-tags', 'to'])
629
self.assertEqual(out, ('', '1 tag updated.\n'))
630
self.assertEqual(to_tree.branch.tags.lookup_tag('mytag'),
632
self.assertEqual(to_tree.branch.last_revision(), revid1)
558
635
class RedirectingMemoryTransport(memory.MemoryTransport):
652
729
self.tree.commit('modify file', rev_id='modified')
654
731
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)
732
br = branch.Branch.open('local')
733
br.get_config_stack().set('push_strict', value)
660
735
_default_command = ['push', '../to']
661
736
_default_wd = 'local'
662
737
_default_errors = ['Working tree ".*/local/" has uncommitted '
663
738
'changes \(See bzr status\)\.',]
664
_default_pushed_revid = 'modified'
739
_default_additional_error = 'Use --no-strict to force the push.\n'
740
_default_additional_warning = 'Uncommitted changes will not be pushed.'
666
743
def assertPushFails(self, args):
667
self.run_bzr_error(self._default_errors, self._default_command + args,
668
working_dir=self._default_wd, retcode=3)
744
out, err = self.run_bzr_error(self._default_errors,
745
self._default_command + args,
746
working_dir=self._default_wd, retcode=3)
747
self.assertContainsRe(err, self._default_additional_error)
670
def assertPushSucceeds(self, args, pushed_revid=None):
671
self.run_bzr(self._default_command + args,
672
working_dir=self._default_wd)
673
if pushed_revid is None:
674
pushed_revid = self._default_pushed_revid
675
tree_to = workingtree.WorkingTree.open('to')
676
repo_to = tree_to.branch.repository
677
self.assertTrue(repo_to.has_revision(pushed_revid))
678
self.assertEqual(tree_to.branch.last_revision_info()[1], pushed_revid)
749
def assertPushSucceeds(self, args, with_warning=False, revid_to_push=None):
751
error_regexes = self._default_errors
754
out, err = self.run_bzr(self._default_command + args,
755
working_dir=self._default_wd,
756
error_regexes=error_regexes)
758
self.assertContainsRe(err, self._default_additional_warning)
760
self.assertNotContainsRe(err, self._default_additional_warning)
761
branch_from = branch.Branch.open(self._default_wd)
762
if revid_to_push is None:
763
revid_to_push = branch_from.last_revision()
764
branch_to = branch.Branch.open('to')
765
repo_to = branch_to.repository
766
self.assertTrue(repo_to.has_revision(revid_to_push))
767
self.assertEqual(revid_to_push, branch_to.last_revision())
704
793
self.assertPushSucceeds([])
796
strict_push_change_scenarios = [
798
dict(_changes_type= '_uncommitted_changes')),
800
dict(_changes_type= '_pending_merges')),
801
('out-of-sync-trees',
802
dict(_changes_type= '_out_of_sync_trees')),
707
806
class TestPushStrictWithChanges(tests.TestCaseWithTransport,
708
807
TestPushStrictMixin):
809
scenarios = strict_push_change_scenarios
710
810
_changes_type = None # Set by load_tests
742
842
self._default_wd = 'checkout'
743
843
self._default_errors = ["Working tree is out of date, please run"
744
844
" 'bzr update'\.",]
745
self._default_pushed_revid = 'modified-in-local'
747
846
def test_push_default(self):
748
self.assertPushFails([])
847
self.assertPushSucceeds([], with_warning=True)
750
849
def test_push_with_revision(self):
751
self.assertPushSucceeds(['-r', 'revid:added'], pushed_revid='added')
850
self.assertPushSucceeds(['-r', 'revid:added'], revid_to_push='added')
753
852
def test_push_no_strict(self):
754
853
self.assertPushSucceeds(['--no-strict'])
793
892
target_branch = self.make_dummy_builder('dp').get_branch()
794
893
source_tree = self.make_branch_and_tree("dc")
795
894
output, error = self.run_bzr("push -d dc dp", retcode=3)
796
self.assertEquals("", output)
797
self.assertEquals(error, "bzr: ERROR: It is not possible to losslessly"
895
self.assertEqual("", output)
896
self.assertEqual(error, "bzr: ERROR: It is not possible to losslessly"
798
897
" push to dummy. You may want to use dpush instead.\n")
900
class TestPushOutput(script.TestCaseWithTransportAndScript):
902
def test_push_log_format(self):
905
Created a standalone tree (format: 2a)
910
$ bzr commit -m 'we need some foo'
911
2>Committing to:...trunk/
913
2>Committed revision 1.
914
$ bzr init ../feature
915
Created a standalone tree (format: 2a)
916
$ bzr push -v ../feature -Olog_format=line
918
1: jrandom@example.com ...we need some foo
919
2>All changes applied successfully.
920
2>Pushed up to revision 1.
923
def test_push_with_revspec(self):
926
Shared repository with trees (format: 2a)
930
Created a repository tree (format: 2a)
931
Using shared repository...
933
$ bzr commit -m 'first rev' --unchanged
934
2>Committing to:...trunk/
935
2>Committed revision 1.
939
$ bzr commit -m 'we need some foo'
940
2>Committing to:...trunk/
942
2>Committed revision 2.
943
$ bzr push -r 1 ../other
944
2>Created new branch.
945
$ bzr st ../other # checking that file is not created (#484516)