/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/per_branch/test_sprout.py

  • Committer: Andrew Bennetts
  • Date: 2010-04-13 04:33:55 UTC
  • mfrom: (5147 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5149.
  • Revision ID: andrew.bennetts@canonical.com-20100413043355-lg3id0uwtju0k3zs
MergeĀ lp:bzr.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
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
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
"""Tests for Branch.sprout()"""
18
18
 
 
19
import os
19
20
from bzrlib import (
 
21
    branch as _mod_branch,
 
22
    errors,
 
23
    osutils,
20
24
    remote,
21
25
    revision as _mod_revision,
22
26
    tests,
23
27
    )
24
 
from bzrlib.tests.branch_implementations import TestCaseWithBranch
 
28
from bzrlib.tests.per_branch import TestCaseWithBranch
25
29
 
26
30
 
27
31
class TestSprout(TestCaseWithBranch):
35
39
        target = source.bzrdir.sprout(self.get_url('target')).open_branch()
36
40
        self.assertEqual(source.bzrdir.root_transport.base, target.get_parent())
37
41
 
38
 
    def test_sprout_preserves_kind(self):
39
 
        branch1 = self.make_branch('branch1')
40
 
        target_repo = self.make_repository('branch2')
41
 
        target_repo.fetch(branch1.repository)
42
 
        branch2 = branch1.sprout(target_repo.bzrdir)
43
 
        if isinstance(branch1, remote.RemoteBranch):
44
 
            branch1._ensure_real()
45
 
            target_class = branch1._real_branch.__class__
46
 
        else:
47
 
            target_class = branch1.__class__
48
 
        self.assertIsInstance(branch2, target_class)
 
42
    def test_sprout_uses_bzrdir_branch_format(self):
 
43
        # branch.sprout(bzrdir) is defined as using the branch format selected
 
44
        # by bzrdir; format preservation is achieved by parameterising the
 
45
        # bzrdir during bzrdir.sprout, which is where stacking compatibility
 
46
        # checks are done. So this test tests that each implementation of
 
47
        # Branch.sprout delegates appropriately to the bzrdir which the
 
48
        # branch is being created in, rather than testing that the result is
 
49
        # in the format that we are testing (which is what would happen if
 
50
        # the branch did not delegate appropriately).
 
51
        if isinstance(self.branch_format, _mod_branch.BranchReferenceFormat):
 
52
            raise tests.TestNotApplicable('cannot sprout to a reference')
 
53
        # Start with a format that is unlikely to be the target format
 
54
        # We call the super class to allow overriding the format of creation)
 
55
        source = tests.TestCaseWithTransport.make_branch(self, 'old-branch',
 
56
                                                         format='metaweave')
 
57
        target_bzrdir = self.make_bzrdir('target')
 
58
        target_bzrdir.create_repository()
 
59
        result_format = self.branch_format
 
60
        if isinstance(target_bzrdir, remote.RemoteBzrDir):
 
61
            # for a remote bzrdir, we need to parameterise it with a branch
 
62
            # format, as, after creation, the newly opened remote objects
 
63
            # do not have one unless a branch was created at the time.
 
64
            # We use branch format 6 because its not the default, and its not
 
65
            # metaweave either.
 
66
            target_bzrdir._format.set_branch_format(_mod_branch.BzrBranchFormat6())
 
67
            result_format = target_bzrdir._format.get_branch_format()
 
68
        target = source.sprout(target_bzrdir)
 
69
        if isinstance(target, remote.RemoteBranch):
 
70
            # we have to look at the real branch to see whether RemoteBranch
 
71
            # did the right thing.
 
72
            target._ensure_real()
 
73
            target = target._real_branch
 
74
        if isinstance(result_format, remote.RemoteBranchFormat):
 
75
            # Unwrap a parameterised RemoteBranchFormat for comparison.
 
76
            result_format = result_format._custom_format
 
77
        self.assertIs(result_format.__class__, target._format.__class__)
49
78
 
50
79
    def test_sprout_partial(self):
51
80
        # test sprouting with a prefix of the revision-history.
97
126
            revision_id='rev1a').open_workingtree()
98
127
        self.assertEqual('rev1a', wt2.last_revision())
99
128
        self.failUnlessExists('target/a')
 
129
 
 
130
    def test_sprout_with_unicode_symlink(self):
 
131
        # this tests bug #272444
 
132
        # Since the trigger function seems to be set_parent_trees, there exists
 
133
        # also a similar test, with name test_unicode_symlink, in class
 
134
        # TestSetParents at file per_workingtree/test_parents.py
 
135
        self.requireFeature(tests.SymlinkFeature)
 
136
        self.requireFeature(tests.UnicodeFilenameFeature)
 
137
 
 
138
        tree = self.make_branch_and_tree('tree1')
 
139
 
 
140
        # The link points to a file whose name is an omega
 
141
        # U+03A9 GREEK CAPITAL LETTER OMEGA
 
142
        # UTF-8: ce a9  UTF-16BE: 03a9  Decimal: Ω
 
143
        target = u'\u03a9'
 
144
        link_name = u'\N{Euro Sign}link'
 
145
        os.symlink(target, 'tree1/' + link_name)
 
146
        tree.add([link_name],['link-id'])
 
147
 
 
148
        revision = tree.commit('added a link to a Unicode target')
 
149
        tree.bzrdir.sprout('dest')
 
150
        self.assertEqual(target, osutils.readlink('dest/' + link_name))
 
151
        tree.lock_read()
 
152
        self.addCleanup(tree.unlock)
 
153
        # Check that the symlink target is safely round-tripped in the trees.
 
154
        self.assertEqual(target, tree.get_symlink_target('link-id'))
 
155
        self.assertEqual(target,
 
156
                         tree.basis_tree().get_symlink_target('link-id'))
 
157
 
 
158
    def test_sprout_with_ghost_in_mainline(self):
 
159
        tree = self.make_branch_and_tree('tree1')
 
160
        tree.set_parent_ids(["spooky"], allow_leftmost_as_ghost=True)
 
161
        tree.add('')
 
162
        tree.commit('msg1', rev_id='rev1')
 
163
        tree.commit('msg2', rev_id='rev2')
 
164
        tree.bzrdir.sprout('target', revision_id='rev1')
 
165
 
 
166
    def assertBranchHookBranchIsStacked(self, pre_change_params):
 
167
        # Just calling will either succeed or fail.
 
168
        pre_change_params.branch.get_stacked_on_url()
 
169
        self.hook_calls.append(pre_change_params)
 
170
 
 
171
    def test_sprout_stacked_hooks_get_stacked_branch(self):
 
172
        tree = self.make_branch_and_tree('source')
 
173
        tree.commit('a commit')
 
174
        revid = tree.commit('a second commit')
 
175
        source = tree.branch
 
176
        target_transport = self.get_transport('target')
 
177
        self.hook_calls = []
 
178
        _mod_branch.Branch.hooks.install_named_hook("pre_change_branch_tip",
 
179
            self.assertBranchHookBranchIsStacked, None)
 
180
        try:
 
181
            dir = source.bzrdir.sprout(target_transport.base,
 
182
                source.last_revision(), possible_transports=[target_transport],
 
183
                source_branch=source, stacked=True)
 
184
        except errors.UnstackableBranchFormat:
 
185
            if isinstance(self.branch_format, _mod_branch.BzrBranchFormat4):
 
186
                raise tests.KnownFailure(
 
187
                    "Format 4 doesn't auto stack successfully.")
 
188
            else:
 
189
                raise
 
190
        result = dir.open_branch()
 
191
        self.assertEqual(revid, result.last_revision())
 
192
        self.assertEqual(source.base, result.get_stacked_on_url())
 
193
        # Smart servers invoke hooks on both sides
 
194
        if isinstance(result, remote.RemoteBranch):
 
195
            expected_calls = 2
 
196
        else:
 
197
            expected_calls = 1
 
198
        self.assertEqual(expected_calls, len(self.hook_calls))
 
199