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
18
from cStringIO import StringIO
20
21
from bzrlib import (
27
from bzrlib.branch import Branch
28
from bzrlib.bzrdir import BzrDir
27
29
from bzrlib.lockdir import LockDir
28
30
from bzrlib.mutabletree import needs_tree_write_lock
29
31
from bzrlib.tests import TestCase, TestCaseWithTransport, TestSkipped
32
from bzrlib.transport import get_transport
30
33
from bzrlib.workingtree import (
123
126
return "opened tree."
126
class SampleExtraTreeFormat(workingtree.WorkingTreeFormat):
127
"""A sample format that does not support use in a metadir.
131
def get_format_string(self):
132
# Not usable in a metadir, so no format string
135
def initialize(self, a_bzrdir, revision_id=None, from_branch=None,
136
accelerator_tree=None, hardlink=False):
137
raise NotImplementedError(self.initialize)
139
def is_supported(self):
142
def open(self, transport, _found=False):
143
raise NotImplementedError(self.open)
146
129
class TestWorkingTreeFormat(TestCaseWithTransport):
147
130
"""Tests for the WorkingTreeFormat facility."""
155
138
dir.create_repository()
156
139
dir.create_branch()
157
140
format.initialize(dir)
158
t = transport.get_transport(url)
141
t = get_transport(url)
159
142
found_format = workingtree.WorkingTreeFormat.find_format(dir)
160
143
self.failUnless(isinstance(found_format, format.__class__))
161
144
check_format(workingtree.WorkingTreeFormat3(), "bar")
185
168
format.initialize(dir)
186
169
# register a format for it.
187
170
workingtree.WorkingTreeFormat.register_format(format)
188
self.assertTrue(format in workingtree.WorkingTreeFormat.get_formats())
189
171
# which branch.Open will refuse (not supported)
190
172
self.assertRaises(errors.UnsupportedFormatError, workingtree.WorkingTree.open, '.')
191
173
# but open_downlevel will work
192
174
self.assertEqual(format.open(dir), workingtree.WorkingTree.open_downlevel('.'))
193
175
# unregister the format
194
176
workingtree.WorkingTreeFormat.unregister_format(format)
195
self.assertFalse(format in workingtree.WorkingTreeFormat.get_formats())
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())
205
179
class TestWorkingTreeFormat3(TestCaseWithTransport):
375
349
self.build_tree_contents([('this/hello', 'Hello World')])
376
350
this.commit('Add World')
377
351
this.merge_from_branch(other.branch)
378
self.assertEqual([conflicts.TextConflict('hello', 'hello_id')],
352
self.assertEqual([conflicts.TextConflict('hello', None, 'hello_id')],
379
353
this.conflicts())
380
354
this.auto_resolve()
381
self.assertEqual([conflicts.TextConflict('hello', 'hello_id')],
355
self.assertEqual([conflicts.TextConflict('hello', None, 'hello_id')],
382
356
this.conflicts())
383
357
self.build_tree_contents([('this/hello', '<<<<<<<')])
384
358
this.auto_resolve()
385
self.assertEqual([conflicts.TextConflict('hello', 'hello_id')],
359
self.assertEqual([conflicts.TextConflict('hello', None, 'hello_id')],
386
360
this.conflicts())
387
361
self.build_tree_contents([('this/hello', '=======')])
388
362
this.auto_resolve()
389
self.assertEqual([conflicts.TextConflict('hello', 'hello_id')],
363
self.assertEqual([conflicts.TextConflict('hello', None, 'hello_id')],
390
364
this.conflicts())
391
365
self.build_tree_contents([('this/hello', '\n>>>>>>>')])
392
366
remaining, resolved = this.auto_resolve()
393
self.assertEqual([conflicts.TextConflict('hello', 'hello_id')],
367
self.assertEqual([conflicts.TextConflict('hello', None, 'hello_id')],
394
368
this.conflicts())
395
369
self.assertEqual([], resolved)
396
370
self.build_tree_contents([('this/hello', 'hELLO wORLD')])
397
371
remaining, resolved = this.auto_resolve()
398
372
self.assertEqual([], this.conflicts())
399
self.assertEqual([conflicts.TextConflict('hello', 'hello_id')],
373
self.assertEqual([conflicts.TextConflict('hello', None, 'hello_id')],
401
375
self.failIfExists('this/hello.BASE')
404
378
tree = self.make_branch_and_tree('tree')
405
379
self.build_tree(['tree/hello/'])
406
380
tree.add('hello', 'hello-id')
407
file_conflict = conflicts.TextConflict('file', 'hello-id')
381
file_conflict = conflicts.TextConflict('file', None, 'hello-id')
408
382
tree.set_conflicts(conflicts.ConflictList([file_conflict]))
409
383
tree.auto_resolve()