1
# Copyright (C) 2006-2011 Canonical Ltd
1
# Copyright (C) 2006-2012, 2016 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
89
90
super(TestTreeTransform, self).setUp()
90
self.wt = self.make_branch_and_tree('.', format='dirstate-with-subtree')
91
self.wt = self.make_branch_and_tree('.', format='development-subtree')
93
94
def get_transform(self):
399
400
self.addCleanup(tree.unlock)
400
401
self.assertEqual('subtree-revision',
401
tree.inventory['subtree-id'].reference_revision)
402
tree.root_inventory['subtree-id'].reference_revision)
403
404
def test_conflicts(self):
404
405
transform, root = self.get_transform()
455
456
newtip = transform2.new_file('tip', oz_id, 'other', 'tip-id')
456
457
result = transform2.find_conflicts()
457
458
fp = FinalPaths(transform2)
458
self.assert_('oz/tip' in transform2._tree_path_ids)
459
self.assertTrue('oz/tip' in transform2._tree_path_ids)
459
460
self.assertEqual(fp.get_path(newtip), pathjoin('oz', 'tip'))
460
461
self.assertEqual(len(result), 2)
461
462
self.assertEqual((result[0][0], result[0][1]),
1476
1477
# The rename will fail because the target directory is not empty (but
1477
1478
# raises FileExists anyway).
1478
1479
err = self.assertRaises(errors.FileExists, tt_helper)
1479
self.assertContainsRe(str(err),
1480
"^File exists: .+/baz")
1480
self.assertEndsWith(err.path, "/baz")
1482
1482
def test_two_directories_clash(self):
1483
1483
def tt_helper():
1497
1497
err = self.assertRaises(errors.FileExists, tt_helper)
1498
self.assertContainsRe(str(err),
1499
"^File exists: .+/foo")
1498
self.assertEndsWith(err.path, "/foo")
1501
1500
def test_two_directories_clash_finalize(self):
1502
1501
def tt_helper():
1516
1515
err = self.assertRaises(errors.FileExists, tt_helper)
1517
self.assertContainsRe(str(err),
1518
"^File exists: .+/foo")
1516
self.assertEndsWith(err.path, "/foo")
1520
1518
def test_file_to_directory(self):
1521
1519
wt = self.make_branch_and_tree('.')
1557
1554
self.assertPathExists("foo")
1559
1556
self.addCleanup(wt.unlock)
1560
self.assertEqual(wt.inventory.get_file_kind(wt.path2id("foo")),
1557
self.assertEqual(wt.kind(wt.path2id("foo")), "symlink")
1563
1559
def test_dir_to_file(self):
1564
1560
wt = self.make_branch_and_tree('.')
1576
1572
self.assertPathExists("foo")
1578
1574
self.addCleanup(wt.unlock)
1579
self.assertEqual(wt.inventory.get_file_kind(wt.path2id("foo")),
1575
self.assertEqual(wt.kind(wt.path2id("foo")), "file")
1582
1577
def test_dir_to_hardlink(self):
1583
1578
self.requireFeature(HardlinkFeature)
1598
1593
self.assertPathExists("baz")
1600
1595
self.addCleanup(wt.unlock)
1601
self.assertEqual(wt.inventory.get_file_kind(wt.path2id("foo")),
1596
self.assertEqual(wt.kind(wt.path2id("foo")), "file")
1604
1598
def test_no_final_path(self):
1605
1599
transform, root = self.get_transform()
1651
1645
def __init__(self, dirname, root_id):
1652
1646
self.name = dirname
1653
1647
os.mkdir(dirname)
1654
self.wt = BzrDir.create_standalone_workingtree(dirname)
1648
self.wt = ControlDir.create_standalone_workingtree(dirname)
1655
1649
self.wt.set_root_id(root_id)
1656
1650
self.b = self.wt.branch
1657
1651
self.tt = TreeTransform(self.wt)
1767
1761
merge_modified = this.wt.merge_modified()
1768
1762
self.assertSubset(merge_modified, modified)
1769
1763
self.assertEqual(len(merge_modified), len(modified))
1770
file(this.wt.id2abspath('a'), 'wb').write('booga')
1764
with file(this.wt.id2abspath('a'), 'wb') as f: f.write('booga')
1771
1765
modified.pop(0)
1772
1766
merge_modified = this.wt.merge_modified()
1773
1767
self.assertSubset(merge_modified, modified)
1887
1881
def test_build_tree_with_symlinks(self):
1888
1882
self.requireFeature(SymlinkFeature)
1890
a = BzrDir.create_standalone_workingtree('a')
1884
a = ControlDir.create_standalone_workingtree('a')
1891
1885
os.mkdir('a/foo')
1892
file('a/foo/bar', 'wb').write('contents')
1886
with file('a/foo/bar', 'wb') as f: f.write('contents')
1893
1887
os.symlink('a/foo/bar', 'a/foo/baz')
1894
1888
a.add(['foo', 'foo/bar', 'foo/baz'])
1895
1889
a.commit('initial commit')
1896
b = BzrDir.create_standalone_workingtree('b')
1890
b = ControlDir.create_standalone_workingtree('b')
1897
1891
basis = a.basis_tree()
1898
1892
basis.lock_read()
1899
1893
self.addCleanup(basis.unlock)
1905
1899
def test_build_with_references(self):
1906
1900
tree = self.make_branch_and_tree('source',
1907
format='dirstate-with-subtree')
1901
format='development-subtree')
1908
1902
subtree = self.make_branch_and_tree('source/subtree',
1909
format='dirstate-with-subtree')
1903
format='development-subtree')
1910
1904
tree.add_reference(subtree)
1911
1905
tree.commit('a revision')
1912
1906
tree.branch.create_checkout('target')
2190
2184
def rot13(chunks, context=None):
2191
2185
return [''.join(chunks).encode('rot13')]
2192
2186
rot13filter = filters.ContentFilter(rot13, rot13)
2193
filters.register_filter_stack_map('rot13', {'yes': [rot13filter]}.get)
2187
filters.filter_stacks_registry.register(
2188
'rot13', {'yes': [rot13filter]}.get)
2194
2189
os.mkdir(self.test_home_dir + '/.bazaar')
2195
2190
rules_filename = self.test_home_dir + '/.bazaar/rules'
2196
2191
f = open(rules_filename, 'wb')
2416
2411
self.assertEqual('tree', revision.properties['branch-nick'])
2419
class TestBackupName(tests.TestCase):
2421
def test_deprecations(self):
2422
class MockTransform(object):
2424
def has_named_child(self, by_parent, parent_id, name):
2425
return name in by_parent.get(parent_id, [])
2427
class MockEntry(object):
2430
object.__init__(self)
2433
tt = MockTransform()
2434
name1 = self.applyDeprecated(
2435
symbol_versioning.deprecated_in((2, 3, 0)),
2436
transform.get_backup_name, MockEntry(), {'a':[]}, 'a', tt)
2437
self.assertEqual('name.~1~', name1)
2438
name2 = self.applyDeprecated(
2439
symbol_versioning.deprecated_in((2, 3, 0)),
2440
transform._get_backup_name, 'name', {'a':['name.~1~']}, 'a', tt)
2441
self.assertEqual('name.~2~', name2)
2444
2414
class TestFileMover(tests.TestCaseWithTransport):
2446
2416
def test_file_mover(self):
2799
2769
def test_iter_changes(self):
2800
2770
revision_tree, preview_tree = self.get_tree_and_preview_tree()
2801
root = revision_tree.inventory.root.file_id
2771
root = revision_tree.get_root_id()
2802
2772
self.assertEqual([('a-id', ('a', 'a'), True, (True, True),
2803
2773
(root, root), ('a', 'a'), ('file', 'file'),
2804
2774
(False, False))],
2808
2778
revision_tree, preview_tree = self.get_tree_and_preview_tree()
2809
2779
changes = preview_tree.iter_changes(revision_tree,
2810
2780
include_unchanged=True)
2811
root = revision_tree.inventory.root.file_id
2781
root = revision_tree.get_root_id()
2813
2783
self.assertEqual([ROOT_ENTRY, A_ENTRY], list(changes))
3640
3610
self.assertRaises(NotImplementedError, tt.new_orphan, 'foo', 'bar')
3642
3612
def _set_orphan_policy(self, wt, policy):
3643
wt.branch.get_config().set_user_option('bzr.transform.orphan_policy',
3613
wt.branch.get_config_stack().set('bzr.transform.orphan_policy',
3646
3616
def _prepare_orphan(self, wt):
3672
3642
warnings.append(args[0] % args[1:])
3673
3643
self.overrideAttr(trace, 'warning', warning)
3674
3644
remaining_conflicts = resolve_conflicts(tt)
3675
self.assertEquals(['dir/foo has been orphaned in bzr-orphans'],
3645
self.assertEqual(['dir/foo has been orphaned in bzr-orphans'],
3677
3647
# Yeah for resolved conflicts !
3678
3648
self.assertLength(0, remaining_conflicts)
3679
3649
# We have a new orphan
3680
self.assertEquals('foo.~1~', tt.final_name(orphan_tid))
3681
self.assertEquals('bzr-orphans',
3650
self.assertEqual('foo.~1~', tt.final_name(orphan_tid))
3651
self.assertEqual('bzr-orphans',
3682
3652
tt.final_name(tt.final_parent(orphan_tid)))
3684
3654
def test_never_orphan(self):
3719
3689
self.assertEqual(('deleting parent', 'Not deleting', 'new-1'),
3720
3690
remaining_conflicts.pop())
3721
3691
self.assertLength(1, warnings)
3722
self.assertStartsWith(warnings[0], 'donttouchmypreciouuus')
3692
self.assertStartsWith(warnings[0], 'Value "donttouchmypreciouuus" ')
3695
class TestTransformHooks(tests.TestCaseWithTransport):
3698
super(TestTransformHooks, self).setUp()
3699
self.wt = self.make_branch_and_tree('.')
3702
def get_transform(self):
3703
transform = TreeTransform(self.wt)
3704
self.addCleanup(transform.finalize)
3705
return transform, transform.root
3707
def test_pre_commit_hooks(self):
3709
def record_pre_transform(tree, tt):
3710
calls.append((tree, tt))
3711
MutableTree.hooks.install_named_hook('pre_transform',
3712
record_pre_transform, "Pre transform")
3713
transform, root = self.get_transform()
3714
old_root_id = transform.tree_file_id(root)
3716
self.assertEqual(old_root_id, self.wt.get_root_id())
3717
self.assertEqual([(self.wt, transform)], calls)
3719
def test_post_commit_hooks(self):
3721
def record_post_transform(tree, tt):
3722
calls.append((tree, tt))
3723
MutableTree.hooks.install_named_hook('post_transform',
3724
record_post_transform, "Post transform")
3725
transform, root = self.get_transform()
3726
old_root_id = transform.tree_file_id(root)
3728
self.assertEqual(old_root_id, self.wt.get_root_id())
3729
self.assertEqual([(self.wt, transform)], calls)