Skip to content

Commit

Permalink
Changed hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
hyades committed Sep 8, 2013
1 parent b8ab132 commit ab8d1f8
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 48 deletions.
50 changes: 50 additions & 0 deletions scripts/hooks/c-pre-commit
@@ -0,0 +1,50 @@
#!/bin/bash
#
# 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.
#

function find-indent () {
if [[ -d .git && -h scripts/indent ]]; then
echo $PWD/scripts/indent
else
cd .. && {
find-indent
cd - > /dev/null
}
fi
}

# If there are whitespace errors, print the offending file names and
files=$(git diff-index --cached --name-only HEAD --diff-filter=ACMR | grep "\.c$")
indent=$(find-indent)

for file in $files; do
nf=`git checkout-index --temp ${file} | cut -f 1`
newfile=`mktemp /tmp/${nf}.XXXXXX` || exit 1
$indent $nf -o $newfile 2>> /dev/null
# FIXME: Call indent twice as it tends to do line-breaks
# different for every second call.
$indent $newfile 2>> /dev/null
diff -u -p "${nf}" "${newfile}"
r=$?
rm "${newfile}"
rm "${nf}"
if [ $r != 0 ] ; then
echo "================================================================================================="
echo " Code style error in: $file "
echo " "
echo " Please fix before committing. Don't forget to run git add before trying to commit again. "
echo " If the whole file is to be committed, this should work (run from the top-level directory): "
echo " "
echo " $indent $file; git add $file; git commit "
echo " "
echo "================================================================================================="
exit 1
fi
echo "Code style okay: $file"
done

echo "Code style okay!"
52 changes: 4 additions & 48 deletions scripts/hooks/pre-commit
@@ -1,50 +1,6 @@
#!/bin/bash
#
# 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.
#

function find-indent () {
if [[ -d .git && -h scripts/indent ]]; then
echo $PWD/scripts/indent
else
cd .. && {
find-indent
cd - > /dev/null
}
fi
}

# If there are whitespace errors, print the offending file names and
files=$(git diff-index --cached --name-only HEAD --diff-filter=ACMR | grep "\.c$")
indent=$(find-indent)

for file in $files; do
nf=`git checkout-index --temp ${file} | cut -f 1`
newfile=`mktemp /tmp/${nf}.XXXXXX` || exit 1
$indent $nf -o $newfile 2>> /dev/null
# FIXME: Call indent twice as it tends to do line-breaks
# different for every second call.
$indent $newfile 2>> /dev/null
diff -u -p "${nf}" "${newfile}"
r=$?
rm "${newfile}"
rm "${nf}"
if [ $r != 0 ] ; then
echo "================================================================================================="
echo " Code style error in: $file "
echo " "
echo " Please fix before committing. Don't forget to run git add before trying to commit again. "
echo " If the whole file is to be committed, this should work (run from the top-level directory): "
echo " "
echo " $indent $file; git add $file; git commit "
echo " "
echo "================================================================================================="
exit 1
fi
echo "Code style okay: $file"
done

echo "Code style okay!"
chmod +x scripts/hooks/c-pre-commit
chmod +x scripts/hooks/py-pre-commit
./scripts/hooks/c-pre-commit
./scripts/hooks/py-pre-commit
1 change: 1 addition & 0 deletions scripts/hooks/py-pre-commit

0 comments on commit ab8d1f8

Please sign in to comment.