1
# Copyright (C) 2008 Canonical Ltd
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.
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.
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
17
"""Tests for Branch.get_stacked_on and set_stacked_on."""
19
from bzrlib import errors
20
from bzrlib.tests import TestNotApplicable
21
from bzrlib.tests.branch_implementations import TestCaseWithBranch
24
class TestStacking(TestCaseWithBranch):
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')
34
errors.UnstackableBranchFormat,
35
errors.UnstackableRepositoryFormat,
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)
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)
48
def test_set_stacked_on_fetches(self):
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
54
new_dir = trunk_tree.bzrdir.sprout('newbranch', shallow=True)
55
except (errors.UnstackableBranchFormat, errors.UnstackableRepositoryFormat):
56
# not a testable combination.
58
new_tree = new_dir.open_workingtree()
59
new_tree.commit('something local')