1
# Copyright (C) 2008 Aaron Bentley
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
from bzrlib.transform import TreeTransform
20
from bzrlib.tests import TestCaseWithTransport, HardlinkFeature
22
from bzrlib.plugins.bzrtools import command
23
from bzrlib.plugins.bzrtools.link_tree import link_tree
26
class TestLinkTreeBase(object):
28
_test_needs_features = [HardlinkFeature]
31
TestCaseWithTransport.setUp(self)
32
self.parent_tree = self.make_branch_and_tree('parent')
33
self.parent_tree.lock_write()
34
self.addCleanup(self.parent_tree.unlock)
35
self.build_tree_contents([('parent/foo', 'bar')])
36
self.parent_tree.add('foo', 'foo-id')
37
self.parent_tree.commit('added foo')
38
child_bzrdir = self.parent_tree.bzrdir.sprout('child')
39
self.child_tree = child_bzrdir.open_workingtree()
42
parent_stat = os.lstat(self.parent_tree.abspath('foo'))
43
child_stat = os.lstat(self.child_tree.abspath('foo'))
44
return parent_stat.st_ino == child_stat.st_ino
47
class TestLinkTree(TestLinkTreeBase, TestCaseWithTransport):
49
def test_link_fails_if_modified(self):
50
"""If the file to be linked has modified text, don't link."""
51
self.build_tree_contents([('child/foo', 'baz')])
52
link_tree(self.child_tree, self.parent_tree)
53
self.assertFalse(self.hardlinked())
55
def test_link_fails_if_execute_bit_changed(self):
56
"""If the file to be linked has modified execute bit, don't link."""
57
tt = TreeTransform(self.child_tree)
59
trans_id = tt.trans_id_tree_file_id('foo-id')
60
tt.set_executability(True, trans_id)
64
link_tree(self.child_tree, self.parent_tree)
65
self.assertFalse(self.hardlinked())
67
def test_link_succeeds_if_unmodified(self):
68
"""If the file to be linked is unmodified, link"""
69
link_tree(self.child_tree, self.parent_tree)
70
self.assertTrue(self.hardlinked())
73
class TestLinkTreeCommand(TestLinkTreeBase, TestCaseWithTransport):
75
def test_link_tree(self):
76
"""Ensure the command works as intended"""
77
command._testing = True
80
self.parent_tree.unlock()
81
self.run_bzr('link-tree ../parent')
82
self.assertTrue(self.hardlinked())
83
# want teh addCleanup to work properly
84
self.parent_tree.lock_write()
86
command._testing = False