-
Notifications
You must be signed in to change notification settings - Fork 109
/
pre-push.hook
executable file
·37 lines (29 loc) · 1.03 KB
/
pre-push.hook
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
#!/usr/bin/env bash
protected_branch='master'
current_branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,')
RED='\033[0;31m'
GREEN='\033[1;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Show hints
echo -e "${YELLOW}Hint${NC}: You might want to know why Git is always ${GREEN}asking for my password${NC}."
echo -e " https://help.github.com/en/github/using-git/why-is-git-always-asking-for-my-password"
echo ""
# only run this if you are pushing to master
if [[ $current_branch = $protected_branch ]] ; then
echo -e "${YELLOW}Running pre push to master check...${NC}"
echo -e "${YELLOW}Trying to build tests project...${NC}"
# build the project
make
# $? is a shell variable which stores the return code from what we just ran
rc=$?
if [[ $rc != 0 ]] ; then
echo -e "${RED}Failed to build the project, please fix this and push again${NC}"
echo ""
exit $rc
fi
# Everything went OK so we can exit with a zero
echo -e "${GREEN}Pre-push check passed!${NC}"
echo ""
fi
exit 0