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