~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/branch_implementations/test_stacking.py

Merge with shallow-branch

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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:
 
44
        self.assertEqual(target.base, branch.get_stacked_on())
 
45
        branch.set_stacked_on(None)
 
46
        self.assertRaises(errors.NotStacked, branch.get_stacked_on)
 
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')
 
52
        # and make branch from it which is shallow
 
53
        try:
 
54
            new_dir = trunk_tree.bzrdir.sprout('newbranch', shallow=True)
 
55
        except (errors.UnstackableBranchFormat, errors.UnstackableRepositoryFormat):
 
56
            # not a testable combination.
 
57
            return
 
58
        new_tree = new_dir.open_workingtree()
 
59
        new_tree.commit('something local')
 
60