pygit2
pygit2 copied to clipboard
Submodule head_id is broken for non-committed submodules
submodule.head_id returns garbage results when the submodule is not yet committed:
> git init
> git submodule add https://github.com/pytest-dev/pytest
> git -C pytest checkout 34a285986e456406b22b62aa563a64331f640e7f
> python script.py # see below
Submodule head id: 801cb63aa57f0000602d0c3da57f000006000000
Submodule head id: e400000000000000000000000000000077726974
Note that the result of head_id is not even stable.
script.py is
from pygit2 import Repository
repo = Repository('.')
sub_module = repo.lookup_submodule('pytest')
print("Submodule head id:", sub_module.head_id)
print("Submodule head id:", sub_module.head_id)
Python version: 3.8.10 Pygit2 version: 1.9.2