-
-
Notifications
You must be signed in to change notification settings - Fork 954
GitPython does not contain a 'is_valid_hash' method. #1266
-
Am I missing something or is that currently missing?
The git command would be git cat-file commit {git_hash}
.
I used the following before using GitPython:
def git_hash_is_valid(git_hash):
return subprocess_return_call(f"git cat-file commit {git_hash}") == 0
def subprocess_return_call(call_string):
call_parameters = call_string.split(" ")
return subprocess.call(
call_parameters,
stderr=subprocess.STDOUT,
stdout=open(os.devnull, 'w')
)
Would a method like that fit into repo directly like repo.is_ancestor()
?
I know self.repo.commit(
works, but that does not differentiate between refs and commit hashes.
Beta Was this translation helpful? Give feedback.
All reactions
The fastest way to do this is this one:
Line 65 in 6752fad
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
-
PS: If this is something that would be ok to include, I'd create the PR, I'm currently doing it with this:
def hash_is_valid(self, git_hash):
try:
self.repo.commit(git_hash)
except ValueError:
return False
return True
Beta Was this translation helpful? Give feedback.
All reactions
-
PPS: We could also add default values to the repo.commit(
method, to add
SymbolicReferences=True, Commit=True, TagObject=True, Blob=True, Tree=True
Beta Was this translation helpful? Give feedback.
All reactions
-
The fastest way to do this is this one:
Line 65 in 6752fad
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
.
Beta Was this translation helpful? Give feedback.