-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpre-commit-install
executable file
·45 lines (34 loc) · 1.27 KB
/
pre-commit-install
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
#!/usr/bin/env bash
set -eu
# move in project root
PROJECT_ROOT_DIR="$(dirname "$0")/../.." # theoretically we should in project root
LIB_ROOT_DIR="$PROJECT_ROOT_DIR/vendor/alecszaharia/pre-commit-php-cs-fixer"
CS_FIXER="${PROJECT_ROOT_DIR}/vendor/bin/php-cs-fixer"
GIT_HOOK_PRE_COMMIT="${PROJECT_ROOT_DIR}/.git/hooks/pre-commit"
CS_FIXER_CONFIG=".php-cs-fixer.dist.php"
CS_FIXER_CONFIG_NEW=".php-cs-fixer.dist.php"
CS_FIXER_CONFIG_OLD=".php-cs-fixer.dist"
if test -f "$GIT_HOOK_PRE_COMMIT"; then
echo "You already have a pre-commit git hook created. Aborting.."
exit 1;
fi
if ! test -f "$CS_FIXER"; then
echo "$CS_FIXER does not exist. Please run composer install";
exit 1;
fi
if test -f "$PROJECT_ROOT_DIR/$CS_FIXER_CONFIG_NEW"; then
CS_FIXER_CONFIG=$CS_FIXER_CONFIG_NEW
fi
if test -f "$PROJECT_ROOT_DIR/$CS_FIXER_CONFIG_OLD"; then
CS_FIXER_CONFIG=$CS_FIXER_CONFIG_OLD
fi
if test -z "${PROJECT_ROOT_DIR}/$CS_FIXER_CONFIG"; then
echo "Unable to find the ${PROJECT_ROOT_DIR}/.php-cs-fixer.dist[.php] file. More info: https://github.com/FriendsOfPHP/PHP-CS-Fixer"
exit 1;
fi
if [[ "$(docker images -q php:cli 2> /dev/null)" == "" ]]; then
docker pull php:cli
fi
cp $LIB_ROOT_DIR/hook/pre-commit.dist $GIT_HOOK_PRE_COMMIT
chmod +x $GIT_HOOK_PRE_COMMIT
echo "All done!!"