Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 foocd fooecho foo> bar.txtgit add bar.txtgit commit -m bazgit tag quux`git hash-object bar.txt`PAGER=cat git show quuxcd ..

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

# pip install gitpython==2.1.0importgittag_name="quux"repo_name="foo"repo_obj=git.Repo(repo_name)tag_obj=repo_obj.tags[0]assertstr(tag_obj)==tag_nameiftag_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/kernel/git/stable/linux-stable.git linux-stablecd linux-stablegit show v2.6.11

Produces this output:

tag v2.6.11-treeThis 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 treeobject up to a real commit. In the meantime, this acts as an anchor point fordoing diffs etc under git.-----BEGIN PGP SIGNATURE-----Version: GnuPG v1.2.4 (GNU/Linux)iD8DBQBCeV/eF3YsRnbiHLsRAl+SAKCVp8lVXwpUhMEvy8N5jVBd16UCmACeOtP6KLMHist5yj0sw1E4hDTyQa0==/bIK-----END PGP SIGNATURE-----tree v2.6.11COPYINGCREDITSDocumentation/MAINTAINERSMakefileREADMEREPORTING-BUGSarch/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


      [8]ページ先頭

      ©2009-2025 Movatter.jp