18
18
from cStringIO import StringIO
21
from bzrlib import ignores
27
23
from bzrlib.branch import Branch
24
from bzrlib import bzrdir, conflicts, errors, workingtree
28
25
from bzrlib.bzrdir import BzrDir
26
from bzrlib.errors import NotBranchError, NotVersionedError
29
27
from bzrlib.lockdir import LockDir
30
28
from bzrlib.mutabletree import needs_tree_write_lock
29
from bzrlib.osutils import pathjoin, getcwd, has_symlinks
30
from bzrlib.symbol_versioning import zero_thirteen
31
31
from bzrlib.tests import TestCase, TestCaseWithTransport, TestSkipped
32
from bzrlib.trace import mutter
32
33
from bzrlib.transport import get_transport
33
34
from bzrlib.workingtree import (
41
42
class TestTreeDirectory(TestCaseWithTransport):
43
44
def test_kind_character(self):
250
256
self.assertEqual(list(tree.conflicts()), [expected])
259
class TestNonFormatSpecificCode(TestCaseWithTransport):
260
"""This class contains tests of workingtree that are not format specific."""
262
def test_gen_file_id(self):
263
file_id = self.applyDeprecated(zero_thirteen, workingtree.gen_file_id,
265
self.assertStartsWith(file_id, 'filename-')
267
def test_gen_root_id(self):
268
file_id = self.applyDeprecated(zero_thirteen, workingtree.gen_root_id)
269
self.assertStartsWith(file_id, 'tree_root-')
253
272
class InstrumentedTree(object):
254
273
"""A instrumented tree to check the needs_tree_write_lock decorator."""
294
313
self.assertEqual(['t', 'u'], tree._locks)
295
314
self.assertRaises(TypeError, tree.method_that_raises, 'foo')
296
315
self.assertEqual(['t', 'u', 't', 'u'], tree._locks)
299
class TestRevert(TestCaseWithTransport):
301
def test_revert_conflicts_recursive(self):
302
this_tree = self.make_branch_and_tree('this-tree')
303
self.build_tree_contents([('this-tree/foo/',),
304
('this-tree/foo/bar', 'bar')])
305
this_tree.add(['foo', 'foo/bar'])
306
this_tree.commit('created foo/bar')
307
other_tree = this_tree.bzrdir.sprout('other-tree').open_workingtree()
308
self.build_tree_contents([('other-tree/foo/bar', 'baz')])
309
other_tree.commit('changed bar')
310
self.build_tree_contents([('this-tree/foo/bar', 'qux')])
311
this_tree.commit('changed qux')
312
this_tree.merge_from_branch(other_tree.branch)
313
self.assertEqual(1, len(this_tree.conflicts()))
314
this_tree.revert(['foo'])
315
self.assertEqual(0, len(this_tree.conflicts()))
318
class TestAutoResolve(TestCaseWithTransport):
320
def test_auto_resolve(self):
321
base = self.make_branch_and_tree('base')
322
self.build_tree_contents([('base/hello', 'Hello')])
323
base.add('hello', 'hello_id')
325
other = base.bzrdir.sprout('other').open_workingtree()
326
self.build_tree_contents([('other/hello', 'hELLO')])
327
other.commit('Case switch')
328
this = base.bzrdir.sprout('this').open_workingtree()
329
self.failUnlessExists('this/hello')
330
self.build_tree_contents([('this/hello', 'Hello World')])
331
this.commit('Add World')
332
this.merge_from_branch(other.branch)
333
self.assertEqual([conflicts.TextConflict('hello', None, 'hello_id')],
336
self.assertEqual([conflicts.TextConflict('hello', None, 'hello_id')],
338
self.build_tree_contents([('this/hello', '<<<<<<<')])
340
self.assertEqual([conflicts.TextConflict('hello', None, 'hello_id')],
342
self.build_tree_contents([('this/hello', '=======')])
344
self.assertEqual([conflicts.TextConflict('hello', None, 'hello_id')],
346
self.build_tree_contents([('this/hello', '\n>>>>>>>')])
347
remaining, resolved = this.auto_resolve()
348
self.assertEqual([conflicts.TextConflict('hello', None, 'hello_id')],
350
self.assertEqual([], resolved)
351
self.build_tree_contents([('this/hello', 'hELLO wORLD')])
352
remaining, resolved = this.auto_resolve()
353
self.assertEqual([], this.conflicts())
354
self.assertEqual([conflicts.TextConflict('hello', None, 'hello_id')],
356
self.failIfExists('this/hello.BASE')
358
def test_auto_resolve_dir(self):
359
tree = self.make_branch_and_tree('tree')
360
self.build_tree(['tree/hello/'])
361
tree.add('hello', 'hello-id')
362
file_conflict = conflicts.TextConflict('file', None, 'hello-id')
363
tree.set_conflicts(conflicts.ConflictList([file_conflict]))
367
class TestFindTrees(TestCaseWithTransport):
369
def test_find_trees(self):
370
self.make_branch_and_tree('foo')
371
self.make_branch_and_tree('foo/bar')
372
# Sticking a tree inside a control dir is heinous, so let's skip it
373
self.make_branch_and_tree('foo/.bzr/baz')
374
self.make_branch('qux')
375
trees = workingtree.WorkingTree.find_trees('.')
376
self.assertEqual(2, len(list(trees)))