21
21
from bzrlib.builtins import merge
22
22
import bzrlib.errors
23
23
from bzrlib.fetch import greedy_fetch
24
from bzrlib.tests import TestCaseWithTransport
25
from bzrlib.tests.HTTPTestUtil import TestCaseWithWebserver
24
26
from bzrlib.tests.test_revision import make_branches
25
from bzrlib.tests import TestCaseInTempDir
26
from bzrlib.tests.HTTPTestUtil import TestCaseWithWebserver
27
27
from bzrlib.trace import mutter
28
from bzrlib.workingtree import WorkingTree
30
31
def has_revision(branch, revision_id):
34
35
except bzrlib.errors.NoSuchRevision:
37
39
def fetch_steps(self, br_a, br_b, writable_a):
38
40
"""A foreign test method for testing fetch locally and remotely."""
39
41
def new_branch(name):
41
return Branch.initialize(name)
43
return WorkingTree.create_standalone(name).branch
43
45
self.assertFalse(has_revision(br_b, br_a.revision_history()[3]))
44
46
self.assert_(has_revision(br_b, br_a.revision_history()[2]))
106
108
fetch_steps(self, br_a, br_b, br_a)
109
class TestMergeFetch(TestCaseInTempDir):
111
class TestMergeFetch(TestCaseWithTransport):
111
113
def test_merge_fetches_unrelated(self):
112
114
"""Merge brings across history from unrelated source"""
114
br1 = Branch.initialize('br1')
115
br1.working_tree().commit(message='rev 1-1', rev_id='1-1')
116
br1.working_tree().commit(message='rev 1-2', rev_id='1-2')
118
br2 = Branch.initialize('br2')
119
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')
120
122
merge(other_revision=['br1', -1], base_revision=['br1', 0],
122
124
self._check_revs_present(br2)
124
126
def test_merge_fetches(self):
125
127
"""Merge brings across history from source"""
127
br1 = Branch.initialize('br1')
128
br1.working_tree().commit(message='rev 1-1', rev_id='1-1')
130
br2 = Branch.open('br2')
131
br1.working_tree().commit(message='rev 1-2', rev_id='1-2')
132
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')
133
134
merge(other_revision=['br1', -1], base_revision=[None, None],
135
136
self._check_revs_present(br2)
142
143
self.assertTrue(br2.repository.get_inventory(rev_id))
146
class TestMergeFileHistory(TestCaseWithTransport):
146
class TestMergeFileHistory(TestCaseInTempDir):
148
TestCaseInTempDir.setUp(self)
150
br1 = Branch.initialize('br1')
149
super(TestMergeFileHistory, self).setUp()
150
wt1 = self.make_branch_and_tree('br1')
151
152
self.build_tree_contents([('br1/file', 'original contents\n')])
152
br1.working_tree().add(['file'], ['this-file-id'])
153
br1.working_tree().commit(message='rev 1-1', rev_id='1-1')
155
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)
156
157
self.build_tree_contents([('br1/file', 'original from 1\n')])
157
br1.working_tree().commit(message='rev 1-2', rev_id='1-2')
158
wt1.commit(message='rev 1-2', rev_id='1-2')
158
159
self.build_tree_contents([('br1/file', 'agreement\n')])
159
br1.working_tree().commit(message='rev 1-3', rev_id='1-3')
160
wt1.commit(message='rev 1-3', rev_id='1-3')
160
161
self.build_tree_contents([('br2/file', 'contents in 2\n')])
161
br2.working_tree().commit(message='rev 2-1', rev_id='2-1')
162
wt2.commit(message='rev 2-1', rev_id='2-1')
162
163
self.build_tree_contents([('br2/file', 'agreement\n')])
163
br2.working_tree().commit(message='rev 2-2', rev_id='2-2')
164
wt2.commit(message='rev 2-2', rev_id='2-2')
165
166
def test_merge_fetches_file_history(self):
166
167
"""Merge brings across file histories"""
176
177
rev_id).get_file_text('this-file-id'), text)
181
180
class TestHttpFetch(TestCaseWithWebserver):
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 ?
183
185
def test_fetch(self):
184
186
#highest indices a: 5, b: 7
187
print "TestHttpFetch.test_fetch disabled during transition."
185
189
br_a, br_b = make_branches(self)
186
190
br_rem_a = Branch.open(self.get_remote_url(br_a.base))
187
191
fetch_steps(self, br_rem_a, br_b, br_a)
189
193
def test_weaves_are_retrieved_once(self):
190
194
self.build_tree(("source/", "source/file", "target/"))
191
branch = Branch.initialize("source")
192
branch.working_tree().add(["file"], ["id"])
193
branch.working_tree().commit("added file")
195
wt = WorkingTree.create_standalone('source')
197
wt.add(["file"], ["id"])
198
wt.commit("added file")
194
199
print >>open("source/file", 'w'), "blah"
195
branch.working_tree().commit("changed file")
196
target = Branch.initialize("target/")
200
wt.commit("changed file")
201
target = Branch.create("target/")
197
202
source = Branch.open(self.get_remote_url("source/"))
198
203
self.assertEqual(greedy_fetch(target, source), (2, []))
199
204
# this is the path to the literal file. As format changes