60
61
f.write("\nsome other new content!")
63
def run_bzr_remove_changed_files(self, error_regexes, files_to_remove):
64
def run_bzr_remove_changed_files(self, error_regexes, files_to_remove,
64
66
error_regexes.extend(["Can't safely remove modified or unknown files:",
65
67
'Use --keep to not delete them,'
66
68
' or --force to delete them regardless.'
68
70
self.run_bzr_error(error_regexes,
69
['remove'] + list(files_to_remove))
71
['remove'] + list(files_to_remove),
72
working_dir=working_dir)
70
73
#see if we can force it now
71
self.run_bzr(['remove', '--force'] + list(files_to_remove))
74
self.run_bzr(['remove', '--force'] + list(files_to_remove),
75
working_dir=working_dir)
77
def test_remove_new_no_files_specified(self):
78
tree = self.make_branch_and_tree('.')
79
self.run_bzr_error(["bzr: ERROR: No matching files."], 'remove --new')
80
self.run_bzr_error(["bzr: ERROR: No matching files."], 'remove --new .')
73
82
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."],
83
tree = self._make_tree_and_add(['foo'])
84
out, err = self.run_bzr(['rm'])
85
self.assertEqual('', err)
86
self.assertEqual('', out)
87
self.assertInWorkingTree('foo', tree=tree)
88
self.failUnlessExists('foo')
90
def test_remove_no_files_specified_missing_dir_and_contents(self):
91
tree = self._make_tree_and_add(
92
['foo', 'dir/', 'dir/missing/', 'dir/missing/child'])
93
self.get_transport('.').delete_tree('dir/missing')
94
out, err = self.run_bzr(['rm'])
95
self.assertEqual('', out)
97
'removed dir/missing/child\n'
98
'removed dir/missing\n',
100
# non-missing paths not touched:
101
self.assertInWorkingTree('foo', tree=tree)
102
self.failUnlessExists('foo')
103
self.assertInWorkingTree('dir', tree=tree)
104
self.failUnlessExists('dir')
105
# missing files unversioned
106
self.assertNotInWorkingTree('dir/missing', tree=tree)
107
self.assertNotInWorkingTree('dir/missing/child', tree=tree)
109
def test_remove_no_files_specified_already_deleted(self):
110
tree = self._make_tree_and_add(['foo', 'bar'])
111
tree.commit('save foo and bar')
114
self.assertEqual(None, tree.path2id('bar'))
115
# Running rm with a deleted file does not error.
116
out, err = self.run_bzr(['rm'])
117
self.assertEqual('', out)
118
self.assertEqual('', err)
120
def test_remove_no_files_specified_missing_file(self):
121
tree = self._make_tree_and_add(['foo', 'bar'])
123
out, err = self.run_bzr(['rm'])
124
self.assertEqual('', out)
125
self.assertEqual('removed bar\n', err)
126
# non-missing files not touched:
127
self.assertInWorkingTree('foo', tree=tree)
128
self.failUnlessExists('foo')
129
# missing files unversioned
130
self.assertNotInWorkingTree('bar', tree=tree)
132
def test_remove_no_files_specified_missing_link(self):
133
self.requireFeature(SymlinkFeature)
134
tree = self._make_tree_and_add(['foo'])
135
os.symlink('foo', 'linkname')
136
tree.add(['linkname'])
137
os.unlink('linkname')
138
out, err = self.run_bzr(['rm'])
139
self.assertEqual('', out)
140
self.assertEqual('removed linkname\n', err)
141
# non-missing files not touched:
142
self.assertInWorkingTree('foo', tree=tree)
143
self.failUnlessExists('foo')
144
# missing files unversioned
145
self.assertNotInWorkingTree('linkname', tree=tree)
83
147
def test_rm_one_file(self):
84
tree = self._make_add_and_assert_tree([a])
148
tree = self._make_tree_and_add([a])
85
149
self.run_bzr("commit -m 'added a'")
86
150
self.run_bzr('rm a', error_regexes=["deleted a"])
87
151
self.assertFilesDeleted([a])
89
153
def test_remove_one_file(self):
90
tree = self._make_add_and_assert_tree([a])
154
tree = self._make_tree_and_add([a])
91
155
self.run_bzr("commit -m 'added a'")
92
156
self.run_bzr('remove a', error_regexes=["deleted a"])
93
157
self.assertFilesDeleted([a])
95
159
def test_remove_keep_one_file(self):
96
tree = self._make_add_and_assert_tree([a])
160
tree = self._make_tree_and_add([a])
97
161
self.run_bzr('remove --keep a', error_regexes=["removed a"])
98
162
self.assertFilesUnversioned([a])
100
164
def test_remove_one_deleted_file(self):
101
tree = self._make_add_and_assert_tree([a])
165
tree = self._make_tree_and_add([a])
102
166
self.run_bzr("commit -m 'added a'")
104
168
self.assertInWorkingTree(a)
117
181
['unknown:[.\s]*d/[.\s]*b/c[.\s]*b/[.\s]*a'], files)
119
183
def test_remove_changed_files(self):
120
tree = self._make_add_and_assert_tree(files)
184
tree = self._make_tree_and_add(files)
121
185
self.run_bzr("commit -m 'added files'")
122
186
self.changeFile(a)
123
187
self.changeFile(c)
124
188
self.run_bzr_remove_changed_files(['modified:[.\s]*a[.\s]*b/c'], files)
190
def test_remove_changed_ignored_files(self):
191
tree = self._make_tree_and_add(['a'])
192
self.run_bzr(['ignore', 'a'])
193
self.run_bzr_remove_changed_files(['added:[.\s]*a'], ['a'])
126
195
def test_remove_changed_files_from_child_dir(self):
127
196
if sys.platform == 'win32':
128
197
raise TestSkipped("Windows unable to remove '.' directory")
129
tree = self._make_add_and_assert_tree(files)
198
tree = self._make_tree_and_add(files)
130
199
self.run_bzr("commit -m 'added files'")
131
200
self.changeFile(a)
132
201
self.changeFile(c)
134
self.run_bzr_remove_changed_files(['modified:[.\s]*a[.\s]*b/c'],
135
['../a', 'c', '.', '../d'])
202
self.run_bzr_remove_changed_files(
203
['modified:[.\s]*a[.\s]*b/c'],
204
['../a', 'c', '.', '../d'], working_dir='b')
137
205
self.assertNotInWorkingTree(files)
138
206
self.failIfExists(files)