[patch] 'bzr mv' with no arguments breaks

Wouter van Heyst larstiq at larstiq.dyndns.org
Wed Jul 5 13:04:16 BST 2006


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')

With tree.commit('move to parent directory') in test_mv_relative uncommented
the move results in hello.txt being unversioned. But with run_bzr, all is fine.


"bzr: ERROR: u'sub1/sub2/hello.txt' is not versioned\n"

^^^^[log from bzrlib.tests.blackbox.test_mv.TestMove.test_mv_relative]--------
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/larstiq/src/bzr/bzr.fixes/bzrlib/tests/blackbox/test_mv.py", line 111, in test_mv_relative
    self.run_bzr('move', 'sub2/hello.txt', '.')
  File "/home/larstiq/src/bzr/bzr.fixes/bzrlib/tests/__init__.py", line 742, in run_bzr
    return self.run_bzr_captured(args, retcode=retcode, encoding=encoding, stdin=stdin)
  File "/home/larstiq/src/bzr/bzr.fixes/bzrlib/tests/__init__.py", line 724, in run_bzr_captured
    self.assertEquals(retcode, result)
AssertionError: 0 != 3


Other than not using commits as much as in too_much I also dropped some relpath
invocations in the conversion, it wasn't entirely sure what was being tested
and what was auxiliary in OldTests.

Patch attached in hope of enlightenment,
Wouter van Heyst
-------------- next part --------------
=== added file 'bzrlib/tests/blackbox/test_mv.py'
--- bzrlib/tests/blackbox/test_mv.py	1970-01-01 00:00:00 +0000
+++ bzrlib/tests/blackbox/test_mv.py	2006-07-05 12:04:05 +0000
@@ -0,0 +1,113 @@
+# 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'])
+        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")
+
+    def test_mv_nonexisting(self):
+        out, err = self.run_bzr('mv', 'doesnotexist', 'somewhereelse', retcode=3)
+        self.assertContainsRe(err, "^bzr: ERROR: can't rename: old working file .* does not exist\n")
+
+    def test_mv_unqualified(self):
+        out, err = self.run_bzr('mv', retcode=3)
+        self.assertEquals('bzr: ERROR: missing file argument\n', err)
+
+    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'])
+
+        out, err = self.run_bzr('rename', 'test.txt', 'sub1', retcode=3)
+        self.assertEquals("bzr: ERROR: destination u'sub1' is not a versioned directory\n", err)
+
+        out, err = self.run_bzr('rename', 'test.txt', 'sub1/hello.txt', retcode=3)
+        self.assertEquals("bzr: ERROR: can't determine destination directory id for u'sub1'\n", err)
+        self.run_bzr('move', 'test.txt', 'sub1', retcode=3)
+    
+    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.commit('commit with some things moved to subdirs', allow_pointless=False)
+        #self.run_bzr('commit', '-m', 'move somethings')
+
+        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')
+        # this commit makes hello.txt unversioned, que?
+        #tree.commit('move to parent directory')
+        self.run_bzr('commit', '-m', '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	2006-07-03 13:35:59 +0000
+++ bzrlib/builtins.py	2006-07-05 11:36:10 +0000
@@ -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	2006-07-03 08:12:23 +0000
+++ bzrlib/tests/blackbox/__init__.py	2006-07-04 12:10:52 +0000
@@ -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	2006-07-03 13:48:52 +0000
+++ bzrlib/tests/blackbox/test_too_much.py	2006-07-04 13:17:37 +0000
@@ -177,17 +177,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
@@ -707,81 +696,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')



More information about the bazaar mailing list