206
213
self.assertEquals(our_lock.peek(), None)
215
def test_missing_pending_merges(self):
216
control = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
217
control.create_repository()
218
control.create_branch()
219
tree = workingtree.WorkingTreeFormat3().initialize(control)
220
tree._control_files._transport.delete("pending-merges")
221
self.assertEqual([], tree.get_parent_ids())
224
class TestFormat2WorkingTree(TestCaseWithTransport):
225
"""Tests that are specific to format 2 trees."""
208
227
def create_format2_tree(self, url):
209
return BzrDir.create_standalone_workingtree(url)
228
return self.make_branch_and_tree(
229
url, format=bzrdir.BzrDirFormat6())
211
def test_conflicts_format2(self):
231
def test_conflicts(self):
212
232
# test backwards compatability
213
233
tree = self.create_format2_tree('.')
214
234
self.assertRaises(errors.UnsupportedOperation, tree.set_conflicts,
216
236
file('lala.BASE', 'wb').write('labase')
217
expected = ContentsConflict('lala')
237
expected = conflicts.ContentsConflict('lala')
218
238
self.assertEqual(list(tree.conflicts()), [expected])
219
239
file('lala', 'wb').write('la')
220
240
tree.add('lala', 'lala-id')
221
expected = ContentsConflict('lala', file_id='lala-id')
241
expected = conflicts.ContentsConflict('lala', file_id='lala-id')
222
242
self.assertEqual(list(tree.conflicts()), [expected])
223
243
file('lala.THIS', 'wb').write('lathis')
224
244
file('lala.OTHER', 'wb').write('laother')
225
245
# When "text conflict"s happen, stem, THIS and OTHER are text
226
expected = TextConflict('lala', file_id='lala-id')
246
expected = conflicts.TextConflict('lala', file_id='lala-id')
227
247
self.assertEqual(list(tree.conflicts()), [expected])
228
248
os.unlink('lala.OTHER')
229
249
os.mkdir('lala.OTHER')
230
expected = ContentsConflict('lala', file_id='lala-id')
250
expected = conflicts.ContentsConflict('lala', file_id='lala-id')
231
251
self.assertEqual(list(tree.conflicts()), [expected])
254
class TestNonFormatSpecificCode(TestCaseWithTransport):
255
"""This class contains tests of workingtree that are not format specific."""
257
def test_gen_file_id(self):
258
file_id = self.applyDeprecated(zero_thirteen, workingtree.gen_file_id,
260
self.assertStartsWith(file_id, 'filename-')
262
def test_gen_root_id(self):
263
file_id = self.applyDeprecated(zero_thirteen, workingtree.gen_root_id)
264
self.assertStartsWith(file_id, 'tree_root-')
267
class InstrumentedTree(object):
268
"""A instrumented tree to check the needs_tree_write_lock decorator."""
273
def lock_tree_write(self):
274
self._locks.append('t')
276
@needs_tree_write_lock
277
def method_with_tree_write_lock(self, *args, **kwargs):
278
"""A lock_tree_write decorated method that returns its arguments."""
281
@needs_tree_write_lock
282
def method_that_raises(self):
283
"""This method causes an exception when called with parameters.
285
This allows the decorator code to be checked - it should still call
290
self._locks.append('u')
293
class TestInstrumentedTree(TestCase):
295
def test_needs_tree_write_lock(self):
296
"""@needs_tree_write_lock should be semantically transparent."""
297
tree = InstrumentedTree()
299
'method_with_tree_write_lock',
300
tree.method_with_tree_write_lock.__name__)
302
"A lock_tree_write decorated method that returns its arguments.",
303
tree.method_with_tree_write_lock.__doc__)
306
result = tree.method_with_tree_write_lock(1,2,3, a='b')
307
self.assertEqual((args, kwargs), result)
308
self.assertEqual(['t', 'u'], tree._locks)
309
self.assertRaises(TypeError, tree.method_that_raises, 'foo')
310
self.assertEqual(['t', 'u', 't', 'u'], tree._locks)
313
class TestRevert(TestCaseWithTransport):
315
def test_revert_conflicts_recursive(self):
316
this_tree = self.make_branch_and_tree('this-tree')
317
self.build_tree_contents([('this-tree/foo/',),
318
('this-tree/foo/bar', 'bar')])
319
this_tree.add(['foo', 'foo/bar'])
320
this_tree.commit('created foo/bar')
321
other_tree = this_tree.bzrdir.sprout('other-tree').open_workingtree()
322
self.build_tree_contents([('other-tree/foo/bar', 'baz')])
323
other_tree.commit('changed bar')
324
self.build_tree_contents([('this-tree/foo/bar', 'qux')])
325
this_tree.commit('changed qux')
326
this_tree.merge_from_branch(other_tree.branch)
327
self.assertEqual(1, len(this_tree.conflicts()))
328
this_tree.revert(['foo'])
329
self.assertEqual(0, len(this_tree.conflicts()))
332
class TestAutoResolve(TestCaseWithTransport):
334
def test_auto_resolve(self):
335
base = self.make_branch_and_tree('base')
336
self.build_tree_contents([('base/hello', 'Hello')])
337
base.add('hello', 'hello_id')
339
other = base.bzrdir.sprout('other').open_workingtree()
340
self.build_tree_contents([('other/hello', 'hELLO')])
341
other.commit('Case switch')
342
this = base.bzrdir.sprout('this').open_workingtree()
343
self.failUnlessExists('this/hello')
344
self.build_tree_contents([('this/hello', 'Hello World')])
345
this.commit('Add World')
346
this.merge_from_branch(other.branch)
347
self.assertEqual([conflicts.TextConflict('hello', None, 'hello_id')],
350
self.assertEqual([conflicts.TextConflict('hello', None, 'hello_id')],
352
self.build_tree_contents([('this/hello', '<<<<<<<')])
354
self.assertEqual([conflicts.TextConflict('hello', None, 'hello_id')],
356
self.build_tree_contents([('this/hello', '=======')])
358
self.assertEqual([conflicts.TextConflict('hello', None, 'hello_id')],
360
self.build_tree_contents([('this/hello', '\n>>>>>>>')])
361
remaining, resolved = this.auto_resolve()
362
self.assertEqual([conflicts.TextConflict('hello', None, 'hello_id')],
364
self.assertEqual([], resolved)
365
self.build_tree_contents([('this/hello', 'hELLO wORLD')])
366
remaining, resolved = this.auto_resolve()
367
self.assertEqual([], this.conflicts())
368
self.assertEqual([conflicts.TextConflict('hello', None, 'hello_id')],
370
self.failIfExists('this/hello.BASE')
372
def test_auto_resolve_dir(self):
373
tree = self.make_branch_and_tree('tree')
374
self.build_tree(['tree/hello/'])
375
tree.add('hello', 'hello-id')
376
file_conflict = conflicts.TextConflict('file', None, 'hello-id')
377
tree.set_conflicts(conflicts.ConflictList([file_conflict]))
381
class TestFindTrees(TestCaseWithTransport):
383
def test_find_trees(self):
384
self.make_branch_and_tree('foo')
385
self.make_branch_and_tree('foo/bar')
386
# Sticking a tree inside a control dir is heinous, so let's skip it
387
self.make_branch_and_tree('foo/.bzr/baz')
388
self.make_branch('qux')
389
trees = workingtree.WorkingTree.find_trees('.')
390
self.assertEqual(2, len(list(trees)))