24
from bzrlib.branch import Branch
25
from bzrlib.tests import TestCaseInTempDir
27
class TestCat(TestCaseInTempDir):
25
from bzrlib.tests.blackbox import TestCaseWithTransport
27
class TestCat(TestCaseWithTransport):
29
29
def test_cat(self):
31
def bzr(*args, **kwargs):
32
return self.run_bzr(*args, **kwargs)[0]
35
open('a', 'wb').write('foo\n')
30
tree = self.make_branch_and_tree('branch')
31
self.build_tree_contents([('branch/a', 'foo\n')])
38
34
# 'bzr cat' without an option should cat the last revision
39
bzr('cat', 'a', retcode=3)
41
bzr('commit', '-m', '1')
42
open('a', 'wb').write('baz\n')
44
self.assertEquals(bzr('cat', 'a'), 'foo\n')
46
bzr('commit', '-m', '2')
47
self.assertEquals(bzr('cat', 'a'), 'baz\n')
48
self.assertEquals(bzr('cat', 'a', '-r', '1'), 'foo\n')
49
self.assertEquals(bzr('cat', 'a', '-r', '-1'), 'baz\n')
51
rev_id = bzr('revision-history').strip().split('\n')[-1]
53
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],
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'],
69
def test_cat_different_id(self):
70
"""'cat' works with old and new files"""
71
tree = self.make_branch_and_tree('.')
72
# the files are named after their path in the revision and
73
# current trees later in the test case
74
# a-rev-tree is special because it appears in both the revision
75
# tree and the working tree
76
self.build_tree_contents([('a-rev-tree', 'foo\n'),
77
('c-rev', 'baz\n'), ('d-rev', 'bar\n'), ('e-rev', 'qux\n')])
80
tree.add(['a-rev-tree', 'c-rev', 'd-rev', 'e-rev'])
81
tree.commit('add test files', rev_id='first')
82
# remove currently uses self._write_inventory -
83
# work around that for now.
85
tree.remove(['d-rev'])
86
tree.rename_one('a-rev-tree', 'b-tree')
87
tree.rename_one('c-rev', 'a-rev-tree')
88
tree.rename_one('e-rev', 'old-rev')
89
self.build_tree_contents([('e-rev', 'new\n')])
92
# calling bzr as another process require free lock on win32
95
# 'b-tree' is not present in the old tree.
96
self.run_bzr_error(["^bzr: ERROR: u?'b-tree' "
97
"is not present in revision .+$"],
98
'cat b-tree --name-from-revision')
100
# get to the old file automatically
101
out, err = self.run_bzr_subprocess('cat d-rev')
102
self.assertEqual('bar\n', out)
103
self.assertEqual('', err)
106
self.run_bzr_subprocess('cat a-rev-tree --name-from-revision')
107
self.assertEqual('foo\n', out)
108
self.assertEqual('', err)
110
out, err = self.run_bzr_subprocess('cat a-rev-tree')
111
self.assertEqual('baz\n', out)
112
self.assertEqual('', err)
114
# the actual file-id for e-rev doesn't exist in the old tree
115
out, err = self.run_bzr_subprocess('cat e-rev -rrevid:first')
116
self.assertEqual('qux\n', out)
117
self.assertEqual('', err)
119
def test_remote_cat(self):
120
wt = self.make_branch_and_tree('.')
121
self.build_tree(['README'])
123
wt.commit('Making sure there is a basis_tree available')
125
url = self.get_readonly_url() + '/README'
126
out, err = self.run_bzr_subprocess(['cat', url])
127
self.assertEqual('contents of README\n', out)
129
def test_cat_no_working_tree(self):
130
wt = self.make_branch_and_tree('.')
131
self.build_tree(['README'])
133
wt.commit('Making sure there is a basis_tree available')
134
wt.branch.bzrdir.destroy_workingtree()
136
url = self.get_readonly_url() + '/README'
137
out, err = self.run_bzr_subprocess(['cat', url])
138
self.assertEqual('contents of README\n', out)
140
def test_cat_nonexistent_branch(self):
141
if sys.platform == "win32":
142
location = "C:/i/do/not/exist"
144
location = "/i/do/not/exist"
145
self.run_bzr_error(['^bzr: ERROR: Not a branch'], ['cat', location])