1
# Copyright (C) 2005 Canonical Ltd
2
# -*- coding: utf-8 -*-
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
"""Black-box tests for bzr cat.
24
from bzrlib.tests.blackbox import TestCaseWithTransport
26
class TestCat(TestCaseWithTransport):
29
tree = self.make_branch_and_tree('branch')
30
self.build_tree_contents([('branch/a', 'foo\n')])
33
# 'bzr cat' without an option should cat the last revision
34
self.run_bzr('cat', 'a', retcode=3)
36
tree.commit(message='1')
37
self.build_tree_contents([('a', 'baz\n')])
39
# We use run_bzr_subprocess rather than run_bzr here so that we can
40
# test mangling of line-endings on Windows.
41
self.assertEquals(self.run_bzr_subprocess('cat', 'a')[0], 'foo\n')
43
tree.commit(message='2')
44
self.assertEquals(self.run_bzr_subprocess('cat', 'a')[0], 'baz\n')
45
self.assertEquals(self.run_bzr_subprocess('cat', 'a', '-r', '1')[0], 'foo\n')
46
self.assertEquals(self.run_bzr_subprocess('cat', 'a', '-r', '-1')[0], 'baz\n')
48
rev_id = tree.branch.last_revision()
50
self.assertEquals(self.run_bzr_subprocess('cat', 'a', '-r', 'revid:%s' % rev_id)[0], 'baz\n')
54
self.assertEquals(self.run_bzr_subprocess('cat', 'branch/a', '-r', 'revno:1:branch')[0],
56
self.run_bzr('cat', 'a', retcode=3)
57
self.run_bzr('cat', 'a', '-r', 'revno:1:branch-that-does-not-exist', retcode=3)
59
def test_cat_different_id(self):
60
"""'cat' works with old and new files"""
61
tree = self.make_branch_and_tree('.')
62
# the files are named after their path in the revision and
63
# current trees later in the test case
64
# a-rev-tree is special because it appears in both the revision
65
# tree and the working tree
66
self.build_tree_contents([('a-rev-tree', 'foo\n'),
67
('c-rev', 'baz\n'), ('d-rev', 'bar\n')])
70
tree.add(['a-rev-tree', 'c-rev', 'd-rev'])
71
tree.commit('add test files')
72
# remove currently uses self._write_inventory -
73
# work around that for now.
75
tree.remove(['d-rev'])
76
tree.rename_one('a-rev-tree', 'b-tree')
77
tree.rename_one('c-rev', 'a-rev-tree')
79
# calling bzr as another process require free lock on win32
82
# 'b-tree' is not present in the old tree.
83
self.run_bzr_error(["^bzr: ERROR: u?'b-tree' "
84
"is not present in revision .+$"],
85
'cat b-tree --name-from-revision')
87
# get to the old file automatically
88
out, err = self.run_bzr_subprocess('cat d-rev')
89
self.assertEqual('bar\n', out)
90
self.assertEqual('', err)
92
out, err = self.run_bzr_subprocess('cat a-rev-tree --name-from-revision')
93
self.assertEqual('foo\n', out)
94
self.assertEqual('', err)
96
out, err = self.run_bzr_subprocess('cat a-rev-tree')
97
self.assertEqual('baz\n', out)
98
self.assertEqual('', err)
100
def test_remote_cat(self):
101
wt = self.make_branch_and_tree('.')
102
self.build_tree(['README'])
104
wt.commit('Making sure there is a basis_tree available')
106
url = self.get_readonly_url() + '/README'
107
out, err = self.run_bzr_subprocess(['cat', url])
108
self.assertEqual('contents of README\n', out)
110
def test_cat_no_working_tree(self):
111
wt = self.make_branch_and_tree('.')
112
self.build_tree(['README'])
114
wt.commit('Making sure there is a basis_tree available')
115
wt.branch.bzrdir.destroy_workingtree()
117
url = self.get_readonly_url() + '/README'
118
out, err = self.run_bzr_subprocess(['cat', url])
119
self.assertEqual('contents of README\n', out)