Comment 3 for bug 1115283

Revision history for this message
Jelmer Vernooij (jelmer) wrote : Re: [Bug 1115283] Re: Can't create tags in git repo via dulwich.

On Wed, 2013-02-06 at 11:40 +0000, Ryan Faulkner wrote:
> Ah I see. You're correct in assuming that I'm looking to create a tag.
> However, the above steps seem to be omitting some calls to actually
> create the tag in .git/refs/tags or .git/packed-refs nor is it visible
> when I run 'git tag'. (http://git-scm.com/book/en/Git-Basics-Tagging)
These steps create an annotated 'tag' object. To create a tag, add the
relevant ref to your git repository. E.g.

r['refs/tags/foo'] = o.id

where o is either an annotated tag object or another object the tag
refers to.

> If I try to to add the object to a repo object store I see the
> following:
>
> >>> from dulwich.repo import Repo
> >>> from dulwich.objects import Tag
> >>> r = Repo(".")
> >>> object_store = r.object_store
> >>> tag = Tag()
> >>> tag.tagger = 'rfaulk'
> >>> tag.message = 'test tag 1,2.'
> >>> tag.name = 'test-tag'
> >>> object_store.add_object(tag)
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> File "/Library/Python/2.7/site-packages/dulwich/object_store.py", line 610, in add_object
> dir = os.path.join(self.path, obj.id[:2])
> File "/Library/Python/2.7/site-packages/dulwich/objects.py", line 492, in id
> return self.sha().hexdigest()
> File "/Library/Python/2.7/site-packages/dulwich/objects.py", line 483, in sha
> new_sha.update(self._header())
> File "/Library/Python/2.7/site-packages/dulwich/objects.py", line 462, in _header
> return object_header(self.type, self.raw_length())
> File "/Library/Python/2.7/site-packages/dulwich/objects.py", line 467, in raw_length
> for chunk in self.as_raw_chunks():
> File "/Library/Python/2.7/site-packages/dulwich/objects.py", line 253, in as_raw_chunks
> self._chunked_text = self._serialize()
> File "/Library/Python/2.7/site-packages/dulwich/objects.py", line 654, in _serialize
> chunks.append("%s %s\n" % (_OBJECT_HEADER, self._object_sha))
> AttributeError: _object_sha
>
> Am I missing something here?
You need to set an object in the tag as well.

tag.object = (type, somesha)

Cheers,

Jelmer