3 # Check that the code follows a consistant code style
6 # Check for existence of indent, and error out if not present.
7 # On some *bsd systems the binary seems to be called gnunindent,
8 # so check for that first.
10 version=`gnuindent --version 2>/dev/null`
11 if test "x$version" = "x"; then
12 version=`gindent --version 2>/dev/null`
13 if test "x$version" = "x"; then
14 version=`indent --version 2>/dev/null`
15 if test "x$version" = "x"; then
16 echo "GStreamer git pre-commit hook:"
17 echo "Did not find GNU indent, please install it before continuing."
29 case `$INDENT --version` in
33 echo "GStreamer git pre-commit hook:"
34 echo "Did not find GNU indent, please install it before continuing."
35 echo "(Found $INDENT, but it doesn't seem to be GNU indent)"
40 INDENT_PARAMETERS="--braces-on-if-line \
41 --case-brace-indentation0 \
43 --braces-after-struct-decl-line \
47 --dont-line-up-parentheses \
48 --continuation-indentation4 \
52 --leave-preprocessor-space"
54 echo "--Checking style--"
55 for file in `git diff-index --cached --name-only HEAD --diff-filter=ACMR| grep "\.c$"` ; do
56 # nf is the temporary checkout. This makes sure we check against the
57 # revision in the index (and not the checked out version).
58 nf=`git checkout-index --temp ${file} | cut -f 1`
59 newfile=`mktemp /tmp/${nf}.XXXXXX` || exit 1
60 $INDENT ${INDENT_PARAMETERS} \
61 $nf -o $newfile 2>> /dev/null
62 # FIXME: Call indent twice as it tends to do line-breaks
63 # different for every second call.
64 $INDENT ${INDENT_PARAMETERS} \
65 $newfile 2>> /dev/null
66 diff -u -p "${nf}" "${newfile}"
71 echo "================================================================================================="
72 echo " Code style error in: $file "
74 echo " Please fix before committing. Don't forget to run git add before trying to commit again. "
75 echo " If the whole file is to be committed, this should work (run from the top-level directory): "
77 echo " gst-indent $file; git add $file; git commit"
79 echo "================================================================================================="
84 csharp_files=` git diff-index --cached --name-only HEAD --diff-filter=ACMR| grep "^subprojects/gstreamer-sharp/.*cs$" `
85 if test "x$csharp_files" != "x"; then
86 version=`dotnet-format --version 2>/dev/null`
87 if test "x$version" = "x"; then
88 echo "GStreamer git pre-commit hook:"
89 echo "Did not find dotnet-format required to format C# files, please install it before continuing."
92 scripts/format-csharp --check
95 echo "================================================================================================="
96 echo " Code style error: "
98 echo " Please fix before committing, running from the top-level directory: "
99 echo " scripts/format-chsarp "
101 echo " Don't forget to run git add before trying to commit again. "
102 echo "================================================================================================="
107 echo "--Checking style pass--"