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)"
23 if test ! -x "$XMLINDENT"
25 echo "Unable to find xmlindent executable on the configuration."
27 echo "Please configure it with :"
28 echo " git config --global hooks.xmlindent C:/path/to/xmlindent"
30 echo " git config --global hooks.xmlindent /usr/bin/xmlindent"
34 if test -z "$(git config --get-all xmlindent.ignored)"
36 echo "Unable to find xmlindent ignored list on the configuration, ignored"
38 echo "You can configure it with :"
39 echo " git config --add xmlindent.ignored 'scilab/Visual-Studio-settings/*.xml' "
40 echo " git config --add xmlindent.ignored 'scilab/checkstyle/*.xml' "
45 XMLINDENT_IGNORED="$(find $(git config --get-all xmlindent.ignored))"
48 ASTYLE="$(git config --get hooks.astyle)"
49 if test ! -x "$ASTYLE"
51 echo "Unable to find astyle executable on the configuration."
53 echo "Please configure it with :"
54 echo " git config --global hooks.astyle C:/path/to/astyle"
56 echo " git config --global hooks.astyle /usr/bin/astyle"
60 if test -z "$(git config --get-all astyle.ignored)"
62 echo "Unable to find astyle ignored list on the configuration, ignored"
64 echo "You can configure it with :"
65 echo " git config --add astyle.ignored 'scilab/modules/*/src/jni/*.hxx' "
66 echo " git config --add astyle.ignored 'scilab/modules/*/src/jni/*.cpp' "
67 echo " git config --add astyle.ignored 'scilab/modules/*/src/jni/*.c' "
68 echo " git config --add astyle.ignored 'scilab/modules/javasci/src/java/org/scilab/modules/javasci/Call_Scilab*.java' "
69 echo " git config --add astyle.ignored 'scilab/modules/renderer/src/java/org/scilab/modules/renderer/FigureScilabCall*.java' "
74 ASTYLE_IGNORED="$(find $(git config --get-all astyle.ignored))"
77 # indent / format file by type
80 # getting against as the current commit
81 if git rev-parse --verify HEAD >/dev/null 2>&1
85 # Initial commit: diff against an empty tree object
86 local against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
89 # loop on modified files
90 git diff --cached --name-status $against |while read st file;
93 if [ "$st" == 'D' ]; then continue; fi
94 local ext=$(expr "$file" : ".*\(\..*\)")
111 # Indent the file with xmlindent if this is an xcos file
114 if test ! -x "$XMLINDENT"
124 if test -n "$XMLINDENT_IGNORED"
126 echo $XMLINDENT_IGNORED |grep -q $file
129 echo "Formatting" $file ": ignored"
134 echo "Formatting" $file
135 "$XMLINDENT" -i 2 -o "$file" "$file" || return 4;
136 git add "$file" || return 5;
139 # Pre process before the indent
141 if test ! -x "$ASTYLE"
151 if test -n "$ASTYLE_IGNORED"
153 echo $ASTYLE_IGNORED |grep -q "$file"
156 echo "Indenting" $file ": ignored"
161 echo "Indenting" $file
165 # post process after the indent
170 COMMON_ASTYLE_ARGS="--pad-header -n --pad-oper --indent-col1-comments --indent-switches"
172 # Indent the file with `astyle' if this is a C/CPP file
174 __pre_indent || return 1
175 $ASTYLE $COMMON_ASTYLE_ARGS --style=linux --indent=spaces=4 -A1 "$file" || return 2
176 __post_indent || return 3
180 # Indent the file with `astyle' if this is a Java file
182 __pre_indent || return 1
183 $ASTYLE $COMMON_ASTYLE_ARGS --style=java --indent=spaces=4 "$file" || return 2
184 __post_indent || return 3