1
# Copyright (C) 2005, 2009 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
19
from StringIO import StringIO
21
from bzrlib.bzrdir import (
24
from bzrlib.clean_tree import (
28
from bzrlib.osutils import (
31
from bzrlib.tests import (
36
class TestCleanTree(TestCaseInTempDir):
38
def test_symlinks(self):
39
if has_symlinks() is False:
42
BzrDir.create_standalone_workingtree('branch')
43
os.symlink(os.path.realpath('no-die-please'), 'branch/die-please')
44
os.mkdir('no-die-please')
45
self.failUnlessExists('branch/die-please')
46
os.mkdir('no-die-please/child')
48
clean_tree('branch', unknown=True, no_prompt=True)
49
self.failUnlessExists('no-die-please')
50
self.failUnlessExists('no-die-please/child')
52
def test_iter_deletable(self):
53
"""Files are selected for deletion appropriately"""
55
tree = BzrDir.create_standalone_workingtree('branch')
56
transport = tree.bzrdir.root_transport
57
transport.put_bytes('.bzrignore', '*~\n*.pyc\n.bzrignore\n')
58
transport.put_bytes('file.BASE', 'contents')
61
self.assertEqual(len(list(iter_deletables(tree, unknown=True))), 1)
62
transport.put_bytes('file', 'contents')
63
transport.put_bytes('file~', 'contents')
64
transport.put_bytes('file.pyc', 'contents')
65
dels = sorted([r for a,r in iter_deletables(tree, unknown=True)])
66
self.assertEqual(['file', 'file.BASE'], dels)
68
dels = [r for a,r in iter_deletables(tree, detritus=True)]
69
self.assertEqual(sorted(['file~', 'file.BASE']), dels)
71
dels = [r for a,r in iter_deletables(tree, ignored=True)]
72
self.assertEqual(sorted(['file~', 'file.pyc', '.bzrignore']),
75
dels = [r for a,r in iter_deletables(tree, unknown=False)]
76
self.assertEqual([], dels)