← Winnitude! Search  ·  Reader Mode (1739 ms)
Links: Stay in Reader Retro Site Converter Retro Mode: OFF Original Page ↗
GITHUB · 8 LINKS

Exception suggestion: raise when making a Commit with non-commit binsha · Issue #2254 · gitpython-developers/GitPython

Repository navigation

Exception suggestion: raise when making a Commit with non-commit binsha  #2254


New issue

New issue

Closed
#2256
Closed
Exception suggestion: raise when making a Commit with non-commit binsha #2254 #2256

Description

@jeffro256's profile jeffro256 opened on Sep 28, 2026

Consider the following code snippet:

import git
repo = git.Repo('GitPython')
tag = repo.rev_parse('3.1.62')
commit = git.Commit(repo, tag.binsha)
index_file = git.IndexFile.new(repo, commit.tree)

If GitPython is a repo in the CWD, then upon running the above code, you will see a traceback like so:

Traceback (most recent call last):
  File "my_python_file.py", line 5, in <module>
    index_file = git.IndexFile.new(repo, commit.tree)
  File "/usr/lib/python3.14/site-packages/git/index/base.py", line 330, in new
    base_entries = aggressive_tree_merge(repo.odb, tree_sha_bytes)
  File "/usr/lib/python3.14/site-packages/git/index/fun.py", line 505, in aggressive_tree_merge
    for entry in traverse_tree_recursive(odb, tree_shas[-1], ""):
                 ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.14/site-packages/git/objects/fun.py", line 271, in traverse_tree_recursive
    data = tree_entries_from_data(odb.stream(tree_sha).read())
  File "/usr/lib/python3.14/site-packages/git/objects/fun.py", line 111, in tree_entries_from_data
    while data[i] != 0:
          ~~~~^^^
IndexError: index out of range

This throws an out-of-bounds array index exception when trying to parse the tag's database stream as a tree, which should fail. However, the real user error occurred when trying to make a Commit object from a tag object's binsha: commit = git.Commit(repo, tag.binsha). The Commit constructor should raise an Exception with a message to this effect. For example, "Given sha value does not refer to a commit`.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions