577
578
self.assertEqual([], changes)
578
579
self.assertEqual(['', 'versioned', 'versioned2'], returned)
581
def get_tree_with_cachable_file_foo(self):
582
tree = self.make_branch_and_tree('.')
583
self.build_tree(['foo'])
584
tree.add(['foo'], ['foo-id'])
585
# a 4 second old timestamp is always hashable - sucks to delay
586
# the test suite, but not testing this is worse.
590
def test_commit_updates_hash_cache(self):
591
tree = self.get_tree_with_cachable_file_foo()
592
revid = tree.commit('a commit')
593
# tree's dirstate should now have a valid stat entry for foo.
595
entry = tree._get_entry(path='foo')
596
expected_sha1 = osutils.sha_file_by_name('foo')
597
self.assertEqual(expected_sha1, entry[1][0][1])
599
def test_observed_sha1_cachable(self):
600
tree = self.get_tree_with_cachable_file_foo()
601
expected_sha1 = osutils.sha_file_by_name('foo')
602
statvalue = os.lstat("foo")
605
tree._observed_sha1("foo-id", "foo", (expected_sha1, statvalue))
606
self.assertEqual(expected_sha1,
607
tree._get_entry(path="foo")[1][0][1])
610
tree = tree.bzrdir.open_workingtree()
612
self.addCleanup(tree.unlock)
613
self.assertEqual(expected_sha1, tree._get_entry(path="foo")[1][0][1])
615
def test_observed_sha1_new_file(self):
616
tree = self.make_branch_and_tree('.')
617
self.build_tree(['foo'])
618
tree.add(['foo'], ['foo-id'])
621
current_sha1 = tree._get_entry(path="foo")[1][0][1]
626
tree._observed_sha1("foo-id", "foo",
627
(osutils.sha_file_by_name('foo'), os.lstat("foo")))
628
# Must not have changed
629
self.assertEqual(current_sha1,
630
tree._get_entry(path="foo")[1][0][1])
634
def test_get_file_with_stat_id_only(self):
635
# Explicit test to ensure we get a lstat value from WT4 trees.
636
tree = self.make_branch_and_tree('.')
637
self.build_tree(['foo'])
638
tree.add(['foo'], ['foo-id'])
640
self.addCleanup(tree.unlock)
641
file_obj, statvalue = tree.get_file_with_stat('foo-id')
642
expected = os.lstat('foo')
643
self.assertEqualStat(expected, statvalue)
644
self.assertEqual(["contents of foo\n"], file_obj.readlines())
581
647
class TestCorruptDirstate(TestCaseWithTransport):
582
648
"""Tests for how we handle when the dirstate has been corrupted."""