/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
    )
6913.5.1 by Jelmer Vernooij
Use HasPathRelations.
22
from breezy.tests.matchers import HasPathRelations
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
23
from breezy.tests.per_workingtree import TestCaseWithWorkingTree
1988.2.2 by Robert Collins
Add test script I forgotten - doh.
24
25
26
class TestUnversion(TestCaseWithWorkingTree):
27
28
    def test_unversion_requires_write_lock(self):
29
        """WT.unversion([]) in a read lock raises ReadOnlyError."""
30
        tree = self.make_branch_and_tree('.')
31
        tree.lock_read()
32
        self.assertRaises(errors.ReadOnlyError, tree.unversion, [])
33
        tree.unlock()
34
35
    def test_unversion_missing_file(self):
6809.4.25 by Jelmer Vernooij
Add paths argument to .unversion.
36
        """WT.unversion(['missing']) raises NoSuchId."""
1988.2.2 by Robert Collins
Add test script I forgotten - doh.
37
        tree = self.make_branch_and_tree('.')
6809.4.25 by Jelmer Vernooij
Add paths argument to .unversion.
38
        self.assertRaises(errors.NoSuchFile, tree.unversion, ['missing'])
1988.2.2 by Robert Collins
Add test script I forgotten - doh.
39
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)
40
    def test_unversion_parent_and_child_renamed_bug_187207(self):
41
        # When unversioning dirstate trees show a bug in dealing with
42
        # unversioning children of reparented children of unversioned
43
        # paths when relocation entries are present and the relocation
44
        # points later into the dirstate.
5459.1.1 by Martin
Fix typo in test for bug 187207 that breaks Python 2.7
45
        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)
46
        self.build_tree(['del/', 'del/sub/', 'del/sub/b'])
6842.2.1 by Jelmer Vernooij
Avoid setting file ids in unversion tests.
47
        tree.add(['del', 'del/sub', 'del/sub/b'])
6913.5.1 by Jelmer Vernooij
Use HasPathRelations.
48
        revid = tree.commit('setup')
49
        revtree = tree.branch.repository.revision_tree(revid)
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)
50
        tree.rename_one('del/sub', 'sub')
6913.5.1 by Jelmer Vernooij
Use HasPathRelations.
51
        self.assertThat(
7143.15.2 by Jelmer Vernooij
Run autopep8.
52
            tree,
53
            HasPathRelations(revtree, [('', ''), ('del/', 'del/'), ('sub/', 'del/sub/'), ('sub/b', 'del/sub/b')]))
6913.5.1 by Jelmer Vernooij
Use HasPathRelations.
54
        if tree.has_versioned_directories():
55
            tree.unversion(['del', 'sub/b'])
56
        else:
57
            tree.unversion(['sub/b'])
58
        self.assertThat(
7143.15.2 by Jelmer Vernooij
Run autopep8.
59
            tree,
60
            HasPathRelations(revtree, [('', ''), ('sub/', 'del/sub/')]))
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)
61
1988.2.2 by Robert Collins
Add test script I forgotten - doh.
62
    def test_unversion_several_files(self):
63
        """After unversioning several files, they should not be versioned."""
64
        tree = self.make_branch_and_tree('.')
65
        self.build_tree(['a', 'b', 'c'])
6842.2.1 by Jelmer Vernooij
Avoid setting file ids in unversion tests.
66
        tree.add(['a', 'b', 'c'])
1988.2.2 by Robert Collins
Add test script I forgotten - doh.
67
        # within a lock unversion should take effect
68
        tree.lock_write()
6852.3.1 by Jelmer Vernooij
add Tree.is_versioned.
69
        self.assertTrue(tree.is_versioned('a'))
6809.4.25 by Jelmer Vernooij
Add paths argument to .unversion.
70
        tree.unversion(['a', 'b'])
6852.3.1 by Jelmer Vernooij
add Tree.is_versioned.
71
        self.assertFalse(tree.is_versioned('a'))
6883.7.12 by Jelmer Vernooij
avoid has_id.
72
        self.assertFalse(tree.is_versioned('a'))
73
        self.assertFalse(tree.is_versioned('b'))
74
        self.assertTrue(tree.is_versioned('c'))
1988.2.2 by Robert Collins
Add test script I forgotten - doh.
75
        self.assertTrue(tree.has_filename('a'))
76
        self.assertTrue(tree.has_filename('b'))
77
        self.assertTrue(tree.has_filename('c'))
78
        tree.unlock()
1988.2.3 by Robert Collins
Merge in commit test case for deletion-heuristic.
79
        # the changes should have persisted to disk - reopen the workingtree
80
        # to be sure.
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
81
        tree = tree.controldir.open_workingtree()
6842.2.1 by Jelmer Vernooij
Avoid setting file ids in unversion tests.
82
        self.addCleanup(tree.lock_read().unlock)
6883.7.12 by Jelmer Vernooij
avoid has_id.
83
        self.assertFalse(tree.is_versioned('a'))
84
        self.assertFalse(tree.is_versioned('b'))
85
        self.assertTrue(tree.is_versioned('c'))
1988.2.2 by Robert Collins
Add test script I forgotten - doh.
86
        self.assertTrue(tree.has_filename('a'))
87
        self.assertTrue(tree.has_filename('b'))
88
        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.
89
1988.2.2 by Robert Collins
Add test script I forgotten - doh.
90
    def test_unversion_subtree(self):
91
        """Unversioning the root of a subtree unversions the entire subtree."""
92
        tree = self.make_branch_and_tree('.')
93
        self.build_tree(['a/', 'a/b', 'c'])
6842.2.1 by Jelmer Vernooij
Avoid setting file ids in unversion tests.
94
        tree.add(['a', 'a/b', 'c'])
1988.2.2 by Robert Collins
Add test script I forgotten - doh.
95
        # within a lock unversion should take effect
6883.7.12 by Jelmer Vernooij
avoid has_id.
96
        with tree.lock_write():
97
            tree.unversion(['a'])
98
            self.assertFalse(tree.is_versioned('a'))
99
            self.assertFalse(tree.is_versioned('a/b'))
100
            self.assertTrue(tree.is_versioned('c'))
101
            self.assertTrue(tree.has_filename('a'))
102
            self.assertTrue(tree.has_filename('a/b'))
103
            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.
104
105
    def test_unversion_subtree_and_children(self):
106
        """Passing a child id will raise NoSuchId.
107
108
        This is because the parent directory will have already been removed.
109
        """
110
        tree = self.make_branch_and_tree('.')
111
        self.build_tree(['a/', 'a/b', 'a/c', 'd'])
6842.2.1 by Jelmer Vernooij
Avoid setting file ids in unversion tests.
112
        tree.add(['a', 'a/b', 'a/c', 'd'])
6852.3.1 by Jelmer Vernooij
add Tree.is_versioned.
113
        with tree.lock_write():
6809.4.25 by Jelmer Vernooij
Add paths argument to .unversion.
114
            tree.unversion(['a/b', 'a'])
6883.7.8 by Jelmer Vernooij
Avoid has_id.
115
            self.assertFalse(tree.is_versioned('a'))
116
            self.assertFalse(tree.is_versioned('a/b'))
117
            self.assertFalse(tree.is_versioned('a/c'))
118
            self.assertTrue(tree.is_versioned('d'))
2255.7.41 by John Arbash Meinel
WorkingTree.unversion() should not raise if unversioning a child and a parent.
119
            # The files are still on disk
120
            self.assertTrue(tree.has_filename('a'))
121
            self.assertTrue(tree.has_filename('a/b'))
122
            self.assertTrue(tree.has_filename('a/c'))
123
            self.assertTrue(tree.has_filename('d'))
2922.2.5 by John Arbash Meinel
Add a direct test for WT.unversion()
124
125
    def test_unversion_renamed(self):
126
        tree = self.make_branch_and_tree('a')
127
        self.build_tree(['a/dir/', 'a/dir/f1', 'a/dir/f2', 'a/dir/f3',
128
                         'a/dir2/'])
6842.2.1 by Jelmer Vernooij
Avoid setting file ids in unversion tests.
129
        tree.add(['dir', 'dir/f1', 'dir/f2', 'dir/f3', 'dir2'])
2922.2.5 by John Arbash Meinel
Add a direct test for WT.unversion()
130
        rev_id1 = tree.commit('init')
6913.5.1 by Jelmer Vernooij
Use HasPathRelations.
131
        revtree = tree.branch.repository.revision_tree(rev_id1)
2922.2.5 by John Arbash Meinel
Add a direct test for WT.unversion()
132
        # Start off by renaming entries, and then unversion a bunch of entries
133
        # https://bugs.launchpad.net/bzr/+bug/114615
134
        tree.rename_one('dir/f1', 'dir/a')
135
        tree.rename_one('dir/f2', 'dir/z')
136
        tree.move(['dir/f3'], 'dir2')
137
6913.5.1 by Jelmer Vernooij
Use HasPathRelations.
138
        self.assertThat(
7143.15.2 by Jelmer Vernooij
Run autopep8.
139
            tree, HasPathRelations(
140
                revtree,
141
                [('', ''), ('dir/', 'dir/'), ('dir2/', 'dir2/'),
142
                 ('dir/a', 'dir/f1'), ('dir/z', 'dir/f2'),
143
                 ('dir2/f3', 'dir/f3')]))
2922.2.5 by John Arbash Meinel
Add a direct test for WT.unversion()
144
6809.4.25 by Jelmer Vernooij
Add paths argument to .unversion.
145
        tree.unversion({'dir'})
6913.5.1 by Jelmer Vernooij
Use HasPathRelations.
146
        self.assertThat(
7143.15.2 by Jelmer Vernooij
Run autopep8.
147
            tree,
148
            HasPathRelations(
149
                revtree,
150
                [('', ''), ('dir2/', 'dir2/'), ('dir2/f3', 'dir/f3')]))
2922.2.5 by John Arbash Meinel
Add a direct test for WT.unversion()
151
2922.2.6 by John Arbash Meinel
Add another direct test in unversion, because the other test
152
    def test_unversion_after_conflicted_merge(self):
153
        # Test for bug #114615
154
        tree_a = self.make_branch_and_tree('A')
155
        self.build_tree(['A/a/', 'A/a/m', 'A/a/n'])
6842.2.1 by Jelmer Vernooij
Avoid setting file ids in unversion tests.
156
        tree_a.add(['a', 'a/m', 'a/n'])
2922.2.6 by John Arbash Meinel
Add another direct test in unversion, because the other test
157
        tree_a.commit('init')
158
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
159
        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
160
        self.build_tree(['B/xyz/'])
6842.2.1 by Jelmer Vernooij
Avoid setting file ids in unversion tests.
161
        tree_b.add(['xyz'])
2922.2.6 by John Arbash Meinel
Add another direct test in unversion, because the other test
162
        tree_b.rename_one('a/m', 'xyz/m')
6809.4.25 by Jelmer Vernooij
Add paths argument to .unversion.
163
        tree_b.unversion(['a'])
2922.2.6 by John Arbash Meinel
Add another direct test in unversion, because the other test
164
        tree_b.commit('delete in B')
165
6913.5.1 by Jelmer Vernooij
Use HasPathRelations.
166
        self.assertThat(
7143.15.2 by Jelmer Vernooij
Run autopep8.
167
            tree_b,
168
            HasPathRelations(
169
                tree_a,
170
                [('', ''), ('xyz/', None), ('xyz/m', 'a/m')]))
2922.2.6 by John Arbash Meinel
Add another direct test in unversion, because the other test
171
6855.4.1 by Jelmer Vernooij
Yet more bees.
172
        self.build_tree_contents([('A/a/n', b'new contents for n\n')])
2922.2.6 by John Arbash Meinel
Add another direct test in unversion, because the other test
173
        tree_a.commit('change n in A')
174
175
        # Merging from A should introduce conflicts because 'n' was modified
176
        # and removed, so 'a' needs to be restored. We also have a conflict
177
        # because 'a' is still an existing directory
178
        num_conflicts = tree_b.merge_from_branch(tree_a.branch)
7490.129.9 by Jelmer Vernooij
Fix tests.
179
        if tree_b.has_versioned_directories():
180
            self.assertEqual(4, num_conflicts)
181
        else:
7490.133.25 by Jelmer Vernooij
More fixes.
182
            self.assertEqual(1, num_conflicts)
6913.5.1 by Jelmer Vernooij
Use HasPathRelations.
183
184
        self.assertThat(
7143.15.2 by Jelmer Vernooij
Run autopep8.
185
            tree_b,
186
            HasPathRelations(
187
                tree_a,
188
                [('', ''), ('a/', 'a/'), ('xyz/', None),
189
                 ('a/n.OTHER', 'a/n'), ('xyz/m', 'a/m')]))
6913.5.1 by Jelmer Vernooij
Use HasPathRelations.
190
6809.4.25 by Jelmer Vernooij
Add paths argument to .unversion.
191
        tree_b.unversion(['a'])
6913.5.1 by Jelmer Vernooij
Use HasPathRelations.
192
        self.assertThat(
7143.15.2 by Jelmer Vernooij
Run autopep8.
193
            tree_b,
194
            HasPathRelations(
195
                tree_a,
196
                [('', ''), ('xyz/', None), ('xyz/m', 'a/m')]))