~bzr-pqm/bzr/bzr.dev

2418.5.1 by John Arbash Meinel
Make a Branch helper which can create a very basic MemoryTree with history.
1
# Copyright (C) 2007 Canonical Ltd
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2418.5.1 by John Arbash Meinel
Make a Branch helper which can create a very basic MemoryTree with history.
16
17
"""Tests for Branch.revision_id_to_revno()"""
18
19
from bzrlib import errors
6164.2.1 by Jelmer Vernooij
Skip tests if the repository doesn't support ghosts.
20
from bzrlib.tests import TestNotApplicable
2418.5.1 by John Arbash Meinel
Make a Branch helper which can create a very basic MemoryTree with history.
21
4523.1.1 by Martin Pool
Rename tests.branch_implementations to per_branch
22
from bzrlib.tests.per_branch import TestCaseWithBranch
2418.5.1 by John Arbash Meinel
Make a Branch helper which can create a very basic MemoryTree with history.
23
24
25
class TestRevisionIdToRevno(TestCaseWithBranch):
26
27
    def test_simple_revno(self):
28
        tree = self.create_tree_with_merge()
29
        the_branch = tree.branch
30
2598.5.3 by Aaron Bentley
Push NULL_REVISION deeper
31
        self.assertEqual(0, the_branch.revision_id_to_revno('null:'))
2418.5.1 by John Arbash Meinel
Make a Branch helper which can create a very basic MemoryTree with history.
32
        self.assertEqual(1, the_branch.revision_id_to_revno('rev-1'))
33
        self.assertEqual(2, the_branch.revision_id_to_revno('rev-2'))
34
        self.assertEqual(3, the_branch.revision_id_to_revno('rev-3'))
35
36
        self.assertRaises(errors.NoSuchRevision,
37
                          the_branch.revision_id_to_revno, 'rev-none')
38
        # revision_id_to_revno is defined as returning only integer revision
39
        # numbers, so non-mainline revisions get NoSuchRevision raised
40
        self.assertRaises(errors.NoSuchRevision,
41
                          the_branch.revision_id_to_revno, 'rev-1.1.1')
42
5689.2.1 by Jelmer Vernooij
Properly raise GhostsHaveNoRevno in revision_id_to_revno.
43
    def test_mainline_ghost(self):
44
        tree = self.make_branch_and_tree('tree1')
6164.2.1 by Jelmer Vernooij
Skip tests if the repository doesn't support ghosts.
45
        if not tree.branch.repository._format.supports_ghosts:
46
            raise TestNotApplicable("repository format does not support ghosts")
5689.2.1 by Jelmer Vernooij
Properly raise GhostsHaveNoRevno in revision_id_to_revno.
47
        tree.set_parent_ids(["spooky"], allow_leftmost_as_ghost=True)
48
        tree.add('')
49
        tree.commit('msg1', rev_id='rev1')
50
        tree.commit('msg2', rev_id='rev2')
51
        # Some older branch formats store the full known revision history
52
        # and thus can't distinguish between not being able to find a revno because of
53
        # a ghost and the revision not being on the mainline. As such,
54
        # allow both NoSuchRevision and GhostRevisionsHaveNoRevno here.
55
        self.assertRaises((errors.NoSuchRevision, errors.GhostRevisionsHaveNoRevno),
56
            tree.branch.revision_id_to_revno, "unknown")
57
        self.assertEquals(1, tree.branch.revision_id_to_revno("rev1"))
58
        self.assertEquals(2, tree.branch.revision_id_to_revno("rev2"))
6263.1.1 by Jelmer Vernooij
Support looking up revision numbers by revision id in empty branches.
59
60
    def test_empty(self):
61
        branch = self.make_branch('.')
62
        self.assertRaises(errors.NoSuchRevision,
63
            branch.revision_id_to_revno, "unknown")
64
        self.assertEquals(0, branch.revision_id_to_revno('null:'))