/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
4634.157.4 by Martin Pool
Add a basic (already passing) test for smart_add of a symlink
1
# Copyright (C) 2010 Canonical Ltd
2
#
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.
7
#
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.
12
#
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
16
17
"""Test symlink support.
18
"""
19
4634.159.2 by Martin Pool
Add reproduction for bug 192859
20
import os
21
4634.157.4 by Martin Pool
Add a basic (already passing) test for smart_add of a symlink
22
from bzrlib import (
4634.157.8 by Martin Pool
tree_files shouldn't dereference the first argument
23
    builtins,
4634.160.2 by Martin Pool
Add test (already passing) for symlink changing to dir
24
    osutils,
4634.157.4 by Martin Pool
Add a basic (already passing) test for smart_add of a symlink
25
    tests,
4634.157.6 by Martin Pool
Add test for opening a branch through a symlink
26
    workingtree,
4634.157.4 by Martin Pool
Add a basic (already passing) test for smart_add of a symlink
27
    )
28
from bzrlib.tests.per_workingtree import TestCaseWithWorkingTree
29
30
31
class TestSmartAddTree(TestCaseWithWorkingTree):
32
4634.159.1 by Martin Pool
Move tests into a class that describes their function
33
    # See eg <https://bugs.launchpad.net/bzr/+bug/192859>
34
4634.157.4 by Martin Pool
Add a basic (already passing) test for smart_add of a symlink
35
    _test_needs_features = [tests.SymlinkFeature]
36
4634.157.5 by Martin Pool
One more symlink add test
37
    def test_smart_add_symlink(self):
4634.157.4 by Martin Pool
Add a basic (already passing) test for smart_add of a symlink
38
        tree = self.make_branch_and_tree('tree')
39
        self.build_tree_contents([
40
            ('tree/link@', 'target'),
41
            ])
42
        tree.smart_add(['tree/link'])
43
        self.assertIsNot(None, tree.path2id('link'))
44
        self.assertIs(None, tree.path2id('target'))
45
        self.assertEqual('symlink',
46
            tree.kind(tree.path2id('link')))
4634.157.5 by Martin Pool
One more symlink add test
47
48
    def test_smart_add_symlink_pointing_outside(self):
49
        tree = self.make_branch_and_tree('tree')
50
        self.build_tree_contents([
51
            ('tree/link@', '../../../../target'),
52
            ])
53
        tree.smart_add(['tree/link'])
54
        self.assertIsNot(None, tree.path2id('link'))
55
        self.assertIs(None, tree.path2id('target'))
56
        self.assertEqual('symlink',
57
            tree.kind(tree.path2id('link')))
4634.157.6 by Martin Pool
Add test for opening a branch through a symlink
58
4634.159.8 by Martin Pool
Handle adding a file under a symlink whose real parent is not yet versioned
59
    def test_add_file_under_symlink(self):
60
        # similar to 
61
        # https://bugs.launchpad.net/bzr/+bug/192859/comments/3
62
        tree = self.make_branch_and_tree('tree')
63
        self.build_tree_contents([
64
            ('tree/link@', 'dir'),
65
            ('tree/dir/',),
66
            ('tree/dir/file', 'content'),
67
            ])
68
        self.assertEquals(
69
            tree.smart_add(['tree/link/file']),
70
            ([u'dir', u'dir/file'], {}))
71
        # should add the actual parent directory, not the apparent parent
72
        # (which is actually a symlink)
73
        self.assertTrue(tree.path2id('dir/file'))
74
        self.assertTrue(tree.path2id('dir'))
75
        self.assertIs(None, tree.path2id('link'))
76
        self.assertIs(None, tree.path2id('link/file'))
77
4634.159.1 by Martin Pool
Move tests into a class that describes their function
78
4634.159.2 by Martin Pool
Add reproduction for bug 192859
79
class TestKindChanges(TestCaseWithWorkingTree):
80
4634.159.7 by Martin Pool
Add symlink test dependency
81
    _test_needs_features = [tests.SymlinkFeature]
82
4634.160.1 by Martin Pool
The test now actually passes on all wt formats
83
    def test_symlink_changes_to_dir(self):
4634.159.4 by Martin Pool
comment
84
        # <https://bugs.launchpad.net/bzr/+bug/192859>:
85
        # we had some past problems with the workingtree remembering for too
86
        # long what kind of object was at a particular name; we really
87
        # shouldn't do that.  Operating on the dirstate through passing
88
        # inventory deltas rather than mutating the inventory largely avoids
89
        # that.
4634.159.2 by Martin Pool
Add reproduction for bug 192859
90
        tree = self.make_branch_and_tree('tree')
91
        self.build_tree_contents([
92
            ('tree/a@', 'target')])
93
        tree.smart_add(['tree/a'])
94
        tree.commit('add symlink')
95
        os.unlink('tree/a')
96
        self.build_tree_contents([
97
            ('tree/a/',),
98
            ('tree/a/f', 'content'),
99
            ])
4634.159.3 by Martin Pool
Better, now failing, test for symlink kind changes
100
        tree.smart_add(['tree/a/f'])
4634.159.2 by Martin Pool
Add reproduction for bug 192859
101
        tree.commit('change to dir')
4634.160.3 by Martin Pool
Check tree after commit of kind change
102
        tree.lock_read()
103
        self.addCleanup(tree.unlock)
104
        self.assertEquals([], list(tree.iter_changes(tree.basis_tree())))
4634.159.2 by Martin Pool
Add reproduction for bug 192859
105
4634.160.2 by Martin Pool
Add test (already passing) for symlink changing to dir
106
    def test_dir_changes_to_symlink(self):
107
        # <https://bugs.launchpad.net/bzr/+bug/192859>:
108
        # we had some past problems with the workingtree remembering for too
109
        # long what kind of object was at a particular name; we really
110
        # shouldn't do that.  Operating on the dirstate through passing
111
        # inventory deltas rather than mutating the inventory largely avoids
112
        # that.
113
        tree = self.make_branch_and_tree('tree')
114
        self.build_tree_contents([
115
            ('tree/a/',),
116
            ('tree/a/file', 'content'),
117
            ])
118
        tree.smart_add(['tree/a'])
119
        tree.commit('add dir')
120
        osutils.rmtree('tree/a')
121
        self.build_tree_contents([
122
            ('tree/a@', 'target'),
123
            ])
124
        tree.commit('change to symlink')
125
4634.159.2 by Martin Pool
Add reproduction for bug 192859
126
4634.159.1 by Martin Pool
Move tests into a class that describes their function
127
class TestOpenTree(TestCaseWithWorkingTree):
128
129
    _test_needs_features = [tests.SymlinkFeature]
130
4634.157.6 by Martin Pool
Add test for opening a branch through a symlink
131
    def test_open_containing_through_symlink(self):
4634.157.7 by Martin Pool
Further open_containing tests
132
        self.make_test_tree()
133
        self.check_open_containing('link/content', 'tree', 'content')
134
        self.check_open_containing('link/sublink', 'tree', 'sublink')
135
        # this next one is a bit debatable, but arguably it's better that
136
        # open_containing is only concerned with opening the tree 
137
        # and then you can deal with symlinks along the way if you want
138
        self.check_open_containing('link/sublink/subcontent', 'tree',
139
            'sublink/subcontent')
140
141
    def check_open_containing(self, to_open, expected_tree_name,
142
        expected_relpath):
143
        wt, relpath = workingtree.WorkingTree.open_containing(to_open)
144
        self.assertEquals(relpath, expected_relpath)
145
        self.assertEndsWith(wt.basedir, expected_tree_name)
146
4634.157.8 by Martin Pool
tree_files shouldn't dereference the first argument
147
    def test_tree_files(self):
148
        # not strictly a WorkingTree method, but it should be
149
        # probably the root cause for
150
        # <https://bugs.launchpad.net/bzr/+bug/128562>
151
        self.make_test_tree()
152
        self.check_tree_files(['tree/outerlink'],
153
            'tree', ['outerlink'])
154
        self.check_tree_files(['link/outerlink'],
155
            'tree', ['outerlink'])
156
        self.check_tree_files(['link/sublink/subcontent'],
157
            'tree', ['subdir/subcontent'])
158
159
    def check_tree_files(self, to_open, expected_tree, expect_paths):
160
        tree, relpaths = builtins.tree_files(to_open)
161
        self.assertEndsWith(tree.basedir, expected_tree)
162
        self.assertEquals(expect_paths, relpaths)
163
4634.157.7 by Martin Pool
Further open_containing tests
164
    def make_test_tree(self):
4634.157.6 by Martin Pool
Add test for opening a branch through a symlink
165
        tree = self.make_branch_and_tree('tree')
166
        self.build_tree_contents([
167
            ('link@', 'tree'),
4634.157.8 by Martin Pool
tree_files shouldn't dereference the first argument
168
            ('tree/outerlink@', '/not/there'),
4634.157.6 by Martin Pool
Add test for opening a branch through a symlink
169
            ('tree/content', 'hello'),
4634.157.7 by Martin Pool
Further open_containing tests
170
            ('tree/sublink@', 'subdir'),
171
            ('tree/subdir/',),
172
            ('tree/subdir/subcontent', 'subcontent stuff')
4634.157.6 by Martin Pool
Add test for opening a branch through a symlink
173
            ])