/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
5557.1.15 by John Arbash Meinel
Merge bzr.dev 5597 to resolve NEWS, aka bzr-2.3.txt
1
# Copyright (C) 2005-2011 Canonical Ltd
1399.1.12 by Robert Collins
add new test script
2
# Authors:  Robert Collins <robert.collins@canonical.com>
3
#
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
8
#
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
4183.7.1 by Sabin Iacob
update FSF mailing address
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1399.1.12 by Robert Collins
add new test script
17
2255.2.121 by John Arbash Meinel
split out the WorkingTreeFormat4 tests into a separate test file
18
from bzrlib import (
19
    bzrdir,
20
    conflicts,
21
    errors,
5662.3.3 by Jelmer Vernooij
add tests
22
    symbol_versioning,
5273.1.7 by Vincent Ladeuil
No more use of the get_transport imported *symbol*, all uses are through
23
    transport,
2255.2.121 by John Arbash Meinel
split out the WorkingTreeFormat4 tests into a separate test file
24
    workingtree,
25
    )
1553.5.74 by Martin Pool
Convert WorkingTree format3 to use LockDirs
26
from bzrlib.lockdir import LockDir
1986.1.8 by Robert Collins
Update to bzr.dev, which involves adding lock_tree_write to MutableTree and MemoryTree.
27
from bzrlib.mutabletree import needs_tree_write_lock
1997.1.1 by Robert Collins
Add WorkingTree.lock_tree_write.
28
from bzrlib.tests import TestCase, TestCaseWithTransport, TestSkipped
29
from bzrlib.workingtree import (
30
    TreeEntry,
31
    TreeDirectory,
32
    TreeFile,
33
    TreeLink,
34
    )
1399.1.12 by Robert Collins
add new test script
35
2255.2.121 by John Arbash Meinel
split out the WorkingTreeFormat4 tests into a separate test file
36
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
37
class TestTreeDirectory(TestCaseWithTransport):
1399.1.12 by Robert Collins
add new test script
38
39
    def test_kind_character(self):
40
        self.assertEqual(TreeDirectory().kind_character(), '/')
41
42
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
43
class TestTreeEntry(TestCaseWithTransport):
1399.1.12 by Robert Collins
add new test script
44
45
    def test_kind_character(self):
46
        self.assertEqual(TreeEntry().kind_character(), '???')
47
48
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
49
class TestTreeFile(TestCaseWithTransport):
1399.1.12 by Robert Collins
add new test script
50
51
    def test_kind_character(self):
52
        self.assertEqual(TreeFile().kind_character(), '')
53
54
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
55
class TestTreeLink(TestCaseWithTransport):
1399.1.12 by Robert Collins
add new test script
56
57
    def test_kind_character(self):
58
        self.assertEqual(TreeLink().kind_character(), '')
59
60
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
61
class TestDefaultFormat(TestCaseWithTransport):
62
63
    def test_get_set_default_format(self):
5662.3.3 by Jelmer Vernooij
add tests
64
        old_format = workingtree.format_registry.get_default()
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
65
        # default is 3
66
        self.assertTrue(isinstance(old_format, workingtree.WorkingTreeFormat3))
5662.3.3 by Jelmer Vernooij
add tests
67
        workingtree.format_registry.set_default(SampleTreeFormat())
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
68
        try:
69
            # the default branch format is used by the meta dir format
70
            # which is not the default bzrdir format at this point
71
            dir = bzrdir.BzrDirMetaFormat1().initialize('.')
72
            dir.create_repository()
73
            dir.create_branch()
74
            result = dir.create_workingtree()
75
            self.assertEqual(result, 'A tree')
76
        finally:
5662.3.3 by Jelmer Vernooij
add tests
77
            workingtree.format_registry.set_default(old_format)
78
        self.assertEqual(old_format, workingtree.format_registry.get_default())
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
79
5816.2.1 by Jelmer Vernooij
Allow lazily setting default for working trees.
80
    def test_get_set_default_format_by_key(self):
81
        old_format = workingtree.format_registry.get_default()
82
        # default is 3
83
        format = SampleTreeFormat()
84
        workingtree.format_registry.register(format)
85
        self.addCleanup(workingtree.format_registry.remove, format)
86
        self.assertTrue(isinstance(old_format, workingtree.WorkingTreeFormat3))
87
        workingtree.format_registry.set_default_key(format.get_format_string())
88
        try:
89
            # the default branch format is used by the meta dir format
90
            # which is not the default bzrdir format at this point
91
            dir = bzrdir.BzrDirMetaFormat1().initialize('.')
92
            dir.create_repository()
93
            dir.create_branch()
94
            result = dir.create_workingtree()
95
            self.assertEqual(result, 'A tree')
96
        finally:
97
            workingtree.format_registry.set_default_key(
98
                old_format.get_format_string())
99
        self.assertEqual(old_format, workingtree.format_registry.get_default())
100
3753.1.1 by John Arbash Meinel
Add some simple direct tests for WT.open and WT.open_containing.
101
    def test_open(self):
102
        tree = self.make_branch_and_tree('.')
3753.1.2 by John Arbash Meinel
Switch to using the class attribute, rather than the instance
103
        open_direct = workingtree.WorkingTree.open('.')
3753.1.1 by John Arbash Meinel
Add some simple direct tests for WT.open and WT.open_containing.
104
        self.assertEqual(tree.basedir, open_direct.basedir)
3753.1.2 by John Arbash Meinel
Switch to using the class attribute, rather than the instance
105
        open_no_args = workingtree.WorkingTree.open()
3753.1.1 by John Arbash Meinel
Add some simple direct tests for WT.open and WT.open_containing.
106
        self.assertEqual(tree.basedir, open_no_args.basedir)
107
108
    def test_open_containing(self):
109
        tree = self.make_branch_and_tree('.')
3753.1.2 by John Arbash Meinel
Switch to using the class attribute, rather than the instance
110
        open_direct, relpath = workingtree.WorkingTree.open_containing('.')
3753.1.1 by John Arbash Meinel
Add some simple direct tests for WT.open and WT.open_containing.
111
        self.assertEqual(tree.basedir, open_direct.basedir)
112
        self.assertEqual('', relpath)
3753.1.2 by John Arbash Meinel
Switch to using the class attribute, rather than the instance
113
        open_no_args, relpath = workingtree.WorkingTree.open_containing()
3753.1.1 by John Arbash Meinel
Add some simple direct tests for WT.open and WT.open_containing.
114
        self.assertEqual(tree.basedir, open_no_args.basedir)
115
        self.assertEqual('', relpath)
3753.1.2 by John Arbash Meinel
Switch to using the class attribute, rather than the instance
116
        open_subdir, relpath = workingtree.WorkingTree.open_containing('subdir')
3753.1.1 by John Arbash Meinel
Add some simple direct tests for WT.open and WT.open_containing.
117
        self.assertEqual(tree.basedir, open_subdir.basedir)
118
        self.assertEqual('subdir', relpath)
119
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
120
121
class SampleTreeFormat(workingtree.WorkingTreeFormat):
122
    """A sample format
123
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
124
    this format is initializable, unsupported to aid in testing the
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
125
    open and open_downlevel routines.
126
    """
127
128
    def get_format_string(self):
129
        """See WorkingTreeFormat.get_format_string()."""
130
        return "Sample tree format."
131
3123.5.3 by Aaron Bentley
Get tests passing with accelerator_tree
132
    def initialize(self, a_bzrdir, revision_id=None, from_branch=None,
3136.1.5 by Aaron Bentley
Fix sample workingtree format
133
                   accelerator_tree=None, hardlink=False):
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
134
        """Sample branches cannot be created."""
135
        t = a_bzrdir.get_workingtree_transport(self)
1955.3.13 by John Arbash Meinel
Run the full test suite, and fix up any deprecation warnings.
136
        t.put_bytes('format', self.get_format_string())
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
137
        return 'A tree'
138
139
    def is_supported(self):
140
        return False
141
142
    def open(self, transport, _found=False):
143
        return "opened tree."
144
145
5642.2.4 by Jelmer Vernooij
add tests.
146
class SampleExtraTreeFormat(workingtree.WorkingTreeFormat):
147
    """A sample format that does not support use in a metadir.
148
149
    """
150
151
    def get_format_string(self):
152
        # Not usable in a metadir, so no format string
153
        return None
154
155
    def initialize(self, a_bzrdir, revision_id=None, from_branch=None,
156
                   accelerator_tree=None, hardlink=False):
157
        raise NotImplementedError(self.initialize)
158
159
    def is_supported(self):
160
        return False
161
162
    def open(self, transport, _found=False):
163
        raise NotImplementedError(self.open)
164
165
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
166
class TestWorkingTreeFormat(TestCaseWithTransport):
167
    """Tests for the WorkingTreeFormat facility."""
168
5816.3.3 by Jelmer Vernooij
Add tariff test to make sure working tree isn't opened by 'bzr serve'
169
    def test_find_format_string(self):
170
        # is the right format object found for a working tree?
171
        branch = self.make_branch('branch')
172
        self.assertRaises(errors.NoWorkingTree,
173
            workingtree.WorkingTreeFormat.find_format_string, branch.bzrdir)
174
        transport = branch.bzrdir.get_workingtree_transport(None)
175
        transport.mkdir('.')
176
        transport.put_bytes("format", "some format name")
177
        # The format does not have to be known by Bazaar,
178
        # find_format_string just retrieves the name
179
        self.assertEquals("some format name",
180
            workingtree.WorkingTreeFormat.find_format_string(branch.bzrdir))
181
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
182
    def test_find_format(self):
183
        # is the right format object found for a working tree?
184
        # create a branch with a few known format objects.
185
        self.build_tree(["foo/", "bar/"])
186
        def check_format(format, url):
187
            dir = format._matchingbzrdir.initialize(url)
188
            dir.create_repository()
189
            dir.create_branch()
190
            format.initialize(dir)
5273.1.7 by Vincent Ladeuil
No more use of the get_transport imported *symbol*, all uses are through
191
            t = transport.get_transport(url)
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
192
            found_format = workingtree.WorkingTreeFormat.find_format(dir)
5784.1.1 by Martin Pool
Stop using failIf, failUnless, etc
193
            self.assertIsInstance(found_format, format.__class__)
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
194
        check_format(workingtree.WorkingTreeFormat3(), "bar")
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
195
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
196
    def test_find_format_no_tree(self):
197
        dir = bzrdir.BzrDirMetaFormat1().initialize('.')
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
198
        self.assertRaises(errors.NoWorkingTree,
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
199
                          workingtree.WorkingTreeFormat.find_format,
200
                          dir)
201
202
    def test_find_format_unknown_format(self):
203
        dir = bzrdir.BzrDirMetaFormat1().initialize('.')
204
        dir.create_repository()
205
        dir.create_branch()
206
        SampleTreeFormat().initialize(dir)
207
        self.assertRaises(errors.UnknownFormatError,
208
                          workingtree.WorkingTreeFormat.find_format,
209
                          dir)
210
211
    def test_register_unregister_format(self):
212
        format = SampleTreeFormat()
213
        # make a control dir
214
        dir = bzrdir.BzrDirMetaFormat1().initialize('.')
215
        dir.create_repository()
216
        dir.create_branch()
217
        # make a branch
218
        format.initialize(dir)
219
        # register a format for it.
5662.3.3 by Jelmer Vernooij
add tests
220
        self.applyDeprecated(symbol_versioning.deprecated_in((2, 4, 0)),
221
            workingtree.WorkingTreeFormat.register_format, format)
222
        self.assertTrue(format in 
223
            self.applyDeprecated(symbol_versioning.deprecated_in((2, 4, 0)),
224
                workingtree.WorkingTreeFormat.get_formats))
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
225
        # which branch.Open will refuse (not supported)
226
        self.assertRaises(errors.UnsupportedFormatError, workingtree.WorkingTree.open, '.')
227
        # but open_downlevel will work
228
        self.assertEqual(format.open(dir), workingtree.WorkingTree.open_downlevel('.'))
229
        # unregister the format
5662.3.3 by Jelmer Vernooij
add tests
230
        self.applyDeprecated(symbol_versioning.deprecated_in((2, 4, 0)),
231
            workingtree.WorkingTreeFormat.unregister_format, format)
232
        self.assertFalse(format in
233
            self.applyDeprecated(symbol_versioning.deprecated_in((2, 4, 0)),
234
                workingtree.WorkingTreeFormat.get_formats))
235
236
237
class TestWorkingTreeFormatRegistry(TestCase):
238
239
    def setUp(self):
240
        super(TestWorkingTreeFormatRegistry, self).setUp()
241
        self.registry = workingtree.WorkingTreeFormatRegistry()
242
243
    def test_register_unregister_format(self):
244
        format = SampleTreeFormat()
245
        self.registry.register(format)
246
        self.assertEquals(format, self.registry.get("Sample tree format."))
247
        self.registry.remove(format)
248
        self.assertRaises(KeyError, self.registry.get, "Sample tree format.")
249
250
    def test_get_all(self):
251
        format = SampleTreeFormat()
252
        self.assertEquals([], self.registry._get_all())
253
        self.registry.register(format)
254
        self.assertEquals([format], self.registry._get_all())
255
256
    def test_register_extra(self):
5642.2.4 by Jelmer Vernooij
add tests.
257
        format = SampleExtraTreeFormat()
5662.3.3 by Jelmer Vernooij
add tests
258
        self.assertEquals([], self.registry._get_all())
259
        self.registry.register_extra(format)
260
        self.assertEquals([format], self.registry._get_all())
261
262
    def test_register_extra_lazy(self):
263
        self.assertEquals([], self.registry._get_all())
264
        self.registry.register_extra_lazy("bzrlib.tests.test_workingtree",
265
            "SampleExtraTreeFormat")
266
        formats = self.registry._get_all()
267
        self.assertEquals(1, len(formats))
268
        self.assertIsInstance(formats[0], SampleExtraTreeFormat)
1534.4.51 by Robert Collins
Test the disk layout of format3 working trees.
269
270
271
class TestWorkingTreeFormat3(TestCaseWithTransport):
272
    """Tests specific to WorkingTreeFormat3."""
273
274
    def test_disk_layout(self):
275
        control = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
276
        control.create_repository()
277
        control.create_branch()
278
        tree = workingtree.WorkingTreeFormat3().initialize(control)
279
        # we want:
280
        # format 'Bazaar-NG Working Tree format 3'
281
        # inventory = blank inventory
282
        # pending-merges = ''
283
        # stat-cache = ??
284
        # no inventory.basis yet
285
        t = control.get_workingtree_transport(None)
1553.5.81 by Martin Pool
Revert change to WorkingTreeFormat3 format string; too many things want it the old way
286
        self.assertEqualDiff('Bazaar-NG Working Tree format 3',
1534.4.51 by Robert Collins
Test the disk layout of format3 working trees.
287
                             t.get('format').read())
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
288
        self.assertEqualDiff(t.get('inventory').read(),
2100.3.12 by Aaron Bentley
Stop generating unique roots for WorkingTree3
289
                              '<inventory format="5">\n'
1731.1.33 by Aaron Bentley
Revert no-special-root changes
290
                              '</inventory>\n',
291
                             )
1534.4.51 by Robert Collins
Test the disk layout of format3 working trees.
292
        self.assertEqualDiff('### bzr hashcache v5\n',
293
                             t.get('stat-cache').read())
294
        self.assertFalse(t.has('inventory.basis'))
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
295
        # no last-revision file means 'None' or 'NULLREVISION'
296
        self.assertFalse(t.has('last-revision'))
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
297
        # TODO RBC 20060210 do a commit, check the inventory.basis is created
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
298
        # correctly and last-revision file becomes present.
1553.5.74 by Martin Pool
Convert WorkingTree format3 to use LockDirs
299
300
    def test_uses_lockdir(self):
301
        """WorkingTreeFormat3 uses its own LockDir:
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
302
1553.5.74 by Martin Pool
Convert WorkingTree format3 to use LockDirs
303
            - lock is a directory
304
            - when the WorkingTree is locked, LockDir can see that
305
        """
306
        t = self.get_transport()
307
        url = self.get_url()
308
        dir = bzrdir.BzrDirMetaFormat1().initialize(url)
309
        repo = dir.create_repository()
310
        branch = dir.create_branch()
1558.10.1 by Aaron Bentley
Handle lockdirs over NFS properly
311
        try:
312
            tree = workingtree.WorkingTreeFormat3().initialize(dir)
313
        except errors.NotLocalUrl:
314
            raise TestSkipped('Not a local URL')
1553.5.74 by Martin Pool
Convert WorkingTree format3 to use LockDirs
315
        self.assertIsDirectory('.bzr', t)
316
        self.assertIsDirectory('.bzr/checkout', t)
317
        self.assertIsDirectory('.bzr/checkout/lock', t)
318
        our_lock = LockDir(t, '.bzr/checkout/lock')
319
        self.assertEquals(our_lock.peek(), None)
1553.5.75 by Martin Pool
Additional WorkingTree LockDir test
320
        tree.lock_write()
321
        self.assertTrue(our_lock.peek())
322
        tree.unlock()
323
        self.assertEquals(our_lock.peek(), None)
1534.10.6 by Aaron Bentley
Conflict serialization working for WorkingTree3
324
1815.2.2 by Jelmer Vernooij
Move missing_pending_merges test to WorkingTreeFormat3-specific tests.
325
    def test_missing_pending_merges(self):
326
        control = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
327
        control.create_repository()
328
        control.create_branch()
329
        tree = workingtree.WorkingTreeFormat3().initialize(control)
3407.2.14 by Martin Pool
Remove more cases of getting transport via control_files
330
        tree._transport.delete("pending-merges")
1908.6.11 by Robert Collins
Remove usage of tree.pending_merges().
331
        self.assertEqual([], tree.get_parent_ids())
1815.2.2 by Jelmer Vernooij
Move missing_pending_merges test to WorkingTreeFormat3-specific tests.
332
1666.1.4 by Robert Collins
* 'Metadir' is now the default disk format. This improves behaviour in
333
1997.1.1 by Robert Collins
Add WorkingTree.lock_tree_write.
334
class InstrumentedTree(object):
335
    """A instrumented tree to check the needs_tree_write_lock decorator."""
336
337
    def __init__(self):
338
        self._locks = []
339
340
    def lock_tree_write(self):
341
        self._locks.append('t')
342
343
    @needs_tree_write_lock
344
    def method_with_tree_write_lock(self, *args, **kwargs):
345
        """A lock_tree_write decorated method that returns its arguments."""
346
        return args, kwargs
347
348
    @needs_tree_write_lock
349
    def method_that_raises(self):
350
        """This method causes an exception when called with parameters.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
351
1997.1.1 by Robert Collins
Add WorkingTree.lock_tree_write.
352
        This allows the decorator code to be checked - it should still call
353
        unlock.
354
        """
355
356
    def unlock(self):
357
        self._locks.append('u')
358
359
360
class TestInstrumentedTree(TestCase):
361
362
    def test_needs_tree_write_lock(self):
363
        """@needs_tree_write_lock should be semantically transparent."""
364
        tree = InstrumentedTree()
365
        self.assertEqual(
366
            'method_with_tree_write_lock',
367
            tree.method_with_tree_write_lock.__name__)
5131.2.1 by Martin
Permit bzrlib to run under python -OO by explictly assigning to __doc__ for user-visible docstrings
368
        self.assertDocstring(
1997.1.1 by Robert Collins
Add WorkingTree.lock_tree_write.
369
            "A lock_tree_write decorated method that returns its arguments.",
5131.2.1 by Martin
Permit bzrlib to run under python -OO by explictly assigning to __doc__ for user-visible docstrings
370
            tree.method_with_tree_write_lock)
1997.1.1 by Robert Collins
Add WorkingTree.lock_tree_write.
371
        args = (1, 2, 3)
372
        kwargs = {'a':'b'}
373
        result = tree.method_with_tree_write_lock(1,2,3, a='b')
374
        self.assertEqual((args, kwargs), result)
375
        self.assertEqual(['t', 'u'], tree._locks)
376
        self.assertRaises(TypeError, tree.method_that_raises, 'foo')
377
        self.assertEqual(['t', 'u', 't', 'u'], tree._locks)
2120.7.2 by Aaron Bentley
Move autoresolve functionality to workingtree
378
379
3017.2.1 by Aaron Bentley
Revert now resolves conflicts recursively (#102739)
380
class TestRevert(TestCaseWithTransport):
381
382
    def test_revert_conflicts_recursive(self):
383
        this_tree = self.make_branch_and_tree('this-tree')
384
        self.build_tree_contents([('this-tree/foo/',),
385
                                  ('this-tree/foo/bar', 'bar')])
386
        this_tree.add(['foo', 'foo/bar'])
387
        this_tree.commit('created foo/bar')
388
        other_tree = this_tree.bzrdir.sprout('other-tree').open_workingtree()
389
        self.build_tree_contents([('other-tree/foo/bar', 'baz')])
390
        other_tree.commit('changed bar')
391
        self.build_tree_contents([('this-tree/foo/bar', 'qux')])
392
        this_tree.commit('changed qux')
393
        this_tree.merge_from_branch(other_tree.branch)
394
        self.assertEqual(1, len(this_tree.conflicts()))
395
        this_tree.revert(['foo'])
396
        self.assertEqual(0, len(this_tree.conflicts()))
397
398
2120.7.2 by Aaron Bentley
Move autoresolve functionality to workingtree
399
class TestAutoResolve(TestCaseWithTransport):
400
401
    def test_auto_resolve(self):
402
        base = self.make_branch_and_tree('base')
403
        self.build_tree_contents([('base/hello', 'Hello')])
404
        base.add('hello', 'hello_id')
405
        base.commit('Hello')
406
        other = base.bzrdir.sprout('other').open_workingtree()
407
        self.build_tree_contents([('other/hello', 'hELLO')])
408
        other.commit('Case switch')
409
        this = base.bzrdir.sprout('this').open_workingtree()
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
410
        self.assertPathExists('this/hello')
2120.7.2 by Aaron Bentley
Move autoresolve functionality to workingtree
411
        self.build_tree_contents([('this/hello', 'Hello World')])
412
        this.commit('Add World')
413
        this.merge_from_branch(other.branch)
5050.51.3 by Vincent Ladeuil
Fix test failing on pqm.
414
        self.assertEqual([conflicts.TextConflict('hello', 'hello_id')],
2120.7.2 by Aaron Bentley
Move autoresolve functionality to workingtree
415
                         this.conflicts())
416
        this.auto_resolve()
5050.51.3 by Vincent Ladeuil
Fix test failing on pqm.
417
        self.assertEqual([conflicts.TextConflict('hello', 'hello_id')],
2120.7.2 by Aaron Bentley
Move autoresolve functionality to workingtree
418
                         this.conflicts())
419
        self.build_tree_contents([('this/hello', '<<<<<<<')])
420
        this.auto_resolve()
5050.51.3 by Vincent Ladeuil
Fix test failing on pqm.
421
        self.assertEqual([conflicts.TextConflict('hello', 'hello_id')],
2120.7.2 by Aaron Bentley
Move autoresolve functionality to workingtree
422
                         this.conflicts())
423
        self.build_tree_contents([('this/hello', '=======')])
424
        this.auto_resolve()
5050.51.3 by Vincent Ladeuil
Fix test failing on pqm.
425
        self.assertEqual([conflicts.TextConflict('hello', 'hello_id')],
2120.7.2 by Aaron Bentley
Move autoresolve functionality to workingtree
426
                         this.conflicts())
427
        self.build_tree_contents([('this/hello', '\n>>>>>>>')])
428
        remaining, resolved = this.auto_resolve()
5050.51.3 by Vincent Ladeuil
Fix test failing on pqm.
429
        self.assertEqual([conflicts.TextConflict('hello', 'hello_id')],
2120.7.2 by Aaron Bentley
Move autoresolve functionality to workingtree
430
                         this.conflicts())
431
        self.assertEqual([], resolved)
432
        self.build_tree_contents([('this/hello', 'hELLO wORLD')])
433
        remaining, resolved = this.auto_resolve()
434
        self.assertEqual([], this.conflicts())
5050.51.3 by Vincent Ladeuil
Fix test failing on pqm.
435
        self.assertEqual([conflicts.TextConflict('hello', 'hello_id')],
2120.7.2 by Aaron Bentley
Move autoresolve functionality to workingtree
436
                         resolved)
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
437
        self.assertPathDoesNotExist('this/hello.BASE')
2120.7.3 by Aaron Bentley
Update resolve command to automatically mark conflicts as resolved
438
439
    def test_auto_resolve_dir(self):
440
        tree = self.make_branch_and_tree('tree')
441
        self.build_tree(['tree/hello/'])
442
        tree.add('hello', 'hello-id')
5050.51.3 by Vincent Ladeuil
Fix test failing on pqm.
443
        file_conflict = conflicts.TextConflict('file', 'hello-id')
2120.7.3 by Aaron Bentley
Update resolve command to automatically mark conflicts as resolved
444
        tree.set_conflicts(conflicts.ConflictList([file_conflict]))
445
        tree.auto_resolve()
3140.1.4 by Aaron Bentley
Add WorkingTree.find_trees
446
447
448
class TestFindTrees(TestCaseWithTransport):
449
450
    def test_find_trees(self):
451
        self.make_branch_and_tree('foo')
452
        self.make_branch_and_tree('foo/bar')
453
        # Sticking a tree inside a control dir is heinous, so let's skip it
454
        self.make_branch_and_tree('foo/.bzr/baz')
455
        self.make_branch('qux')
456
        trees = workingtree.WorkingTree.find_trees('.')
457
        self.assertEqual(2, len(list(trees)))