1
# Copyright (C) 2007, 2009-2012, 2016 Canonical Ltd
1
# Copyright (C) 2004, 2005, 2007 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
13
13
# You should have received a copy of the GNU General Public License
14
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
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
17
"""Tests for branch.last_revision_info."""
26
26
# on an empty branch we want (0, NULL_REVISION)
27
27
branch = self.make_branch('branch')
28
28
self.assertEqual((0, NULL_REVISION), branch.last_revision_info())
30
30
def test_non_empty_branch(self):
31
31
# after the second commit we want (2, 'second-revid')
32
32
tree = self.make_branch_and_tree('branch')
33
33
tree.commit('1st post')
34
34
revid = tree.commit('2st post', allow_pointless=True)
35
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())