1
# Copyright (C) 2007, 2009-2012, 2016 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
17
"""Tests for branch.last_revision_info."""
19
from bzrlib.revision import NULL_REVISION
20
from bzrlib.tests import TestCaseWithTransport
23
class TestLastRevisionInfo(TestCaseWithTransport):
25
def test_empty_branch(self):
26
# on an empty branch we want (0, NULL_REVISION)
27
branch = self.make_branch('branch')
28
self.assertEqual((0, NULL_REVISION), branch.last_revision_info())
30
def test_non_empty_branch(self):
31
# after the second commit we want (2, 'second-revid')
32
tree = self.make_branch_and_tree('branch')
33
tree.commit('1st post')
34
revid = tree.commit('2st post', allow_pointless=True)
35
self.assertEqual((2, revid), tree.branch.last_revision_info())
37
def test_import(self):
38
# importing and setting last revision
39
tree1 = self.make_branch_and_tree('branch1')
40
tree1.commit('1st post')
41
revid = tree1.commit('2st post', allow_pointless=True)
42
branch2 = self.make_branch('branch2')
43
self.assertEqual((2, revid),
44
branch2.import_last_revision_info_and_tags(tree1.branch, 2, revid))
45
self.assertEqual((2, revid), branch2.last_revision_info())
46
self.assertTrue(branch2.repository.has_revision(revid))
48
def test_import_lossy(self):
49
# importing with lossy=True works
50
tree1 = self.make_branch_and_tree('branch1')
51
tree1.commit('1st post')
52
revid = tree1.commit('2st post', allow_pointless=True)
53
branch2 = self.make_branch('branch2')
54
ret = branch2.import_last_revision_info_and_tags(tree1.branch, 2,
56
self.assertIsInstance(ret, tuple)
57
self.assertIsInstance(ret[0], int)
58
self.assertIsInstance(ret[1], str)
60
def test_same_repo(self):
61
# importing and setting last revision within the same repo
62
tree = self.make_branch_and_tree('branch1')
63
tree.commit('1st post')
64
revid = tree.commit('2st post', allow_pointless=True)
65
tree.branch.set_last_revision_info(0, NULL_REVISION)
66
tree.branch.import_last_revision_info_and_tags(tree.branch, 2, revid)
67
self.assertEqual((2, revid), tree.branch.last_revision_info())