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