1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
# Copyright (C) 2007 Canonical Ltd
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
"""Tests for Branch.sprout()"""
import os
from bzrlib import (
branch as _mod_branch,
remote,
revision as _mod_revision,
tests,
)
from bzrlib.tests import KnownFailure, SymlinkFeature, UnicodeFilenameFeature
from bzrlib.tests.branch_implementations import TestCaseWithBranch
class TestSprout(TestCaseWithBranch):
def test_sprout_branch_nickname(self):
# test the nick name is reset always
raise tests.TestSkipped('XXX branch sprouting is not yet tested.')
def test_sprout_branch_parent(self):
source = self.make_branch('source')
target = source.bzrdir.sprout(self.get_url('target')).open_branch()
self.assertEqual(source.bzrdir.root_transport.base, target.get_parent())
def test_sprout_uses_bzrdir_branch_format(self):
if isinstance(self.branch_format, _mod_branch.BranchReferenceFormat):
raise tests.TestNotApplicable('cannot sprout to a reference')
# Start with a format that is unlikely to be the target format
source = tests.TestCaseWithTransport.make_branch(self, 'old-branch',
format='metaweave')
target_bzrdir = self.make_bzrdir('target')
target_bzrdir.create_repository()
target = source.sprout(target_bzrdir)
self.assertIs(self.branch_format.__class__, target._format.__class__)
def test_sprout_partial(self):
# test sprouting with a prefix of the revision-history.
# also needs not-on-revision-history behaviour defined.
wt_a = self.make_branch_and_tree('a')
self.build_tree(['a/one'])
wt_a.add(['one'])
wt_a.commit('commit one', rev_id='1')
self.build_tree(['a/two'])
wt_a.add(['two'])
wt_a.commit('commit two', rev_id='2')
repo_b = self.make_repository('b')
repo_a = wt_a.branch.repository
repo_a.copy_content_into(repo_b)
br_b = wt_a.branch.sprout(repo_b.bzrdir, revision_id='1')
self.assertEqual('1', br_b.last_revision())
def test_sprout_partial_not_in_revision_history(self):
"""We should be able to sprout from any revision in ancestry."""
wt = self.make_branch_and_tree('source')
self.build_tree(['source/a'])
wt.add('a')
wt.commit('rev1', rev_id='rev1')
wt.commit('rev2-alt', rev_id='rev2-alt')
wt.set_parent_ids(['rev1'])
wt.branch.set_last_revision_info(1, 'rev1')
wt.commit('rev2', rev_id='rev2')
wt.set_parent_ids(['rev2', 'rev2-alt'])
wt.commit('rev3', rev_id='rev3')
repo = self.make_repository('target')
repo.fetch(wt.branch.repository)
branch2 = wt.branch.sprout(repo.bzrdir, revision_id='rev2-alt')
self.assertEqual((2, 'rev2-alt'), branch2.last_revision_info())
self.assertEqual(['rev1', 'rev2-alt'], branch2.revision_history())
def test_sprout_from_any_repo_revision(self):
"""We should be able to sprout from any revision."""
wt = self.make_branch_and_tree('source')
self.build_tree(['source/a'])
wt.add('a')
wt.commit('rev1a', rev_id='rev1a')
# simulated uncommit
wt.branch.set_last_revision_info(0, _mod_revision.NULL_REVISION)
wt.set_last_revision(_mod_revision.NULL_REVISION)
wt.revert()
wt.commit('rev1b', rev_id='rev1b')
wt2 = wt.bzrdir.sprout('target',
revision_id='rev1a').open_workingtree()
self.assertEqual('rev1a', wt2.last_revision())
self.failUnlessExists('target/a')
def test_sprout_with_unicode_symlink(self):
# this tests bug #272444
# Since the trigger function seems to be set_parent_trees, there exists
# also a similar test, with name test_unicode_symlink, in class
# TestSetParents at file workingtree_implementations/test_parents.py
self.requireFeature(SymlinkFeature)
self.requireFeature(UnicodeFilenameFeature)
tree = self.make_branch_and_tree('tree1')
# The link points to a file whose name is an omega
# U+03A9 GREEK CAPITAL LETTER OMEGA
# UTF-8: ce a9 UTF-16BE: 03a9 Decimal: Ω
os.symlink(u'\u03a9','tree1/link_name')
tree.add(['link_name'],['link-id'])
try:
# python 2.7a0 failed on commit:
revision = tree.commit('added a link to a Unicode target')
# python 2.5 failed on sprout:
tree.bzrdir.sprout('target')
except UnicodeEncodeError, e:
raise KnownFailure('there is no support for'
' symlinks to non-ASCII targets (bug #272444)')
|