1
# Copyright (C) 2006-2011 Canonical Ltd
1
# Copyright (C) 2006-2010 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
34
34
from bzrlib.tests import (
41
40
from bzrlib.transport import memory
44
load_tests = scenarios.load_tests_apply_scenarios
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)
47
67
class TestPush(tests.TestCaseWithTransport):
104
124
transport.delete('branch_b/c')
105
125
out, err = self.run_bzr('push', working_dir='branch_a')
106
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))
107
130
self.assertEqual(err,
108
'Using saved push location: %s\n'
109
131
'All changes applied successfully.\n'
110
'Pushed up to revision 2.\n'
111
% urlutils.local_path_from_url(path))
132
'Pushed up to revision 2.\n')
112
133
self.assertEqual(path,
113
134
branch_b.bzrdir.root_transport.base)
114
135
# test explicit --remember
125
146
b2 = branch.Branch.open('pushed-location')
126
147
self.assertEndsWith(b2.base, 'pushed-location/')
128
def test_push_no_tree(self):
129
# bzr push --no-tree of a branch with working trees
130
b = self.make_branch_and_tree('push-from')
131
self.build_tree(['push-from/file'])
134
out, err = self.run_bzr('push --no-tree -d push-from push-to')
135
self.assertEqual('', out)
136
self.assertEqual('Created new branch.\n', err)
137
self.assertPathDoesNotExist('push-to/file')
139
149
def test_push_new_branch_revision_count(self):
140
150
# bzr push of a branch with revisions to a new location
141
151
# should print the number of revisions equal to the length of the
148
158
self.assertEqual('', out)
149
159
self.assertEqual('Created new branch.\n', err)
151
def test_push_quiet(self):
152
# test that using -q makes output quiet
153
t = self.make_branch_and_tree('tree')
154
self.build_tree(['tree/file'])
157
self.run_bzr('push -d tree pushed-to')
158
path = t.branch.get_push_location()
159
out, err = self.run_bzr('push', working_dir="tree")
160
self.assertEqual('Using saved push location: %s\n'
161
'No new revisions or tags to push.\n' %
162
urlutils.local_path_from_url(path), err)
163
out, err = self.run_bzr('push -q', working_dir="tree")
164
self.assertEqual('', out)
165
self.assertEqual('', err)
167
161
def test_push_only_pushes_history(self):
168
162
# Knit branches should only push the history for the current revision.
169
163
format = bzrdir.BzrDirMetaFormat1()
214
208
t.commit(allow_pointless=True,
215
209
message='first commit')
216
210
self.run_bzr('push -d from to-one')
217
self.assertPathExists('to-one')
211
self.failUnlessExists('to-one')
218
212
self.run_bzr('push -d %s %s'
219
213
% tuple(map(urlutils.local_path_to_url, ['from', 'to-two'])))
220
self.assertPathExists('to-two')
222
def test_push_repository_no_branch_doesnt_fetch_all_revs(self):
223
# See https://bugs.launchpad.net/bzr/+bug/465517
224
target_repo = self.make_repository('target')
225
source = self.make_branch_builder('source')
226
source.start_series()
227
source.build_snapshot('A', None, [
228
('add', ('', 'root-id', 'directory', None))])
229
source.build_snapshot('B', ['A'], [])
230
source.build_snapshot('C', ['A'], [])
231
source.finish_series()
232
self.run_bzr('push target -d source')
233
self.addCleanup(target_repo.lock_read().unlock)
234
# We should have pushed 'C', but not 'B', since it isn't in the
236
self.assertEqual([('A',), ('C',)], sorted(target_repo.revisions.keys()))
214
self.failUnlessExists('to-two')
238
216
def test_push_smart_non_stacked_streaming_acceptance(self):
239
217
self.setup_smart_server_with_call_log()
262
240
# being too low. If rpc_count increases, more network roundtrips have
263
241
# become necessary for this use case. Please do not adjust this number
264
242
# upwards without agreement from bzr's network support maintainers.
265
self.assertLength(13, self.hpss_calls)
243
self.assertLength(14, self.hpss_calls)
266
244
remote = branch.Branch.open('public')
267
245
self.assertEndsWith(remote.get_stacked_on_url(), '/parent')
339
317
working_dir='tree')
340
318
new_tree = workingtree.WorkingTree.open('new/tree')
341
319
self.assertEqual(tree.last_revision(), new_tree.last_revision())
342
self.assertPathExists('new/tree/a')
320
self.failUnlessExists('new/tree/a')
344
322
def test_push_use_existing(self):
345
323
"""'bzr push --use-existing-dir' can push into an existing dir.
360
338
new_tree = workingtree.WorkingTree.open('target')
361
339
self.assertEqual(tree.last_revision(), new_tree.last_revision())
362
340
# The push should have created target/a
363
self.assertPathExists('target/a')
341
self.failUnlessExists('target/a')
365
343
def test_push_use_existing_into_empty_bzrdir(self):
366
344
"""'bzr push --use-existing-dir' into a dir with an empty .bzr dir
676
654
def set_config_push_strict(self, value):
677
655
# set config var (any of bazaar.conf, locations.conf, branch.conf
679
conf = self.tree.branch.get_config_stack()
680
conf.set('push_strict', value)
657
conf = self.tree.branch.get_config()
658
conf.set_user_option('push_strict', value)
682
660
_default_command = ['push', '../to']
683
661
_default_wd = 'local'
740
718
self.assertPushSucceeds([])
743
strict_push_change_scenarios = [
745
dict(_changes_type= '_uncommitted_changes')),
747
dict(_changes_type= '_pending_merges')),
748
('out-of-sync-trees',
749
dict(_changes_type= '_out_of_sync_trees')),
753
721
class TestPushStrictWithChanges(tests.TestCaseWithTransport,
754
722
TestPushStrictMixin):
756
scenarios = strict_push_change_scenarios
757
724
_changes_type = None # Set by load_tests