Check for git repository before git commands (#5403)

When we are attempting to fetch the version info from the git
repository, first check if we're actually in one, otherwise
spurious errors messages get printed.
This commit is contained in:
André Cruz 2023-09-11 21:52:31 +01:00 committed by GitHub
parent 361638cfd0
commit 2d6996f731
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -111,9 +111,11 @@ def describe(repo_path):
Runs 'git describe', or alternately 'git rev-parse HEAD', in directory. If
successful, returns the output; otherwise returns 'unknown hash, <date>'."""
success, output = command_output(['git', 'describe'], repo_path)
# if we're in a git repository, attempt to extract version info
if os.path.exists(".git"):
success, output = command_output(["git", "describe"], repo_path)
if not success:
output = command_output(['git', 'rev-parse', 'HEAD'], repo_path)
output = command_output(["git", "rev-parse", "HEAD"], repo_path)
if success:
# decode() is needed here for Python3 compatibility. In Python2,