8000 Exception triggered when lightweight tag points to blob/tree · Issue #561 · gitpython-developers/GitPython · GitHub
[go: up one dir, main page]

Skip to content
Exception triggered when lightweight tag points to blob/tree #561
Closed
@edrawd

Description

@edrawd

Bug summary

The Reference.TagReference.tag() function in the module git/refs/tag.py in Gitpython 2.1.0 (and potentially other versions after 2.0.8) does not properly handle lightweight tags that point to blobs or trees.

Below I will demonstrate how to create a tag pointing to a blob or tree. Next I will demonstrate how to trigger the bug in gitpython. Finally, I will show an example popular git repo that contains a tag pointing to a tree.

I do not have a suggestion for what the correct behavior of Reference.TagReference.tag() should be, but I do not think that it should trigger an exception when the tag points to a blob or tree.

Sample script to create a repo with a tag pointing to a blob

git init foo
cd foo
echo foo > bar.txt
git add bar.txt
git commit -m baz
git tag quux `git hash-object bar.txt`
PAGER=cat git show quux
cd ..

Python script to trigger the bug (using the above repo)

# pip install gitpython==2.1.0

import git

tag_name = "quux"
repo_name = "foo"
repo_obj = git.Repo(repo_name)

tag_obj = repo_obj.tags[0]
assert str(tag_obj) == tag_name

if tag_obj.commit.type == 'commit':
    print("Is a commit")
else:
    print("Not a commit")

Traceback from test script

Traceback (most recent call last):
  File "delme.py", line 10, in <module>
    if tag_obj.commit.type == 'commit':
  File "/usr/lib/python2.7/site-packages/git/refs/tag.py", line 33, in commit
    raise ValueError("Tag %s points to a Blob or Tree - have never seen that before" % self)
ValueError: Tag quux points to a Blob or Tree - have never seen that before

Example from the wild: linux

Here I will show an example of a popular git repo that includes a tag (v2.6.11) pointing to a blob or tree. Note that Linus Torvalds, the original author of git, probably created this tag, based on the fact that he authored the successively-named tag (v2.6.12-rc2). v2.6.11 does not contain metadata.

Running these commands:

git clone git://git.kernel.org/pub/scm/linux/kerne
5D86
l/git/stable/linux-stable.git linux-stable
cd linux-stable
git show v2.6.11

Produces this output:

tag v2.6.11-tree

This is the 2.6.11 tree object.

NOTE! There's no commit for this, since it happened before I started with git.
Eventually we'll import some sort of history, and that should tie this tree
object up to a real commit. In the meantime, this acts as an anchor point for
doing diffs etc under git.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQBCeV/eF3YsRnbiHLsRAl+SAKCVp8lVXwpUhMEvy8N5jVBd16UCmACeOtP6
KLMHist5yj0sw1E4hDTyQa0=
=/bIK
-----END PGP SIGNATURE-----

tree v2.6.11

COPYING
CREDITS
Documentation/
MAINTAINERS
Makefile
README
REPORTING-BUGS
arch/
crypto/
drivers/
fs/
include/
init/
ipc/
kernel/
lib/
mm/
net/
scripts/
security/
sound/
usr/

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0