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
|
|
15 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
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 |
|
26 |
from bzrlib.tests.repository_implementations import TestCaseWithRepository |
|
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.
|
|
34 |
# it is defined as a convenience function with the underlying
|
|
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 |
## pb=bzrlib.progress.DummyProgress())
|
|
48 |
||
49 |
def test_fetch_knit3(self): |
|
50 |
# create a repository of the sort we are testing.
|
|
51 |
tree_a = self.make_branch_and_tree('a', '') |
|
52 |
self.build_tree(['a/foo']) |
|
53 |
tree_a.add('foo', 'file1') |
|
54 |
tree_a.commit('rev1', rev_id='rev1') |
|
55 |
# create a knit-3 based format to fetch into
|
|
56 |
f = bzrdir.format_registry.make_bzrdir('dirstate-with-subtree') |
|
57 |
try: |
|
58 |
format = tree_a.branch.repository._format |
|
59 |
format.check_conversion_target(f.repository_format) |
|
60 |
# if we cannot convert data to knit3, skip the test.
|
|
61 |
except errors.BadConversionTarget, e: |
|
62 |
raise TestSkipped(str(e)) |
|
63 |
self.get_transport().mkdir('b') |
|
64 |
b_bzrdir = f.initialize(self.get_url('b')) |
|
65 |
knit3_repo = b_bzrdir.create_repository() |
|
66 |
# fetch with a default limit (grab everything)
|
|
67 |
knit3_repo.fetch(tree_a.branch.repository, revision_id=None) |
|
2592.3.96
by Robert Collins
Merge index improvements (includes bzr.dev). |
68 |
# Reopen to avoid any in-memory caching - ensure its reading from
|
69 |
# disk.
|
|
70 |
knit3_repo = b_bzrdir.open_repository() |
|
2696.3.2
by Martin Pool
Move some per-repository tests from big test_repository to test_fetch |
71 |
rev1_tree = knit3_repo.revision_tree('rev1') |
2946.3.3
by John Arbash Meinel
Prefer tree.get_root_id() as more explicit than tree.path2id('') |
72 |
lines = rev1_tree.get_file_lines(rev1_tree.get_root_id()) |
2696.3.2
by Martin Pool
Move some per-repository tests from big test_repository to test_fetch |
73 |
self.assertEqual([], lines) |
74 |
b_branch = b_bzrdir.create_branch() |
|
75 |
b_branch.pull(tree_a.branch) |
|
76 |
try: |
|
77 |
tree_b = b_bzrdir.create_workingtree() |
|
78 |
except errors.NotLocalUrl: |
|
79 |
raise TestSkipped("cannot make working tree with transport %r" |
|
80 |
% b_bzrdir.transport) |
|
81 |
tree_b.commit('no change', rev_id='rev2') |
|
82 |
rev2_tree = knit3_repo.revision_tree('rev2') |
|
83 |
self.assertEqual('rev1', rev2_tree.inventory.root.revision) |
|
2696.3.9
by Martin Pool
merge trunk |
84 |
|
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. |
85 |
def test_fetch_all_from_self(self): |
86 |
tree = self.make_branch_and_tree('.') |
|
87 |
rev_id = tree.commit('one') |
|
88 |
# This needs to be a new copy of the repository, if this changes, the
|
|
89 |
# test needs to be rewritten
|
|
90 |
repo = tree.branch.repository.bzrdir.open_repository() |
|
91 |
# This fetch should be a no-op see bug #158333
|
|
92 |
tree.branch.repository.fetch(repo, None) |
|
93 |
||
94 |
def test_fetch_from_self(self): |
|
95 |
tree = self.make_branch_and_tree('.') |
|
96 |
rev_id = tree.commit('one') |
|
97 |
repo = tree.branch.repository.bzrdir.open_repository() |
|
98 |
# This fetch should be a no-op see bug #158333
|
|
99 |
tree.branch.repository.fetch(repo, rev_id) |
|
100 |
||
101 |
def test_fetch_missing_from_self(self): |
|
102 |
tree = self.make_branch_and_tree('.') |
|
103 |
rev_id = tree.commit('one') |
|
104 |
# Even though the fetch() is a NO-OP it should assert the revision id
|
|
105 |
# is present
|
|
106 |
repo = tree.branch.repository.bzrdir.open_repository() |
|
107 |
self.assertRaises(errors.NoSuchRevision, tree.branch.repository.fetch, |
|
108 |
repo, 'no-such-revision') |
|
109 |
||
2696.3.9
by Martin Pool
merge trunk |
110 |
def makeARepoWithSignatures(self): |
111 |
wt = self.make_branch_and_tree('a-repo-with-sigs') |
|
112 |
wt.commit('rev1', allow_pointless=True, rev_id='rev1') |
|
113 |
repo = wt.branch.repository |
|
2592.3.96
by Robert Collins
Merge index improvements (includes bzr.dev). |
114 |
repo.lock_write() |
115 |
repo.start_write_group() |
|
2592.3.103
by Robert Collins
Fix some more pack-related test breakage. |
116 |
repo.sign_revision('rev1', gpg.LoopbackGPGStrategy(None)) |
2592.3.96
by Robert Collins
Merge index improvements (includes bzr.dev). |
117 |
repo.commit_write_group() |
118 |
repo.unlock() |
|
2696.3.9
by Martin Pool
merge trunk |
119 |
return repo |
120 |
||
121 |
def test_fetch_copies_signatures(self): |
|
122 |
source_repo = self.makeARepoWithSignatures() |
|
123 |
target_repo = self.make_repository('target') |
|
124 |
target_repo.fetch(source_repo, revision_id=None) |
|
125 |
self.assertEqual( |
|
126 |
source_repo.get_signature_text('rev1'), |
|
127 |
target_repo.get_signature_text('rev1')) |
|
2535.3.48
by Andrew Bennetts
Merge from bzr.dev. |
128 |
|
129 |
def make_repository_with_one_revision(self): |
|
130 |
wt = self.make_branch_and_tree('source', '') |
|
131 |
wt.commit('rev1', allow_pointless=True, rev_id='rev1') |
|
132 |
return wt.branch.repository |
|
133 |
||
134 |
def test_fetch_revision_already_exists(self): |
|
135 |
# Make a repository with one revision.
|
|
136 |
source_repo = self.make_repository_with_one_revision() |
|
137 |
# Fetch that revision into a second repository.
|
|
138 |
target_repo = self.make_repository('target') |
|
139 |
target_repo.fetch(source_repo, revision_id='rev1') |
|
140 |
# Now fetch again; there will be nothing to do. This should work
|
|
141 |
# without causing any errors.
|
|
142 |
target_repo.fetch(source_repo, revision_id='rev1') |
|
143 |