forked from supertokens/supertokens-docker-postgresql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pre-commit.sh
executable file
·56 lines (47 loc) · 1.39 KB
/
pre-commit.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/bash
# checks if locally staged changes are
# formatted properly. Ignores non-staged
# changes.
# Intended as git pre-commit hook
#COLOR CODES:
#tput setaf 3 = yellow -> Info
#tput setaf 1 = red -> warning/not allowed commit
#tput setaf 2 = green -> all good!/allowed commit
echo ""
echo "$(tput setaf 3)Running pre-commit hook ... (you can omit this with --no-verify, but don't)$(tput sgr 0)"
# get current version----------
version=`cat Dockerfile | grep -e 'ARG CORE_VERSION='`
while IFS='=' read -ra ADDR; do
counter=0
for i in "${ADDR[@]}"; do
if [ $counter == 1 ]
then
version=$i
fi
counter=$(($counter+1))
done
done <<< "$version"
# get git branch name-----------
branch_name="$(git symbolic-ref HEAD 2>/dev/null)" ||
branch_name="(unnamed branch)" # detached HEAD
branch_name=${branch_name##refs/heads/}
# check if branch is correct based on the version-----------
if [ $branch_name == "master" ]
then
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
printf "${YELLOW}committing to MASTER${NC}\n"
elif [[ $version == $branch_name* ]]
then
continue=1
elif ! [[ $branch_name =~ ^[0-9]+.[0-9]+$ ]]
then
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
printf "${YELLOW}Not committing to master or version branches${NC}\n"
else
RED='\033[0;31m'
NC='\033[0m' # No Color
printf "${RED}Pushing to wrong branch. Stopping commit${NC}\n"
exit 1
fi