~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Robert Collins
  • Date: 2008-08-13 03:52:23 UTC
  • mto: This revision was merged to the branch mainline in revision 3637.
  • Revision ID: robertc@robertcollins.net-20080813035223-i9sxgq2rp5477oc5
 * ``bzr rm`` will now scan for files that are missing and remove just
   them automatically, much as ``bzr add`` scans for new files that
   are not ignored and adds them automatically. (Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
import os
19
19
import sys
20
20
 
21
 
from bzrlib.tests import TestSkipped
 
21
from bzrlib.tests import SymlinkFeature, TestSkipped
22
22
from bzrlib.tests.blackbox import ExternalBase
23
23
from bzrlib.workingtree import WorkingTree
24
24
from bzrlib import osutils
33
33
 
34
34
class TestRemove(ExternalBase):
35
35
 
36
 
    def _make_add_and_assert_tree(self, files):
 
36
    def _make_add_and_assert_tree(self, paths):
37
37
        tree = self.make_branch_and_tree('.')
38
 
        self.build_tree(files)
39
 
        for f in files:
40
 
            id=str(f).replace('/', '_') + _id
41
 
            tree.add(f, id)
42
 
            self.assertEqual(tree.path2id(f), id)
43
 
            self.failUnlessExists(f)
44
 
            self.assertInWorkingTree(f)
 
38
        tree.lock_write()
 
39
        try:
 
40
            self.build_tree(paths)
 
41
            for path in paths:
 
42
                file_id=str(path).replace('/', '_') + _id
 
43
                tree.add(path, file_id)
 
44
        finally:
 
45
            tree.unlock()
45
46
        return tree
46
47
 
47
48
    def assertFilesDeleted(self, files):
71
72
        self.run_bzr(['remove', '--force'] + list(files_to_remove))
72
73
 
73
74
    def test_remove_no_files_specified(self):
74
 
        tree = self._make_add_and_assert_tree([])
75
 
        self.run_bzr_error(["bzr: ERROR: Specify one or more files to remove, "
76
 
            "or use --new."], 'remove')
77
 
 
78
 
        self.run_bzr_error(["bzr: ERROR: No matching files."], 'remove --new')
79
 
 
80
 
        self.run_bzr_error(["bzr: ERROR: No matching files."],
81
 
            'remove --new .')
 
75
        tree = self._make_add_and_assert_tree(['foo'])
 
76
        out, err = self.run_bzr(['rm'])
 
77
        self.assertEqual('', err)
 
78
        self.assertEqual('', out)
 
79
        self.assertInWorkingTree('foo', tree=tree)
 
80
        self.failUnlessExists('foo')
 
81
 
 
82
    def test_remove_no_files_specified_missing_dir_and_contents(self):
 
83
        tree = self._make_add_and_assert_tree(
 
84
            ['foo', 'dir/', 'dir/missing/', 'dir/missing/child'])
 
85
        self.get_transport('.').delete_tree('dir/missing')
 
86
        out, err = self.run_bzr(['rm'])
 
87
        self.assertEqual('', out)
 
88
        self.assertEqual(
 
89
            'removed dir/missing/child\n'
 
90
            'removed dir/missing\n',
 
91
            err)
 
92
        # non-missing paths not touched:
 
93
        self.assertInWorkingTree('foo', tree=tree)
 
94
        self.failUnlessExists('foo')
 
95
        self.assertInWorkingTree('dir', tree=tree)
 
96
        self.failUnlessExists('dir')
 
97
        # missing files unversioned
 
98
        self.assertNotInWorkingTree('dir/missing', tree=tree)
 
99
        self.assertNotInWorkingTree('dir/missing/child', tree=tree)
 
100
 
 
101
    def test_remove_no_files_specified_missing_file(self):
 
102
        tree = self._make_add_and_assert_tree(['foo', 'bar'])
 
103
        os.unlink('bar')
 
104
        out, err = self.run_bzr(['rm'])
 
105
        self.assertEqual('', out)
 
106
        self.assertEqual('removed bar\n', err)
 
107
        # non-missing files not touched:
 
108
        self.assertInWorkingTree('foo', tree=tree)
 
109
        self.failUnlessExists('foo')
 
110
        # missing files unversioned
 
111
        self.assertNotInWorkingTree('bar', tree=tree)
 
112
 
 
113
    def test_remove_no_files_specified_missing_link(self):
 
114
        self.requireFeature(SymlinkFeature)
 
115
        tree = self._make_add_and_assert_tree(['foo'])
 
116
        os.symlink('foo', 'linkname')
 
117
        tree.add(['linkname'])
 
118
        os.unlink('linkname')
 
119
        out, err = self.run_bzr(['rm'])
 
120
        self.assertEqual('', out)
 
121
        self.assertEqual('removed linkname\n', err)
 
122
        # non-missing files not touched:
 
123
        self.assertInWorkingTree('foo', tree=tree)
 
124
        self.failUnlessExists('foo')
 
125
        # missing files unversioned
 
126
        self.assertNotInWorkingTree('linkname', tree=tree)
82
127
 
83
128
    def test_rm_one_file(self):
84
129
        tree = self._make_add_and_assert_tree([a])