GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Needs better error message when repository is rejected by `git` (related to `safe.directory`) · Issue #1616 · gitpython-developers/GitPython

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

New issue
Copy link
New issue
Copy link
Closed
Closed
Needs better error message when repository is rejected by git (related to safe.directory)#1616
Copy link
Assignees
marioaag
Labels
acknowledgedhelp wanted

Description

@marioaag
marioaag
opened on Jul 17, 2023
Issue body actions

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>

Activity

  1. Byron commented on Jul 17, 2023

    @Byron
    Byron
    on Jul 17, 2023
    Member
    More actions

    Do I understand correctly that the repository isn't trusted by git and GitPython fails with a dubious, seemingly unrelated error?

    Reacted by Mario Alvarado
  2. Byron
    added
    waiting for feedback
    on Jul 17, 2023
  3. marioaag commented on Jul 17, 2023

    @marioaag
    marioaag
    on Jul 17, 2023
    Author
    More actions

    Correct!

  4. Byron
    added
    acknowledged
    and removed
    waiting for feedback
    on Jul 18, 2023
  5. Byron
    changed the title [-]ValueError: SHA could not be resolved, git returned: b''[/-] [+]Needs better error message when repository is rejected by `git` (related to `safe.directory`)[/+] on Jul 18, 2023
  6. Byron commented on Jul 18, 2023

    @Byron
    Byron
    on Jul 18, 2023
    Member
    More actions

    Perfect! If you don't mind, could you look at my title and formulate the issue so that it matches the title more? It could be in the form of initial state (a repository owned by someone else), current behaviour, expected behaviour. With that, maybe the issue has a chance to be picked up by someone.

    Reacted by Mario Alvarado
  7. Byron
    added
    help wanted
    on Jul 18, 2023
  8. marioaag commented on Jul 19, 2023

    @marioaag
    marioaag
    on Jul 19, 2023
    Author
    More actions

    Ready! Thanks for the help!

    Reacted by Sebastian Thiel
  9. marioaag commented on Nov 22, 2023

    @marioaag
    marioaag
    on Nov 22, 2023
    Author
    More actions

    Hi @Byron, could you help me to assign the ticket, I will work on it

  10. Byron
    assigned
    marioaag
    on Nov 23, 2023
  11. Byron commented on Nov 23, 2023

    @Byron
    Byron
    on Nov 23, 2023
    Member
    More actions

    Thanks a lot! It’s assigned.

  12. marioaag commented on Nov 28, 2023

    @marioaag
    marioaag
    on Nov 28, 2023
    Author
    More actions

    Hi @Byron, pull request generated! #1746

  13. EliahKagan commented on Dec 23, 2023

    @EliahKagan
    EliahKagan
    on Dec 23, 2023
    Member
    More actions

    Should this issue be closed as completed (in #1746)?

  14. Byron commented on Dec 23, 2023

    @Byron
    Byron
    on Dec 23, 2023
    Member
    More actions

    Thanks for the reminder!

  15. Byron
    closed this as completedon Dec 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @marioaag
    marioaag

Labels

acknowledgedhelp wanted

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402503 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.