2696.3.2
by Martin Pool
Move some per-repository tests from big test_repository to test_fetch |
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
|
2696.3.2
by Martin Pool
Move some per-repository tests from big test_repository to test_fetch |
16 |
|
17 |
"""Tests for fetch between repositories of the same type."""
|
|
18 |
||
19 |
from bzrlib import ( |
|
20 |
bzrdir, |
|
21 |
errors, |
|
2696.3.10
by Martin Pool
Add missing import |
22 |
gpg, |
2948.3.1
by John Arbash Meinel
Fix bug #158333, make sure that Repository.fetch(self) is properly a no-op for all Repository implementations. |
23 |
repository, |
2696.3.2
by Martin Pool
Move some per-repository tests from big test_repository to test_fetch |
24 |
)
|
25 |
from bzrlib.tests import TestSkipped |
|
3689.1.1
by John Arbash Meinel
Rename repository_implementations tests into per_repository tests |
26 |
from bzrlib.tests.per_repository import TestCaseWithRepository |
2696.3.2
by Martin Pool
Move some per-repository tests from big test_repository to test_fetch |
27 |
from bzrlib.transport import get_transport |
28 |
||
29 |
||
30 |
class TestFetchSameRepository(TestCaseWithRepository): |
|
31 |
||
32 |
def test_fetch(self): |
|
33 |
# smoke test fetch to ensure that the convenience function works.
|
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
34 |
# it is defined as a convenience function with the underlying
|
2696.3.2
by Martin Pool
Move some per-repository tests from big test_repository to test_fetch |
35 |
# functionality provided by an InterRepository
|
36 |
tree_a = self.make_branch_and_tree('a') |
|
37 |
self.build_tree(['a/foo']) |
|
38 |
tree_a.add('foo', 'file1') |
|
39 |
tree_a.commit('rev1', rev_id='rev1') |
|
40 |
# fetch with a default limit (grab everything)
|
|
2711.2.6
by Martin Pool
Fix up conversion of create_repository to make_repository in test_fetch |
41 |
repo = self.make_repository('b') |
2696.3.2
by Martin Pool
Move some per-repository tests from big test_repository to test_fetch |
42 |
if (tree_a.branch.repository.supports_rich_root() and not |
43 |
repo.supports_rich_root()): |
|
44 |
raise TestSkipped('Cannot fetch from model2 to model1') |
|
45 |
repo.fetch(tree_a.branch.repository, |
|
46 |
revision_id=None) |
|
47 |
||
4145.1.1
by Robert Collins
Explicitly prevent fetching while the target repository is in a write group. |
48 |
def test_fetch_fails_in_write_group(self): |
49 |
# fetch() manages a write group itself, fetching within one isn't safe.
|
|
50 |
repo = self.make_repository('a') |
|
51 |
repo.lock_write() |
|
52 |
self.addCleanup(repo.unlock) |
|
53 |
repo.start_write_group() |
|
54 |
self.addCleanup(repo.abort_write_group) |
|
55 |
# Don't need a specific class - not expecting flow control based on
|
|
56 |
# this.
|
|
57 |
self.assertRaises(errors.BzrError, repo.fetch, repo) |
|
58 |
||
4060.1.4
by Robert Collins
Streaming fetch from remote servers. |
59 |
def test_fetch_to_knit3(self): |
2696.3.2
by Martin Pool
Move some per-repository tests from big test_repository to test_fetch |
60 |
# create a repository of the sort we are testing.
|
3242.2.17
by Aaron Bentley
Fix broken tests |
61 |
tree_a = self.make_branch_and_tree('a') |
2696.3.2
by Martin Pool
Move some per-repository tests from big test_repository to test_fetch |
62 |
self.build_tree(['a/foo']) |
63 |
tree_a.add('foo', 'file1') |
|
64 |
tree_a.commit('rev1', rev_id='rev1') |
|
65 |
# create a knit-3 based format to fetch into
|
|
66 |
f = bzrdir.format_registry.make_bzrdir('dirstate-with-subtree') |
|
67 |
try: |
|
68 |
format = tree_a.branch.repository._format |
|
69 |
format.check_conversion_target(f.repository_format) |
|
70 |
# if we cannot convert data to knit3, skip the test.
|
|
71 |
except errors.BadConversionTarget, e: |
|
72 |
raise TestSkipped(str(e)) |
|
73 |
self.get_transport().mkdir('b') |
|
74 |
b_bzrdir = f.initialize(self.get_url('b')) |
|
75 |
knit3_repo = b_bzrdir.create_repository() |
|
76 |
# fetch with a default limit (grab everything)
|
|
77 |
knit3_repo.fetch(tree_a.branch.repository, revision_id=None) |
|
2592.3.96
by Robert Collins
Merge index improvements (includes bzr.dev). |
78 |
# Reopen to avoid any in-memory caching - ensure its reading from
|
79 |
# disk.
|
|
80 |
knit3_repo = b_bzrdir.open_repository() |
|
2696.3.2
by Martin Pool
Move some per-repository tests from big test_repository to test_fetch |
81 |
rev1_tree = knit3_repo.revision_tree('rev1') |
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. |
82 |
rev1_tree.lock_read() |
83 |
try: |
|
84 |
lines = rev1_tree.get_file_lines(rev1_tree.get_root_id()) |
|
85 |
finally: |
|
86 |
rev1_tree.unlock() |
|
2696.3.2
by Martin Pool
Move some per-repository tests from big test_repository to test_fetch |
87 |
self.assertEqual([], lines) |
88 |
b_branch = b_bzrdir.create_branch() |
|
89 |
b_branch.pull(tree_a.branch) |
|
90 |
try: |
|
91 |
tree_b = b_bzrdir.create_workingtree() |
|
92 |
except errors.NotLocalUrl: |
|
4060.1.4
by Robert Collins
Streaming fetch from remote servers. |
93 |
try: |
94 |
tree_b = b_branch.create_checkout('b', lightweight=True) |
|
95 |
except errors.NotLocalUrl: |
|
96 |
raise TestSkipped("cannot make working tree with transport %r" |
|
2696.3.2
by Martin Pool
Move some per-repository tests from big test_repository to test_fetch |
97 |
% b_bzrdir.transport) |
98 |
tree_b.commit('no change', rev_id='rev2') |
|
99 |
rev2_tree = knit3_repo.revision_tree('rev2') |
|
100 |
self.assertEqual('rev1', rev2_tree.inventory.root.revision) |
|
2696.3.9
by Martin Pool
merge trunk |
101 |
|
2948.3.1
by John Arbash Meinel
Fix bug #158333, make sure that Repository.fetch(self) is properly a no-op for all Repository implementations. |
102 |
def test_fetch_all_from_self(self): |
103 |
tree = self.make_branch_and_tree('.') |
|
104 |
rev_id = tree.commit('one') |
|
105 |
# This needs to be a new copy of the repository, if this changes, the
|
|
106 |
# test needs to be rewritten
|
|
107 |
repo = tree.branch.repository.bzrdir.open_repository() |
|
108 |
# This fetch should be a no-op see bug #158333
|
|
109 |
tree.branch.repository.fetch(repo, None) |
|
110 |
||
111 |
def test_fetch_from_self(self): |
|
112 |
tree = self.make_branch_and_tree('.') |
|
113 |
rev_id = tree.commit('one') |
|
114 |
repo = tree.branch.repository.bzrdir.open_repository() |
|
115 |
# This fetch should be a no-op see bug #158333
|
|
116 |
tree.branch.repository.fetch(repo, rev_id) |
|
117 |
||
118 |
def test_fetch_missing_from_self(self): |
|
119 |
tree = self.make_branch_and_tree('.') |
|
120 |
rev_id = tree.commit('one') |
|
121 |
# Even though the fetch() is a NO-OP it should assert the revision id
|
|
122 |
# is present
|
|
123 |
repo = tree.branch.repository.bzrdir.open_repository() |
|
124 |
self.assertRaises(errors.NoSuchRevision, tree.branch.repository.fetch, |
|
125 |
repo, 'no-such-revision') |
|
126 |
||
2696.3.9
by Martin Pool
merge trunk |
127 |
def makeARepoWithSignatures(self): |
128 |
wt = self.make_branch_and_tree('a-repo-with-sigs') |
|
129 |
wt.commit('rev1', allow_pointless=True, rev_id='rev1') |
|
130 |
repo = wt.branch.repository |
|
2592.3.96
by Robert Collins
Merge index improvements (includes bzr.dev). |
131 |
repo.lock_write() |
132 |
repo.start_write_group() |
|
2592.3.103
by Robert Collins
Fix some more pack-related test breakage. |
133 |
repo.sign_revision('rev1', gpg.LoopbackGPGStrategy(None)) |
2592.3.96
by Robert Collins
Merge index improvements (includes bzr.dev). |
134 |
repo.commit_write_group() |
135 |
repo.unlock() |
|
2696.3.9
by Martin Pool
merge trunk |
136 |
return repo |
137 |
||
138 |
def test_fetch_copies_signatures(self): |
|
139 |
source_repo = self.makeARepoWithSignatures() |
|
140 |
target_repo = self.make_repository('target') |
|
141 |
target_repo.fetch(source_repo, revision_id=None) |
|
142 |
self.assertEqual( |
|
143 |
source_repo.get_signature_text('rev1'), |
|
144 |
target_repo.get_signature_text('rev1')) |
|
2535.3.48
by Andrew Bennetts
Merge from bzr.dev. |
145 |
|
146 |
def make_repository_with_one_revision(self): |
|
3242.2.17
by Aaron Bentley
Fix broken tests |
147 |
wt = self.make_branch_and_tree('source') |
2535.3.48
by Andrew Bennetts
Merge from bzr.dev. |
148 |
wt.commit('rev1', allow_pointless=True, rev_id='rev1') |
149 |
return wt.branch.repository |
|
150 |
||
151 |
def test_fetch_revision_already_exists(self): |
|
152 |
# Make a repository with one revision.
|
|
153 |
source_repo = self.make_repository_with_one_revision() |
|
154 |
# Fetch that revision into a second repository.
|
|
155 |
target_repo = self.make_repository('target') |
|
156 |
target_repo.fetch(source_repo, revision_id='rev1') |
|
157 |
# Now fetch again; there will be nothing to do. This should work
|
|
158 |
# without causing any errors.
|
|
159 |
target_repo.fetch(source_repo, revision_id='rev1') |
|
160 |
||
1551.19.36
by Aaron Bentley
Prevent fetch all from causing pack collisions |
161 |
def test_fetch_all_same_revisions_twice(self): |
162 |
# Blind-fetching all the same revisions twice should succeed and be a
|
|
163 |
# no-op the second time.
|
|
164 |
repo = self.make_repository('repo') |
|
165 |
tree = self.make_branch_and_tree('tree') |
|
166 |
revision_id = tree.commit('test') |
|
167 |
repo.fetch(tree.branch.repository) |
|
168 |
repo.fetch(tree.branch.repository) |