1
# Copyright (C) 2005 by Canonical Ltd
1
# Copyright (C) 2005 Canonical Ltd
2
2
# -*- coding: utf-8 -*-
4
4
# This program is free software; you can redistribute it and/or modify
5
5
# it under the terms of the GNU General Public License as published by
6
6
# the Free Software Foundation; either version 2 of the License, or
7
7
# (at your option) any later version.
9
9
# This program is distributed in the hope that it will be useful,
10
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
12
# GNU General Public License for more details.
14
14
# You should have received a copy of the GNU General Public License
15
15
# along with this program; if not, write to the Free Software
16
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24
from bzrlib.branch import Branch
25
from bzrlib.tests import TestCaseInTempDir
24
from bzrlib.tests.blackbox import TestCaseWithTransport
27
class TestCat(TestCaseInTempDir):
26
class TestCat(TestCaseWithTransport):
29
28
def test_cat(self):
31
30
def bzr(*args, **kwargs):
32
return self.run_bzr(*args, **kwargs)[0]
31
return self.run_bzr_subprocess(*args, **kwargs)[0]
35
36
open('a', 'wb').write('foo\n')
51
52
rev_id = bzr('revision-history').strip().split('\n')[-1]
53
54
self.assertEquals(bzr('cat', 'a', '-r', 'revid:%s' % rev_id), 'baz\n')
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)
63
def test_cat_different_id(self):
64
"""'cat' works with old and new files"""
65
tree = self.make_branch_and_tree('.')
66
# the files are named after their path in the revision and
67
# current trees later in the test case
68
# a-rev-tree is special because it appears in both the revision
69
# tree and the working tree
70
self.build_tree_contents([('a-rev-tree', 'foo\n'),
71
('c-rev', 'baz\n'), ('d-rev', 'bar\n')])
74
tree.add(['a-rev-tree', 'c-rev', 'd-rev'])
75
tree.commit('add test files')
76
# remove currently uses self._write_inventory -
77
# work around that for now.
79
tree.remove(['d-rev'])
80
tree.rename_one('a-rev-tree', 'b-tree')
81
tree.rename_one('c-rev', 'a-rev-tree')
83
# 'b-tree' is not present in the old tree.
84
self.run_bzr_error([], 'cat', 'b-tree', '--name-from-revision')
86
# get to the old file automatically
87
out, err = self.run_bzr('cat', 'd-rev')
88
self.assertEqual('bar\n', out)
89
self.assertEqual('', err)
91
out, err = self.run_bzr('cat', 'a-rev-tree',
92
'--name-from-revision')
93
self.assertEqual('foo\n', out)
94
self.assertEqual('', err)
96
out, err = self.run_bzr('cat', 'a-rev-tree')
97
self.assertEqual('baz\n', out)
98
self.assertEqual('', err)
102
def test_remote_cat(self):
103
wt = self.make_branch_and_tree('.')
104
self.build_tree(['README'])
106
wt.commit('Making sure there is a basis_tree available')
108
url = self.get_readonly_url() + '/README'
109
out, err = self.run_bzr('cat', url)
110
self.assertEqual('contents of README\n', out)
112
def test_cat_no_working_tree(self):
113
wt = self.make_branch_and_tree('.')
114
self.build_tree(['README'])
116
wt.commit('Making sure there is a basis_tree available')
117
wt.branch.bzrdir.destroy_workingtree()
119
url = self.get_readonly_url() + '/README'
120
out, err = self.run_bzr('cat', url)
121
self.assertEqual('contents of README\n', out)