bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
4044.1.1
by Robert Collins
Create Branch.create_clone_on_transport helper method to combine bzr and branch creation for push. |
1 |
# Copyright (C) 2009 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
|
|
4044.1.1
by Robert Collins
Create Branch.create_clone_on_transport helper method to combine bzr and branch creation for push. |
16 |
|
17 |
"""Tests for branch.create_clone behaviour."""
|
|
18 |
||
|
4050.1.1
by Robert Collins
Fix race condition with branch hooks during cloning when the new branch is stacked. |
19 |
from bzrlib.branch import Branch |
|
4053.2.2
by Andrew Bennetts
Better fix, with test. |
20 |
from bzrlib import errors |
|
4053.2.5
by Andrew Bennetts
Merge from bzr.dev. |
21 |
from bzrlib import remote |
|
4053.2.2
by Andrew Bennetts
Better fix, with test. |
22 |
from bzrlib import tests |
|
4523.1.1
by Martin Pool
Rename tests.branch_implementations to per_branch |
23 |
from bzrlib.tests.per_branch.test_branch import TestCaseWithBranch |
|
4044.1.1
by Robert Collins
Create Branch.create_clone_on_transport helper method to combine bzr and branch creation for push. |
24 |
|
25 |
||
26 |
class TestCreateClone(TestCaseWithBranch): |
|
27 |
||
|
4294.2.1
by Robert Collins
Move directory checking for bzr push options into Branch.create_clone_on_transport. |
28 |
def test_create_clone_on_transport_missing_parent_dir(self): |
|
4523.4.15
by John Arbash Meinel
First pass at marking tests that are known to fail. |
29 |
self.thisFailsStrictLockCheck() |
|
4294.2.1
by Robert Collins
Move directory checking for bzr push options into Branch.create_clone_on_transport. |
30 |
tree = self.make_branch_and_tree('source') |
31 |
tree.commit('a commit') |
|
32 |
source = tree.branch |
|
33 |
target_transport = self.get_transport('subdir').clone('target') |
|
|
4294.2.9
by Robert Collins
Fixup tests broken by cleaning up the layering. |
34 |
self.assertRaises(errors.NoSuchFile, |
|
4294.2.1
by Robert Collins
Move directory checking for bzr push options into Branch.create_clone_on_transport. |
35 |
tree.branch.create_clone_on_transport, target_transport) |
36 |
self.assertFalse(self.get_transport('.').has('subdir')) |
|
37 |
||
38 |
def test_create_clone_on_transport_missing_parent_dir_create(self): |
|
|
4523.4.15
by John Arbash Meinel
First pass at marking tests that are known to fail. |
39 |
self.thisFailsStrictLockCheck() |
|
4294.2.1
by Robert Collins
Move directory checking for bzr push options into Branch.create_clone_on_transport. |
40 |
tree = self.make_branch_and_tree('source') |
41 |
tree.commit('a commit') |
|
42 |
source = tree.branch |
|
43 |
target_transport = self.get_transport('subdir').clone('target') |
|
44 |
result = tree.branch.create_clone_on_transport(target_transport, |
|
45 |
create_prefix=True) |
|
46 |
self.assertEqual(source.last_revision(), result.last_revision()) |
|
47 |
self.assertEqual(target_transport.base, |
|
48 |
result.bzrdir.root_transport.base) |
|
49 |
||
50 |
def test_create_clone_on_transport_use_existing_dir_false(self): |
|
|
4523.4.15
by John Arbash Meinel
First pass at marking tests that are known to fail. |
51 |
self.thisFailsStrictLockCheck() |
|
4294.2.1
by Robert Collins
Move directory checking for bzr push options into Branch.create_clone_on_transport. |
52 |
tree = self.make_branch_and_tree('source') |
53 |
tree.commit('a commit') |
|
54 |
source = tree.branch |
|
55 |
target_transport = self.get_transport('target') |
|
56 |
target_transport.create_prefix() |
|
|
4294.2.9
by Robert Collins
Fixup tests broken by cleaning up the layering. |
57 |
self.assertRaises(errors.FileExists, |
|
4294.2.1
by Robert Collins
Move directory checking for bzr push options into Branch.create_clone_on_transport. |
58 |
tree.branch.create_clone_on_transport, target_transport) |
59 |
self.assertFalse(target_transport.has(".bzr")) |
|
60 |
||
61 |
def test_create_clone_on_transport_use_existing_dir_true(self): |
|
|
4523.4.15
by John Arbash Meinel
First pass at marking tests that are known to fail. |
62 |
self.thisFailsStrictLockCheck() |
|
4294.2.1
by Robert Collins
Move directory checking for bzr push options into Branch.create_clone_on_transport. |
63 |
tree = self.make_branch_and_tree('source') |
64 |
tree.commit('a commit') |
|
65 |
source = tree.branch |
|
66 |
target_transport = self.get_transport('target') |
|
67 |
target_transport.create_prefix() |
|
68 |
result = tree.branch.create_clone_on_transport(target_transport, |
|
69 |
use_existing_dir=True) |
|
70 |
self.assertEqual(source.last_revision(), result.last_revision()) |
|
71 |
||
|
4044.1.1
by Robert Collins
Create Branch.create_clone_on_transport helper method to combine bzr and branch creation for push. |
72 |
def test_create_clone_on_transport_no_revision_id(self): |
|
4523.4.15
by John Arbash Meinel
First pass at marking tests that are known to fail. |
73 |
self.thisFailsStrictLockCheck() |
|
4044.1.1
by Robert Collins
Create Branch.create_clone_on_transport helper method to combine bzr and branch creation for push. |
74 |
tree = self.make_branch_and_tree('source') |
75 |
tree.commit('a commit') |
|
76 |
source = tree.branch |
|
77 |
target_transport = self.get_transport('target') |
|
78 |
result = tree.branch.create_clone_on_transport(target_transport) |
|
79 |
self.assertEqual(source.last_revision(), result.last_revision()) |
|
80 |
||
81 |
def test_create_clone_on_transport_revision_id(self): |
|
|
4523.4.15
by John Arbash Meinel
First pass at marking tests that are known to fail. |
82 |
self.thisFailsStrictLockCheck() |
|
4044.1.1
by Robert Collins
Create Branch.create_clone_on_transport helper method to combine bzr and branch creation for push. |
83 |
tree = self.make_branch_and_tree('source') |
84 |
old_revid = tree.commit('a commit') |
|
85 |
source_tip = tree.commit('a second commit') |
|
86 |
source = tree.branch |
|
87 |
target_transport = self.get_transport('target') |
|
88 |
result = tree.branch.create_clone_on_transport(target_transport, |
|
89 |
revision_id=old_revid) |
|
90 |
self.assertEqual(old_revid, result.last_revision()) |
|
91 |
result.lock_read() |
|
92 |
self.addCleanup(result.unlock) |
|
93 |
self.assertFalse(result.repository.has_revision(source_tip)) |
|
94 |
||
95 |
def test_create_clone_on_transport_stacked(self): |
|
|
4523.4.15
by John Arbash Meinel
First pass at marking tests that are known to fail. |
96 |
self.thisFailsStrictLockCheck() |
|
4044.1.1
by Robert Collins
Create Branch.create_clone_on_transport helper method to combine bzr and branch creation for push. |
97 |
tree = self.make_branch_and_tree('source') |
98 |
tree.commit('a commit') |
|
99 |
trunk = tree.branch.create_clone_on_transport( |
|
100 |
self.get_transport('trunk')) |
|
101 |
revid = tree.commit('a second commit') |
|
102 |
source = tree.branch |
|
103 |
target_transport = self.get_transport('target') |
|
104 |
result = tree.branch.create_clone_on_transport(target_transport, |
|
105 |
stacked_on=trunk.base) |
|
106 |
self.assertEqual(revid, result.last_revision()) |
|
107 |
self.assertEqual(trunk.base, result.get_stacked_on_url()) |
|
|
4053.2.2
by Andrew Bennetts
Better fix, with test. |
108 |
|
|
4053.2.3
by Andrew Bennetts
Fix some nits. |
109 |
def test_create_clone_of_multiple_roots(self): |
|
4523.4.15
by John Arbash Meinel
First pass at marking tests that are known to fail. |
110 |
self.thisFailsStrictLockCheck() |
|
4053.2.2
by Andrew Bennetts
Better fix, with test. |
111 |
try: |
112 |
builder = self.make_branch_builder('local') |
|
113 |
except (errors.TransportNotPossible, errors.UninitializableFormat): |
|
114 |
raise tests.TestNotApplicable('format not directly constructable') |
|
115 |
builder.start_series() |
|
116 |
builder.build_snapshot('rev1', None, [ |
|
117 |
('add', ('', 'root-id', 'directory', ''))]) |
|
118 |
builder.build_snapshot('rev2', ['rev1'], []) |
|
119 |
builder.build_snapshot('other', None, [ |
|
120 |
('add', ('', 'root-id', 'directory', ''))]) |
|
121 |
builder.build_snapshot('rev3', ['rev2', 'other'], []) |
|
122 |
builder.finish_series() |
|
123 |
local = builder.get_branch() |
|
124 |
local.bzrdir.clone(self.get_url('remote'), revision_id='rev3') |
|
125 |
||
|
4050.1.1
by Robert Collins
Fix race condition with branch hooks during cloning when the new branch is stacked. |
126 |
def assertBranchHookBranchIsStacked(self, pre_change_params): |
127 |
# Just calling will either succeed or fail.
|
|
128 |
pre_change_params.branch.get_stacked_on_url() |
|
129 |
self.hook_calls.append(pre_change_params) |
|
130 |
||
131 |
def test_create_clone_on_transport_stacked_hooks_get_stacked_branch(self): |
|
|
4523.4.15
by John Arbash Meinel
First pass at marking tests that are known to fail. |
132 |
self.thisFailsStrictLockCheck() |
|
4050.1.1
by Robert Collins
Fix race condition with branch hooks during cloning when the new branch is stacked. |
133 |
tree = self.make_branch_and_tree('source') |
134 |
tree.commit('a commit') |
|
135 |
trunk = tree.branch.create_clone_on_transport( |
|
136 |
self.get_transport('trunk')) |
|
137 |
revid = tree.commit('a second commit') |
|
138 |
source = tree.branch |
|
139 |
target_transport = self.get_transport('target') |
|
140 |
self.hook_calls = [] |
|
141 |
Branch.hooks.install_named_hook("pre_change_branch_tip", |
|
142 |
self.assertBranchHookBranchIsStacked, None) |
|
143 |
result = tree.branch.create_clone_on_transport(target_transport, |
|
144 |
stacked_on=trunk.base) |
|
145 |
self.assertEqual(revid, result.last_revision()) |
|
146 |
self.assertEqual(trunk.base, result.get_stacked_on_url()) |
|
147 |
# Smart servers invoke hooks on both sides
|
|
148 |
if isinstance(result, remote.RemoteBranch): |
|
149 |
expected_calls = 2 |
|
150 |
else: |
|
151 |
expected_calls = 1 |
|
152 |
self.assertEqual(expected_calls, len(self.hook_calls)) |