Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

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

Closed
bytefluxio opened this issue Jun 4, 2021 · 2 comments
Closed

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

bytefluxio opened this issue Jun 4, 2021 · 2 comments

Comments

@bytefluxio
Copy link
Contributor

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.

@bytefluxio
Copy link
Contributor Author

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

@bytefluxio
Copy link
Contributor Author

PPS: We could also add default values to the repo.commit( method, to add
SymbolicReferences=True, Commit=True, TagObject=True, Blob=True, Tree=True

@Byron Byron closed this as completed Jun 5, 2021
@gitpython-developers gitpython-developers locked and limited conversation to collaborators Jun 5, 2021

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Development

No branches or pull requests

2 participants