/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
2524.1.1 by Aaron Bentley
Revert broken changes
1
# Copyright (C) 2007 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
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2524.1.1 by Aaron Bentley
Revert broken changes
16
17
"""Tests for Branch.sprout()"""
18
3763.9.4 by Daniel Clemente
New test for utf-8 symlinks in BzrDir.sprout
19
import os
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
20
from breezy import (
3834.5.1 by Andrew Bennetts
Improve test_sprout.
21
    branch as _mod_branch,
4070.3.1 by Robert Collins
Alter branch sprouting with an alternate fix for stacked branches that does not require multiple copy_content_into and set_parent calls, reducing IO and round trips.
22
    errors,
4241.14.12 by Vincent Ladeuil
Far too many modifications for a single commit, need to restart.
23
    osutils,
2487.2.4 by Aaron Bentley
Add test to ensure we can branch from repository revisions
24
    revision as _mod_revision,
2524.1.1 by Aaron Bentley
Revert broken changes
25
    tests,
26
    )
6670.4.3 by Jelmer Vernooij
Fix more imports.
27
from breezy.bzr import (
28
    branch as _mod_bzrbranch,
6670.4.14 by Jelmer Vernooij
Move remote to breezy.bzr.
29
    remote,
6670.4.3 by Jelmer Vernooij
Fix more imports.
30
    )
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
31
from breezy.tests import (
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
32
    features,
33
    )
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
34
from breezy.tests.per_branch import TestCaseWithBranch
2524.1.1 by Aaron Bentley
Revert broken changes
35
36
37
class TestSprout(TestCaseWithBranch):
38
39
    def test_sprout_branch_nickname(self):
40
        # test the nick name is reset always
2949.5.1 by Alexander Belchenko
selftest: use SymlinkFeature instead of TestSkipped where appropriate
41
        raise tests.TestSkipped('XXX branch sprouting is not yet tested.')
2524.1.1 by Aaron Bentley
Revert broken changes
42
43
    def test_sprout_branch_parent(self):
44
        source = self.make_branch('source')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
45
        target = source.controldir.sprout(self.get_url('target')).open_branch()
46
        self.assertEqual(source.controldir.root_transport.base, target.get_parent())
2524.1.1 by Aaron Bentley
Revert broken changes
47
3834.5.2 by John Arbash Meinel
Track down the various BranchFormats that weren't setting the branch format as part of the _matchingbzrdir format.
48
    def test_sprout_uses_bzrdir_branch_format(self):
4005.2.1 by Robert Collins
Fix RemoteBranch to be used correctly in tests using bzr+ssh, to fire off Branch hooks correctly, and improve the branch_implementations tests to check that making a branch gets the right format under test.
49
        # branch.sprout(bzrdir) is defined as using the branch format selected
50
        # by bzrdir; format preservation is achieved by parameterising the
51
        # bzrdir during bzrdir.sprout, which is where stacking compatibility
52
        # checks are done. So this test tests that each implementation of
53
        # Branch.sprout delegates appropriately to the bzrdir which the
54
        # branch is being created in, rather than testing that the result is
55
        # in the format that we are testing (which is what would happen if
56
        # the branch did not delegate appropriately).
6653.1.2 by Jelmer Vernooij
Fix imports.
57
        if isinstance(self.branch_format, _mod_bzrbranch.BranchReferenceFormat):
3834.5.1 by Andrew Bennetts
Improve test_sprout.
58
            raise tests.TestNotApplicable('cannot sprout to a reference')
59
        # Start with a format that is unlikely to be the target format
4005.2.1 by Robert Collins
Fix RemoteBranch to be used correctly in tests using bzr+ssh, to fire off Branch hooks correctly, and improve the branch_implementations tests to check that making a branch gets the right format under test.
60
        # We call the super class to allow overriding the format of creation)
3834.5.1 by Andrew Bennetts
Improve test_sprout.
61
        source = tests.TestCaseWithTransport.make_branch(self, 'old-branch',
5582.10.96 by Jelmer Vernooij
Support running without plugins.
62
                                                         format='knit')
6653.6.5 by Jelmer Vernooij
Rename make_bzrdir to make_controldir.
63
        target_bzrdir = self.make_controldir('target')
3834.5.2 by John Arbash Meinel
Track down the various BranchFormats that weren't setting the branch format as part of the _matchingbzrdir format.
64
        target_bzrdir.create_repository()
4005.2.1 by Robert Collins
Fix RemoteBranch to be used correctly in tests using bzr+ssh, to fire off Branch hooks correctly, and improve the branch_implementations tests to check that making a branch gets the right format under test.
65
        result_format = self.branch_format
66
        if isinstance(target_bzrdir, remote.RemoteBzrDir):
67
            # for a remote bzrdir, we need to parameterise it with a branch
68
            # format, as, after creation, the newly opened remote objects
69
            # do not have one unless a branch was created at the time.
70
            # We use branch format 6 because its not the default, and its not
71
            # metaweave either.
6653.1.2 by Jelmer Vernooij
Fix imports.
72
            target_bzrdir._format.set_branch_format(_mod_bzrbranch.BzrBranchFormat6())
4005.2.1 by Robert Collins
Fix RemoteBranch to be used correctly in tests using bzr+ssh, to fire off Branch hooks correctly, and improve the branch_implementations tests to check that making a branch gets the right format under test.
73
            result_format = target_bzrdir._format.get_branch_format()
3834.5.1 by Andrew Bennetts
Improve test_sprout.
74
        target = source.sprout(target_bzrdir)
4005.2.1 by Robert Collins
Fix RemoteBranch to be used correctly in tests using bzr+ssh, to fire off Branch hooks correctly, and improve the branch_implementations tests to check that making a branch gets the right format under test.
75
        if isinstance(target, remote.RemoteBranch):
76
            # we have to look at the real branch to see whether RemoteBranch
77
            # did the right thing.
78
            target._ensure_real()
79
            target = target._real_branch
4032.3.2 by Robert Collins
Create and use a RPC call to create branches on bzr servers rather than using VFS calls.
80
        if isinstance(result_format, remote.RemoteBranchFormat):
81
            # Unwrap a parameterised RemoteBranchFormat for comparison.
82
            result_format = result_format._custom_format
4005.2.1 by Robert Collins
Fix RemoteBranch to be used correctly in tests using bzr+ssh, to fire off Branch hooks correctly, and improve the branch_implementations tests to check that making a branch gets the right format under test.
83
        self.assertIs(result_format.__class__, target._format.__class__)
2524.1.1 by Aaron Bentley
Revert broken changes
84
85
    def test_sprout_partial(self):
86
        # test sprouting with a prefix of the revision-history.
87
        # also needs not-on-revision-history behaviour defined.
88
        wt_a = self.make_branch_and_tree('a')
89
        self.build_tree(['a/one'])
90
        wt_a.add(['one'])
91
        wt_a.commit('commit one', rev_id='1')
92
        self.build_tree(['a/two'])
93
        wt_a.add(['two'])
94
        wt_a.commit('commit two', rev_id='2')
95
        repo_b = self.make_repository('b')
96
        repo_a = wt_a.branch.repository
97
        repo_a.copy_content_into(repo_b)
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
98
        br_b = wt_a.branch.sprout(repo_b.controldir, revision_id='1')
2524.1.1 by Aaron Bentley
Revert broken changes
99
        self.assertEqual('1', br_b.last_revision())
100
101
    def test_sprout_partial_not_in_revision_history(self):
102
        """We should be able to sprout from any revision in ancestry."""
103
        wt = self.make_branch_and_tree('source')
104
        self.build_tree(['source/a'])
105
        wt.add('a')
106
        wt.commit('rev1', rev_id='rev1')
107
        wt.commit('rev2-alt', rev_id='rev2-alt')
108
        wt.set_parent_ids(['rev1'])
109
        wt.branch.set_last_revision_info(1, 'rev1')
110
        wt.commit('rev2', rev_id='rev2')
111
        wt.set_parent_ids(['rev2', 'rev2-alt'])
112
        wt.commit('rev3', rev_id='rev3')
113
114
        repo = self.make_repository('target')
115
        repo.fetch(wt.branch.repository)
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
116
        branch2 = wt.branch.sprout(repo.controldir, revision_id='rev2-alt')
2524.1.1 by Aaron Bentley
Revert broken changes
117
        self.assertEqual((2, 'rev2-alt'), branch2.last_revision_info())
6165.4.6 by Jelmer Vernooij
Avoid more uses of revision_history.
118
        self.assertEqual('rev2-alt', branch2.last_revision())
2487.2.4 by Aaron Bentley
Add test to ensure we can branch from repository revisions
119
5535.3.38 by Andrew Bennetts
Remove XXX, add some test coverage to prove it works.
120
    def test_sprout_preserves_tags(self):
121
        """Sprout preserves tags, even tags of absent revisions."""
122
        try:
123
            builder = self.make_branch_builder('source')
124
        except errors.UninitializableFormat:
125
            raise tests.TestSkipped('Uninitializable branch format')
126
        builder.build_commit(message="Rev 1", rev_id='rev-1')
127
        source = builder.get_branch()
128
        try:
129
            source.tags.set_tag('tag-a', 'missing-rev')
6123.9.10 by Jelmer Vernooij
Improve tag handling.
130
        except (errors.TagsNotSupported, errors.GhostTagsNotSupported):
5535.3.38 by Andrew Bennetts
Remove XXX, add some test coverage to prove it works.
131
            raise tests.TestNotApplicable(
6123.9.10 by Jelmer Vernooij
Improve tag handling.
132
                'Branch format does not support tags or tags to ghosts.')
5535.3.38 by Andrew Bennetts
Remove XXX, add some test coverage to prove it works.
133
        # Now source has a tag pointing to an absent revision.  Sprout it.
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
134
        target_bzrdir = self.make_repository('target').controldir
5535.3.38 by Andrew Bennetts
Remove XXX, add some test coverage to prove it works.
135
        new_branch = source.sprout(target_bzrdir)
136
        # The tag is present in the target
137
        self.assertEqual('missing-rev', new_branch.tags.lookup_tag('tag-a'))
138
2487.2.4 by Aaron Bentley
Add test to ensure we can branch from repository revisions
139
    def test_sprout_from_any_repo_revision(self):
140
        """We should be able to sprout from any revision."""
141
        wt = self.make_branch_and_tree('source')
142
        self.build_tree(['source/a'])
143
        wt.add('a')
144
        wt.commit('rev1a', rev_id='rev1a')
145
        # simulated uncommit
146
        wt.branch.set_last_revision_info(0, _mod_revision.NULL_REVISION)
2598.5.3 by Aaron Bentley
Push NULL_REVISION deeper
147
        wt.set_last_revision(_mod_revision.NULL_REVISION)
2796.1.4 by Aaron Bentley
Fix up various test cases
148
        wt.revert()
2487.2.4 by Aaron Bentley
Add test to ensure we can branch from repository revisions
149
        wt.commit('rev1b', rev_id='rev1b')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
150
        wt2 = wt.controldir.sprout('target',
2487.2.4 by Aaron Bentley
Add test to ensure we can branch from repository revisions
151
            revision_id='rev1a').open_workingtree()
152
        self.assertEqual('rev1a', wt2.last_revision())
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
153
        self.assertPathExists('target/a')
3763.9.4 by Daniel Clemente
New test for utf-8 symlinks in BzrDir.sprout
154
3763.9.7 by Daniel Clemente
Tested Unicode target rather than always trying to create it in UTF-8. Test renamed
155
    def test_sprout_with_unicode_symlink(self):
3763.9.8 by Daniel Clemente
Broken lines, and prepended # before bug numbers
156
        # this tests bug #272444
3763.9.11 by Daniel Clemente
More detailed comment and in broken line
157
        # Since the trigger function seems to be set_parent_trees, there exists
158
        # also a similar test, with name test_unicode_symlink, in class
4523.1.4 by Martin Pool
Rename remaining *_implementations tests
159
        # TestSetParents at file per_workingtree/test_parents.py
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
160
        self.requireFeature(features.SymlinkFeature)
161
        self.requireFeature(features.UnicodeFilenameFeature)
3763.9.4 by Daniel Clemente
New test for utf-8 symlinks in BzrDir.sprout
162
163
        tree = self.make_branch_and_tree('tree1')
164
3763.9.9 by Daniel Clemente
Used a greek omega instead of an accented 'o' to avoid combining characters
165
        # The link points to a file whose name is an omega
166
        # U+03A9 GREEK CAPITAL LETTER OMEGA
167
        # UTF-8: ce a9  UTF-16BE: 03a9  Decimal: Ω
4241.14.12 by Vincent Ladeuil
Far too many modifications for a single commit, need to restart.
168
        target = u'\u03a9'
169
        link_name = u'\N{Euro Sign}link'
170
        os.symlink(target, 'tree1/' + link_name)
171
        tree.add([link_name],['link-id'])
3763.9.4 by Daniel Clemente
New test for utf-8 symlinks in BzrDir.sprout
172
4095.3.1 by Vincent Ladeuil
Fix #339055 and #277444 by handling non ascii symlink targets.
173
        revision = tree.commit('added a link to a Unicode target')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
174
        tree.controldir.sprout('dest')
4241.14.23 by Vincent Ladeuil
NEWS entry and final cleanup before submission.
175
        self.assertEqual(target, osutils.readlink('dest/' + link_name))
4241.14.12 by Vincent Ladeuil
Far too many modifications for a single commit, need to restart.
176
        tree.lock_read()
177
        self.addCleanup(tree.unlock)
178
        # Check that the symlink target is safely round-tripped in the trees.
179
        self.assertEqual(target, tree.get_symlink_target('link-id'))
180
        self.assertEqual(target,
181
                         tree.basis_tree().get_symlink_target('link-id'))
3763.9.4 by Daniel Clemente
New test for utf-8 symlinks in BzrDir.sprout
182
4266.3.6 by Jelmer Vernooij
Add test for handling ghosts in Branch._synchronize_history if the revision that's being cloned is not the tip.
183
    def test_sprout_with_ghost_in_mainline(self):
184
        tree = self.make_branch_and_tree('tree1')
6164.2.1 by Jelmer Vernooij
Skip tests if the repository doesn't support ghosts.
185
        if not tree.branch.repository._format.supports_ghosts:
186
            raise tests.TestNotApplicable(
187
                "repository format does not support ghosts in mainline")
4266.3.6 by Jelmer Vernooij
Add test for handling ghosts in Branch._synchronize_history if the revision that's being cloned is not the tip.
188
        tree.set_parent_ids(["spooky"], allow_leftmost_as_ghost=True)
189
        tree.add('')
190
        tree.commit('msg1', rev_id='rev1')
191
        tree.commit('msg2', rev_id='rev2')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
192
        tree.controldir.sprout('target', revision_id='rev1')
4266.3.6 by Jelmer Vernooij
Add test for handling ghosts in Branch._synchronize_history if the revision that's being cloned is not the tip.
193
4070.3.1 by Robert Collins
Alter branch sprouting with an alternate fix for stacked branches that does not require multiple copy_content_into and set_parent calls, reducing IO and round trips.
194
    def assertBranchHookBranchIsStacked(self, pre_change_params):
195
        # Just calling will either succeed or fail.
196
        pre_change_params.branch.get_stacked_on_url()
197
        self.hook_calls.append(pre_change_params)
198
199
    def test_sprout_stacked_hooks_get_stacked_branch(self):
200
        tree = self.make_branch_and_tree('source')
201
        tree.commit('a commit')
202
        revid = tree.commit('a second commit')
203
        source = tree.branch
204
        target_transport = self.get_transport('target')
205
        self.hook_calls = []
206
        _mod_branch.Branch.hooks.install_named_hook("pre_change_branch_tip",
207
            self.assertBranchHookBranchIsStacked, None)
208
        try:
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
209
            dir = source.controldir.sprout(target_transport.base,
4070.3.1 by Robert Collins
Alter branch sprouting with an alternate fix for stacked branches that does not require multiple copy_content_into and set_parent calls, reducing IO and round trips.
210
                source.last_revision(), possible_transports=[target_transport],
211
                source_branch=source, stacked=True)
6164.2.8 by Jelmer Vernooij
Move ex_stacked_on
212
        except errors.UnstackableBranchFormat:
5582.9.8 by Jelmer Vernooij
Avoid specifying format 4. Rather, check for consistency with the branch format's own information.
213
            if not self.branch_format.supports_stacking():
214
                raise tests.TestNotApplicable(
215
                    "Format doesn't auto stack successfully.")
4070.3.1 by Robert Collins
Alter branch sprouting with an alternate fix for stacked branches that does not require multiple copy_content_into and set_parent calls, reducing IO and round trips.
216
            else:
217
                raise
218
        result = dir.open_branch()
219
        self.assertEqual(revid, result.last_revision())
220
        self.assertEqual(source.base, result.get_stacked_on_url())
221
        # Smart servers invoke hooks on both sides
222
        if isinstance(result, remote.RemoteBranch):
223
            expected_calls = 2
224
        else:
225
            expected_calls = 1
226
        self.assertEqual(expected_calls, len(self.hook_calls))
227