34
from bzrlib.errors import (NotBranchError, NotVersionedError,
35
UnsupportedOperation, PathsNotVersionedError)
33
from bzrlib.errors import (
35
PathsNotVersionedError,
36
37
from bzrlib.inventory import Inventory
37
38
from bzrlib.osutils import pathjoin, getcwd, has_symlinks
38
39
from bzrlib.tests import TestSkipped, TestNotApplicable
39
40
from bzrlib.tests.per_workingtree import TestCaseWithWorkingTree
40
from bzrlib.trace import mutter
41
from bzrlib.workingtree import (TreeEntry, TreeDirectory, TreeFile, TreeLink,
42
WorkingTree, WorkingTree2)
41
from bzrlib.workingtree import (
43
48
from bzrlib.conflicts import ConflictList, TextConflict, ContentsConflict
46
51
class TestWorkingTree(TestCaseWithWorkingTree):
53
def test_branch_builder(self):
54
# Just a smoke test that we get a branch at the specified relpath
55
builder = self.make_branch_builder('foobar')
56
br = branch.Branch.open('foobar')
48
58
def test_list_files(self):
49
59
tree = self.make_branch_and_tree('.')
50
60
self.build_tree(['dir/', 'file'])
195
205
os.unlink('hello.txt')
196
206
tree.remove('hello.txt')
197
207
tree.revert(['hello.txt'])
198
self.failUnlessExists('hello.txt')
208
self.assertPathExists('hello.txt')
200
210
def test_versioned_files_not_unknown(self):
201
211
tree = self.make_branch_and_tree('.')
236
246
revid = b.revision_history()[0]
237
247
self.log('first revision_id is {%s}' % revid)
239
inv = b.repository.get_inventory(revid)
240
self.log('contents of inventory: %r' % inv.entries())
249
tree = b.repository.revision_tree(revid)
250
self.log('contents of tree: %r' % list(tree.iter_entries_by_dir()))
242
self.check_inventory_shape(inv,
243
['dir/', 'dir/sub/', 'dir/sub/file'])
252
self.check_tree_shape(tree, ['dir/', 'dir/sub/', 'dir/sub/file'])
244
253
wt.rename_one('dir', 'newdir')
247
self.check_inventory_shape(wt.inventory,
256
self.check_tree_shape(wt,
248
257
['newdir/', 'newdir/sub/', 'newdir/sub/file'])
250
259
wt.rename_one('newdir/sub', 'newdir/newsub')
252
self.check_inventory_shape(wt.inventory,
253
['newdir/', 'newdir/newsub/',
261
self.check_tree_shape(wt, ['newdir/', 'newdir/newsub/',
254
262
'newdir/newsub/file'])
319
327
# because some formats mutate the branch to set it on the tree
320
328
# we need to alter the branch to let this pass.
322
wt.branch.set_revision_history(['A', 'B'])
330
self.applyDeprecated(symbol_versioning.deprecated_in((2, 4, 0)),
331
wt.branch.set_revision_history, ['A', 'B'])
323
332
except errors.NoSuchRevision, e:
324
333
self.assertEqual('B', e.revision)
325
334
raise TestSkipped("Branch format does not permit arbitrary"
390
399
wt.set_parent_ids(['B'])
391
400
tree = wt.basis_tree()
393
self.failUnless(tree.has_filename('bar'))
402
self.assertTrue(tree.has_filename('bar'))
395
404
wt.set_parent_ids(['A'])
396
405
tree = wt.basis_tree()
398
self.failUnless(tree.has_filename('foo'))
407
self.assertTrue(tree.has_filename('foo'))
401
410
def test_clone_tree_revision(self):
456
465
wt.commit('A', rev_id='A')
457
466
# and update old_tree
458
467
self.assertEqual(0, old_tree.update())
459
self.failUnlessExists('checkout/file')
468
self.assertPathExists('checkout/file')
460
469
self.assertEqual(['A'], old_tree.get_parent_ids())
462
471
def test_update_sets_root_id(self):
477
486
wt.commit('A', rev_id='A')
478
487
# and update checkout
479
488
self.assertEqual(0, checkout.update())
480
self.failUnlessExists('checkout/file')
489
self.assertPathExists('checkout/file')
481
490
self.assertEqual(wt.get_root_id(), checkout.get_root_id())
482
491
self.assertNotEqual(None, wt.get_root_id())
560
569
self.assertFileEqual('a test\n', 'b1/a')
561
self.failUnlessExists('b1/b.~1~')
562
self.failIfExists('b1/c')
563
self.failIfExists('b1/a.~1~')
564
self.failUnlessExists('b1/d')
570
self.assertPathExists('b1/b.~1~')
571
self.assertPathDoesNotExist('b1/c')
572
self.assertPathDoesNotExist('b1/a.~1~')
573
self.assertPathExists('b1/d')
566
575
def test_update_updates_bound_branch_no_local_commits(self):
567
576
# doing an update in a tree updates the branch its bound to too.
730
739
def test_format_description(self):
731
740
tree = self.make_branch_and_tree('tree')
732
741
text = tree._format.get_format_description()
733
self.failUnless(len(text))
742
self.assertTrue(len(text))
735
744
def test_branch_attribute_is_not_settable(self):
736
745
# the branch attribute is an aspect of the working tree, not a
768
777
self.assertEqual([('', 'directory'), (u'\xe5', 'file')],
769
778
[(path, ie.kind) for path,ie in
770
tree.inventory.iter_entries()])
779
tree.iter_entries_by_dir()])
773
782
osutils.normalized_filename = orig
789
798
def test__write_inventory(self):
790
799
# The private interface _write_inventory is currently used by transform.
791
800
tree = self.make_branch_and_tree('.')
801
if not isinstance(tree, InventoryWorkingTree):
802
raise TestNotApplicable("_write_inventory does not exist on "
803
"non-inventory working trees")
792
804
# if we write write an inventory then do a walkdirs we should get back
793
805
# missing entries, and actual, and unknowns as appropriate.
794
806
self.build_tree(['present', 'unknown'])
916
928
case_sensitive = True
917
929
tree = self.make_branch_and_tree('test')
918
if tree.__class__ == WorkingTree2:
919
raise TestSkipped('WorkingTree2 is not supported')
920
930
self.assertEqual(case_sensitive, tree.case_sensitive)
931
# now we cheat, and make a file that matches the case-sensitive name
932
t = tree.bzrdir.get_workingtree_transport(None)
934
content = tree._format.get_format_string()
935
except NotImplementedError:
936
# All-in-one formats didn't have a separate format string.
937
content = tree.bzrdir._format.get_format_string()
938
t.put_bytes(tree._format.case_sensitive_filename, content)
939
tree = tree.bzrdir.open_workingtree()
940
self.assertFalse(tree.case_sensitive)
922
942
def test_all_file_ids_with_missing(self):
923
943
tree = self.make_branch_and_tree('tree')
1054
1074
self.assertEqual(0, wt.update(revision='1'))
1055
1075
self.assertEqual('1', wt.last_revision())
1056
1076
self.assertEqual(tip, wt.branch.last_revision())
1057
self.failUnlessExists('checkout/file1')
1058
self.failIfExists('checkout/file4')
1059
self.failIfExists('checkout/file5')
1077
self.assertPathExists('checkout/file1')
1078
self.assertPathDoesNotExist('checkout/file4')
1079
self.assertPathDoesNotExist('checkout/file5')
1062
1082
class TestIllegalPaths(TestCaseWithWorkingTree):
1104
1124
# above the control dir but we might need to relax that?
1105
1125
self.assertEqual(wt.control_url.find(wt.user_url), 0)
1106
1126
self.assertEqual(wt.control_url, wt.control_transport.base)
1129
class TestWorthSavingLimit(TestCaseWithWorkingTree):
1131
def make_wt_with_worth_saving_limit(self):
1132
wt = self.make_branch_and_tree('wt')
1133
if getattr(wt, '_worth_saving_limit', None) is None:
1134
raise tests.TestNotApplicable('no _worth_saving_limit for'
1137
self.addCleanup(wt.unlock)
1140
def test_not_set(self):
1141
# Default should be 10
1142
wt = self.make_wt_with_worth_saving_limit()
1143
self.assertEqual(10, wt._worth_saving_limit())
1144
ds = wt.current_dirstate()
1145
self.assertEqual(10, ds._worth_saving_limit)
1147
def test_set_in_branch(self):
1148
wt = self.make_wt_with_worth_saving_limit()
1149
config = wt.branch.get_config()
1150
config.set_user_option('bzr.workingtree.worth_saving_limit', '20')
1151
self.assertEqual(20, wt._worth_saving_limit())
1152
ds = wt.current_dirstate()
1153
self.assertEqual(10, ds._worth_saving_limit)
1155
def test_invalid(self):
1156
wt = self.make_wt_with_worth_saving_limit()
1157
config = wt.branch.get_config()
1158
config.set_user_option('bzr.workingtree.worth_saving_limit', 'a')
1159
# If the config entry is invalid, default to 10
1160
# TODO: This writes a warning to the user, trap it somehow
1161
self.assertEqual(10, wt._worth_saving_limit())