1904.2.2
by Martin Pool
Merge invalid-parent fix from John |
1 |
# Copyright (C) 2004, 2005, 2006 by Canonical Ltd
|
1887.1.1
by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines, |
2 |
#
|
1149
by Martin Pool
- make get_parent() be a method of Branch; add simple tests for it |
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.
|
|
1887.1.1
by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines, |
7 |
#
|
1149
by Martin Pool
- make get_parent() be a method of Branch; add simple tests for it |
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.
|
|
1887.1.1
by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines, |
12 |
#
|
1149
by Martin Pool
- make get_parent() be a method of Branch; add simple tests for it |
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 |
||
1711.2.46
by John Arbash Meinel
Allow backwards compatibility with absolute local paths in parent |
18 |
import cStringIO |
1152
by Martin Pool
- add test that branching sets the parent of the new branch |
19 |
import os |
1711.2.46
by John Arbash Meinel
Allow backwards compatibility with absolute local paths in parent |
20 |
import sys |
1534.4.26
by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create. |
21 |
|
1185.65.17
by Robert Collins
Merge from integration, mode-changes are broken. |
22 |
from bzrlib.branch import Branch |
1685.1.70
by Wouter van Heyst
working on get_parent, set_parent and relative urls, broken |
23 |
import bzrlib.errors |
24 |
from bzrlib.osutils import abspath, realpath, getcwd |
|
25 |
from bzrlib.urlutils import local_path_from_url, local_path_to_url, escape |
|
1534.4.26
by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create. |
26 |
from bzrlib.tests import TestCaseWithTransport |
1149
by Martin Pool
- make get_parent() be a method of Branch; add simple tests for it |
27 |
|
28 |
||
1211
by Martin Pool
doc |
29 |
"""Tests for Branch parent URL"""
|
30 |
||
1149
by Martin Pool
- make get_parent() be a method of Branch; add simple tests for it |
31 |
|
1534.4.26
by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create. |
32 |
class TestParent(TestCaseWithTransport): |
1185.65.17
by Robert Collins
Merge from integration, mode-changes are broken. |
33 |
|
1149
by Martin Pool
- make get_parent() be a method of Branch; add simple tests for it |
34 |
def test_no_default_parent(self): |
35 |
"""Branches should have no parent by default"""
|
|
1534.4.26
by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create. |
36 |
b = self.make_branch('.') |
1711.2.46
by John Arbash Meinel
Allow backwards compatibility with absolute local paths in parent |
37 |
self.assertEqual(None, b.get_parent()) |
1149
by Martin Pool
- make get_parent() be a method of Branch; add simple tests for it |
38 |
|
39 |
def test_set_get_parent(self): |
|
1614.2.14
by Olaf Conradi
Add test case for resetting parent in branch_implementations. |
40 |
"""Set, re-get and reset the parent"""
|
1534.4.26
by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create. |
41 |
b = self.make_branch('.') |
1185.50.94
by John Arbash Meinel
Updated web page url to http://bazaar-vcs.org |
42 |
url = 'http://bazaar-vcs.org/bzr/bzr.dev' |
1150
by Martin Pool
- add new Branch.set_parent and tests |
43 |
b.set_parent(url) |
1711.2.46
by John Arbash Meinel
Allow backwards compatibility with absolute local paths in parent |
44 |
self.assertEqual(url, b.get_parent()) |
45 |
self.assertEqual(url, b.control_files.get('parent').read().strip('\n')) |
|
1685.1.70
by Wouter van Heyst
working on get_parent, set_parent and relative urls, broken |
46 |
|
1614.2.14
by Olaf Conradi
Add test case for resetting parent in branch_implementations. |
47 |
b.set_parent(None) |
1711.2.46
by John Arbash Meinel
Allow backwards compatibility with absolute local paths in parent |
48 |
self.assertEqual(None, b.get_parent()) |
1685.1.70
by Wouter van Heyst
working on get_parent, set_parent and relative urls, broken |
49 |
|
50 |
b.set_parent('../other_branch') |
|
51 |
||
1711.2.46
by John Arbash Meinel
Allow backwards compatibility with absolute local paths in parent |
52 |
self.assertEqual(local_path_to_url('../other_branch'), b.get_parent()) |
1685.1.70
by Wouter van Heyst
working on get_parent, set_parent and relative urls, broken |
53 |
path = local_path_to_url('../yanb') |
54 |
b.set_parent(path) |
|
1711.2.46
by John Arbash Meinel
Allow backwards compatibility with absolute local paths in parent |
55 |
self.assertEqual('../yanb', |
56 |
b.control_files.get('parent').read().strip('\n')) |
|
57 |
self.assertEqual(path, b.get_parent()) |
|
1685.1.70
by Wouter van Heyst
working on get_parent, set_parent and relative urls, broken |
58 |
|
59 |
||
60 |
self.assertRaises(bzrlib.errors.InvalidURL, b.set_parent, u'\xb5') |
|
61 |
b.set_parent(escape(u'\xb5')) |
|
1864.7.1
by John Arbash Meinel
Let Branch.get_parent() return None if parent is not accessible, (bug #52976) |
62 |
self.assertEqual('%C2%B5', |
1711.2.46
by John Arbash Meinel
Allow backwards compatibility with absolute local paths in parent |
63 |
b.control_files.get('parent').read().strip('\n')) |
64 |
||
65 |
self.assertEqual(b.base + '%C2%B5', b.get_parent()) |
|
66 |
||
67 |
# Handle the case for older style absolute local paths
|
|
68 |
if sys.platform == 'win32': |
|
69 |
# TODO: jam 20060515 Do we want to special case Windows local
|
|
70 |
# paths as well? Nobody has complained about it.
|
|
71 |
pass
|
|
72 |
else: |
|
73 |
b.control_files.put('parent', cStringIO.StringIO('/local/abs/path')) |
|
74 |
self.assertEqual('file:///local/abs/path', b.get_parent()) |
|
1685.1.70
by Wouter van Heyst
working on get_parent, set_parent and relative urls, broken |
75 |
|
1864.7.1
by John Arbash Meinel
Let Branch.get_parent() return None if parent is not accessible, (bug #52976) |
76 |
def test_get_invalid_parent(self): |
77 |
b = self.make_branch('.') |
|
78 |
||
79 |
cwd = getcwd() |
|
80 |
n_dirs = len(cwd.split('/')) |
|
81 |
||
82 |
# Force the relative path to be something invalid
|
|
83 |
# This should attempt to go outside the filesystem
|
|
84 |
path = ('../'*(n_dirs+5)) + 'foo' |
|
85 |
b.control_files.put('parent', cStringIO.StringIO(path)) |
|
86 |
||
87 |
# With an invalid branch parent, just return None
|
|
1864.7.2
by John Arbash Meinel
Test that we copy the parent across properly (if it is available) |
88 |
self.assertRaises(bzrlib.errors.InaccessibleParent, b.get_parent) |
1864.7.1
by John Arbash Meinel
Let Branch.get_parent() return None if parent is not accessible, (bug #52976) |
89 |