Using Bazaar programatically

James Westby jw+debian at jameswestby.net
Fri Feb 8 17:31:16 GMT 2008


On Fri, 2008-02-08 at 12:44 +0100, Gertjan Klein wrote:
> 
> from bzrlib import workingtree
> 
> def test():
>     dir = r'C:\dev\bzr\cache'
>     file = r'C:\dev\bzr\cache\test.txt'
>     files = [file]
>     message = "Test commit"
>     wtree = workingtree.WorkingTree.open(dir)
>     wtree.smart_add(files)
>     wtree.commit(message, specific_files=files)
> 
> if __name__ == '__main__':
>     test()
> 
> This gives me an exception:
> 
> >Traceback (most recent call last):
> >  File "C:\Temp\commit_test.py", line 13, in <module>
> >    test()
> >  File "C:\Temp\commit_test.py", line 10, in test
> >    wtree.commit(message, specific_files=files)
> >  File "<string>", line 4, in commit_write_locked
> >  File "C:\dev\Python\Python25\Lib\site-packages\bzrlib\workingtree_4.py", line 246, in commit
> >    result = WorkingTree3.commit(self, message, revprops, *args, **kwargs)
> >  File "<string>", line 4, in commit_write_locked
> >  File "C:\dev\Python\Python25\Lib\site-packages\bzrlib\mutabletree.py", line 187, in commit
> >    revprops=revprops, *args, **kwargs)
> >  File "C:\dev\Python\Python25\Lib\site-packages\bzrlib\commit.py", line 315, in commit
> >    specific_files, [self.basis_tree, self.work_tree])
> >  File "C:\dev\Python\Python25\Lib\site-packages\bzrlib\tree.py", line 596, in find_ids_across_trees
> >    require_versioned)
> >  File "C:\dev\Python\Python25\Lib\site-packages\bzrlib\tree.py", line 623, in _find_ids_across_trees
> >    raise errors.PathsNotVersionedError(not_versioned)
> >bzrlib.errors.PathsNotVersionedError: Path(s) are not versioned: C:\dev\bzr\cache\test.txt
> 
> Oddly, smart_add() seems to accept the file, but commit doesn't. Any
> ideas?

Hi,

My hunch is that if you supply the relative path of the files from the
root of the branch to commit() then it will work.

The reason smart_add() works I think is that it is "smart". If you just
used add() then you would have the same problem.

You may like to look in to the tests in bzrlib/tests/ as they
demonstrate the use of the API. Also, looking at some other plugins
may help.

Thanks,

James





More information about the bazaar mailing list