1
# Copyright (C) 2006-2010 Canonical Ltd
1
# Copyright (C) 2006-2011 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
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)
68
self.assertEquals(out,
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)
74
self.assertEquals(out,
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()
124
125
transport.delete('branch_b/c')
125
126
out, err = self.run_bzr('push', working_dir='branch_a')
126
127
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
128
self.assertEqual(err,
129
'Using saved push location: %s\n'
131
130
'All changes applied successfully.\n'
132
'Pushed up to revision 2.\n')
131
'Pushed up to revision 2.\n'
132
% urlutils.local_path_from_url(path))
133
133
self.assertEqual(path,
134
134
branch_b.bzrdir.root_transport.base)
135
135
# test explicit --remember
146
146
b2 = branch.Branch.open('pushed-location')
147
147
self.assertEndsWith(b2.base, 'pushed-location/')
149
def test_push_no_tree(self):
150
# bzr push --no-tree of a branch with working trees
151
b = self.make_branch_and_tree('push-from')
152
self.build_tree(['push-from/file'])
155
out, err = self.run_bzr('push --no-tree -d push-from push-to')
156
self.assertEqual('', out)
157
self.assertEqual('Created new branch.\n', err)
158
self.assertPathDoesNotExist('push-to/file')
149
160
def test_push_new_branch_revision_count(self):
150
161
# bzr push of a branch with revisions to a new location
151
162
# should print the number of revisions equal to the length of the
158
169
self.assertEqual('', out)
159
170
self.assertEqual('Created new branch.\n', err)
172
def test_push_quiet(self):
173
# test that using -q makes output quiet
174
t = self.make_branch_and_tree('tree')
175
self.build_tree(['tree/file'])
178
self.run_bzr('push -d tree pushed-to')
179
path = t.branch.get_push_location()
180
out, err = self.run_bzr('push', working_dir="tree")
181
self.assertEqual('Using saved push location: %s\n'
182
'No new revisions or tags to push.\n' %
183
urlutils.local_path_from_url(path), err)
184
out, err = self.run_bzr('push -q', working_dir="tree")
185
self.assertEqual('', out)
186
self.assertEqual('', err)
161
188
def test_push_only_pushes_history(self):
162
189
# Knit branches should only push the history for the current revision.
163
190
format = bzrdir.BzrDirMetaFormat1()
168
195
def make_shared_tree(path):
169
196
shared_repo.bzrdir.root_transport.mkdir(path)
170
shared_repo.bzrdir.create_branch_convenience('repo/' + path)
197
controldir.ControlDir.create_branch_convenience('repo/' + path)
171
198
return workingtree.WorkingTree.open('repo/' + path)
172
199
tree_a = make_shared_tree('a')
173
200
self.build_tree(['repo/a/file'])
208
235
t.commit(allow_pointless=True,
209
236
message='first commit')
210
237
self.run_bzr('push -d from to-one')
211
self.failUnlessExists('to-one')
238
self.assertPathExists('to-one')
212
239
self.run_bzr('push -d %s %s'
213
240
% tuple(map(urlutils.local_path_to_url, ['from', 'to-two'])))
214
self.failUnlessExists('to-two')
241
self.assertPathExists('to-two')
243
def test_push_repository_no_branch_doesnt_fetch_all_revs(self):
244
# See https://bugs.launchpad.net/bzr/+bug/465517
245
target_repo = self.make_repository('target')
246
source = self.make_branch_builder('source')
247
source.start_series()
248
source.build_snapshot('A', None, [
249
('add', ('', 'root-id', 'directory', None))])
250
source.build_snapshot('B', ['A'], [])
251
source.build_snapshot('C', ['A'], [])
252
source.finish_series()
253
self.run_bzr('push target -d source')
254
self.addCleanup(target_repo.lock_read().unlock)
255
# We should have pushed 'C', but not 'B', since it isn't in the
257
self.assertEqual([('A',), ('C',)], sorted(target_repo.revisions.keys()))
216
259
def test_push_smart_non_stacked_streaming_acceptance(self):
217
260
self.setup_smart_server_with_call_log()
225
268
# become necessary for this use case. Please do not adjust this number
226
269
# upwards without agreement from bzr's network support maintainers.
227
270
self.assertLength(9, self.hpss_calls)
271
self.assertLength(1, self.hpss_connections)
272
self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
229
274
def test_push_smart_stacked_streaming_acceptance(self):
230
275
self.setup_smart_server_with_call_log()
241
286
# become necessary for this use case. Please do not adjust this number
242
287
# upwards without agreement from bzr's network support maintainers.
243
288
self.assertLength(14, self.hpss_calls)
289
self.assertLength(1, self.hpss_connections)
290
self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
244
291
remote = branch.Branch.open('public')
245
292
self.assertEndsWith(remote.get_stacked_on_url(), '/parent')
257
304
# become necessary for this use case. Please do not adjust this number
258
305
# upwards without agreement from bzr's network support maintainers.
259
306
self.assertLength(11, self.hpss_calls)
307
self.assertLength(1, self.hpss_connections)
308
self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
261
310
def test_push_smart_incremental_acceptance(self):
262
311
self.setup_smart_server_with_call_log()
273
322
# become necessary for this use case. Please do not adjust this number
274
323
# upwards without agreement from bzr's network support maintainers.
275
324
self.assertLength(11, self.hpss_calls)
325
self.assertLength(1, self.hpss_connections)
326
self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
277
328
def test_push_smart_with_default_stacking_url_path_segment(self):
278
329
# If the default stacked-on location is a path element then branches
317
368
working_dir='tree')
318
369
new_tree = workingtree.WorkingTree.open('new/tree')
319
370
self.assertEqual(tree.last_revision(), new_tree.last_revision())
320
self.failUnlessExists('new/tree/a')
371
self.assertPathExists('new/tree/a')
322
373
def test_push_use_existing(self):
323
374
"""'bzr push --use-existing-dir' can push into an existing dir.
338
389
new_tree = workingtree.WorkingTree.open('target')
339
390
self.assertEqual(tree.last_revision(), new_tree.last_revision())
340
391
# The push should have created target/a
341
self.failUnlessExists('target/a')
392
self.assertPathExists('target/a')
343
394
def test_push_use_existing_into_empty_bzrdir(self):
344
395
"""'bzr push --use-existing-dir' into a dir with an empty .bzr dir
654
705
def set_config_push_strict(self, value):
655
706
# 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)
708
conf = self.tree.branch.get_config_stack()
709
conf.set('push_strict', value)
660
711
_default_command = ['push', '../to']
661
712
_default_wd = 'local'
718
769
self.assertPushSucceeds([])
772
strict_push_change_scenarios = [
774
dict(_changes_type= '_uncommitted_changes')),
776
dict(_changes_type= '_pending_merges')),
777
('out-of-sync-trees',
778
dict(_changes_type= '_out_of_sync_trees')),
721
782
class TestPushStrictWithChanges(tests.TestCaseWithTransport,
722
783
TestPushStrictMixin):
785
scenarios = strict_push_change_scenarios
724
786
_changes_type = None # Set by load_tests
809
871
self.assertEquals("", output)
810
872
self.assertEquals(error, "bzr: ERROR: It is not possible to losslessly"
811
873
" push to dummy. You may want to use dpush instead.\n")
876
class TestPushOutput(script.TestCaseWithTransportAndScript):
878
def test_push_log_format(self):
881
Created a standalone tree (format: 2a)
886
$ bzr commit -m 'we need some foo'
887
2>Committing to:...trunk/
889
2>Committed revision 1.
890
$ bzr init ../feature
891
Created a standalone tree (format: 2a)
892
$ bzr push -v ../feature -Olog_format=line
894
1: jrandom@example.com ...we need some foo
895
2>All changes applied successfully.
896
2>Pushed up to revision 1.