1
# Copyright (C) 2005, 2007 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
22
21
from bzrlib import (
28
26
from bzrlib.branch import Branch
29
27
from bzrlib.bzrdir import BzrDir
28
from bzrlib.builtins import merge
30
30
from bzrlib.repofmt import knitrepo
31
from bzrlib.symbol_versioning import (
34
31
from bzrlib.tests import TestCaseWithTransport
35
32
from bzrlib.tests.HTTPTestUtil import TestCaseWithWebserver
36
33
from bzrlib.tests.test_revision import make_branches
38
35
from bzrlib.upgrade import Convert
39
36
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
46
39
def has_revision(branch, revision_id):
47
40
return branch.repository.has_revision(revision_id)
101
94
self.assertEquals(fetched, 3, "fetched %d instead of 3" % fetched)
102
95
# InstallFailed should be raised if the branch is missing the revision
103
96
# that was requested.
104
self.assertRaises(errors.InstallFailed, br_a3.fetch, br_a2, 'pizza')
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)
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
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
112
110
#TODO: test that fetch correctly does reweaving when needed. RBC 20051008
113
111
# Note that this means - updating the weave when ghosts are filled in to
119
117
def test_fetch(self):
120
118
#highest indices a: 5, b: 7
121
br_a, br_b = make_branches(self, format='dirstate-tags')
119
br_a, br_b = make_branches(self)
122
120
fetch_steps(self, br_a, br_b, br_a)
124
122
def test_fetch_self(self):
181
179
wt2 = self.make_branch_and_tree('br2')
183
181
wt2.commit(message='rev 2-1', rev_id='2-1')
184
wt2.merge_from_branch(br1, from_revision='null:')
182
merge(other_revision=['br1', -1], base_revision=['br1', 0],
185
184
self._check_revs_present(br2)
187
186
def test_merge_fetches(self):
192
191
dir_2 = br1.bzrdir.sprout('br2')
193
192
br2 = dir_2.open_branch()
194
193
wt1.commit(message='rev 1-2', rev_id='1-2')
195
wt2 = dir_2.open_workingtree()
196
wt2.commit(message='rev 2-1', rev_id='2-1')
197
wt2.merge_from_branch(br1)
194
dir_2.open_workingtree().commit(message='rev 2-1', rev_id='2-1')
195
merge(other_revision=['br1', -1], base_revision=[None, None],
198
197
self._check_revs_present(br2)
200
199
def _check_revs_present(self, br2):
229
228
def test_merge_fetches_file_history(self):
230
229
"""Merge brings across file histories"""
231
230
br2 = Branch.open('br2')
232
br1 = Branch.open('br1')
233
wt2 = WorkingTree.open('br2').merge_from_branch(br1)
235
self.addCleanup(br2.unlock)
231
merge(other_revision=['br1', -1], base_revision=[None, None],
236
233
for rev_id, text in [('1-2', 'original from 1\n'),
237
234
('1-3', 'agreement\n'),
238
235
('2-1', 'contents in 2\n'),
267
264
def test_weaves_are_retrieved_once(self):
268
265
self.build_tree(("source/", "source/file", "target/"))
269
# This test depends on knit dasta storage.
270
wt = self.make_branch_and_tree('source', format='dirstate-tags')
266
wt = self.make_branch_and_tree('source')
271
267
branch = wt.branch
272
268
wt.add(["file"], ["id"])
273
269
wt.commit("added file")
274
open("source/file", 'w').write("blah\n")
270
print >>open("source/file", 'w'), "blah"
275
271
wt.commit("changed file")
276
272
target = BzrDir.create_branch_and_repo("target/")
277
273
source = Branch.open(self.get_readonly_url("source/"))