/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
4343.3.10 by John Arbash Meinel
Add a per_repository_reference test with real stacked repos.
1
# Copyright (C) 2009 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
17
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
18
from breezy import (
4392.2.2 by John Arbash Meinel
Add tests that ensure we can fetch branches with ghosts in their ancestry.
19
    branch,
6670.4.3 by Jelmer Vernooij
Fix more imports.
20
    )
21
from breezy.bzr import (
6341.1.4 by Jelmer Vernooij
Move more functionality to vf_search.
22
    vf_search,
4392.2.2 by John Arbash Meinel
Add tests that ensure we can fetch branches with ghosts in their ancestry.
23
    )
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
24
from breezy.tests.per_repository import TestCaseWithRepository
4343.3.10 by John Arbash Meinel
Add a per_repository_reference test with real stacked repos.
25
26
5539.2.7 by Andrew Bennetts
Add a test, revise a comment.
27
class TestFetchBase(TestCaseWithRepository):
4343.3.10 by John Arbash Meinel
Add a per_repository_reference test with real stacked repos.
28
4343.3.17 by John Arbash Meinel
Finally found a way to write a test case to exercise the code path.
29
    def make_source_branch(self):
30
        # It would be nice if there was a way to force this to be memory-only
4343.3.10 by John Arbash Meinel
Add a per_repository_reference test with real stacked repos.
31
        builder = self.make_branch_builder('source')
32
        content = ['content lines\n'
33
                   'for the first revision\n'
34
                   'which is a marginal amount of content\n'
35
                  ]
36
        builder.start_series()
37
        builder.build_snapshot('A-id', None, [
38
            ('add', ('', 'root-id', 'directory', None)),
39
            ('add', ('a', 'a-id', 'file', ''.join(content))),
40
            ])
41
        content.append('and some more lines for B\n')
42
        builder.build_snapshot('B-id', ['A-id'], [
43
            ('modify', ('a-id', ''.join(content)))])
44
        content.append('and yet even more content for C\n')
45
        builder.build_snapshot('C-id', ['B-id'], [
46
            ('modify', ('a-id', ''.join(content)))])
47
        builder.finish_series()
48
        source_b = builder.get_branch()
49
        source_b.lock_read()
50
        self.addCleanup(source_b.unlock)
4343.3.17 by John Arbash Meinel
Finally found a way to write a test case to exercise the code path.
51
        return content, source_b
52
5539.2.7 by Andrew Bennetts
Add a test, revise a comment.
53
54
class TestFetch(TestFetchBase):
55
4343.3.17 by John Arbash Meinel
Finally found a way to write a test case to exercise the code path.
56
    def test_sprout_from_stacked_with_short_history(self):
4343.3.36 by John Arbash Meinel
Some review feedback from Andrew.
57
        content, source_b = self.make_source_branch()
58
        # Split the generated content into a base branch, and a stacked branch
4343.3.13 by John Arbash Meinel
Update the fetch tests to make sure we are properly testing a smart base branch
59
        # Use 'make_branch' which gives us a bzr:// branch when appropriate,
60
        # rather than creating a branch-on-disk
61
        stack_b = self.make_branch('stack-on')
62
        stack_b.pull(source_b, stop_revision='B-id')
4343.3.10 by John Arbash Meinel
Add a per_repository_reference test with real stacked repos.
63
        target_b = self.make_branch('target')
4343.3.13 by John Arbash Meinel
Update the fetch tests to make sure we are properly testing a smart base branch
64
        target_b.set_stacked_on_url('../stack-on')
4343.3.10 by John Arbash Meinel
Add a per_repository_reference test with real stacked repos.
65
        target_b.pull(source_b, stop_revision='C-id')
66
        # At this point, we should have a target branch, with 1 revision, on
67
        # top of the source.
4343.3.17 by John Arbash Meinel
Finally found a way to write a test case to exercise the code path.
68
        final_b = self.make_branch('final')
69
        final_b.pull(target_b)
4343.3.10 by John Arbash Meinel
Add a per_repository_reference test with real stacked repos.
70
        final_b.lock_read()
71
        self.addCleanup(final_b.unlock)
72
        self.assertEqual('C-id', final_b.last_revision())
73
        text_keys = [('a-id', 'A-id'), ('a-id', 'B-id'), ('a-id', 'C-id')]
74
        stream = final_b.repository.texts.get_record_stream(text_keys,
75
            'unordered', True)
4343.3.36 by John Arbash Meinel
Some review feedback from Andrew.
76
        records = sorted([(r.key, r.get_bytes_as('fulltext')) for r in stream])
77
        self.assertEqual([
78
            (('a-id', 'A-id'), ''.join(content[:-2])),
79
            (('a-id', 'B-id'), ''.join(content[:-1])),
80
            (('a-id', 'C-id'), ''.join(content)),
81
            ], records)
4343.3.17 by John Arbash Meinel
Finally found a way to write a test case to exercise the code path.
82
83
    def test_sprout_from_smart_stacked_with_short_history(self):
84
        content, source_b = self.make_source_branch()
85
        transport = self.make_smart_server('server')
86
        transport.ensure_base()
87
        url = transport.abspath('')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
88
        stack_b = source_b.controldir.sprout(url + '/stack-on', revision_id='B-id')
4343.3.17 by John Arbash Meinel
Finally found a way to write a test case to exercise the code path.
89
        # self.make_branch only takes relative paths, so we do it the 'hard'
90
        # way
91
        target_transport = transport.clone('target')
92
        target_transport.ensure_base()
93
        target_bzrdir = self.bzrdir_format.initialize_on_transport(
94
                            target_transport)
95
        target_bzrdir.create_repository()
96
        target_b = target_bzrdir.create_branch()
97
        target_b.set_stacked_on_url('../stack-on')
98
        target_b.pull(source_b, stop_revision='C-id')
99
        # Now we should be able to branch from the remote location to a local
100
        # location
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
101
        final_b = target_b.controldir.sprout('final').open_branch()
4343.3.17 by John Arbash Meinel
Finally found a way to write a test case to exercise the code path.
102
        self.assertEqual('C-id', final_b.last_revision())
103
104
        # bzrdir.sprout() has slightly different code paths if you supply a
105
        # revision_id versus not. If you supply revision_id, then you get a
106
        # PendingAncestryResult for the search, versus a SearchResult...
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
107
        final2_b = target_b.controldir.sprout('final2',
4343.3.17 by John Arbash Meinel
Finally found a way to write a test case to exercise the code path.
108
                                          revision_id='C-id').open_branch()
109
        self.assertEqual('C-id', final_b.last_revision())
4392.2.2 by John Arbash Meinel
Add tests that ensure we can fetch branches with ghosts in their ancestry.
110
111
    def make_source_with_ghost_and_stacked_target(self):
112
        builder = self.make_branch_builder('source')
113
        builder.start_series()
114
        builder.build_snapshot('A-id', None, [
115
            ('add', ('', 'root-id', 'directory', None)),
116
            ('add', ('file', 'file-id', 'file', 'content\n'))])
117
        builder.build_snapshot('B-id', ['A-id', 'ghost-id'], [])
118
        builder.finish_series()
119
        source_b = builder.get_branch()
120
        source_b.lock_read()
121
        self.addCleanup(source_b.unlock)
122
        base = self.make_branch('base')
123
        base.pull(source_b, stop_revision='A-id')
124
        stacked = self.make_branch('stacked')
125
        stacked.set_stacked_on_url('../base')
126
        return source_b, base, stacked
127
128
    def test_fetch_with_ghost_stacked(self):
129
        (source_b, base,
130
         stacked) = self.make_source_with_ghost_and_stacked_target()
131
        stacked.pull(source_b, stop_revision='B-id')
132
133
    def test_fetch_into_smart_stacked_with_ghost(self):
134
        (source_b, base,
135
         stacked) = self.make_source_with_ghost_and_stacked_target()
136
        # Now, create a smart server on 'stacked' and re-open to force the
137
        # target to be a smart target
138
        trans = self.make_smart_server('stacked')
139
        stacked = branch.Branch.open(trans.base)
140
        stacked.lock_write()
141
        self.addCleanup(stacked.unlock)
142
        stacked.pull(source_b, stop_revision='B-id')
143
144
    def test_fetch_to_stacked_from_smart_with_ghost(self):
145
        (source_b, base,
146
         stacked) = self.make_source_with_ghost_and_stacked_target()
147
        # Now, create a smart server on 'source' and re-open to force the
148
        # target to be a smart target
149
        trans = self.make_smart_server('source')
150
        source_b = branch.Branch.open(trans.base)
151
        source_b.lock_read()
152
        self.addCleanup(source_b.unlock)
153
        stacked.pull(source_b, stop_revision='B-id')
5539.2.7 by Andrew Bennetts
Add a test, revise a comment.
154
155
156
class TestFetchFromRepoWithUnconfiguredFallbacks(TestFetchBase):
157
158
    def make_stacked_source_repo(self):
159
        _, source_b = self.make_source_branch()
160
        # Use 'make_branch' which gives us a bzr:// branch when appropriate,
161
        # rather than creating a branch-on-disk
162
        stack_b = self.make_branch('stack-on')
163
        stack_b.pull(source_b, stop_revision='B-id')
164
        stacked_b = self.make_branch('stacked')
165
        stacked_b.set_stacked_on_url('../stack-on')
166
        stacked_b.pull(source_b, stop_revision='C-id')
167
        return stacked_b.repository
168
169
    def test_fetch_everything_includes_parent_invs(self):
170
        stacked = self.make_stacked_source_repo()
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
171
        repo_missing_fallbacks = stacked.controldir.open_repository()
5539.2.7 by Andrew Bennetts
Add a test, revise a comment.
172
        self.addCleanup(repo_missing_fallbacks.lock_read().unlock)
173
        target = self.make_repository('target')
174
        self.addCleanup(target.lock_write().unlock)
175
        target.fetch(
176
            repo_missing_fallbacks,
6341.1.4 by Jelmer Vernooij
Move more functionality to vf_search.
177
            fetch_spec=vf_search.EverythingResult(repo_missing_fallbacks))
5539.2.7 by Andrew Bennetts
Add a test, revise a comment.
178
        self.assertEqual(repo_missing_fallbacks.revisions.keys(),
179
            target.revisions.keys())
180
        self.assertEqual(repo_missing_fallbacks.inventories.keys(),
181
            target.inventories.keys())
182
        self.assertEqual(['C-id'],
183
            sorted(k[-1] for k in target.revisions.keys()))
184
        self.assertEqual(['B-id', 'C-id'],
185
            sorted(k[-1] for k in target.inventories.keys()))
186
187
188