1
# Copyright (C) 2006 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
"""Test branches with inaccessible parents."""
21
from bzrlib import branch, errors
22
from bzrlib.tests.branch_implementations.test_branch import TestCaseWithBranch
23
from bzrlib.tests.http_server import HttpServer
24
from bzrlib.transport.local import LocalURLServer
25
from bzrlib.transport.chroot import TestingChrootServer
28
class InaccessibleParentTests(TestCaseWithBranch):
29
"""Tests with branches with "inaccessible" parents.
31
An "inaccessible" parent location is one that cannot be represented, e.g. if
32
a child branch says its parent is at "../../my-parent", but that child is at
33
"http://host/one" then that parent location is inaccessible. These
34
branches' get_parent method will raise InaccessibleParent.
38
super(InaccessibleParentTests, self).setUp()
39
if self.transport_server in (LocalURLServer, None):
40
self.transport_readonly_server = TestingChrootServer
42
def get_branch_with_invalid_parent(self):
43
"""Get a branch whose get_parent will raise InaccessibleParent."""
45
['parent/', 'parent/path/', 'parent/path/to/',
46
'child/', 'child/path/', 'child/path/to/'],
47
transport=self.get_transport())
48
self.make_branch('parent/path/to/a').bzrdir.sprout(self.get_url('child/path/to/b'))
50
# The child branch internally will have recorded that its parent is at
51
# "../../../../parent/path/to/a" or similar. So we move the child
52
# branch up several directories, so that its parent path will point to
53
# somewhere outside the directory served by the HTTP server. Thus its
54
# parent is now inaccessible.
55
self.get_transport().rename('child/path/to/b', 'b')
56
branch_b = branch.Branch.open(self.get_readonly_url('b'))
59
def test_get_parent_invalid(self):
60
# When you have a branch whose parent URL cannot be calculated, this
61
# exception will be raised.
62
branch_b = self.get_branch_with_invalid_parent()
63
self.assertRaises(errors.InaccessibleParent, branch_b.get_parent)
65
def test_clone_invalid_parent(self):
66
# If clone can't determine the location of the parent of the branch
67
# being cloned, then the new branch will have no parent set.
68
branch_b = self.get_branch_with_invalid_parent()
69
branch_c = branch_b.bzrdir.clone('c').open_branch()
70
self.assertEqual(None, branch_c.get_parent())
72
def test_sprout_invalid_parent(self):
73
# A sprouted branch will have a parent of the branch it was sprouted
74
# from, even if that branch has an invalid parent.
75
branch_b = self.get_branch_with_invalid_parent()
76
branch_c = branch_b.bzrdir.sprout('c').open_branch()
77
self.assertEqual(branch_b.base, branch_c.get_parent())