75
83
('zz_dir/subfile', 'file'),
86
def test_list_files_kind_change(self):
87
tree = self.make_branch_and_tree('tree')
88
self.build_tree(['tree/filename'])
89
tree.add('filename', 'file-id')
90
os.unlink('tree/filename')
91
self.build_tree(['tree/filename/'])
93
self.addCleanup(tree.unlock)
94
result = list(tree.list_files())
95
self.assertEqual(1, len(result))
96
self.assertEqual(('filename', 'V', 'directory', 'file-id'),
78
99
def test_open_containing(self):
79
100
branch = self.make_branch_and_tree('.').branch
80
101
local_base = urlutils.local_path_from_url(branch.base)
212
232
self.log('contents of inventory: %r' % inv.entries())
214
234
self.check_inventory_shape(inv,
215
['dir', 'dir/sub', 'dir/sub/file'])
235
['dir/', 'dir/sub/', 'dir/sub/file'])
217
236
wt.rename_one('dir', 'newdir')
219
self.check_inventory_shape(wt.read_working_inventory(),
220
['newdir', 'newdir/sub', 'newdir/sub/file'])
239
self.check_inventory_shape(wt.inventory,
240
['newdir/', 'newdir/sub/', 'newdir/sub/file'])
222
242
wt.rename_one('newdir/sub', 'newdir/newsub')
223
self.check_inventory_shape(wt.read_working_inventory(),
224
['newdir', 'newdir/newsub',
244
self.check_inventory_shape(wt.inventory,
245
['newdir/', 'newdir/newsub/',
225
246
'newdir/newsub/file'])
227
249
def test_add_in_unversioned(self):
228
250
"""Try to add a file in an unversioned directory.
285
310
# and now we can set it to 'A'
286
311
# because some formats mutate the branch to set it on the tree
287
312
# we need to alter the branch to let this pass.
288
wt.branch.set_revision_history(['A', 'B'])
314
wt.branch.set_revision_history(['A', 'B'])
315
except errors.NoSuchRevision, e:
316
self.assertEqual('B', e.revision)
317
raise TestSkipped("Branch format does not permit arbitrary"
289
319
wt.set_last_revision('A')
290
320
self.assertEqual(['A'], wt.get_parent_ids())
321
self.assertRaises(errors.ReservedId, wt.set_last_revision, 'A:')
292
323
def test_set_last_revision_different_to_branch(self):
293
324
# working tree formats from the meta-dir format and newer support
413
449
self.failUnlessExists('checkout/file')
414
450
self.assertEqual(['A'], old_tree.get_parent_ids())
452
def test_update_sets_root_id(self):
453
"""Ensure tree root is set properly by update.
455
Since empty trees don't have root_ids, but workingtrees do,
456
an update of a checkout of revision 0 to a new revision, should set
459
wt = self.make_branch_and_tree('tree')
460
main_branch = wt.branch
461
# create an out of date working tree by making a checkout in this
463
self.build_tree(['checkout/', 'tree/file'])
464
checkout = main_branch.create_checkout('checkout')
465
# now commit to 'tree'
467
wt.commit('A', rev_id='A')
468
# and update checkout
469
self.assertEqual(0, checkout.update())
470
self.failUnlessExists('checkout/file')
471
self.assertEqual(wt.get_root_id(), checkout.get_root_id())
472
self.assertNotEqual(None, wt.get_root_id())
416
474
def test_update_returns_conflict_count(self):
417
475
# working tree formats from the meta-dir format and newer support
418
476
# setting the last revision on a tree independently of that on the
517
575
self.assertEqual(master_tree.branch.revision_history(),
518
576
tree.branch.revision_history())
520
def test_merge_modified(self):
578
def test_merge_modified_detects_corruption(self):
579
# FIXME: This doesn't really test that it works; also this is not
580
# implementation-independent. mbp 20070226
521
581
tree = self.make_branch_and_tree('master')
522
582
tree._control_files.put('merge-hashes', StringIO('asdfasdf'))
523
583
self.assertRaises(errors.MergeModifiedFormatError, tree.merge_modified)
585
def test_merge_modified(self):
586
# merge_modified stores a map from file id to hash
587
tree = self.make_branch_and_tree('tree')
588
d = {'file-id': osutils.sha_string('hello')}
589
self.build_tree_contents([('tree/somefile', 'hello')])
592
tree.add(['somefile'], ['file-id'])
593
tree.set_merge_modified(d)
594
mm = tree.merge_modified()
595
self.assertEquals(mm, d)
598
mm = tree.merge_modified()
599
self.assertEquals(mm, d)
525
601
def test_conflicts(self):
526
602
from bzrlib.tests.test_conflicts import example_conflicts
527
603
tree = self.make_branch_and_tree('master')
659
738
tree.add, [u'a\u030a'])
661
740
osutils.normalized_filename = orig
742
def test__write_inventory(self):
743
# The private interface _write_inventory is currently used by transform.
744
tree = self.make_branch_and_tree('.')
745
# if we write write an inventory then do a walkdirs we should get back
746
# missing entries, and actual, and unknowns as appropriate.
747
self.build_tree(['present', 'unknown'])
748
inventory = Inventory(tree.path2id(''))
749
inventory.add_path('missing', 'file', 'missing-id')
750
inventory.add_path('present', 'file', 'present-id')
751
# there is no point in being able to write an inventory to an unlocked
752
# tree object - its a low level api not a convenience api.
754
tree._write_inventory(inventory)
758
present_stat = os.lstat('present')
759
unknown_stat = os.lstat('unknown')
761
(('', tree.inventory.root.file_id),
762
[('missing', 'missing', 'unknown', None, 'missing-id', 'file'),
763
('present', 'present', 'file', present_stat, 'present-id', 'file'),
764
('unknown', 'unknown', 'file', unknown_stat, None, None),
767
self.assertEqual(expected_results, list(tree.walkdirs()))
771
def test_path2id(self):
772
# smoke test for path2id
773
tree = self.make_branch_and_tree('.')
774
self.build_tree(['foo'])
775
tree.add(['foo'], ['foo-id'])
776
self.assertEqual('foo-id', tree.path2id('foo'))
777
# the next assertion is for backwards compatability with WorkingTree3,
778
# though its probably a bad idea, it makes things work. Perhaps
779
# it should raise a deprecation warning?
780
self.assertEqual('foo-id', tree.path2id('foo/'))
782
def test_filter_unversioned_files(self):
783
# smoke test for filter_unversioned_files
784
tree = self.make_branch_and_tree('.')
785
paths = ['here-and-versioned', 'here-and-not-versioned',
786
'not-here-and-versioned', 'not-here-and-not-versioned']
787
tree.add(['here-and-versioned', 'not-here-and-versioned'],
788
kinds=['file', 'file'])
789
self.build_tree(['here-and-versioned', 'here-and-not-versioned'])
791
self.addCleanup(tree.unlock)
793
set(['not-here-and-not-versioned', 'here-and-not-versioned']),
794
tree.filter_unversioned_files(paths))
796
def test_detect_real_kind(self):
797
# working trees report the real kind of the file on disk, not the kind
798
# they had when they were first added
799
# create one file of every interesting type
800
tree = self.make_branch_and_tree('.')
801
self.build_tree(['file', 'directory/'])
802
names = ['file', 'directory']
804
os.symlink('target', 'symlink')
805
names.append('symlink')
806
tree.add(names, [n + '-id' for n in names])
807
if tree.supports_tree_reference():
808
sub_tree = self.make_branch_and_tree('tree-reference')
809
sub_tree.set_root_id('tree-reference-id')
810
sub_tree.commit('message')
811
names.append('tree-reference')
812
tree.add_reference(sub_tree)
813
# now when we first look, we should see everything with the same kind
814
# with which they were initially added
816
actual_kind = tree.kind(n + '-id')
817
self.assertEqual(n, actual_kind)
818
# move them around so the names no longer correspond to the types
819
os.rename(names[0], 'tmp')
820
for i in range(1, len(names)):
821
os.rename(names[i], names[i-1])
822
os.rename('tmp', names[-1])
823
# now look and expect to see the correct types again
824
for i in range(len(names)):
825
actual_kind = tree.kind(names[i-1] + '-id')
826
expected_kind = names[i]
827
self.assertEqual(expected_kind, actual_kind)
829
def test_missing_file_sha1(self):
830
"""If a file is missing, its sha1 should be reported as None."""
831
tree = self.make_branch_and_tree('.')
833
self.addCleanup(tree.unlock)
834
self.build_tree(['file'])
835
tree.add('file', 'file-id')
836
tree.commit('file added')
838
self.assertIs(None, tree.get_file_sha1('file-id'))