191
182
def test_find_format_string(self):
192
183
# is the right format object found for a working tree?
193
184
branch = self.make_branch('branch')
195
errors.NoWorkingTree,
196
bzrworkingtree.WorkingTreeFormatMetaDir.find_format_string,
185
self.assertRaises(errors.NoWorkingTree,
186
bzrworkingtree.WorkingTreeFormatMetaDir.find_format_string, branch.controldir)
198
187
transport = branch.controldir.get_workingtree_transport(None)
199
188
transport.mkdir('.')
200
transport.put_bytes("format", b"some format name")
189
transport.put_bytes("format", "some format name")
201
190
# The format does not have to be known by Bazaar,
202
191
# find_format_string just retrieves the name
205
bzrworkingtree.WorkingTreeFormatMetaDir.find_format_string(
192
self.assertEqual("some format name",
193
bzrworkingtree.WorkingTreeFormatMetaDir.find_format_string(branch.controldir))
208
195
def test_find_format(self):
209
196
# is the right format object found for a working tree?
210
197
# create a branch with a few known format objects.
211
198
self.build_tree(["foo/", "bar/"])
213
199
def check_format(format, url):
214
200
dir = format._matchingcontroldir.initialize(url)
215
201
dir.create_repository()
216
202
dir.create_branch()
217
203
format.initialize(dir)
218
found_format = bzrworkingtree.WorkingTreeFormatMetaDir.find_format(
204
t = transport.get_transport(url)
205
found_format = bzrworkingtree.WorkingTreeFormatMetaDir.find_format(dir)
220
206
self.assertIsInstance(found_format, format.__class__)
221
207
check_format(workingtree_3.WorkingTreeFormat3(), "bar")
432
410
this.merge_from_branch(other.branch)
433
411
self.assertEqual([conflicts.TextConflict('hello', b'hello_id')],
434
412
this.conflicts())
435
self._auto_resolve(this)
436
self.assertEqual([conflicts.TextConflict('hello', b'hello_id')],
438
self.build_tree_contents([('this/hello', '<<<<<<<')])
439
self._auto_resolve(this)
440
self.assertEqual([conflicts.TextConflict('hello', b'hello_id')],
442
self.build_tree_contents([('this/hello', '=======')])
443
self._auto_resolve(this)
444
self.assertEqual([conflicts.TextConflict('hello', b'hello_id')],
446
self.build_tree_contents([('this/hello', '\n>>>>>>>')])
447
remaining, resolved = self._auto_resolve(this)
414
self.assertEqual([conflicts.TextConflict('hello', b'hello_id')],
416
self.build_tree_contents([('this/hello', b'<<<<<<<')])
418
self.assertEqual([conflicts.TextConflict('hello', b'hello_id')],
420
self.build_tree_contents([('this/hello', b'=======')])
422
self.assertEqual([conflicts.TextConflict('hello', b'hello_id')],
424
self.build_tree_contents([('this/hello', b'\n>>>>>>>')])
425
remaining, resolved = this.auto_resolve()
448
426
self.assertEqual([conflicts.TextConflict('hello', b'hello_id')],
449
427
this.conflicts())
450
428
self.assertEqual([], resolved)
451
429
self.build_tree_contents([('this/hello', b'hELLO wORLD')])
452
remaining, resolved = self._auto_resolve(this)
430
remaining, resolved = this.auto_resolve()
453
431
self.assertEqual([], this.conflicts())
454
432
self.assertEqual([conflicts.TextConflict('hello', b'hello_id')],
456
434
self.assertPathDoesNotExist('this/hello.BASE')
458
def test_unsupported_symlink_auto_resolve(self):
459
self.requireFeature(SymlinkFeature)
460
base = self.make_branch_and_tree('base')
461
self.build_tree_contents([('base/hello', 'Hello')])
462
base.add('hello', b'hello_id')
463
base.commit('commit 0')
464
other = base.controldir.sprout('other').open_workingtree()
465
self.build_tree_contents([('other/hello', 'Hello')])
466
os.symlink('other/hello', 'other/foo')
467
other.add('foo', b'foo_id')
468
other.commit('commit symlink')
469
this = base.controldir.sprout('this').open_workingtree()
470
self.assertPathExists('this/hello')
471
self.build_tree_contents([('this/hello', 'Hello')])
472
this.commit('commit 2')
474
trace.push_log_file(log)
475
os_symlink = getattr(os, 'symlink', None)
478
this.merge_from_branch(other.branch)
481
os.symlink = os_symlink
482
self.assertContainsRe(
484
b'Unable to create symlink "foo" on this filesystem')
486
436
def test_auto_resolve_dir(self):
487
437
tree = self.make_branch_and_tree('tree')
488
438
self.build_tree(['tree/hello/'])
489
439
tree.add('hello', b'hello-id')
490
file_conflict = conflicts.TextConflict('hello', b'hello-id')
491
tree.set_conflicts(conflicts.ConflictList([file_conflict]))
492
remaining, resolved = self._auto_resolve(tree)
495
conflicts.ConflictList([conflicts.TextConflict(u'hello', 'hello-id')]))
496
self.assertEqual(resolved, [])
498
def test_auto_resolve_missing(self):
499
tree = self.make_branch_and_tree('tree')
500
file_conflict = conflicts.TextConflict('hello', b'hello-id')
501
tree.set_conflicts(conflicts.ConflictList([file_conflict]))
502
remaining, resolved = self._auto_resolve(tree)
503
self.assertEqual(remaining, [])
506
conflicts.ConflictList([conflicts.TextConflict(u'hello', 'hello-id')]))
440
file_conflict = conflicts.TextConflict('file', b'hello-id')
441
tree.set_conflicts(conflicts.ConflictList([file_conflict]))
445
class TestFindTrees(TestCaseWithTransport):
447
def test_find_trees(self):
448
self.make_branch_and_tree('foo')
449
self.make_branch_and_tree('foo/bar')
450
# Sticking a tree inside a control dir is heinous, so let's skip it
451
self.make_branch_and_tree('foo/.bzr/baz')
452
self.make_branch('qux')
453
trees = workingtree.WorkingTree.find_trees('.')
454
self.assertEqual(2, len(list(trees)))
509
457
class TestStoredUncommitted(TestCaseWithTransport):