/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
5080.3.2 by Vincent Ladeuil
Reproduce bug #533547 where DirstateRevisionTree.kind query the wrong inventory entry.
1
# Copyright (C) 2006, 2007, 2009, 2010 Canonical Ltd
1908.11.2 by Robert Collins
Implement WorkingTree interface conformance tests for
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1908.11.2 by Robert Collins
Implement WorkingTree interface conformance tests for
16
17
"""Tests for WorkingTree.revision_tree.
18
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
19
These tests are in addition to the tests from
4523.1.4 by Martin Pool
Rename remaining *_implementations tests
20
per_tree.test_revision_tree which cover the behaviour expected from
1908.11.2 by Robert Collins
Implement WorkingTree interface conformance tests for
21
all Trees. WorkingTrees implement the revision_tree api to allow access to
22
cached data, but we don't require that all WorkingTrees have such a cache,
23
so these tests are testing that when there is a cache, it performs correctly.
24
"""
25
5080.3.2 by Vincent Ladeuil
Reproduce bug #533547 where DirstateRevisionTree.kind query the wrong inventory entry.
26
from bzrlib import (
27
    branchbuilder,
28
    errors,
29
    tests,
30
    )
31
from bzrlib.tests import per_workingtree
32
33
34
class TestRevisionTree(per_workingtree.TestCaseWithWorkingTree):
1908.11.2 by Robert Collins
Implement WorkingTree interface conformance tests for
35
36
    def test_get_zeroth_basis_tree_via_revision_tree(self):
37
        tree = self.make_branch_and_tree('.')
38
        try:
39
            revision_tree = tree.revision_tree(tree.last_revision())
40
        except errors.NoSuchRevision:
41
            # its ok for a working tree to not cache trees, so just return.
42
            return
43
        basis_tree = tree.basis_tree()
44
        self.assertTreesEqual(revision_tree, basis_tree)
45
46
    def test_get_nonzeroth_basis_tree_via_revision_tree(self):
47
        tree = self.make_branch_and_tree('.')
48
        revision1 = tree.commit('first post')
49
        revision_tree = tree.revision_tree(revision1)
50
        basis_tree = tree.basis_tree()
51
        self.assertTreesEqual(revision_tree, basis_tree)
52
53
    def test_get_pending_merge_revision_tree(self):
54
        tree = self.make_branch_and_tree('tree1')
55
        tree.commit('first post')
56
        tree2 = tree.bzrdir.sprout('tree2').open_workingtree()
57
        revision1 = tree2.commit('commit in branch', allow_pointless=True)
58
        tree.merge_from_branch(tree2.branch)
59
        try:
60
            cached_revision_tree = tree.revision_tree(revision1)
61
        except errors.NoSuchRevision:
62
            # its ok for a working tree to not cache trees, so just return.
63
            return
64
        real_revision_tree = tree2.basis_tree()
65
        self.assertTreesEqual(real_revision_tree, cached_revision_tree)
66
67
    def test_get_uncached_basis_via_revision_tree(self):
68
        # The basis_tree method returns an empty tree when you ask for the
69
        # basis if the basis is not cached, and it is a ghost. However the
70
        # revision_tree method should always raise when a request tree is not
71
        # cached, so we force this by setting a basis that is a ghost and
72
        # thus cannot be cached.
73
        tree = self.make_branch_and_tree('.')
74
        tree.set_parent_ids(['a-ghost'], allow_leftmost_as_ghost=True)
75
        self.assertRaises(errors.NoSuchRevision, tree.revision_tree, 'a-ghost')
2255.2.76 by Robert Collins
Add tests for revision trees with a different unique root to the current tree.
76
77
    def test_revision_tree_different_root_id(self):
78
        """A revision tree might have a very different root."""
79
        tree = self.make_branch_and_tree('tree1')
80
        tree.set_root_id('one')
81
        rev1 = tree.commit('first post')
82
        tree.set_root_id('two')
83
        try:
84
            cached_revision_tree = tree.revision_tree(rev1)
85
        except errors.NoSuchRevision:
86
            # its ok for a working tree to not cache trees, so just return.
87
            return
88
        repository_revision_tree = tree.branch.repository.revision_tree(rev1)
89
        self.assertTreesEqual(repository_revision_tree, cached_revision_tree)
5080.3.2 by Vincent Ladeuil
Reproduce bug #533547 where DirstateRevisionTree.kind query the wrong inventory entry.
90
91
92
class TestRevisionTreeKind(per_workingtree.TestCaseWithWorkingTree):
93
94
    def make_branch_with_merged_deletions(self, relpath='tree'):
95
        tree = self.make_branch_and_tree(relpath)
96
        files = ['a', 'b/', 'b/c']
97
        self.build_tree(files, line_endings='binary',
98
                        transport=tree.bzrdir.root_transport)
99
        tree.set_root_id('root-id')
100
        tree.add(files, ['a-id', 'b-id', 'c-id'])
101
        tree.commit('a, b and b/c', rev_id='base')
102
        tree2 = tree.bzrdir.sprout(relpath + '2').open_workingtree()
103
        # Delete 'a' in tree
104
        tree.remove('a', keep_files=False)
105
        tree.commit('remove a', rev_id='this')
106
        # Delete 'c' in tree2
107
        tree2.remove('b/c', keep_files=False)
108
        tree2.remove('b', keep_files=False)
109
        tree2.commit('remove b/c', rev_id='other')
110
        # Merge tree2 into tree
111
        tree.merge_from_branch(tree2.branch)
112
        return tree
113
114
    def test_kind_parent_tree(self):
115
        tree = self.make_branch_with_merged_deletions()
116
        tree.lock_read()
117
        self.addCleanup(tree.unlock)
118
        parents = tree.get_parent_ids()
119
        self.assertEqual(['this', 'other'], parents)
5080.3.4 by Vincent Ladeuil
Cleanup test from overly cautious checks.
120
        basis = tree.revision_tree(parents[0])
5080.3.2 by Vincent Ladeuil
Reproduce bug #533547 where DirstateRevisionTree.kind query the wrong inventory entry.
121
        basis.lock_read()
122
        self.addCleanup(basis.unlock)
123
        self.assertRaises(errors.NoSuchId, basis.kind, 'a-id')
124
        self.assertEqual(['directory', 'file'],
125
                         [basis.kind('b-id'), basis.kind('c-id')])
126
        try:
127
            other = tree.revision_tree(parents[1])
128
        except errors.NoSuchRevisionInTree:
129
            raise tests.TestNotApplicable(
130
                'Tree type %s caches only the basis revision tree.'
131
                % type(tree))
132
        other.lock_read()
133
        self.addCleanup(other.unlock)
134
        self.assertRaises(errors.NoSuchId, other.kind, 'b-id')
135
        self.assertRaises(errors.NoSuchId, other.kind, 'c-id')
136
        self.assertEqual('file', other.kind('a-id'))