3727
3727
transform.apply()
3728
3728
self.assertEqual(old_root_id, self.wt.get_root_id())
3729
3729
self.assertEqual([(self.wt, transform)], calls)
3732
class TestLinkTree(tests.TestCaseWithTransport):
3734
_test_needs_features = [HardlinkFeature]
3737
tests.TestCaseWithTransport.setUp(self)
3738
self.parent_tree = self.make_branch_and_tree('parent')
3739
self.parent_tree.lock_write()
3740
self.addCleanup(self.parent_tree.unlock)
3741
self.build_tree_contents([('parent/foo', 'bar')])
3742
self.parent_tree.add('foo', 'foo-id')
3743
self.parent_tree.commit('added foo')
3744
child_controldir = self.parent_tree.controldir.sprout('child')
3745
self.child_tree = child_controldir.open_workingtree()
3747
def hardlinked(self):
3748
parent_stat = os.lstat(self.parent_tree.abspath('foo'))
3749
child_stat = os.lstat(self.child_tree.abspath('foo'))
3750
return parent_stat.st_ino == child_stat.st_ino
3752
def test_link_fails_if_modified(self):
3753
"""If the file to be linked has modified text, don't link."""
3754
self.build_tree_contents([('child/foo', 'baz')])
3755
transform.link_tree(self.child_tree, self.parent_tree)
3756
self.assertFalse(self.hardlinked())
3758
def test_link_fails_if_execute_bit_changed(self):
3759
"""If the file to be linked has modified execute bit, don't link."""
3760
tt = TreeTransform(self.child_tree)
3762
trans_id = tt.trans_id_tree_file_id('foo-id')
3763
tt.set_executability(True, trans_id)
3767
transform.link_tree(self.child_tree, self.parent_tree)
3768
self.assertFalse(self.hardlinked())
3770
def test_link_succeeds_if_unmodified(self):
3771
"""If the file to be linked is unmodified, link"""
3772
transform.link_tree(self.child_tree, self.parent_tree)
3773
self.assertTrue(self.hardlinked())