~bzr-pqm/bzr/bzr.dev

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
18
import os
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
19
2255.2.121 by John Arbash Meinel
split out the WorkingTreeFormat4 tests into a separate test file
20
from bzrlib import (
21
    bzrdir,
22
    conflicts,
23
    errors,
5273.1.7 by Vincent Ladeuil
No more use of the get_transport imported *symbol*, all uses are through
24
    transport,
2255.2.121 by John Arbash Meinel
split out the WorkingTreeFormat4 tests into a separate test file
25
    workingtree,
26
    )
1553.5.74 by Martin Pool
Convert WorkingTree format3 to use LockDirs
27
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.
28
from bzrlib.mutabletree import needs_tree_write_lock
1997.1.1 by Robert Collins
Add WorkingTree.lock_tree_write.
29
from bzrlib.tests import TestCase, TestCaseWithTransport, TestSkipped
30
from bzrlib.workingtree import (
31
    TreeEntry,
32
    TreeDirectory,
33
    TreeFile,
34
    TreeLink,
35
    )
1399.1.12 by Robert Collins
add new test script
36
2255.2.121 by John Arbash Meinel
split out the WorkingTreeFormat4 tests into a separate test file
37
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
38
class TestTreeDirectory(TestCaseWithTransport):
1399.1.12 by Robert Collins
add new test script
39
40
    def test_kind_character(self):
41
        self.assertEqual(TreeDirectory().kind_character(), '/')
42
43
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
44
class TestTreeEntry(TestCaseWithTransport):
1399.1.12 by Robert Collins
add new test script
45
46
    def test_kind_character(self):
47
        self.assertEqual(TreeEntry().kind_character(), '???')
48
49
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
50
class TestTreeFile(TestCaseWithTransport):
1399.1.12 by Robert Collins
add new test script
51
52
    def test_kind_character(self):
53
        self.assertEqual(TreeFile().kind_character(), '')
54
55
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
56
class TestTreeLink(TestCaseWithTransport):
1399.1.12 by Robert Collins
add new test script
57
58
    def test_kind_character(self):
59
        self.assertEqual(TreeLink().kind_character(), '')
60
61
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
62
class TestDefaultFormat(TestCaseWithTransport):
63
64
    def test_get_set_default_format(self):
65
        old_format = workingtree.WorkingTreeFormat.get_default_format()
66
        # default is 3
67
        self.assertTrue(isinstance(old_format, workingtree.WorkingTreeFormat3))
68
        workingtree.WorkingTreeFormat.set_default_format(SampleTreeFormat())
69
        try:
70
            # the default branch format is used by the meta dir format
71
            # which is not the default bzrdir format at this point
72
            dir = bzrdir.BzrDirMetaFormat1().initialize('.')
73
            dir.create_repository()
74
            dir.create_branch()
75
            result = dir.create_workingtree()
76
            self.assertEqual(result, 'A tree')
77
        finally:
78
            workingtree.WorkingTreeFormat.set_default_format(old_format)
79
        self.assertEqual(old_format, workingtree.WorkingTreeFormat.get_default_format())
80
3753.1.1 by John Arbash Meinel
Add some simple direct tests for WT.open and WT.open_containing.
81
    def test_open(self):
82
        tree = self.make_branch_and_tree('.')
3753.1.2 by John Arbash Meinel
Switch to using the class attribute, rather than the instance
83
        open_direct = workingtree.WorkingTree.open('.')
3753.1.1 by John Arbash Meinel
Add some simple direct tests for WT.open and WT.open_containing.
84
        self.assertEqual(tree.basedir, open_direct.basedir)
3753.1.2 by John Arbash Meinel
Switch to using the class attribute, rather than the instance
85
        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.
86
        self.assertEqual(tree.basedir, open_no_args.basedir)
87
88
    def test_open_containing(self):
89
        tree = self.make_branch_and_tree('.')
3753.1.2 by John Arbash Meinel
Switch to using the class attribute, rather than the instance
90
        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.
91
        self.assertEqual(tree.basedir, open_direct.basedir)
92
        self.assertEqual('', relpath)
3753.1.2 by John Arbash Meinel
Switch to using the class attribute, rather than the instance
93
        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.
94
        self.assertEqual(tree.basedir, open_no_args.basedir)
95
        self.assertEqual('', relpath)
3753.1.2 by John Arbash Meinel
Switch to using the class attribute, rather than the instance
96
        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.
97
        self.assertEqual(tree.basedir, open_subdir.basedir)
98
        self.assertEqual('subdir', relpath)
99
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
100
101
class SampleTreeFormat(workingtree.WorkingTreeFormat):
102
    """A sample format
103
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
104
    this format is initializable, unsupported to aid in testing the
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
105
    open and open_downlevel routines.
106
    """
107
108
    def get_format_string(self):
109
        """See WorkingTreeFormat.get_format_string()."""
110
        return "Sample tree format."
111
3123.5.3 by Aaron Bentley
Get tests passing with accelerator_tree
112
    def initialize(self, a_bzrdir, revision_id=None, from_branch=None,
3136.1.5 by Aaron Bentley
Fix sample workingtree format
113
                   accelerator_tree=None, hardlink=False):
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
114
        """Sample branches cannot be created."""
115
        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.
116
        t.put_bytes('format', self.get_format_string())
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
117
        return 'A tree'
118
119
    def is_supported(self):
120
        return False
121
122
    def open(self, transport, _found=False):
123
        return "opened tree."
124
125
5642.2.4 by Jelmer Vernooij
add tests.
126
class SampleExtraTreeFormat(workingtree.WorkingTreeFormat):
127
    """A sample format that does not support use in a metadir.
128
129
    """
130
131
    def get_format_string(self):
132
        # Not usable in a metadir, so no format string
133
        return None
134
135
    def initialize(self, a_bzrdir, revision_id=None, from_branch=None,
136
                   accelerator_tree=None, hardlink=False):
137
        raise NotImplementedError(self.initialize)
138
139
    def is_supported(self):
140
        return False
141
142
    def open(self, transport, _found=False):
143
        raise NotImplementedError(self.open)
144
145
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
146
class TestWorkingTreeFormat(TestCaseWithTransport):
147
    """Tests for the WorkingTreeFormat facility."""
148
149
    def test_find_format(self):
150
        # is the right format object found for a working tree?
151
        # create a branch with a few known format objects.
152
        self.build_tree(["foo/", "bar/"])
153
        def check_format(format, url):
154
            dir = format._matchingbzrdir.initialize(url)
155
            dir.create_repository()
156
            dir.create_branch()
157
            format.initialize(dir)
5273.1.7 by Vincent Ladeuil
No more use of the get_transport imported *symbol*, all uses are through
158
            t = transport.get_transport(url)
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
159
            found_format = workingtree.WorkingTreeFormat.find_format(dir)
160
            self.failUnless(isinstance(found_format, format.__class__))
161
        check_format(workingtree.WorkingTreeFormat3(), "bar")
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
162
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
163
    def test_find_format_no_tree(self):
164
        dir = bzrdir.BzrDirMetaFormat1().initialize('.')
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
165
        self.assertRaises(errors.NoWorkingTree,
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
166
                          workingtree.WorkingTreeFormat.find_format,
167
                          dir)
168
169
    def test_find_format_unknown_format(self):
170
        dir = bzrdir.BzrDirMetaFormat1().initialize('.')
171
        dir.create_repository()
172
        dir.create_branch()
173
        SampleTreeFormat().initialize(dir)
174
        self.assertRaises(errors.UnknownFormatError,
175
                          workingtree.WorkingTreeFormat.find_format,
176
                          dir)
177
178
    def test_register_unregister_format(self):
179
        format = SampleTreeFormat()
180
        # make a control dir
181
        dir = bzrdir.BzrDirMetaFormat1().initialize('.')
182
        dir.create_repository()
183
        dir.create_branch()
184
        # make a branch
185
        format.initialize(dir)
186
        # register a format for it.
187
        workingtree.WorkingTreeFormat.register_format(format)
5642.2.4 by Jelmer Vernooij
add tests.
188
        self.assertTrue(format in workingtree.WorkingTreeFormat.get_formats())
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
189
        # which branch.Open will refuse (not supported)
190
        self.assertRaises(errors.UnsupportedFormatError, workingtree.WorkingTree.open, '.')
191
        # but open_downlevel will work
192
        self.assertEqual(format.open(dir), workingtree.WorkingTree.open_downlevel('.'))
193
        # unregister the format
194
        workingtree.WorkingTreeFormat.unregister_format(format)
5642.2.4 by Jelmer Vernooij
add tests.
195
        self.assertFalse(format in workingtree.WorkingTreeFormat.get_formats())
196
197
    def test_register_unregister_extra_format(self):
198
        format = SampleExtraTreeFormat()
199
        workingtree.WorkingTreeFormat.register_extra_format(format)
200
        self.assertTrue(format in workingtree.WorkingTreeFormat.get_formats())
201
        workingtree.WorkingTreeFormat.unregister_extra_format(format)
202
        self.assertFalse(format in workingtree.WorkingTreeFormat.get_formats())
1534.4.51 by Robert Collins
Test the disk layout of format3 working trees.
203
204
205
class TestWorkingTreeFormat3(TestCaseWithTransport):
206
    """Tests specific to WorkingTreeFormat3."""
207
208
    def test_disk_layout(self):
209
        control = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
210
        control.create_repository()
211
        control.create_branch()
212
        tree = workingtree.WorkingTreeFormat3().initialize(control)
213
        # we want:
214
        # format 'Bazaar-NG Working Tree format 3'
215
        # inventory = blank inventory
216
        # pending-merges = ''
217
        # stat-cache = ??
218
        # no inventory.basis yet
219
        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
220
        self.assertEqualDiff('Bazaar-NG Working Tree format 3',
1534.4.51 by Robert Collins
Test the disk layout of format3 working trees.
221
                             t.get('format').read())
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
222
        self.assertEqualDiff(t.get('inventory').read(),
2100.3.12 by Aaron Bentley
Stop generating unique roots for WorkingTree3
223
                              '<inventory format="5">\n'
1731.1.33 by Aaron Bentley
Revert no-special-root changes
224
                              '</inventory>\n',
225
                             )
1534.4.51 by Robert Collins
Test the disk layout of format3 working trees.
226
        self.assertEqualDiff('### bzr hashcache v5\n',
227
                             t.get('stat-cache').read())
228
        self.assertFalse(t.has('inventory.basis'))
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
229
        # no last-revision file means 'None' or 'NULLREVISION'
230
        self.assertFalse(t.has('last-revision'))
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
231
        # 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.
232
        # correctly and last-revision file becomes present.
1553.5.74 by Martin Pool
Convert WorkingTree format3 to use LockDirs
233
234
    def test_uses_lockdir(self):
235
        """WorkingTreeFormat3 uses its own LockDir:
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
236
1553.5.74 by Martin Pool
Convert WorkingTree format3 to use LockDirs
237
            - lock is a directory
238
            - when the WorkingTree is locked, LockDir can see that
239
        """
240
        t = self.get_transport()
241
        url = self.get_url()
242
        dir = bzrdir.BzrDirMetaFormat1().initialize(url)
243
        repo = dir.create_repository()
244
        branch = dir.create_branch()
1558.10.1 by Aaron Bentley
Handle lockdirs over NFS properly
245
        try:
246
            tree = workingtree.WorkingTreeFormat3().initialize(dir)
247
        except errors.NotLocalUrl:
248
            raise TestSkipped('Not a local URL')
1553.5.74 by Martin Pool
Convert WorkingTree format3 to use LockDirs
249
        self.assertIsDirectory('.bzr', t)
250
        self.assertIsDirectory('.bzr/checkout', t)
251
        self.assertIsDirectory('.bzr/checkout/lock', t)
252
        our_lock = LockDir(t, '.bzr/checkout/lock')
253
        self.assertEquals(our_lock.peek(), None)
1553.5.75 by Martin Pool
Additional WorkingTree LockDir test
254
        tree.lock_write()
255
        self.assertTrue(our_lock.peek())
256
        tree.unlock()
257
        self.assertEquals(our_lock.peek(), None)
1534.10.6 by Aaron Bentley
Conflict serialization working for WorkingTree3
258
1815.2.2 by Jelmer Vernooij
Move missing_pending_merges test to WorkingTreeFormat3-specific tests.
259
    def test_missing_pending_merges(self):
260
        control = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
261
        control.create_repository()
262
        control.create_branch()
263
        tree = workingtree.WorkingTreeFormat3().initialize(control)
3407.2.14 by Martin Pool
Remove more cases of getting transport via control_files
264
        tree._transport.delete("pending-merges")
1908.6.11 by Robert Collins
Remove usage of tree.pending_merges().
265
        self.assertEqual([], tree.get_parent_ids())
1815.2.2 by Jelmer Vernooij
Move missing_pending_merges test to WorkingTreeFormat3-specific tests.
266
1666.1.4 by Robert Collins
* 'Metadir' is now the default disk format. This improves behaviour in
267
268
class TestFormat2WorkingTree(TestCaseWithTransport):
269
    """Tests that are specific to format 2 trees."""
270
1534.10.8 by Aaron Bentley
Implemented conflict_lines in terms of old system on WorkingTree
271
    def create_format2_tree(self, url):
1666.1.4 by Robert Collins
* 'Metadir' is now the default disk format. This improves behaviour in
272
        return self.make_branch_and_tree(
2255.2.121 by John Arbash Meinel
split out the WorkingTreeFormat4 tests into a separate test file
273
            url, format=bzrdir.BzrDirFormat6())
1534.10.6 by Aaron Bentley
Conflict serialization working for WorkingTree3
274
1666.1.4 by Robert Collins
* 'Metadir' is now the default disk format. This improves behaviour in
275
    def test_conflicts(self):
1534.10.8 by Aaron Bentley
Implemented conflict_lines in terms of old system on WorkingTree
276
        # test backwards compatability
277
        tree = self.create_format2_tree('.')
1534.10.22 by Aaron Bentley
Got ConflictList implemented
278
        self.assertRaises(errors.UnsupportedOperation, tree.set_conflicts,
1534.10.8 by Aaron Bentley
Implemented conflict_lines in terms of old system on WorkingTree
279
                          None)
280
        file('lala.BASE', 'wb').write('labase')
1773.4.1 by Martin Pool
Add pyflakes makefile target; fix many warnings
281
        expected = conflicts.ContentsConflict('lala')
1534.10.22 by Aaron Bentley
Got ConflictList implemented
282
        self.assertEqual(list(tree.conflicts()), [expected])
1534.10.8 by Aaron Bentley
Implemented conflict_lines in terms of old system on WorkingTree
283
        file('lala', 'wb').write('la')
284
        tree.add('lala', 'lala-id')
1773.4.1 by Martin Pool
Add pyflakes makefile target; fix many warnings
285
        expected = conflicts.ContentsConflict('lala', file_id='lala-id')
1534.10.22 by Aaron Bentley
Got ConflictList implemented
286
        self.assertEqual(list(tree.conflicts()), [expected])
1534.10.8 by Aaron Bentley
Implemented conflict_lines in terms of old system on WorkingTree
287
        file('lala.THIS', 'wb').write('lathis')
288
        file('lala.OTHER', 'wb').write('laother')
289
        # When "text conflict"s happen, stem, THIS and OTHER are text
1773.4.1 by Martin Pool
Add pyflakes makefile target; fix many warnings
290
        expected = conflicts.TextConflict('lala', file_id='lala-id')
1534.10.22 by Aaron Bentley
Got ConflictList implemented
291
        self.assertEqual(list(tree.conflicts()), [expected])
1534.10.8 by Aaron Bentley
Implemented conflict_lines in terms of old system on WorkingTree
292
        os.unlink('lala.OTHER')
293
        os.mkdir('lala.OTHER')
1773.4.1 by Martin Pool
Add pyflakes makefile target; fix many warnings
294
        expected = conflicts.ContentsConflict('lala', file_id='lala-id')
1534.10.22 by Aaron Bentley
Got ConflictList implemented
295
        self.assertEqual(list(tree.conflicts()), [expected])
1713.2.3 by Robert Collins
Combine ignore rules into a single regex preventing pathological behaviour during add.
296
297
1997.1.1 by Robert Collins
Add WorkingTree.lock_tree_write.
298
class InstrumentedTree(object):
299
    """A instrumented tree to check the needs_tree_write_lock decorator."""
300
301
    def __init__(self):
302
        self._locks = []
303
304
    def lock_tree_write(self):
305
        self._locks.append('t')
306
307
    @needs_tree_write_lock
308
    def method_with_tree_write_lock(self, *args, **kwargs):
309
        """A lock_tree_write decorated method that returns its arguments."""
310
        return args, kwargs
311
312
    @needs_tree_write_lock
313
    def method_that_raises(self):
314
        """This method causes an exception when called with parameters.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
315
1997.1.1 by Robert Collins
Add WorkingTree.lock_tree_write.
316
        This allows the decorator code to be checked - it should still call
317
        unlock.
318
        """
319
320
    def unlock(self):
321
        self._locks.append('u')
322
323
324
class TestInstrumentedTree(TestCase):
325
326
    def test_needs_tree_write_lock(self):
327
        """@needs_tree_write_lock should be semantically transparent."""
328
        tree = InstrumentedTree()
329
        self.assertEqual(
330
            'method_with_tree_write_lock',
331
            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
332
        self.assertDocstring(
1997.1.1 by Robert Collins
Add WorkingTree.lock_tree_write.
333
            "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
334
            tree.method_with_tree_write_lock)
1997.1.1 by Robert Collins
Add WorkingTree.lock_tree_write.
335
        args = (1, 2, 3)
336
        kwargs = {'a':'b'}
337
        result = tree.method_with_tree_write_lock(1,2,3, a='b')
338
        self.assertEqual((args, kwargs), result)
339
        self.assertEqual(['t', 'u'], tree._locks)
340
        self.assertRaises(TypeError, tree.method_that_raises, 'foo')
341
        self.assertEqual(['t', 'u', 't', 'u'], tree._locks)
2120.7.2 by Aaron Bentley
Move autoresolve functionality to workingtree
342
343
3017.2.1 by Aaron Bentley
Revert now resolves conflicts recursively (#102739)
344
class TestRevert(TestCaseWithTransport):
345
346
    def test_revert_conflicts_recursive(self):
347
        this_tree = self.make_branch_and_tree('this-tree')
348
        self.build_tree_contents([('this-tree/foo/',),
349
                                  ('this-tree/foo/bar', 'bar')])
350
        this_tree.add(['foo', 'foo/bar'])
351
        this_tree.commit('created foo/bar')
352
        other_tree = this_tree.bzrdir.sprout('other-tree').open_workingtree()
353
        self.build_tree_contents([('other-tree/foo/bar', 'baz')])
354
        other_tree.commit('changed bar')
355
        self.build_tree_contents([('this-tree/foo/bar', 'qux')])
356
        this_tree.commit('changed qux')
357
        this_tree.merge_from_branch(other_tree.branch)
358
        self.assertEqual(1, len(this_tree.conflicts()))
359
        this_tree.revert(['foo'])
360
        self.assertEqual(0, len(this_tree.conflicts()))
361
362
2120.7.2 by Aaron Bentley
Move autoresolve functionality to workingtree
363
class TestAutoResolve(TestCaseWithTransport):
364
365
    def test_auto_resolve(self):
366
        base = self.make_branch_and_tree('base')
367
        self.build_tree_contents([('base/hello', 'Hello')])
368
        base.add('hello', 'hello_id')
369
        base.commit('Hello')
370
        other = base.bzrdir.sprout('other').open_workingtree()
371
        self.build_tree_contents([('other/hello', 'hELLO')])
372
        other.commit('Case switch')
373
        this = base.bzrdir.sprout('this').open_workingtree()
374
        self.failUnlessExists('this/hello')
375
        self.build_tree_contents([('this/hello', 'Hello World')])
376
        this.commit('Add World')
377
        this.merge_from_branch(other.branch)
5050.51.3 by Vincent Ladeuil
Fix test failing on pqm.
378
        self.assertEqual([conflicts.TextConflict('hello', 'hello_id')],
2120.7.2 by Aaron Bentley
Move autoresolve functionality to workingtree
379
                         this.conflicts())
380
        this.auto_resolve()
5050.51.3 by Vincent Ladeuil
Fix test failing on pqm.
381
        self.assertEqual([conflicts.TextConflict('hello', 'hello_id')],
2120.7.2 by Aaron Bentley
Move autoresolve functionality to workingtree
382
                         this.conflicts())
383
        self.build_tree_contents([('this/hello', '<<<<<<<')])
384
        this.auto_resolve()
5050.51.3 by Vincent Ladeuil
Fix test failing on pqm.
385
        self.assertEqual([conflicts.TextConflict('hello', 'hello_id')],
2120.7.2 by Aaron Bentley
Move autoresolve functionality to workingtree
386
                         this.conflicts())
387
        self.build_tree_contents([('this/hello', '=======')])
388
        this.auto_resolve()
5050.51.3 by Vincent Ladeuil
Fix test failing on pqm.
389
        self.assertEqual([conflicts.TextConflict('hello', 'hello_id')],
2120.7.2 by Aaron Bentley
Move autoresolve functionality to workingtree
390
                         this.conflicts())
391
        self.build_tree_contents([('this/hello', '\n>>>>>>>')])
392
        remaining, resolved = this.auto_resolve()
5050.51.3 by Vincent Ladeuil
Fix test failing on pqm.
393
        self.assertEqual([conflicts.TextConflict('hello', 'hello_id')],
2120.7.2 by Aaron Bentley
Move autoresolve functionality to workingtree
394
                         this.conflicts())
395
        self.assertEqual([], resolved)
396
        self.build_tree_contents([('this/hello', 'hELLO wORLD')])
397
        remaining, resolved = this.auto_resolve()
398
        self.assertEqual([], this.conflicts())
5050.51.3 by Vincent Ladeuil
Fix test failing on pqm.
399
        self.assertEqual([conflicts.TextConflict('hello', 'hello_id')],
2120.7.2 by Aaron Bentley
Move autoresolve functionality to workingtree
400
                         resolved)
401
        self.failIfExists('this/hello.BASE')
2120.7.3 by Aaron Bentley
Update resolve command to automatically mark conflicts as resolved
402
403
    def test_auto_resolve_dir(self):
404
        tree = self.make_branch_and_tree('tree')
405
        self.build_tree(['tree/hello/'])
406
        tree.add('hello', 'hello-id')
5050.51.3 by Vincent Ladeuil
Fix test failing on pqm.
407
        file_conflict = conflicts.TextConflict('file', 'hello-id')
2120.7.3 by Aaron Bentley
Update resolve command to automatically mark conflicts as resolved
408
        tree.set_conflicts(conflicts.ConflictList([file_conflict]))
409
        tree.auto_resolve()
3140.1.4 by Aaron Bentley
Add WorkingTree.find_trees
410
411
412
class TestFindTrees(TestCaseWithTransport):
413
414
    def test_find_trees(self):
415
        self.make_branch_and_tree('foo')
416
        self.make_branch_and_tree('foo/bar')
417
        # Sticking a tree inside a control dir is heinous, so let's skip it
418
        self.make_branch_and_tree('foo/.bzr/baz')
419
        self.make_branch('qux')
420
        trees = workingtree.WorkingTree.find_trees('.')
421
        self.assertEqual(2, len(list(trees)))