124
146
output, error = self.run_bzr("dpush -d dc d", retcode=3)
125
147
self.assertEquals(output, "")
126
148
self.assertContainsRe(error, "have diverged")
151
class TestDpushStrictMixin(object):
153
# FIXME: setUp and unregister_format needs to be dedupe from TestDpush
154
# (made into functions in test_foreign ?).
156
bzrdir.BzrDirFormat.register_control_format(
157
test_foreign.DummyForeignVcsDirFormat)
158
branch.InterBranch.register_optimiser(
159
test_foreign.InterToDummyVcsBranch)
160
self.addCleanup(self.unregister_format)
162
def unregister_format(self):
164
bzrdir.BzrDirFormat.unregister_control_format(
165
test_foreign.DummyForeignVcsDirFormat)
168
branch.InterBranch.unregister_optimiser(
169
test_foreign.InterToDummyVcsBranch)
171
def make_local_branch_and_tree(self):
172
self.tree = self.make_branch_and_tree('local')
173
self.build_tree_contents([('local/file', 'initial')])
174
self.tree.add('file')
175
self.tree.commit('adding file', rev_id='added')
176
self.build_tree_contents([('local/file', 'modified')])
177
self.tree.commit('modify file', rev_id='modified')
179
def make_foreign_branch(self, relpath='to'):
180
# Create an empty branch where we will be able to push
181
self.foreign = self.make_branch(
182
relpath, format=test_foreign.DummyForeignVcsDirFormat())
184
def set_config_dpush_strict(self, value):
185
# set config var (any of bazaar.conf, locations.conf, branch.conf
187
conf = self.tree.branch.get_config()
188
conf.set_user_option('dpush_strict', value)
190
_default_command = ['dpush', '../to']
191
_default_wd = 'local'
192
_default_errors = ['Working tree ".*/local/" has uncommitted '
193
'changes \(See bzr status\)\.',]
194
_default_dpushed_revid = 'modified'
196
def assertDpushFails(self, args):
197
self.run_bzr_error(self._default_errors, self._default_command + args,
198
working_dir=self._default_wd, retcode=3)
200
def assertDpushSucceeds(self, args, pushed_revid=None):
201
self.run_bzr(self._default_command + args,
202
working_dir=self._default_wd)
203
if pushed_revid is None:
204
# dpush change the revids, so we need to get back to it
205
branch_from = branch.Branch.open(self._default_wd)
206
pushed_revid = branch_from.last_revision()
207
branch_to = branch.Branch.open('to')
208
repo_to = branch_to.repository
209
self.assertTrue(repo_to.has_revision(pushed_revid))
210
self.assertEqual(branch_to.last_revision(), pushed_revid)
214
class TestDpushStrictWithoutChanges(tests.TestCaseWithTransport,
215
TestDpushStrictMixin):
218
super(TestDpushStrictWithoutChanges, self).setUp()
219
TestDpushStrictMixin.setUp(self)
220
self.make_local_branch_and_tree()
221
self.make_foreign_branch()
223
def test_dpush_default(self):
224
self.assertDpushSucceeds([])
226
def test_dpush_strict(self):
227
self.assertDpushSucceeds(['--strict'])
229
def test_dpush_no_strict(self):
230
self.assertDpushSucceeds(['--no-strict'])
232
def test_dpush_config_var_strict(self):
233
self.set_config_dpush_strict('true')
234
self.assertDpushSucceeds([])
236
def test_dpush_config_var_no_strict(self):
237
self.set_config_dpush_strict('false')
238
self.assertDpushSucceeds([])
241
class TestDpushStrictWithChanges(tests.TestCaseWithTransport,
242
TestDpushStrictMixin):
244
_changes_type = None # Set by load_tests
247
super(TestDpushStrictWithChanges, self).setUp()
248
TestDpushStrictMixin.setUp(self)
249
# Apply the changes defined in load_tests: one of _uncommitted_changes,
250
# _pending_merges or _out_of_sync_trees
251
getattr(self, self._changes_type)()
252
self.make_foreign_branch()
254
def _uncommitted_changes(self):
255
self.make_local_branch_and_tree()
256
# Make a change without committing it
257
self.build_tree_contents([('local/file', 'in progress')])
259
def _pending_merges(self):
260
self.make_local_branch_and_tree()
261
# Create 'other' branch containing a new file
262
other_bzrdir = self.tree.bzrdir.sprout('other')
263
other_tree = other_bzrdir.open_workingtree()
264
self.build_tree_contents([('other/other-file', 'other')])
265
other_tree.add('other-file')
266
other_tree.commit('other commit', rev_id='other')
267
# Merge and revert, leaving a pending merge
268
self.tree.merge_from_branch(other_tree.branch)
269
self.tree.revert(filenames=['other-file'], backups=False)
271
def _out_of_sync_trees(self):
272
self.make_local_branch_and_tree()
273
self.run_bzr(['checkout', '--lightweight', 'local', 'checkout'])
274
# Make a change and commit it
275
self.build_tree_contents([('local/file', 'modified in local')])
276
self.tree.commit('modify file', rev_id='modified-in-local')
277
# Exercise commands from the checkout directory
278
self._default_wd = 'checkout'
279
self._default_errors = ["Working tree is out of date, please run"
281
self._default_dpushed_revid = 'modified-in-local'
283
def test_dpush_default(self):
284
self.assertDpushFails([])
286
def test_dpush_no_strict(self):
287
self.assertDpushSucceeds(['--no-strict'])
289
def test_dpush_strict_with_changes(self):
290
self.assertDpushFails(['--strict'])
292
def test_dpush_respect_config_var_strict(self):
293
self.set_config_dpush_strict('true')
294
self.assertDpushFails([])
296
def test_dpush_bogus_config_var_ignored(self):
297
self.set_config_dpush_strict("I don't want you to be strict")
298
self.assertDpushFails([])
300
def test_dpush_no_strict_command_line_override_config(self):
301
self.set_config_dpush_strict('yES')
302
self.assertDpushFails([])
303
self.assertDpushSucceeds(['--no-strict'])
305
def test_dpush_strict_command_line_override_config(self):
306
self.set_config_dpush_strict('oFF')
307
self.assertDpushFails(['--strict'])
308
self.assertDpushSucceeds([])