-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpre-commit
executable file
·57 lines (50 loc) · 1.6 KB
/
pre-commit
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/sh
#
# Step 1 : EDITS_WITH_PERSONAL_TAG=`edited` => Get files with personal changes using edited script.
#
# Step 2 : prompt () => if there are files with personal changes prompt user if he wants to still commit, it might be the case.
# exec < /dev/tty => Allows us to read input inside git, without this you can never read, try commenting and see for yourself. :P
# read => reads input from terminal into variable named "yn"
#
# Step 3 : If no files carry on,
GIT_ROOT="$(git rev-parse --show-toplevel)"
cd $GIT_ROOT
EDITS_WITH_PERSONAL_TAG=`$GIT_ROOT/.git/hooks/edited`
IS_MAVEN=`find $GIT_ROOT -maxdepth 1 -name "pom.xml" | wc -l`
echo $ECLIPSE_HOME
echo $JAVA_HOME
prompt () {
while true; do
read -p "$(tput setaf 1)$1 $(tput sgr0)" yn
case $yn in
[Yy]* ) return 0;;
[Nn]* ) return 1;;
* ) echo "Please answer yes or no.";;
esac
done
}
if [ -n "$ECLIPSE_HOME" ];
then
$ECLIPSE_HOME/eclipse -nosplash -application org.eclipse.jdt.core.JavaCodeFormatter -verbose -config $GIT_ROOT/code-style/pref $GIT_ROOT/src
else
echo "ECLIPSE_HOME not set, please make sure it is."
fi
if [ $IS_MAVEN -ge 1 ];
then
mvn compile;
return $pipestatus;
else
echo "Not a maven project";
fi
if [ "$EDITS_WITH_PERSONAL_TAG" ];
then
echo
echo "$(tput setaf 3)Following files have REVERTME Tag$(tput sgr0)";
echo
echo "$EDITS_WITH_PERSONAL_TAG";
echo
exec < /dev/tty
prompt "You sure want to commit?";
else
return 0;
fi