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."""
21
from __future__ import absolute_import
25
from ..object_store import BazaarObjectStore
33
class BranchNameRefConversionTests(tests.TestCase):
36
self.assertEqual("", ref_to_branch_name(b"HEAD"))
37
self.assertEqual(b"HEAD", branch_name_to_ref(""))
40
self.assertRaises(ValueError, ref_to_branch_name, b"refs/tags/FOO")
42
def test_branch(self):
43
self.assertEqual("frost", ref_to_branch_name(b"refs/heads/frost"))
44
self.assertEqual(b"refs/heads/frost", branch_name_to_ref("frost"))
47
class BazaarRefsContainerTests(tests.TestCaseWithTransport):
50
tree = self.make_branch_and_tree('.')
51
store = BazaarObjectStore(tree.branch.repository)
52
refs = BazaarRefsContainer(tree.controldir, store)
53
self.assertEqual(refs.as_dict(), {})
55
def test_some_commit(self):
56
tree = self.make_branch_and_tree('.')
57
revid = tree.commit('somechange')
58
store = BazaarObjectStore(tree.branch.repository)
59
refs = BazaarRefsContainer(tree.controldir, store)
62
{b'HEAD': store._lookup_revision_sha1(revid)})
64
def test_some_tag(self):
65
tree = self.make_branch_and_tree('.')
66
revid = tree.commit('somechange')
67
tree.branch.tags.set_tag('sometag', revid)
68
store = BazaarObjectStore(tree.branch.repository)
69
refs = BazaarRefsContainer(tree.controldir, store)
72
{b'HEAD': store._lookup_revision_sha1(revid),
73
b'refs/tags/sometag': store._lookup_revision_sha1(revid),
76
def test_some_branch(self):
77
tree = self.make_branch_and_tree('.')
78
revid = tree.commit('somechange')
79
otherbranch = tree.controldir.create_branch(name='otherbranch')
80
otherbranch.generate_revision_history(revid)
81
store = BazaarObjectStore(tree.branch.repository)
82
refs = BazaarRefsContainer(tree.controldir, store)
85
{b'HEAD': store._lookup_revision_sha1(revid),
86
b'refs/heads/otherbranch': store._lookup_revision_sha1(revid),