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