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()
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()
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)
1890
1884
a = BzrDir.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')
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')
2799
2793
def test_iter_changes(self):
2800
2794
revision_tree, preview_tree = self.get_tree_and_preview_tree()
2801
root = revision_tree.inventory.root.file_id
2795
root = revision_tree.get_root_id()
2802
2796
self.assertEqual([('a-id', ('a', 'a'), True, (True, True),
2803
2797
(root, root), ('a', 'a'), ('file', 'file'),
2804
2798
(False, False))],
2808
2802
revision_tree, preview_tree = self.get_tree_and_preview_tree()
2809
2803
changes = preview_tree.iter_changes(revision_tree,
2810
2804
include_unchanged=True)
2811
root = revision_tree.inventory.root.file_id
2805
root = revision_tree.get_root_id()
2813
2807
self.assertEqual([ROOT_ENTRY, A_ENTRY], list(changes))
3640
3634
self.assertRaises(NotImplementedError, tt.new_orphan, 'foo', 'bar')
3642
3636
def _set_orphan_policy(self, wt, policy):
3643
wt.branch.get_config().set_user_option('bzr.transform.orphan_policy',
3637
wt.branch.get_config_stack().set('bzr.transform.orphan_policy',
3646
3640
def _prepare_orphan(self, wt):
3719
3713
self.assertEqual(('deleting parent', 'Not deleting', 'new-1'),
3720
3714
remaining_conflicts.pop())
3721
3715
self.assertLength(1, warnings)
3722
self.assertStartsWith(warnings[0], 'donttouchmypreciouuus')
3716
self.assertStartsWith(warnings[0], 'Value "donttouchmypreciouuus" ')
3719
class TestTransformHooks(tests.TestCaseWithTransport):
3722
super(TestTransformHooks, self).setUp()
3723
self.wt = self.make_branch_and_tree('.')
3726
def get_transform(self):
3727
transform = TreeTransform(self.wt)
3728
self.addCleanup(transform.finalize)
3729
return transform, transform.root
3731
def test_pre_commit_hooks(self):
3733
def record_pre_transform(tree, tt):
3734
calls.append((tree, tt))
3735
MutableTree.hooks.install_named_hook('pre_transform',
3736
record_pre_transform, "Pre transform")
3737
transform, root = self.get_transform()
3738
old_root_id = transform.tree_file_id(root)
3740
self.assertEqual(old_root_id, self.wt.get_root_id())
3741
self.assertEquals([(self.wt, transform)], calls)
3743
def test_post_commit_hooks(self):
3745
def record_post_transform(tree, tt):
3746
calls.append((tree, tt))
3747
MutableTree.hooks.install_named_hook('post_transform',
3748
record_post_transform, "Post transform")
3749
transform, root = self.get_transform()
3750
old_root_id = transform.tree_file_id(root)
3752
self.assertEqual(old_root_id, self.wt.get_root_id())
3753
self.assertEquals([(self.wt, transform)], calls)