[BUG] bzr mkdir subdir fails... -> patch: test+fix

John A Meinel john at arbash-meinel.com
Fri Nov 11 13:57:23 GMT 2005


Alexander Belchenko wrote:
> Alexander Belchenko wrote:
>  > When I trying to make dir via 'bzr mkdir' command in subdirectory
>  > (not in the root directory of tree) then directory successfully created
>  > but during add bzr fails:...
> 
> I'm creating selftest and fix for this bug. Please review attached patch.
> 
> Alexander
> 
> 
> ------------------------------------------------------------------------
> 
> === modified file 'bzrlib\\builtins.py'
> --- bzrlib\builtins.py
> +++ bzrlib\builtins.py
> @@ -239,8 +239,10 @@
>              os.mkdir(d)
>              if not b:
>                  b = Branch.open_containing(d)[0]
> -            b.add([d])
> -            print 'added', d
> +                tree = b.working_tree()
> +            dd = tree.relpath(d)
> +            b.add([dd])
> +            print 'added', dd

Actually, there should be a simpler fix:

if not b:
    b, dd = Branch.open_containing(d)
else:
    dd = b.working_tree().relpath(d)

b.add([dd])
print 'added', dd

The open_containing() function returns both the branch, and the relative
path to what you requested.

Thanks for the tests. If Martin doesn't say he's merged this, than I'll
merge it into my integration branch by tomorrow.

John
=:->

>  
>  
>  class cmd_relpath(Command):
> 
> === modified file 'bzrlib\\selftest\\versioning.py'
> --- bzrlib\selftest\versioning.py
> +++ bzrlib\selftest\versioning.py
> @@ -52,6 +52,33 @@
>          self.assertEquals(len(delta.added), 1)
>          self.assertEquals(delta.added[0][0], 'foo')
>          self.failIf(delta.modified)
> +
> +    def test_mkdir_in_subdir(self):
> +        """'bzr mkdir' operation in subdirectory"""
> +
> +        self.run_bzr('init')
> +        self.run_bzr('mkdir', 'dir')
> +        self.assert_(os.path.isdir('dir'))
> +
> +        os.chdir('dir')
> +        self.log('Run mkdir in subdir')
> +        self.run_bzr('mkdir', 'subdir')
> +        self.assert_(os.path.isdir('subdir'))
> +        os.chdir('..')
> +
> +        from bzrlib.diff import compare_trees
> +        from bzrlib.branch import Branch
> +        b = Branch.open('.')
> +        
> +        delta = compare_trees(b.basis_tree(), b.working_tree())
> +
> +        self.log('delta.added = %r' % delta.added)
> +
> +        self.assertEquals(len(delta.added), 2)
> +        self.assertEquals(delta.added[0][0], 'dir')
> +        self.assertEquals(delta.added[1][0], os.path.join('dir','subdir'))
> +        self.failIf(delta.modified)
> +
>  
>      def test_branch_add_in_unversioned(self):
>          """Try to add a file in an unversioned directory.
> 
> 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 249 bytes
Desc: OpenPGP digital signature
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20051111/ae12ff88/attachment.pgp 


More information about the bazaar mailing list