1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
|
# Copyright (C) 2006-2010 Canonical Ltd
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
"""External tests of 'bzr ls'"""
import os
from bzrlib import ignores
from bzrlib.tests import TestCaseWithTransport
from bzrlib.tests.matchers import ContainsNoVfsCalls
class TestLS(TestCaseWithTransport):
def setUp(self):
super(TestLS, self).setUp()
# Create a simple branch that can be used in testing
ignores._set_user_ignores(['user-ignore'])
self.wt = self.make_branch_and_tree('.')
self.build_tree_contents([
('.bzrignore', '*.pyo\n'),
('a', 'hello\n'),
])
def ls_equals(self, value, args=None, recursive=True):
command = 'ls'
if args is not None:
command += ' ' + args
if recursive:
command += ' -R'
out, err = self.run_bzr(command)
self.assertEqual('', err)
self.assertEqualDiff(value, out)
def test_ls_null_verbose(self):
# Can't supply both
self.run_bzr_error(['Cannot set both --verbose and --null'],
'ls --verbose --null')
def test_ls_basic(self):
"""Test the abilities of 'bzr ls'"""
self.ls_equals('.bzrignore\na\n')
self.ls_equals('.bzrignore\na\n', './')
self.ls_equals('? .bzrignore\n'
'? a\n',
'--verbose')
self.ls_equals('.bzrignore\n'
'a\n',
'--unknown')
self.ls_equals('', '--ignored')
self.ls_equals('', '--versioned')
self.ls_equals('', '-V')
self.ls_equals('.bzrignore\n'
'a\n',
'--unknown --ignored --versioned')
self.ls_equals('.bzrignore\n'
'a\n',
'--unknown --ignored -V')
self.ls_equals('', '--ignored --versioned')
self.ls_equals('', '--ignored -V')
self.ls_equals('.bzrignore\0a\0', '--null')
def test_ls_added(self):
self.wt.add(['a'])
self.ls_equals('? .bzrignore\n'
'V a\n',
'--verbose')
self.wt.commit('add')
self.build_tree(['subdir/'])
self.ls_equals('? .bzrignore\n'
'V a\n'
'? subdir/\n'
, '--verbose')
self.build_tree(['subdir/b'])
self.wt.add(['subdir/', 'subdir/b', '.bzrignore'])
self.ls_equals('V .bzrignore\n'
'V a\n'
'V subdir/\n'
'V subdir/b\n'
, '--verbose')
def test_show_ids(self):
self.build_tree(['subdir/'])
self.wt.add(['a', 'subdir'], ['a-id', 'subdir-id'])
self.ls_equals(
'.bzrignore \n'
'a a-id\n'
'subdir/ subdir-id\n',
'--show-ids')
self.ls_equals(
'? .bzrignore\n'
'V a a-id\n'
'V subdir/ subdir-id\n',
'--show-ids --verbose')
self.ls_equals('.bzrignore\0\0'
'a\0a-id\0'
'subdir\0subdir-id\0', '--show-ids --null')
def test_ls_no_recursive(self):
self.build_tree(['subdir/', 'subdir/b'])
self.wt.add(['a', 'subdir/', 'subdir/b', '.bzrignore'])
self.ls_equals('.bzrignore\n'
'a\n'
'subdir/\n'
, recursive=False)
self.ls_equals('V .bzrignore\n'
'V a\n'
'V subdir/\n'
, '--verbose', recursive=False)
# Check what happens in a sub-directory
os.chdir('subdir')
self.ls_equals('b\n')
self.ls_equals('b\0'
, '--null')
self.ls_equals('subdir/b\n'
, '--from-root')
self.ls_equals('subdir/b\0'
, '--from-root --null')
self.ls_equals('subdir/b\n'
, '--from-root', recursive=False)
def test_ls_path(self):
"""If a path is specified, files are listed with that prefix"""
self.build_tree(['subdir/', 'subdir/b'])
self.wt.add(['subdir', 'subdir/b'])
self.ls_equals('subdir/b\n' ,
'subdir')
os.chdir('subdir')
self.ls_equals('../.bzrignore\n'
'../a\n'
'../subdir/\n'
'../subdir/b\n' ,
'..')
self.ls_equals('../.bzrignore\0'
'../a\0'
'../subdir\0'
'../subdir/b\0' ,
'.. --null')
self.ls_equals('? ../.bzrignore\n'
'? ../a\n'
'V ../subdir/\n'
'V ../subdir/b\n' ,
'.. --verbose')
self.run_bzr_error(['cannot specify both --from-root and PATH'],
'ls --from-root ..')
def test_ls_revision(self):
self.wt.add(['a'])
self.wt.commit('add')
self.build_tree(['subdir/'])
# Check what happens when we supply a specific revision
self.ls_equals('a\n', '--revision 1')
self.ls_equals('V a\n'
, '--verbose --revision 1')
os.chdir('subdir')
self.ls_equals('', '--revision 1')
def test_ls_branch(self):
"""If a branch is specified, files are listed from it"""
self.build_tree(['subdir/', 'subdir/b'])
self.wt.add(['subdir', 'subdir/b'])
self.wt.commit('committing')
branch = self.make_branch('branchdir')
branch.pull(self.wt.branch)
self.ls_equals('branchdir/subdir/\n'
'branchdir/subdir/b\n',
'branchdir')
self.ls_equals('branchdir/subdir/\n'
'branchdir/subdir/b\n',
'branchdir --revision 1')
def test_ls_ignored(self):
# Now try to do ignored files.
self.wt.add(['a', '.bzrignore'])
self.build_tree(['blah.py', 'blah.pyo', 'user-ignore'])
self.ls_equals('.bzrignore\n'
'a\n'
'blah.py\n'
'blah.pyo\n'
'user-ignore\n'
)
self.ls_equals('V .bzrignore\n'
'V a\n'
'? blah.py\n'
'I blah.pyo\n'
'I user-ignore\n'
, '--verbose')
self.ls_equals('blah.pyo\n'
'user-ignore\n'
, '--ignored')
self.ls_equals('blah.py\n'
, '--unknown')
self.ls_equals('.bzrignore\n'
'a\n'
, '--versioned')
self.ls_equals('.bzrignore\n'
'a\n'
, '-V')
def test_kinds(self):
self.build_tree(['subdir/'])
self.ls_equals('.bzrignore\n'
'a\n',
'--kind=file')
self.ls_equals('subdir/\n',
'--kind=directory')
self.ls_equals('',
'--kind=symlink')
self.run_bzr_error(['invalid kind specified'], 'ls --kind=pile')
def test_ls_path_nonrecursive(self):
self.ls_equals('%s/.bzrignore\n'
'%s/a\n'
% (self.test_dir, self.test_dir),
self.test_dir, recursive=False)
def test_ls_directory(self):
"""Test --directory option"""
self.wt = self.make_branch_and_tree('dir')
self.build_tree(['dir/sub/', 'dir/sub/file'])
self.wt.add(['sub', 'sub/file'])
self.wt.commit('commit')
self.ls_equals('sub/\nsub/file\n', '--directory=dir')
self.ls_equals('sub/file\n', '-d dir sub')
class TestSmartServerLs(TestCaseWithTransport):
def test_simple_ls(self):
self.setup_smart_server_with_call_log()
t = self.make_branch_and_tree('branch')
self.build_tree_contents([('branch/foo', 'thecontents')])
t.add("foo")
t.commit("message")
self.reset_smart_call_log()
out, err = self.run_bzr(['ls', self.get_url('branch')])
# This figure represent the amount of work to perform this use case. It
# is entirely ok to reduce this number if a test fails due to rpc_count
# being too low. If rpc_count increases, more network roundtrips have
# become necessary for this use case. Please do not adjust this number
# upwards without agreement from bzr's network support maintainers.
self.assertLength(6, self.hpss_calls)
self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
|