/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to brzlib/tests/test_workingtree.py

  • Committer: Jelmer Vernooij
  • Date: 2017-05-21 12:41:27 UTC
  • mto: This revision was merged to the branch mainline in revision 6623.
  • Revision ID: jelmer@jelmer.uk-20170521124127-iv8etg0vwymyai6y
s/bzr/brz/ in apport config.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
# along with this program; if not, write to the Free Software
16
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
17
 
18
 
from io import BytesIO
19
 
import os
20
 
 
21
 
from .. import (
 
18
from brzlib import (
 
19
    bzrdir,
22
20
    conflicts,
23
21
    errors,
24
 
    symbol_versioning,
25
 
    trace,
26
22
    transport,
27
23
    workingtree,
28
 
    )
29
 
from ..bzr import (
30
 
    bzrdir,
31
 
    workingtree as bzrworkingtree,
32
24
    workingtree_3,
33
25
    workingtree_4,
34
26
    )
35
 
from ..lock import write_locked
36
 
from ..lockdir import LockDir
37
 
from . import TestCase, TestCaseWithTransport, TestSkipped
38
 
from ..tree import (
 
27
from brzlib.lock import write_locked
 
28
from brzlib.lockdir import LockDir
 
29
from brzlib.mutabletree import needs_tree_write_lock
 
30
from brzlib.tests import TestCase, TestCaseWithTransport, TestSkipped
 
31
from brzlib.workingtree import (
39
32
    TreeEntry,
40
33
    TreeDirectory,
41
34
    TreeFile,
42
35
    TreeLink,
43
36
    )
44
37
 
45
 
from .features import SymlinkFeature
46
38
 
47
39
class TestTreeDirectory(TestCaseWithTransport):
48
40
 
73
65
    def test_get_set_default_format(self):
74
66
        old_format = workingtree.format_registry.get_default()
75
67
        # default is 6
76
 
        self.assertTrue(isinstance(
77
 
            old_format, workingtree_4.WorkingTreeFormat6))
 
68
        self.assertTrue(isinstance(old_format, workingtree_4.WorkingTreeFormat6))
78
69
        workingtree.format_registry.set_default(SampleTreeFormat())
79
70
        try:
80
71
            # the default branch format is used by the meta dir format
90
81
 
91
82
    def test_from_string(self):
92
83
        self.assertIsInstance(
93
 
            SampleTreeFormat.from_string(b"Sample tree format."),
 
84
            SampleTreeFormat.from_string("Sample tree format."),
94
85
            SampleTreeFormat)
95
 
        self.assertRaises(
96
 
            AssertionError, SampleTreeFormat.from_string,
97
 
            b"Different format string.")
 
86
        self.assertRaises(AssertionError,
 
87
            SampleTreeFormat.from_string, "Different format string.")
98
88
 
99
89
    def test_get_set_default_format_by_key(self):
100
90
        old_format = workingtree.format_registry.get_default()
102
92
        format = SampleTreeFormat()
103
93
        workingtree.format_registry.register(format)
104
94
        self.addCleanup(workingtree.format_registry.remove, format)
105
 
        self.assertTrue(isinstance(
106
 
            old_format, workingtree_4.WorkingTreeFormat6))
 
95
        self.assertTrue(isinstance(old_format, workingtree_4.WorkingTreeFormat6))
107
96
        workingtree.format_registry.set_default_key(format.get_format_string())
108
97
        try:
109
98
            # the default branch format is used by the meta dir format
133
122
        open_no_args, relpath = workingtree.WorkingTree.open_containing()
134
123
        self.assertEqual(tree.basedir, open_no_args.basedir)
135
124
        self.assertEqual('', relpath)
136
 
        open_subdir, relpath = workingtree.WorkingTree.open_containing(
137
 
            'subdir')
 
125
        open_subdir, relpath = workingtree.WorkingTree.open_containing('subdir')
138
126
        self.assertEqual(tree.basedir, open_subdir.basedir)
139
127
        self.assertEqual('subdir', relpath)
140
128
 
141
129
 
142
 
class SampleTreeFormat(bzrworkingtree.WorkingTreeFormatMetaDir):
 
130
class SampleTreeFormat(workingtree.WorkingTreeFormatMetaDir):
143
131
    """A sample format
144
132
 
145
133
    this format is initializable, unsupported to aid in testing the
149
137
    @classmethod
150
138
    def get_format_string(cls):
151
139
        """See WorkingTreeFormat.get_format_string()."""
152
 
        return b"Sample tree format."
 
140
        return "Sample tree format."
153
141
 
154
 
    def initialize(self, a_controldir, revision_id=None, from_branch=None,
 
142
    def initialize(self, a_bzrdir, revision_id=None, from_branch=None,
155
143
                   accelerator_tree=None, hardlink=False):
156
144
        """Sample branches cannot be created."""
157
 
        t = a_controldir.get_workingtree_transport(self)
 
145
        t = a_bzrdir.get_workingtree_transport(self)
158
146
        t.put_bytes('format', self.get_format_string())
159
147
        return 'A tree'
160
148
 
174
162
        # Not usable in a metadir, so no format string
175
163
        return None
176
164
 
177
 
    def initialize(self, a_controldir, revision_id=None, from_branch=None,
 
165
    def initialize(self, a_bzrdir, revision_id=None, from_branch=None,
178
166
                   accelerator_tree=None, hardlink=False):
179
167
        raise NotImplementedError(self.initialize)
180
168
 
191
179
    def test_find_format_string(self):
192
180
        # is the right format object found for a working tree?
193
181
        branch = self.make_branch('branch')
194
 
        self.assertRaises(
195
 
            errors.NoWorkingTree,
196
 
            bzrworkingtree.WorkingTreeFormatMetaDir.find_format_string,
197
 
            branch.controldir)
198
 
        transport = branch.controldir.get_workingtree_transport(None)
 
182
        self.assertRaises(errors.NoWorkingTree,
 
183
            workingtree.WorkingTreeFormatMetaDir.find_format_string, branch.bzrdir)
 
184
        transport = branch.bzrdir.get_workingtree_transport(None)
199
185
        transport.mkdir('.')
200
 
        transport.put_bytes("format", b"some format name")
 
186
        transport.put_bytes("format", "some format name")
201
187
        # The format does not have to be known by Bazaar,
202
188
        # find_format_string just retrieves the name
203
 
        self.assertEqual(
204
 
            b"some format name",
205
 
            bzrworkingtree.WorkingTreeFormatMetaDir.find_format_string(
206
 
                branch.controldir))
 
189
        self.assertEqual("some format name",
 
190
            workingtree.WorkingTreeFormatMetaDir.find_format_string(branch.bzrdir))
207
191
 
208
192
    def test_find_format(self):
209
193
        # is the right format object found for a working tree?
210
194
        # create a branch with a few known format objects.
211
195
        self.build_tree(["foo/", "bar/"])
212
 
 
213
196
        def check_format(format, url):
214
 
            dir = format._matchingcontroldir.initialize(url)
 
197
            dir = format._matchingbzrdir.initialize(url)
215
198
            dir.create_repository()
216
199
            dir.create_branch()
217
200
            format.initialize(dir)
218
 
            found_format = bzrworkingtree.WorkingTreeFormatMetaDir.find_format(
219
 
                dir)
 
201
            t = transport.get_transport(url)
 
202
            found_format = workingtree.WorkingTreeFormatMetaDir.find_format(dir)
220
203
            self.assertIsInstance(found_format, format.__class__)
221
204
        check_format(workingtree_3.WorkingTreeFormat3(), "bar")
222
205
 
223
206
    def test_find_format_no_tree(self):
224
207
        dir = bzrdir.BzrDirMetaFormat1().initialize('.')
225
208
        self.assertRaises(errors.NoWorkingTree,
226
 
                          bzrworkingtree.WorkingTreeFormatMetaDir.find_format,
 
209
                          workingtree.WorkingTreeFormatMetaDir.find_format,
227
210
                          dir)
228
211
 
229
212
    def test_find_format_unknown_format(self):
232
215
        dir.create_branch()
233
216
        SampleTreeFormat().initialize(dir)
234
217
        self.assertRaises(errors.UnknownFormatError,
235
 
                          bzrworkingtree.WorkingTreeFormatMetaDir.find_format,
 
218
                          workingtree.WorkingTreeFormatMetaDir.find_format,
236
219
                          dir)
237
220
 
238
221
    def test_find_format_with_features(self):
239
222
        tree = self.make_branch_and_tree('.', format='2a')
240
 
        tree.update_feature_flags({b"name": b"necessity"})
241
 
        found_format = bzrworkingtree.WorkingTreeFormatMetaDir.find_format(
242
 
            tree.controldir)
 
223
        tree.update_feature_flags({"name": "necessity"})
 
224
        found_format = workingtree.WorkingTreeFormatMetaDir.find_format(
 
225
            tree.bzrdir)
243
226
        self.assertIsInstance(found_format, workingtree.WorkingTreeFormat)
244
 
        self.assertEqual(found_format.features.get(b"name"), b"necessity")
245
 
        self.assertRaises(
246
 
            bzrdir.MissingFeature, found_format.check_support_status, True)
247
 
        self.addCleanup(
248
 
            bzrworkingtree.WorkingTreeFormatMetaDir.unregister_feature,
249
 
            b"name")
250
 
        bzrworkingtree.WorkingTreeFormatMetaDir.register_feature(b"name")
 
227
        self.assertEqual(found_format.features.get("name"), "necessity")
 
228
        self.assertRaises(errors.MissingFeature, found_format.check_support_status,
 
229
            True)
 
230
        self.addCleanup(workingtree.WorkingTreeFormatMetaDir.unregister_feature,
 
231
            "name")
 
232
        workingtree.WorkingTreeFormatMetaDir.register_feature("name")
251
233
        found_format.check_support_status(True)
252
234
 
253
235
 
256
238
    def make_simple_tree(self):
257
239
        tree = self.make_branch_and_tree('tree', format='development-subtree')
258
240
        self.build_tree(['tree/a/', 'tree/a/b/', 'tree/a/b/c'])
259
 
        tree.set_root_id(b'root-id')
260
 
        tree.add(['a', 'a/b', 'a/b/c'], [b'a-id', b'b-id', b'c-id'])
 
241
        tree.set_root_id('root-id')
 
242
        tree.add(['a', 'a/b', 'a/b/c'], ['a-id', 'b-id', 'c-id'])
261
243
        tree.commit('initial')
262
244
        return tree
263
245
 
264
246
    def test_just_directory(self):
265
247
        tree = self.make_simple_tree()
266
 
        self.assertEqual([('directory', b'root-id'),
267
 
                          ('directory', b'a-id'),
268
 
                          ('directory', b'b-id'),
269
 
                          ('file', b'c-id')],
 
248
        self.assertEqual([('directory', 'root-id'),
 
249
                          ('directory', 'a-id'),
 
250
                          ('directory', 'b-id'),
 
251
                          ('file', 'c-id')],
270
252
                         [(ie.kind, ie.file_id)
271
253
                          for path, ie in tree.iter_entries_by_dir()])
272
 
        self.make_branch_and_tree('tree/a/b')
273
 
        self.assertEqual([('tree-reference', b'b-id')],
 
254
        subtree = self.make_branch_and_tree('tree/a/b')
 
255
        self.assertEqual([('tree-reference', 'b-id')],
274
256
                         [(ie.kind, ie.file_id)
275
 
                          for path, ie in tree.iter_entries_by_dir(
276
 
                              specific_files=['a/b'])])
 
257
                          for path, ie in tree.iter_entries_by_dir(['b-id'])])
277
258
 
278
259
    def test_direct_subtree(self):
279
260
        tree = self.make_simple_tree()
280
 
        self.make_branch_and_tree('tree/a/b')
281
 
        self.assertEqual([('directory', b'root-id'),
282
 
                          ('directory', b'a-id'),
283
 
                          ('tree-reference', b'b-id')],
 
261
        subtree = self.make_branch_and_tree('tree/a/b')
 
262
        self.assertEqual([('directory', 'root-id'),
 
263
                          ('directory', 'a-id'),
 
264
                          ('tree-reference', 'b-id')],
284
265
                         [(ie.kind, ie.file_id)
285
266
                          for path, ie in tree.iter_entries_by_dir()])
286
267
 
287
268
    def test_indirect_subtree(self):
288
269
        tree = self.make_simple_tree()
289
 
        self.make_branch_and_tree('tree/a')
290
 
        self.assertEqual([('directory', b'root-id'),
291
 
                          ('tree-reference', b'a-id')],
 
270
        subtree = self.make_branch_and_tree('tree/a')
 
271
        self.assertEqual([('directory', 'root-id'),
 
272
                          ('tree-reference', 'a-id')],
292
273
                         [(ie.kind, ie.file_id)
293
274
                          for path, ie in tree.iter_entries_by_dir()])
294
275
 
302
283
    def test_register_unregister_format(self):
303
284
        format = SampleTreeFormat()
304
285
        self.registry.register(format)
305
 
        self.assertEqual(format, self.registry.get(b"Sample tree format."))
 
286
        self.assertEqual(format, self.registry.get("Sample tree format."))
306
287
        self.registry.remove(format)
307
 
        self.assertRaises(KeyError, self.registry.get, b"Sample tree format.")
 
288
        self.assertRaises(KeyError, self.registry.get, "Sample tree format.")
308
289
 
309
290
    def test_get_all(self):
310
291
        format = SampleTreeFormat()
320
301
 
321
302
    def test_register_extra_lazy(self):
322
303
        self.assertEqual([], self.registry._get_all())
323
 
        self.registry.register_extra_lazy("breezy.tests.test_workingtree",
324
 
                                          "SampleExtraTreeFormat")
 
304
        self.registry.register_extra_lazy("brzlib.tests.test_workingtree",
 
305
            "SampleExtraTreeFormat")
325
306
        formats = self.registry._get_all()
326
307
        self.assertEqual(1, len(formats))
327
308
        self.assertIsInstance(formats[0], SampleExtraTreeFormat)
334
315
        control = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
335
316
        control.create_repository()
336
317
        control.create_branch()
337
 
        workingtree_3.WorkingTreeFormat3().initialize(control)
 
318
        tree = workingtree_3.WorkingTreeFormat3().initialize(control)
338
319
        # we want:
339
320
        # format 'Bazaar-NG Working Tree format 3'
340
321
        # inventory = blank inventory
342
323
        # stat-cache = ??
343
324
        # no inventory.basis yet
344
325
        t = control.get_workingtree_transport(None)
345
 
        self.assertEqualDiff(b'Bazaar-NG Working Tree format 3',
 
326
        self.assertEqualDiff('Bazaar-NG Working Tree format 3',
346
327
                             t.get('format').read())
347
328
        self.assertEqualDiff(t.get('inventory').read(),
348
 
                             b'<inventory format="5">\n'
349
 
                             b'</inventory>\n',
 
329
                              '<inventory format="5">\n'
 
330
                              '</inventory>\n',
350
331
                             )
351
 
        self.assertEqualDiff(b'### bzr hashcache v5\n',
 
332
        self.assertEqualDiff('### bzr hashcache v5\n',
352
333
                             t.get('stat-cache').read())
353
334
        self.assertFalse(t.has('inventory.basis'))
354
335
        # no last-revision file means 'None' or 'NULLREVISION'
365
346
        t = self.get_transport()
366
347
        url = self.get_url()
367
348
        dir = bzrdir.BzrDirMetaFormat1().initialize(url)
368
 
        dir.create_repository()
369
 
        dir.create_branch()
 
349
        repo = dir.create_repository()
 
350
        branch = dir.create_branch()
370
351
        try:
371
352
            tree = workingtree_3.WorkingTreeFormat3().initialize(dir)
372
353
        except errors.NotLocalUrl:
376
357
        self.assertIsDirectory('.bzr/checkout/lock', t)
377
358
        our_lock = LockDir(t, '.bzr/checkout/lock')
378
359
        self.assertEqual(our_lock.peek(), None)
379
 
        with tree.lock_write():
380
 
            self.assertTrue(our_lock.peek())
 
360
        tree.lock_write()
 
361
        self.assertTrue(our_lock.peek())
 
362
        tree.unlock()
381
363
        self.assertEqual(our_lock.peek(), None)
382
364
 
383
365
    def test_missing_pending_merges(self):
389
371
        self.assertEqual([], tree.get_parent_ids())
390
372
 
391
373
 
 
374
class InstrumentedTree(object):
 
375
    """A instrumented tree to check the needs_tree_write_lock decorator."""
 
376
 
 
377
    def __init__(self):
 
378
        self._locks = []
 
379
 
 
380
    def lock_tree_write(self):
 
381
        self._locks.append('t')
 
382
 
 
383
    @needs_tree_write_lock
 
384
    def method_with_tree_write_lock(self, *args, **kwargs):
 
385
        """A lock_tree_write decorated method that returns its arguments."""
 
386
        return args, kwargs
 
387
 
 
388
    @needs_tree_write_lock
 
389
    def method_that_raises(self):
 
390
        """This method causes an exception when called with parameters.
 
391
 
 
392
        This allows the decorator code to be checked - it should still call
 
393
        unlock.
 
394
        """
 
395
 
 
396
    def unlock(self):
 
397
        self._locks.append('u')
 
398
 
 
399
 
 
400
class TestInstrumentedTree(TestCase):
 
401
 
 
402
    def test_needs_tree_write_lock(self):
 
403
        """@needs_tree_write_lock should be semantically transparent."""
 
404
        tree = InstrumentedTree()
 
405
        self.assertEqual(
 
406
            'method_with_tree_write_lock',
 
407
            tree.method_with_tree_write_lock.__name__)
 
408
        self.assertDocstring(
 
409
            "A lock_tree_write decorated method that returns its arguments.",
 
410
            tree.method_with_tree_write_lock)
 
411
        args = (1, 2, 3)
 
412
        kwargs = {'a':'b'}
 
413
        result = tree.method_with_tree_write_lock(1,2,3, a='b')
 
414
        self.assertEqual((args, kwargs), result)
 
415
        self.assertEqual(['t', 'u'], tree._locks)
 
416
        self.assertRaises(TypeError, tree.method_that_raises, 'foo')
 
417
        self.assertEqual(['t', 'u', 't', 'u'], tree._locks)
 
418
 
 
419
 
392
420
class TestRevert(TestCaseWithTransport):
393
421
 
394
422
    def test_revert_conflicts_recursive(self):
395
423
        this_tree = self.make_branch_and_tree('this-tree')
396
424
        self.build_tree_contents([('this-tree/foo/',),
397
 
                                  ('this-tree/foo/bar', b'bar')])
 
425
                                  ('this-tree/foo/bar', 'bar')])
398
426
        this_tree.add(['foo', 'foo/bar'])
399
427
        this_tree.commit('created foo/bar')
400
 
        other_tree = this_tree.controldir.sprout(
401
 
            'other-tree').open_workingtree()
402
 
        self.build_tree_contents([('other-tree/foo/bar', b'baz')])
 
428
        other_tree = this_tree.bzrdir.sprout('other-tree').open_workingtree()
 
429
        self.build_tree_contents([('other-tree/foo/bar', 'baz')])
403
430
        other_tree.commit('changed bar')
404
 
        self.build_tree_contents([('this-tree/foo/bar', b'qux')])
 
431
        self.build_tree_contents([('this-tree/foo/bar', 'qux')])
405
432
        this_tree.commit('changed qux')
406
433
        this_tree.merge_from_branch(other_tree.branch)
407
434
        self.assertEqual(1, len(this_tree.conflicts()))
411
438
 
412
439
class TestAutoResolve(TestCaseWithTransport):
413
440
 
414
 
    def _auto_resolve(self, tree):
415
 
        """Call auto_resolve on tree expecting deprecation"""
416
 
        return self.applyDeprecated(
417
 
            symbol_versioning.deprecated_in((3, 0, 1)),
418
 
            tree.auto_resolve,)
419
 
 
420
441
    def test_auto_resolve(self):
421
442
        base = self.make_branch_and_tree('base')
422
 
        self.build_tree_contents([('base/hello', b'Hello')])
423
 
        base.add('hello', b'hello_id')
 
443
        self.build_tree_contents([('base/hello', 'Hello')])
 
444
        base.add('hello', 'hello_id')
424
445
        base.commit('Hello')
425
 
        other = base.controldir.sprout('other').open_workingtree()
426
 
        self.build_tree_contents([('other/hello', b'hELLO')])
 
446
        other = base.bzrdir.sprout('other').open_workingtree()
 
447
        self.build_tree_contents([('other/hello', 'hELLO')])
427
448
        other.commit('Case switch')
428
 
        this = base.controldir.sprout('this').open_workingtree()
 
449
        this = base.bzrdir.sprout('this').open_workingtree()
429
450
        self.assertPathExists('this/hello')
430
 
        self.build_tree_contents([('this/hello', b'Hello World')])
 
451
        self.build_tree_contents([('this/hello', 'Hello World')])
431
452
        this.commit('Add World')
432
453
        this.merge_from_branch(other.branch)
433
 
        self.assertEqual([conflicts.TextConflict('hello', b'hello_id')],
 
454
        self.assertEqual([conflicts.TextConflict('hello', 'hello_id')],
434
455
                         this.conflicts())
435
 
        self._auto_resolve(this)
436
 
        self.assertEqual([conflicts.TextConflict('hello', b'hello_id')],
 
456
        this.auto_resolve()
 
457
        self.assertEqual([conflicts.TextConflict('hello', 'hello_id')],
437
458
                         this.conflicts())
438
459
        self.build_tree_contents([('this/hello', '<<<<<<<')])
439
 
        self._auto_resolve(this)
440
 
        self.assertEqual([conflicts.TextConflict('hello', b'hello_id')],
 
460
        this.auto_resolve()
 
461
        self.assertEqual([conflicts.TextConflict('hello', 'hello_id')],
441
462
                         this.conflicts())
442
463
        self.build_tree_contents([('this/hello', '=======')])
443
 
        self._auto_resolve(this)
444
 
        self.assertEqual([conflicts.TextConflict('hello', b'hello_id')],
 
464
        this.auto_resolve()
 
465
        self.assertEqual([conflicts.TextConflict('hello', 'hello_id')],
445
466
                         this.conflicts())
446
467
        self.build_tree_contents([('this/hello', '\n>>>>>>>')])
447
 
        remaining, resolved = self._auto_resolve(this)
448
 
        self.assertEqual([conflicts.TextConflict('hello', b'hello_id')],
 
468
        remaining, resolved = this.auto_resolve()
 
469
        self.assertEqual([conflicts.TextConflict('hello', 'hello_id')],
449
470
                         this.conflicts())
450
471
        self.assertEqual([], resolved)
451
 
        self.build_tree_contents([('this/hello', b'hELLO wORLD')])
452
 
        remaining, resolved = self._auto_resolve(this)
 
472
        self.build_tree_contents([('this/hello', 'hELLO wORLD')])
 
473
        remaining, resolved = this.auto_resolve()
453
474
        self.assertEqual([], this.conflicts())
454
 
        self.assertEqual([conflicts.TextConflict('hello', b'hello_id')],
 
475
        self.assertEqual([conflicts.TextConflict('hello', 'hello_id')],
455
476
                         resolved)
456
477
        self.assertPathDoesNotExist('this/hello.BASE')
457
478
 
458
 
    def test_unsupported_symlink_auto_resolve(self):
459
 
        self.requireFeature(SymlinkFeature)
460
 
        base = self.make_branch_and_tree('base')
461
 
        self.build_tree_contents([('base/hello', 'Hello')])
462
 
        base.add('hello', b'hello_id')
463
 
        base.commit('commit 0')
464
 
        other = base.controldir.sprout('other').open_workingtree()
465
 
        self.build_tree_contents([('other/hello', 'Hello')])
466
 
        os.symlink('other/hello', 'other/foo')
467
 
        other.add('foo', b'foo_id')
468
 
        other.commit('commit symlink')
469
 
        this = base.controldir.sprout('this').open_workingtree()
470
 
        self.assertPathExists('this/hello')
471
 
        self.build_tree_contents([('this/hello', 'Hello')])
472
 
        this.commit('commit 2')
473
 
        log = BytesIO()
474
 
        trace.push_log_file(log)
475
 
        os_symlink = getattr(os, 'symlink', None)
476
 
        os.symlink = None
477
 
        try:
478
 
            this.merge_from_branch(other.branch)
479
 
        finally:
480
 
            if os_symlink:
481
 
                os.symlink = os_symlink
482
 
        self.assertContainsRe(
483
 
            log.getvalue(),
484
 
            b'Unable to create symlink "foo" on this filesystem')
485
 
 
486
479
    def test_auto_resolve_dir(self):
487
480
        tree = self.make_branch_and_tree('tree')
488
481
        self.build_tree(['tree/hello/'])
489
 
        tree.add('hello', b'hello-id')
490
 
        file_conflict = conflicts.TextConflict('hello', b'hello-id')
491
 
        tree.set_conflicts(conflicts.ConflictList([file_conflict]))
492
 
        remaining, resolved = self._auto_resolve(tree)
493
 
        self.assertEqual(
494
 
            remaining,
495
 
            conflicts.ConflictList([conflicts.TextConflict(u'hello', 'hello-id')]))
496
 
        self.assertEqual(resolved, [])
497
 
 
498
 
    def test_auto_resolve_missing(self):
499
 
        tree = self.make_branch_and_tree('tree')
500
 
        file_conflict = conflicts.TextConflict('hello', b'hello-id')
501
 
        tree.set_conflicts(conflicts.ConflictList([file_conflict]))
502
 
        remaining, resolved = self._auto_resolve(tree)
503
 
        self.assertEqual(remaining, [])
504
 
        self.assertEqual(
505
 
            resolved,
506
 
            conflicts.ConflictList([conflicts.TextConflict(u'hello', 'hello-id')]))
 
482
        tree.add('hello', 'hello-id')
 
483
        file_conflict = conflicts.TextConflict('file', 'hello-id')
 
484
        tree.set_conflicts(conflicts.ConflictList([file_conflict]))
 
485
        tree.auto_resolve()
 
486
 
 
487
 
 
488
class TestFindTrees(TestCaseWithTransport):
 
489
 
 
490
    def test_find_trees(self):
 
491
        self.make_branch_and_tree('foo')
 
492
        self.make_branch_and_tree('foo/bar')
 
493
        # Sticking a tree inside a control dir is heinous, so let's skip it
 
494
        self.make_branch_and_tree('foo/.bzr/baz')
 
495
        self.make_branch('qux')
 
496
        trees = workingtree.WorkingTree.find_trees('.')
 
497
        self.assertEqual(2, len(list(trees)))
507
498
 
508
499
 
509
500
class TestStoredUncommitted(TestCaseWithTransport):
511
502
    def store_uncommitted(self):
512
503
        tree = self.make_branch_and_tree('tree')
513
504
        tree.commit('get root in there')
514
 
        self.build_tree_contents([('tree/file', b'content')])
515
 
        tree.add('file', b'file-id')
 
505
        self.build_tree_contents([('tree/file', 'content')])
 
506
        tree.add('file', 'file-id')
516
507
        tree.store_uncommitted()
517
508
        return tree
518
509