~bzr-pqm/bzr/bzr.dev

5452.4.3 by John Arbash Meinel
Merge bzr.dev to resolve bzr-2.3.txt (aka NEWS)
1
# Copyright (C) 2006, 2007, 2009, 2010 Canonical Ltd
1988.2.2 by Robert Collins
Add test script I forgotten - doh.
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
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1988.2.2 by Robert Collins
Add test script I forgotten - doh.
16
17
"""Tests of the WorkingTree.unversion API."""
18
2922.2.6 by John Arbash Meinel
Add another direct test in unversion, because the other test
19
from bzrlib import (
20
    errors,
21
    )
4523.1.4 by Martin Pool
Rename remaining *_implementations tests
22
from bzrlib.tests.per_workingtree import TestCaseWithWorkingTree
1988.2.2 by Robert Collins
Add test script I forgotten - doh.
23
24
25
class TestUnversion(TestCaseWithWorkingTree):
26
27
    def test_unversion_requires_write_lock(self):
28
        """WT.unversion([]) in a read lock raises ReadOnlyError."""
29
        tree = self.make_branch_and_tree('.')
30
        tree.lock_read()
31
        self.assertRaises(errors.ReadOnlyError, tree.unversion, [])
32
        tree.unlock()
33
34
    def test_unversion_missing_file(self):
35
        """WT.unversion(['missing-id']) raises NoSuchId."""
36
        tree = self.make_branch_and_tree('.')
37
        self.assertRaises(errors.NoSuchId, tree.unversion, ['missing-id'])
38
4536.2.1 by Robert Collins
Fix WorkingTree4.unversion when unversioning the parents of files that were renamed from a basis tree. (Robert Collins, bug 187207)
39
    def test_unversion_parent_and_child_renamed_bug_187207(self):
40
        # When unversioning dirstate trees show a bug in dealing with
41
        # unversioning children of reparented children of unversioned
42
        # paths when relocation entries are present and the relocation
43
        # points later into the dirstate.
5459.1.1 by Martin
Fix typo in test for bug 187207 that breaks Python 2.7
44
        tree = self.make_branch_and_tree('.')
4536.2.1 by Robert Collins
Fix WorkingTree4.unversion when unversioning the parents of files that were renamed from a basis tree. (Robert Collins, bug 187207)
45
        self.build_tree(['del/', 'del/sub/', 'del/sub/b'])
46
        tree.add(['del', 'del/sub', 'del/sub/b'], ['del', 'sub', 'b'])
47
        tree.commit('setup')
48
        tree.rename_one('del/sub', 'sub')
49
        self.assertEqual('sub/b', tree.id2path('b'))
50
        tree.unversion(['del', 'b'])
51
        self.assertRaises(errors.NoSuchId, tree.id2path, 'b')
52
1988.2.2 by Robert Collins
Add test script I forgotten - doh.
53
    def test_unversion_several_files(self):
54
        """After unversioning several files, they should not be versioned."""
55
        tree = self.make_branch_and_tree('.')
56
        self.build_tree(['a', 'b', 'c'])
57
        tree.add(['a', 'b', 'c'], ['a-id', 'b-id', 'c-id'])
58
        # within a lock unversion should take effect
59
        tree.lock_write()
60
        tree.unversion(['a-id', 'b-id'])
61
        self.assertFalse(tree.has_id('a-id'))
62
        self.assertFalse(tree.has_id('b-id'))
63
        self.assertTrue(tree.has_id('c-id'))
64
        self.assertTrue(tree.has_filename('a'))
65
        self.assertTrue(tree.has_filename('b'))
66
        self.assertTrue(tree.has_filename('c'))
67
        tree.unlock()
1988.2.3 by Robert Collins
Merge in commit test case for deletion-heuristic.
68
        # the changes should have persisted to disk - reopen the workingtree
69
        # to be sure.
70
        tree = tree.bzrdir.open_workingtree()
2255.2.46 by Robert Collins
Dirstate - unversion should set the tree state as dirty.
71
        tree.lock_read()
1988.2.2 by Robert Collins
Add test script I forgotten - doh.
72
        self.assertFalse(tree.has_id('a-id'))
73
        self.assertFalse(tree.has_id('b-id'))
74
        self.assertTrue(tree.has_id('c-id'))
75
        self.assertTrue(tree.has_filename('a'))
76
        self.assertTrue(tree.has_filename('b'))
77
        self.assertTrue(tree.has_filename('c'))
2255.2.46 by Robert Collins
Dirstate - unversion should set the tree state as dirty.
78
        tree.unlock()
2255.7.41 by John Arbash Meinel
WorkingTree.unversion() should not raise if unversioning a child and a parent.
79
1988.2.2 by Robert Collins
Add test script I forgotten - doh.
80
    def test_unversion_subtree(self):
81
        """Unversioning the root of a subtree unversions the entire subtree."""
82
        tree = self.make_branch_and_tree('.')
83
        self.build_tree(['a/', 'a/b', 'c'])
84
        tree.add(['a', 'a/b', 'c'], ['a-id', 'b-id', 'c-id'])
85
        # within a lock unversion should take effect
86
        tree.lock_write()
87
        tree.unversion(['a-id'])
88
        self.assertFalse(tree.has_id('a-id'))
89
        self.assertFalse(tree.has_id('b-id'))
90
        self.assertTrue(tree.has_id('c-id'))
91
        self.assertTrue(tree.has_filename('a'))
92
        self.assertTrue(tree.has_filename('a/b'))
93
        self.assertTrue(tree.has_filename('c'))
94
        tree.unlock()
2255.7.41 by John Arbash Meinel
WorkingTree.unversion() should not raise if unversioning a child and a parent.
95
96
    def test_unversion_subtree_and_children(self):
97
        """Passing a child id will raise NoSuchId.
98
99
        This is because the parent directory will have already been removed.
100
        """
101
        tree = self.make_branch_and_tree('.')
102
        self.build_tree(['a/', 'a/b', 'a/c', 'd'])
103
        tree.add(['a', 'a/b', 'a/c', 'd'], ['a-id', 'b-id', 'c-id', 'd-id'])
104
        tree.lock_write()
105
        try:
106
            tree.unversion(['b-id', 'a-id'])
107
            self.assertFalse(tree.has_id('a-id'))
108
            self.assertFalse(tree.has_id('b-id'))
109
            self.assertFalse(tree.has_id('c-id'))
110
            self.assertTrue(tree.has_id('d-id'))
111
            # The files are still on disk
112
            self.assertTrue(tree.has_filename('a'))
113
            self.assertTrue(tree.has_filename('a/b'))
114
            self.assertTrue(tree.has_filename('a/c'))
115
            self.assertTrue(tree.has_filename('d'))
116
        finally:
117
            tree.unlock()
2922.2.5 by John Arbash Meinel
Add a direct test for WT.unversion()
118
119
    def test_unversion_renamed(self):
120
        tree = self.make_branch_and_tree('a')
121
        self.build_tree(['a/dir/', 'a/dir/f1', 'a/dir/f2', 'a/dir/f3',
122
                         'a/dir2/'])
123
        tree.add(['dir', 'dir/f1', 'dir/f2', 'dir/f3', 'dir2'],
124
                 ['dir-id', 'f1-id', 'f2-id', 'f3-id', 'dir2-id'])
125
        rev_id1 = tree.commit('init')
126
        # Start off by renaming entries, and then unversion a bunch of entries
127
        # https://bugs.launchpad.net/bzr/+bug/114615
128
        tree.rename_one('dir/f1', 'dir/a')
129
        tree.rename_one('dir/f2', 'dir/z')
130
        tree.move(['dir/f3'], 'dir2')
131
132
        tree.lock_read()
133
        try:
2946.3.3 by John Arbash Meinel
Prefer tree.get_root_id() as more explicit than tree.path2id('')
134
            root_id = tree.get_root_id()
2922.2.5 by John Arbash Meinel
Add a direct test for WT.unversion()
135
            paths = [(path, ie.file_id)
136
                     for path, ie in tree.iter_entries_by_dir()]
137
        finally:
138
            tree.unlock()
139
        self.assertEqual([('', root_id),
140
                          ('dir', 'dir-id'),
141
                          ('dir2', 'dir2-id'),
142
                          ('dir/a', 'f1-id'),
143
                          ('dir/z', 'f2-id'),
144
                          ('dir2/f3', 'f3-id'),
145
                         ], paths)
146
147
        tree.unversion(set(['dir-id']))
148
        paths = [(path, ie.file_id)
149
                 for path, ie in tree.iter_entries_by_dir()]
150
151
        self.assertEqual([('', root_id),
152
                          ('dir2', 'dir2-id'),
153
                          ('dir2/f3', 'f3-id'),
154
                         ], paths)
155
2922.2.6 by John Arbash Meinel
Add another direct test in unversion, because the other test
156
    def test_unversion_after_conflicted_merge(self):
157
        # Test for bug #114615
158
        tree_a = self.make_branch_and_tree('A')
159
        self.build_tree(['A/a/', 'A/a/m', 'A/a/n'])
160
        tree_a.add(['a', 'a/m', 'a/n'], ['a-id', 'm-id', 'n-id'])
161
        tree_a.commit('init')
162
163
        tree_a.lock_read()
164
        try:
2946.3.3 by John Arbash Meinel
Prefer tree.get_root_id() as more explicit than tree.path2id('')
165
            root_id = tree_a.get_root_id()
2922.2.6 by John Arbash Meinel
Add another direct test in unversion, because the other test
166
        finally:
167
            tree_a.unlock()
168
169
        tree_b = tree_a.bzrdir.sprout('B').open_workingtree()
170
        self.build_tree(['B/xyz/'])
171
        tree_b.add(['xyz'], ['xyz-id'])
172
        tree_b.rename_one('a/m', 'xyz/m')
173
        tree_b.unversion(['a-id'])
174
        tree_b.commit('delete in B')
175
176
        paths = [(path, ie.file_id)
177
                 for path, ie in tree_b.iter_entries_by_dir()]
178
        self.assertEqual([('', root_id),
179
                          ('xyz', 'xyz-id'),
180
                          ('xyz/m', 'm-id'),
181
                         ], paths)
182
183
        self.build_tree_contents([('A/a/n', 'new contents for n\n')])
184
        tree_a.commit('change n in A')
185
186
        # Merging from A should introduce conflicts because 'n' was modified
187
        # and removed, so 'a' needs to be restored. We also have a conflict
188
        # because 'a' is still an existing directory
189
        num_conflicts = tree_b.merge_from_branch(tree_a.branch)
190
        self.assertEqual(4, num_conflicts)
191
        paths = [(path, ie.file_id)
192
                 for path, ie in tree_b.iter_entries_by_dir()]
193
        self.assertEqual([('', root_id),
194
                          ('a', 'a-id'),
195
                          ('xyz', 'xyz-id'),
196
                          ('a/n.OTHER', 'n-id'),
197
                          ('xyz/m', 'm-id'),
198
                         ], paths)
199
        tree_b.unversion(['a-id'])
200
        paths = [(path, ie.file_id)
201
                 for path, ie in tree_b.iter_entries_by_dir()]
202
        self.assertEqual([('', root_id),
203
                          ('xyz', 'xyz-id'),
204
                          ('xyz/m', 'm-id'),
205
                         ], paths)