1
# Copyright (C) 2005, 2007, 2008, 2009 Canonical Ltd
1
# Copyright (C) 2009, 2010, 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
18
18
"""Black-box tests for bzr dpush."""
23
21
from bzrlib import (
30
24
from bzrlib.tests import (
34
28
from bzrlib.tests.blackbox import test_push
37
def load_tests(standard_tests, module, loader):
38
"""Multiply tests for the dpush command."""
39
result = loader.suiteClass()
41
# one for each king of change
42
changes_tests, remaining_tests = tests.split_suite_by_condition(
43
standard_tests, tests.condition_isinstance((
44
TestDpushStrictWithChanges,
48
dict(_changes_type= '_uncommitted_changes')),
50
dict(_changes_type= '_pending_merges')),
52
dict(_changes_type= '_out_of_sync_trees')),
54
tests.multiply_tests(changes_tests, changes_scenarios, result)
55
# No parametrization for the remaining tests
56
result.addTests(remaining_tests)
61
class TestDpush(blackbox.ExternalBase):
29
from bzrlib.tests.scenarios import (
30
load_tests_apply_scenarios,
34
load_tests = load_tests_apply_scenarios
37
class TestDpush(tests.TestCaseWithTransport):
64
40
super(TestDpush, self).setUp()
77
53
source_tree = self.make_branch_and_tree("dc")
78
54
output, error = self.run_bzr("dpush -d dc dp", retcode=3)
79
55
self.assertEquals("", output)
80
self.assertContainsRe(error, 'in the same VCS, lossy push not necessary. Please use regular push.')
56
self.assertContainsRe(error,
57
'in the same VCS, lossy push not necessary. Please use regular '
82
60
def test_dpush(self):
83
61
branch = self.make_dummy_builder('d').get_branch()
86
64
self.build_tree(("dc/foo", "blaaaa"))
87
65
dc.open_workingtree().commit('msg')
89
output, error = self.run_bzr("dpush -d dc d")
90
self.assertEquals(error, "Pushed up to revision 2.\n")
91
self.check_output("", "status dc")
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.
93
75
def test_dpush_new(self):
94
76
b = self.make_dummy_builder('d').get_branch()
99
81
dc_tree.add("foofile")
100
82
dc_tree.commit("msg")
102
self.check_output("", "dpush -d dc d")
103
self.check_output("2\n", "revno dc")
104
self.check_output("", "status dc")
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.
106
94
def test_dpush_wt_diff(self):
107
95
b = self.make_dummy_builder('d').get_branch()
113
101
newrevid = dc_tree.commit('msg')
115
103
self.build_tree_contents([("dc/foofile", "blaaaal")])
116
self.check_output("", "dpush -d dc d --no-strict")
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.
117
110
self.assertFileEqual("blaaaal", "dc/foofile")
118
111
# if the dummy vcs wasn't that dummy we could uncomment the line below
119
112
# self.assertFileEqual("blaaaa", "d/foofile")
120
self.check_output('modified:\n foofile\n', "status dc")
113
script.run_script(self, '''
122
119
def test_diverged(self):
123
120
builder = self.make_dummy_builder('d')
149
146
def set_config_push_strict(self, value):
150
147
# set config var (any of bazaar.conf, locations.conf, branch.conf
152
conf = self.tree.branch.get_config()
153
conf.set_user_option('dpush_strict', value)
149
conf = self.tree.branch.get_config_stack()
150
conf.set('dpush_strict', value)
155
152
_default_command = ['dpush', '../to']
156
_default_pushed_revid = False # Doesn't aplly for dpush
158
def assertPushSucceeds(self, args, pushed_revid=None):
159
self.run_bzr(self._default_command + args,
160
working_dir=self._default_wd)
161
if pushed_revid is None:
162
# dpush change the revids, so we need to get back to it
163
branch_from = branch.Branch.open(self._default_wd)
164
pushed_revid = branch_from.last_revision()
165
branch_to = branch.Branch.open('to')
166
repo_to = branch_to.repository
167
self.assertTrue(repo_to.has_revision(pushed_revid))
168
self.assertEqual(branch_to.last_revision(), pushed_revid)
172
155
class TestDpushStrictWithoutChanges(TestDpushStrictMixin,
180
163
class TestDpushStrictWithChanges(TestDpushStrictMixin,
181
164
test_push.TestPushStrictWithChanges):
166
scenarios = test_push.strict_push_change_scenarios
183
168
_changes_type = None # Set by load_tests