/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
3380.1.4 by Aaron Bentley
Split interrepository fetch tests into their own file
1
# Copyright (C) 2005, 2006, 2008 Canonical Ltd
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
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
17
18
import sys
19
20
import bzrlib
21
from bzrlib import (
22
    errors,
23
    repository,
3380.1.6 by Aaron Bentley
Ensure fetching munges sha1s
24
    osutils,
3380.1.4 by Aaron Bentley
Split interrepository fetch tests into their own file
25
    )
26
from bzrlib.errors import (
27
    NoSuchRevision,
28
    )
29
from bzrlib.revision import (
30
    NULL_REVISION,
31
    Revision,
32
    )
33
from bzrlib.tests import (
34
    TestNotApplicable,
35
    )
36
from bzrlib.tests.interrepository_implementations import (
37
    TestCaseWithInterRepository,
38
    )
3616.2.3 by Mark Hammond
Fix test failures due to missing check_repo_format_for_funky_id_on_win32
39
from bzrlib.tests.interrepository_implementations.test_interrepository import (
40
    check_repo_format_for_funky_id_on_win32
41
    )
3380.1.4 by Aaron Bentley
Split interrepository fetch tests into their own file
42
43
44
class TestInterRepository(TestCaseWithInterRepository):
45
46
    def test_fetch(self):
47
        tree_a = self.make_branch_and_tree('a')
48
        self.build_tree(['a/foo'])
49
        tree_a.add('foo', 'file1')
50
        tree_a.commit('rev1', rev_id='rev1')
51
        def check_push_rev1(repo):
52
            # ensure the revision is missing.
53
            self.assertRaises(NoSuchRevision, repo.get_revision, 'rev1')
4110.2.5 by Martin Pool
Deprecate passing pbs in to fetch()
54
            # fetch with a limit of NULL_REVISION
3380.1.4 by Aaron Bentley
Split interrepository fetch tests into their own file
55
            repo.fetch(tree_a.branch.repository,
4110.2.5 by Martin Pool
Deprecate passing pbs in to fetch()
56
                       revision_id=NULL_REVISION)
3380.1.4 by Aaron Bentley
Split interrepository fetch tests into their own file
57
            # nothing should have been pushed
58
            self.assertFalse(repo.has_revision('rev1'))
59
            # fetch with a default limit (grab everything)
60
            repo.fetch(tree_a.branch.repository)
61
            # check that b now has all the data from a's first commit.
62
            rev = repo.get_revision('rev1')
63
            tree = repo.revision_tree('rev1')
64
            tree.lock_read()
65
            self.addCleanup(tree.unlock)
66
            tree.get_file_text('file1')
67
            for file_id in tree:
68
                if tree.inventory[file_id].kind == "file":
69
                    tree.get_file(file_id).read()
70
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
71
        # makes a target version repo
3380.1.4 by Aaron Bentley
Split interrepository fetch tests into their own file
72
        repo_b = self.make_to_repository('b')
73
        check_push_rev1(repo_b)
74
75
    def test_fetch_missing_basis_text(self):
76
        """If fetching a delta, we should die if a basis is not present."""
77
        tree = self.make_branch_and_tree('tree')
78
        self.build_tree(['tree/a'])
79
        tree.add(['a'], ['a-id'])
80
        tree.commit('one', rev_id='rev-one')
81
        self.build_tree_contents([('tree/a', 'new contents\n')])
82
        tree.commit('two', rev_id='rev-two')
83
84
        to_repo = self.make_to_repository('to_repo')
85
        # We build a broken revision so that we can test the fetch code dies
86
        # properly. So copy the inventory and revision, but not the text.
87
        to_repo.lock_write()
88
        try:
89
            to_repo.start_write_group()
90
            inv = tree.branch.repository.get_inventory('rev-one')
91
            to_repo.add_inventory('rev-one', inv, [])
92
            rev = tree.branch.repository.get_revision('rev-one')
93
            to_repo.add_revision('rev-one', rev, inv=inv)
94
            to_repo.commit_write_group()
95
        finally:
96
            to_repo.unlock()
97
3350.3.21 by Robert Collins
Merge bzr.dev.
98
        # Implementations can either ensure that the target of the delta is
99
        # reconstructable, or raise an exception (which stream based copies
100
        # generally do).
3380.1.4 by Aaron Bentley
Split interrepository fetch tests into their own file
101
        try:
102
            to_repo.fetch(tree.branch.repository, 'rev-two')
3830.3.12 by Martin Pool
Review cleanups: unify has_key impls, add missing_keys(), clean up exception blocks
103
        except (errors.BzrCheckError, errors.RevisionNotPresent), e:
104
            # If an exception is raised, the revision should not be in the
105
            # target.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
106
            #
3830.3.9 by Martin Pool
Simplify kvf insert_record_stream; add has_key shorthand methods; update stacking effort tests
107
            # Can also just raise a generic check errors; stream insertion
108
            # does this to include all the missing data
109
            self.assertRaises((errors.NoSuchRevision, errors.RevisionNotPresent),
110
                              to_repo.revision_tree, 'rev-two')
3380.1.4 by Aaron Bentley
Split interrepository fetch tests into their own file
111
        else:
3350.3.21 by Robert Collins
Merge bzr.dev.
112
            # If not exception is raised, then the text should be
3380.1.4 by Aaron Bentley
Split interrepository fetch tests into their own file
113
            # available.
114
            to_repo.lock_read()
115
            try:
3350.3.21 by Robert Collins
Merge bzr.dev.
116
                rt = to_repo.revision_tree('rev-two')
117
                self.assertEqual('new contents\n',
3380.1.4 by Aaron Bentley
Split interrepository fetch tests into their own file
118
                                 rt.get_file_text('a-id'))
119
            finally:
120
                to_repo.unlock()
121
122
    def test_fetch_missing_revision_same_location_fails(self):
123
        repo_a = self.make_repository('.')
124
        repo_b = repository.Repository.open('.')
125
        try:
3350.3.21 by Robert Collins
Merge bzr.dev.
126
            self.assertRaises(errors.NoSuchRevision, repo_b.fetch, repo_a, revision_id='XXX')
3380.1.4 by Aaron Bentley
Split interrepository fetch tests into their own file
127
        except errors.LockError, e:
128
            check_old_format_lock_error(self.repository_format)
129
130
    def test_fetch_same_location_trivial_works(self):
131
        repo_a = self.make_repository('.')
132
        repo_b = repository.Repository.open('.')
133
        try:
134
            repo_a.fetch(repo_b)
135
        except errors.LockError, e:
136
            check_old_format_lock_error(self.repository_format)
137
138
    def test_fetch_missing_text_other_location_fails(self):
139
        source_tree = self.make_branch_and_tree('source')
140
        source = source_tree.branch.repository
141
        target = self.make_to_repository('target')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
142
3380.1.4 by Aaron Bentley
Split interrepository fetch tests into their own file
143
        # start by adding a file so the data knit for the file exists in
144
        # repositories that have specific files for each fileid.
145
        self.build_tree(['source/id'])
146
        source_tree.add(['id'], ['id'])
147
        source_tree.commit('a', rev_id='a')
148
        # now we manually insert a revision with an inventory referencing
149
        # 'id' at revision 'b', but we do not insert revision b.
150
        # this should ensure that the new versions of files are being checked
151
        # for during pull operations
152
        inv = source.get_inventory('a')
153
        source.lock_write()
3380.1.5 by Aaron Bentley
Merge with make-it-work
154
        self.addCleanup(source.unlock)
3380.1.4 by Aaron Bentley
Split interrepository fetch tests into their own file
155
        source.start_write_group()
156
        inv['id'].revision = 'b'
157
        inv.revision_id = 'b'
158
        sha1 = source.add_inventory('b', inv, ['a'])
159
        rev = Revision(timestamp=0,
160
                       timezone=None,
161
                       committer="Foo Bar <foo@example.com>",
162
                       message="Message",
163
                       inventory_sha1=sha1,
164
                       revision_id='b')
165
        rev.parent_ids = ['a']
166
        source.add_revision('b', rev)
167
        source.commit_write_group()
168
        self.assertRaises(errors.RevisionNotPresent, target.fetch, source)
169
        self.assertFalse(target.has_revision('b'))
170
171
    def test_fetch_funky_file_id(self):
172
        from_tree = self.make_branch_and_tree('tree')
173
        if sys.platform == 'win32':
174
            from_repo = from_tree.branch.repository
175
            check_repo_format_for_funky_id_on_win32(from_repo)
176
        self.build_tree(['tree/filename'])
177
        from_tree.add('filename', 'funky-chars<>%&;"\'')
178
        from_tree.commit('commit filename')
179
        to_repo = self.make_to_repository('to')
3350.3.21 by Robert Collins
Merge bzr.dev.
180
        to_repo.fetch(from_tree.branch.repository, from_tree.get_parent_ids()[0])
3380.1.4 by Aaron Bentley
Split interrepository fetch tests into their own file
181
3380.1.6 by Aaron Bentley
Ensure fetching munges sha1s
182
    def test_fetch_revision_hash(self):
183
        """Ensure that inventory hashes are updated by fetch"""
184
        from_tree = self.make_branch_and_tree('tree')
185
        from_tree.commit('foo', rev_id='foo-id')
186
        to_repo = self.make_to_repository('to')
187
        to_repo.fetch(from_tree.branch.repository)
188
        recorded_inv_sha1 = to_repo.get_inventory_sha1('foo-id')
189
        xml = to_repo.get_inventory_xml('foo-id')
190
        computed_inv_sha1 = osutils.sha_string(xml)
191
        self.assertEqual(computed_inv_sha1, recorded_inv_sha1)
192
3380.1.4 by Aaron Bentley
Split interrepository fetch tests into their own file
193
194
class TestFetchDependentData(TestCaseWithInterRepository):
195
196
    def test_reference(self):
197
        from_tree = self.make_branch_and_tree('tree')
198
        to_repo = self.make_to_repository('to')
199
        if (not from_tree.supports_tree_reference() or
200
            not from_tree.branch.repository._format.supports_tree_reference or
201
            not to_repo._format.supports_tree_reference):
202
            raise TestNotApplicable("Need subtree support.")
203
        subtree = self.make_branch_and_tree('tree/subtree')
204
        subtree.commit('subrev 1')
205
        from_tree.add_reference(subtree)
206
        tree_rev = from_tree.commit('foo')
207
        # now from_tree has a last-modified of subtree of the rev id of the
208
        # commit for foo, and a reference revision of the rev id of the commit
209
        # for subrev 1
210
        to_repo.fetch(from_tree.branch.repository, tree_rev)
211
        # to_repo should have a file_graph for from_tree.path2id('subtree') and
212
        # revid tree_rev.
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
213
        file_id = from_tree.path2id('subtree')
3380.1.4 by Aaron Bentley
Split interrepository fetch tests into their own file
214
        to_repo.lock_read()
215
        try:
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
216
            self.assertEqual({(file_id, tree_rev):()},
217
                to_repo.texts.get_parent_map([(file_id, tree_rev)]))
3380.1.4 by Aaron Bentley
Split interrepository fetch tests into their own file
218
        finally:
219
            to_repo.unlock()