[MERGE] [bug #111664] bzr rm refuses to delete renamed files

Alexander Belchenko bialix at ukr.net
Fri May 4 07:42:59 BST 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Marius Kruger пишет:
> On 5/3/07, Marius Kruger <amanic at gmail.com> wrote:
>> hi
>>
>> here is the fix for the above mentioned bug,
>> I still need to add a test for a modified renamed file.
> done

=== modified file bzrlib/tests/workingtree_implementations/test_remove.py
- --- bzrlib/tests/workingtree_implementations/test_remove.py
+++ bzrlib/tests/workingtree_implementations/test_remove.py
@@ -24,6 +24,7 @@
     """Tests WorkingTree.remove"""

     files=['a', 'b/', 'b/c', 'd/']
+    rfiles=['b/c', 'b', 'a', 'd']

^-- please use spaces around =, i.e.

    files = ['a', 'b/', 'b/c', 'd/']
    rfiles = ['b/c', 'b', 'a', 'd']



@@ -34,6 +35,11 @@
         self.build_tree(TestRemove.files)
         return tree

+    def writeFile(self, relpath, content="Some content"):
+        f = file(relpath, 'wb')
+        f.write(content)
+        f.close()
+

^-- Martin always suggest to use try-finally block for such things, i.e.

        f = file(relpath, 'wb')
	try:
	        f.write(content)
	finally:
		f.close()


+    def test_remove_renamed_changed_files(self):
+        """Check that files are not removed if they are renamed and changed."""
+        tree = self.getTree()
+        tree.add(TestRemove.files)
+        tree.commit("make sure files are versioned")
+
+        for f in TestRemove.rfiles:
+            tree.rename_one(f,f+'x')
+        rfilesx = ['bx/cx', 'bx', 'ax', 'dx']
+        self.writeFile('ax','changed and renamed!')
+        self.writeFile('bx/cx','changed and renamed!')
+        self.assertInWorkingTree(rfilesx)
+        self.failUnlessExists(rfilesx)
+
+        try:
+            tree.remove(rfilesx, keep_files=False)
+            self.fail('Should throw BzrRemoveChangedFilesError')
+        except errors.BzrRemoveChangedFilesError, e:
+            self.assertTrue(re.match('Can\'t remove changed or unknown files:'
+                '.*modified:.*ax.*bx/cx.*',
+                str(e), re.DOTALL))
+        self.assertInWorkingTree(rfilesx)
+        self.failUnlessExists(rfilesx)
+

^-- I'd like to propose instead of manual try-except use something similar
    to recipe from Ned Batchelder:
	http://www.nedbatchelder.com/blog/200609.html#e20060905T064418
    But his original recipe don't use regular expressions match, only
    strings compare.

[µ]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGOtXzzYr338mxwCURAqO7AJ4sU8WC4z4ZaqsZ7hyb/C3wKq1YCQCfZ9yv
qaiOcrjxwyGvU/VSvq0lA/U=
=kAmV
-----END PGP SIGNATURE-----



More information about the bazaar mailing list