Skip to content

Is gitdb an implementation detail? #933

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
tucked opened this issue Oct 10, 2019 · 5 comments
Open

Is gitdb an implementation detail? #933

tucked opened this issue Oct 10, 2019 · 5 comments

Comments

@tucked
Copy link

tucked commented Oct 10, 2019

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.

@stsewd
Copy link
Contributor

stsewd commented Oct 10, 2019

Yes, gitdb is part of the requirements https://gitpython.readthedocs.io/en/stable/intro.html#requirements

@tucked
Copy link
Author

tucked commented Oct 10, 2019

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.

@Byron
Copy link
Member

Byron commented Oct 10, 2019

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.

@tucked
Copy link
Author

tucked commented Oct 11, 2019

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:

raise BadName(name)

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:

from gitdb.exc import * # NOQA @UnusedWildImport

@Byron
Copy link
Member

Byron commented Oct 15, 2019

@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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants