3 # Hook used to indent all xcos files before commiting
10 if test -d ".git/rebase-merge" || \
11 test -d ".git/rebase-apply" || \
12 test -f ".git/MERGE_HEAD" || \
13 test -f ".git/CHERRY_PICK_HEAD" || \
14 test -f ".git/BISECT_LOG"
22 XMLLINT="$(git config --get hooks.xmllint)"
24 if test ! -x "$XMLLINT"
26 echo "Unable to find xmllint executable on the configuration."
28 echo "Please configure it with :"
29 echo " git config --global hooks.xmllint C:/path/to/xmllint"
31 echo " git config --global hooks.xmllint /usr/bin/xmllint"
35 if test -z "$(git config --get-all xmllint.ignored)"
37 echo "Unable to find xmllint ignored list on the configuration, ignored"
39 echo "You can configure it with :"
40 echo " git config --add xmllint.ignored 'scilab/Visual-Studio-settings/*.xml' "
41 echo " git config --add xmllint.ignored 'scilab/checkstyle/*.xml' "
46 XMLLINT_IGNORED="$(find $(git config --get-all xmllint.ignored))"
49 INDENT="$(git config --get hooks.indent)"
50 if test ! -x "$INDENT"
52 echo "Unable to find indent executable on the configuration."
54 echo "Please configure it with :"
55 echo " git config --global hooks.indent C:/path/to/indent"
57 echo " git config --global hooks.indent /usr/bin/indent"
61 if test -z "$(git config --get-all indent.ignored)"
63 echo "Unable to find indent ignored list on the configuration, ignored"
65 echo "You can configure it with :"
66 echo " git config --add indent.ignored 'scilab/modules/*/src/jni/*.hxx' "
67 echo " git config --add indent.ignored 'scilab/modules/*/src/jni/*.cpp' "
68 echo " git config --add indent.ignored 'scilab/modules/*/src/jni/*.c' "
73 INDENT_IGNORED="$(find $(git config --get-all indent.ignored))"
76 # indent / format file by type
79 # getting against as the current commit
80 if git rev-parse --verify HEAD >/dev/null 2>&1
84 # Initial commit: diff against an empty tree object
85 local against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
88 # loop on modified files
89 git diff --cached --name-only $against |while read file;
91 local ext=$(expr "$file" : ".*\(\..*\)")
102 # Indent the file with xmllint if this is an xcos file
105 if test ! -x "$XMLLINT"
115 if test -n "$XMLLINT_IGNORED"
117 echo $XMLLINT_IGNORED |grep -q $file
120 echo "Formatting" $file ": ignored"
125 echo "Formatting" $file
126 "$XMLLINT" --format -o "$file" "$file"
129 # Indent the file with `indent' if this is a C/CPP file
132 if test ! -x "$INDENT"
142 if test -n "$INDENT_IGNORED"
144 echo $INDENT_IGNORED |grep -q "$file"
147 echo "Indenting" $file ": ignored"
153 echo "Indenting" $file
154 "$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"