/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 rev 4098

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
import os
20
20
from bzrlib import (
21
21
    branch as _mod_branch,
 
22
    errors,
22
23
    remote,
23
24
    revision as _mod_revision,
24
25
    tests,
151
152
            raise KnownFailure('there is no support for'
152
153
                               ' symlinks to non-ASCII targets (bug #272444)')
153
154
 
 
155
    def assertBranchHookBranchIsStacked(self, pre_change_params):
 
156
        # Just calling will either succeed or fail.
 
157
        pre_change_params.branch.get_stacked_on_url()
 
158
        self.hook_calls.append(pre_change_params)
 
159
 
 
160
    def test_sprout_stacked_hooks_get_stacked_branch(self):
 
161
        tree = self.make_branch_and_tree('source')
 
162
        tree.commit('a commit')
 
163
        revid = tree.commit('a second commit')
 
164
        source = tree.branch
 
165
        target_transport = self.get_transport('target')
 
166
        self.hook_calls = []
 
167
        _mod_branch.Branch.hooks.install_named_hook("pre_change_branch_tip",
 
168
            self.assertBranchHookBranchIsStacked, None)
 
169
        try:
 
170
            dir = source.bzrdir.sprout(target_transport.base,
 
171
                source.last_revision(), possible_transports=[target_transport],
 
172
                source_branch=source, stacked=True)
 
173
        except errors.UnstackableBranchFormat:
 
174
            if isinstance(self.branch_format, _mod_branch.BzrBranchFormat4):
 
175
                raise KnownFailure("Format 4 doesn't auto stack successfully.")
 
176
            else:
 
177
                raise
 
178
        result = dir.open_branch()
 
179
        self.assertEqual(revid, result.last_revision())
 
180
        self.assertEqual(source.base, result.get_stacked_on_url())
 
181
        # Smart servers invoke hooks on both sides
 
182
        if isinstance(result, remote.RemoteBranch):
 
183
            expected_calls = 2
 
184
        else:
 
185
            expected_calls = 1
 
186
        self.assertEqual(expected_calls, len(self.hook_calls))
 
187