This repository has been archived by the owner on May 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pre-commit.hook
89 lines (76 loc) · 3.58 KB
/
pre-commit.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
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/bin/sh
version="Version 4.7"
echo "pre-commit: $version"
# Fonction end pour quitter le script
End(){
echo "pre-commit: FIN, supprime le fichier temporaire stagedFiles.tmp"
rm -f stagedFiles.tmp
exit $1
}
# Interrompt dès qu'une erreur est rencontrée
set -e
# Arrête le script et demande d'exécuter le batch si les versions ne correspondent pas
echo "pre-commit: Check la version du hook pre-commit"
read -r firstLineBatch < "(Ré)initialiser pre-commit.bat"
# Enlève le caractère CR de firstLineBatch pour pouvoir comparer
if [[ "${firstLineBatch%$'\r'}" != "::$version" ]]; then
cp -f "pre-commit.hook" ".git/hooks/pre-commit"
echo -e "\npre-commit: Le hook pre-commit a été mis à jour"
echo -e "pre-commit: VEUILLEZ COMMIT À NOUVEAU\n"
End 1
fi
# Par défaut les commandes git n'output pas en UTF-8
# L'activer permet de supporter l'UTF-8 pour la suite de ce bash
echo "pre-commit: Active les outputs UTF-8 avec git pour ce repo"
git config core.quotepath off
echo "pre-commit: Crée et remplie le fichier stagedFiles.tmp avec les fichiers à commit"
git diff --name-only --no-renames --cached > stagedFiles.tmp
echo "pre-commit: Check s'il y a des fichiers dans PETAL parmi les fichiers à commit"
sortieRapide=$(awk 'BEGIN {awk_sortieRapide=1}
/PETAL\// {awk_sortieRapide=0; exit}
END {print awk_sortieRapide}' stagedFiles.tmp)
if [[ $sortieRapide == 1 ]]; then
echo "pre-commit: Aucun fichier à commit n'est dans PETAL, sortie rapide"
End 0
else
echo "pre-commit: Il y a des fichiers à commit se trouvant dans PETAL"
fi
echo "pre-commit: Enlève les fichiers dans PETAL des fichiers à commit"
git reset -q HEAD -- PETAL
# Si au moins 1 fichier BDD est à commit, il faut
# commit tous les fichiers BDD
echo "pre-commit: Check s'il y a des fichiers BDD parmi les fichiers à commit"
FichiersBDDSelectionnes=$(awk 'BEGIN {awk_FichiersBDDSelectionnes=0}
/PETAL\/bin\/database\/mysql-5.7.11\/data\/petal_db\// {awk_FichiersBDDSelectionnes=1; exit}
/PETAL\/bin\/database\/mysql-5.7.11\/data\/mysql\/proc.MYD/ {awk_FichiersBDDSelectionnes=1; exit}
/PETAL\/bin\/database\/mysql-5.7.11\/data\/mysql\/proc.MYI/ {awk_FichiersBDDSelectionnes=1; exit}
END {print awk_FichiersBDDSelectionnes}' stagedFiles.tmp)
if [[ $FichiersBDDSelectionnes == 1 ]]; then
echo "pre-commit: Au moins 1 fichier BDD à commit, ajoute tous les fichiers BDD"
fichiersCaches=$(git ls-files -v "PETAL/bin/database/mysql-5.7.11/data/ibdata1" | { grep "^h" || true; })
if [[ -z "$fichiersCaches" ]]; then
git add "PETAL/bin/database/mysql-5.7.11/data/ibdata1"
else
echo "pre-commit: Réaffiche ibdata1 pour pouvoir le commit"
git update-index --no-assume-unchanged "PETAL/bin/database/mysql-5.7.11/data/ibdata1"
git add "PETAL/bin/database/mysql-5.7.11/data/ibdata1"
echo "pre-commit: Recache ibdata1"
git update-index --assume-unchanged "PETAL/bin/database/mysql-5.7.11/data/ibdata1"
fi
git add "PETAL/bin/database/mysql-5.7.11/data/petal_db/"
git add "PETAL/bin/database/mysql-5.7.11/data/mysql/proc.MYD"
git add "PETAL/bin/database/mysql-5.7.11/data/mysql/proc.MYI"
else
echo "pre-commit: Pas de fichier BDD à commit"
fi
echo "pre-commit: Ajoute les fichiers Web et tous les autres fichiers utiles dans PETAL étant à la fois à commit et pouvant être commit"
awk '
/PETAL\/www\// {system("git add " "\"" $0 "\"")}
/PETAL\/bin\/apache\/conf\/httpd_uwamp.conf/ {system("git add " "\"" $0 "\"")}
/PETAL\/bin\/php\/php-7.0.3\/php_uwamp.ini/ {system("git add " "\"" $0 "\"")}
' stagedFiles.tmp
if [[ `git diff --cached --numstat | wc -l` == 0 ]]; then
echo -e "\npre-commit: ERREUR, IL NE RESTE AUCUN FICHIER À COMMIT\n"
End 1
fi
End 0