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=None):
43
out, err = self.run_bzr(command)
44
self.assertEqual('', err)
45
self.assertEqualDiff(value, out)
47
def test_ls_null_verbose(self):
49
self.run_bzr_error(['Cannot set both --verbose and --null'],
50
'ls --verbose --null')
52
def test_ls_basic(self):
53
"""Test the abilities of 'bzr ls'"""
54
self.ls_equals('.bzrignore\na\n')
55
self.ls_equals('? .bzrignore\n'
58
self.ls_equals('.bzrignore\n'
61
self.ls_equals('', '--ignored')
62
self.ls_equals('', '--versioned')
63
self.ls_equals('', '-V')
64
self.ls_equals('.bzrignore\n'
66
'--unknown --ignored --versioned')
67
self.ls_equals('.bzrignore\n'
69
'--unknown --ignored -V')
70
self.ls_equals('', '--ignored --versioned')
71
self.ls_equals('', '--ignored -V')
72
self.ls_equals('.bzrignore\0a\0', '--null')
74
def test_ls_added(self):
76
self.ls_equals('? .bzrignore\n'
81
self.build_tree(['subdir/'])
82
self.ls_equals('? .bzrignore\n'
86
self.build_tree(['subdir/b'])
87
self.wt.add(['subdir/', 'subdir/b', '.bzrignore'])
88
self.ls_equals('V .bzrignore\n'
94
def test_show_ids(self):
95
self.build_tree(['subdir/'])
96
self.wt.add(['a', 'subdir'], ['a-id', 'subdir-id'])
100
'subdir/ subdir-id\n',
105
'V subdir/ subdir-id\n',
106
'--show-ids --verbose')
107
self.ls_equals('.bzrignore\0\0'
109
'subdir\0subdir-id\0', '--show-ids --null')
111
def test_ls_recursive(self):
112
self.build_tree(['subdir/', 'subdir/b'])
113
self.wt.add(['a', 'subdir/', 'subdir/b', '.bzrignore'])
115
self.ls_equals('.bzrignore\n'
120
self.ls_equals('V .bzrignore\n'
123
, '--verbose --non-recursive')
125
# Check what happens in a sub-directory
127
self.ls_equals('b\n')
130
self.ls_equals('.bzrignore\n'
135
self.ls_equals('.bzrignore\0'
139
, '--from-root --null')
140
self.ls_equals('.bzrignore\n'
143
, '--from-root --non-recursive')
145
def test_ls_path(self):
146
"""If a path is specified, files are listed with that prefix"""
147
self.build_tree(['subdir/', 'subdir/b'])
148
self.wt.add(['subdir', 'subdir/b'])
149
self.ls_equals('subdir/b\n' ,
152
self.ls_equals('../.bzrignore\n'
157
self.ls_equals('../.bzrignore\0'
162
self.ls_equals('? ../.bzrignore\n'
167
self.run_bzr_error('cannot specify both --from-root and PATH',
170
def test_ls_revision(self):
172
self.wt.commit('add')
174
self.build_tree(['subdir/'])
176
# Check what happens when we supply a specific revision
177
self.ls_equals('a\n', '--revision 1')
178
self.ls_equals('V a\n'
179
, '--verbose --revision 1')
182
self.ls_equals('', '--revision 1')
184
def test_ls_branch(self):
185
"""If a branch is specified, files are listed from it"""
186
self.build_tree(['subdir/', 'subdir/b'])
187
self.wt.add(['subdir', 'subdir/b'])
188
self.wt.commit('committing')
189
branch = self.make_branch('branchdir')
190
branch.pull(self.wt.branch)
191
self.ls_equals('branchdir/subdir/\n'
192
'branchdir/subdir/b\n',
194
self.ls_equals('branchdir/subdir/\n'
195
'branchdir/subdir/b\n',
196
'branchdir --revision 1')
198
def test_ls_ignored(self):
199
# Now try to do ignored files.
200
self.wt.add(['a', '.bzrignore'])
202
self.build_tree(['blah.py', 'blah.pyo', 'user-ignore'])
203
self.ls_equals('.bzrignore\n'
209
self.ls_equals('V .bzrignore\n'
215
self.ls_equals('blah.pyo\n'
218
self.ls_equals('blah.py\n'
220
self.ls_equals('.bzrignore\n'
223
self.ls_equals('.bzrignore\n'
227
def test_kinds(self):
228
self.build_tree(['subdir/'])
229
self.ls_equals('.bzrignore\n'
232
self.ls_equals('subdir/\n',
236
self.run_bzr_error('invalid kind specified', 'ls --kind=pile')