140
141
class TestDpushStrictMixin(object):
142
def make_local_branch_and_tree(self):
143
self.tree = self.make_branch_and_tree('local')
144
self.build_tree_contents([('local/file', 'initial')])
145
self.tree.add('file')
146
self.tree.commit('adding file', rev_id='added')
147
self.build_tree_contents([('local/file', 'modified')])
148
self.tree.commit('modify file', rev_id='modified')
150
143
def make_foreign_branch(self, relpath='to'):
151
144
# Create an empty branch where we will be able to push
152
145
self.foreign = self.make_branch(
153
146
relpath, format=test_foreign.DummyForeignVcsDirFormat())
155
def set_config_dpush_strict(self, value):
148
def set_config_push_strict(self, value):
156
149
# set config var (any of bazaar.conf, locations.conf, branch.conf
158
151
conf = self.tree.branch.get_config()
159
152
conf.set_user_option('dpush_strict', value)
161
154
_default_command = ['dpush', '../to']
162
_default_wd = 'local'
163
_default_errors = ['Working tree ".*/local/" has uncommitted '
164
'changes \(See bzr status\)\.',]
165
_default_dpushed_revid = 'modified'
167
def assertDpushFails(self, args):
168
self.run_bzr_error(self._default_errors, self._default_command + args,
169
working_dir=self._default_wd, retcode=3)
171
def assertDpushSucceeds(self, args, pushed_revid=None):
155
_default_pushed_revid = False # Doesn't aplly for dpush
157
def assertPushSucceeds(self, args, pushed_revid=None):
172
158
self.run_bzr(self._default_command + args,
173
159
working_dir=self._default_wd)
174
160
if pushed_revid is None:
185
class TestDpushStrictWithoutChanges(tests.TestCaseWithTransport,
186
TestDpushStrictMixin):
171
class TestDpushStrictWithoutChanges(TestDpushStrictMixin,
172
test_push.TestPushStrictWithoutChanges):
189
175
super(TestDpushStrictWithoutChanges, self).setUp()
190
176
test_foreign.register_dummy_foreign_for_test(self)
191
self.make_local_branch_and_tree()
192
177
self.make_foreign_branch()
194
def test_dpush_default(self):
195
self.assertDpushSucceeds([])
197
def test_dpush_strict(self):
198
self.assertDpushSucceeds(['--strict'])
200
def test_dpush_no_strict(self):
201
self.assertDpushSucceeds(['--no-strict'])
203
def test_dpush_config_var_strict(self):
204
self.set_config_dpush_strict('true')
205
self.assertDpushSucceeds([])
207
def test_dpush_config_var_no_strict(self):
208
self.set_config_dpush_strict('false')
209
self.assertDpushSucceeds([])
212
class TestDpushStrictWithChanges(tests.TestCaseWithTransport,
213
TestDpushStrictMixin):
180
class TestDpushStrictWithChanges(TestDpushStrictMixin,
181
test_push.TestPushStrictWithChanges):
215
183
_changes_type = None # Set by load_tests
218
186
super(TestDpushStrictWithChanges, self).setUp()
219
187
test_foreign.register_dummy_foreign_for_test(self)
220
# Apply the changes defined in load_tests: one of _uncommitted_changes,
221
# _pending_merges or _out_of_sync_trees
222
getattr(self, self._changes_type)()
223
188
self.make_foreign_branch()
225
def _uncommitted_changes(self):
226
self.make_local_branch_and_tree()
227
# Make a change without committing it
228
self.build_tree_contents([('local/file', 'in progress')])
230
def _pending_merges(self):
231
self.make_local_branch_and_tree()
232
# Create 'other' branch containing a new file
233
other_bzrdir = self.tree.bzrdir.sprout('other')
234
other_tree = other_bzrdir.open_workingtree()
235
self.build_tree_contents([('other/other-file', 'other')])
236
other_tree.add('other-file')
237
other_tree.commit('other commit', rev_id='other')
238
# Merge and revert, leaving a pending merge
239
self.tree.merge_from_branch(other_tree.branch)
240
self.tree.revert(filenames=['other-file'], backups=False)
242
def _out_of_sync_trees(self):
243
self.make_local_branch_and_tree()
244
self.run_bzr(['checkout', '--lightweight', 'local', 'checkout'])
245
# Make a change and commit it
246
self.build_tree_contents([('local/file', 'modified in local')])
247
self.tree.commit('modify file', rev_id='modified-in-local')
248
# Exercise commands from the checkout directory
249
self._default_wd = 'checkout'
250
self._default_errors = ["Working tree is out of date, please run"
252
self._default_dpushed_revid = 'modified-in-local'
254
def test_dpush_default(self):
255
self.assertDpushFails([])
257
def test_dpush_no_strict(self):
258
self.assertDpushSucceeds(['--no-strict'])
260
def test_dpush_strict_with_changes(self):
261
self.assertDpushFails(['--strict'])
263
def test_dpush_respect_config_var_strict(self):
264
self.set_config_dpush_strict('true')
265
self.assertDpushFails([])
267
def test_dpush_bogus_config_var_ignored(self):
268
self.set_config_dpush_strict("I don't want you to be strict")
269
self.assertDpushFails([])
271
def test_dpush_no_strict_command_line_override_config(self):
272
self.set_config_dpush_strict('yES')
273
self.assertDpushFails([])
274
self.assertDpushSucceeds(['--no-strict'])
276
def test_dpush_strict_command_line_override_config(self):
277
self.set_config_dpush_strict('oFF')
278
self.assertDpushFails(['--strict'])
279
self.assertDpushSucceeds([])
190
def test_push_with_revision(self):
191
raise tests.TestNotApplicable('dpush does not handle --revision')