3 # Hook used to indent all xcos files before commiting
6 XMLLINT="$(git config --get hooks.xmllint)"
7 if test ! -x "$XMLLINT"
9 echo "Unable to find xmllint executable on the configuration."
11 echo "Please configure it with :"
12 echo " git config hooks.xmllint C:/path/to/xmllint"
16 if test -z "$(git config --get-all xmllint.ignored)"
18 echo "Unable to find xmllint ignored list on the configuration, ignored"
20 echo "You can configure it with :"
21 echo " git config --add xmllint.ignored 'scilab/Visual-Studio-settings/*.xml' "
22 echo " git config --add xmllint.ignored 'scilab/checkstyle/*.xml' "
27 XMLLINT_IGNORED="$(find $(git config --get-all xmllint.ignored))"
30 INDENT="$(git config --get hooks.indent)"
31 if test ! -x "$INDENT"
33 echo "Unable to find indent executable on the configuration."
35 echo "Please configure it with :"
36 echo " git config hooks.indent C:/path/to/indent"
40 if test -z "$(git config --get-all indent.ignored)"
42 echo "Unable to find indent ignored list on the configuration, ignored"
44 echo "You can configure it with :"
45 echo " git config --add indent.ignored 'scilab/modules/*/src/jni/*.hxx' "
46 echo " git config --add indent.ignored 'scilab/modules/*/src/jni/*.cpp' "
51 INDENT_IGNORED="$(find $(git config --get-all indent.ignored))"
54 # indent / format file by type
56 # getting against as the current commit
57 if git rev-parse --verify HEAD >/dev/null 2>&1
61 # Initial commit: diff against an empty tree object
62 local against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
65 # loop on modified files
66 git diff --cached --name-only $against |while read file;
68 local ext=$(expr "$file" : ".*\(\..*\)")
91 # Indent the file with xmllint if this is an xcos file
94 if test ! -x "$XMLLINT"
104 if test -n "$XMLLINT_IGNORED"
106 echo $XMLLINT_IGNORED |grep -q $file
109 echo "Formatting" $file ": ignored"
114 echo "Formatting" $file
115 "$XMLLINT" --format -o "$file" "$file"
118 # Indent the file with `indent' if this is a C/CPP file
121 if test ! -x "$INDENT"
131 if test -n "$INDENT_IGNORED"
133 echo $INDENT_IGNORED |grep -q "$file"
136 echo "Indenting" $file ": ignored"
142 echo "Indenting" $file
143 "$INDENT" -npro --braces-after-if-line -i4 -ts4 -sob -ss -ncs -sc --no-space-after-parentheses -cp1 --no-tabs -bap -bad -npcs --dont-break-function-decl-args --dont-break-procedure-type -bli0 -l150 -il0 "$file"