Gitpython: Is gitdb an implementation detail?

Created on 10 Oct 2019  路  5Comments  路  Source: gitpython-developers/GitPython

git.Repo(path).commit(bad_hash)

This raises gitdb.exc.BadName (which is not catchable with git.exc.GitError "Base class for all package exceptions").

Do I need to catch gitdb exceptions too? I don't have a dep on gitdb otherwise.

acknowledged help wanted

Most helpful comment

Thanks for posting! I believe this is indeed an issue, and it's worth fixing for better usability and less surprises.
Historically, GitDB was meant as standalone low-level library anyone could use, but practically it's only used by GitPython. And if memory serves, at some point I did my best to reduce the dependency by using the git <command> backend instead. However, depending on the method, GitDB is still used as indicated here.

I believe everyone would benefit by removing or merging GitDB into GitPython for good, and PRs are very welcome.

All 5 comments

Those are _GitPython's_ requirements, though, not _my_ requirements...
For example, gitdb2 depends on smmap, but GitPython doesn't have that in its requirements.txt.

Thanks for posting! I believe this is indeed an issue, and it's worth fixing for better usability and less surprises.
Historically, GitDB was meant as standalone low-level library anyone could use, but practically it's only used by GitPython. And if memory serves, at some point I did my best to reduce the dependency by using the git <command> backend instead. However, depending on the method, GitDB is still used as indicated here.

I believe everyone would benefit by removing or merging GitDB into GitPython for good, and PRs are very welcome.

That sounds like a big task... In the meantime, maybe something like this could suffice:

try:
    gitdb.op()
except gitdb.exc.ODBError as exc:
    raise git.exc.GitDBError from exc

Actually though, I just realized that GitPython (not GitDB) is raising gitdb.exc.BadName:
https://github.com/gitpython-developers/GitPython/blob/23b83cd6a10403b5fe478932980bdd656280844d/git/repo/fun.py#L147

So, maybe more like:

class BadName(git.exc.GitError, gitdb.exc.BadName):
    pass

raise BadName(name)

edit: FWIW, my workaround is to catch git.exc.BadName directly which works because GitPython imports gitdb exceptions:
https://github.com/gitpython-developers/GitPython/blob/23b83cd6a10403b5fe478932980bdd656280844d/git/exc.py#L8

@tucked Wow, fantastic write up! I would be so happy if this could be fixed for everyone with what seems like a small PR. _(Still catching up on emails, maybe the PR is already there)_

Was this page helpful?
0 / 5 - 0 ratings