Skip to content

Commit

Permalink
fix(Sentry): handle cases where Git is available but we're not in a r…
Browse files Browse the repository at this point in the history
…epository (#1275)
  • Loading branch information
afeld authored Feb 15, 2023
2 parents e11c2ff + 39f8841 commit f2503e5
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion benefits/sentry.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ def git_available():
return bool(shutil.which("git"))


# https://stackoverflow.com/a/24584384/358804
def is_git_directory(path="."):
dev_null = open(os.devnull, "w")
return subprocess.call(["git", "-C", path, "status"], stderr=dev_null, stdout=dev_null) == 0


# https://stackoverflow.com/a/21901260/358804
def get_git_revision_hash():
return subprocess.check_output(["git", "rev-parse", "HEAD"]).decode("ascii").strip()
Expand All @@ -26,7 +32,7 @@ def get_sha_path():
def get_release() -> str:
"""Returns the first available: the SHA from Git, the value from sha.txt, or the VERSION."""

if git_available():
if git_available() and is_git_directory():
return get_git_revision_hash()
else:
sha_path = get_sha_path()
Expand Down

0 comments on commit f2503e5

Please sign in to comment.