-
Notifications
You must be signed in to change notification settings - Fork 0
/
pre-commit
67 lines (55 loc) · 2.33 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
57
58
59
60
61
62
63
64
65
66
#!/bin/sh
#----------------------------- INITIALIZE
#Go to root of the git folder
git_root=$(git rev-parse --show-toplevel)
cd $git_root || exit
echo "**** we moved to the root of the project : $(pwd)"
#Activate virtual env
#source myvenv/bin/activate || source ffhb_venv/bin/activate || exit
#echo "**** Virtual env activated"
#----------------------------- UPDATE REQUIREMENTS
pwd
echo "**** Git commit Hook : Update requirements"
myvenv/bin/pip freeze > requirements.txt || ffhb_venv/bin/pip freeze > requirements.txt || exit
if git diff --name-only | grep --quiet "requirements.txt"
then
git add requirements.txt || exit
echo "updated requirements.txt"
else
echo "no programms added to requirements.txt"
fi
#Doc for UML picture generation : https://django-extensions.readthedocs.io/en/latest/graph_models.html
#----------------------------- UML CHART
pwd
echo "**** Git commit Hook : Check if the model has been updated"
#If model has been updated, we update the UML diagramm of the project
if git diff --cached --name-only | grep --quiet "ffhb_cal/ffhb_cal_app/models.py"
then
cd ffhb_cal || exit
#generate graph
../myvenv/bin/python manage.py graph_models -a > ../infos_project/ffhb_cal_UML.dot || ../ffhb_venv/bin/python manage.py graph_models -a > ../infos_project/ffhb_cal_UML.dot || exit
#convert to png
dot ../infos_project/ffhb_cal_UML.dot -Tpng -o ../infos_project/ffhb_cal_UML.png || exit
#ajout des fichiers au commit
#git add ../infos_project/ || exit
cd ../
git add infos_project/ffhb_cal_UML.dot || exit
git add infos_project/ffhb_cal_UML.png || exit
else
echo "the model has not been updated - we don't generate new diagramms"
fi
echo "**** End Git commit Hook : updated uml diagram"
#----------------------------- FORMAT PYTHON FILE
echo "**** Git commit Hook : Finding python files to format to pep8 convention"
for file in $(git diff --cached --name-only | grep ".py$")
do
if [[ -z "$file" ]]
then
echo "no python files commited"
else
echo "the file $file is a .py file, and will be autopep8"
myvenv/bin/autopep8 --in-place --aggressive --aggressive $file || ffhb_venv/bin/autopep8 --in-place --aggressive --aggressive $file || exit
git add $file
fi
done
echo "**** End Git commit Hook : Finding python files to format to pep8 convention"