24
25
from bzrlib.tests.blackbox import TestCaseWithTransport
26
27
class TestCat(TestCaseWithTransport):
28
29
def test_cat(self):
30
def bzr(*args, **kwargs):
31
return self.run_bzr_subprocess(*args, **kwargs)[0]
30
tree = self.make_branch_and_tree('branch')
31
self.build_tree_contents([('branch/a', 'foo\n')])
36
open('a', 'wb').write('foo\n')
39
34
# 'bzr cat' without an option should cat the last revision
40
bzr('cat', 'a', retcode=3)
42
bzr('commit', '-m', '1')
43
open('a', 'wb').write('baz\n')
45
self.assertEquals(bzr('cat', 'a'), 'foo\n')
47
bzr('commit', '-m', '2')
48
self.assertEquals(bzr('cat', 'a'), 'baz\n')
49
self.assertEquals(bzr('cat', 'a', '-r', '1'), 'foo\n')
50
self.assertEquals(bzr('cat', 'a', '-r', '-1'), 'baz\n')
52
rev_id = bzr('revision-history').strip().split('\n')[-1]
54
self.assertEquals(bzr('cat', 'a', '-r', 'revid:%s' % rev_id), 'baz\n')
35
self.run_bzr(['cat', 'a'], retcode=3)
37
tree.commit(message='1')
38
self.build_tree_contents([('a', 'baz\n')])
40
# We use run_bzr_subprocess rather than run_bzr here so that we can
41
# test mangling of line-endings on Windows.
42
self.assertEquals(self.run_bzr_subprocess(['cat', 'a'])[0], 'foo\n')
44
tree.commit(message='2')
45
self.assertEquals(self.run_bzr_subprocess(['cat', 'a'])[0], 'baz\n')
46
self.assertEquals(self.run_bzr_subprocess(
47
['cat', 'a', '-r', '1'])[0],
49
self.assertEquals(self.run_bzr_subprocess(
50
['cat', 'a', '-r', '-1'])[0],
53
rev_id = tree.branch.last_revision()
55
self.assertEquals(self.run_bzr_subprocess(
56
['cat', 'a', '-r', 'revid:%s' % rev_id])[0],
58
self.assertEquals(bzr('cat', 'branch/a', '-r', 'revno:1:branch'),
60
bzr('cat', 'a', retcode=3)
61
bzr('cat', 'a', '-r', 'revno:1:branch-that-does-not-exist', retcode=3)
61
self.assertEquals(self.run_bzr_subprocess(
62
['cat', 'branch/a', '-r', 'revno:1:branch'])[0],
64
self.run_bzr(['cat', 'a'], retcode=3)
66
['cat', 'a', '-r', 'revno:1:branch-that-does-not-exist'],
63
69
def test_cat_different_id(self):
64
70
"""'cat' works with old and new files"""
65
71
tree = self.make_branch_and_tree('.')
74
80
tree.add(['a-rev-tree', 'c-rev', 'd-rev'])
75
81
tree.commit('add test files')
82
# remove currently uses self._write_inventory -
83
# work around that for now.
76
85
tree.remove(['d-rev'])
77
86
tree.rename_one('a-rev-tree', 'b-tree')
78
87
tree.rename_one('c-rev', 'a-rev-tree')
80
# 'b-tree' is not present in the old tree.
81
self.run_bzr_error([], 'cat', 'b-tree', '--name-from-revision')
83
# get to the old file automatically
84
out, err = self.run_bzr('cat', 'd-rev')
85
self.assertEqual('bar\n', out)
86
self.assertEqual('', err)
88
out, err = self.run_bzr('cat', 'a-rev-tree',
89
'--name-from-revision')
90
self.assertEqual('foo\n', out)
91
self.assertEqual('', err)
93
out, err = self.run_bzr('cat', 'a-rev-tree')
94
self.assertEqual('baz\n', out)
95
self.assertEqual('', err)
89
# calling bzr as another process require free lock on win32
92
# 'b-tree' is not present in the old tree.
93
self.run_bzr_error(["^bzr: ERROR: u?'b-tree' "
94
"is not present in revision .+$"],
95
'cat b-tree --name-from-revision')
97
# get to the old file automatically
98
out, err = self.run_bzr_subprocess('cat d-rev')
99
self.assertEqual('bar\n', out)
100
self.assertEqual('', err)
103
self.run_bzr_subprocess('cat a-rev-tree --name-from-revision')
104
self.assertEqual('foo\n', out)
105
self.assertEqual('', err)
107
out, err = self.run_bzr_subprocess('cat a-rev-tree')
108
self.assertEqual('baz\n', out)
109
self.assertEqual('', err)
99
111
def test_remote_cat(self):
100
112
wt = self.make_branch_and_tree('.')
101
113
self.build_tree(['README'])
103
115
wt.commit('Making sure there is a basis_tree available')
105
117
url = self.get_readonly_url() + '/README'
106
out, err = self.run_bzr('cat', url)
107
self.assertEqual('contents of README\n', out)
118
out, err = self.run_bzr_subprocess(['cat', url])
119
self.assertEqual('contents of README\n', out)
121
def test_cat_no_working_tree(self):
122
wt = self.make_branch_and_tree('.')
123
self.build_tree(['README'])
125
wt.commit('Making sure there is a basis_tree available')
126
wt.branch.bzrdir.destroy_workingtree()
128
url = self.get_readonly_url() + '/README'
129
out, err = self.run_bzr_subprocess(['cat', url])
130
self.assertEqual('contents of README\n', out)
132
def test_cat_nonexistent_branch(self):
133
if sys.platform == "win32":
134
location = "C:/i/do/not/exist"
136
location = "/i/do/not/exist"
137
self.run_bzr_error(['^bzr: ERROR: Not a branch'], ['cat', location])