69
86
('hello.sploo.OTHER', 'yellowworld2'),
72
self.assertEqual(6, len(list(tree.list_files())))
89
self.assertLength(6, list(tree.list_files()))
74
91
tree_conflicts = tree.conflicts()
75
self.assertEqual(2, len(tree_conflicts))
92
self.assertLength(2, tree_conflicts)
76
93
self.assertTrue('hello' in tree_conflicts[0].path)
77
94
self.assertTrue('hello.sploo' in tree_conflicts[1].path)
78
95
conflicts.restore('hello')
79
96
conflicts.restore('hello.sploo')
80
self.assertEqual(0, len(tree.conflicts()))
97
self.assertLength(0, tree.conflicts())
81
98
self.assertFileEqual('hello world2', 'hello')
82
99
self.assertFalse(os.path.lexists('hello.sploo'))
83
100
self.assertRaises(errors.NotConflicted, conflicts.restore, 'hello')
195
class TestResolveContentConflicts(TestResolveConflicts):
197
# FIXME: We need to add the reverse case (delete in trunk, modify in
198
# branch) but that could wait until the resolution mechanism is implemented.
203
$ echo 'trunk content' >file
205
$ bzr commit -m 'Create trunk'
207
$ bzr branch . ../branch
210
$ bzr commit -m 'Delete file'
213
$ echo 'more content' >>file
214
$ bzr commit -m 'Modify file'
219
2>Contents conflict in file
220
2>1 conflicts encountered.
223
def test_take_this(self):
225
$ bzr rm file.OTHER --force # a simple rm file.OTHER is valid too
227
$ bzr commit --strict -m 'No more conflicts nor unknown files'
230
def test_take_other(self):
232
$ bzr mv file.OTHER file
234
$ bzr commit --strict -m 'No more conflicts nor unknown files'
212
def content_conflict_scenarios():
213
return [('file,None', dict(_this_actions='modify_file',
214
_check_this='file_has_more_content',
215
_other_actions='delete_file',
216
_check_other='file_doesnt_exist',
218
('None,file', dict(_this_actions='delete_file',
219
_check_this='file_doesnt_exist',
220
_other_actions='modify_file',
221
_check_other='file_has_more_content',
226
class TestResolveContentConflicts(tests.TestCaseWithTransport):
233
super(TestResolveContentConflicts, self).setUp()
234
builder = self.make_branch_builder('trunk')
235
builder.start_series()
236
# Create an empty trunk
237
builder.build_snapshot('start', None, [
238
('add', ('', 'root-id', 'directory', ''))])
239
# Add a minimal base content
240
builder.build_snapshot('base', ['start'], [
241
('add', ('file', 'file-id', 'file', 'trunk content\n'))])
242
# Modify the base content in branch
243
other_actions = self._get_actions(self._other_actions)
244
builder.build_snapshot('other', ['base'], other_actions())
245
# Modify the base content in trunk
246
this_actions = self._get_actions(self._this_actions)
247
builder.build_snapshot('this', ['base'], this_actions())
248
builder.finish_series()
249
self.builder = builder
251
def _get_actions(self, name):
252
return getattr(self, 'do_%s' % name)
254
def _get_check(self, name):
255
return getattr(self, 'check_%s' % name)
257
def do_modify_file(self):
258
return [('modify', ('file-id', 'trunk content\nmore content\n'))]
260
def check_file_has_more_content(self):
261
self.assertFileEqual('trunk content\nmore content\n', 'branch/file')
263
def do_delete_file(self):
264
return [('unversion', 'file-id')]
266
def check_file_doesnt_exist(self):
267
self.failIfExists('branch/file')
269
def _merge_other_into_this(self):
270
b = self.builder.get_branch()
271
wt = b.bzrdir.sprout('branch').open_workingtree()
272
wt.merge_from_branch(b, 'other')
275
def assertConflict(self, wt, ctype, **kwargs):
276
confs = wt.conflicts()
277
self.assertLength(1, confs)
279
self.assertIsInstance(c, ctype)
280
sentinel = object() # An impossible value
281
for k, v in kwargs.iteritems():
282
self.assertEqual(v, getattr(c, k, sentinel))
284
def check_resolved(self, wt, item, action):
285
conflicts.resolve(wt, [item], action=action)
286
# Check that we don't have any conflicts nor unknown left
287
self.assertLength(0, wt.conflicts())
288
self.assertLength(0, list(wt.unknowns()))
237
290
def test_resolve_taking_this(self):
239
$ bzr resolve --take-this file
240
$ bzr commit --strict -m 'No more conflicts nor unknown files'
291
wt = self._merge_other_into_this()
292
self.assertConflict(wt, conflicts.ContentsConflict,
293
path='file', file_id='file-id',)
294
self.check_resolved(wt, 'file', 'take_this')
295
check_this = self._get_check(self._check_this)
243
298
def test_resolve_taking_other(self):
245
$ bzr resolve --take-other file
246
$ bzr commit --strict -m 'No more conflicts nor unknown files'
299
wt = self._merge_other_into_this()
300
self.assertConflict(wt, conflicts.ContentsConflict,
301
path='file', file_id='file-id',)
302
self.check_resolved(wt, 'file', 'take_other')
303
check_other = self._get_check(self._check_other)
250
307
class TestResolveDuplicateEntry(TestResolveConflicts):