1
# Copyright (C) 2009, 2010, 2011 Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
"""Black-box tests for bzr dpush."""
24
from bzrlib.tests import (
28
from bzrlib.tests.blackbox import test_push
29
from bzrlib.tests.scenarios import (
30
load_tests_apply_scenarios,
34
load_tests = load_tests_apply_scenarios
37
class TestDpush(tests.TestCaseWithTransport):
40
super(TestDpush, self).setUp()
41
test_foreign.register_dummy_foreign_for_test(self)
43
def make_dummy_builder(self, relpath):
44
builder = self.make_branch_builder(
45
relpath, format=test_foreign.DummyForeignVcsDirFormat())
46
builder.build_snapshot('revid', None,
47
[('add', ('', 'TREE_ROOT', 'directory', None)),
48
('add', ('foo', 'fooid', 'file', 'bar'))])
51
def test_dpush_native(self):
52
target_tree = self.make_branch_and_tree("dp")
53
source_tree = self.make_branch_and_tree("dc")
54
output, error = self.run_bzr("dpush -d dc dp", retcode=3)
55
self.assertEquals("", output)
56
self.assertContainsRe(error,
57
'in the same VCS, lossy push not necessary. Please use regular '
61
branch = self.make_dummy_builder('d').get_branch()
63
dc = branch.bzrdir.sprout('dc', force_new_repo=True)
64
self.build_tree(("dc/foo", "blaaaa"))
65
dc.open_workingtree().commit('msg')
67
script.run_script(self, """
69
2>Doing on-the-fly conversion from DummyForeignVcsRepositoryFormat() to RepositoryFormat2a().
70
2>This may take some time. Upgrade the repositories to the same format for better performance.
71
2>Pushed up to revision 2.
75
def test_dpush_new(self):
76
b = self.make_dummy_builder('d').get_branch()
78
dc = b.bzrdir.sprout('dc', force_new_repo=True)
79
self.build_tree_contents([("dc/foofile", "blaaaa")])
80
dc_tree = dc.open_workingtree()
81
dc_tree.add("foofile")
84
script.run_script(self, '''
86
2>Doing on-the-fly conversion from DummyForeignVcsRepositoryFormat() to RepositoryFormat2a().
87
2>This may take some time. Upgrade the repositories to the same format for better performance.
88
2>Pushed up to revision 2.
94
def test_dpush_wt_diff(self):
95
b = self.make_dummy_builder('d').get_branch()
97
dc = b.bzrdir.sprout('dc', force_new_repo=True)
98
self.build_tree_contents([("dc/foofile", "blaaaa")])
99
dc_tree = dc.open_workingtree()
100
dc_tree.add("foofile")
101
newrevid = dc_tree.commit('msg')
103
self.build_tree_contents([("dc/foofile", "blaaaal")])
104
script.run_script(self, '''
105
$ bzr dpush -d dc d --no-strict
106
2>Doing on-the-fly conversion from DummyForeignVcsRepositoryFormat() to RepositoryFormat2a().
107
2>This may take some time. Upgrade the repositories to the same format for better performance.
108
2>Pushed up to revision 2.
110
self.assertFileEqual("blaaaal", "dc/foofile")
111
# if the dummy vcs wasn't that dummy we could uncomment the line below
112
# self.assertFileEqual("blaaaa", "d/foofile")
113
script.run_script(self, '''
119
def test_diverged(self):
120
builder = self.make_dummy_builder('d')
122
b = builder.get_branch()
124
dc = b.bzrdir.sprout('dc', force_new_repo=True)
125
dc_tree = dc.open_workingtree()
127
self.build_tree_contents([("dc/foo", "bar")])
128
dc_tree.commit('msg1')
130
builder.build_snapshot('revid2', None,
131
[('modify', ('fooid', 'blie'))])
133
output, error = self.run_bzr("dpush -d dc d", retcode=3)
134
self.assertEquals(output, "")
135
self.assertContainsRe(error, "have diverged")
138
class TestDpushStrictMixin(object):
141
test_foreign.register_dummy_foreign_for_test(self)
142
# Create an empty branch where we will be able to push
143
self.foreign = self.make_branch(
144
'to', format=test_foreign.DummyForeignVcsDirFormat())
146
def set_config_push_strict(self, value):
147
# set config var (any of bazaar.conf, locations.conf, branch.conf
149
conf = self.tree.branch.get_config_stack()
150
conf.set('dpush_strict', value)
152
_default_command = ['dpush', '../to']
155
class TestDpushStrictWithoutChanges(TestDpushStrictMixin,
156
test_push.TestPushStrictWithoutChanges):
159
test_push.TestPushStrictWithoutChanges.setUp(self)
160
TestDpushStrictMixin.setUp(self)
163
class TestDpushStrictWithChanges(TestDpushStrictMixin,
164
test_push.TestPushStrictWithChanges):
166
scenarios = test_push.strict_push_change_scenarios
168
_changes_type = None # Set by load_tests
171
test_push.TestPushStrictWithChanges.setUp(self)
172
TestDpushStrictMixin.setUp(self)
174
def test_push_with_revision(self):
175
raise tests.TestNotApplicable('dpush does not handle --revision')