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 XMLINDENT="$(git config --get hooks.xmlindent)"
24 if test ! -x "$XMLINDENT"
26 echo "Unable to find xmlindent executable on the configuration."
28 echo "Please configure it with :"
29 echo " git config --global hooks.xmlindent C:/path/to/xmlindent"
31 echo " git config --global hooks.xmlindent /usr/bin/xmlindent"
35 if test -z "$(git config --get-all xmlindent.ignored)"
37 echo "Unable to find xmlindent ignored list on the configuration, ignored"
39 echo "You can configure it with :"
40 echo " git config --add xmlindent.ignored 'scilab/Visual-Studio-settings/*.xml' "
41 echo " git config --add xmlindent.ignored 'scilab/checkstyle/*.xml' "
46 XMLINDENT_IGNORED="$(find $(git config --get-all xmlindent.ignored))"
49 INDENT="$(git config --get hooks.astyle)"
50 if test ! -x "$INDENT"
52 echo "Unable to find astyle executable on the configuration."
54 echo "Please configure it with :"
55 echo " git config --global hooks.astyle C:/path/to/astyle"
57 echo " git config --global hooks.astyle /usr/bin/astyle"
61 if test -z "$(git config --get-all astyle.ignored)"
63 echo "Unable to find astyle ignored list on the configuration, ignored"
65 echo "You can configure it with :"
66 echo " git config --add astyle.ignored 'scilab/modules/*/src/jni/*.hxx' "
67 echo " git config --add astyle.ignored 'scilab/modules/*/src/jni/*.cpp' "
68 echo " git config --add astyle.ignored 'scilab/modules/*/src/jni/*.c' "
73 ASTYLE_IGNORED="$(find $(git config --get-all astyle.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" : ".*\(\..*\)")
106 # Indent the file with xmlindent if this is an xcos file
109 if test ! -x "$XMLINDENT"
119 if test -n "$XMLINDENT_IGNORED"
121 echo $XMLINDENT_IGNORED |grep -q $file
124 echo "Formatting" $file ": ignored"
129 echo "Formatting" $file
130 "$XMLINDENT" -i 2 -o "$file" "$file"
134 # Pre process before the indent
137 if test ! -x "$ASTYLE"
147 if test -n "$ASTYLE_IGNORED"
149 echo $ASTYLE_IGNORED |grep -q "$file"
152 echo "Indenting" $file ": ignored"
157 echo "Indenting" $file
161 # post process after the indent
166 COMMON_ASTYLE_ARGS="--pad-header -n --pad-oper --indent-col1-comments --indent-switches"
168 # Indent the file with `astyle' if this is a C/CPP file
171 astyle $COMMON_ASTYLE_ARGS --style=linux --indent=spaces=4 -A1 "$file"
175 # Indent the file with `astyle' if this is a Java file
178 astyle $COMMON_ASTYLE_ARGS --style=java --indent=spaces=4 "$file"