You've already forked opencryptoki
mirror of
https://github.com/opencryptoki/opencryptoki.git
synced 2026-10-24 05:39:17 +03:00
Add pre-commit hook and update documentation
The pre-commit hook will help developers have their code changes checked for indentation problems. Documentation mentions how the hook can be set up. Signed-off-by: Eduardo Barretto <ebarretto@linux.vnet.ibm.com>
This commit is contained in:
committed by
Patrick Steuer
parent
1b802a043c
commit
49fbb7a769
58
.githooks/pre-commit
Normal file
58
.githooks/pre-commit
Normal file
@@ -0,0 +1,58 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Check that the code follows the coding style
|
||||
#
|
||||
# If the code does not follow the coding style a warning will be printed.
|
||||
#
|
||||
|
||||
version=`gnuindent --version 2> /dev/null`
|
||||
if [ "x$version" = "x" ]; then
|
||||
version=`indent --version 2> /dev/null`
|
||||
if [ "x$version" = "x" ] || [[ "$version" != *GNU* ]]; then
|
||||
echo "Git pre-commit hook:"
|
||||
echo "Did not find GNU indent, please install it before continuing."
|
||||
exit 1
|
||||
fi
|
||||
INDENT=indent
|
||||
else
|
||||
INDENT=gnuindent
|
||||
fi
|
||||
|
||||
echo "*******************"
|
||||
|
||||
for file in `git diff-index --cached --name-only HEAD --diff-filter=ACMR`; do
|
||||
ext=$(expr "$file" : ".*\(\..*\)")
|
||||
case $ext in
|
||||
.c|.h)
|
||||
echo "Checking code style"
|
||||
# ckfile is the temporary checkout and we indent it
|
||||
ckfile=`git checkout-index --temp ${file} | cut -f 1`
|
||||
newfile=`mktemp /tmp/${ckfile}.XXXXXX` || exit 1
|
||||
$INDENT $ckfile -o $newfile 2>> /dev/null
|
||||
$INDENT $newfile 2>> /dev/null
|
||||
diff -u -p "${ckfile}" "${newfile}"
|
||||
r=$?
|
||||
rm "${ckfile}"
|
||||
rm "${newfile}"
|
||||
rm "${newfile}~"
|
||||
if [ $r != 0 ]; then
|
||||
echo "Warning: Code style error in $file"
|
||||
read -n1 -p "Do you want to CONTINUE committing? [Y/n]" opt < /dev/tty
|
||||
case $opt in
|
||||
n|N)
|
||||
echo
|
||||
exit 1
|
||||
;;
|
||||
*)
|
||||
;;
|
||||
esac
|
||||
echo "*******************"
|
||||
fi
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
echo "Not checking code style for this type of file"
|
||||
echo "*******************"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
@@ -10,6 +10,20 @@ The inspiration and formatting of this document came from the Linux Kernel
|
||||
coding style document, but make no assumption as the coding style differ from
|
||||
each other on some aspects.
|
||||
|
||||
## 0. Setting up automatic code style check
|
||||
|
||||
To help developers on checking if their code changes are following the coding
|
||||
style format, we created a pre-commit git hook which is shared under .githooks/
|
||||
directory. This hook will use GNU indent to check your code changes.
|
||||
|
||||
You might wonder "why we ask for user confirmation?". Well, we don't want to
|
||||
create a overhead for developers that are working on feature branches and their
|
||||
code changes are not yet ready for a pull request.
|
||||
|
||||
To set up the pre-commit hook, each developer after cloning the project needs
|
||||
to run:
|
||||
$ ln -s ../../.githooks/pre-commit .git/hooks/pre-commit
|
||||
|
||||
## 1. Indentation
|
||||
|
||||
Tabs are 4 space characters, differently from many projects that define it as 8
|
||||
|
||||
Reference in New Issue
Block a user