1
# Copyright (C) 2005 Canonical Ltd
1
# Copyright (C) 2005, 2007 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
21
22
from bzrlib import (
26
28
from bzrlib.branch import Branch
27
29
from bzrlib.bzrdir import BzrDir
28
from bzrlib.builtins import merge
30
30
from bzrlib.repofmt import knitrepo
31
from bzrlib.symbol_versioning import (
31
34
from bzrlib.tests import TestCaseWithTransport
32
from bzrlib.tests.HTTPTestUtil import TestCaseWithWebserver
35
from bzrlib.tests.http_utils import TestCaseWithWebserver
33
36
from bzrlib.tests.test_revision import make_branches
34
37
from bzrlib.trace import mutter
35
38
from bzrlib.upgrade import Convert
36
39
from bzrlib.workingtree import WorkingTree
41
# These tests are a bit old; please instead add new tests into
42
# interrepository_implementations/ so they'll run on all relevant
39
46
def has_revision(branch, revision_id):
40
47
return branch.repository.has_revision(revision_id)
94
101
self.assertEquals(fetched, 3, "fetched %d instead of 3" % fetched)
95
102
# InstallFailed should be raised if the branch is missing the revision
96
103
# that was requested.
97
self.assertRaises(bzrlib.errors.InstallFailed, br_a3.fetch, br_a2, 'pizza')
98
# InstallFailed should be raised if the branch is missing a revision
99
# from its own revision history
100
br_a2.append_revision('a-b-c')
101
self.assertRaises(bzrlib.errors.InstallFailed, br_a3.fetch, br_a2)
104
self.assertRaises(errors.InstallFailed, br_a3.fetch, br_a2, 'pizza')
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
106
# TODO: Test trying to fetch from a branch that points to a revision not
107
# actually present in its repository. Not every branch format allows you
108
# to directly point to such revisions, so it's a bit complicated to
109
# construct. One way would be to uncommit and gc the revision, but not
110
# every branch supports that. -- mbp 20070814
110
112
#TODO: test that fetch correctly does reweaving when needed. RBC 20051008
111
113
# Note that this means - updating the weave when ghosts are filled in to
117
119
def test_fetch(self):
118
120
#highest indices a: 5, b: 7
119
br_a, br_b = make_branches(self)
121
br_a, br_b = make_branches(self, format='dirstate-tags')
120
122
fetch_steps(self, br_a, br_b, br_a)
122
124
def test_fetch_self(self):
179
181
wt2 = self.make_branch_and_tree('br2')
181
183
wt2.commit(message='rev 2-1', rev_id='2-1')
182
merge(other_revision=['br1', -1], base_revision=['br1', 0],
184
wt2.merge_from_branch(br1, from_revision='null:')
184
185
self._check_revs_present(br2)
186
187
def test_merge_fetches(self):
191
192
dir_2 = br1.bzrdir.sprout('br2')
192
193
br2 = dir_2.open_branch()
193
194
wt1.commit(message='rev 1-2', rev_id='1-2')
194
dir_2.open_workingtree().commit(message='rev 2-1', rev_id='2-1')
195
merge(other_revision=['br1', -1], base_revision=[None, None],
195
wt2 = dir_2.open_workingtree()
196
wt2.commit(message='rev 2-1', rev_id='2-1')
197
wt2.merge_from_branch(br1)
197
198
self._check_revs_present(br2)
199
200
def _check_revs_present(self, br2):
228
229
def test_merge_fetches_file_history(self):
229
230
"""Merge brings across file histories"""
230
231
br2 = Branch.open('br2')
231
merge(other_revision=['br1', -1], base_revision=[None, None],
232
br1 = Branch.open('br1')
233
wt2 = WorkingTree.open('br2').merge_from_branch(br1)
235
self.addCleanup(br2.unlock)
233
236
for rev_id, text in [('1-2', 'original from 1\n'),
234
237
('1-3', 'agreement\n'),
235
238
('2-1', 'contents in 2\n'),
264
267
def test_weaves_are_retrieved_once(self):
265
268
self.build_tree(("source/", "source/file", "target/"))
266
wt = self.make_branch_and_tree('source')
269
# This test depends on knit dasta storage.
270
wt = self.make_branch_and_tree('source', format='dirstate-tags')
267
271
branch = wt.branch
268
272
wt.add(["file"], ["id"])
269
273
wt.commit("added file")
270
print >>open("source/file", 'w'), "blah"
274
open("source/file", 'w').write("blah\n")
271
275
wt.commit("changed file")
272
276
target = BzrDir.create_branch_and_repo("target/")
273
277
source = Branch.open(self.get_readonly_url("source/"))