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