From 6f6eb1e93cc87b03d82d6a49d894e3e6e05b7ede Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20A=20Le=C3=B3n=20Baldelli?= Date: Tue, 26 Mar 2024 11:33:37 +0100 Subject: [PATCH] q&d fix for graceful failure --- src/irrevolutions/utils/__init__.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/irrevolutions/utils/__init__.py b/src/irrevolutions/utils/__init__.py index 11dc15cb..c1fa9e1b 100644 --- a/src/irrevolutions/utils/__init__.py +++ b/src/irrevolutions/utils/__init__.py @@ -123,10 +123,22 @@ def format(self, record): import subprocess # Get the current Git branch -branch = subprocess.check_output(["git", "rev-parse", "--abbrev-ref", "HEAD"]).strip().decode("utf-8") +def get_current_branch(): + try: + # Get the current Git branch + branch = subprocess.check_output(["git", "rev-parse", "--abbrev-ref", "HEAD"], stderr=subprocess.PIPE).strip().decode("utf-8") + commit_hash = subprocess.check_output(["git", "rev-parse", "HEAD"]).strip().decode("utf-8") + return branch, commit_hash + except subprocess.CalledProcessError as e: + # Handle the error + error_message = e.stderr.decode("utf-8").strip() + print(f"Error occurred while getting the current branch: {error_message}") + return 'unknown', 'unknown' + +# Get the current branch +branch, commit_hash = get_current_branch() # Get the current Git commit hash -commit_hash = subprocess.check_output(["git", "rev-parse", "HEAD"]).strip().decode("utf-8") code_info = { "branch": branch,