15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
branch as _mod_branch,
22
from bzrlib.tests import TestCaseWithTransport
21
from breezy.bzr import (
22
branch as _mod_bzrbranch,
24
from breezy.tests import TestCaseWithTransport
25
27
class TestReference(TestCaseWithTransport):
27
def make_branch(self, location, format=None):
29
format = bzrdir.format_registry.make_bzrdir('1.9')
30
format.set_branch_format(_mod_branch.BzrBranchFormat8())
31
return TestCaseWithTransport.make_branch(self, location, format=format)
29
def get_default_format(self):
30
return controldir.format_registry.make_controldir('development-subtree')
33
32
def test_no_args_lists(self):
34
33
branch = self.make_branch('branch')
35
branch.set_reference_info('file-id', 'path', 'http://example.org')
36
branch.set_reference_info('file-id2', 'lath', 'http://example.org/2')
34
branch.set_reference_info('path', 'http://example.org', b'file-id')
35
branch.set_reference_info('lath', 'http://example.org/2', b'file-id2')
37
36
out, err = self.run_bzr('reference', working_dir='branch')
38
37
lines = out.splitlines()
39
38
self.assertEqual('lath http://example.org/2', lines[0])
42
41
def make_tree_with_reference(self):
43
42
tree = self.make_branch_and_tree('tree')
44
43
self.build_tree(['tree/newpath'])
45
tree.add('newpath', 'file-id')
46
tree.branch.set_reference_info('file-id', 'path', 'http://example.org')
47
tree.branch.set_reference_info('file-id2', 'lath',
48
'http://example.org/2')
44
tree.add('newpath', b'file-id')
45
tree.branch.set_reference_info(
46
'newpath', 'http://example.org', b'file-id')
47
tree.branch.set_reference_info('lath', 'http://example.org/2',
51
51
def test_uses_working_tree_location(self):
56
56
def test_uses_basis_tree_location(self):
57
57
tree = self.make_tree_with_reference()
58
58
tree.commit('add newpath')
59
tree.bzrdir.destroy_workingtree()
59
tree.controldir.destroy_workingtree()
60
60
out, err = self.run_bzr('reference', working_dir='tree')
61
61
self.assertContainsRe(out, 'newpath http://example.org\n')
73
73
def test_two_args_sets(self):
74
74
tree = self.make_branch_and_tree('tree')
75
75
self.build_tree(['tree/file'])
76
tree.add('file', 'file-id')
76
tree.add('file', b'file-id')
77
77
out, err = self.run_bzr('reference tree/file http://example.org')
78
path, location = tree.branch.get_reference_info('file-id')
78
location, file_id = tree.branch.get_reference_info('file')
79
79
self.assertEqual('http://example.org', location)
80
self.assertEqual('file', path)
80
self.assertEqual(b'file-id', file_id)
81
81
self.assertEqual('', out)
82
82
self.assertEqual('', err)
85
85
tree = self.make_branch_and_tree('tree')
86
86
out, err = self.run_bzr('reference file http://example.org',
87
87
working_dir='tree', retcode=3)
88
self.assertEqual('bzr: ERROR: file is not versioned.\n', err)
88
self.assertEqual('brz: ERROR: file is not versioned.\n', err)
90
def test_missing_file_forced(self):
91
tree = self.make_branch_and_tree('tree')
92
out, err = self.run_bzr(
93
'reference --force-unversioned file http://example.org',
95
location, file_id = tree.branch.get_reference_info('file')
96
self.assertEqual('http://example.org', location)
97
self.assertEqual('', out)
98
self.assertEqual('', err)