3380.1.4
by Aaron Bentley
Split interrepository fetch tests into their own file |
1 |
# Copyright (C) 2005, 2006, 2008 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
|
|
15 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
16 |
||
17 |
||
18 |
import sys |
|
19 |
||
20 |
import bzrlib |
|
21 |
from bzrlib import ( |
|
22 |
errors, |
|
23 |
repository, |
|
3380.1.6
by Aaron Bentley
Ensure fetching munges sha1s |
24 |
osutils, |
3380.1.4
by Aaron Bentley
Split interrepository fetch tests into their own file |
25 |
)
|
26 |
from bzrlib.errors import ( |
|
27 |
NoSuchRevision, |
|
28 |
)
|
|
29 |
from bzrlib.revision import ( |
|
30 |
NULL_REVISION, |
|
31 |
Revision, |
|
32 |
)
|
|
33 |
from bzrlib.tests import ( |
|
34 |
TestNotApplicable, |
|
35 |
)
|
|
36 |
from bzrlib.tests.interrepository_implementations import ( |
|
37 |
TestCaseWithInterRepository, |
|
38 |
)
|
|
3616.2.3
by Mark Hammond
Fix test failures due to missing check_repo_format_for_funky_id_on_win32 |
39 |
from bzrlib.tests.interrepository_implementations.test_interrepository import ( |
40 |
check_repo_format_for_funky_id_on_win32
|
|
41 |
)
|
|
3380.1.4
by Aaron Bentley
Split interrepository fetch tests into their own file |
42 |
|
43 |
||
44 |
class TestInterRepository(TestCaseWithInterRepository): |
|
45 |
||
46 |
def test_fetch(self): |
|
47 |
tree_a = self.make_branch_and_tree('a') |
|
48 |
self.build_tree(['a/foo']) |
|
49 |
tree_a.add('foo', 'file1') |
|
50 |
tree_a.commit('rev1', rev_id='rev1') |
|
51 |
def check_push_rev1(repo): |
|
52 |
# ensure the revision is missing.
|
|
53 |
self.assertRaises(NoSuchRevision, repo.get_revision, 'rev1') |
|
54 |
# fetch with a limit of NULL_REVISION and an explicit progress bar.
|
|
55 |
repo.fetch(tree_a.branch.repository, |
|
56 |
revision_id=NULL_REVISION, |
|
57 |
pb=bzrlib.progress.DummyProgress()) |
|
58 |
# nothing should have been pushed
|
|
59 |
self.assertFalse(repo.has_revision('rev1')) |
|
60 |
# fetch with a default limit (grab everything)
|
|
61 |
repo.fetch(tree_a.branch.repository) |
|
62 |
# check that b now has all the data from a's first commit.
|
|
63 |
rev = repo.get_revision('rev1') |
|
64 |
tree = repo.revision_tree('rev1') |
|
65 |
tree.lock_read() |
|
66 |
self.addCleanup(tree.unlock) |
|
67 |
tree.get_file_text('file1') |
|
68 |
for file_id in tree: |
|
69 |
if tree.inventory[file_id].kind == "file": |
|
70 |
tree.get_file(file_id).read() |
|
71 |
||
72 |
# makes a target version repo
|
|
73 |
repo_b = self.make_to_repository('b') |
|
74 |
check_push_rev1(repo_b) |
|
75 |
||
76 |
def test_fetch_missing_basis_text(self): |
|
77 |
"""If fetching a delta, we should die if a basis is not present."""
|
|
78 |
tree = self.make_branch_and_tree('tree') |
|
79 |
self.build_tree(['tree/a']) |
|
80 |
tree.add(['a'], ['a-id']) |
|
81 |
tree.commit('one', rev_id='rev-one') |
|
82 |
self.build_tree_contents([('tree/a', 'new contents\n')]) |
|
83 |
tree.commit('two', rev_id='rev-two') |
|
84 |
||
85 |
to_repo = self.make_to_repository('to_repo') |
|
86 |
# We build a broken revision so that we can test the fetch code dies
|
|
87 |
# properly. So copy the inventory and revision, but not the text.
|
|
88 |
to_repo.lock_write() |
|
89 |
try: |
|
90 |
to_repo.start_write_group() |
|
91 |
inv = tree.branch.repository.get_inventory('rev-one') |
|
92 |
to_repo.add_inventory('rev-one', inv, []) |
|
93 |
rev = tree.branch.repository.get_revision('rev-one') |
|
94 |
to_repo.add_revision('rev-one', rev, inv=inv) |
|
95 |
to_repo.commit_write_group() |
|
96 |
finally: |
|
97 |
to_repo.unlock() |
|
98 |
||
3350.3.21
by Robert Collins
Merge bzr.dev. |
99 |
# Implementations can either ensure that the target of the delta is
|
100 |
# reconstructable, or raise an exception (which stream based copies
|
|
101 |
# generally do).
|
|
3380.1.4
by Aaron Bentley
Split interrepository fetch tests into their own file |
102 |
try: |
103 |
to_repo.fetch(tree.branch.repository, 'rev-two') |
|
104 |
except errors.RevisionNotPresent, e: |
|
105 |
# If an exception is raised, the revision should not be in the
|
|
106 |
# target.
|
|
3350.3.21
by Robert Collins
Merge bzr.dev. |
107 |
self.assertRaises((errors.NoSuchRevision, errors.RevisionNotPresent), |
108 |
to_repo.revision_tree, 'rev-two') |
|
3380.1.4
by Aaron Bentley
Split interrepository fetch tests into their own file |
109 |
else: |
3350.3.21
by Robert Collins
Merge bzr.dev. |
110 |
# If not exception is raised, then the text should be
|
3380.1.4
by Aaron Bentley
Split interrepository fetch tests into their own file |
111 |
# available.
|
112 |
to_repo.lock_read() |
|
113 |
try: |
|
3350.3.21
by Robert Collins
Merge bzr.dev. |
114 |
rt = to_repo.revision_tree('rev-two') |
115 |
self.assertEqual('new contents\n', |
|
3380.1.4
by Aaron Bentley
Split interrepository fetch tests into their own file |
116 |
rt.get_file_text('a-id')) |
117 |
finally: |
|
118 |
to_repo.unlock() |
|
119 |
||
120 |
def test_fetch_missing_revision_same_location_fails(self): |
|
121 |
repo_a = self.make_repository('.') |
|
122 |
repo_b = repository.Repository.open('.') |
|
123 |
try: |
|
3350.3.21
by Robert Collins
Merge bzr.dev. |
124 |
self.assertRaises(errors.NoSuchRevision, repo_b.fetch, repo_a, revision_id='XXX') |
3380.1.4
by Aaron Bentley
Split interrepository fetch tests into their own file |
125 |
except errors.LockError, e: |
126 |
check_old_format_lock_error(self.repository_format) |
|
127 |
||
128 |
def test_fetch_same_location_trivial_works(self): |
|
129 |
repo_a = self.make_repository('.') |
|
130 |
repo_b = repository.Repository.open('.') |
|
131 |
try: |
|
132 |
repo_a.fetch(repo_b) |
|
133 |
except errors.LockError, e: |
|
134 |
check_old_format_lock_error(self.repository_format) |
|
135 |
||
136 |
def test_fetch_missing_text_other_location_fails(self): |
|
137 |
source_tree = self.make_branch_and_tree('source') |
|
138 |
source = source_tree.branch.repository |
|
139 |
target = self.make_to_repository('target') |
|
140 |
||
141 |
# start by adding a file so the data knit for the file exists in
|
|
142 |
# repositories that have specific files for each fileid.
|
|
143 |
self.build_tree(['source/id']) |
|
144 |
source_tree.add(['id'], ['id']) |
|
145 |
source_tree.commit('a', rev_id='a') |
|
146 |
# now we manually insert a revision with an inventory referencing
|
|
147 |
# 'id' at revision 'b', but we do not insert revision b.
|
|
148 |
# this should ensure that the new versions of files are being checked
|
|
149 |
# for during pull operations
|
|
150 |
inv = source.get_inventory('a') |
|
151 |
source.lock_write() |
|
3380.1.5
by Aaron Bentley
Merge with make-it-work |
152 |
self.addCleanup(source.unlock) |
3380.1.4
by Aaron Bentley
Split interrepository fetch tests into their own file |
153 |
source.start_write_group() |
154 |
inv['id'].revision = 'b' |
|
155 |
inv.revision_id = 'b' |
|
156 |
sha1 = source.add_inventory('b', inv, ['a']) |
|
157 |
rev = Revision(timestamp=0, |
|
158 |
timezone=None, |
|
159 |
committer="Foo Bar <foo@example.com>", |
|
160 |
message="Message", |
|
161 |
inventory_sha1=sha1, |
|
162 |
revision_id='b') |
|
163 |
rev.parent_ids = ['a'] |
|
164 |
source.add_revision('b', rev) |
|
165 |
source.commit_write_group() |
|
166 |
self.assertRaises(errors.RevisionNotPresent, target.fetch, source) |
|
167 |
self.assertFalse(target.has_revision('b')) |
|
168 |
||
169 |
def test_fetch_funky_file_id(self): |
|
170 |
from_tree = self.make_branch_and_tree('tree') |
|
171 |
if sys.platform == 'win32': |
|
172 |
from_repo = from_tree.branch.repository |
|
173 |
check_repo_format_for_funky_id_on_win32(from_repo) |
|
174 |
self.build_tree(['tree/filename']) |
|
175 |
from_tree.add('filename', 'funky-chars<>%&;"\'') |
|
176 |
from_tree.commit('commit filename') |
|
177 |
to_repo = self.make_to_repository('to') |
|
3350.3.21
by Robert Collins
Merge bzr.dev. |
178 |
to_repo.fetch(from_tree.branch.repository, from_tree.get_parent_ids()[0]) |
3380.1.4
by Aaron Bentley
Split interrepository fetch tests into their own file |
179 |
|
3380.1.6
by Aaron Bentley
Ensure fetching munges sha1s |
180 |
def test_fetch_revision_hash(self): |
181 |
"""Ensure that inventory hashes are updated by fetch"""
|
|
182 |
from_tree = self.make_branch_and_tree('tree') |
|
183 |
from_tree.commit('foo', rev_id='foo-id') |
|
184 |
to_repo = self.make_to_repository('to') |
|
185 |
to_repo.fetch(from_tree.branch.repository) |
|
186 |
recorded_inv_sha1 = to_repo.get_inventory_sha1('foo-id') |
|
187 |
xml = to_repo.get_inventory_xml('foo-id') |
|
188 |
computed_inv_sha1 = osutils.sha_string(xml) |
|
189 |
self.assertEqual(computed_inv_sha1, recorded_inv_sha1) |
|
190 |
||
3380.1.4
by Aaron Bentley
Split interrepository fetch tests into their own file |
191 |
|
192 |
class TestFetchDependentData(TestCaseWithInterRepository): |
|
193 |
||
194 |
def test_reference(self): |
|
195 |
from_tree = self.make_branch_and_tree('tree') |
|
196 |
to_repo = self.make_to_repository('to') |
|
197 |
if (not from_tree.supports_tree_reference() or |
|
198 |
not from_tree.branch.repository._format.supports_tree_reference or |
|
199 |
not to_repo._format.supports_tree_reference): |
|
200 |
raise TestNotApplicable("Need subtree support.") |
|
201 |
subtree = self.make_branch_and_tree('tree/subtree') |
|
202 |
subtree.commit('subrev 1') |
|
203 |
from_tree.add_reference(subtree) |
|
204 |
tree_rev = from_tree.commit('foo') |
|
205 |
# now from_tree has a last-modified of subtree of the rev id of the
|
|
206 |
# commit for foo, and a reference revision of the rev id of the commit
|
|
207 |
# for subrev 1
|
|
208 |
to_repo.fetch(from_tree.branch.repository, tree_rev) |
|
209 |
# to_repo should have a file_graph for from_tree.path2id('subtree') and
|
|
210 |
# revid tree_rev.
|
|
3350.6.4
by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores. |
211 |
file_id = from_tree.path2id('subtree') |
3380.1.4
by Aaron Bentley
Split interrepository fetch tests into their own file |
212 |
to_repo.lock_read() |
213 |
try: |
|
3350.6.4
by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores. |
214 |
self.assertEqual({(file_id, tree_rev):()}, |
215 |
to_repo.texts.get_parent_map([(file_id, tree_rev)])) |
|
3380.1.4
by Aaron Bentley
Split interrepository fetch tests into their own file |
216 |
finally: |
217 |
to_repo.unlock() |