13
13
# You should have received a copy of the GNU General Public License
14
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
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
17
"""External tests of 'bzr ls'"""
23
from bzrlib.tests.matchers import ContainsNoVfsCalls
26
class TestLS(tests.TestCaseWithTransport):
21
from bzrlib import ignores
22
from bzrlib.tests import TestCaseWithTransport
25
class TestLS(TestCaseWithTransport):
29
28
super(TestLS, self).setUp()
31
30
# Create a simple branch that can be used in testing
32
31
ignores._set_user_ignores(['user-ignore'])
40
def ls_equals(self, value, args=None, recursive=True, working_dir=None):
46
out, err = self.run_bzr(command, working_dir=working_dir)
39
def ls_equals(self, value, *args):
40
out, err = self.run_bzr('ls', *args)
47
41
self.assertEqual('', err)
48
42
self.assertEqualDiff(value, out)
50
44
def test_ls_null_verbose(self):
51
45
# Can't supply both
52
46
self.run_bzr_error(['Cannot set both --verbose and --null'],
53
'ls --verbose --null')
47
'ls', '--verbose', '--null')
55
49
def test_ls_basic(self):
56
50
"""Test the abilities of 'bzr ls'"""
57
51
self.ls_equals('.bzrignore\na\n')
58
self.ls_equals('.bzrignore\na\n', './')
59
52
self.ls_equals('? .bzrignore\n'
65
58
self.ls_equals('', '--ignored')
66
59
self.ls_equals('', '--versioned')
67
self.ls_equals('', '-V')
68
self.ls_equals('.bzrignore\n'
70
'--unknown --ignored --versioned')
71
self.ls_equals('.bzrignore\n'
73
'--unknown --ignored -V')
74
self.ls_equals('', '--ignored --versioned')
75
self.ls_equals('', '--ignored -V')
60
self.ls_equals('.bzrignore\n'
62
'--unknown', '--ignored', '--versioned')
63
self.ls_equals('', '--ignored', '--versioned')
76
64
self.ls_equals('.bzrignore\0a\0', '--null')
78
66
def test_ls_added(self):
104
'subdir/ subdir-id\n',
109
'V subdir/ subdir-id\n',
110
'--show-ids --verbose')
97
'V subdir/ subdir-id\n',
98
'--show-ids', '--verbose')
111
99
self.ls_equals('.bzrignore\0\0'
113
'subdir\0subdir-id\0', '--show-ids --null')
101
'subdir\0subdir-id\0', '--show-ids', '--null')
115
def test_ls_no_recursive(self):
103
def test_ls_recursive(self):
116
104
self.build_tree(['subdir/', 'subdir/b'])
117
105
self.wt.add(['a', 'subdir/', 'subdir/b', '.bzrignore'])
119
107
self.ls_equals('.bzrignore\n'
124
112
self.ls_equals('V .bzrignore\n'
127
, '--verbose', recursive=False)
115
, '--verbose', '--non-recursive')
129
117
# Check what happens in a sub-directory
130
self.ls_equals('b\n', working_dir='subdir')
131
self.ls_equals('b\0', '--null', working_dir='subdir')
132
self.ls_equals('subdir/b\n', '--from-root', working_dir='subdir')
133
self.ls_equals('subdir/b\0', '--from-root --null',
134
working_dir='subdir')
135
self.ls_equals('subdir/b\n', '--from-root', recursive=False,
136
working_dir='subdir')
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')
138
137
def test_ls_path(self):
139
138
"""If a path is specified, files are listed with that prefix"""
141
140
self.wt.add(['subdir', 'subdir/b'])
142
141
self.ls_equals('subdir/b\n' ,
144
144
self.ls_equals('../.bzrignore\n'
147
147
'../subdir/b\n' ,
148
'..', working_dir='subdir')
149
149
self.ls_equals('../.bzrignore\0'
152
152
'../subdir/b\0' ,
153
'.. --null', working_dir='subdir')
154
154
self.ls_equals('? ../.bzrignore\n'
157
157
'V ../subdir/b\n' ,
158
'.. --verbose', working_dir='subdir')
159
self.run_bzr_error(['cannot specify both --from-root and PATH'],
160
'ls --from-root ..', working_dir='subdir')
159
self.run_bzr_error('cannot specify both --from-root and PATH', 'ls',
162
162
def test_ls_revision(self):
163
163
self.wt.add(['a'])
166
166
self.build_tree(['subdir/'])
168
168
# Check what happens when we supply a specific revision
169
self.ls_equals('a\n', '--revision 1')
169
self.ls_equals('a\n', '--revision', '1')
170
170
self.ls_equals('V a\n'
171
, '--verbose --revision 1')
171
, '--verbose', '--revision', '1')
173
self.ls_equals('', '--revision 1', working_dir='subdir')
174
self.ls_equals('', '--revision', '1')
175
176
def test_ls_branch(self):
176
177
"""If a branch is specified, files are listed from it"""
179
180
self.wt.commit('committing')
180
181
branch = self.make_branch('branchdir')
181
182
branch.pull(self.wt.branch)
182
self.ls_equals('branchdir/subdir/\n'
183
self.ls_equals('branchdir/subdir\n'
183
184
'branchdir/subdir/b\n',
185
self.ls_equals('branchdir/subdir/\n'
186
self.ls_equals('branchdir/subdir\n'
186
187
'branchdir/subdir/b\n',
187
'branchdir --revision 1')
188
'branchdir', '--revision', '1')
189
190
def test_ls_ignored(self):
190
191
# Now try to do ignored files.
211
212
self.ls_equals('.bzrignore\n'
214
self.ls_equals('.bzrignore\n'
218
216
def test_kinds(self):
219
217
self.build_tree(['subdir/'])
220
self.ls_equals('.bzrignore\n'
218
self.ls_equals('.bzrignore\n'
223
self.ls_equals('subdir/\n',
221
self.ls_equals('subdir\n',
224
222
'--kind=directory')
225
223
self.ls_equals('',
226
224
'--kind=symlink')
227
self.run_bzr_error(['invalid kind specified'], 'ls --kind=pile')
229
def test_ls_path_nonrecursive(self):
230
self.ls_equals('%s/.bzrignore\n'
232
% (self.test_dir, self.test_dir),
233
self.test_dir, recursive=False)
235
def test_ls_directory(self):
236
"""Test --directory option"""
237
self.wt = self.make_branch_and_tree('dir')
238
self.build_tree(['dir/sub/', 'dir/sub/file'])
239
self.wt.add(['sub', 'sub/file'])
240
self.wt.commit('commit')
241
self.ls_equals('sub/\nsub/file\n', '--directory=dir')
242
self.ls_equals('sub/file\n', '-d dir sub')
245
class TestSmartServerLs(tests.TestCaseWithTransport):
247
def test_simple_ls(self):
248
self.setup_smart_server_with_call_log()
249
t = self.make_branch_and_tree('branch')
250
self.build_tree_contents([('branch/foo', 'thecontents')])
253
self.reset_smart_call_log()
254
out, err = self.run_bzr(['ls', self.get_url('branch')])
255
# This figure represent the amount of work to perform this use case. It
256
# is entirely ok to reduce this number if a test fails due to rpc_count
257
# being too low. If rpc_count increases, more network roundtrips have
258
# become necessary for this use case. Please do not adjust this number
259
# upwards without agreement from bzr's network support maintainers.
260
self.assertLength(6, self.hpss_calls)
261
self.assertLength(1, self.hpss_connections)
262
self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
225
self.run_bzr_error('invalid kind specified', 'ls', '--kind=pile')