Skip to content
Snippets Groups Projects
Commit 8fcf0626 authored by Allan Blanchard's avatar Allan Blanchard
Browse files

Merge branch 'fix/dev/check-files-with-spaces' into 'master'

[dev] allow spaces in file names

See merge request frama-c/frama-c!4472
parents a171c877 accf2639
No related branches found
No related tags found
No related merge requests found
#!/bin/bash #!/bin/bash -eu
########################################################################## ##########################################################################
# # # #
# This file is part of Frama-C. # # This file is part of Frama-C. #
...@@ -29,7 +29,7 @@ DO_HDRCK="yes" ...@@ -29,7 +29,7 @@ DO_HDRCK="yes"
REFERENCE= REFERENCE=
MODE="all" MODE="all"
while [ "$1" != "" ] while [ $# -gt 0 ]
do do
case "$1" in case "$1" in
"-h"|"-help"|"--help") "-h"|"-help"|"--help")
...@@ -37,8 +37,8 @@ do ...@@ -37,8 +37,8 @@ do
echo "OPTIONS" echo "OPTIONS"
echo " -h|-help|--help print this message and exit" echo " -h|-help|--help print this message and exit"
echo " -f|--fix fix files" echo " -f|--fix fix files"
echo " -c|--commit check modified files to be commited only" echo " -c|--commit check modified files to be committed only"
echo " -p|--push check modified files to be pushed only" echo " -p|--push range check modified files to be pushed only"
echo " --no-headers do not check headers" echo " --no-headers do not check headers"
echo " --no-lint do not check lint" echo " --no-lint do not check lint"
exit 0 exit 0
...@@ -48,10 +48,12 @@ do ...@@ -48,10 +48,12 @@ do
HDRCK=headers HDRCK=headers
;; ;;
"-p"|"--push") "-p"|"--push")
REFERENCE="origin/$(git rev-parse --abbrev-ref HEAD)" shift
DIFF_ARG=$1
MODE="push" MODE="push"
;; ;;
"-c"|"--commit") "-c"|"--commit")
DIFF_ARG=--cached
MODE="commit" MODE="commit"
;; ;;
"--no-headers") "--no-headers")
...@@ -70,53 +72,52 @@ done ...@@ -70,53 +72,52 @@ done
if [ "$MODE" = "all" ]; then if [ "$MODE" = "all" ]; then
if [ $DO_LINT = "yes" ] ; then if [ $DO_LINT = "yes" ] ; then
make $LINT || exit 1 make $LINT
fi fi
if [ $DO_HDRCK = "yes" ] ; then if [ $DO_HDRCK = "yes" ] ; then
# Don't define HDRCK_EXTRA, that is required by external plugins # Don't define HDRCK_EXTRA, that is required by external plugins
make $HDRCK || exit 1 make $HDRCK
fi fi
else else
STAGED=$(git diff --diff-filter ACMR --name-only --cached $REFERENCE | sort) TMP_STAGED=$(mktemp)
UNSTAGED=$(git diff --diff-filter DMR --name-only | sort) TMP_UNSTAGED=$(mktemp)
TMP_INTER=$(mktemp)
TMP_INPUT=$(mktemp)
if [ "$STAGED" = "" ]; cleanup () {
rm -f "$TMP_STAGED" "$TMP_UNSTAGED" "$TMP_INPUT" "$TMP_INTER"
}
trap cleanup exit
git diff -z --diff-filter ACMR --name-only $DIFF_ARG | sort -z > "$TMP_STAGED"
git diff -z --diff-filter DMR --name-only | sort -z > "$TMP_UNSTAGED"
if [ ! -s "$TMP_STAGED" ];
then then
echo "No staged modification since last $MODE, nothing to do." echo "No staged modification since last $MODE, nothing to do."
exit 0 exit 0
fi fi
if [ "$UNSTAGED" != "" ]; if [ -s "$TMP_UNSTAGED" ];
then then
INTER=$(comm -12 <(ls $STAGED) <(ls $UNSTAGED)) comm -12 --zero-terminated "$TMP_STAGED" "$TMP_UNSTAGED" > "$TMP_INTER"
if [ -s "$TMP_INTER" ];
if [ "$INTER" != "" ];
then then
echo "Cannot validate push." echo "Cannot validate push."
echo "The following staged files have been modified, renamed or deleted." echo "The following staged files have been modified, renamed or deleted."
for file in $INTER ; do while IFS= read -r -d $'\0' f; do
echo "- $file" echo "- $f"
done done < "$TMP_INTER"
exit 1 exit 1
fi fi
fi fi
STAGED=$(echo $STAGED | tr '\n' ' ') if [ $DO_LINT = "yes" -a -s "$TMP_STAGED" ] ; then
git check-attr -za --stdin < "$TMP_STAGED" > "$TMP_INPUT"
TMP=$(mktemp) make $LINT LINTCK_FILES_INPUT="$TMP_INPUT"
cleanup () {
rm -f "$TMP"
}
trap cleanup exit
if [ $DO_LINT = "yes" ] ; then
git check-attr -za $STAGED > "$TMP"
make $LINT LINTCK_FILES_INPUT="$TMP" || exit 1
fi fi
if [ $DO_HDRCK = "yes" ] ; then if [ $DO_HDRCK = "yes" -a -s "$TMP_STAGED" ] ; then
git check-attr -z header_spec $STAGED > "$TMP" git check-attr -z header_spec --stdin < "$TMP_STAGED" > "$TMP_INPUT"
# Don't define HDRCK_EXTRA, that is required by external plugins # Don't define HDRCK_EXTRA, that is required by external plugins
make $HDRCK HDRCK_FILES_INPUT="$TMP" || exit 1 make $HDRCK HDRCK_FILES_INPUT="$TMP_INPUT"
fi fi
fi fi
...@@ -23,8 +23,8 @@ ...@@ -23,8 +23,8 @@
# Example of installation of this pre-commit hook (client side): # Example of installation of this pre-commit hook (client side):
# - (cd .git/hooks/ && ln -s ../../dev/git-hooks/pre-commit.sh pre-commit) # - (cd .git/hooks/ && ln -s ../../dev/git-hooks/pre-commit.sh pre-commit)
# Note: if you decide to copy the file, the `SCRIPT_DIR` variable must be
# fixed accordingly. ROOT=$(git rev-parse --show-toplevel)
echo "Pre-commit Hook..." echo "Pre-commit Hook..."
...@@ -36,5 +36,4 @@ then ...@@ -36,5 +36,4 @@ then
exit 0 exit 0
fi fi
SCRIPT_DIR=$(dirname -- "$( readlink -f -- "$0"; )") "$ROOT/dev/check-files.sh" -c || exit 1
"$SCRIPT_DIR/../check-files.sh" -c || exit 1
...@@ -21,20 +21,30 @@ ...@@ -21,20 +21,30 @@
# # # #
########################################################################## ##########################################################################
# Example of installation of this pre-push hook (client side): ROOT=$(git rev-parse --show-toplevel)
# - (cd .git/hooks/ && ln -s ../../dev/git-hooks/pre-push.sh pre-push)
# Note: if you decide to copy the file, the `SCRIPT_DIR` variable must be
# fixed accordingly.
echo "Pre-push Hook..." echo "Pre-push Hook..."
STAGED=$(git diff --diff-filter ACMR --name-only --cached origin/$(git rev-parse --abbrev-ref HEAD) | sort) empty=$(git hash-object --stdin </dev/null | tr '[0-9a-f]' '0')
if [ "$STAGED" = "" ]; remote=$1
then
echo "No diff since last push, nothing to do"
exit 0
fi
SCRIPT_DIR=$(dirname -- "$( readlink -f -- "$0"; )") while read local_ref local_oid remote_ref remote_oid
"$SCRIPT_DIR/../check-files.sh" -p || exit 1 do
if test "$local_oid" = "$empty"
then
# Handle delete
:
else
if test "$remote_oid" = "$empty"
then
# New branch, examine commits starting
# the forking point from master
remote_oid=$(git merge-base $local_ref master);
fi
range="$remote_oid $local_oid";
"$ROOT/dev/check-files.sh" -p "$range" || exit 1;
fi;
done
exit 0
...@@ -2,3 +2,4 @@ ...@@ -2,3 +2,4 @@
LIBS: ../with\ space/module LIBS: ../with\ space/module
OPT: OPT:
*/ */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment