1
# Copyright (C) 2010 Canonical Ltd
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
"""Test symlink support.
19
See eg <https://bugs.launchpad.net/bzr/+bug/192859>
27
from bzrlib.tests.per_workingtree import TestCaseWithWorkingTree
30
class TestSmartAddTree(TestCaseWithWorkingTree):
32
_test_needs_features = [tests.SymlinkFeature]
34
def test_smart_add_symlink(self):
35
tree = self.make_branch_and_tree('tree')
36
self.build_tree_contents([
37
('tree/link@', 'target'),
39
tree.smart_add(['tree/link'])
40
self.assertIsNot(None, tree.path2id('link'))
41
self.assertIs(None, tree.path2id('target'))
42
self.assertEqual('symlink',
43
tree.kind(tree.path2id('link')))
45
def test_smart_add_symlink_pointing_outside(self):
46
tree = self.make_branch_and_tree('tree')
47
self.build_tree_contents([
48
('tree/link@', '../../../../target'),
50
tree.smart_add(['tree/link'])
51
self.assertIsNot(None, tree.path2id('link'))
52
self.assertIs(None, tree.path2id('target'))
53
self.assertEqual('symlink',
54
tree.kind(tree.path2id('link')))
56
def test_open_containing_through_symlink(self):
58
self.check_open_containing('link/content', 'tree', 'content')
59
self.check_open_containing('link/sublink', 'tree', 'sublink')
60
# this next one is a bit debatable, but arguably it's better that
61
# open_containing is only concerned with opening the tree
62
# and then you can deal with symlinks along the way if you want
63
self.check_open_containing('link/sublink/subcontent', 'tree',
66
def check_open_containing(self, to_open, expected_tree_name,
68
wt, relpath = workingtree.WorkingTree.open_containing(to_open)
69
self.assertEquals(relpath, expected_relpath)
70
self.assertEndsWith(wt.basedir, expected_tree_name)
72
def test_tree_files(self):
73
# not strictly a WorkingTree method, but it should be
74
# probably the root cause for
75
# <https://bugs.launchpad.net/bzr/+bug/128562>
77
self.check_tree_files(['tree/outerlink'],
78
'tree', ['outerlink'])
79
self.check_tree_files(['link/outerlink'],
80
'tree', ['outerlink'])
81
self.check_tree_files(['link/sublink/subcontent'],
82
'tree', ['subdir/subcontent'])
84
def check_tree_files(self, to_open, expected_tree, expect_paths):
85
tree, relpaths = builtins.tree_files(to_open)
86
self.assertEndsWith(tree.basedir, expected_tree)
87
self.assertEquals(expect_paths, relpaths)
89
def make_test_tree(self):
90
tree = self.make_branch_and_tree('tree')
91
self.build_tree_contents([
93
('tree/outerlink@', '/not/there'),
94
('tree/content', 'hello'),
95
('tree/sublink@', 'subdir'),
97
('tree/subdir/subcontent', 'subcontent stuff')