From 6e3756103b7740236e9d1ac7c6682ccefc8b9413 Mon Sep 17 00:00:00 2001
From: Tobias Pfandzelter <pfandzelter@campus.tu-berlin.de>
Date: Thu, 23 Jul 2020 14:57:24 +0200
Subject: [PATCH 1/2] add return code check to precommit

---
 ci/tools/pre-commit | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/ci/tools/pre-commit b/ci/tools/pre-commit
index 6ff4bd0..4186fd7 100644
--- a/ci/tools/pre-commit
+++ b/ci/tools/pre-commit
@@ -63,20 +63,23 @@ echo "${GREEN}No AWS access keys found!${NC}"
 
 # -------------------------------------- PREVENT PUSH TO MASTER ----------------------------------------------------
 
-echo "${YELLOW}Checking if you're trying to push to master...${NC}"
+echo "${YELLOW}Checking if you're trying to commit to master...${NC}"
 
 if [ "$branch" = "master" ]; then
   echo "You can't commit directly to '"${branch}"' branch" # webstorm or intellij will show this as popup
   exit 1 # if you remove this line then it won't block commit but send message to group and on command line
 fi
 
-echo "${GREEN}You're not trying to push to master!${NC}"
+echo "${GREEN}You're not trying to commit to master!${NC}"
 
 # ------------------------------------------- GO LINT --------------------------------------------------------------
 
 echo "${YELLOW}Linting your code...${NC}"
 
-make lint
+if ! make lint; then
+  echo "${RED}Linter found mistakes!${NC}"
+  exit 1
+fi
 
 echo "${GREEN}Linter did not find mistakes!${NC}"
 
@@ -84,6 +87,9 @@ echo "${GREEN}Linter did not find mistakes!${NC}"
 
 echo "${YELLOW}Doing static code analysis...${NC}"
 
-make staticcheck
+if ! make staticcheck; then
+  echo "${RED}Staticcheck found mistakes!${NC}"
+  exit 1
+fi
 
 echo "${GREEN}Staticcheck did not find mistakes!${NC}"
\ No newline at end of file
-- 
GitLab


From ef01afeca5f280ec46eb00aeb4f5495a11bae391 Mon Sep 17 00:00:00 2001
From: Tobias Pfandzelter <pfandzelter@campus.tu-berlin.de>
Date: Thu, 23 Jul 2020 15:01:18 +0200
Subject: [PATCH 2/2] add update check to precommit

---
 ci/tools/pre-commit | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/ci/tools/pre-commit b/ci/tools/pre-commit
index 4186fd7..a5df55e 100644
--- a/ci/tools/pre-commit
+++ b/ci/tools/pre-commit
@@ -11,6 +11,15 @@ GREEN='\033[1;32m'
 YELLOW='\033[1;33m'
 NC='\033[0m'
 
+# ---------------------------------------- UPDATE PRE-COMMIT HOOK -------------------------------------------------
+
+if ! cmp -s ./.git/hooks/pre-commit ./ci/tools/pre-commit; then
+  cp ./ci/tools/pre-commit ./.git/hooks/pre-commit
+  chmod +x ./.git/hooks/pre-commit
+  echo "${RED}Pre-commit hook not up-to-date, updated now. Please try to commit again.${NC}"
+  exit 1
+fi
+
 # -------------------------------------- CHECK FOR AWS ACCESS KEYS ------------------------------------------------
 
 echo "${YELLOW}Checking for AWS access keys...${NC}"
-- 
GitLab