Closed
Description
The blobs returned by diff are somehow different that the blobs returned by commit.tree/path
for submodule blobs. E.g. if I try to create a IndexEntry from a blob it fails with a ValueError, when using the blob from diff. As you see I added an assert (line 28) to make sure, that I really access the same blob!
I can run successfully:
sub_blob = r.head.commit.tree/"sub"
git.IndexEntry.from_blob(sub_blob)
but fails for:
d = r.commit('1').diff(r.commit('2'))[0]
git.IndexEntry.from_blob(d.b_blob)
$ rm -rf /tmp/sub /tmp/foo && python3 /tmp/test.py
Traceback (most recent call last):
File "/tmp/test.py", line 29, in <module>
git.IndexEntry.from_blob(d.b_blob)
File "/usr/lib/python3/dist-packages/git/index/typ.py", line 176, in from_blob
time, time, 0, 0, 0, 0, blob.size))
File "/usr/lib/python3/dist-packages/gitdb/util.py", line 253, in __getattr__
self._set_cache_(attr)
File "/usr/lib/python3/dist-packages/git/objects/base.py", line 166, in _set_cache_
super(IndexObject, self)._set_cache_(attr)
File "/usr/lib/python3/dist-packages/git/objects/base.py", line 72, in _set_cache_
oinfo = self.repo.odb.info(self.binsha)
File "/usr/lib/python3/dist-packages/git/db.py", line 37, in info
hexsha, typename, size = self._git.get_object_header(bin_to_hex(sha))
File "/usr/lib/python3/dist-packages/git/cmd.py", line 1077, in get_object_header
return self.__get_object_header(cmd, ref)
File "/usr/lib/python3/dist-packages/git/cmd.py", line 1066, in __get_object_header
return self._parse_object_header(cmd.stdout.readline())
File "/usr/lib/python3/dist-packages/git/cmd.py", line 1030, in _parse_object_header
raise ValueError("SHA %s could not be resolved, git returned: %r" % (tokens[0], header_line.strip()))
ValueError: SHA b'e03cac5f0551bfd7cc9030a7bf862aee43937ae0' could not be resolved, git returned: b'e03cac5f0551bfd7cc9030a7bf862aee43937ae0 missing'
Here is my test script (/tmp/test.py)
import git
sub = git.Repo.init("/tmp/sub")
open("/tmp/sub/subfile", "w").write("")
sub.index.add(["subfile"])
sub.index.commit("first commit")
r = git.Repo.init("/tmp/foo")
open("/tmp/foo/test", "w").write("")
r.index.add(['test'])
git.Submodule.add(r, "subtest", "sub", url="file:///tmp/sub")
r.index.commit("first commit")
r.create_tag('1')
submodule = r.submodule('subtest')
open("/tmp/foo/sub/subfile", "w").write("blub")
submodule.module().index.add(["subfile"])
submodule.module().index.commit("changed subfile")
submodule.binsha = submodule.module().head.commit.binsha
r.index.add([submodule])
r.index.commit("submodule changed")
r.create_tag('2')
sub_blob = r.head.commit.tree/"sub"
git.IndexEntry.from_blob(sub_blob)
d = r.commit('1').diff(r.commit('2'))[0]
assert(sub_blob.hexsha == d.b_blob.hexsha)
git.IndexEntry.from_blob(d.b_blob)