Skip to content

How to check if a commit exists? #721

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
strokirk opened this issue Feb 2, 2018 · 3 comments
Closed

How to check if a commit exists? #721

strokirk opened this issue Feb 2, 2018 · 3 comments
Labels

Comments

@strokirk
Copy link

strokirk commented Feb 2, 2018

Like the title says. I'd like to check if a specific commit exists.
Trying to run iter_commits over a rev that doesn't exists throws an exception, and I'd like to avoid that in order to provide nicer user output for my script.

Pseudocode:

if repo.exists(source):
    return list(repo.iter_commits("%s...%s" % (source, target)))
else:
    print("Couldn't find %s, you need to run git fetch")
@Byron Byron added the Q&A label Feb 24, 2018
@Byron
Copy link
Member

Byron commented Feb 24, 2018

I think the way to go is to catch the exception.
Exceptions are the way GitPython communicates errors in most (if not all) cases, and I believe there is no way around it.
As I hope this answered your question, I am closing the issue. Please feel free to keep posting here if you need clarification.

@Byron Byron closed this as completed Feb 24, 2018
@leos313
Copy link

leos313 commented Feb 27, 2020

Hi Byron, your answer is clear, thank you. However, I think it is possible to keep the issue open for future improvement: it can be a feature that other people think is worth to have.
The improvement can solve problems that generate this kind of errors:

GitCommandError: Cmd('git') failed due to: exit code(128)
  cmdline: git diff HEAD~1
  stderr: 'fatal: ambiguous argument 'HEAD~1': unknown revision or path not in the working tree.

Thank you, Byron

@Byron
Copy link
Member

Byron commented Feb 27, 2020

If it should be a feature or change in behavior, please submit a new issue which presents the desired capabilities in a way that would allow discussion and/or contributions. Thank you

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

No branches or pull requests

3 participants