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
17
17
"""Tests for Branch.sprout()"""
20
20
from bzrlib import (
21
21
branch as _mod_branch,
23
24
revision as _mod_revision,
26
from bzrlib.tests import KnownFailure, SymlinkFeature, UnicodeFilenameFeature
27
27
from bzrlib.tests.branch_implementations import TestCaseWithBranch
70
70
# did the right thing.
71
71
target._ensure_real()
72
72
target = target._real_branch
73
if isinstance(result_format, remote.RemoteBranchFormat):
74
# Unwrap a parameterised RemoteBranchFormat for comparison.
75
result_format = result_format._custom_format
73
76
self.assertIs(result_format.__class__, target._format.__class__)
75
78
def test_sprout_partial(self):
128
131
# Since the trigger function seems to be set_parent_trees, there exists
129
132
# also a similar test, with name test_unicode_symlink, in class
130
133
# TestSetParents at file workingtree_implementations/test_parents.py
131
self.requireFeature(SymlinkFeature)
132
self.requireFeature(UnicodeFilenameFeature)
134
self.requireFeature(tests.SymlinkFeature)
135
self.requireFeature(tests.UnicodeFilenameFeature)
134
137
tree = self.make_branch_and_tree('tree1')
139
142
os.symlink(u'\u03a9','tree1/link_name')
140
143
tree.add(['link_name'],['link-id'])
145
revision = tree.commit('added a link to a Unicode target')
146
tree.bzrdir.sprout('target')
148
def assertBranchHookBranchIsStacked(self, pre_change_params):
149
# Just calling will either succeed or fail.
150
pre_change_params.branch.get_stacked_on_url()
151
self.hook_calls.append(pre_change_params)
153
def test_sprout_stacked_hooks_get_stacked_branch(self):
154
tree = self.make_branch_and_tree('source')
155
tree.commit('a commit')
156
revid = tree.commit('a second commit')
158
target_transport = self.get_transport('target')
160
_mod_branch.Branch.hooks.install_named_hook("pre_change_branch_tip",
161
self.assertBranchHookBranchIsStacked, None)
143
# python 2.7a0 failed on commit:
144
revision = tree.commit('added a link to a Unicode target')
145
# python 2.5 failed on sprout:
146
tree.bzrdir.sprout('target')
147
except UnicodeEncodeError, e:
148
raise KnownFailure('there is no support for'
149
' symlinks to non-ASCII targets (bug #272444)')
163
dir = source.bzrdir.sprout(target_transport.base,
164
source.last_revision(), possible_transports=[target_transport],
165
source_branch=source, stacked=True)
166
except errors.UnstackableBranchFormat:
167
if isinstance(self.branch_format, _mod_branch.BzrBranchFormat4):
168
raise tests.KnownFailure(
169
"Format 4 doesn't auto stack successfully.")
172
result = dir.open_branch()
173
self.assertEqual(revid, result.last_revision())
174
self.assertEqual(source.base, result.get_stacked_on_url())
175
# Smart servers invoke hooks on both sides
176
if isinstance(result, remote.RemoteBranch):
180
self.assertEqual(expected_calls, len(self.hook_calls))