From c5cc46acbb3bcccff7774c6dc965dd85df071c0e Mon Sep 17 00:00:00 2001
From: Remi Cresson <remi.cresson@irstea.fr>
Date: Wed, 1 Jun 2022 21:16:56 +0200
Subject: [PATCH] FIX: get hash

---
 decloud/core/system.py | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/decloud/core/system.py b/decloud/core/system.py
index 17da552..8114052 100644
--- a/decloud/core/system.py
+++ b/decloud/core/system.py
@@ -41,13 +41,16 @@ def get_commit_hash():
     """ Return the git hash of the repository """
     repo = git.Repo(os.path.dirname(os.path.realpath(__file__)), search_parent_directories=True)
 
+    commit_hash = "nohash"
     try:
-        commit_hash = repo.active_branch.name + "_" + repo.head.object.hexsha[0:5]
-    except TypeError:
-        try:
-            commit_hash = 'DETACHED_' + repo.head.object.hexsha[0:5]
-        except ValueError:
-            commit_hash = 'NoHash'
+        commit_hash = repo.head.object.hexsha[0:5]
+    except (ValueError, TypeError) as e:
+        print(f"Unable to get commit hash! {e}")
+
+    try:
+        commit_hash = repo.active_branch.name + "_" + commit_hash
+    except (ValueError, TypeError) as e:
+        print(f"Unable to get branch name! {e}")
 
     return commit_hash
 
-- 
GitLab