20
from bzrlib.branch import Branch
21
from bzrlib.builtins import merge
20
22
import bzrlib.errors
23
from bzrlib.fetch import greedy_fetch
24
from bzrlib.tests import TestCaseWithTransport
25
from bzrlib.tests.HTTPTestUtil import TestCaseWithWebserver
21
26
from bzrlib.tests.test_revision import make_branches
22
27
from bzrlib.trace import mutter
23
from bzrlib.branch import Branch
24
from bzrlib.fetch import greedy_fetch
25
from bzrlib.merge import merge
26
from bzrlib.clone import copy_branch
28
from bzrlib.tests import TestCaseInTempDir
29
from bzrlib.tests.HTTPTestUtil import TestCaseWithWebserver
28
from bzrlib.workingtree import WorkingTree
32
31
def has_revision(branch, revision_id):
34
branch.get_revision_xml(revision_id)
33
branch.repository.get_revision_xml_file(revision_id)
36
35
except bzrlib.errors.NoSuchRevision:
39
39
def fetch_steps(self, br_a, br_b, writable_a):
40
40
"""A foreign test method for testing fetch locally and remotely."""
41
41
def new_branch(name):
43
return Branch.initialize(name)
43
return WorkingTree.create_standalone(name).branch
45
45
self.assertFalse(has_revision(br_b, br_a.revision_history()[3]))
46
46
self.assert_(has_revision(br_b, br_a.revision_history()[2]))
108
108
fetch_steps(self, br_a, br_b, br_a)
111
class TestMergeFetch(TestCaseInTempDir):
111
class TestMergeFetch(TestCaseWithTransport):
113
113
def test_merge_fetches_unrelated(self):
114
114
"""Merge brings across history from unrelated source"""
116
br1 = Branch.initialize('br1')
117
br1.working_tree().commit(message='rev 1-1', rev_id='1-1')
118
br1.working_tree().commit(message='rev 1-2', rev_id='1-2')
120
br2 = Branch.initialize('br2')
121
br2.working_tree().commit(message='rev 2-1', rev_id='2-1')
115
wt1 = self.make_branch_and_tree('br1')
117
wt1.commit(message='rev 1-1', rev_id='1-1')
118
wt1.commit(message='rev 1-2', rev_id='1-2')
119
wt2 = self.make_branch_and_tree('br2')
121
wt2.commit(message='rev 2-1', rev_id='2-1')
122
122
merge(other_revision=['br1', -1], base_revision=['br1', 0],
124
124
self._check_revs_present(br2)
126
126
def test_merge_fetches(self):
127
127
"""Merge brings across history from source"""
129
br1 = Branch.initialize('br1')
130
br1.working_tree().commit(message='rev 1-1', rev_id='1-1')
131
copy_branch(br1, 'br2')
132
br2 = Branch.open('br2')
133
br1.working_tree().commit(message='rev 1-2', rev_id='1-2')
134
br2.working_tree().commit(message='rev 2-1', rev_id='2-1')
128
wt1 = self.make_branch_and_tree('br1')
130
wt1.commit(message='rev 1-1', rev_id='1-1')
131
br2 = br1.clone('br2')
132
wt1.commit(message='rev 1-2', rev_id='1-2')
133
WorkingTree('br2', br2).commit(message='rev 2-1', rev_id='2-1')
135
134
merge(other_revision=['br1', -1], base_revision=[None, None],
137
136
self._check_revs_present(br2)
139
138
def _check_revs_present(self, br2):
140
139
for rev_id in '1-1', '1-2', '2-1':
141
self.assertTrue(br2.has_revision(rev_id))
142
rev = br2.get_revision(rev_id)
140
self.assertTrue(br2.repository.has_revision(rev_id))
141
rev = br2.repository.get_revision(rev_id)
143
142
self.assertEqual(rev.revision_id, rev_id)
144
self.assertTrue(br2.get_inventory(rev_id))
148
class TestMergeFileHistory(TestCaseInTempDir):
143
self.assertTrue(br2.repository.get_inventory(rev_id))
146
class TestMergeFileHistory(TestCaseWithTransport):
150
TestCaseInTempDir.setUp(self)
152
br1 = Branch.initialize('br1')
149
super(TestMergeFileHistory, self).setUp()
150
wt1 = self.make_branch_and_tree('br1')
153
152
self.build_tree_contents([('br1/file', 'original contents\n')])
154
br1.working_tree().add(['file'], ['this-file-id'])
155
br1.working_tree().commit(message='rev 1-1', rev_id='1-1')
156
copy_branch(br1, 'br2')
157
br2 = Branch.open('br2')
153
wt1.add('file', 'this-file-id')
154
wt1.commit(message='rev 1-1', rev_id='1-1')
155
br2 = br1.clone('br2')
156
wt2 = WorkingTree('br2', br2)
158
157
self.build_tree_contents([('br1/file', 'original from 1\n')])
159
br1.working_tree().commit(message='rev 1-2', rev_id='1-2')
158
wt1.commit(message='rev 1-2', rev_id='1-2')
160
159
self.build_tree_contents([('br1/file', 'agreement\n')])
161
br1.working_tree().commit(message='rev 1-3', rev_id='1-3')
160
wt1.commit(message='rev 1-3', rev_id='1-3')
162
161
self.build_tree_contents([('br2/file', 'contents in 2\n')])
163
br2.working_tree().commit(message='rev 2-1', rev_id='2-1')
162
wt2.commit(message='rev 2-1', rev_id='2-1')
164
163
self.build_tree_contents([('br2/file', 'agreement\n')])
165
br2.working_tree().commit(message='rev 2-2', rev_id='2-2')
164
wt2.commit(message='rev 2-2', rev_id='2-2')
167
166
def test_merge_fetches_file_history(self):
168
167
"""Merge brings across file histories"""
173
172
('1-3', 'agreement\n'),
174
173
('2-1', 'contents in 2\n'),
175
174
('2-2', 'agreement\n')]:
176
self.assertEqualDiff(br2.revision_tree(rev_id).get_file_text('this-file-id'),
175
self.assertEqualDiff(
176
br2.repository.revision_tree(
177
rev_id).get_file_text('this-file-id'), text)
182
180
class TestHttpFetch(TestCaseWithWebserver):
185
super(TestHttpFetch, self).setUp()
181
# FIXME RBC 20060124 this really isn't web specific, perhaps an
182
# instrumented readonly transport? Can we do an instrumented
183
# adapter and use self.get_readonly_url ?
188
185
def test_fetch(self):
189
186
#highest indices a: 5, b: 7
187
print "TestHttpFetch.test_fetch disabled during transition."
190
189
br_a, br_b = make_branches(self)
191
br_rem_a = Branch.open(self.get_remote_url(br_a._transport.base))
190
br_rem_a = Branch.open(self.get_remote_url(br_a.base))
192
191
fetch_steps(self, br_rem_a, br_b, br_a)
194
def log(self, *args):
195
"""Capture web server log messages for introspection."""
196
super(TestHttpFetch, self).log(*args)
197
# if this call indicates a url being fetched, save it specially
198
if args[0].startswith("webserver"):
199
self.weblogs.append(args[3])
201
193
def test_weaves_are_retrieved_once(self):
202
194
self.build_tree(("source/", "source/file", "target/"))
203
branch = Branch.initialize("source")
204
branch.working_tree().add(["file"], ["id"])
205
branch.working_tree().commit("added file")
195
wt = WorkingTree.create_standalone('source')
197
wt.add(["file"], ["id"])
198
wt.commit("added file")
206
199
print >>open("source/file", 'w'), "blah"
207
branch.working_tree().commit("changed file")
208
target = Branch.initialize("target/")
200
wt.commit("changed file")
201
target = Branch.create("target/")
209
202
source = Branch.open(self.get_remote_url("source/"))
210
203
self.assertEqual(greedy_fetch(target, source), (2, []))
211
204
# this is the path to the literal file. As format changes
214
207
weave_suffix = 'weaves/ce/id.weave HTTP/1.1" 200 -'
215
208
self.assertEqual(1,
216
len([log for log in self.weblogs if log.endswith(weave_suffix)]))
209
len([log for log in self.server.logs if log.endswith(weave_suffix)]))
217
210
inventory_weave_suffix = 'inventory.weave HTTP/1.1" 200 -'
218
211
self.assertEqual(1,
219
len([log for log in self.weblogs if log.endswith(
212
len([log for log in self.server.logs if log.endswith(
220
213
inventory_weave_suffix)]))
221
214
# this r-h check test will prevent regressions, but it currently already
222
215
# passes, before the patch to cache-rh is applied :[
223
216
revision_history_suffix = 'revision-history HTTP/1.1" 200 -'
224
217
self.assertEqual(1,
225
len([log for log in self.weblogs if log.endswith(
218
len([log for log in self.server.logs if log.endswith(
226
219
revision_history_suffix)]))
220
# FIXME naughty poking in there.
221
self.server.logs = []
228
222
# check there is nothing more to fetch
229
223
source = Branch.open(self.get_remote_url("source/"))
230
224
self.assertEqual(greedy_fetch(target, source), (0, []))
231
self.failUnless(self.weblogs[0].endswith('branch-format HTTP/1.1" 200 -'))
232
self.failUnless(self.weblogs[1].endswith('revision-history HTTP/1.1" 200 -'))
233
self.assertEqual(2, len(self.weblogs))
225
self.failUnless(self.server.logs[0].endswith('branch-format HTTP/1.1" 200 -'))
226
self.failUnless(self.server.logs[1].endswith('revision-history HTTP/1.1" 200 -'))
227
self.assertEqual(2, len(self.server.logs))