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 (
40
41
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)
44
load_tests = scenarios.load_tests_apply_scenarios
67
47
class TestPush(tests.TestCaseWithTransport):
76
56
['push', public_url],
77
57
working_dir='source')
59
def test_push_suggests_parent_alias(self):
60
"""Push suggests using :parent if there is a known parent branch."""
61
tree_a = self.make_branch_and_tree('a')
62
tree_a.commit('this is a commit')
63
tree_b = self.make_branch_and_tree('b')
65
# If there is no parent location set, :parent isn't mentioned.
66
out = self.run_bzr('push', working_dir='a', retcode=3)
67
self.assertEquals(out,
68
('','bzr: ERROR: No push location known or specified.\n'))
70
# If there is a parent location set, the error suggests :parent.
71
tree_a.branch.set_parent(tree_b.branch.base)
72
out = self.run_bzr('push', working_dir='a', retcode=3)
73
self.assertEquals(out,
74
('','bzr: ERROR: No push location known or specified. '
75
'To push to the parent branch '
76
'(at %s), use \'bzr push :parent\'.\n' %
77
urlutils.unescape_for_display(tree_b.branch.base, 'utf-8')))
79
79
def test_push_remember(self):
80
80
"""Push changes from one branch to another and test push location."""
81
81
transport = self.get_transport()
124
124
transport.delete('branch_b/c')
125
125
out, err = self.run_bzr('push', working_dir='branch_a')
126
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))
130
127
self.assertEqual(err,
128
'Using saved push location: %s\n'
131
129
'All changes applied successfully.\n'
132
'Pushed up to revision 2.\n')
130
'Pushed up to revision 2.\n'
131
% urlutils.local_path_from_url(path))
133
132
self.assertEqual(path,
134
133
branch_b.bzrdir.root_transport.base)
135
134
# test explicit --remember
146
145
b2 = branch.Branch.open('pushed-location')
147
146
self.assertEndsWith(b2.base, 'pushed-location/')
148
def test_push_no_tree(self):
149
# bzr push --no-tree of a branch with working trees
150
b = self.make_branch_and_tree('push-from')
151
self.build_tree(['push-from/file'])
154
out, err = self.run_bzr('push --no-tree -d push-from push-to')
155
self.assertEqual('', out)
156
self.assertEqual('Created new branch.\n', err)
157
self.assertPathDoesNotExist('push-to/file')
149
159
def test_push_new_branch_revision_count(self):
150
160
# bzr push of a branch with revisions to a new location
151
161
# should print the number of revisions equal to the length of the
158
168
self.assertEqual('', out)
159
169
self.assertEqual('Created new branch.\n', err)
171
def test_push_quiet(self):
172
# test that using -q makes output quiet
173
t = self.make_branch_and_tree('tree')
174
self.build_tree(['tree/file'])
177
self.run_bzr('push -d tree pushed-to')
178
path = t.branch.get_push_location()
179
out, err = self.run_bzr('push', working_dir="tree")
180
self.assertEqual('Using saved push location: %s\n'
181
'No new revisions or tags to push.\n' %
182
urlutils.local_path_from_url(path), err)
183
out, err = self.run_bzr('push -q', working_dir="tree")
184
self.assertEqual('', out)
185
self.assertEqual('', err)
161
187
def test_push_only_pushes_history(self):
162
188
# Knit branches should only push the history for the current revision.
163
189
format = bzrdir.BzrDirMetaFormat1()
168
194
def make_shared_tree(path):
169
195
shared_repo.bzrdir.root_transport.mkdir(path)
170
shared_repo.bzrdir.create_branch_convenience('repo/' + path)
196
controldir.ControlDir.create_branch_convenience('repo/' + path)
171
197
return workingtree.WorkingTree.open('repo/' + path)
172
198
tree_a = make_shared_tree('a')
173
199
self.build_tree(['repo/a/file'])
208
234
t.commit(allow_pointless=True,
209
235
message='first commit')
210
236
self.run_bzr('push -d from to-one')
211
self.failUnlessExists('to-one')
237
self.assertPathExists('to-one')
212
238
self.run_bzr('push -d %s %s'
213
239
% tuple(map(urlutils.local_path_to_url, ['from', 'to-two'])))
214
self.failUnlessExists('to-two')
240
self.assertPathExists('to-two')
242
def test_push_repository_no_branch_doesnt_fetch_all_revs(self):
243
# See https://bugs.launchpad.net/bzr/+bug/465517
244
target_repo = self.make_repository('target')
245
source = self.make_branch_builder('source')
246
source.start_series()
247
source.build_snapshot('A', None, [
248
('add', ('', 'root-id', 'directory', None))])
249
source.build_snapshot('B', ['A'], [])
250
source.build_snapshot('C', ['A'], [])
251
source.finish_series()
252
self.run_bzr('push target -d source')
253
self.addCleanup(target_repo.lock_read().unlock)
254
# We should have pushed 'C', but not 'B', since it isn't in the
256
self.assertEqual([('A',), ('C',)], sorted(target_repo.revisions.keys()))
216
258
def test_push_smart_non_stacked_streaming_acceptance(self):
217
259
self.setup_smart_server_with_call_log()
317
359
working_dir='tree')
318
360
new_tree = workingtree.WorkingTree.open('new/tree')
319
361
self.assertEqual(tree.last_revision(), new_tree.last_revision())
320
self.failUnlessExists('new/tree/a')
362
self.assertPathExists('new/tree/a')
322
364
def test_push_use_existing(self):
323
365
"""'bzr push --use-existing-dir' can push into an existing dir.
338
380
new_tree = workingtree.WorkingTree.open('target')
339
381
self.assertEqual(tree.last_revision(), new_tree.last_revision())
340
382
# The push should have created target/a
341
self.failUnlessExists('target/a')
383
self.assertPathExists('target/a')
343
385
def test_push_use_existing_into_empty_bzrdir(self):
344
386
"""'bzr push --use-existing-dir' into a dir with an empty .bzr dir
654
696
def set_config_push_strict(self, value):
655
697
# 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)
699
conf = self.tree.branch.get_config_stack()
700
conf.set('push_strict', value)
660
702
_default_command = ['push', '../to']
661
703
_default_wd = 'local'
718
760
self.assertPushSucceeds([])
763
strict_push_change_scenarios = [
765
dict(_changes_type= '_uncommitted_changes')),
767
dict(_changes_type= '_pending_merges')),
768
('out-of-sync-trees',
769
dict(_changes_type= '_out_of_sync_trees')),
721
773
class TestPushStrictWithChanges(tests.TestCaseWithTransport,
722
774
TestPushStrictMixin):
776
scenarios = strict_push_change_scenarios
724
777
_changes_type = None # Set by load_tests
788
841
self.assertPushSucceeds([])
791
class TestPushForeign(blackbox.ExternalBase):
844
class TestPushForeign(tests.TestCaseWithTransport):
794
847
super(TestPushForeign, self).setUp()
809
862
self.assertEquals("", output)
810
863
self.assertEquals(error, "bzr: ERROR: It is not possible to losslessly"
811
864
" push to dummy. You may want to use dpush instead.\n")
867
class TestPushOutput(script.TestCaseWithTransportAndScript):
869
def test_push_log_format(self):
872
Created a standalone tree (format: 2a)
877
$ bzr commit -m 'we need some foo'
878
2>Committing to:...trunk/
880
2>Committed revision 1.
881
$ bzr init ../feature
882
Created a standalone tree (format: 2a)
883
$ bzr push -v ../feature -Olog_format=line
885
1: jrandom@example.com ...we need some foo
886
2>All changes applied successfully.
887
2>Pushed up to revision 1.