1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
# Copyright (C) 2006-2010 Canonical Ltd
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
from bzrlib import (
errors,
revision as _mod_revision,
)
from bzrlib.tests import per_branch
"""Tests for branch.update()"""
class TestUpdate(per_branch.TestCaseWithBranch):
def test_update_unbound_works(self):
b = self.make_branch('.')
b.update()
self.assertEqual(_mod_revision.NULL_REVISION,
_mod_revision.ensure_null(b.last_revision()))
def test_update_prefix_returns_none(self):
# update in a branch when its a prefix of the master should
# indicate that no local changes were present.
master_tree = self.make_branch_and_tree('master')
child_tree = self.make_branch_and_tree('child')
try:
child_tree.branch.bind(master_tree.branch)
except errors.UpgradeRequired:
# old branch, cant test.
return
# commit to the child to make the last rev not-None.
child_tree.commit('foo', rev_id='foo', allow_pointless=True)
# update the master so we can commit there.
master_tree.update()
# commit to the master making the child tree out of date and a prefix.
master_tree.commit('bar', rev_id='bar', allow_pointless=True)
self.assertEqual(None, child_tree.branch.update())
def test_update_local_commits_returns_old_tip(self):
# update in a branch when its not a prefix of the master should
# return the previous tip and reset the revision history.
master_tree = self.make_branch_and_tree('master')
child_tree = self.make_branch_and_tree('child')
try:
child_tree.branch.bind(master_tree.branch)
except errors.UpgradeRequired:
# old branch, cant test.
return
# commit to the child to make the last rev not-None and skew it from master.
child_tree.commit('foo', rev_id='foo', allow_pointless=True, local=True)
# commit to the master making the child tree out of date and not a prefix.
master_tree.commit('bar', rev_id='bar', allow_pointless=True)
self.assertEqual('foo', child_tree.branch.update())
self.assertEqual(['bar'], child_tree.branch.revision_history())
class TestUpdateRevisions(per_branch.TestCaseWithBranch):
def test_accepts_graph(self):
# An implementation may not use it, but it should allow a 'graph' to be
# supplied
tree1 = self.make_branch_and_tree('tree1')
rev1 = tree1.commit('one')
tree2 = tree1.bzrdir.sprout('tree2').open_workingtree()
rev2 = tree2.commit('two')
tree1.lock_write()
self.addCleanup(tree1.unlock)
tree2.lock_read()
self.addCleanup(tree2.unlock)
graph = tree2.branch.repository.get_graph(tree1.branch.repository)
tree1.branch.update_revisions(tree2.branch, graph=graph)
self.assertEqual((2, rev2), tree1.branch.last_revision_info())
def test_overwrite_ignores_diverged(self):
tree1 = self.make_branch_and_tree('tree1')
rev1 = tree1.commit('one')
tree2 = tree1.bzrdir.sprout('tree2').open_workingtree()
rev2 = tree1.commit('two')
rev2b = tree2.commit('alt two')
self.assertRaises(errors.DivergedBranches,
tree1.branch.update_revisions,
tree2.branch, overwrite=False)
# However, the revision should be copied into the repository
self.assertTrue(tree1.branch.repository.has_revision(rev2b))
tree1.branch.update_revisions(tree2.branch, overwrite=True)
self.assertEqual((2, rev2b), tree1.branch.last_revision_info())
def test_ignores_older_unless_overwrite(self):
tree1 = self.make_branch_and_tree('tree1')
rev1 = tree1.commit('one')
tree2 = tree1.bzrdir.sprout('tree2').open_workingtree()
rev2 = tree1.commit('two')
tree1.branch.update_revisions(tree2.branch)
self.assertEqual((2, rev2), tree1.branch.last_revision_info())
tree1.branch.update_revisions(tree2.branch, overwrite=True)
self.assertEqual((1, rev1), tree1.branch.last_revision_info())
|