Repository navigation
Closed as not planned
Labels
Description
GitPython is failing to retrieve commits from a specific repository I am currently analyzing: https://github.com/jbrowncfa/Cryptobomb.
Exception's stack trace:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.6/site-packages/git/repo/base.py", line 524, in iter_commits
rev = self.head.commit
File "/usr/local/lib/python3.6/site-packages/git/refs/symbolic.py", line 197, in _get_commit
obj = self._get_object()
File "/usr/local/lib/python3.6/site-packages/git/refs/symbolic.py", line 190, in _get_object
return Object.new_from_sha(self.repo, hex_to_bin(self.dereference_recursive(self.repo, self.path)))
File "/usr/local/lib/python3.6/site-packages/git/objects/base.py", line 64, in new_from_sha
oinfo = repo.odb.info(sha1)
File "/usr/local/lib/python3.6/site-packages/git/db.py", line 37, in info
hexsha, typename, size = self._git.get_object_header(bin_to_hex(sha))
File "/usr/local/lib/python3.6/site-packages/git/cmd.py", line 1068, in get_object_header
return self.__get_object_header(cmd, ref)
File "/usr/local/lib/python3.6/site-packages/git/cmd.py", line 1057, in __get_object_header
return self._parse_object_header(cmd.stdout.readline())
File "/usr/local/lib/python3.6/site-packages/git/cmd.py", line 1019, in _parse_object_header
raise ValueError("SHA could not be resolved, git returned: %r" % (header_line.strip()))
ValueError: SHA could not be resolved, git returned: b''
Reproducible example:
$ git clone https://github.com/jbrowncfa/Cryptobomb
from git import Repo
repo = Repo("./Cryptobomb")
for commit in repo.iter_commits():
print(commit.hexsha) # error
Here is the Dockerfile I'm using:
FROM python:3.6
ENV GIT_DISCOVERY_ACROSS_FILESYSTEM=1
RUN apt-get update
RUN apt-get install -y git
Please let me know if you guys need any more info.
Reacted by Sebastian Thiel, Fabian Keller, Carlos Juan Gómez Peñalver and lingxiaotang
Reacted by Bogdan Pradatu and Jack
Activity
Byron commentedon Jun 5, 2020
Thanks a lot, I was able to reproduce the issue, and here is how it looks for me:
simisimon commentedon Nov 6, 2020
We face the same problem when we analyze repositories. Do you have any updates on this issue?
andbue commentedon Jan 5, 2021
Had the same problem, updating git to git-2.30.0-1 solved it for me.
Yook74 commentedon Apr 18, 2022
I was getting this error message when I was trying to get info about a repository which I was not the owner of (even though I was root). I tried doing it manually with
git rev-parse HEADand gotfatal: unsafe repository ('[my repo]' is owned by someone else)If you're having this problem, see if
git rev-parse HEADworks.I would like to see some better error handling if possible. It seems clear to me that an error was not properly being raised somewhere and a function was silently returning an empty binary string.
Byron commentedon Apr 18, 2022
This is a known issue as some commands are configured to stream data and only look at stdout. That said, git appears to exit with code 129 making it possible to provide a better error message. We could use an issue to keep track of this or a PR to fix it. Here is a related conversation.
ramonlins commentedon Apr 20, 2022
Maybe git is running into a different owner than the repository.
Inside repo, you can try this command:
git config --global -add safe.directory <repo_path>Yook74 commentedon Apr 20, 2022
@ramonlins yes that was the fix for my particular problem
kapsner commentedon May 4, 2022
thanks @ramonlins , that works for me as well.
However, I do not understand what caused this error message to suddenly appear, while it was working before for a long time without any significant changes in the setup lately...
Yook74 commentedon May 4, 2022
@kapsner a recent update to Git on the apt repositories added a feature which is causing this problem.
frozenpandaman commentedon Oct 30, 2022
For more reading: https://stackoverflow.com/a/71904131/3580553
mamiksik commentedon Jan 19, 2023
I am getting this error for https://github.com/nodejs/node.
git config --global --add safe.directory '*'did not solve the issue.