15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
"""Black-box tests for brz cat.
18
"""Black-box tests for bzr cat.
22
from ..matchers import ContainsNoVfsCalls
23
from ...transport import memory
21
from bzrlib import tests
22
from bzrlib.tests.matchers import ContainsNoVfsCalls
23
from bzrlib.transport import memory
26
26
class TestCat(tests.TestCaseWithTransport):
28
28
def test_cat(self):
29
29
tree = self.make_branch_and_tree('branch')
30
self.build_tree_contents([('branch/a', b'foo\n')])
30
self.build_tree_contents([('branch/a', 'foo\n')])
32
# 'brz cat' without an option should cat the last revision
32
# 'bzr cat' without an option should cat the last revision
33
33
self.run_bzr(['cat', 'a'], retcode=3, working_dir='branch')
35
35
tree.commit(message='1')
36
self.build_tree_contents([('branch/a', b'baz\n')])
36
self.build_tree_contents([('branch/a', 'baz\n')])
38
self.assertEqual('foo\n',
38
self.assertEquals('foo\n',
39
39
self.run_bzr(['cat', 'a'], working_dir='branch')[0])
41
41
# On Windows, we used to have a bug where newlines got changed into
42
42
# crlf, whereas cat ought to write out the file exactly as it's
43
43
# recorded (by default.) That problem can't be reproduced in-process,
44
44
# so we need just one test here that
45
self.assertEqual('foo\n',
45
self.assertEquals('foo\n',
46
46
self.run_bzr_subprocess(['cat', 'a'],
47
47
working_dir='branch')[0])
49
49
tree.commit(message='2')
51
51
'baz\n', self.run_bzr(['cat', 'a'], working_dir='branch')[0])
53
53
'foo\n', self.run_bzr(['cat', 'a', '-r', '1'],
54
54
working_dir='branch')[0])
56
56
'baz\n', self.run_bzr(['cat', 'a', '-r', '-1'],
57
57
working_dir='branch')[0])
59
59
rev_id = tree.branch.last_revision()
62
62
'baz\n', self.run_bzr(['cat', 'a', '-r', 'revid:%s' % rev_id],
63
63
working_dir='branch')[0])
65
self.assertEqual('foo\n',
65
self.assertEquals('foo\n',
66
66
self.run_bzr(['cat', 'branch/a',
67
67
'-r', 'revno:1:branch'])[0])
68
68
self.run_bzr(['cat', 'a'], retcode=3)
77
77
# current trees later in the test case
78
78
# a-rev-tree is special because it appears in both the revision
79
79
# tree and the working tree
80
self.build_tree_contents([('a-rev-tree', b'foo\n'),
81
('c-rev', b'baz\n'), ('d-rev', b'bar\n'), ('e-rev', b'qux\n')])
82
with tree.lock_write():
80
self.build_tree_contents([('a-rev-tree', 'foo\n'),
81
('c-rev', 'baz\n'), ('d-rev', 'bar\n'), ('e-rev', 'qux\n')])
83
84
tree.add(['a-rev-tree', 'c-rev', 'd-rev', 'e-rev'])
84
tree.commit('add test files', rev_id=b'first')
85
tree.commit('add test files', rev_id='first')
85
86
# remove currently uses self._write_inventory -
86
87
# work around that for now.
89
90
tree.rename_one('a-rev-tree', 'b-tree')
90
91
tree.rename_one('c-rev', 'a-rev-tree')
91
92
tree.rename_one('e-rev', 'old-rev')
92
self.build_tree_contents([('e-rev', b'new\n')])
93
self.build_tree_contents([('e-rev', 'new\n')])
93
94
tree.add(['e-rev'])
96
# calling bzr as another process require free lock on win32
95
99
# 'b-tree' is not present in the old tree.
96
self.run_bzr_error(["^brz: ERROR: u?'b-tree' "
100
self.run_bzr_error(["^bzr: ERROR: u?'b-tree' "
97
101
"is not present in revision .+$"],
98
102
'cat b-tree --name-from-revision')
100
104
# get to the old file automatically
101
105
out, err = self.run_bzr('cat d-rev')
102
self.assertEqual('', err)
103
106
self.assertEqual('bar\n', out)
107
self.assertEqual('', err)
106
110
self.run_bzr('cat a-rev-tree --name-from-revision')
157
161
# subprocess because we really need to patch in a plugin that
158
162
# registers the filters. Instead, we patch in a custom
159
163
# filter_stack and use run_bzr() ...
160
from ..test_filters import _stack_2
161
from ...tree import Tree
164
from cStringIO import StringIO
165
from bzrlib.commands import run_bzr
166
from bzrlib.tests.test_filters import _stack_2
167
from bzrlib.trace import mutter
168
from bzrlib.tree import Tree
162
169
wt = self.make_branch_and_tree('.')
163
170
self.build_tree_contents([
164
('README', b"junk\nline 1 of README\nline 2 of README\n"),
171
('README', "junk\nline 1 of README\nline 2 of README\n"),
167
174
wt.commit('Making sure there is a basis_tree available')