/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/git/tests/test_refs.py

  • Committer: Jelmer Vernooij
  • Date: 2017-07-23 22:06:41 UTC
  • mfrom: (6738 trunk)
  • mto: This revision was merged to the branch mainline in revision 6739.
  • Revision ID: jelmer@jelmer.uk-20170723220641-69eczax9bmv8d6kk
Merge trunk, address review comments.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2010-2018 Jelmer Vernooij <jelmer@jelmer.uk>
2
 
# vim: encoding=utf-8
3
 
#
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.
8
 
#
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.
13
 
#
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
17
 
 
18
 
 
19
 
"""Tests for ref handling."""
20
 
 
21
 
from ... import tests
22
 
 
23
 
from ..object_store import BazaarObjectStore
24
 
from ..refs import (
25
 
    BazaarRefsContainer,
26
 
    ref_to_branch_name,
27
 
    branch_name_to_ref,
28
 
    )
29
 
 
30
 
 
31
 
class BranchNameRefConversionTests(tests.TestCase):
32
 
 
33
 
    def test_head(self):
34
 
        self.assertEqual("", ref_to_branch_name(b"HEAD"))
35
 
        self.assertEqual(b"HEAD", branch_name_to_ref(""))
36
 
 
37
 
    def test_tag(self):
38
 
        self.assertRaises(ValueError, ref_to_branch_name, b"refs/tags/FOO")
39
 
 
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"))
43
 
 
44
 
 
45
 
class BazaarRefsContainerTests(tests.TestCaseWithTransport):
46
 
 
47
 
    def test_empty(self):
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(), {})
52
 
 
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)
58
 
        self.assertEqual(
59
 
            refs.as_dict(),
60
 
            {b'HEAD': store._lookup_revision_sha1(revid)})
61
 
 
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)
68
 
        self.assertEqual(
69
 
            refs.as_dict(),
70
 
            {b'HEAD': store._lookup_revision_sha1(revid),
71
 
             b'refs/tags/sometag': store._lookup_revision_sha1(revid),
72
 
             })
73
 
 
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)
81
 
        self.assertEqual(
82
 
            refs.as_dict(),
83
 
            {b'HEAD': store._lookup_revision_sha1(revid),
84
 
             b'refs/heads/otherbranch': store._lookup_revision_sha1(revid),
85
 
             })