bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
1773.4.1
by Martin Pool
Add pyflakes makefile target; fix many warnings |
1 |
# Copyright (C) 2005, 2006 Canonical Ltd
|
|
1534.4.46
by Robert Collins
Nearly complete .bzr/checkout splitout. |
2 |
# Authors: Robert Collins <robert.collins@canonical.com>
|
3 |
#
|
|
4 |
# This program is free software; you can redistribute it and/or modify
|
|
5 |
# it under the terms of the GNU General Public License as published by
|
|
6 |
# the Free Software Foundation; either version 2 of the License, or
|
|
7 |
# (at your option) any later version.
|
|
8 |
#
|
|
9 |
# This program is distributed in the hope that it will be useful,
|
|
10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 |
# GNU General Public License for more details.
|
|
13 |
#
|
|
14 |
# You should have received a copy of the GNU General Public License
|
|
15 |
# along with this program; if not, write to the Free Software
|
|
16 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
17 |
||
18 |
from cStringIO import StringIO |
|
19 |
import os |
|
|
1711.7.19
by John Arbash Meinel
file:// urls look slightly different on win32 |
20 |
import sys |
|
1534.4.46
by Robert Collins
Nearly complete .bzr/checkout splitout. |
21 |
|
22 |
import bzrlib |
|
|
1773.4.1
by Martin Pool
Add pyflakes makefile target; fix many warnings |
23 |
from bzrlib import branch, bzrdir, errors, urlutils, workingtree |
|
1534.10.8
by Aaron Bentley
Implemented conflict_lines in terms of old system on WorkingTree |
24 |
from bzrlib.errors import (NotBranchError, NotVersionedError, |
25 |
UnsupportedOperation) |
|
|
1685.1.45
by John Arbash Meinel
Moved url functions into bzrlib.urlutils |
26 |
from bzrlib.osutils import pathjoin, getcwd, has_symlinks |
|
1534.5.5
by Robert Collins
Move is_control_file into WorkingTree.is_control_filename and test. |
27 |
from bzrlib.tests import TestSkipped |
28 |
from bzrlib.tests.workingtree_implementations import TestCaseWithWorkingTree |
|
|
1534.4.46
by Robert Collins
Nearly complete .bzr/checkout splitout. |
29 |
from bzrlib.trace import mutter |
30 |
from bzrlib.workingtree import (TreeEntry, TreeDirectory, TreeFile, TreeLink, |
|
31 |
WorkingTree) |
|
|
1773.4.1
by Martin Pool
Add pyflakes makefile target; fix many warnings |
32 |
from bzrlib.conflicts import ConflictList |
|
1534.4.46
by Robert Collins
Nearly complete .bzr/checkout splitout. |
33 |
|
|
1711.7.19
by John Arbash Meinel
file:// urls look slightly different on win32 |
34 |
|
|
1534.4.46
by Robert Collins
Nearly complete .bzr/checkout splitout. |
35 |
class TestWorkingTree(TestCaseWithWorkingTree): |
36 |
||
|
1732.1.8
by John Arbash Meinel
Adding a test for list_files |
37 |
def test_list_files(self): |
|
1534.4.46
by Robert Collins
Nearly complete .bzr/checkout splitout. |
38 |
tree = self.make_branch_and_tree('.') |
|
1732.1.8
by John Arbash Meinel
Adding a test for list_files |
39 |
self.build_tree(['dir/', 'file']) |
|
1534.4.46
by Robert Collins
Nearly complete .bzr/checkout splitout. |
40 |
if has_symlinks(): |
41 |
os.symlink('target', 'symlink') |
|
42 |
files = list(tree.list_files()) |
|
43 |
self.assertEqual(files[0], ('dir', '?', 'directory', None, TreeDirectory())) |
|
44 |
self.assertEqual(files[1], ('file', '?', 'file', None, TreeFile())) |
|
45 |
if has_symlinks(): |
|
46 |
self.assertEqual(files[2], ('symlink', '?', 'symlink', None, TreeLink())) |
|
47 |
||
|
1732.1.8
by John Arbash Meinel
Adding a test for list_files |
48 |
def test_list_files_sorted(self): |
49 |
tree = self.make_branch_and_tree('.') |
|
|
1732.1.22
by John Arbash Meinel
Bug in list_files if the last entry in a directory is another directory |
50 |
self.build_tree(['dir/', 'file', 'dir/file', 'dir/b', 'dir/subdir/', 'a', 'dir/subfile', |
51 |
'zz_dir/', 'zz_dir/subfile']) |
|
|
1732.1.8
by John Arbash Meinel
Adding a test for list_files |
52 |
files = [(path, kind) for (path, versioned, kind, file_id, entry) in tree.list_files()] |
53 |
self.assertEqual([ |
|
54 |
('a', 'file'), |
|
55 |
('dir', 'directory'), |
|
56 |
('file', 'file'), |
|
|
1732.1.25
by John Arbash Meinel
Fix list_files test, we don't need to check if children are empty if we fall off the loop. |
57 |
('zz_dir', 'directory'), |
|
1732.1.8
by John Arbash Meinel
Adding a test for list_files |
58 |
], files) |
59 |
||
|
1732.1.25
by John Arbash Meinel
Fix list_files test, we don't need to check if children are empty if we fall off the loop. |
60 |
tree.add(['dir', 'zz_dir']) |
|
1732.1.8
by John Arbash Meinel
Adding a test for list_files |
61 |
files = [(path, kind) for (path, versioned, kind, file_id, entry) in tree.list_files()] |
62 |
self.assertEqual([ |
|
63 |
('a', 'file'), |
|
64 |
('dir', 'directory'), |
|
65 |
('dir/b', 'file'), |
|
66 |
('dir/file', 'file'), |
|
67 |
('dir/subdir', 'directory'), |
|
68 |
('dir/subfile', 'file'), |
|
69 |
('file', 'file'), |
|
|
1732.1.22
by John Arbash Meinel
Bug in list_files if the last entry in a directory is another directory |
70 |
('zz_dir', 'directory'), |
71 |
('zz_dir/subfile', 'file'), |
|
|
1732.1.8
by John Arbash Meinel
Adding a test for list_files |
72 |
], files) |
73 |
||
|
1534.4.46
by Robert Collins
Nearly complete .bzr/checkout splitout. |
74 |
def test_open_containing(self): |
|
1534.4.50
by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running. |
75 |
branch = self.make_branch_and_tree('.').branch |
|
1534.4.46
by Robert Collins
Nearly complete .bzr/checkout splitout. |
76 |
wt, relpath = WorkingTree.open_containing() |
77 |
self.assertEqual('', relpath) |
|
|
1685.1.45
by John Arbash Meinel
Moved url functions into bzrlib.urlutils |
78 |
self.assertEqual(wt.basedir + '/', urlutils.local_path_from_url(branch.base)) |
|
1534.4.46
by Robert Collins
Nearly complete .bzr/checkout splitout. |
79 |
wt, relpath = WorkingTree.open_containing(u'.') |
80 |
self.assertEqual('', relpath) |
|
|
1685.1.45
by John Arbash Meinel
Moved url functions into bzrlib.urlutils |
81 |
self.assertEqual(wt.basedir + '/', urlutils.local_path_from_url(branch.base)) |
|
1534.4.46
by Robert Collins
Nearly complete .bzr/checkout splitout. |
82 |
wt, relpath = WorkingTree.open_containing('./foo') |
83 |
self.assertEqual('foo', relpath) |
|
|
1685.1.45
by John Arbash Meinel
Moved url functions into bzrlib.urlutils |
84 |
self.assertEqual(wt.basedir + '/', urlutils.local_path_from_url(branch.base)) |
|
1711.7.19
by John Arbash Meinel
file:// urls look slightly different on win32 |
85 |
if sys.platform == 'win32': |
86 |
wt, relpath = WorkingTree.open_containing('file:///' + getcwd() + '/foo') |
|
87 |
else: |
|
88 |
wt, relpath = WorkingTree.open_containing('file://' + getcwd() + '/foo') |
|
|
1534.4.46
by Robert Collins
Nearly complete .bzr/checkout splitout. |
89 |
self.assertEqual('foo', relpath) |
|
1685.1.45
by John Arbash Meinel
Moved url functions into bzrlib.urlutils |
90 |
self.assertEqual(wt.basedir + '/', urlutils.local_path_from_url(branch.base)) |
|
1534.4.46
by Robert Collins
Nearly complete .bzr/checkout splitout. |
91 |
|
92 |
def test_basic_relpath(self): |
|
93 |
# for comprehensive relpath tests, see whitebox.py.
|
|
|
1534.4.50
by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running. |
94 |
tree = self.make_branch_and_tree('.') |
|
1534.4.46
by Robert Collins
Nearly complete .bzr/checkout splitout. |
95 |
self.assertEqual('child', |
96 |
tree.relpath(pathjoin(getcwd(), 'child'))) |
|
97 |
||
98 |
def test_lock_locks_branch(self): |
|
|
1534.4.50
by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running. |
99 |
tree = self.make_branch_and_tree('.') |
|
1534.4.46
by Robert Collins
Nearly complete .bzr/checkout splitout. |
100 |
tree.lock_read() |
101 |
self.assertEqual('r', tree.branch.peek_lock_mode()) |
|
102 |
tree.unlock() |
|
103 |
self.assertEqual(None, tree.branch.peek_lock_mode()) |
|
104 |
tree.lock_write() |
|
105 |
self.assertEqual('w', tree.branch.peek_lock_mode()) |
|
106 |
tree.unlock() |
|
107 |
self.assertEqual(None, tree.branch.peek_lock_mode()) |
|
108 |
||
109 |
def test_revert(self): |
|
110 |
"""Test selected-file revert""" |
|
|
1534.4.50
by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running. |
111 |
tree = self.make_branch_and_tree('.') |
|
1534.4.46
by Robert Collins
Nearly complete .bzr/checkout splitout. |
112 |
|
113 |
self.build_tree(['hello.txt']) |
|
114 |
file('hello.txt', 'w').write('initial hello') |
|
115 |
||
116 |
self.assertRaises(NotVersionedError, |
|
117 |
tree.revert, ['hello.txt']) |
|
118 |
tree.add(['hello.txt']) |
|
119 |
tree.commit('create initial hello.txt') |
|
120 |
||
121 |
self.check_file_contents('hello.txt', 'initial hello') |
|
122 |
file('hello.txt', 'w').write('new hello') |
|
123 |
self.check_file_contents('hello.txt', 'new hello') |
|
124 |
||
125 |
# revert file modified since last revision
|
|
126 |
tree.revert(['hello.txt']) |
|
127 |
self.check_file_contents('hello.txt', 'initial hello') |
|
|
1534.10.29
by Aaron Bentley
Fixed backup numbering to match GNU standard better |
128 |
self.check_file_contents('hello.txt.~1~', 'new hello') |
|
1534.4.46
by Robert Collins
Nearly complete .bzr/checkout splitout. |
129 |
|
130 |
# reverting again does not clobber the backup
|
|
131 |
tree.revert(['hello.txt']) |
|
132 |
self.check_file_contents('hello.txt', 'initial hello') |
|
|
1534.10.29
by Aaron Bentley
Fixed backup numbering to match GNU standard better |
133 |
self.check_file_contents('hello.txt.~1~', 'new hello') |
|
1534.10.28
by Aaron Bentley
Use numbered backup files |
134 |
|
135 |
# backup files are numbered
|
|
136 |
file('hello.txt', 'w').write('new hello2') |
|
137 |
tree.revert(['hello.txt']) |
|
138 |
self.check_file_contents('hello.txt', 'initial hello') |
|
|
1534.10.29
by Aaron Bentley
Fixed backup numbering to match GNU standard better |
139 |
self.check_file_contents('hello.txt.~1~', 'new hello') |
140 |
self.check_file_contents('hello.txt.~2~', 'new hello2') |
|
|
1534.4.46
by Robert Collins
Nearly complete .bzr/checkout splitout. |
141 |
|
|
1558.12.7
by Aaron Bentley
Fixed revert with missing files |
142 |
def test_revert_missing(self): |
143 |
# Revert a file that has been deleted since last commit
|
|
144 |
tree = self.make_branch_and_tree('.') |
|
145 |
file('hello.txt', 'w').write('initial hello') |
|
146 |
tree.add('hello.txt') |
|
147 |
tree.commit('added hello.txt') |
|
148 |
os.unlink('hello.txt') |
|
149 |
tree.remove('hello.txt') |
|
150 |
tree.revert(['hello.txt']) |
|
151 |
self.failUnlessExists('hello.txt') |
|
152 |
||
|
1740.6.1
by Martin Pool
Remove Scratch objects used by doctests |
153 |
def test_unknowns_by_default_patterns(self): |
154 |
"""Backup files are ignored by default""" |
|
155 |
tree = self.make_branch_and_tree('.') |
|
156 |
self.build_tree(['hello.txt', |
|
157 |
'hello.txt.~1~']) |
|
158 |
self.assertEquals(list(tree.unknowns()), |
|
159 |
['hello.txt']) |
|
160 |
||
161 |
def test_versioned_files_not_unknown(self): |
|
162 |
tree = self.make_branch_and_tree('.') |
|
163 |
self.build_tree(['hello.txt', |
|
164 |
'hello.txt.~1~']) |
|
165 |
tree.add('hello.txt') |
|
166 |
self.assertEquals(list(tree.unknowns()), |
|
167 |
[])
|
|
168 |
tree.remove('hello.txt') |
|
|
1534.4.46
by Robert Collins
Nearly complete .bzr/checkout splitout. |
169 |
self.assertEquals(list(tree.unknowns()), |
170 |
['hello.txt']) |
|
171 |
||
172 |
def test_hashcache(self): |
|
173 |
from bzrlib.tests.test_hashcache import pause |
|
|
1534.4.50
by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running. |
174 |
tree = self.make_branch_and_tree('.') |
|
1534.4.46
by Robert Collins
Nearly complete .bzr/checkout splitout. |
175 |
self.build_tree(['hello.txt', |
|
1534.10.29
by Aaron Bentley
Fixed backup numbering to match GNU standard better |
176 |
'hello.txt.~1~']) |
|
1534.4.46
by Robert Collins
Nearly complete .bzr/checkout splitout. |
177 |
tree.add('hello.txt') |
178 |
pause() |
|
179 |
sha = tree.get_file_sha1(tree.path2id('hello.txt')) |
|
180 |
self.assertEqual(1, tree._hashcache.miss_count) |
|
|
1534.5.3
by Robert Collins
Make format 4/5/6 branches share a single LockableFiles instance across wt/branch/repository. |
181 |
tree2 = WorkingTree.open('.') |
|
1534.4.46
by Robert Collins
Nearly complete .bzr/checkout splitout. |
182 |
sha2 = tree2.get_file_sha1(tree2.path2id('hello.txt')) |
183 |
self.assertEqual(0, tree2._hashcache.miss_count) |
|
184 |
self.assertEqual(1, tree2._hashcache.hit_count) |
|
185 |
||
186 |
def test_initialize(self): |
|
187 |
# initialize should create a working tree and branch in an existing dir
|
|
|
1534.4.50
by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running. |
188 |
t = self.make_branch_and_tree('.') |
|
1773.4.1
by Martin Pool
Add pyflakes makefile target; fix many warnings |
189 |
b = branch.Branch.open('.') |
|
1534.4.46
by Robert Collins
Nearly complete .bzr/checkout splitout. |
190 |
self.assertEqual(t.branch.base, b.base) |
|
1508.1.19
by Robert Collins
Give format3 working trees their own last-revision marker. |
191 |
t2 = WorkingTree.open('.') |
|
1534.4.46
by Robert Collins
Nearly complete .bzr/checkout splitout. |
192 |
self.assertEqual(t.basedir, t2.basedir) |
193 |
self.assertEqual(b.base, t2.branch.base) |
|
194 |
# TODO maybe we should check the branch format? not sure if its
|
|
195 |
# appropriate here.
|
|
196 |
||
197 |
def test_rename_dirs(self): |
|
198 |
"""Test renaming directories and the files within them.""" |
|
199 |
wt = self.make_branch_and_tree('.') |
|
200 |
b = wt.branch |
|
201 |
self.build_tree(['dir/', 'dir/sub/', 'dir/sub/file']) |
|
202 |
wt.add(['dir', 'dir/sub', 'dir/sub/file']) |
|
203 |
||
204 |
wt.commit('create initial state') |
|
205 |
||
206 |
revid = b.revision_history()[0] |
|
207 |
self.log('first revision_id is {%s}' % revid) |
|
208 |
||
209 |
inv = b.repository.get_revision_inventory(revid) |
|
210 |
self.log('contents of inventory: %r' % inv.entries()) |
|
211 |
||
212 |
self.check_inventory_shape(inv, |
|
213 |
['dir', 'dir/sub', 'dir/sub/file']) |
|
214 |
||
215 |
wt.rename_one('dir', 'newdir') |
|
216 |
||
217 |
self.check_inventory_shape(wt.read_working_inventory(), |
|
218 |
['newdir', 'newdir/sub', 'newdir/sub/file']) |
|
219 |
||
220 |
wt.rename_one('newdir/sub', 'newdir/newsub') |
|
221 |
self.check_inventory_shape(wt.read_working_inventory(), |
|
222 |
['newdir', 'newdir/newsub', |
|
223 |
'newdir/newsub/file']) |
|
224 |
||
225 |
def test_add_in_unversioned(self): |
|
226 |
"""Try to add a file in an unversioned directory. |
|
227 |
||
228 |
"bzr add" adds the parent as necessary, but simple working tree add
|
|
229 |
doesn't do that.
|
|
230 |
"""
|
|
231 |
from bzrlib.errors import NotVersionedError |
|
232 |
wt = self.make_branch_and_tree('.') |
|
233 |
self.build_tree(['foo/', |
|
234 |
'foo/hello']) |
|
235 |
self.assertRaises(NotVersionedError, |
|
236 |
wt.add, |
|
237 |
'foo/hello') |
|
238 |
||
239 |
def test_add_missing(self): |
|
240 |
# adding a msising file -> NoSuchFile
|
|
241 |
wt = self.make_branch_and_tree('.') |
|
242 |
self.assertRaises(errors.NoSuchFile, wt.add, 'fpp') |
|
243 |
||
244 |
def test_remove_verbose(self): |
|
245 |
#FIXME the remove api should not print or otherwise depend on the
|
|
246 |
# text UI - RBC 20060124
|
|
247 |
wt = self.make_branch_and_tree('.') |
|
248 |
self.build_tree(['hello']) |
|
249 |
wt.add(['hello']) |
|
250 |
wt.commit(message='add hello') |
|
251 |
stdout = StringIO() |
|
252 |
stderr = StringIO() |
|
253 |
self.assertEqual(None, self.apply_redirected(None, stdout, stderr, |
|
254 |
wt.remove, |
|
255 |
['hello'], |
|
256 |
verbose=True)) |
|
257 |
self.assertEqual('? hello\n', stdout.getvalue()) |
|
258 |
self.assertEqual('', stderr.getvalue()) |
|
259 |
||
260 |
def test_clone_trivial(self): |
|
261 |
wt = self.make_branch_and_tree('source') |
|
|
1534.4.50
by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running. |
262 |
cloned_dir = wt.bzrdir.clone('target') |
263 |
cloned = cloned_dir.open_workingtree() |
|
|
1534.4.46
by Robert Collins
Nearly complete .bzr/checkout splitout. |
264 |
self.assertEqual(cloned.last_revision(), wt.last_revision()) |
265 |
||
266 |
def test_last_revision(self): |
|
267 |
wt = self.make_branch_and_tree('source') |
|
268 |
self.assertEqual(None, wt.last_revision()) |
|
269 |
wt.commit('A', allow_pointless=True, rev_id='A') |
|
270 |
self.assertEqual('A', wt.last_revision()) |
|
271 |
||
272 |
def test_set_last_revision(self): |
|
273 |
wt = self.make_branch_and_tree('source') |
|
274 |
self.assertEqual(None, wt.last_revision()) |
|
|
1508.1.19
by Robert Collins
Give format3 working trees their own last-revision marker. |
275 |
# cannot set the last revision to one not in the branch history.
|
|
1534.4.46
by Robert Collins
Nearly complete .bzr/checkout splitout. |
276 |
self.assertRaises(errors.NoSuchRevision, wt.set_last_revision, 'A') |
277 |
wt.commit('A', allow_pointless=True, rev_id='A') |
|
278 |
self.assertEqual('A', wt.last_revision()) |
|
279 |
# None is aways in the branch
|
|
280 |
wt.set_last_revision(None) |
|
281 |
self.assertEqual(None, wt.last_revision()) |
|
282 |
# and now we can set it to 'A'
|
|
|
1508.1.19
by Robert Collins
Give format3 working trees their own last-revision marker. |
283 |
# because some formats mutate the branch to set it on the tree
|
|
1534.4.46
by Robert Collins
Nearly complete .bzr/checkout splitout. |
284 |
# we need to alter the branch to let this pass.
|
285 |
wt.branch.set_revision_history(['A', 'B']) |
|
286 |
wt.set_last_revision('A') |
|
287 |
self.assertEqual('A', wt.last_revision()) |
|
288 |
||
|
1508.1.19
by Robert Collins
Give format3 working trees their own last-revision marker. |
289 |
def test_set_last_revision_different_to_branch(self): |
290 |
# working tree formats from the meta-dir format and newer support
|
|
291 |
# setting the last revision on a tree independently of that on the
|
|
292 |
# branch. Its concievable that some future formats may want to
|
|
293 |
# couple them again (i.e. because its really a smart server and
|
|
294 |
# the working tree will always match the branch). So we test
|
|
295 |
# that formats where initialising a branch does not initialise a
|
|
296 |
# tree - and thus have separable entities - support skewing the
|
|
297 |
# two things.
|
|
298 |
branch = self.make_branch('tree') |
|
299 |
try: |
|
300 |
# if there is a working tree now, this is not supported.
|
|
301 |
branch.bzrdir.open_workingtree() |
|
302 |
return
|
|
303 |
except errors.NoWorkingTree: |
|
304 |
pass
|
|
305 |
wt = branch.bzrdir.create_workingtree() |
|
306 |
wt.commit('A', allow_pointless=True, rev_id='A') |
|
307 |
wt.set_last_revision(None) |
|
308 |
self.assertEqual(None, wt.last_revision()) |
|
309 |
self.assertEqual('A', wt.branch.last_revision()) |
|
310 |
# and now we can set it back to 'A'
|
|
311 |
wt.set_last_revision('A') |
|
312 |
self.assertEqual('A', wt.last_revision()) |
|
313 |
self.assertEqual('A', wt.branch.last_revision()) |
|
314 |
||
|
1534.4.46
by Robert Collins
Nearly complete .bzr/checkout splitout. |
315 |
def test_clone_and_commit_preserves_last_revision(self): |
316 |
wt = self.make_branch_and_tree('source') |
|
|
1534.4.50
by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running. |
317 |
cloned_dir = wt.bzrdir.clone('target') |
|
1534.4.46
by Robert Collins
Nearly complete .bzr/checkout splitout. |
318 |
wt.commit('A', allow_pointless=True, rev_id='A') |
|
1534.4.50
by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running. |
319 |
self.assertNotEqual(cloned_dir.open_workingtree().last_revision(), |
320 |
wt.last_revision()) |
|
321 |
||
322 |
def test_clone_preserves_content(self): |
|
323 |
wt = self.make_branch_and_tree('source') |
|
324 |
self.build_tree(['added', 'deleted', 'notadded'], transport=wt.bzrdir.transport.clone('..')) |
|
325 |
wt.add('deleted', 'deleted') |
|
326 |
wt.commit('add deleted') |
|
327 |
wt.remove('deleted') |
|
328 |
wt.add('added', 'added') |
|
329 |
cloned_dir = wt.bzrdir.clone('target') |
|
330 |
cloned = cloned_dir.open_workingtree() |
|
331 |
cloned_transport = cloned.bzrdir.transport.clone('..') |
|
332 |
self.assertFalse(cloned_transport.has('deleted')) |
|
333 |
self.assertTrue(cloned_transport.has('added')) |
|
334 |
self.assertFalse(cloned_transport.has('notadded')) |
|
335 |
self.assertEqual('added', cloned.path2id('added')) |
|
336 |
self.assertEqual(None, cloned.path2id('deleted')) |
|
337 |
self.assertEqual(None, cloned.path2id('notadded')) |
|
|
1534.4.46
by Robert Collins
Nearly complete .bzr/checkout splitout. |
338 |
|
339 |
def test_basis_tree_returns_last_revision(self): |
|
340 |
wt = self.make_branch_and_tree('.') |
|
341 |
self.build_tree(['foo']) |
|
342 |
wt.add('foo', 'foo-id') |
|
343 |
wt.commit('A', rev_id='A') |
|
344 |
wt.rename_one('foo', 'bar') |
|
345 |
wt.commit('B', rev_id='B') |
|
346 |
wt.set_last_revision('B') |
|
347 |
tree = wt.basis_tree() |
|
348 |
self.failUnless(tree.has_filename('bar')) |
|
349 |
wt.set_last_revision('A') |
|
350 |
tree = wt.basis_tree() |
|
351 |
self.failUnless(tree.has_filename('foo')) |
|
352 |
||
|
1534.4.50
by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running. |
353 |
def test_clone_tree_revision(self): |
354 |
# make a tree with a last-revision,
|
|
355 |
# and clone it with a different last-revision, this should switch
|
|
356 |
# do it.
|
|
357 |
#
|
|
358 |
# also test that the content is merged
|
|
359 |
# and conflicts recorded.
|
|
360 |
# This should merge between the trees - local edits should be preserved
|
|
361 |
# but other changes occured.
|
|
362 |
# we test this by having one file that does
|
|
363 |
# not change between two revisions, and another that does -
|
|
364 |
# if the changed one is not changed, fail,
|
|
365 |
# if the one that did not change has lost a local change, fail.
|
|
366 |
#
|
|
367 |
raise TestSkipped('revision limiting is not implemented yet.') |
|
|
1508.1.21
by Robert Collins
Implement -r limit for checkout command. |
368 |
|
369 |
def test_initialize_with_revision_id(self): |
|
370 |
# a bzrdir can construct a working tree for itself @ a specific revision.
|
|
371 |
source = self.make_branch_and_tree('source') |
|
372 |
source.commit('a', rev_id='a', allow_pointless=True) |
|
373 |
source.commit('b', rev_id='b', allow_pointless=True) |
|
374 |
self.build_tree(['new/']) |
|
375 |
made_control = self.bzrdir_format.initialize('new') |
|
376 |
source.branch.repository.clone(made_control) |
|
377 |
source.branch.clone(made_control) |
|
378 |
made_tree = self.workingtree_format.initialize(made_control, revision_id='a') |
|
379 |
self.assertEqual('a', made_tree.last_revision()) |
|
|
1508.1.23
by Robert Collins
Test that the working tree last revision is indeed set during commit. |
380 |
|
|
1508.1.24
by Robert Collins
Add update command for use with checkouts. |
381 |
def test_update_sets_last_revision(self): |
382 |
# working tree formats from the meta-dir format and newer support
|
|
383 |
# setting the last revision on a tree independently of that on the
|
|
384 |
# branch. Its concievable that some future formats may want to
|
|
385 |
# couple them again (i.e. because its really a smart server and
|
|
386 |
# the working tree will always match the branch). So we test
|
|
387 |
# that formats where initialising a branch does not initialise a
|
|
388 |
# tree - and thus have separable entities - support skewing the
|
|
389 |
# two things.
|
|
390 |
main_branch = self.make_branch('tree') |
|
391 |
try: |
|
392 |
# if there is a working tree now, this is not supported.
|
|
393 |
main_branch.bzrdir.open_workingtree() |
|
394 |
return
|
|
395 |
except errors.NoWorkingTree: |
|
396 |
pass
|
|
397 |
wt = main_branch.bzrdir.create_workingtree() |
|
398 |
# create an out of date working tree by making a checkout in this
|
|
399 |
# current format
|
|
400 |
self.build_tree(['checkout/', 'tree/file']) |
|
401 |
checkout = bzrdir.BzrDirMetaFormat1().initialize('checkout') |
|
|
1773.4.1
by Martin Pool
Add pyflakes makefile target; fix many warnings |
402 |
branch.BranchReferenceFormat().initialize(checkout, main_branch) |
|
1508.1.24
by Robert Collins
Add update command for use with checkouts. |
403 |
old_tree = self.workingtree_format.initialize(checkout) |
404 |
# now commit to 'tree'
|
|
405 |
wt.add('file') |
|
406 |
wt.commit('A', rev_id='A') |
|
407 |
# and update old_tree
|
|
408 |
self.assertEqual(0, old_tree.update()) |
|
409 |
self.failUnlessExists('checkout/file') |
|
410 |
self.assertEqual('A', old_tree.last_revision()) |
|
411 |
||
412 |
def test_update_returns_conflict_count(self): |
|
413 |
# working tree formats from the meta-dir format and newer support
|
|
414 |
# setting the last revision on a tree independently of that on the
|
|
415 |
# branch. Its concievable that some future formats may want to
|
|
416 |
# couple them again (i.e. because its really a smart server and
|
|
417 |
# the working tree will always match the branch). So we test
|
|
418 |
# that formats where initialising a branch does not initialise a
|
|
419 |
# tree - and thus have separable entities - support skewing the
|
|
420 |
# two things.
|
|
421 |
main_branch = self.make_branch('tree') |
|
422 |
try: |
|
423 |
# if there is a working tree now, this is not supported.
|
|
424 |
main_branch.bzrdir.open_workingtree() |
|
425 |
return
|
|
426 |
except errors.NoWorkingTree: |
|
427 |
pass
|
|
428 |
wt = main_branch.bzrdir.create_workingtree() |
|
429 |
# create an out of date working tree by making a checkout in this
|
|
430 |
# current format
|
|
431 |
self.build_tree(['checkout/', 'tree/file']) |
|
432 |
checkout = bzrdir.BzrDirMetaFormat1().initialize('checkout') |
|
|
1773.4.1
by Martin Pool
Add pyflakes makefile target; fix many warnings |
433 |
branch.BranchReferenceFormat().initialize(checkout, main_branch) |
|
1508.1.24
by Robert Collins
Add update command for use with checkouts. |
434 |
old_tree = self.workingtree_format.initialize(checkout) |
435 |
# now commit to 'tree'
|
|
436 |
wt.add('file') |
|
437 |
wt.commit('A', rev_id='A') |
|
438 |
# and add a file file to the checkout
|
|
439 |
self.build_tree(['checkout/file']) |
|
440 |
old_tree.add('file') |
|
441 |
# and update old_tree
|
|
442 |
self.assertEqual(1, old_tree.update()) |
|
443 |
self.assertEqual('A', old_tree.last_revision()) |
|
444 |
||
|
1534.7.199
by Aaron Bentley
Moved merge/revert tests into test_workingtree.py |
445 |
def test_merge_revert(self): |
446 |
from bzrlib.merge import merge_inner |
|
447 |
this = self.make_branch_and_tree('b1') |
|
448 |
open('b1/a', 'wb').write('a test\n') |
|
449 |
this.add('a') |
|
450 |
open('b1/b', 'wb').write('b test\n') |
|
451 |
this.add('b') |
|
452 |
this.commit(message='') |
|
453 |
base = this.bzrdir.clone('b2').open_workingtree() |
|
454 |
open('b2/a', 'wb').write('b test\n') |
|
455 |
other = this.bzrdir.clone('b3').open_workingtree() |
|
456 |
open('b3/a', 'wb').write('c test\n') |
|
457 |
open('b3/c', 'wb').write('c test\n') |
|
458 |
other.add('c') |
|
459 |
||
460 |
open('b1/b', 'wb').write('q test\n') |
|
461 |
open('b1/d', 'wb').write('d test\n') |
|
462 |
merge_inner(this.branch, other, base, this_tree=this) |
|
463 |
self.assertNotEqual(open('b1/a', 'rb').read(), 'a test\n') |
|
464 |
this.revert([]) |
|
465 |
self.assertEqual(open('b1/a', 'rb').read(), 'a test\n') |
|
|
1534.10.29
by Aaron Bentley
Fixed backup numbering to match GNU standard better |
466 |
self.assertIs(os.path.exists('b1/b.~1~'), True) |
|
1534.7.199
by Aaron Bentley
Moved merge/revert tests into test_workingtree.py |
467 |
self.assertIs(os.path.exists('b1/c'), False) |
|
1534.10.29
by Aaron Bentley
Fixed backup numbering to match GNU standard better |
468 |
self.assertIs(os.path.exists('b1/a.~1~'), False) |
|
1534.7.199
by Aaron Bentley
Moved merge/revert tests into test_workingtree.py |
469 |
self.assertIs(os.path.exists('b1/d'), True) |
|
1534.7.200
by Aaron Bentley
Merge from mainline |
470 |
|
|
1587.1.10
by Robert Collins
update updates working tree and branch together. |
471 |
def test_update_updates_bound_branch_no_local_commits(self): |
472 |
# doing an update in a tree updates the branch its bound to too.
|
|
473 |
master_tree = self.make_branch_and_tree('master') |
|
474 |
tree = self.make_branch_and_tree('tree') |
|
475 |
try: |
|
476 |
tree.branch.bind(master_tree.branch) |
|
477 |
except errors.UpgradeRequired: |
|
478 |
# legacy branches cannot bind
|
|
479 |
return
|
|
480 |
master_tree.commit('foo', rev_id='foo', allow_pointless=True) |
|
481 |
tree.update() |
|
482 |
self.assertEqual('foo', tree.last_revision()) |
|
483 |
self.assertEqual('foo', tree.branch.last_revision()) |
|
|
1587.1.11
by Robert Collins
Local commits appear to be working properly. |
484 |
|
485 |
def test_update_turns_local_commit_into_merge(self): |
|
486 |
# doing an update with a few local commits and no master commits
|
|
|
1587.1.13
by Robert Collins
Explain why update pivots more clearly in the relevant test. |
487 |
# makes pending-merges.
|
488 |
# this is done so that 'bzr update; bzr revert' will always produce
|
|
489 |
# an exact copy of the 'logical branch' - the referenced branch for
|
|
490 |
# a checkout, and the master for a bound branch.
|
|
491 |
# its possible that we should instead have 'bzr update' when there
|
|
492 |
# is nothing new on the master leave the current commits intact and
|
|
493 |
# alter 'revert' to revert to the master always. But for now, its
|
|
494 |
# good.
|
|
|
1587.1.11
by Robert Collins
Local commits appear to be working properly. |
495 |
master_tree = self.make_branch_and_tree('master') |
496 |
tree = self.make_branch_and_tree('tree') |
|
497 |
try: |
|
498 |
tree.branch.bind(master_tree.branch) |
|
499 |
except errors.UpgradeRequired: |
|
500 |
# legacy branches cannot bind
|
|
501 |
return
|
|
502 |
tree.commit('foo', rev_id='foo', allow_pointless=True, local=True) |
|
503 |
tree.commit('bar', rev_id='bar', allow_pointless=True, local=True) |
|
504 |
tree.update() |
|
505 |
self.assertEqual(None, tree.last_revision()) |
|
506 |
self.assertEqual([], tree.branch.revision_history()) |
|
507 |
self.assertEqual(['bar'], tree.pending_merges()) |
|
508 |
||
|
1558.3.3
by Aaron Bentley
Fix error handling for merge_modified |
509 |
def test_merge_modified(self): |
510 |
tree = self.make_branch_and_tree('master') |
|
511 |
tree._control_files.put('merge-hashes', StringIO('asdfasdf')) |
|
512 |
self.assertRaises(errors.MergeModifiedFormatError, tree.merge_modified) |
|
|
1534.10.8
by Aaron Bentley
Implemented conflict_lines in terms of old system on WorkingTree |
513 |
|
|
1534.10.22
by Aaron Bentley
Got ConflictList implemented |
514 |
def test_conflicts(self): |
|
1534.10.8
by Aaron Bentley
Implemented conflict_lines in terms of old system on WorkingTree |
515 |
from bzrlib.tests.test_conflicts import example_conflicts |
516 |
tree = self.make_branch_and_tree('master') |
|
517 |
try: |
|
|
1534.10.22
by Aaron Bentley
Got ConflictList implemented |
518 |
tree.set_conflicts(example_conflicts) |
|
1534.10.8
by Aaron Bentley
Implemented conflict_lines in terms of old system on WorkingTree |
519 |
except UnsupportedOperation: |
|
1534.10.22
by Aaron Bentley
Got ConflictList implemented |
520 |
raise TestSkipped('set_conflicts not supported') |
|
1534.10.8
by Aaron Bentley
Implemented conflict_lines in terms of old system on WorkingTree |
521 |
|
522 |
tree2 = WorkingTree.open('master') |
|
|
1534.10.22
by Aaron Bentley
Got ConflictList implemented |
523 |
self.assertEqual(tree2.conflicts(), example_conflicts) |
|
1534.10.8
by Aaron Bentley
Implemented conflict_lines in terms of old system on WorkingTree |
524 |
tree2._control_files.put('conflicts', StringIO('')) |
525 |
self.assertRaises(errors.ConflictFormatError, |
|
|
1534.10.22
by Aaron Bentley
Got ConflictList implemented |
526 |
tree2.conflicts) |
|
1534.10.8
by Aaron Bentley
Implemented conflict_lines in terms of old system on WorkingTree |
527 |
tree2._control_files.put('conflicts', StringIO('a')) |
528 |
self.assertRaises(errors.ConflictFormatError, |
|
|
1534.10.22
by Aaron Bentley
Got ConflictList implemented |
529 |
tree2.conflicts) |
|
1534.10.12
by Aaron Bentley
Merge produces new conflicts |
530 |
|
531 |
def make_merge_conflicts(self): |
|
532 |
from bzrlib.merge import merge_inner |
|
533 |
tree = self.make_branch_and_tree('mine') |
|
534 |
file('mine/bloo', 'wb').write('one') |
|
535 |
tree.add('bloo') |
|
|
1534.10.14
by Aaron Bentley
Made revert clear conflicts |
536 |
file('mine/blo', 'wb').write('on') |
537 |
tree.add('blo') |
|
|
1534.10.12
by Aaron Bentley
Merge produces new conflicts |
538 |
tree.commit("blah", allow_pointless=False) |
539 |
base = tree.basis_tree() |
|
|
1773.4.1
by Martin Pool
Add pyflakes makefile target; fix many warnings |
540 |
bzrdir.BzrDir.open("mine").sprout("other") |
|
1534.10.12
by Aaron Bentley
Merge produces new conflicts |
541 |
file('other/bloo', 'wb').write('two') |
542 |
othertree = WorkingTree.open('other') |
|
543 |
othertree.commit('blah', allow_pointless=False) |
|
544 |
file('mine/bloo', 'wb').write('three') |
|
545 |
tree.commit("blah", allow_pointless=False) |
|
546 |
merge_inner(tree.branch, othertree, base, this_tree=tree) |
|
547 |
return tree |
|
548 |
||
549 |
def test_merge_conflicts(self): |
|
550 |
tree = self.make_merge_conflicts() |
|
|
1534.10.22
by Aaron Bentley
Got ConflictList implemented |
551 |
self.assertEqual(len(tree.conflicts()), 1) |
|
1534.10.12
by Aaron Bentley
Merge produces new conflicts |
552 |
|
553 |
def test_clear_merge_conflicts(self): |
|
554 |
tree = self.make_merge_conflicts() |
|
|
1534.10.22
by Aaron Bentley
Got ConflictList implemented |
555 |
self.assertEqual(len(tree.conflicts()), 1) |
|
1534.10.12
by Aaron Bentley
Merge produces new conflicts |
556 |
try: |
|
1534.10.22
by Aaron Bentley
Got ConflictList implemented |
557 |
tree.set_conflicts(ConflictList()) |
|
1534.10.12
by Aaron Bentley
Merge produces new conflicts |
558 |
except UnsupportedOperation: |
559 |
raise TestSkipped |
|
|
1534.10.22
by Aaron Bentley
Got ConflictList implemented |
560 |
self.assertEqual(tree.conflicts(), ConflictList()) |
|
1534.10.14
by Aaron Bentley
Made revert clear conflicts |
561 |
|
562 |
def test_revert_clear_conflicts(self): |
|
563 |
tree = self.make_merge_conflicts() |
|
|
1534.10.22
by Aaron Bentley
Got ConflictList implemented |
564 |
self.assertEqual(len(tree.conflicts()), 1) |
|
1534.10.14
by Aaron Bentley
Made revert clear conflicts |
565 |
tree.revert(["blo"]) |
|
1534.10.22
by Aaron Bentley
Got ConflictList implemented |
566 |
self.assertEqual(len(tree.conflicts()), 1) |
|
1534.10.14
by Aaron Bentley
Made revert clear conflicts |
567 |
tree.revert(["bloo"]) |
|
1534.10.22
by Aaron Bentley
Got ConflictList implemented |
568 |
self.assertEqual(len(tree.conflicts()), 0) |
|
1534.10.14
by Aaron Bentley
Made revert clear conflicts |
569 |
|
570 |
def test_revert_clear_conflicts2(self): |
|
571 |
tree = self.make_merge_conflicts() |
|
|
1534.10.22
by Aaron Bentley
Got ConflictList implemented |
572 |
self.assertEqual(len(tree.conflicts()), 1) |
|
1534.10.14
by Aaron Bentley
Made revert clear conflicts |
573 |
tree.revert([]) |
|
1534.10.22
by Aaron Bentley
Got ConflictList implemented |
574 |
self.assertEqual(len(tree.conflicts()), 0) |
|
1624.3.22
by Olaf Conradi
Merge bzr.dev |
575 |
|
|
1624.3.19
by Olaf Conradi
New call get_format_description to give a user-friendly description of a |
576 |
def test_format_description(self): |
577 |
tree = self.make_branch_and_tree('tree') |
|
578 |
text = tree._format.get_format_description() |
|
579 |
self.failUnless(len(text)) |
|
|
1681.1.1
by Robert Collins
Make WorkingTree.branch a read only property. (Robert Collins) |
580 |
|
581 |
def test_branch_attribute_is_not_settable(self): |
|
582 |
# the branch attribute is an aspect of the working tree, not a
|
|
583 |
# configurable attribute
|
|
584 |
tree = self.make_branch_and_tree('tree') |
|
585 |
def set_branch(): |
|
586 |
tree.branch = tree.branch |
|
587 |
self.assertRaises(AttributeError, set_branch) |
|
588 |
||
|
1713.3.1
by Robert Collins
Smoke tests for tree.list_files and bzr ignored when a versioned file matches an ignore rule. |
589 |
def test_list_files_versioned_before_ignored(self): |
590 |
"""A versioned file matching an ignore rule should not be ignored.""" |
|
591 |
tree = self.make_branch_and_tree('.') |
|
592 |
self.build_tree(['foo.pyc']) |
|
593 |
# ensure that foo.pyc is ignored
|
|
594 |
self.build_tree_contents([('.bzrignore', 'foo.pyc')]) |
|
595 |
tree.add('foo.pyc', 'anid') |
|
596 |
files = sorted(list(tree.list_files())) |
|
597 |
self.assertEqual((u'.bzrignore', '?', 'file', None), files[0][:-1]) |
|
598 |
self.assertEqual((u'foo.pyc', 'V', 'file', 'anid'), files[1][:-1]) |
|
599 |
self.assertEqual(2, len(files)) |