1
# Copyright (C) 2005 Canonical Ltd
1
# Copyright (C) 2005 by Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
5
5
# the Free Software Foundation; either version 2 of the License, or
6
6
# (at your option) any later version.
8
8
# This program is distributed in the hope that it will be useful,
9
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
11
# GNU General Public License for more details.
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26
20
from bzrlib.branch import Branch
27
21
from bzrlib.bzrdir import BzrDir
28
22
from bzrlib.builtins import merge
29
23
import bzrlib.errors
30
from bzrlib.repofmt import knitrepo
31
24
from bzrlib.tests import TestCaseWithTransport
32
25
from bzrlib.tests.HTTPTestUtil import TestCaseWithWebserver
33
26
from bzrlib.tests.test_revision import make_branches
34
27
from bzrlib.trace import mutter
35
from bzrlib.upgrade import Convert
36
28
from bzrlib.workingtree import WorkingTree
100
92
br_a2.append_revision('a-b-c')
101
93
self.assertRaises(bzrlib.errors.InstallFailed, br_a3.fetch, br_a2)
103
# TODO: ADHB 20070116 Perhaps set_last_revision shouldn't accept
104
# revisions which are not present? In that case, this test
107
# RBC 20060403 the way to do this is to uncommit the revision from
108
# the repository after the commit
95
# TODO: jam 20051218 Branch should no longer allow append_revision for revisions
96
# which don't exist. So this test needs to be rewritten
97
# RBC 20060403 the way to do this is to uncommit the revision from the
98
# repository after the commit
110
100
#TODO: test that fetch correctly does reweaving when needed. RBC 20051008
111
101
# Note that this means - updating the weave when ghosts are filled in to
123
113
wt = self.make_branch_and_tree('br')
124
114
self.assertEqual(wt.branch.fetch(wt.branch), (0, []))
126
def test_fetch_root_knit(self):
127
"""Ensure that knit2.fetch() updates the root knit
129
This tests the case where the root has a new revision, but there are no
130
corresponding filename, parent, contents or other changes.
132
knit1_format = bzrdir.BzrDirMetaFormat1()
133
knit1_format.repository_format = knitrepo.RepositoryFormatKnit1()
134
knit2_format = bzrdir.BzrDirMetaFormat1()
135
knit2_format.repository_format = knitrepo.RepositoryFormatKnit3()
136
# we start with a knit1 repository because that causes the
137
# root revision to change for each commit, even though the content,
138
# parent, name, and other attributes are unchanged.
139
tree = self.make_branch_and_tree('tree', knit1_format)
140
tree.set_root_id('tree-root')
141
tree.commit('rev1', rev_id='rev1')
142
tree.commit('rev2', rev_id='rev2')
144
# Now we convert it to a knit2 repository so that it has a root knit
145
Convert(tree.basedir, knit2_format)
146
tree = WorkingTree.open(tree.basedir)
147
branch = self.make_branch('branch', format=knit2_format)
148
branch.pull(tree.branch, stop_revision='rev1')
149
repo = branch.repository
150
root_knit = repo.weave_store.get_weave('tree-root',
151
repo.get_transaction())
152
# Make sure fetch retrieved only what we requested
153
self.assertTrue('rev1' in root_knit)
154
self.assertTrue('rev2' not in root_knit)
155
branch.pull(tree.branch)
156
root_knit = repo.weave_store.get_weave('tree-root',
157
repo.get_transaction())
158
# Make sure that the next revision in the root knit was retrieved,
159
# even though the text, name, parent_id, etc., were unchanged.
160
self.assertTrue('rev2' in root_knit)
162
def test_fetch_incompatible(self):
163
knit_tree = self.make_branch_and_tree('knit', format='knit')
164
knit3_tree = self.make_branch_and_tree('knit3',
165
format='dirstate-with-subtree')
166
knit3_tree.commit('blah')
167
self.assertRaises(errors.IncompatibleRepositories,
168
knit_tree.branch.fetch, knit3_tree.branch)
171
117
class TestMergeFetch(TestCaseWithTransport):
253
199
def _count_log_matches(self, target, logs):
254
200
"""Count the number of times the target file pattern was fetched in an http log"""
255
get_succeeds_re = re.compile(
256
'.*"GET .*%s HTTP/1.1" 20[06] - "-" "bzr/%s' %
257
( target, bzrlib.__version__))
201
log_pattern = '%s HTTP/1.1" 200 - "-" "bzr/%s' % \
202
(target, bzrlib.__version__)
259
204
for line in logs:
260
if get_succeeds_re.match(line):
205
# TODO: perhaps use a regexp instead so we can match more
207
if line.find(log_pattern) > -1:
272
219
target = BzrDir.create_branch_and_repo("target/")
273
220
source = Branch.open(self.get_readonly_url("source/"))
274
221
self.assertEqual(target.fetch(source), (2, []))
222
log_pattern = '%%s HTTP/1.1" 200 - "-" "bzr/%s' % bzrlib.__version__
275
223
# this is the path to the literal file. As format changes
276
224
# occur it needs to be updated. FIXME: ask the store for the
284
232
self.assertEqual(1, self._count_log_matches('/ce/id.kndx', http_logs))
285
233
self.assertEqual(1, self._count_log_matches('/ce/id.knit', http_logs))
286
234
self.assertEqual(1, self._count_log_matches('inventory.kndx', http_logs))
235
self.assertEqual(1, self._count_log_matches('inventory.knit', http_logs))
287
236
# this r-h check test will prevent regressions, but it currently already
288
237
# passes, before the patch to cache-rh is applied :[
289
self.assertTrue(1 >= self._count_log_matches('revision-history',
291
self.assertTrue(1 >= self._count_log_matches('last-revision',
238
self.assertEqual(1, self._count_log_matches('revision-history', http_logs))
293
239
# FIXME naughty poking in there.
294
240
self.get_readonly_server().logs = []
295
241
# check there is nothing more to fetch
302
248
self.assertEqual(1, self._count_log_matches('branch-format', http_logs))
303
249
self.assertEqual(1, self._count_log_matches('branch/format', http_logs))
304
250
self.assertEqual(1, self._count_log_matches('repository/format', http_logs))
305
self.assertTrue(1 >= self._count_log_matches('revision-history',
307
self.assertTrue(1 >= self._count_log_matches('last-revision',
251
self.assertEqual(1, self._count_log_matches('revision-history', http_logs))
309
252
self.assertEqual(4, len(http_logs))