24
from bzrlib.tests.blackbox import TestCaseWithTransport
24
from bzrlib.branch import Branch
25
from bzrlib.tests import TestCaseInTempDir
26
class TestCat(TestCaseWithTransport):
27
class TestCat(TestCaseInTempDir):
28
29
def test_cat(self):
30
31
def bzr(*args, **kwargs):
31
return self.run_bzr_subprocess(*args, **kwargs)[0]
32
return self.run_bzr(*args, **kwargs)[0]
60
61
bzr('cat', 'a', retcode=3)
61
62
bzr('cat', 'a', '-r', 'revno:1:branch-that-does-not-exist', retcode=3)
63
def test_cat_different_id(self):
64
"""'cat' works with old and new files"""
65
tree = self.make_branch_and_tree('.')
66
# the files are named after their path in the revision and
67
# current trees later in the test case
68
# a-rev-tree is special because it appears in both the revision
69
# tree and the working tree
70
self.build_tree_contents([('a-rev-tree', 'foo\n'),
71
('c-rev', 'baz\n'), ('d-rev', 'bar\n')])
74
tree.add(['a-rev-tree', 'c-rev', 'd-rev'])
75
tree.commit('add test files')
76
# remove currently uses self._write_inventory -
77
# work around that for now.
79
tree.remove(['d-rev'])
80
tree.rename_one('a-rev-tree', 'b-tree')
81
tree.rename_one('c-rev', 'a-rev-tree')
83
# calling bzr as another process require free lock on win32
86
# 'b-tree' is not present in the old tree.
87
self.run_bzr_error(["^bzr: ERROR: u?'b-tree' "
88
"is not present in revision .+$"],
89
'cat b-tree --name-from-revision')
91
# get to the old file automatically
92
out, err = self.run_bzr('cat d-rev')
93
self.assertEqual('bar\n', out)
94
self.assertEqual('', err)
96
out, err = self.run_bzr('cat a-rev-tree --name-from-revision')
97
self.assertEqual('foo\n', out)
98
self.assertEqual('', err)
100
out, err = self.run_bzr('cat a-rev-tree')
101
self.assertEqual('baz\n', out)
102
self.assertEqual('', err)
104
def test_remote_cat(self):
105
wt = self.make_branch_and_tree('.')
106
self.build_tree(['README'])
108
wt.commit('Making sure there is a basis_tree available')
110
url = self.get_readonly_url() + '/README'
111
out, err = self.run_bzr(['cat', url])
112
self.assertEqual('contents of README\n', out)
114
def test_cat_no_working_tree(self):
115
wt = self.make_branch_and_tree('.')
116
self.build_tree(['README'])
118
wt.commit('Making sure there is a basis_tree available')
119
wt.branch.bzrdir.destroy_workingtree()
121
url = self.get_readonly_url() + '/README'
122
out, err = self.run_bzr(['cat', url])
123
self.assertEqual('contents of README\n', out)