~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/per_workingtree/test_symlinks.py

  • Committer: Andrew Bennetts
  • Date: 2010-08-17 06:45:33 UTC
  • mfrom: (5050.17.9 2.2)
  • mto: This revision was merged to the branch mainline in revision 5379.
  • Revision ID: andrew.bennetts@canonical.com-20100817064533-kof2i2f3r6mr4ayb
Merge lp:bzr/2.2 into lp:bzr, including fixes for #192859, #224373, #300062, #585667, #614404, #617503.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
"""Test symlink support.
18
 
 
19
 
See eg <https://bugs.launchpad.net/bzr/+bug/192859>
20
18
"""
21
19
 
 
20
import os
 
21
 
22
22
from bzrlib import (
23
23
    builtins,
 
24
    osutils,
24
25
    tests,
25
26
    workingtree,
26
27
    )
29
30
 
30
31
class TestSmartAddTree(TestCaseWithWorkingTree):
31
32
 
 
33
    # See eg <https://bugs.launchpad.net/bzr/+bug/192859>
 
34
 
32
35
    _test_needs_features = [tests.SymlinkFeature]
33
36
 
34
37
    def test_smart_add_symlink(self):
53
56
        self.assertEqual('symlink',
54
57
            tree.kind(tree.path2id('link')))
55
58
 
 
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
 
 
78
 
 
79
class TestKindChanges(TestCaseWithWorkingTree):
 
80
 
 
81
    _test_needs_features = [tests.SymlinkFeature]
 
82
 
 
83
    def test_symlink_changes_to_dir(self):
 
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.
 
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
            ])
 
100
        tree.smart_add(['tree/a/f'])
 
101
        tree.commit('change to dir')
 
102
        tree.lock_read()
 
103
        self.addCleanup(tree.unlock)
 
104
        self.assertEquals([], list(tree.iter_changes(tree.basis_tree())))
 
105
        self.assertEquals(
 
106
            ['a', 'a/f'], sorted(info[0] for info in tree.list_files()))
 
107
 
 
108
    def test_dir_changes_to_symlink(self):
 
109
        # <https://bugs.launchpad.net/bzr/+bug/192859>:
 
110
        # we had some past problems with the workingtree remembering for too
 
111
        # long what kind of object was at a particular name; we really
 
112
        # shouldn't do that.  Operating on the dirstate through passing
 
113
        # inventory deltas rather than mutating the inventory largely avoids
 
114
        # that.
 
115
        tree = self.make_branch_and_tree('tree')
 
116
        self.build_tree_contents([
 
117
            ('tree/a/',),
 
118
            ('tree/a/file', 'content'),
 
119
            ])
 
120
        tree.smart_add(['tree/a'])
 
121
        tree.commit('add dir')
 
122
        osutils.rmtree('tree/a')
 
123
        self.build_tree_contents([
 
124
            ('tree/a@', 'target'),
 
125
            ])
 
126
        tree.commit('change to symlink')
 
127
 
 
128
 
 
129
class TestOpenTree(TestCaseWithWorkingTree):
 
130
 
 
131
    _test_needs_features = [tests.SymlinkFeature]
 
132
 
56
133
    def test_open_containing_through_symlink(self):
57
134
        self.make_test_tree()
58
135
        self.check_open_containing('link/content', 'tree', 'content')