34
34
class TestRemove(ExternalBase):
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)
40
id=str(f).replace('/', '_') + _id
42
self.assertEqual(tree.path2id(f), id)
43
self.failUnlessExists(f)
44
self.assertInWorkingTree(f)
40
self.build_tree(paths)
42
file_id=str(path).replace('/', '_') + _id
43
tree.add(path, file_id)
47
48
def assertFilesDeleted(self, files):
71
72
self.run_bzr(['remove', '--force'] + list(files_to_remove))
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')
78
self.run_bzr_error(["bzr: ERROR: No matching files."], 'remove --new')
80
self.run_bzr_error(["bzr: ERROR: No matching files."],
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')
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)
89
'removed dir/missing/child\n'
90
'removed dir/missing\n',
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)
101
def test_remove_no_files_specified_missing_file(self):
102
tree = self._make_add_and_assert_tree(['foo', '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)
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)
83
128
def test_rm_one_file(self):
84
129
tree = self._make_add_and_assert_tree([a])