1
# Copyright (C) 2006 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
revision as _mod_revision,
22
from bzrlib.tests.per_branch.test_branch import TestCaseWithBranch
25
"""Tests for branch.update()"""
28
class TestUpdate(TestCaseWithBranch):
30
def test_update_unbound_works(self):
31
b = self.make_branch('.')
33
self.assertEqual(_mod_revision.NULL_REVISION,
34
_mod_revision.ensure_null(b.last_revision()))
36
def test_update_prefix_returns_none(self):
37
# update in a branch when its a prefix of the master should
38
# indicate that no local changes were present.
39
master_tree = self.make_branch_and_tree('master')
40
child_tree = self.make_branch_and_tree('child')
42
child_tree.branch.bind(master_tree.branch)
43
except errors.UpgradeRequired:
44
# old branch, cant test.
46
# commit to the child to make the last rev not-None.
47
child_tree.commit('foo', rev_id='foo', allow_pointless=True)
48
# update the master so we can commit there.
50
# commit to the master making the child tree out of date and a prefix.
51
master_tree.commit('bar', rev_id='bar', allow_pointless=True)
52
self.assertEqual(None, child_tree.branch.update())
54
def test_update_local_commits_returns_old_tip(self):
55
# update in a branch when its not a prefix of the master should
56
# return the previous tip and reset the revision history.
57
master_tree = self.make_branch_and_tree('master')
58
child_tree = self.make_branch_and_tree('child')
60
child_tree.branch.bind(master_tree.branch)
61
except errors.UpgradeRequired:
62
# old branch, cant test.
64
# commit to the child to make the last rev not-None and skew it from master.
65
child_tree.commit('foo', rev_id='foo', allow_pointless=True, local=True)
66
# commit to the master making the child tree out of date and not a prefix.
67
master_tree.commit('bar', rev_id='bar', allow_pointless=True)
68
self.assertEqual('foo', child_tree.branch.update())
69
self.assertEqual(['bar'], child_tree.branch.revision_history())
72
class TestUpdateRevisions(TestCaseWithBranch):
74
def test_accepts_graph(self):
75
# An implementation may not use it, but it should allow a 'graph' to be
77
tree1 = self.make_branch_and_tree('tree1')
78
rev1 = tree1.commit('one')
79
tree2 = tree1.bzrdir.sprout('tree2').open_workingtree()
80
rev2 = tree2.commit('two')
83
self.addCleanup(tree1.unlock)
85
self.addCleanup(tree2.unlock)
86
graph = tree2.branch.repository.get_graph(tree1.branch.repository)
88
tree1.branch.update_revisions(tree2.branch, graph=graph)
89
self.assertEqual((2, rev2), tree1.branch.last_revision_info())
91
def test_overwrite_ignores_diverged(self):
92
tree1 = self.make_branch_and_tree('tree1')
93
rev1 = tree1.commit('one')
94
tree2 = tree1.bzrdir.sprout('tree2').open_workingtree()
95
rev2 = tree1.commit('two')
96
rev2b = tree2.commit('alt two')
98
self.assertRaises(errors.DivergedBranches,
99
tree1.branch.update_revisions,
100
tree2.branch, overwrite=False)
101
# However, the revision should be copied into the repository
102
self.assertTrue(tree1.branch.repository.has_revision(rev2b))
104
tree1.branch.update_revisions(tree2.branch, overwrite=True)
105
self.assertEqual((2, rev2b), tree1.branch.last_revision_info())
107
def test_ignores_older_unless_overwrite(self):
108
tree1 = self.make_branch_and_tree('tree1')
109
rev1 = tree1.commit('one')
110
tree2 = tree1.bzrdir.sprout('tree2').open_workingtree()
111
rev2 = tree1.commit('two')
113
tree1.branch.update_revisions(tree2.branch)
114
self.assertEqual((2, rev2), tree1.branch.last_revision_info())
116
tree1.branch.update_revisions(tree2.branch, overwrite=True)
117
self.assertEqual((1, rev1), tree1.branch.last_revision_info())