bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
6404.6.1
by Vincent Ladeuil
Tests passing for a first rough version of a cached branch config store. The changes here are too invasive and several parallel proposals have been made. |
1 |
# Copyright (C) 2009-2012 Canonical Ltd
|
|
4044.1.1
by Robert Collins
Create Branch.create_clone_on_transport helper method to combine bzr and branch creation for push. |
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 |
||
|
6622.1.34
by Jelmer Vernooij
Rename brzlib => breezy. |
19 |
from breezy import ( |
|
5010.2.14
by Vincent Ladeuil
Fix imports in per_branch/test_create_clone.py. |
20 |
branch, |
21 |
errors, |
|
|
6670.4.14
by Jelmer Vernooij
Move remote to breezy.bzr. |
22 |
tests, |
23 |
)
|
|
24 |
from breezy.bzr import ( |
|
|
5010.2.14
by Vincent Ladeuil
Fix imports in per_branch/test_create_clone.py. |
25 |
remote, |
26 |
)
|
|
|
6622.1.34
by Jelmer Vernooij
Rename brzlib => breezy. |
27 |
from breezy.tests import per_branch |
|
5010.2.14
by Vincent Ladeuil
Fix imports in per_branch/test_create_clone.py. |
28 |
|
29 |
||
30 |
class TestCreateClone(per_branch.TestCaseWithBranch): |
|
|
4044.1.1
by Robert Collins
Create Branch.create_clone_on_transport helper method to combine bzr and branch creation for push. |
31 |
|
|
4294.2.1
by Robert Collins
Move directory checking for bzr push options into Branch.create_clone_on_transport. |
32 |
def test_create_clone_on_transport_missing_parent_dir(self): |
33 |
tree = self.make_branch_and_tree('source') |
|
34 |
tree.commit('a commit') |
|
35 |
source = tree.branch |
|
36 |
target_transport = self.get_transport('subdir').clone('target') |
|
|
4294.2.9
by Robert Collins
Fixup tests broken by cleaning up the layering. |
37 |
self.assertRaises(errors.NoSuchFile, |
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
38 |
tree.branch.create_clone_on_transport, target_transport) |
|
4294.2.1
by Robert Collins
Move directory checking for bzr push options into Branch.create_clone_on_transport. |
39 |
self.assertFalse(self.get_transport('.').has('subdir')) |
40 |
||
41 |
def test_create_clone_on_transport_missing_parent_dir_create(self): |
|
42 |
tree = self.make_branch_and_tree('source') |
|
43 |
tree.commit('a commit') |
|
44 |
source = tree.branch |
|
45 |
target_transport = self.get_transport('subdir').clone('target') |
|
46 |
result = tree.branch.create_clone_on_transport(target_transport, |
|
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
47 |
create_prefix=True) |
|
4294.2.1
by Robert Collins
Move directory checking for bzr push options into Branch.create_clone_on_transport. |
48 |
self.assertEqual(source.last_revision(), result.last_revision()) |
49 |
self.assertEqual(target_transport.base, |
|
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
50 |
result.controldir.root_transport.base) |
|
4294.2.1
by Robert Collins
Move directory checking for bzr push options into Branch.create_clone_on_transport. |
51 |
|
52 |
def test_create_clone_on_transport_use_existing_dir_false(self): |
|
53 |
tree = self.make_branch_and_tree('source') |
|
54 |
tree.commit('a commit') |
|
55 |
source = tree.branch |
|
56 |
target_transport = self.get_transport('target') |
|
57 |
target_transport.create_prefix() |
|
|
4294.2.9
by Robert Collins
Fixup tests broken by cleaning up the layering. |
58 |
self.assertRaises(errors.FileExists, |
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
59 |
tree.branch.create_clone_on_transport, target_transport) |
|
4294.2.1
by Robert Collins
Move directory checking for bzr push options into Branch.create_clone_on_transport. |
60 |
self.assertFalse(target_transport.has(".bzr")) |
61 |
||
62 |
def test_create_clone_on_transport_use_existing_dir_true(self): |
|
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, |
|
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
69 |
use_existing_dir=True) |
|
4294.2.1
by Robert Collins
Move directory checking for bzr push options into Branch.create_clone_on_transport. |
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): |
73 |
tree = self.make_branch_and_tree('source') |
|
74 |
tree.commit('a commit') |
|
75 |
source = tree.branch |
|
76 |
target_transport = self.get_transport('target') |
|
77 |
result = tree.branch.create_clone_on_transport(target_transport) |
|
78 |
self.assertEqual(source.last_revision(), result.last_revision()) |
|
79 |
||
80 |
def test_create_clone_on_transport_revision_id(self): |
|
81 |
tree = self.make_branch_and_tree('source') |
|
82 |
old_revid = tree.commit('a commit') |
|
83 |
source_tip = tree.commit('a second commit') |
|
84 |
source = tree.branch |
|
85 |
target_transport = self.get_transport('target') |
|
86 |
result = tree.branch.create_clone_on_transport(target_transport, |
|
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
87 |
revision_id=old_revid) |
|
4044.1.1
by Robert Collins
Create Branch.create_clone_on_transport helper method to combine bzr and branch creation for push. |
88 |
self.assertEqual(old_revid, result.last_revision()) |
89 |
result.lock_read() |
|
90 |
self.addCleanup(result.unlock) |
|
91 |
self.assertFalse(result.repository.has_revision(source_tip)) |
|
92 |
||
93 |
def test_create_clone_on_transport_stacked(self): |
|
94 |
tree = self.make_branch_and_tree('source') |
|
95 |
tree.commit('a commit') |
|
96 |
trunk = tree.branch.create_clone_on_transport( |
|
97 |
self.get_transport('trunk')) |
|
98 |
revid = tree.commit('a second commit') |
|
99 |
source = tree.branch |
|
100 |
target_transport = self.get_transport('target') |
|
|
6164.2.6
by Jelmer Vernooij
Non-stacking formats can also raise UnstackableRepositoryFormat. |
101 |
try: |
102 |
result = tree.branch.create_clone_on_transport(target_transport, |
|
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
103 |
stacked_on=trunk.base) |
|
6734.1.11
by Jelmer Vernooij
Move UnstackableBranchFormat. |
104 |
except branch.UnstackableBranchFormat: |
|
6164.2.7
by Jelmer Vernooij
Only accept UnstackableRepositoryFormat if the stacked_on does not support full versioned files |
105 |
if not trunk.repository._format.supports_full_versioned_files: |
106 |
raise tests.TestNotApplicable("can not stack on format") |
|
107 |
raise
|
|
|
4044.1.1
by Robert Collins
Create Branch.create_clone_on_transport helper method to combine bzr and branch creation for push. |
108 |
self.assertEqual(revid, result.last_revision()) |
109 |
self.assertEqual(trunk.base, result.get_stacked_on_url()) |
|
|
4053.2.2
by Andrew Bennetts
Better fix, with test. |
110 |
|
|
4053.2.3
by Andrew Bennetts
Fix some nits. |
111 |
def test_create_clone_of_multiple_roots(self): |
|
4053.2.2
by Andrew Bennetts
Better fix, with test. |
112 |
try: |
113 |
builder = self.make_branch_builder('local') |
|
114 |
except (errors.TransportNotPossible, errors.UninitializableFormat): |
|
115 |
raise tests.TestNotApplicable('format not directly constructable') |
|
116 |
builder.start_series() |
|
|
6816.2.1
by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument. |
117 |
rev1 = builder.build_snapshot(None, [ |
|
6883.22.13
by Jelmer Vernooij
Actually pass in None file-ids to BranchBuilder. |
118 |
('add', ('', None, 'directory', ''))]) |
|
6816.2.1
by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument. |
119 |
rev2 = builder.build_snapshot([rev1], []) |
120 |
other = builder.build_snapshot(None, [ |
|
|
6883.22.13
by Jelmer Vernooij
Actually pass in None file-ids to BranchBuilder. |
121 |
('add', ('', None, 'directory', ''))]) |
|
6816.2.1
by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument. |
122 |
rev3 = builder.build_snapshot([rev2, other], []) |
|
4053.2.2
by Andrew Bennetts
Better fix, with test. |
123 |
builder.finish_series() |
124 |
local = builder.get_branch() |
|
|
6747.4.2
by Jelmer Vernooij
Avoid setting revision ids in a few more places. |
125 |
local.controldir.clone(self.get_url('remote'), revision_id=rev3) |
|
4053.2.2
by Andrew Bennetts
Better fix, with test. |
126 |
|
|
4050.1.1
by Robert Collins
Fix race condition with branch hooks during cloning when the new branch is stacked. |
127 |
def assertBranchHookBranchIsStacked(self, pre_change_params): |
128 |
# Just calling will either succeed or fail.
|
|
129 |
pre_change_params.branch.get_stacked_on_url() |
|
130 |
self.hook_calls.append(pre_change_params) |
|
131 |
||
132 |
def test_create_clone_on_transport_stacked_hooks_get_stacked_branch(self): |
|
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 |
target_transport = self.get_transport('target') |
|
139 |
self.hook_calls = [] |
|
|
5010.2.14
by Vincent Ladeuil
Fix imports in per_branch/test_create_clone.py. |
140 |
branch.Branch.hooks.install_named_hook( |
141 |
'pre_change_branch_tip', self.assertBranchHookBranchIsStacked, None) |
|
|
6164.2.6
by Jelmer Vernooij
Non-stacking formats can also raise UnstackableRepositoryFormat. |
142 |
try: |
|
6989.3.4
by Jelmer Vernooij
Deal with unknown formats. |
143 |
result = tree.branch.create_clone_on_transport( |
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
144 |
target_transport, stacked_on=trunk.base) |
|
6734.1.11
by Jelmer Vernooij
Move UnstackableBranchFormat. |
145 |
except branch.UnstackableBranchFormat: |
|
6164.2.7
by Jelmer Vernooij
Only accept UnstackableRepositoryFormat if the stacked_on does not support full versioned files |
146 |
if not trunk.repository._format.supports_full_versioned_files: |
147 |
raise tests.TestNotApplicable("can not stack on format") |
|
148 |
raise
|
|
|
4050.1.1
by Robert Collins
Fix race condition with branch hooks during cloning when the new branch is stacked. |
149 |
self.assertEqual(revid, result.last_revision()) |
150 |
self.assertEqual(trunk.base, result.get_stacked_on_url()) |
|
151 |
# Smart servers invoke hooks on both sides
|
|
152 |
if isinstance(result, remote.RemoteBranch): |
|
153 |
expected_calls = 2 |
|
154 |
else: |
|
155 |
expected_calls = 1 |
|
156 |
self.assertEqual(expected_calls, len(self.hook_calls)) |