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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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, recursive=True):
45
out, err = self.run_bzr(command)
46
self.assertEqual('', err)
47
self.assertEqualDiff(value, out)
49
def test_ls_null_verbose(self):
51
self.run_bzr_error(['Cannot set both --verbose and --null'],
52
'ls --verbose --null')
54
def test_ls_basic(self):
55
"""Test the abilities of 'bzr ls'"""
56
self.ls_equals('.bzrignore\na\n')
57
self.ls_equals('? .bzrignore\n'
60
self.ls_equals('.bzrignore\n'
63
self.ls_equals('', '--ignored')
64
self.ls_equals('', '--versioned')
65
self.ls_equals('', '-V')
66
self.ls_equals('.bzrignore\n'
68
'--unknown --ignored --versioned')
69
self.ls_equals('.bzrignore\n'
71
'--unknown --ignored -V')
72
self.ls_equals('', '--ignored --versioned')
73
self.ls_equals('', '--ignored -V')
74
self.ls_equals('.bzrignore\0a\0', '--null')
76
def test_ls_added(self):
78
self.ls_equals('? .bzrignore\n'
83
self.build_tree(['subdir/'])
84
self.ls_equals('? .bzrignore\n'
88
self.build_tree(['subdir/b'])
89
self.wt.add(['subdir/', 'subdir/b', '.bzrignore'])
90
self.ls_equals('V .bzrignore\n'
96
def test_show_ids(self):
97
self.build_tree(['subdir/'])
98
self.wt.add(['a', 'subdir'], ['a-id', 'subdir-id'])
102
'subdir/ subdir-id\n',
107
'V subdir/ subdir-id\n',
108
'--show-ids --verbose')
109
self.ls_equals('.bzrignore\0\0'
111
'subdir\0subdir-id\0', '--show-ids --null')
113
def test_ls_no_recursive(self):
114
self.build_tree(['subdir/', 'subdir/b'])
115
self.wt.add(['a', 'subdir/', 'subdir/b', '.bzrignore'])
117
self.ls_equals('.bzrignore\n'
122
self.ls_equals('V .bzrignore\n'
125
, '--verbose', recursive=False)
127
# Check what happens in a sub-directory
129
self.ls_equals('b\n')
132
self.ls_equals('subdir/b\n'
134
self.ls_equals('subdir/b\0'
135
, '--from-root --null')
136
self.ls_equals('subdir/b\n'
137
, '--from-root', recursive=False)
139
def test_ls_path(self):
140
"""If a path is specified, files are listed with that prefix"""
141
self.build_tree(['subdir/', 'subdir/b'])
142
self.wt.add(['subdir', 'subdir/b'])
143
self.ls_equals('subdir/b\n' ,
146
self.ls_equals('../.bzrignore\n'
151
self.ls_equals('../.bzrignore\0'
156
self.ls_equals('? ../.bzrignore\n'
161
self.run_bzr_error(['cannot specify both --from-root and PATH'],
164
def test_ls_revision(self):
166
self.wt.commit('add')
168
self.build_tree(['subdir/'])
170
# Check what happens when we supply a specific revision
171
self.ls_equals('a\n', '--revision 1')
172
self.ls_equals('V a\n'
173
, '--verbose --revision 1')
176
self.ls_equals('', '--revision 1')
178
def test_ls_branch(self):
179
"""If a branch is specified, files are listed from it"""
180
self.build_tree(['subdir/', 'subdir/b'])
181
self.wt.add(['subdir', 'subdir/b'])
182
self.wt.commit('committing')
183
branch = self.make_branch('branchdir')
184
branch.pull(self.wt.branch)
185
self.ls_equals('branchdir/subdir/\n'
186
'branchdir/subdir/b\n',
188
self.ls_equals('branchdir/subdir/\n'
189
'branchdir/subdir/b\n',
190
'branchdir --revision 1')
192
def test_ls_ignored(self):
193
# Now try to do ignored files.
194
self.wt.add(['a', '.bzrignore'])
196
self.build_tree(['blah.py', 'blah.pyo', 'user-ignore'])
197
self.ls_equals('.bzrignore\n'
203
self.ls_equals('V .bzrignore\n'
209
self.ls_equals('blah.pyo\n'
212
self.ls_equals('blah.py\n'
214
self.ls_equals('.bzrignore\n'
217
self.ls_equals('.bzrignore\n'
221
def test_kinds(self):
222
self.build_tree(['subdir/'])
223
self.ls_equals('.bzrignore\n'
226
self.ls_equals('subdir/\n',
230
self.run_bzr_error(['invalid kind specified'], 'ls --kind=pile')
232
def test_ls_path_nonrecursive(self):
233
self.ls_equals('%s/.bzrignore\n'
235
% (self.test_dir, self.test_dir),
236
self.test_dir, recursive=False)