2524.1.1
by Aaron Bentley
Revert broken changes |
1 |
# Copyright (C) 2007 Canonical Ltd
|
2 |
#
|
|
3 |
# This program is free software; you can redistribute it and/or modify
|
|
4 |
# it under the terms of the GNU General Public License as published by
|
|
5 |
# the Free Software Foundation; either version 2 of the License, or
|
|
6 |
# (at your option) any later version.
|
|
7 |
#
|
|
8 |
# This program is distributed in the hope that it will be useful,
|
|
9 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
11 |
# GNU General Public License for more details.
|
|
12 |
#
|
|
13 |
# You should have received a copy of the GNU General Public License
|
|
14 |
# along with this program; if not, write to the Free Software
|
|
4183.7.1
by Sabin Iacob
update FSF mailing address |
15 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2524.1.1
by Aaron Bentley
Revert broken changes |
16 |
|
17 |
"""Tests for Branch.sprout()"""
|
|
18 |
||
3763.9.4
by Daniel Clemente
New test for utf-8 symlinks in BzrDir.sprout |
19 |
import os |
2524.1.1
by Aaron Bentley
Revert broken changes |
20 |
from bzrlib import ( |
3834.5.1
by Andrew Bennetts
Improve test_sprout. |
21 |
branch as _mod_branch, |
4070.3.1
by Robert Collins
Alter branch sprouting with an alternate fix for stacked branches that does not require multiple copy_content_into and set_parent calls, reducing IO and round trips. |
22 |
errors, |
4241.14.12
by Vincent Ladeuil
Far too many modifications for a single commit, need to restart. |
23 |
osutils, |
2524.1.1
by Aaron Bentley
Revert broken changes |
24 |
remote, |
2487.2.4
by Aaron Bentley
Add test to ensure we can branch from repository revisions |
25 |
revision as _mod_revision, |
2524.1.1
by Aaron Bentley
Revert broken changes |
26 |
tests, |
27 |
)
|
|
4523.1.1
by Martin Pool
Rename tests.branch_implementations to per_branch |
28 |
from bzrlib.tests.per_branch import TestCaseWithBranch |
2524.1.1
by Aaron Bentley
Revert broken changes |
29 |
|
30 |
||
31 |
class TestSprout(TestCaseWithBranch): |
|
32 |
||
33 |
def test_sprout_branch_nickname(self): |
|
34 |
# test the nick name is reset always
|
|
2949.5.1
by Alexander Belchenko
selftest: use SymlinkFeature instead of TestSkipped where appropriate |
35 |
raise tests.TestSkipped('XXX branch sprouting is not yet tested.') |
2524.1.1
by Aaron Bentley
Revert broken changes |
36 |
|
37 |
def test_sprout_branch_parent(self): |
|
38 |
source = self.make_branch('source') |
|
39 |
target = source.bzrdir.sprout(self.get_url('target')).open_branch() |
|
40 |
self.assertEqual(source.bzrdir.root_transport.base, target.get_parent()) |
|
41 |
||
3834.5.2
by John Arbash Meinel
Track down the various BranchFormats that weren't setting the branch format as part of the _matchingbzrdir format. |
42 |
def test_sprout_uses_bzrdir_branch_format(self): |
4005.2.1
by Robert Collins
Fix RemoteBranch to be used correctly in tests using bzr+ssh, to fire off Branch hooks correctly, and improve the branch_implementations tests to check that making a branch gets the right format under test. |
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).
|
|
3834.5.1
by Andrew Bennetts
Improve test_sprout. |
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
|
|
4005.2.1
by Robert Collins
Fix RemoteBranch to be used correctly in tests using bzr+ssh, to fire off Branch hooks correctly, and improve the branch_implementations tests to check that making a branch gets the right format under test. |
54 |
# We call the super class to allow overriding the format of creation)
|
3834.5.1
by Andrew Bennetts
Improve test_sprout. |
55 |
source = tests.TestCaseWithTransport.make_branch(self, 'old-branch', |
56 |
format='metaweave') |
|
3834.5.2
by John Arbash Meinel
Track down the various BranchFormats that weren't setting the branch format as part of the _matchingbzrdir format. |
57 |
target_bzrdir = self.make_bzrdir('target') |
58 |
target_bzrdir.create_repository() |
|
4005.2.1
by Robert Collins
Fix RemoteBranch to be used correctly in tests using bzr+ssh, to fire off Branch hooks correctly, and improve the branch_implementations tests to check that making a branch gets the right format under test. |
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() |
|
3834.5.1
by Andrew Bennetts
Improve test_sprout. |
68 |
target = source.sprout(target_bzrdir) |
4005.2.1
by Robert Collins
Fix RemoteBranch to be used correctly in tests using bzr+ssh, to fire off Branch hooks correctly, and improve the branch_implementations tests to check that making a branch gets the right format under test. |
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 |
|
4032.3.2
by Robert Collins
Create and use a RPC call to create branches on bzr servers rather than using VFS calls. |
74 |
if isinstance(result_format, remote.RemoteBranchFormat): |
75 |
# Unwrap a parameterised RemoteBranchFormat for comparison.
|
|
76 |
result_format = result_format._custom_format |
|
4005.2.1
by Robert Collins
Fix RemoteBranch to be used correctly in tests using bzr+ssh, to fire off Branch hooks correctly, and improve the branch_implementations tests to check that making a branch gets the right format under test. |
77 |
self.assertIs(result_format.__class__, target._format.__class__) |
2524.1.1
by Aaron Bentley
Revert broken changes |
78 |
|
79 |
def test_sprout_partial(self): |
|
80 |
# test sprouting with a prefix of the revision-history.
|
|
81 |
# also needs not-on-revision-history behaviour defined.
|
|
82 |
wt_a = self.make_branch_and_tree('a') |
|
83 |
self.build_tree(['a/one']) |
|
84 |
wt_a.add(['one']) |
|
85 |
wt_a.commit('commit one', rev_id='1') |
|
86 |
self.build_tree(['a/two']) |
|
87 |
wt_a.add(['two']) |
|
88 |
wt_a.commit('commit two', rev_id='2') |
|
89 |
repo_b = self.make_repository('b') |
|
90 |
repo_a = wt_a.branch.repository |
|
91 |
repo_a.copy_content_into(repo_b) |
|
92 |
br_b = wt_a.branch.sprout(repo_b.bzrdir, revision_id='1') |
|
93 |
self.assertEqual('1', br_b.last_revision()) |
|
94 |
||
95 |
def test_sprout_partial_not_in_revision_history(self): |
|
96 |
"""We should be able to sprout from any revision in ancestry."""
|
|
97 |
wt = self.make_branch_and_tree('source') |
|
98 |
self.build_tree(['source/a']) |
|
99 |
wt.add('a') |
|
100 |
wt.commit('rev1', rev_id='rev1') |
|
101 |
wt.commit('rev2-alt', rev_id='rev2-alt') |
|
102 |
wt.set_parent_ids(['rev1']) |
|
103 |
wt.branch.set_last_revision_info(1, 'rev1') |
|
104 |
wt.commit('rev2', rev_id='rev2') |
|
105 |
wt.set_parent_ids(['rev2', 'rev2-alt']) |
|
106 |
wt.commit('rev3', rev_id='rev3') |
|
107 |
||
108 |
repo = self.make_repository('target') |
|
109 |
repo.fetch(wt.branch.repository) |
|
110 |
branch2 = wt.branch.sprout(repo.bzrdir, revision_id='rev2-alt') |
|
111 |
self.assertEqual((2, 'rev2-alt'), branch2.last_revision_info()) |
|
112 |
self.assertEqual(['rev1', 'rev2-alt'], branch2.revision_history()) |
|
2487.2.4
by Aaron Bentley
Add test to ensure we can branch from repository revisions |
113 |
|
114 |
def test_sprout_from_any_repo_revision(self): |
|
115 |
"""We should be able to sprout from any revision."""
|
|
116 |
wt = self.make_branch_and_tree('source') |
|
117 |
self.build_tree(['source/a']) |
|
118 |
wt.add('a') |
|
119 |
wt.commit('rev1a', rev_id='rev1a') |
|
120 |
# simulated uncommit
|
|
121 |
wt.branch.set_last_revision_info(0, _mod_revision.NULL_REVISION) |
|
2598.5.3
by Aaron Bentley
Push NULL_REVISION deeper |
122 |
wt.set_last_revision(_mod_revision.NULL_REVISION) |
2796.1.4
by Aaron Bentley
Fix up various test cases |
123 |
wt.revert() |
2487.2.4
by Aaron Bentley
Add test to ensure we can branch from repository revisions |
124 |
wt.commit('rev1b', rev_id='rev1b') |
125 |
wt2 = wt.bzrdir.sprout('target', |
|
126 |
revision_id='rev1a').open_workingtree() |
|
127 |
self.assertEqual('rev1a', wt2.last_revision()) |
|
128 |
self.failUnlessExists('target/a') |
|
3763.9.4
by Daniel Clemente
New test for utf-8 symlinks in BzrDir.sprout |
129 |
|
3763.9.7
by Daniel Clemente
Tested Unicode target rather than always trying to create it in UTF-8. Test renamed |
130 |
def test_sprout_with_unicode_symlink(self): |
3763.9.8
by Daniel Clemente
Broken lines, and prepended # before bug numbers |
131 |
# this tests bug #272444
|
3763.9.11
by Daniel Clemente
More detailed comment and in broken line |
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
|
|
4523.1.4
by Martin Pool
Rename remaining *_implementations tests |
134 |
# TestSetParents at file per_workingtree/test_parents.py
|
4095.3.4
by Vincent Ladeuil
Some trivial cleanups, related to fix for bug #272444. |
135 |
self.requireFeature(tests.SymlinkFeature) |
136 |
self.requireFeature(tests.UnicodeFilenameFeature) |
|
3763.9.4
by Daniel Clemente
New test for utf-8 symlinks in BzrDir.sprout |
137 |
|
138 |
tree = self.make_branch_and_tree('tree1') |
|
139 |
||
3763.9.9
by Daniel Clemente
Used a greek omega instead of an accented 'o' to avoid combining characters |
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: Ω
|
|
4241.14.12
by Vincent Ladeuil
Far too many modifications for a single commit, need to restart. |
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']) |
|
3763.9.4
by Daniel Clemente
New test for utf-8 symlinks in BzrDir.sprout |
147 |
|
4095.3.1
by Vincent Ladeuil
Fix #339055 and #277444 by handling non ascii symlink targets. |
148 |
revision = tree.commit('added a link to a Unicode target') |
4241.14.12
by Vincent Ladeuil
Far too many modifications for a single commit, need to restart. |
149 |
tree.bzrdir.sprout('dest') |
4241.14.23
by Vincent Ladeuil
NEWS entry and final cleanup before submission. |
150 |
self.assertEqual(target, osutils.readlink('dest/' + link_name)) |
4241.14.12
by Vincent Ladeuil
Far too many modifications for a single commit, need to restart. |
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')) |
|
3763.9.4
by Daniel Clemente
New test for utf-8 symlinks in BzrDir.sprout |
157 |
|
4266.3.6
by Jelmer Vernooij
Add test for handling ghosts in Branch._synchronize_history if the revision that's being cloned is not the tip. |
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 |
||
4070.3.1
by Robert Collins
Alter branch sprouting with an alternate fix for stacked branches that does not require multiple copy_content_into and set_parent calls, reducing IO and round trips. |
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): |
|
4095.3.4
by Vincent Ladeuil
Some trivial cleanups, related to fix for bug #272444. |
186 |
raise tests.KnownFailure( |
187 |
"Format 4 doesn't auto stack successfully.") |
|
4070.3.1
by Robert Collins
Alter branch sprouting with an alternate fix for stacked branches that does not require multiple copy_content_into and set_parent calls, reducing IO and round trips. |
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 |