1
# Copyright (C) 2006 Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
"""External tests of 'bzr ls'"""
21
from bzrlib import ignores
22
from bzrlib.tests import TestCaseWithTransport
25
class TestLS(TestCaseWithTransport):
28
super(TestLS, self).setUp()
30
# Create a simple branch that can be used in testing
31
ignores._set_user_ignores(['user-ignore'])
33
self.wt = self.make_branch_and_tree('.')
34
self.build_tree_contents([
35
('.bzrignore', '*.pyo\n'),
39
def ls_equals(self, value, *args):
40
out, err = self.run_bzr('ls', *args)
41
self.assertEqual('', err)
42
self.assertEqualDiff(value, out)
44
def test_ls_null_verbose(self):
46
self.run_bzr_error(['Cannot set both --verbose and --null'],
47
'ls', '--verbose', '--null')
49
def test_ls_basic(self):
50
"""Test the abilities of 'bzr ls'"""
51
self.ls_equals('.bzrignore\na\n')
52
self.ls_equals('? .bzrignore\n'
55
self.ls_equals('.bzrignore\n'
58
self.ls_equals('', '--ignored')
59
self.ls_equals('', '--versioned')
60
self.ls_equals('.bzrignore\n'
62
'--unknown', '--ignored', '--versioned')
63
self.ls_equals('', '--ignored', '--versioned')
64
self.ls_equals('.bzrignore\0a\0', '--null')
66
def test_ls_added(self):
68
self.ls_equals('? .bzrignore\n'
73
self.build_tree(['subdir/'])
74
self.ls_equals('? .bzrignore\n'
78
self.build_tree(['subdir/b'])
79
self.wt.add(['subdir/', 'subdir/b', '.bzrignore'])
80
self.ls_equals('V .bzrignore\n'
86
def test_show_ids(self):
87
self.build_tree(['subdir/'])
88
self.wt.add(['a', 'subdir'], ['a-id', 'subdir-id'])
97
'V subdir/ subdir-id\n',
98
'--show-ids', '--verbose')
99
self.ls_equals('.bzrignore\0\0'
101
'subdir\0subdir-id\0', '--show-ids', '--null')
103
def test_ls_recursive(self):
104
self.build_tree(['subdir/', 'subdir/b'])
105
self.wt.add(['a', 'subdir/', 'subdir/b', '.bzrignore'])
107
self.ls_equals('.bzrignore\n'
112
self.ls_equals('V .bzrignore\n'
115
, '--verbose', '--non-recursive')
117
# Check what happens in a sub-directory
119
self.ls_equals('b\n')
122
self.ls_equals('.bzrignore\n'
127
self.ls_equals('.bzrignore\0'
131
, '--from-root', '--null')
132
self.ls_equals('.bzrignore\n'
135
, '--from-root', '--non-recursive')
137
def test_ls_path(self):
138
"""If a path is specified, files are listed with that prefix"""
139
self.build_tree(['subdir/', 'subdir/b'])
140
self.wt.add(['subdir', 'subdir/b'])
141
self.ls_equals('subdir/b\n' ,
144
self.ls_equals('../.bzrignore\n'
149
self.ls_equals('../.bzrignore\0'
154
self.ls_equals('? ../.bzrignore\n'
159
self.run_bzr_error('cannot specify both --from-root and PATH', 'ls',
162
def test_ls_revision(self):
164
self.wt.commit('add')
166
self.build_tree(['subdir/'])
168
# Check what happens when we supply a specific revision
169
self.ls_equals('a\n', '--revision', '1')
170
self.ls_equals('V a\n'
171
, '--verbose', '--revision', '1')
174
self.ls_equals('', '--revision', '1')
176
def test_ls_branch(self):
177
"""If a branch is specified, files are listed from it"""
178
self.build_tree(['subdir/', 'subdir/b'])
179
self.wt.add(['subdir', 'subdir/b'])
180
self.wt.commit('committing')
181
branch = self.make_branch('branchdir')
182
branch.pull(self.wt.branch)
183
self.ls_equals('branchdir/subdir\n'
184
'branchdir/subdir/b\n',
186
self.ls_equals('branchdir/subdir\n'
187
'branchdir/subdir/b\n',
188
'branchdir', '--revision', '1')
190
def test_ls_ignored(self):
191
# Now try to do ignored files.
192
self.wt.add(['a', '.bzrignore'])
194
self.build_tree(['blah.py', 'blah.pyo', 'user-ignore'])
195
self.ls_equals('.bzrignore\n'
201
self.ls_equals('V .bzrignore\n'
207
self.ls_equals('blah.pyo\n'
210
self.ls_equals('blah.py\n'
212
self.ls_equals('.bzrignore\n'
216
def test_kinds(self):
217
self.build_tree(['subdir/'])
218
self.ls_equals('.bzrignore\n'
221
self.ls_equals('subdir\n',
225
self.run_bzr_error('invalid kind specified', 'ls', '--kind=pile')