/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/branch_implementations/test_sprout.py

merge bzr.dev.

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,
28
32
 
29
33
    def test_sprout_branch_nickname(self):
30
34
        # test the nick name is reset always
31
 
        raise tests.TestSkipped('XXX branch sprouting is not yet tested..')
 
35
        raise tests.TestSkipped('XXX branch sprouting is not yet tested.')
32
36
 
33
37
    def test_sprout_branch_parent(self):
34
38
        source = self.make_branch('source')
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.
91
120
        # simulated uncommit
92
121
        wt.branch.set_last_revision_info(0, _mod_revision.NULL_REVISION)
93
122
        wt.set_last_revision(_mod_revision.NULL_REVISION)
94
 
        wt.revert([])
 
123
        wt.revert()
95
124
        wt.commit('rev1b', rev_id='rev1b')
96
125
        wt2 = wt.bzrdir.sprout('target',
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 workingtree_implementations/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 assertBranchHookBranchIsStacked(self, pre_change_params):
 
159
        # Just calling will either succeed or fail.
 
160
        pre_change_params.branch.get_stacked_on_url()
 
161
        self.hook_calls.append(pre_change_params)
 
162
 
 
163
    def test_sprout_stacked_hooks_get_stacked_branch(self):
 
164
        tree = self.make_branch_and_tree('source')
 
165
        tree.commit('a commit')
 
166
        revid = tree.commit('a second commit')
 
167
        source = tree.branch
 
168
        target_transport = self.get_transport('target')
 
169
        self.hook_calls = []
 
170
        _mod_branch.Branch.hooks.install_named_hook("pre_change_branch_tip",
 
171
            self.assertBranchHookBranchIsStacked, None)
 
172
        try:
 
173
            dir = source.bzrdir.sprout(target_transport.base,
 
174
                source.last_revision(), possible_transports=[target_transport],
 
175
                source_branch=source, stacked=True)
 
176
        except errors.UnstackableBranchFormat:
 
177
            if isinstance(self.branch_format, _mod_branch.BzrBranchFormat4):
 
178
                raise tests.KnownFailure(
 
179
                    "Format 4 doesn't auto stack successfully.")
 
180
            else:
 
181
                raise
 
182
        result = dir.open_branch()
 
183
        self.assertEqual(revid, result.last_revision())
 
184
        self.assertEqual(source.base, result.get_stacked_on_url())
 
185
        # Smart servers invoke hooks on both sides
 
186
        if isinstance(result, remote.RemoteBranch):
 
187
            expected_calls = 2
 
188
        else:
 
189
            expected_calls = 1
 
190
        self.assertEqual(expected_calls, len(self.hook_calls))
 
191