1
# Copyright (C) 2010-2018 Jelmer Vernooij <jelmer@jelmer.uk>
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
"""Tests for ref handling."""
23
from ..object_store import BazaarObjectStore
31
class BranchNameRefConversionTests(tests.TestCase):
34
self.assertEqual("", ref_to_branch_name(b"HEAD"))
35
self.assertEqual(b"HEAD", branch_name_to_ref(""))
38
self.assertRaises(ValueError, ref_to_branch_name, b"refs/tags/FOO")
40
def test_branch(self):
41
self.assertEqual("frost", ref_to_branch_name(b"refs/heads/frost"))
42
self.assertEqual(b"refs/heads/frost", branch_name_to_ref("frost"))
45
class BazaarRefsContainerTests(tests.TestCaseWithTransport):
48
tree = self.make_branch_and_tree('.')
49
store = BazaarObjectStore(tree.branch.repository)
50
refs = BazaarRefsContainer(tree.controldir, store)
51
self.assertEqual(refs.as_dict(), {})
53
def test_some_commit(self):
54
tree = self.make_branch_and_tree('.')
55
revid = tree.commit('somechange')
56
store = BazaarObjectStore(tree.branch.repository)
57
refs = BazaarRefsContainer(tree.controldir, store)
60
{b'HEAD': store._lookup_revision_sha1(revid)})
62
def test_some_tag(self):
63
tree = self.make_branch_and_tree('.')
64
revid = tree.commit('somechange')
65
tree.branch.tags.set_tag('sometag', revid)
66
store = BazaarObjectStore(tree.branch.repository)
67
refs = BazaarRefsContainer(tree.controldir, store)
70
{b'HEAD': store._lookup_revision_sha1(revid),
71
b'refs/tags/sometag': store._lookup_revision_sha1(revid),
74
def test_some_branch(self):
75
tree = self.make_branch_and_tree('.')
76
revid = tree.commit('somechange')
77
otherbranch = tree.controldir.create_branch(name='otherbranch')
78
otherbranch.generate_revision_history(revid)
79
store = BazaarObjectStore(tree.branch.repository)
80
refs = BazaarRefsContainer(tree.controldir, store)
83
{b'HEAD': store._lookup_revision_sha1(revid),
84
b'refs/heads/otherbranch': store._lookup_revision_sha1(revid),