[patch] 'bzr mv' with no arguments breaks

Wouter van Heyst larstiq at larstiq.dyndns.org
Sat Jul 8 13:17:34 BST 2006


On Wed, Jul 05, 2006 at 08:50:26AM -0500, John Arbash Meinel wrote:
> Wouter van Heyst wrote:
> > Moshe Zadka reported bzr mv failing with 
> > bzr: ERROR: exceptions.TypeError: len() of unsized object
> > 
> > The issue itself is easy to fix, but in writing a test I decided to
> > extract old move tests from too_much.OldTests. Ouch.
> > 
> > I'm not really happy with the result, one problem I don't understand is that
> > commit on a workingtree works differently than self.run_bzr('commit')
> 
> One thing you have to be aware of, is that a WorkingTree object won't
> necessarily reload its state if you use run_bzr behind its back.
> 
> So doing:
> 
> wt = self.make_branch_and_tree('.')
> ...
> self.run_bzr('mv', 'a', 'b')
> 
> You may need to do one of:
> self.wt.read_inventory()
> 
> or
> self.wt = self.wt.bzrdir.open_workingtree()

Ah, that certainly got me. Doing a tree.read_working_inventory() after
moving around files fixes the problem for me.

...

> > +    def test_mv_unversioned(self):
> > +        self.build_tree(['unversioned.txt'])
> > +        out, err = self.run_bzr('mv', 'unversioned.txt', 'elsewhere', retcode=3)
> > +        self.assertContainsRe(err, "^bzr: ERROR: can't rename: old name .* is not versioned\n")
> > +
> 
> You can use the new: self.run_bzr_error() function, which takes a list
> of regexes to match on the error output. This would make it:
> self.run_bzr_error(["^bzr: ERROR: can't rename: old name .* ..."],
> 		   'mv', 'unversioned.txt', 'elsewhere')
> 
> It defaults to retcode=3

That is certainly useful. I've now also replaced the assertEquals, but
I'm not sure that is a good idea. This way I'm not asserting that the
error is all the output there is, and you can easily exceed 80 columns
if you don't want to split the error string. 

> The rest all looks good. It would be nice if you could figure out why
> committing doesn't do what you want, and do a little bit of cleanup. Let
> me know if you find run_bzr_error() ugly for any reason. I'd like it to
> be a helpful function. But otherwise +1 from me.

I've cleaned the patch up a bit, I'll see if I can find out where the
bug in workingtree is, but rereading the inventory works for now.

Wouter van Heyst
-------------- next part --------------
# Bazaar revision bundle v0.8
#
# message:
#   Don't fail on 'bzr mv', extract move tests from OldTests.
# committer: Wouter van Heyst <larstiq at larstiq.dyndns.org>
# date: Sat 2006-07-08 14:11:28.915580034 +0200

=== added file bzrlib/tests/blackbox/test_mv.py // file-id:test_mv.py-200607051
... 14902-33tkxz0o9cdshemo-1
--- /dev/null
+++ bzrlib/tests/blackbox/test_mv.py
@@ -0,0 +1,118 @@
+# Copyright (C) 2006 by Canonical Ltd
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+"""Test for 'bzr mv'"""
+
+import os
+
+from bzrlib.tests import TestCaseWithTransport
+
+
+class TestMove(TestCaseWithTransport):
+
+    def test_mv_modes(self):
+        """Test two modes of operation for mv"""
+        tree = self.make_branch_and_tree('.')
+        files = self.build_tree(['a', 'c', 'subdir/'])
+        tree.add(['a', 'c', 'subdir'])
+
+        self.run_bzr('mv', 'a', 'b')
+        self.run_bzr('mv', 'b', 'subdir')
+        self.run_bzr('mv', 'subdir/b', 'a')
+        self.run_bzr('mv', 'a', 'c', 'subdir')
+        self.run_bzr('mv', 'subdir/a', 'subdir/newa')
+
+    def test_mv_unversioned(self):
+        self.build_tree(['unversioned.txt'])
+        self.run_bzr_error(
+            ["^bzr: ERROR: can't rename: old name .* is not versioned$"],
+            'mv', 'unversioned.txt', 'elsewhere')
+
+    def test_mv_nonexisting(self):
+        self.run_bzr_error(
+            ["^bzr: ERROR: can't rename: old working file .* does not exist$"],
+            'mv', 'doesnotexist', 'somewhereelse')
+
+    def test_mv_unqualified(self):
+        self.run_bzr_error(['^bzr: ERROR: missing file argument$'], 'mv')
+        
+    def test_mv_newly_added(self):
+        tree = self.make_branch_and_tree('.')
+        self.build_tree(['test.txt'])
+        tree.add(['test.txt'])
+
+        self.run_bzr('mv', 'test.txt', 'hello.txt')
+        self.failUnlessExists("hello.txt")
+        self.failIfExists("test.txt")
+
+    def test_mv_invalid(self):
+        tree = self.make_branch_and_tree('.')
+        self.build_tree(['test.txt', 'sub1/'])
+        tree.add(['test.txt'])
+
+        self.run_bzr_error(
+            ["^bzr: ERROR: destination u'sub1' is not a versioned directory$"],
+            'rename', 'test.txt', 'sub1')
+        
+        self.run_bzr_error(
+            ["^bzr: ERROR: can't determine destination directory id for u'sub1'$"],
+            'rename', 'test.txt', 'sub1/hello.txt')
+        
+        self.run_bzr_error(
+            ["^bzr: ERROR: destination u'sub1' is not a versioned directory$"],
+            'move', 'test.txt', 'sub1')
+    
+    def test_mv_dirs(self):
+        tree = self.make_branch_and_tree('.')
+        self.build_tree(['hello.txt', 'sub1/'])
+        tree.add(['hello.txt', 'sub1'])
+
+        self.run_bzr('rename', 'sub1', 'sub2')
+        self.run_bzr('move', 'hello.txt', 'sub2')
+
+        self.failUnlessExists("sub2")
+        self.failUnlessExists("sub2/hello.txt")
+        self.failIfExists("sub1")
+        self.failIfExists("hello.txt")
+
+        tree.read_working_inventory()
+        tree.commit('commit with some things moved to subdirs')
+
+        self.build_tree(['sub1/'])
+        tree.add(['sub1'])
+        self.run_bzr('move', 'sub2/hello.txt', 'sub1')
+        self.failIfExists('sub2/hello.txt')
+        self.failUnlessExists('sub1/hello.txt')
+        self.run_bzr('move', 'sub2', 'sub1')
+        self.failIfExists('sub2')
+        self.failUnlessExists('sub1/sub2')
+
+    def test_mv_relative(self): 
+        self.build_tree(['sub1/', 'sub1/sub2/', 'sub1/hello.txt'])
+        tree = self.make_branch_and_tree('.')
+        tree.add(['sub1', 'sub1/sub2', 'sub1/hello.txt'])
+        tree.commit('initial tree')
+
+        os.chdir('sub1/sub2')
+        self.run_bzr('move', '../hello.txt', '.')
+        self.failUnlessExists('./hello.txt')
+        tree.read_working_inventory()
+        tree.commit('move to parent directory')
+
+        os.chdir('..')
+
+        self.run_bzr('move', 'sub2/hello.txt', '.')
+        self.failUnlessExists('hello.txt')

=== modified file bzrlib/builtins.py
--- bzrlib/builtins.py
+++ bzrlib/builtins.py
@@ -375,6 +375,9 @@
     encoding_type = 'replace'
 
     def run(self, names_list):
+        if names_list is None:
+            names_list = []
+
         if len(names_list) < 2:
             raise BzrCommandError("missing file argument")
         tree, rel_names = tree_files(names_list)

=== modified file bzrlib/tests/blackbox/__init__.py
--- bzrlib/tests/blackbox/__init__.py
+++ bzrlib/tests/blackbox/__init__.py
@@ -64,6 +64,7 @@
                      'bzrlib.tests.blackbox.test_logformats',
                      'bzrlib.tests.blackbox.test_merge',
                      'bzrlib.tests.blackbox.test_missing',
+                     'bzrlib.tests.blackbox.test_mv',
                      'bzrlib.tests.blackbox.test_outside_wt',
                      'bzrlib.tests.blackbox.test_pull',
                      'bzrlib.tests.blackbox.test_push',

=== modified file bzrlib/tests/blackbox/test_too_much.py
--- bzrlib/tests/blackbox/test_too_much.py
+++ bzrlib/tests/blackbox/test_too_much.py
@@ -147,17 +147,6 @@
         self.runbzr('revert')
         os.chdir('..')
 
-    def test_mv_modes(self):
-        """Test two modes of operation for mv"""
-        self.runbzr('init')
-        self.build_tree(['a', 'c', 'subdir/'])
-        self.run_bzr_captured(['add', self.test_dir])
-        self.run_bzr_captured(['mv', 'a', 'b'])
-        self.run_bzr_captured(['mv', 'b', 'subdir'])
-        self.run_bzr_captured(['mv', 'subdir/b', 'a'])
-        self.run_bzr_captured(['mv', 'a', 'c', 'subdir'])
-        self.run_bzr_captured(['mv', 'subdir/a', 'subdir/newa'])
-
     def test_main_version(self):
         """Check output from version command and master option is reasonable"""
         # output is intentionally passed through to stdout so that we
@@ -677,81 +666,20 @@
         out = capture("help ci")
         out.index('aliases: ')
 
-        progress("can't rename unversioned file")
-        runbzr("rename test.txt new-test.txt", 3)
-
-        progress("adding a file")
-
-        runbzr("add test.txt")
-        self.assertEquals(capture("unknowns"), '')
-
-        progress("rename newly-added file")
-        runbzr("rename test.txt hello.txt")
-        self.assert_(os.path.exists("hello.txt"))
-        self.assert_(not os.path.exists("test.txt"))
-
-        self.assertEquals(capture("revno"), '0\n')
-
-        progress("add first revision")
-        runbzr(['commit', '-m', 'add first revision'])
-
-        progress("more complex renames")
-        os.mkdir("sub1")
-        runbzr("rename hello.txt sub1", 3)
-        runbzr("rename hello.txt sub1/hello.txt", 3)
-        runbzr("move hello.txt sub1", 3)
-
-        runbzr("add sub1")
-        runbzr("rename sub1 sub2")
-        runbzr("move hello.txt sub2")
-        self.assertEqual(capture("relpath sub2/hello.txt"),
-                         pathjoin("sub2", "hello.txt\n"))
-
-        self.assert_(exists("sub2"))
-        self.assert_(exists("sub2/hello.txt"))
-        self.assert_(not exists("sub1"))
-        self.assert_(not exists("hello.txt"))
-
-        runbzr(['commit', '-m', 'commit with some things moved to subdirs'])
-
-        mkdir("sub1")
-        runbzr('add sub1')
-        runbzr('move sub2/hello.txt sub1')
-        self.assert_(not exists('sub2/hello.txt'))
-        self.assert_(exists('sub1/hello.txt'))
-        runbzr('move sub2 sub1')
-        self.assert_(not exists('sub2'))
-        self.assert_(exists('sub1/sub2'))
-
-        runbzr(['commit', '-m', 'rename nested subdirectories'])
-
-        chdir('sub1/sub2')
-        self.assertEquals(capture('root')[:-1],
-                          pathjoin(self.test_dir, 'branch1'))
-        runbzr('move ../hello.txt .')
-        self.assert_(exists('./hello.txt'))
-        self.assertEquals(capture('relpath hello.txt'),
-                          pathjoin('sub1', 'sub2', 'hello.txt') + '\n')
-        self.assertEquals(capture('relpath ../../sub1/sub2/hello.txt'), pathjoin('sub1', 'sub2', 'hello.txt\n'))
-        runbzr(['commit', '-m', 'move to parent directory'])
-        chdir('..')
-        self.assertEquals(capture('relpath sub2/hello.txt'), pathjoin('sub1', 'sub2', 'hello.txt\n'))
-
-        runbzr('move sub2/hello.txt .')
-        self.assert_(exists('hello.txt'))
-
         f = file('hello.txt', 'wt')
         f.write('some nice new content\n')
         f.close()
 
+        runbzr("add hello.txt")
+        
         f = file('msg.tmp', 'wt')
         f.write('this is my new commit\nand it has multiple lines, for fun')
         f.close()
 
         runbzr('commit -F msg.tmp')
 
-        self.assertEquals(capture('revno'), '5\n')
-        runbzr('export -r 5 export-5.tmp')
+        self.assertEquals(capture('revno'), '1\n')
+        runbzr('export -r 1 export-1.tmp')
         runbzr('export export.tmp')
 
         runbzr('log')

# revision id: larstiq at larstiq.dyndns.org-20060708121128-690bb2a2742b283d
# sha1: 7320d59b16078a12814fa0d673b1a59303ad0eaa
# inventory sha1: ece2c09bd170ad88f07a50a079a1bfa3a97979fe
# parent ids:
#   pqm at pqm.ubuntu.com-20060708044058-a64fc46ea66545cb
# base id: pqm at pqm.ubuntu.com-20060708044058-a64fc46ea66545cb
# properties:
#   branch-nick: bzr.fixes



More information about the bazaar mailing list