31
29
tree = self.make_branch_and_tree('branch')
32
30
self.build_tree_contents([('branch/a', 'foo\n')])
35
32
# 'bzr cat' without an option should cat the last revision
36
self.run_bzr(['cat', 'a'], retcode=3)
33
self.run_bzr(['cat', 'a'], retcode=3, working_dir='branch')
38
35
tree.commit(message='1')
39
self.build_tree_contents([('a', 'baz\n')])
41
# We use run_bzr_subprocess rather than run_bzr here so that we can
42
# test mangling of line-endings on Windows.
43
self.assertEquals(self.run_bzr_subprocess(['cat', 'a'])[0], 'foo\n')
36
self.build_tree_contents([('branch/a', 'baz\n')])
38
self.assertEquals('foo\n',
39
self.run_bzr(['cat', 'a'], working_dir='branch')[0])
41
# On Windows, we used to have a bug where newlines got changed into
42
# crlf, whereas cat ought to write out the file exactly as it's
43
# recorded (by default.) That problem can't be reproduced in-process,
44
# so we need just one test here that
45
self.assertEquals('foo\n',
46
self.run_bzr_subprocess(['cat', 'a'],
47
working_dir='branch')[0])
45
49
tree.commit(message='2')
46
self.assertEquals(self.run_bzr_subprocess(['cat', 'a'])[0], 'baz\n')
47
self.assertEquals(self.run_bzr_subprocess(
48
['cat', 'a', '-r', '1'])[0],
50
self.assertEquals(self.run_bzr_subprocess(
51
['cat', 'a', '-r', '-1'])[0],
51
'baz\n', self.run_bzr(['cat', 'a'], working_dir='branch')[0])
53
'foo\n', self.run_bzr(['cat', 'a', '-r', '1'],
54
working_dir='branch')[0])
56
'baz\n', self.run_bzr(['cat', 'a', '-r', '-1'],
57
working_dir='branch')[0])
54
59
rev_id = tree.branch.last_revision()
56
self.assertEquals(self.run_bzr_subprocess(
57
['cat', 'a', '-r', 'revid:%s' % rev_id])[0],
62
self.assertEquals(self.run_bzr_subprocess(
63
['cat', 'branch/a', '-r', 'revno:1:branch'])[0],
62
'baz\n', self.run_bzr(['cat', 'a', '-r', 'revid:%s' % rev_id],
63
working_dir='branch')[0])
65
self.assertEquals('foo\n',
66
self.run_bzr(['cat', 'branch/a',
67
'-r', 'revno:1:branch'])[0])
65
68
self.run_bzr(['cat', 'a'], retcode=3)
67
['cat', 'a', '-r', 'revno:1:branch-that-does-not-exist'],
69
self.run_bzr(['cat', 'a', '-r', 'revno:1:branch-that-does-not-exist'],
70
72
def test_cat_different_id(self):
71
73
"""'cat' works with old and new files"""
100
102
'cat b-tree --name-from-revision')
102
104
# get to the old file automatically
103
out, err = self.run_bzr_subprocess('cat d-rev')
105
out, err = self.run_bzr('cat d-rev')
104
106
self.assertEqual('bar\n', out)
105
107
self.assertEqual('', err)
108
self.run_bzr_subprocess('cat a-rev-tree --name-from-revision')
110
self.run_bzr('cat a-rev-tree --name-from-revision')
109
111
self.assertEqual('foo\n', out)
110
112
self.assertEqual('', err)
112
out, err = self.run_bzr_subprocess('cat a-rev-tree')
114
out, err = self.run_bzr('cat a-rev-tree')
113
115
self.assertEqual('baz\n', out)
114
116
self.assertEqual('', err)
116
118
# the actual file-id for e-rev doesn't exist in the old tree
117
out, err = self.run_bzr_subprocess('cat e-rev -rrevid:first')
119
out, err = self.run_bzr('cat e-rev -rrevid:first')
118
120
self.assertEqual('qux\n', out)
119
121
self.assertEqual('', err)
148
149
url = self.get_readonly_url() + '/README'
150
151
# Test unfiltered output
151
out, err = self.run_bzr_subprocess(['cat', url])
152
out, err = self.run_bzr(['cat', url])
152
153
self.assertEqual('contents of README\n', out)
154
155
# Test --filters option is legal but has no impact if no filters
155
out, err = self.run_bzr_subprocess(['cat', '--filters', url])
156
out, err = self.run_bzr(['cat', '--filters', url])
156
157
self.assertEqual('contents of README\n', out)
158
159
def test_cat_filters_applied(self):
216
217
wt.commit('Making sure there is a basis_tree available')
218
219
url = self.get_readonly_url() + '/a'
219
out, err = self.run_bzr_subprocess(['cat', '-d', url, 'README'])
220
out, err = self.run_bzr(['cat', '-d', url, 'README'])
220
221
self.assertEqual('contents of a/README\n', out)
224
class TestSmartServerCat(tests.TestCaseWithTransport):
226
def test_simple_branch_cat(self):
227
self.setup_smart_server_with_call_log()
228
t = self.make_branch_and_tree('branch')
229
self.build_tree_contents([('branch/foo', 'thecontents')])
232
self.reset_smart_call_log()
233
out, err = self.run_bzr(['cat', "%s/foo" % self.get_url('branch')])
234
# This figure represent the amount of work to perform this use case. It
235
# is entirely ok to reduce this number if a test fails due to rpc_count
236
# being too low. If rpc_count increases, more network roundtrips have
237
# become necessary for this use case. Please do not adjust this number
238
# upwards without agreement from bzr's network support maintainers.
239
self.assertLength(9, self.hpss_calls)
240
self.assertLength(1, self.hpss_connections)
241
self.assertThat(self.hpss_calls, ContainsNoVfsCalls)