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