1
# Copyright (C) 2009, 2010 Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
from bzrlib.tests.per_interbranch import (
21
TestCaseWithInterBranch,
25
class TestUpdateRevisions(TestCaseWithInterBranch):
28
super(TestUpdateRevisions, self).setUp()
29
self.tree1 = self.make_from_branch_and_tree('tree1')
30
rev1 = self.tree1.commit('one')
31
branch2 = self.make_to_branch('tree2')
32
branch2.repository.fetch(self.tree1.branch.repository)
33
self.tree1.branch.copy_content_into(branch2)
34
self.tree2 = branch2.bzrdir.create_workingtree()
36
def test_accepts_graph(self):
37
# An implementation may not use it, but it should allow a 'graph' to be
39
rev2 = self.tree2.commit('two')
41
self.tree1.lock_write()
42
self.addCleanup(self.tree1.unlock)
43
self.tree2.lock_read()
44
self.addCleanup(self.tree2.unlock)
45
graph = self.tree2.branch.repository.get_graph(
46
self.tree1.branch.repository)
48
self.tree1.branch.update_revisions(self.tree2.branch, graph=graph)
49
self.assertEqual((2, rev2), self.tree1.branch.last_revision_info())
51
def test_overwrite_ignores_diverged(self):
52
rev2 = self.tree1.commit('two')
53
rev2b = self.tree2.commit('alt two')
55
self.assertRaises(errors.DivergedBranches,
56
self.tree1.branch.update_revisions,
57
self.tree2.branch, overwrite=False)
58
# However, the revision should be copied into the repository
59
self.assertTrue(self.tree1.branch.repository.has_revision(rev2b))
61
self.tree1.branch.update_revisions(self.tree2.branch, overwrite=True)
62
self.assertEqual((2, rev2b), self.tree1.branch.last_revision_info())
64
def test_ignores_older_unless_overwrite(self):
65
rev2 = self.tree1.commit('two')
67
self.tree1.branch.update_revisions(self.tree2.branch)
68
self.assertEqual((2, rev2), self.tree1.branch.last_revision_info())
70
self.tree1.branch.update_revisions(self.tree2.branch, overwrite=True)