镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

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

Description

@bytefluxio

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.

Activity

  1. bytefluxio commented on Jun 4, 2021

    @bytefluxio
    ContributorAuthor

    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
    
  2. bytefluxio commented on Jun 4, 2021

    @bytefluxio
    ContributorAuthor

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

  3. locked and limited conversation to collaborators on Jun 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions