1
# Copyright (C) 2009 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21
from breezy.bzr import (
22
branch as _mod_bzrbranch,
24
from breezy.tests import TestCaseWithTransport
27
class TestReference(TestCaseWithTransport):
29
def get_default_format(self):
30
return controldir.format_registry.make_controldir('development-subtree')
32
def test_no_args_lists(self):
33
tree = self.make_branch_and_tree('branch')
35
tree.add_reference(self.make_branch_and_tree('branch/path'))
36
tree.add_reference(self.make_branch_and_tree('branch/lath'))
37
tree.set_reference_info('path', 'http://example.org')
38
tree.set_reference_info('lath', 'http://example.org/2')
39
out, err = self.run_bzr('reference', working_dir='branch')
40
lines = out.splitlines()
41
self.assertEqual('lath http://example.org/2', lines[0])
42
self.assertEqual('path http://example.org', lines[1])
44
def make_tree_with_reference(self):
45
tree = self.make_branch_and_tree('tree')
46
subtree = self.make_branch_and_tree('tree/newpath')
47
tree.add_reference(subtree)
48
tree.set_reference_info('newpath', 'http://example.org')
49
tree.commit('add reference')
52
def test_uses_working_tree_location(self):
53
tree = self.make_tree_with_reference()
54
out, err = self.run_bzr('reference', working_dir='tree')
55
self.assertContainsRe(out, 'newpath http://example.org\n')
57
def test_uses_basis_tree_location(self):
58
tree = self.make_tree_with_reference()
59
tree.controldir.destroy_workingtree()
60
out, err = self.run_bzr('reference', working_dir='tree')
61
self.assertContainsRe(out, 'newpath http://example.org\n')
63
def test_one_arg_displays(self):
64
tree = self.make_tree_with_reference()
65
out, err = self.run_bzr('reference newpath', working_dir='tree')
66
self.assertEqual('newpath http://example.org\n', out)
68
def test_one_arg_uses_containing_tree(self):
69
tree = self.make_tree_with_reference()
70
out, err = self.run_bzr('reference -d tree newpath')
71
self.assertEqual('newpath http://example.org\n', out)
73
def test_two_args_sets(self):
74
tree = self.make_branch_and_tree('tree')
75
self.build_tree(['tree/file'])
77
out, err = self.run_bzr('reference -d tree file http://example.org')
78
location = tree.get_reference_info('file')
79
self.assertEqual('http://example.org', location)
80
self.assertEqual('', out)
81
self.assertEqual('', err)
83
def test_missing_file(self):
84
tree = self.make_branch_and_tree('tree')
85
out, err = self.run_bzr('reference file http://example.org',
86
working_dir='tree', retcode=3)
87
self.assertEqual('brz: ERROR: file is not versioned.\n', err)
89
def test_missing_file_forced(self):
90
tree = self.make_branch_and_tree('tree')
91
tree.add_reference(self.make_branch_and_tree('tree/file'))
92
out, err = self.run_bzr(
93
'reference --force-unversioned file http://example.org',
95
location = tree.get_reference_info('file')
96
self.assertEqual('http://example.org', location)
97
self.assertEqual('', out)
98
self.assertEqual('', err)