-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit-pre-push.example
54 lines (40 loc) · 1.23 KB
/
git-pre-push.example
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
#!/bin/bash
set -eu
SUCCESS=0
ERROR=1
remote_repo_name="$1"
remote_repo_url="$2"
has_master_ref=0
while read local_ref local_sha remote_ref remote_sha; do
if [[ $remote_ref = "refs/heads/master" ]]; then
has_master_ref=1
fi
done
if [[ $has_master_ref -eq 0 ]]; then
exit $SUCCESS
fi
echo "#------------------------------------------------------------"
echo "# You're about to push to master ! "
echo "# Current directory: $(pwd) "
echo "#------------------------------------------------------------"
echo
# Execute project's tests
echo "====== REPLACE THIS LINE WITH COMMAND TO TEST YOUR APP" && exit 1
if [[ $? -ne 0 ]]; then
echo "#------------------------------------------------------------"
echo "# TEST KO :("
echo "#------------------------------------------------------------"
echo
else
echo "#------------------------------------------------------------"
echo "# TEST ok, let's push your changes!"
echo "#------------------------------------------------------------"
echo
read -p ">> DO YOU STILL WANT TO PUSH ? " resp < /dev/tty
if [[ "$resp" =~ ^[Nn]$ ]]; then
echo "Hope for a better push ;)"
exit $ERROR
fi
exit $SUCCESS
fi
exit $ERROR