Skip to content

Needs better error message when repository is rejected by git (related to safe.directory) #1616

@marioaag

Description

@marioaag

Initial state:
Executions using the latest version of Git (version 2.39.3), in a repository owned by other user.

Current behavior:
Executing:

repo = git.Repo(dir_path)
last_commit = repo.head.commit

Ambiguos error is reported:

  File "/usr/local/lib/python3.9/site-packages/git/refs/symbolic.py", line 226, in _get_commit
    obj = self._get_object()
  File "/usr/local/lib/python3.9/site-packages/git/refs/symbolic.py", line 219, 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.9/site-packages/git/objects/base.py", line 94, in new_from_sha
    oinfo = repo.odb.info(sha1)
  File "/usr/local/lib/python3.9/site-packages/git/db.py", line 40, in info
    hexsha, typename, size = self._git.get_object_header(bin_to_hex(binsha))
  File "/usr/local/lib/python3.9/site-packages/git/cmd.py", line 1383, in get_object_header
    return self.__get_object_header(cmd, ref)
  File "/usr/local/lib/python3.9/site-packages/git/cmd.py", line 1370, in __get_object_header
    return self._parse_object_header(cmd.stdout.readline())
  File "/usr/local/lib/python3.9/site-packages/git/cmd.py", line 1329, 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''

Expected behavior:
More clear an specific error message or even better a parameter in git.repo() to handle the dubious ownership

Notes:
Doing some debug found that the new version of Git has enable by default a check for dubious ownership that is not handle gracefully by GitPython.

A work around for this is add an exception in Git to consider the file safe git config --global --add safe.directory <dir path>

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    pFad - Phonifier reborn

    Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

    Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


    Alternative Proxies:

    Alternative Proxy

    pFad Proxy

    pFad v3 Proxy

    pFad v4 Proxy