]> git.mxchange.org Git - friendica.git/blob - mods/sample-pre-commit-hook.sh
Added sample pre-commit hook to give you an idea how to start to include:
[friendica.git] / mods / sample-pre-commit-hook.sh
1 #!/bin/sh
2
3 # INSTRUCTION: Copy this file to .git/hooks/pre-commit
4
5 DBSTRUCTURE_PHP="static/dbstructure.config.php"
6
7 # You might have to change this to run the unit tests:
8 UNIT_TEST_SCRIPT="/some/path/run_unit_tests.sh"
9
10 echo "$0: Checking syntax and code-style ..."
11 CHANGES=$(git status | grep "modified:" | grep ".php" | cut -d ":" -f 2)
12 ERRORS=""
13
14 for CHANGE in ${CHANGES};
15 do
16         CHECK=$(php -l ${CHANGE} | grep -v "No syntax errors detected in")
17         if [ -n "${CHECK}" ]
18         then
19                 echo "${CHECK}"
20                 ERRORS="1"
21         fi
22         CHECK=$(./bin/dev/php-cs-fixer/vendor/bin/php-cs-fixer fix --dry-run ${CHANGE})
23         if [ "$$" != "0" -a "$$" -lt 100 ]
24         then
25                 echo "$0: Found code-style issue in '${CHANGE}'."
26                 ERRORS="1"
27         fi
28 done
29
30 if [ -n "${ERRORS}" ]
31 then
32         echo "$0: Some error(s) were found."
33         exit 255
34 fi
35
36 DBSTRUCTURE=$(echo "${CHANGES}" | grep "${DBSTRUCTURE_PHP}")
37 if [ -n "${DBSTRUCTURE}" ]
38 then
39         echo "$0: '${DBSTRUCTURE_PHP}' has changed. Updating documentation ..."
40         ./bin/console dbstructure dumpsql > database.sql || exit 255
41         git add database.sql doc/database/*.md
42 fi
43
44 echo "$0: Running unit tests ..."
45 ${UNIT_TEST_SCRIPT}
46 STATUS=$?
47 echo "$0: STATUS='${STATUS}'"
48
49 echo "$0: All checks passed."
50 exit 0