Commit initial: récupération et tri rapide
This commit is contained in:
commit
a52829f96c
104 changed files with 11892 additions and 0 deletions
83
hooks-git/mantis-filename-commitmsg_pre-receive
Executable file
83
hooks-git/mantis-filename-commitmsg_pre-receive
Executable file
|
@ -0,0 +1,83 @@
|
|||
#!/bin/sh
|
||||
|
||||
# This pre-receive hook is meant to be put in the main
|
||||
# repository of the project to detect if a commit follow
|
||||
# the rule for database updates.
|
||||
# For example, with the issue #123, second script :
|
||||
# - adding the file scripts/script_123-2.sql
|
||||
# - putting the filename in the commit msg for easier retrieval
|
||||
|
||||
# When encountering non-UTF8 messages commit, sed may fail.
|
||||
LANG=C
|
||||
# Small attemp at making this script portable...
|
||||
PATH_SCRUTINIZED="scripts"
|
||||
|
||||
# We fail on all uncaught errors
|
||||
# and it helps us transmit error status outside
|
||||
# of the loops
|
||||
set -e
|
||||
|
||||
while read LINE; do
|
||||
oldrev="$( echo $LINE | cut -f 1 -d ' ' )"
|
||||
newrev="$( echo $LINE | cut -f 2 -d ' ' )"
|
||||
refname="$( echo $LINE | cut -f 3 -d ' ' )"
|
||||
|
||||
# We ignore refs/tags and refs/remotes
|
||||
if ! echo "$refname" | grep "^refs/heads/" >/dev/null; then
|
||||
continue
|
||||
fi
|
||||
|
||||
# In case oldrev is "000000..."
|
||||
if [ "$oldrev" = "0000000000000000000000000000000000000000" ]; then
|
||||
period="$newrev"
|
||||
else
|
||||
period="$oldrev..$newrev"
|
||||
fi
|
||||
|
||||
# We loop over each commit to check if they
|
||||
# put a script file to the scripts/ directory
|
||||
# without having the following format in the
|
||||
# first line of the commit message :
|
||||
# [NNNN-NN-SQL] blabla... bla...
|
||||
git log --pretty=oneline "$period" -- "$PATH_SCRUTINIZED" | while read COMMIT; do
|
||||
# Commit metadata extraction
|
||||
commitsha="$( echo "$COMMIT" | sed 's/^\([^ ]\+\) \(.*\)$/\1/' )"
|
||||
commitmsg="$( echo "$COMMIT" | sed 's/^\([^ ]\+\) \(.*\)$/\2/' )"
|
||||
|
||||
# Listing of files modified by commit
|
||||
# (git diff-tree will escape tab and other shell-risky characters, but not spaces)
|
||||
IFS="$( printf "\t\n" )"
|
||||
for filename in $( git diff-tree --no-commit-id --name-only --root -r "$commitsha" ); do
|
||||
if echo "$filename" | grep "^$PATH_SCRUTINIZED/script"; then
|
||||
# Check the filename is well-formed
|
||||
if ! echo "$filename" | egrep "^$PATH_SCRUTINIZED/script_[0-9]{4,5}-[0-9]{2}.(sql|php)$" >/dev/null; then
|
||||
echo "check-scripts: nom de fichier non conforme : $filename"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check the filename matches the commit message
|
||||
mantis_number="$( echo "$filename" | sed -n 's#.*/script_\([0-9]\+\)-\([0-9]\+\).\(sql\|php\)#\1#p' )"
|
||||
script_number="$( echo "$filename" | sed -n 's#.*/script_\([0-9]\+\)-\([0-9]\+\).\(sql\|php\)#\2#p' )"
|
||||
extension="$( echo "$filename" | sed -n 's#.*/script_\([0-9]\+\)-\([0-9]\+\).\(sql\|php\)#\3#p' | tr "a-z" "A-Z" )"
|
||||
if ! echo $commitmsg | grep "\[$mantis_number-$script_number-$extension\] " >/dev/null; then
|
||||
echo "check-scripts: message de commit non conforme au script (filename : $filename) ($commitsha) : $commitmsg"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
# Inversely, for every commit message with the correct format, we
|
||||
# check the matching file exists
|
||||
if echo "$commitmsg" | egrep "^\[[0-9-]+[A-Z]{3}\]" >/dev/null; then
|
||||
# Check the filename matches the commit message
|
||||
mantis_number="$( echo "$commitmsg" | sed -n 's#^\[\([0-9]\{4,5\}\)-\([0-9]\{2\}\)-\(SQL\|PHP\)\] .*#\1#p' )"
|
||||
script_number="$( echo "$commitmsg" | sed -n 's#^\[\([0-9]\{4,5\}\)-\([0-9]\{2\}\)-\(SQL\|PHP\)\] .*#\2#p' )"
|
||||
extension="$( echo "$commitmsg" | sed -n 's#^\[\([0-9]\{4,5\}\)-\([0-9]\{2\}\)-\(SQL\|PHP\)\] .*#\3#p' | tr "A-Z" "a-z" )"
|
||||
if [ -z "$mantis_number" ] || ! git diff-tree --no-commit-id --name-only --root -r "$commitsha" | grep "^$PATH_SCRUTINIZED/script_$mantis_number-$script_number.$extension$" >/dev/null; then
|
||||
echo "check-scripts: aucun script SQL/PHP correspondant au message de commit ($commitsha) : $commitmsg"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
done
|
||||
done
|
58
hooks-git/simple-php-checks_pre-commit
Executable file
58
hooks-git/simple-php-checks_pre-commit
Executable file
|
@ -0,0 +1,58 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
# An example hook script to verify what is about to be committed.
|
||||
# Called by "git commit" with no arguments. The hook should
|
||||
# exit with non-zero status after issuing an appropriate message if
|
||||
# it wants to stop the commit.
|
||||
#
|
||||
# To enable this hook, rename this file to "pre-commit".
|
||||
|
||||
if git rev-parse --verify HEAD >/dev/null 2>&1
|
||||
then
|
||||
against=HEAD
|
||||
else
|
||||
# Initial commit: diff against an empty tree object
|
||||
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
|
||||
fi
|
||||
|
||||
# If you want to allow non-ASCII filenames set this variable to true.
|
||||
allownonascii=$(git config --bool hooks.allownonascii)
|
||||
|
||||
# Redirect output to stderr.
|
||||
exec 1>&2
|
||||
|
||||
# Cross platform projects tend to avoid non-ASCII filenames; prevent
|
||||
# them from being added to the repository. We exploit the fact that the
|
||||
# printable range starts at the space character and ends with tilde.
|
||||
if [ "$allownonascii" != "true" ] &&
|
||||
# Note that the use of brackets around a tr range is ok here, (it's
|
||||
# even required, for portability to Solaris 10's /usr/bin/tr), since
|
||||
# the square bracket bytes happen to fall in the designated range.
|
||||
test $(git diff --cached --name-only --diff-filter=A -z $against |
|
||||
LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0
|
||||
then
|
||||
cat <<\EOF
|
||||
Error: Attempt to add a non-ASCII file name.
|
||||
|
||||
This can cause problems if you want to work with people on other platforms.
|
||||
|
||||
To be portable it is advisable to rename the file.
|
||||
|
||||
If you know what you are doing you can disable this check using:
|
||||
|
||||
git config hooks.allownonascii true
|
||||
EOF
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Stop at any uncatched non-zero status
|
||||
set -e
|
||||
|
||||
# If there are whitespace errors, print the offending file names and fail.
|
||||
git diff-index --check --cached $against --
|
||||
|
||||
# PHP checks
|
||||
echo "Checking PHP syntax (linting)..."
|
||||
git diff-index --diff-filter=ACMRT --cached --name-only HEAD -- | egrep '\.php$|\.inc$' | xargs --no-run-if-empty -d "\n" -n 1 php -l
|
||||
echo "Checking PHP CodeStyle..."
|
||||
git diff-index --diff-filter=ACMRT --cached --name-only HEAD -- | egrep '\.php$|\.inc$' | xargs --no-run-if-empty -d "\n" phpcs --standard=phpcs.xml --extensions=php --ignore=autoload.php --ignore=bootstrap/cache/
|
11
hooks-git/website-cracra/post-receive
Executable file
11
hooks-git/website-cracra/post-receive
Executable file
|
@ -0,0 +1,11 @@
|
|||
#!/bin/sh
|
||||
|
||||
# Stop on the first error
|
||||
set -ex
|
||||
|
||||
export GIT_WORK_TREE=$GIT_DIR/..
|
||||
|
||||
# Theoretically, everything has been checked in the pre-receive hook
|
||||
# and no local modification should go missing (at worst, there's the
|
||||
# reflog)
|
||||
git reset --hard
|
14
hooks-git/website-cracra/pre-receive
Executable file
14
hooks-git/website-cracra/pre-receive
Executable file
|
@ -0,0 +1,14 @@
|
|||
#!/bin/sh
|
||||
|
||||
# Stop on the first error
|
||||
set -ex
|
||||
|
||||
export GIT_WORK_TREE=$GIT_DIR/..
|
||||
|
||||
# Check for diff between the index and the staging area
|
||||
git diff-index --quiet --cached HEAD --
|
||||
# Check for diff between the working tree and the staging area
|
||||
git diff-files --quiet
|
||||
|
||||
# No abandoned files
|
||||
test -z "$( cd "$GIT_WORK_TREE" && GIT_WORK_TREE="$PWD" GIT_DIR="$GIT_WORK_TREE/.git" git --git-dir=.git ls-files --others )"
|
11
hooks-git/website-cracra/readme.txt
Normal file
11
hooks-git/website-cracra/readme.txt
Normal file
|
@ -0,0 +1,11 @@
|
|||
fr : Ces hooks permettent de mettre à jour un site web statique
|
||||
directement via git push.
|
||||
Il faut autoriser le "in place" dans le dépôt Git distant :
|
||||
[receive]
|
||||
denyCurrentBranch = ignore
|
||||
|
||||
en : Those hooks allow to update a static website directly with
|
||||
a git push.
|
||||
You need to allow 'in place' in the remote git repository :
|
||||
[receive]
|
||||
denyCurrentBranch = ignore
|
Loading…
Add table
Add a link
Reference in a new issue