/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
3221.11.3 by Robert Collins
Add missing test script.
1
# Copyright (C) 2008 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
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
17
"""Tests for Branch.get_stacked_on and set_stacked_on."""
18
3517.4.12 by Martin Pool
Clearer per-branch-format tests for stacking
19
from bzrlib import (
20
    bzrdir,
21
    errors,
22
    )
23
from bzrlib.revision import NULL_REVISION
3221.11.3 by Robert Collins
Add missing test script.
24
from bzrlib.tests import TestNotApplicable
25
from bzrlib.tests.branch_implementations import TestCaseWithBranch
26
27
28
class TestStacking(TestCaseWithBranch):
29
30
    def test_get_set_stacked_on(self):
31
        # branches must either:
32
        # raise UnstackableBranchFormat or
33
        # raise UnstackableRepositoryFormat or
34
        # permit stacking to be done and then return the stacked location.
35
        branch = self.make_branch('branch')
36
        target = self.make_branch('target')
37
        old_format_errors = (
38
            errors.UnstackableBranchFormat,
39
            errors.UnstackableRepositoryFormat,
40
            )
41
        try:
42
            branch.set_stacked_on(target.base)
43
        except old_format_errors:
44
            # if the set failed, so must the get
45
            self.assertRaises(old_format_errors, branch.get_stacked_on)
46
            return
47
        # now we have a stacked branch:
3221.11.6 by Robert Collins
Stackable branch fixes.
48
        self.assertEqual(target.base, branch.get_stacked_on())
3221.11.3 by Robert Collins
Add missing test script.
49
        branch.set_stacked_on(None)
3221.11.6 by Robert Collins
Stackable branch fixes.
50
        self.assertRaises(errors.NotStacked, branch.get_stacked_on)
3221.13.2 by Robert Collins
Add a shallow parameter to bzrdir.sprout, which involved fixing a lateny bug in pack to pack fetching with ghost discovery.
51
3517.4.12 by Martin Pool
Clearer per-branch-format tests for stacking
52
    def assertRevisionInRepository(self, repo_path, revid):
53
        """Check that a revision is in a repository, disregarding stacking."""
54
        repo = bzrdir.BzrDir.open(repo_path).open_repository()
55
        self.assertTrue(repo.has_revision(revid))
56
57
    def assertRevisionNotInRepository(self, repo_path, revid):
58
        """Check that a revision is not in a repository, disregarding stacking."""
59
        repo = bzrdir.BzrDir.open(repo_path).open_repository()
60
        self.assertFalse(repo.has_revision(revid))
61
62
    def test_get_graph_stacked(self):
63
        """A stacked repository shows the graph of its parent."""
64
        trunk_tree = self.make_branch_and_tree('mainline')
65
        trunk_revid = trunk_tree.commit('mainline')
66
        # make a new branch, and stack on the existing one.  we don't use
67
        # sprout(stacked=True) here because if that is buggy and copies data
68
        # it would cause a false pass of this test.
69
        new_branch = self.make_branch('new_branch')
70
        try:
71
            new_branch.set_stacked_on(trunk_tree.branch.base)
72
        except (errors.UnstackableBranchFormat,
73
            errors.UnstackableRepositoryFormat), e:
74
            raise TestNotApplicable(e)
75
        # reading the graph from the stacked branch's repository should see
76
        # data from the stacked-on branch
77
        new_repo = new_branch.repository
78
        new_repo.lock_read()
79
        try:
80
            self.assertEqual(new_repo.get_parent_map([trunk_revid]),
81
                {trunk_revid: (NULL_REVISION, )})
82
        finally:
83
            new_repo.unlock()
84
85
    def test_sprout_stacked(self):
3221.13.2 by Robert Collins
Add a shallow parameter to bzrdir.sprout, which involved fixing a lateny bug in pack to pack fetching with ghost discovery.
86
        # We have a mainline
87
        trunk_tree = self.make_branch_and_tree('mainline')
88
        trunk_revid = trunk_tree.commit('mainline')
3221.18.4 by Ian Clatworthy
shallow -> stacked
89
        # and make branch from it which is stacked
3221.13.2 by Robert Collins
Add a shallow parameter to bzrdir.sprout, which involved fixing a lateny bug in pack to pack fetching with ghost discovery.
90
        try:
3221.18.4 by Ian Clatworthy
shallow -> stacked
91
            new_dir = trunk_tree.bzrdir.sprout('newbranch', stacked=True)
92
        except (errors.UnstackableBranchFormat,
3517.4.12 by Martin Pool
Clearer per-branch-format tests for stacking
93
            errors.UnstackableRepositoryFormat), e:
94
            raise TestNotApplicable(e)
95
        # stacked repository
96
        self.assertRevisionNotInRepository('newbranch', trunk_revid)
3221.13.2 by Robert Collins
Add a shallow parameter to bzrdir.sprout, which involved fixing a lateny bug in pack to pack fetching with ghost discovery.
97
        new_tree = new_dir.open_workingtree()
98
        new_tree.commit('something local')