Tag command breaks badly with empty repository

Bug #93853 reported by Gustavo Niemeyer
6
Affects Status Importance Assigned to Milestone
Bazaar
Fix Released
Medium
Unassigned

Bug Description

[niemeyer@burma ~]% mkdir a
[niemeyer@burma ~]% cd a
[niemeyer@burma ~/a]% bzr init --format=dirstate-tags
[niemeyer@burma ~/a]% bzr tag foo
bzr: ERROR: exceptions.KeyError: <type 'NoneType'>

Traceback (most recent call last):
  File "/usr/lib/python2.4/site-packages/bzrlib/commands.py", line 650, in run_bzr_catch_errors
    return run_bzr(argv)
  File "/usr/lib/python2.4/site-packages/bzrlib/commands.py", line 612, in run_bzr
    ret = run(*run_argv)
  File "/usr/lib/python2.4/site-packages/bzrlib/commands.py", line 304, in run_argv_aliases
    return self.run(**all_cmd_args)
  File "/usr/lib/python2.4/site-packages/bzrlib/builtins.py", line 3470, in run
    branch.tags.set_tag(tag_name, revision_id)
  File "/usr/lib/python2.4/site-packages/bzrlib/tag.py", line 87, in set_tag
    self._set_tag_dict(td)
  File "/usr/lib/python2.4/site-packages/bzrlib/tag.py", line 137, in _set_tag_dict
    self._serialize_tag_dict(new_dict))
  File "/usr/lib/python2.4/site-packages/bzrlib/tag.py", line 144, in _serialize_tag_dict
    return bencode.bencode(td)
  File "/usr/lib/python2.4/site-packages/bzrlib/util/bencode.py", line 299, in bencode
    encode_func[type(x)](x, r)
  File "/usr/lib/python2.4/site-packages/bzrlib/util/bencode.py", line 279, in encode_dict
    encode_func[type(v)](v, r)
KeyError: <type 'NoneType'>

bzr 0.15.0candidate2 on python 2.4.4.candidate.1 (linux2)
arguments: ['/usr/bin/bzr', 'tag', 'foo']

** please send this report to <email address hidden>

Revision history for this message
John A Meinel (jameinel) wrote :

This seems to be 2-fold

First, with no commits "bzr tag foo" is creating a tag and pointing it at None, which I don't think we really want.

This is being exposed at the bencode layer, because bencode cannot handle None.

bencode should probably be exposing a better exception, but since it isn't our code, we may just need to do that at a higher level.

But I *think* the 'bzr tag' command should just complain "You are trying to create a tag pointing to None".

Either that, or it should change tags pointing to None into pointing them at "null:". But I probably would rather not expose "null:" if we can help it.

Revision history for this message
Martin Pool (mbp) wrote :

I agree with John

Changed in bzr:
importance: Undecided → Medium
status: Unconfirmed → Confirmed
Revision history for this message
Tim Hatch (timhatch) wrote :

I also agree with John, having just hit this. Something along the lines of:

=== modified file 'bzrlib/builtins.py'
--- bzrlib/builtins.py 2007-07-23 19:37:15 +0000
+++ bzrlib/builtins.py 2007-07-27 22:24:01 +0000
@@ -3847,6 +3847,10 @@
                     revision_id = revision[0].in_history(branch).rev_id
                 else:
                     revision_id = branch.last_revision()
+ if not revision_id:
+ raise errors.BzrCommandError(
+ "Tags can not be placed on an empty branch, "
+ "try making a commit first")
                 if (not force) and branch.tags.has_tag(tag_name):
                     raise errors.TagAlreadyExists(tag_name)
                 branch.tags.set_tag(tag_name, revision_id)

Revision history for this message
Martin Pool (mbp) wrote : Re: [Bug 93853] Re: Tag command breaks badly with empty repository

That looks like a reasonable placeholder.

--
Martin

Revision history for this message
Martin Pool (mbp) wrote :

Has now been fixed; a tag pointing to the empty revision is created.

Changed in bzr:
status: Confirmed → Fix Released
Revision history for this message
Martin Pool (mbp) wrote :

However, I still have a patch around originally from Tim Hatch that seems to fix this in a different way, by declining to tag the origin. That may be a better ui.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.