Skip to content

Parse tag fail for some tag info. #503

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
hwchiu opened this issue Aug 26, 2016 · 2 comments
Closed

Parse tag fail for some tag info. #503

hwchiu opened this issue Aug 26, 2016 · 2 comments
Assignees

Comments

@hwchiu
Copy link

hwchiu commented Aug 26, 2016

Environment

  • Git: 2.9.1
  • GitPython: master branch (2016-08-26)
  • Target project:

Status

  • Use the GitPython to parse the tag info of openvpn.
  • The tag v2.2-beta1 will cause the wrong data structure
    • The repo.tags[xx] should return the TagReference object.
    • The repo.tags[xx].commit should return the Commit object.
    • when the tag v2.2-beta1 be loaded
      • The repo.tags[xx].commit still be the TagObject object rather than Commit object.
  • Result of the 'git show v2.2-beta1'
  • Reason
    • Maybe there are two "tag v2.2-beta1" in the show info will cause the parse error ?

My Code

import git

repo = git.Repo.clone_from('....' , '...')
test = sorted(repo.tags, key=lambda t: t.commit.committed_date)


Error:
  File "/usr/local/lib/python2.7/dist-packages/gitdb/util.py", line 239, in __getattr__
    return object.__getattribute__(self, attr)
AttributeError: 'TagObject' object has no attribute 'committed_date'

Is it a bug ? or Do you have any suggestion I can do in my application to get all tag by date?

Thanks.

@Byron
Copy link
Member

Byron commented Sep 11, 2016

@hwchiu Thanks for this great example of an issue - I could easily reproduce it. Digging into the code I found this line, which states:

        elif obj.type == "tag":
            # it is a tag object which carries the commit as an object - we can point to anything
            return obj.object

However, in any case, the API is not delivering on its promise of only returning commit objects, which should be fixed in some way.
We could throw an exception, similar to what already happens in the tree or blob case.
Thus it seems it is up to the caller to determine what kind of object that commit actually is, and the example code would then probably look more like this:

sorted(repo.tags, key=lambda t: safe_commtted_date_of(t.object))

@Byron Byron self-assigned this Sep 11, 2016
@Byron
Copy link
Member

Byron commented Sep 11, 2016

Alternatively, it could recursively resolve the commit, assuming that eventually it will find one. This is certainly the better fix, which I am going for.

@Byron Byron added this to the v2.0.9 - Bugfixes milestone Sep 11, 2016
@Byron Byron closed this as completed in ae6e26e Sep 11, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants