Skip to content
\n

Would a method like that fit into repo directly like repo.is_ancestor()?

\n

I know self.repo.commit( works, but that does not differentiate between refs and commit hashes.

","upvoteCount":1,"answerCount":3,"acceptedAnswer":{"@type":"Answer","text":"

The fastest way to do this is this one:

\n

\n
\n

\n GitPython/git/objects/base.py\n

\n

\n Line 65\n in\n 6752fad\n

\n
\n
\n \n\n \n \n \n \n
oinfo = repo.odb.info(sha1)
\n
\n
\n

\n

As it will call git cat-file under the hood it might be that other forms of rev names are also supported, like branch names and the likes. It's certainly something to test out if that's a problem in this case.

\n

A PR is welcome in case you would like to add a method to test for an objects existence on a Repo.

","upvoteCount":1,"url":"https://github.com/gitpython-developers/GitPython/discussions/1266#discussioncomment-828047"}}}

GitPython does not contain a 'is_valid_hash' method. #1266

Answered by Byron
bytefluxio asked this question in Q&A
Discussion options

You must be logged in to vote

The fastest way to do this is this one:

oinfo = repo.odb.info(sha1)

As it will call git cat-file under the hood it might be that other forms of rev names are also supported, like branch names and the likes. It's certainly something to test out if that's a problem in this case.

A PR is welcome in case you would like to add a method to test for an objects existence on a Repo.

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by Byron
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #1265 on June 05, 2021 02:15.