/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
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
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
19
from breezy import (
2922.2.6 by John Arbash Meinel
Add another direct test in unversion, because the other test
20
    errors,
21
    )
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
22
from breezy.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):
6809.4.25 by Jelmer Vernooij
Add paths argument to .unversion.
35
        """WT.unversion(['missing']) raises NoSuchId."""
1988.2.2 by Robert Collins
Add test script I forgotten - doh.
36
        tree = self.make_branch_and_tree('.')
6809.4.25 by Jelmer Vernooij
Add paths argument to .unversion.
37
        self.assertRaises(errors.NoSuchFile, tree.unversion, ['missing'])
1988.2.2 by Robert Collins
Add test script I forgotten - doh.
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'])
6842.2.1 by Jelmer Vernooij
Avoid setting file ids in unversion tests.
46
        tree.add(['del', 'del/sub', 'del/sub/b'])
47
        b_id = tree.path2id('del/sub/b')
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)
48
        tree.commit('setup')
49
        tree.rename_one('del/sub', 'sub')
6842.2.1 by Jelmer Vernooij
Avoid setting file ids in unversion tests.
50
        self.assertEqual('sub/b', tree.id2path(b_id))
6809.4.25 by Jelmer Vernooij
Add paths argument to .unversion.
51
        tree.unversion(['del', 'sub/b'])
6842.2.1 by Jelmer Vernooij
Avoid setting file ids in unversion tests.
52
        self.assertRaises(errors.NoSuchId, tree.id2path, b_id)
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)
53
1988.2.2 by Robert Collins
Add test script I forgotten - doh.
54
    def test_unversion_several_files(self):
55
        """After unversioning several files, they should not be versioned."""
56
        tree = self.make_branch_and_tree('.')
57
        self.build_tree(['a', 'b', 'c'])
6842.2.1 by Jelmer Vernooij
Avoid setting file ids in unversion tests.
58
        tree.add(['a', 'b', 'c'])
59
        a_id = tree.path2id('a')
60
        b_id = tree.path2id('b')
61
        c_id = tree.path2id('c')
1988.2.2 by Robert Collins
Add test script I forgotten - doh.
62
        # within a lock unversion should take effect
63
        tree.lock_write()
6809.4.25 by Jelmer Vernooij
Add paths argument to .unversion.
64
        tree.unversion(['a', 'b'])
6842.2.1 by Jelmer Vernooij
Avoid setting file ids in unversion tests.
65
        self.assertFalse(tree.has_id(a_id))
66
        self.assertFalse(tree.has_id(b_id))
67
        self.assertTrue(tree.has_id(c_id))
1988.2.2 by Robert Collins
Add test script I forgotten - doh.
68
        self.assertTrue(tree.has_filename('a'))
69
        self.assertTrue(tree.has_filename('b'))
70
        self.assertTrue(tree.has_filename('c'))
71
        tree.unlock()
1988.2.3 by Robert Collins
Merge in commit test case for deletion-heuristic.
72
        # the changes should have persisted to disk - reopen the workingtree
73
        # to be sure.
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
74
        tree = tree.controldir.open_workingtree()
6842.2.1 by Jelmer Vernooij
Avoid setting file ids in unversion tests.
75
        self.addCleanup(tree.lock_read().unlock)
76
        self.assertFalse(tree.has_id(a_id))
77
        self.assertFalse(tree.has_id(b_id))
78
        self.assertTrue(tree.has_id(c_id))
1988.2.2 by Robert Collins
Add test script I forgotten - doh.
79
        self.assertTrue(tree.has_filename('a'))
80
        self.assertTrue(tree.has_filename('b'))
81
        self.assertTrue(tree.has_filename('c'))
2255.7.41 by John Arbash Meinel
WorkingTree.unversion() should not raise if unversioning a child and a parent.
82
1988.2.2 by Robert Collins
Add test script I forgotten - doh.
83
    def test_unversion_subtree(self):
84
        """Unversioning the root of a subtree unversions the entire subtree."""
85
        tree = self.make_branch_and_tree('.')
86
        self.build_tree(['a/', 'a/b', 'c'])
6842.2.1 by Jelmer Vernooij
Avoid setting file ids in unversion tests.
87
        tree.add(['a', 'a/b', 'c'])
88
        a_id = tree.path2id('a')
89
        b_id = tree.path2id('a/b')
90
        c_id = tree.path2id('c')
1988.2.2 by Robert Collins
Add test script I forgotten - doh.
91
        # within a lock unversion should take effect
92
        tree.lock_write()
6809.4.25 by Jelmer Vernooij
Add paths argument to .unversion.
93
        tree.unversion(['a'])
6842.2.1 by Jelmer Vernooij
Avoid setting file ids in unversion tests.
94
        self.assertFalse(tree.has_id(a_id))
95
        self.assertFalse(tree.has_id(b_id))
96
        self.assertTrue(tree.has_id(c_id))
1988.2.2 by Robert Collins
Add test script I forgotten - doh.
97
        self.assertTrue(tree.has_filename('a'))
98
        self.assertTrue(tree.has_filename('a/b'))
99
        self.assertTrue(tree.has_filename('c'))
100
        tree.unlock()
2255.7.41 by John Arbash Meinel
WorkingTree.unversion() should not raise if unversioning a child and a parent.
101
102
    def test_unversion_subtree_and_children(self):
103
        """Passing a child id will raise NoSuchId.
104
105
        This is because the parent directory will have already been removed.
106
        """
107
        tree = self.make_branch_and_tree('.')
108
        self.build_tree(['a/', 'a/b', 'a/c', 'd'])
6842.2.1 by Jelmer Vernooij
Avoid setting file ids in unversion tests.
109
        tree.add(['a', 'a/b', 'a/c', 'd'])
110
        a_id = tree.path2id('a')
111
        b_id = tree.path2id('a/b')
112
        c_id = tree.path2id('a/c')
113
        d_id = tree.path2id('d')
2255.7.41 by John Arbash Meinel
WorkingTree.unversion() should not raise if unversioning a child and a parent.
114
        tree.lock_write()
115
        try:
6809.4.25 by Jelmer Vernooij
Add paths argument to .unversion.
116
            tree.unversion(['a/b', 'a'])
6842.2.1 by Jelmer Vernooij
Avoid setting file ids in unversion tests.
117
            self.assertFalse(tree.has_id(a_id))
118
            self.assertFalse(tree.has_id(b_id))
119
            self.assertFalse(tree.has_id(c_id))
120
            self.assertTrue(tree.has_id(d_id))
2255.7.41 by John Arbash Meinel
WorkingTree.unversion() should not raise if unversioning a child and a parent.
121
            # The files are still on disk
122
            self.assertTrue(tree.has_filename('a'))
123
            self.assertTrue(tree.has_filename('a/b'))
124
            self.assertTrue(tree.has_filename('a/c'))
125
            self.assertTrue(tree.has_filename('d'))
126
        finally:
127
            tree.unlock()
2922.2.5 by John Arbash Meinel
Add a direct test for WT.unversion()
128
129
    def test_unversion_renamed(self):
130
        tree = self.make_branch_and_tree('a')
131
        self.build_tree(['a/dir/', 'a/dir/f1', 'a/dir/f2', 'a/dir/f3',
132
                         'a/dir2/'])
6842.2.1 by Jelmer Vernooij
Avoid setting file ids in unversion tests.
133
        tree.add(['dir', 'dir/f1', 'dir/f2', 'dir/f3', 'dir2'])
134
        dir_id = tree.path2id('dir')
135
        dir2_id = tree.path2id('dir2')
136
        f1_id = tree.path2id('dir/f1')
137
        f2_id = tree.path2id('dir/f2')
138
        f3_id = tree.path2id('dir/f3')
2922.2.5 by John Arbash Meinel
Add a direct test for WT.unversion()
139
        rev_id1 = tree.commit('init')
140
        # Start off by renaming entries, and then unversion a bunch of entries
141
        # https://bugs.launchpad.net/bzr/+bug/114615
142
        tree.rename_one('dir/f1', 'dir/a')
143
        tree.rename_one('dir/f2', 'dir/z')
144
        tree.move(['dir/f3'], 'dir2')
145
146
        tree.lock_read()
147
        try:
2946.3.3 by John Arbash Meinel
Prefer tree.get_root_id() as more explicit than tree.path2id('')
148
            root_id = tree.get_root_id()
2922.2.5 by John Arbash Meinel
Add a direct test for WT.unversion()
149
            paths = [(path, ie.file_id)
150
                     for path, ie in tree.iter_entries_by_dir()]
151
        finally:
152
            tree.unlock()
153
        self.assertEqual([('', root_id),
6842.2.1 by Jelmer Vernooij
Avoid setting file ids in unversion tests.
154
                          ('dir', dir_id),
155
                          ('dir2', dir2_id),
156
                          ('dir/a', f1_id),
157
                          ('dir/z', f2_id),
158
                          ('dir2/f3', f3_id),
2922.2.5 by John Arbash Meinel
Add a direct test for WT.unversion()
159
                         ], paths)
160
6809.4.25 by Jelmer Vernooij
Add paths argument to .unversion.
161
        tree.unversion({'dir'})
2922.2.5 by John Arbash Meinel
Add a direct test for WT.unversion()
162
        paths = [(path, ie.file_id)
163
                 for path, ie in tree.iter_entries_by_dir()]
164
165
        self.assertEqual([('', root_id),
6842.2.1 by Jelmer Vernooij
Avoid setting file ids in unversion tests.
166
                          ('dir2', dir2_id),
167
                          ('dir2/f3', f3_id),
2922.2.5 by John Arbash Meinel
Add a direct test for WT.unversion()
168
                         ], paths)
169
2922.2.6 by John Arbash Meinel
Add another direct test in unversion, because the other test
170
    def test_unversion_after_conflicted_merge(self):
171
        # Test for bug #114615
172
        tree_a = self.make_branch_and_tree('A')
173
        self.build_tree(['A/a/', 'A/a/m', 'A/a/n'])
6842.2.1 by Jelmer Vernooij
Avoid setting file ids in unversion tests.
174
        tree_a.add(['a', 'a/m', 'a/n'])
175
        a_id = tree_a.path2id('a')
176
        m_id = tree_a.path2id('a/m')
177
        n_id = tree_a.path2id('a/n')
2922.2.6 by John Arbash Meinel
Add another direct test in unversion, because the other test
178
        tree_a.commit('init')
179
180
        tree_a.lock_read()
181
        try:
2946.3.3 by John Arbash Meinel
Prefer tree.get_root_id() as more explicit than tree.path2id('')
182
            root_id = tree_a.get_root_id()
2922.2.6 by John Arbash Meinel
Add another direct test in unversion, because the other test
183
        finally:
184
            tree_a.unlock()
185
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
186
        tree_b = tree_a.controldir.sprout('B').open_workingtree()
2922.2.6 by John Arbash Meinel
Add another direct test in unversion, because the other test
187
        self.build_tree(['B/xyz/'])
6842.2.1 by Jelmer Vernooij
Avoid setting file ids in unversion tests.
188
        tree_b.add(['xyz'])
189
        xyz_id = tree_b.path2id('xyz')
2922.2.6 by John Arbash Meinel
Add another direct test in unversion, because the other test
190
        tree_b.rename_one('a/m', 'xyz/m')
6809.4.25 by Jelmer Vernooij
Add paths argument to .unversion.
191
        tree_b.unversion(['a'])
2922.2.6 by John Arbash Meinel
Add another direct test in unversion, because the other test
192
        tree_b.commit('delete in B')
193
194
        paths = [(path, ie.file_id)
195
                 for path, ie in tree_b.iter_entries_by_dir()]
196
        self.assertEqual([('', root_id),
6842.2.1 by Jelmer Vernooij
Avoid setting file ids in unversion tests.
197
                          ('xyz', xyz_id),
198
                          ('xyz/m', m_id),
2922.2.6 by John Arbash Meinel
Add another direct test in unversion, because the other test
199
                         ], paths)
200
201
        self.build_tree_contents([('A/a/n', 'new contents for n\n')])
202
        tree_a.commit('change n in A')
203
204
        # Merging from A should introduce conflicts because 'n' was modified
205
        # and removed, so 'a' needs to be restored. We also have a conflict
206
        # because 'a' is still an existing directory
207
        num_conflicts = tree_b.merge_from_branch(tree_a.branch)
208
        self.assertEqual(4, num_conflicts)
209
        paths = [(path, ie.file_id)
210
                 for path, ie in tree_b.iter_entries_by_dir()]
211
        self.assertEqual([('', root_id),
6842.2.1 by Jelmer Vernooij
Avoid setting file ids in unversion tests.
212
                          ('a', a_id),
213
                          ('xyz', xyz_id),
214
                          ('a/n.OTHER', n_id),
215
                          ('xyz/m', m_id),
2922.2.6 by John Arbash Meinel
Add another direct test in unversion, because the other test
216
                         ], paths)
6809.4.25 by Jelmer Vernooij
Add paths argument to .unversion.
217
        tree_b.unversion(['a'])
2922.2.6 by John Arbash Meinel
Add another direct test in unversion, because the other test
218
        paths = [(path, ie.file_id)
219
                 for path, ie in tree_b.iter_entries_by_dir()]
220
        self.assertEqual([('', root_id),
6842.2.1 by Jelmer Vernooij
Avoid setting file ids in unversion tests.
221
                          ('xyz', xyz_id),
222
                          ('xyz/m', m_id),
2922.2.6 by John Arbash Meinel
Add another direct test in unversion, because the other test
223
                         ], paths)