1
# Copyright (C) 2006 by 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(['./.bazaar', '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):
 
 
40
        out, err = self.run_bzr('ls', *args)
 
 
41
        self.assertEqual('', err)
 
 
42
        self.assertEqual(value, out)
 
 
44
    def test_ls_null_verbose(self):
 
 
46
        self.run_bzr_error(['Cannot set both --verbose and --null'],
 
 
47
                           'ls', '--verbose', '--null')
 
 
49
    def test_ls_basic(self):
 
 
50
        """Test the abilities of 'bzr ls'"""
 
 
51
        self.ls_equals('.bazaar\n.bzrignore\na\n')
 
 
52
        self.ls_equals('I        .bazaar/\n'
 
 
56
        self.ls_equals('.bzrignore\n'
 
 
59
        self.ls_equals('.bazaar\n', '--ignored')
 
 
60
        self.ls_equals('', '--versioned')
 
 
61
        self.ls_equals('.bazaar\n'
 
 
64
                       '--unknown', '--ignored', '--versioned')
 
 
65
        self.ls_equals('.bazaar\n', '--ignored', '--versioned')
 
 
66
        self.ls_equals('.bazaar\0.bzrignore\0a\0', '--null')
 
 
68
    def test_ls_added(self):
 
 
70
        self.ls_equals('I        .bazaar/\n'
 
 
76
        self.build_tree(['subdir/'])
 
 
77
        self.ls_equals('I        .bazaar/\n'
 
 
82
        self.build_tree(['subdir/b'])
 
 
83
        self.wt.add(['subdir/', 'subdir/b', '.bzrignore'])
 
 
84
        self.ls_equals('I        .bazaar/\n'
 
 
91
    def test_ls_recursive(self):
 
 
92
        self.build_tree(['subdir/', 'subdir/b'])
 
 
93
        self.wt.add(['a', 'subdir/', 'subdir/b', '.bzrignore'])
 
 
95
        self.ls_equals('.bazaar\n'
 
 
101
        self.ls_equals('I        .bazaar/\n'
 
 
105
                       , '--verbose', '--non-recursive')
 
 
107
        # Check what happens in a sub-directory
 
 
109
        self.ls_equals('b\n')
 
 
112
        self.ls_equals('.bazaar\n'
 
 
118
        self.ls_equals('.bazaar\0'
 
 
123
                       , '--from-root', '--null')
 
 
124
        self.ls_equals('.bazaar\n'
 
 
128
                       , '--from-root', '--non-recursive')
 
 
130
    def test_ls_revision(self):
 
 
132
        self.wt.commit('add')
 
 
134
        self.build_tree(['subdir/'])
 
 
136
        # Check what happens when we supply a specific revision
 
 
137
        self.ls_equals('a\n', '--revision', '1')
 
 
138
        self.ls_equals('V        a\n'
 
 
139
                       , '--verbose', '--revision', '1')
 
 
142
        self.ls_equals('', '--revision', '1')
 
 
144
    def test_ls_ignored(self):
 
 
145
        # Now try to do ignored files.
 
 
146
        self.wt.add(['a', '.bzrignore'])
 
 
148
        self.build_tree(['blah.py', 'blah.pyo', 'user-ignore'])
 
 
149
        self.ls_equals('.bazaar\n'
 
 
156
        self.ls_equals('I        .bazaar/\n'
 
 
163
        self.ls_equals('.bazaar\n'
 
 
167
        self.ls_equals('blah.py\n'
 
 
169
        self.ls_equals('.bzrignore\n'