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
25
27
from bzrlib.tests.HTTPTestUtil import TestCaseWithWebserver
26
28
from bzrlib.tests.test_revision import make_branches
27
29
from bzrlib.trace import mutter
30
from bzrlib.upgrade import Convert
28
31
from bzrlib.workingtree import WorkingTree
113
116
wt = self.make_branch_and_tree('br')
114
117
self.assertEqual(wt.branch.fetch(wt.branch), (0, []))
119
def test_fetch_root_knit(self):
120
"""Ensure that knit2.fetch() updates the root knit
122
This tests the case where the root has a new revision, but there are no
123
corresponding filename, parent, contents or other changes.
125
knit1_format = bzrdir.BzrDirMetaFormat1()
126
knit1_format.repository_format = repository.RepositoryFormatKnit1()
127
knit2_format = bzrdir.BzrDirMetaFormat1()
128
knit2_format.repository_format = repository.RepositoryFormatKnit2()
129
# we start with a knit1 repository because that causes the
130
# root revision to change for each commit, even though the content,
131
# parent, name, and other attributes are unchanged.
132
tree = self.make_branch_and_tree('tree', knit1_format)
133
tree.set_root_id('tree-root')
134
tree.commit('rev1', rev_id='rev1')
135
tree.commit('rev2', rev_id='rev2')
137
# Now we convert it to a knit2 repository so that it has a root knit
138
Convert(tree.basedir, knit2_format)
139
tree = WorkingTree.open(tree.basedir)
140
branch = self.make_branch('branch', format=knit2_format)
141
branch.pull(tree.branch, stop_revision='rev1')
142
repo = branch.repository
143
root_knit = repo.weave_store.get_weave('tree-root',
144
repo.get_transaction())
145
# Make sure fetch retrieved only what we requested
146
self.assertTrue('rev1' in root_knit)
147
self.assertTrue('rev2' not in root_knit)
148
branch.pull(tree.branch)
149
root_knit = repo.weave_store.get_weave('tree-root',
150
repo.get_transaction())
151
# Make sure that the next revision in the root knit was retrieved,
152
# even though the text, name, parent_id, etc., were unchanged.
153
self.assertTrue('rev2' in root_knit)
117
156
class TestMergeFetch(TestCaseWithTransport):
199
238
def _count_log_matches(self, target, logs):
200
239
"""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__)
240
get_succeeds_re = re.compile(
241
'.*"GET .*%s HTTP/1.1" 20[06] - "-" "bzr/%s' %
242
( target, bzrlib.__version__))
204
244
for line in logs:
205
# TODO: perhaps use a regexp instead so we can match more
207
if line.find(log_pattern) > -1:
245
if get_succeeds_re.match(line):
219
257
target = BzrDir.create_branch_and_repo("target/")
220
258
source = Branch.open(self.get_readonly_url("source/"))
221
259
self.assertEqual(target.fetch(source), (2, []))
222
log_pattern = '%%s HTTP/1.1" 200 - "-" "bzr/%s' % bzrlib.__version__
223
260
# this is the path to the literal file. As format changes
224
261
# occur it needs to be updated. FIXME: ask the store for the