/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
18
from bzrlib.smart import server
19
from bzrlib.tests.per_repository import TestCaseWithRepository
20
21
4343.3.29 by John Arbash Meinel
Add 'check_for_missing_texts' flag to get_missing_parent_inv..
22
class TestFetch(TestCaseWithRepository):
4343.3.10 by John Arbash Meinel
Add a per_repository_reference test with real stacked repos.
23
4343.3.17 by John Arbash Meinel
Finally found a way to write a test case to exercise the code path.
24
    def make_source_branch(self):
25
        # 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.
26
        builder = self.make_branch_builder('source')
27
        content = ['content lines\n'
28
                   'for the first revision\n'
29
                   'which is a marginal amount of content\n'
30
                  ]
31
        builder.start_series()
32
        builder.build_snapshot('A-id', None, [
33
            ('add', ('', 'root-id', 'directory', None)),
34
            ('add', ('a', 'a-id', 'file', ''.join(content))),
35
            ])
36
        content.append('and some more lines for B\n')
37
        builder.build_snapshot('B-id', ['A-id'], [
38
            ('modify', ('a-id', ''.join(content)))])
39
        content.append('and yet even more content for C\n')
40
        builder.build_snapshot('C-id', ['B-id'], [
41
            ('modify', ('a-id', ''.join(content)))])
42
        builder.finish_series()
43
        source_b = builder.get_branch()
44
        source_b.lock_read()
45
        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.
46
        return content, source_b
47
48
    def test_sprout_from_stacked_with_short_history(self):
4343.3.36 by John Arbash Meinel
Some review feedback from Andrew.
49
        content, source_b = self.make_source_branch()
50
        # 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
51
        # Use 'make_branch' which gives us a bzr:// branch when appropriate,
52
        # rather than creating a branch-on-disk
53
        stack_b = self.make_branch('stack-on')
54
        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.
55
        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
56
        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.
57
        target_b.pull(source_b, stop_revision='C-id')
58
        # At this point, we should have a target branch, with 1 revision, on
59
        # 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.
60
        final_b = self.make_branch('final')
61
        final_b.pull(target_b)
4343.3.10 by John Arbash Meinel
Add a per_repository_reference test with real stacked repos.
62
        final_b.lock_read()
63
        self.addCleanup(final_b.unlock)
64
        self.assertEqual('C-id', final_b.last_revision())
65
        text_keys = [('a-id', 'A-id'), ('a-id', 'B-id'), ('a-id', 'C-id')]
66
        stream = final_b.repository.texts.get_record_stream(text_keys,
67
            'unordered', True)
4343.3.36 by John Arbash Meinel
Some review feedback from Andrew.
68
        records = sorted([(r.key, r.get_bytes_as('fulltext')) for r in stream])
69
        self.assertEqual([
70
            (('a-id', 'A-id'), ''.join(content[:-2])),
71
            (('a-id', 'B-id'), ''.join(content[:-1])),
72
            (('a-id', 'C-id'), ''.join(content)),
73
            ], records)
4343.3.17 by John Arbash Meinel
Finally found a way to write a test case to exercise the code path.
74
75
    def test_sprout_from_smart_stacked_with_short_history(self):
76
        content, source_b = self.make_source_branch()
77
        transport = self.make_smart_server('server')
78
        transport.ensure_base()
79
        url = transport.abspath('')
80
        stack_b = source_b.bzrdir.sprout(url + '/stack-on', revision_id='B-id')
81
        # self.make_branch only takes relative paths, so we do it the 'hard'
82
        # way
83
        target_transport = transport.clone('target')
84
        target_transport.ensure_base()
85
        target_bzrdir = self.bzrdir_format.initialize_on_transport(
86
                            target_transport)
87
        target_bzrdir.create_repository()
88
        target_b = target_bzrdir.create_branch()
89
        target_b.set_stacked_on_url('../stack-on')
90
        target_b.pull(source_b, stop_revision='C-id')
91
        # Now we should be able to branch from the remote location to a local
92
        # location
93
        final_b = target_b.bzrdir.sprout('final').open_branch()
94
        self.assertEqual('C-id', final_b.last_revision())
95
96
        # bzrdir.sprout() has slightly different code paths if you supply a
97
        # revision_id versus not. If you supply revision_id, then you get a
98
        # PendingAncestryResult for the search, versus a SearchResult...
99
        final2_b = target_b.bzrdir.sprout('final2',
100
                                          revision_id='C-id').open_branch()
101
        self.assertEqual('C-id', final_b.last_revision())