30
29
tree = self.make_branch_and_tree('branch')
31
30
self.build_tree_contents([('branch/a', 'foo\n')])
34
32
# 'bzr cat' without an option should cat the last revision
35
self.run_bzr(['cat', 'a'], retcode=3)
33
self.run_bzr(['cat', 'a'], retcode=3, working_dir='branch')
37
35
tree.commit(message='1')
38
self.build_tree_contents([('a', 'baz\n')])
36
self.build_tree_contents([('branch/a', 'baz\n')])
40
self.assertEquals(self.run_bzr(['cat', 'a'])[0], 'foo\n')
38
self.assertEqual('foo\n',
39
self.run_bzr(['cat', 'a'], working_dir='branch')[0])
42
41
# On Windows, we used to have a bug where newlines got changed into
43
42
# crlf, whereas cat ought to write out the file exactly as it's
44
43
# recorded (by default.) That problem can't be reproduced in-process,
45
44
# so we need just one test here that
46
self.assertEquals(self.run_bzr_subprocess(['cat', 'a'])[0], 'foo\n')
45
self.assertEqual('foo\n',
46
self.run_bzr_subprocess(['cat', 'a'],
47
working_dir='branch')[0])
48
49
tree.commit(message='2')
49
self.assertEquals(self.run_bzr(['cat', 'a'])[0], 'baz\n')
50
self.assertEquals(self.run_bzr(
51
['cat', 'a', '-r', '1'])[0],
53
self.assertEquals(self.run_bzr(
54
['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])
57
59
rev_id = tree.branch.last_revision()
59
self.assertEquals(self.run_bzr(
60
['cat', 'a', '-r', 'revid:%s' % rev_id])[0],
65
self.assertEquals(self.run_bzr(
66
['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.assertEqual('foo\n',
66
self.run_bzr(['cat', 'branch/a',
67
'-r', 'revno:1:branch'])[0])
68
68
self.run_bzr(['cat', 'a'], retcode=3)
70
['cat', 'a', '-r', 'revno:1:branch-that-does-not-exist'],
69
self.run_bzr(['cat', 'a', '-r', 'revno:1:branch-that-does-not-exist'],
73
72
def test_cat_different_id(self):
74
73
"""'cat' works with old and new files"""
221
219
url = self.get_readonly_url() + '/a'
222
220
out, err = self.run_bzr(['cat', '-d', url, 'README'])
223
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)