1
# Copyright (C) 2009-2012 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."""
25
from bzrlib.tests import (
29
from bzrlib.tests.blackbox import test_push
30
from bzrlib.tests.scenarios import (
31
load_tests_apply_scenarios,
35
load_tests = load_tests_apply_scenarios
38
class TestDpush(tests.TestCaseWithTransport):
41
super(TestDpush, self).setUp()
42
test_foreign.register_dummy_foreign_for_test(self)
44
def make_dummy_builder(self, relpath):
45
builder = self.make_branch_builder(
46
relpath, format=test_foreign.DummyForeignVcsDirFormat())
47
builder.build_snapshot('revid', None,
48
[('add', ('', 'TREE_ROOT', 'directory', None)),
49
('add', ('foo', 'fooid', 'file', 'bar'))])
52
def test_dpush_native(self):
53
target_tree = self.make_branch_and_tree("dp")
54
source_tree = self.make_branch_and_tree("dc")
55
output, error = self.run_bzr("dpush -d dc dp", retcode=3)
56
self.assertEquals("", output)
57
self.assertContainsRe(error,
58
'in the same VCS, lossy push not necessary. Please use regular '
62
branch = self.make_dummy_builder('d').get_branch()
64
dc = branch.bzrdir.sprout('dc', force_new_repo=True)
65
self.build_tree(("dc/foo", "blaaaa"))
66
dc.open_workingtree().commit('msg')
68
script.run_script(self, """
70
2>Doing on-the-fly conversion from DummyForeignVcsRepositoryFormat() to RepositoryFormat2a().
71
2>This may take some time. Upgrade the repositories to the same format for better performance.
72
2>Pushed up to revision 2.
76
def test_dpush_new(self):
77
b = self.make_dummy_builder('d').get_branch()
79
dc = b.bzrdir.sprout('dc', force_new_repo=True)
80
self.build_tree_contents([("dc/foofile", "blaaaa")])
81
dc_tree = dc.open_workingtree()
82
dc_tree.add("foofile")
85
script.run_script(self, '''
87
2>Doing on-the-fly conversion from DummyForeignVcsRepositoryFormat() to RepositoryFormat2a().
88
2>This may take some time. Upgrade the repositories to the same format for better performance.
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>Doing on-the-fly conversion from DummyForeignVcsRepositoryFormat() to RepositoryFormat2a().
108
2>This may take some time. Upgrade the repositories to the same format for better performance.
109
2>Pushed up to revision 2.
111
self.assertFileEqual("blaaaal", "dc/foofile")
112
# if the dummy vcs wasn't that dummy we could uncomment the line below
113
# self.assertFileEqual("blaaaa", "d/foofile")
114
script.run_script(self, '''
120
def test_diverged(self):
121
builder = self.make_dummy_builder('d')
123
b = builder.get_branch()
125
dc = b.bzrdir.sprout('dc', force_new_repo=True)
126
dc_tree = dc.open_workingtree()
128
self.build_tree_contents([("dc/foo", "bar")])
129
dc_tree.commit('msg1')
131
builder.build_snapshot('revid2', None,
132
[('modify', ('fooid', 'blie'))])
134
output, error = self.run_bzr("dpush -d dc d", retcode=3)
135
self.assertEquals(output, "")
136
self.assertContainsRe(error, "have diverged")
139
class TestDpushStrictMixin(object):
142
test_foreign.register_dummy_foreign_for_test(self)
143
# Create an empty branch where we will be able to push
144
self.foreign = self.make_branch(
145
'to', format=test_foreign.DummyForeignVcsDirFormat())
147
def set_config_push_strict(self, value):
148
br = branch.Branch.open('local')
149
br.get_config_stack().set('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')