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."""
30
from bzrlib.tests import (
35
from bzrlib.tests.blackbox import test_push
36
from bzrlib.tests.scenarios import (
37
load_tests_apply_scenarios,
41
load_tests = load_tests_apply_scenarios
44
class TestDpush(tests.TestCaseWithTransport):
47
super(TestDpush, self).setUp()
48
test_foreign.register_dummy_foreign_for_test(self)
50
def make_dummy_builder(self, relpath):
51
builder = self.make_branch_builder(
52
relpath, format=test_foreign.DummyForeignVcsDirFormat())
53
builder.build_snapshot('revid', None,
54
[('add', ('', 'TREE_ROOT', 'directory', None)),
55
('add', ('foo', 'fooid', 'file', 'bar'))])
58
def test_dpush_native(self):
59
target_tree = self.make_branch_and_tree("dp")
60
source_tree = self.make_branch_and_tree("dc")
61
output, error = self.run_bzr("dpush -d dc dp", retcode=3)
62
self.assertEquals("", output)
63
self.assertContainsRe(error, 'in the same VCS, lossy push not necessary. Please use regular push.')
66
branch = self.make_dummy_builder('d').get_branch()
68
dc = branch.bzrdir.sprout('dc', force_new_repo=True)
69
self.build_tree(("dc/foo", "blaaaa"))
70
dc.open_workingtree().commit('msg')
72
script.run_script(self, """
74
2>Pushed up to revision 2.
78
def test_dpush_new(self):
79
b = self.make_dummy_builder('d').get_branch()
81
dc = b.bzrdir.sprout('dc', force_new_repo=True)
82
self.build_tree_contents([("dc/foofile", "blaaaa")])
83
dc_tree = dc.open_workingtree()
84
dc_tree.add("foofile")
87
script.run_script(self, '''
89
2>Pushed up to revision 2.
95
def test_dpush_wt_diff(self):
96
b = self.make_dummy_builder('d').get_branch()
98
dc = b.bzrdir.sprout('dc', force_new_repo=True)
99
self.build_tree_contents([("dc/foofile", "blaaaa")])
100
dc_tree = dc.open_workingtree()
101
dc_tree.add("foofile")
102
newrevid = dc_tree.commit('msg')
104
self.build_tree_contents([("dc/foofile", "blaaaal")])
105
script.run_script(self, '''
106
$ bzr dpush -d dc d --no-strict
107
2>Pushed up to revision 2.
109
self.assertFileEqual("blaaaal", "dc/foofile")
110
# if the dummy vcs wasn't that dummy we could uncomment the line below
111
# self.assertFileEqual("blaaaa", "d/foofile")
112
script.run_script(self, '''
118
def test_diverged(self):
119
builder = self.make_dummy_builder('d')
121
b = builder.get_branch()
123
dc = b.bzrdir.sprout('dc', force_new_repo=True)
124
dc_tree = dc.open_workingtree()
126
self.build_tree_contents([("dc/foo", "bar")])
127
dc_tree.commit('msg1')
129
builder.build_snapshot('revid2', None,
130
[('modify', ('fooid', 'blie'))])
132
output, error = self.run_bzr("dpush -d dc d", retcode=3)
133
self.assertEquals(output, "")
134
self.assertContainsRe(error, "have diverged")
137
class TestDpushStrictMixin(object):
140
test_foreign.register_dummy_foreign_for_test(self)
141
# Create an empty branch where we will be able to push
142
self.foreign = self.make_branch(
143
'to', format=test_foreign.DummyForeignVcsDirFormat())
145
def set_config_push_strict(self, value):
146
# set config var (any of bazaar.conf, locations.conf, branch.conf
148
conf = self.tree.branch.get_config()
149
conf.set_user_option('dpush_strict', value)
151
_default_command = ['dpush', '../to']
154
class TestDpushStrictWithoutChanges(TestDpushStrictMixin,
155
test_push.TestPushStrictWithoutChanges):
158
test_push.TestPushStrictWithoutChanges.setUp(self)
159
TestDpushStrictMixin.setUp(self)
162
class TestDpushStrictWithChanges(TestDpushStrictMixin,
163
test_push.TestPushStrictWithChanges):
165
scenarios = test_push.strict_push_change_scenarios
167
_changes_type = None # Set by load_tests
170
test_push.TestPushStrictWithChanges.setUp(self)
171
TestDpushStrictMixin.setUp(self)
173
def test_push_with_revision(self):
174
raise tests.TestNotApplicable('dpush does not handle --revision')