/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
19
from bzrlib import errors
20
from bzrlib.tests import TestNotApplicable
21
from bzrlib.tests.branch_implementations import TestCaseWithBranch
22
23
24
class TestStacking(TestCaseWithBranch):
25
26
    def test_get_set_stacked_on(self):
27
        # branches must either:
28
        # raise UnstackableBranchFormat or
29
        # raise UnstackableRepositoryFormat or
30
        # permit stacking to be done and then return the stacked location.
31
        branch = self.make_branch('branch')
32
        target = self.make_branch('target')
33
        old_format_errors = (
34
            errors.UnstackableBranchFormat,
35
            errors.UnstackableRepositoryFormat,
36
            )
37
        try:
38
            branch.set_stacked_on(target.base)
39
        except old_format_errors:
40
            # if the set failed, so must the get
41
            self.assertRaises(old_format_errors, branch.get_stacked_on)
42
            return
43
        # now we have a stacked branch:
3221.11.6 by Robert Collins
Stackable branch fixes.
44
        self.assertEqual(target.base, branch.get_stacked_on())
3221.11.3 by Robert Collins
Add missing test script.
45
        branch.set_stacked_on(None)
3221.11.6 by Robert Collins
Stackable branch fixes.
46
        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.
47
48
    def test_set_stacked_on_fetches(self):
49
        # We have a mainline
50
        trunk_tree = self.make_branch_and_tree('mainline')
51
        trunk_revid = trunk_tree.commit('mainline')
3221.18.4 by Ian Clatworthy
shallow -> stacked
52
        # 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.
53
        try:
3221.18.4 by Ian Clatworthy
shallow -> stacked
54
            new_dir = trunk_tree.bzrdir.sprout('newbranch', stacked=True)
55
        except (errors.UnstackableBranchFormat,
56
            errors.UnstackableRepositoryFormat):
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.
57
            # not a testable combination.
58
            return
59
        new_tree = new_dir.open_workingtree()
60
        new_tree.commit('something local')
61
3242.3.21 by Jonathan Lange
Preserve stacking in clone
62
    def test_clone_from_stacked_branch(self):
3242.3.24 by Aaron Bentley
Fix test failures
63
        # We can clone from the bzrdir of a stacked branch. If
64
        # preserve_stacking is True, the cloned branch is stacked on the
65
        # same branch as the original.
3242.3.21 by Jonathan Lange
Preserve stacking in clone
66
        tree = self.make_branch_and_tree('stacked-on')
67
        tree.commit('Added foo')
68
        try:
69
            stacked_bzrdir = tree.branch.bzrdir.sprout(
3242.3.24 by Aaron Bentley
Fix test failures
70
                'stacked', tree.branch.last_revision(), stacked=True)
3242.3.21 by Jonathan Lange
Preserve stacking in clone
71
        except (errors.UnstackableBranchFormat,
72
                errors.UnstackableRepositoryFormat):
73
            # not a testable combination.
74
            return
3242.3.24 by Aaron Bentley
Fix test failures
75
        cloned_bzrdir = stacked_bzrdir.clone('cloned', preserve_stacking=True)
3242.3.21 by Jonathan Lange
Preserve stacking in clone
76
        try:
77
            self.assertEqual(
78
                stacked_bzrdir.open_branch().get_stacked_on(),
79
                cloned_bzrdir.open_branch().get_stacked_on())
80
        except (errors.UnstackableBranchFormat,
81
                errors.UnstackableRepositoryFormat):
82
            pass
3242.3.24 by Aaron Bentley
Fix test failures
83
        cloned_unstacked_bzrdir = stacked_bzrdir.clone('cloned-unstacked',
84
                                                       preserve_stacking=False)
85
        unstacked_branch = cloned_unstacked_bzrdir.open_branch()
86
        self.assertRaises(errors.NotStacked, unstacked_branch.get_stacked_on)