~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_ls.py

Merged bzr.dev and updated NEWS with a better description of changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006 by Canonical Ltd
 
1
# Copyright (C) 2006 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
28
28
        super(TestLS, self).setUp()
29
29
        
30
30
        # Create a simple branch that can be used in testing
31
 
        ignores._set_user_ignores(['./.bazaar', 'user-ignore'])
 
31
        ignores._set_user_ignores(['user-ignore'])
32
32
 
33
33
        self.wt = self.make_branch_and_tree('.')
34
34
        self.build_tree_contents([
36
36
                                 ('a', 'hello\n'),
37
37
                                 ])
38
38
 
39
 
    def ls_equals(self, value, *args):
40
 
        out, err = self.run_bzr('ls', *args)
 
39
    def ls_equals(self, value, args=None):
 
40
        command = 'ls'
 
41
        if args is not None:
 
42
            command += ' ' + args
 
43
        out, err = self.run_bzr(command)
41
44
        self.assertEqual('', err)
42
 
        self.assertEqual(value, out)
 
45
        self.assertEqualDiff(value, out)
43
46
 
44
47
    def test_ls_null_verbose(self):
45
48
        # Can't supply both
46
49
        self.run_bzr_error(['Cannot set both --verbose and --null'],
47
 
                           'ls', '--verbose', '--null')
 
50
                           'ls --verbose --null')
48
51
 
49
52
    def test_ls_basic(self):
50
53
        """Test the abilities of 'bzr ls'"""
51
 
        self.ls_equals('.bazaar\n.bzrignore\na\n')
52
 
        self.ls_equals('I        .bazaar/\n'
53
 
                       '?        .bzrignore\n'
 
54
        self.ls_equals('.bzrignore\na\n')
 
55
        self.ls_equals('?        .bzrignore\n'
54
56
                       '?        a\n',
55
57
                       '--verbose')
56
58
        self.ls_equals('.bzrignore\n'
57
59
                       'a\n',
58
60
                       '--unknown')
59
 
        self.ls_equals('.bazaar\n', '--ignored')
 
61
        self.ls_equals('', '--ignored')
60
62
        self.ls_equals('', '--versioned')
61
 
        self.ls_equals('.bazaar\n'
62
 
                       '.bzrignore\n'
 
63
        self.ls_equals('.bzrignore\n'
63
64
                       'a\n',
64
 
                       '--unknown', '--ignored', '--versioned')
65
 
        self.ls_equals('.bazaar\n', '--ignored', '--versioned')
66
 
        self.ls_equals('.bazaar\0.bzrignore\0a\0', '--null')
 
65
                       '--unknown --ignored --versioned')
 
66
        self.ls_equals('', '--ignored --versioned')
 
67
        self.ls_equals('.bzrignore\0a\0', '--null')
67
68
 
68
69
    def test_ls_added(self):
69
70
        self.wt.add(['a'])
70
 
        self.ls_equals('I        .bazaar/\n'
71
 
                       '?        .bzrignore\n'
 
71
        self.ls_equals('?        .bzrignore\n'
72
72
                       'V        a\n',
73
73
                       '--verbose')
74
74
        self.wt.commit('add')
75
75
        
76
76
        self.build_tree(['subdir/'])
77
 
        self.ls_equals('I        .bazaar/\n'
78
 
                       '?        .bzrignore\n'
 
77
        self.ls_equals('?        .bzrignore\n'
79
78
                       'V        a\n'
80
79
                       '?        subdir/\n'
81
80
                       , '--verbose')
82
81
        self.build_tree(['subdir/b'])
83
82
        self.wt.add(['subdir/', 'subdir/b', '.bzrignore'])
84
 
        self.ls_equals('I        .bazaar/\n'
85
 
                       'V        .bzrignore\n'
 
83
        self.ls_equals('V        .bzrignore\n'
86
84
                       'V        a\n'
87
85
                       'V        subdir/\n'
88
86
                       'V        subdir/b\n'
89
87
                       , '--verbose')
90
88
 
 
89
    def test_show_ids(self):
 
90
        self.build_tree(['subdir/'])
 
91
        self.wt.add(['a', 'subdir'], ['a-id', 'subdir-id'])
 
92
        self.ls_equals(
 
93
            '.bzrignore                                         \n'
 
94
            'a                                                  a-id\n'
 
95
            'subdir                                             subdir-id\n', 
 
96
            '--show-ids')
 
97
        self.ls_equals(
 
98
            '?        .bzrignore\n'
 
99
            'V        a                                         a-id\n'
 
100
            'V        subdir/                                   subdir-id\n', 
 
101
            '--show-ids --verbose')
 
102
        self.ls_equals('.bzrignore\0\0'
 
103
                       'a\0a-id\0'
 
104
                       'subdir\0subdir-id\0', '--show-ids --null')
 
105
 
91
106
    def test_ls_recursive(self):
92
107
        self.build_tree(['subdir/', 'subdir/b'])
93
108
        self.wt.add(['a', 'subdir/', 'subdir/b', '.bzrignore'])
94
109
 
95
 
        self.ls_equals('.bazaar\n'
96
 
                       '.bzrignore\n'
 
110
        self.ls_equals('.bzrignore\n'
97
111
                       'a\n'
98
112
                       'subdir\n'
99
113
                       , '--non-recursive')
100
114
 
101
 
        self.ls_equals('I        .bazaar/\n'
102
 
                       'V        .bzrignore\n'
 
115
        self.ls_equals('V        .bzrignore\n'
103
116
                       'V        a\n'
104
117
                       'V        subdir/\n'
105
 
                       , '--verbose', '--non-recursive')
 
118
                       , '--verbose --non-recursive')
106
119
 
107
120
        # Check what happens in a sub-directory
108
121
        os.chdir('subdir')
109
122
        self.ls_equals('b\n')
110
123
        self.ls_equals('b\0'
111
124
                  , '--null')
112
 
        self.ls_equals('.bazaar\n'
113
 
                       '.bzrignore\n'
 
125
        self.ls_equals('.bzrignore\n'
114
126
                       'a\n'
115
127
                       'subdir\n'
116
128
                       'subdir/b\n'
117
129
                       , '--from-root')
118
 
        self.ls_equals('.bazaar\0'
119
 
                       '.bzrignore\0'
 
130
        self.ls_equals('.bzrignore\0'
120
131
                       'a\0'
121
132
                       'subdir\0'
122
133
                       'subdir/b\0'
123
 
                       , '--from-root', '--null')
124
 
        self.ls_equals('.bazaar\n'
125
 
                       '.bzrignore\n'
 
134
                       , '--from-root --null')
 
135
        self.ls_equals('.bzrignore\n'
126
136
                       'a\n'
127
137
                       'subdir\n'
128
 
                       , '--from-root', '--non-recursive')
 
138
                       , '--from-root --non-recursive')
 
139
 
 
140
    def test_ls_path(self):
 
141
        """If a path is specified, files are listed with that prefix"""
 
142
        self.build_tree(['subdir/', 'subdir/b'])
 
143
        self.wt.add(['subdir', 'subdir/b'])
 
144
        self.ls_equals('subdir/b\n' ,
 
145
                       'subdir')
 
146
        os.chdir('subdir')
 
147
        self.ls_equals('../.bzrignore\n'
 
148
                       '../a\n'
 
149
                       '../subdir\n'
 
150
                       '../subdir/b\n' ,
 
151
                       '..')
 
152
        self.ls_equals('../.bzrignore\0'
 
153
                       '../a\0'
 
154
                       '../subdir\0'
 
155
                       '../subdir/b\0' ,
 
156
                       '.. --null')
 
157
        self.ls_equals('?        ../.bzrignore\n'
 
158
                       '?        ../a\n'
 
159
                       'V        ../subdir/\n'
 
160
                       'V        ../subdir/b\n' ,
 
161
                       '.. --verbose')
 
162
        self.run_bzr_error('cannot specify both --from-root and PATH',
 
163
                           'ls --from-root ..')
129
164
 
130
165
    def test_ls_revision(self):
131
166
        self.wt.add(['a'])
134
169
        self.build_tree(['subdir/'])
135
170
 
136
171
        # Check what happens when we supply a specific revision
137
 
        self.ls_equals('a\n', '--revision', '1')
 
172
        self.ls_equals('a\n', '--revision 1')
138
173
        self.ls_equals('V        a\n'
139
 
                       , '--verbose', '--revision', '1')
 
174
                       , '--verbose --revision 1')
140
175
 
141
176
        os.chdir('subdir')
142
 
        self.ls_equals('', '--revision', '1')
 
177
        self.ls_equals('', '--revision 1')
 
178
 
 
179
    def test_ls_branch(self):
 
180
        """If a branch is specified, files are listed from it"""
 
181
        self.build_tree(['subdir/', 'subdir/b'])
 
182
        self.wt.add(['subdir', 'subdir/b'])
 
183
        self.wt.commit('committing')
 
184
        branch = self.make_branch('branchdir')
 
185
        branch.pull(self.wt.branch)
 
186
        self.ls_equals('branchdir/subdir\n'
 
187
                       'branchdir/subdir/b\n',
 
188
                       'branchdir')
 
189
        self.ls_equals('branchdir/subdir\n'
 
190
                       'branchdir/subdir/b\n',
 
191
                       'branchdir --revision 1')
143
192
 
144
193
    def test_ls_ignored(self):
145
194
        # Now try to do ignored files.
146
195
        self.wt.add(['a', '.bzrignore'])
147
196
 
148
197
        self.build_tree(['blah.py', 'blah.pyo', 'user-ignore'])
149
 
        self.ls_equals('.bazaar\n'
150
 
                       '.bzrignore\n'
 
198
        self.ls_equals('.bzrignore\n'
151
199
                       'a\n'
152
200
                       'blah.py\n'
153
201
                       'blah.pyo\n'
154
202
                       'user-ignore\n'
155
203
                       )
156
 
        self.ls_equals('I        .bazaar/\n'
157
 
                       'V        .bzrignore\n'
 
204
        self.ls_equals('V        .bzrignore\n'
158
205
                       'V        a\n'
159
206
                       '?        blah.py\n'
160
207
                       'I        blah.pyo\n'
161
208
                       'I        user-ignore\n'
162
209
                       , '--verbose')
163
 
        self.ls_equals('.bazaar\n'
164
 
                       'blah.pyo\n'
 
210
        self.ls_equals('blah.pyo\n'
165
211
                       'user-ignore\n'
166
212
                       , '--ignored')
167
213
        self.ls_equals('blah.py\n'
170
216
                       'a\n'
171
217
                       , '--versioned')
172
218
 
 
219
    def test_kinds(self):
 
220
        self.build_tree(['subdir/'])
 
221
        self.ls_equals('.bzrignore\n' 
 
222
                       'a\n', 
 
223
                       '--kind=file')
 
224
        self.ls_equals('subdir\n',
 
225
                       '--kind=directory')
 
226
        self.ls_equals('',
 
227
                       '--kind=symlink')
 
228
        self.run_bzr_error('invalid kind specified', 'ls --kind=pile')