1
# Copyright (C) 2005 by Canonical Ltd
1
# Copyright (C) 2005 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
21
from bzrlib import bzrdir, repository
20
22
from bzrlib.branch import Branch
21
23
from bzrlib.bzrdir import BzrDir
22
24
from bzrlib.builtins import merge
23
25
import bzrlib.errors
26
from bzrlib.repofmt import knitrepo
24
27
from bzrlib.tests import TestCaseWithTransport
25
28
from bzrlib.tests.HTTPTestUtil import TestCaseWithWebserver
26
29
from bzrlib.tests.test_revision import make_branches
27
30
from bzrlib.trace import mutter
31
from bzrlib.upgrade import Convert
28
32
from bzrlib.workingtree import WorkingTree
92
96
br_a2.append_revision('a-b-c')
93
97
self.assertRaises(bzrlib.errors.InstallFailed, br_a3.fetch, br_a2)
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
99
# TODO: ADHB 20070116 Perhaps set_last_revision shouldn't accept
100
# revisions which are not present? In that case, this test
103
# RBC 20060403 the way to do this is to uncommit the revision from
104
# the repository after the commit
100
106
#TODO: test that fetch correctly does reweaving when needed. RBC 20051008
101
107
# Note that this means - updating the weave when ghosts are filled in to
113
119
wt = self.make_branch_and_tree('br')
114
120
self.assertEqual(wt.branch.fetch(wt.branch), (0, []))
122
def test_fetch_root_knit(self):
123
"""Ensure that knit2.fetch() updates the root knit
125
This tests the case where the root has a new revision, but there are no
126
corresponding filename, parent, contents or other changes.
128
knit1_format = bzrdir.BzrDirMetaFormat1()
129
knit1_format.repository_format = knitrepo.RepositoryFormatKnit1()
130
knit2_format = bzrdir.BzrDirMetaFormat1()
131
knit2_format.repository_format = knitrepo.RepositoryFormatKnit3()
132
# we start with a knit1 repository because that causes the
133
# root revision to change for each commit, even though the content,
134
# parent, name, and other attributes are unchanged.
135
tree = self.make_branch_and_tree('tree', knit1_format)
136
tree.set_root_id('tree-root')
137
tree.commit('rev1', rev_id='rev1')
138
tree.commit('rev2', rev_id='rev2')
140
# Now we convert it to a knit2 repository so that it has a root knit
141
Convert(tree.basedir, knit2_format)
142
tree = WorkingTree.open(tree.basedir)
143
branch = self.make_branch('branch', format=knit2_format)
144
branch.pull(tree.branch, stop_revision='rev1')
145
repo = branch.repository
146
root_knit = repo.weave_store.get_weave('tree-root',
147
repo.get_transaction())
148
# Make sure fetch retrieved only what we requested
149
self.assertTrue('rev1' in root_knit)
150
self.assertTrue('rev2' not in root_knit)
151
branch.pull(tree.branch)
152
root_knit = repo.weave_store.get_weave('tree-root',
153
repo.get_transaction())
154
# Make sure that the next revision in the root knit was retrieved,
155
# even though the text, name, parent_id, etc., were unchanged.
156
self.assertTrue('rev2' in root_knit)
117
159
class TestMergeFetch(TestCaseWithTransport):
199
241
def _count_log_matches(self, target, logs):
200
242
"""Count the number of times the target file pattern was fetched in an http log"""
201
log_pattern = '%s HTTP/1.1" 200 - "-" "bzr/%s' % \
202
(target, bzrlib.__version__)
243
get_succeeds_re = re.compile(
244
'.*"GET .*%s HTTP/1.1" 20[06] - "-" "bzr/%s' %
245
( target, bzrlib.__version__))
204
247
for line in logs:
205
# TODO: perhaps use a regexp instead so we can match more
207
if line.find(log_pattern) > -1:
248
if get_succeeds_re.match(line):
219
260
target = BzrDir.create_branch_and_repo("target/")
220
261
source = Branch.open(self.get_readonly_url("source/"))
221
262
self.assertEqual(target.fetch(source), (2, []))
222
log_pattern = '%%s HTTP/1.1" 200 - "-" "bzr/%s' % bzrlib.__version__
223
263
# this is the path to the literal file. As format changes
224
264
# occur it needs to be updated. FIXME: ask the store for the
232
272
self.assertEqual(1, self._count_log_matches('/ce/id.kndx', http_logs))
233
273
self.assertEqual(1, self._count_log_matches('/ce/id.knit', http_logs))
234
274
self.assertEqual(1, self._count_log_matches('inventory.kndx', http_logs))
235
self.assertEqual(1, self._count_log_matches('inventory.knit', http_logs))
236
275
# this r-h check test will prevent regressions, but it currently already
237
276
# passes, before the patch to cache-rh is applied :[
238
self.assertEqual(1, self._count_log_matches('revision-history', http_logs))
277
self.assertTrue(1 >= self._count_log_matches('revision-history',
279
self.assertTrue(1 >= self._count_log_matches('last-revision',
239
281
# FIXME naughty poking in there.
240
282
self.get_readonly_server().logs = []
241
283
# check there is nothing more to fetch
248
290
self.assertEqual(1, self._count_log_matches('branch-format', http_logs))
249
291
self.assertEqual(1, self._count_log_matches('branch/format', http_logs))
250
292
self.assertEqual(1, self._count_log_matches('repository/format', http_logs))
251
self.assertEqual(1, self._count_log_matches('revision-history', http_logs))
293
self.assertTrue(1 >= self._count_log_matches('revision-history',
295
self.assertTrue(1 >= self._count_log_matches('last-revision',
252
297
self.assertEqual(4, len(http_logs))