/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: Robert Collins
  • Date: 2005-10-19 10:11:57 UTC
  • mfrom: (1185.16.78)
  • mto: This revision was merged to the branch mainline in revision 1470.
  • Revision ID: robertc@robertcollins.net-20051019101157-17438d311e746b4f
mergeĀ fromĀ upstream

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 __future__ import absolute_import
22
 
 
23
 
from ... import tests
24
 
 
25
 
from ..object_store import BazaarObjectStore
26
 
from ..refs import (
27
 
    BazaarRefsContainer,
28
 
    ref_to_branch_name,
29
 
    branch_name_to_ref,
30
 
    )
31
 
 
32
 
 
33
 
class BranchNameRefConversionTests(tests.TestCase):
34
 
 
35
 
    def test_head(self):
36
 
        self.assertEqual("", ref_to_branch_name(b"HEAD"))
37
 
        self.assertEqual(b"HEAD", branch_name_to_ref(""))
38
 
 
39
 
    def test_tag(self):
40
 
        self.assertRaises(ValueError, ref_to_branch_name, b"refs/tags/FOO")
41
 
 
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"))
45
 
 
46
 
 
47
 
class BazaarRefsContainerTests(tests.TestCaseWithTransport):
48
 
 
49
 
    def test_empty(self):
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(), {})
54
 
 
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)
60
 
        self.assertEqual(
61
 
            refs.as_dict(),
62
 
            {b'HEAD': store._lookup_revision_sha1(revid)})
63
 
 
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)
70
 
        self.assertEqual(
71
 
            refs.as_dict(),
72
 
            {b'HEAD': store._lookup_revision_sha1(revid),
73
 
             b'refs/tags/sometag': store._lookup_revision_sha1(revid),
74
 
             })
75
 
 
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)
83
 
        self.assertEqual(
84
 
            refs.as_dict(),
85
 
            {b'HEAD': store._lookup_revision_sha1(revid),
86
 
             b'refs/heads/otherbranch': store._lookup_revision_sha1(revid),
87
 
             })