3 # Hook used to indent 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 if test ! -x "$XMLINDENT"
24 XMLINDENT="$(git config --get hooks.xmlindent)"
26 if test ! -x "$XMLINDENT"
28 echo "Unable to find xmlindent executable on the configuration."
30 echo "Please configure it with :"
31 echo " git config --global hooks.xmlindent C:/path/to/xmlindent"
33 echo " git config --global hooks.xmlindent /usr/bin/xmlindent"
37 if test -z "$(git config --get-all xmlindent.ignored)"
39 echo "Unable to find xmlindent ignored list on the configuration, ignored"
41 echo "You can configure it with :"
42 echo " git config --add xmlindent.ignored 'scilab/Visual-Studio-settings/*.xml' "
43 echo " git config --add xmlindent.ignored 'scilab/checkstyle/*.xml' "
48 XMLINDENT_IGNORED="$(find $(git config --get-all xmlindent.ignored))"
51 if test ! -x "$ASTYLE"
53 ASTYLE="$(git config --get hooks.astyle)"
55 if test ! -x "$ASTYLE"
57 echo "Unable to find astyle executable on the configuration."
59 echo "Please configure it with :"
60 echo " git config --global hooks.astyle C:/path/to/astyle"
62 echo " git config --global hooks.astyle /usr/bin/astyle"
66 if test -z "$(git config --get-all astyle.ignored)"
68 echo "Unable to find astyle ignored list on the configuration, ignored"
70 echo "You can configure it with :"
71 echo " git config --add astyle.ignored 'scilab/modules/*/src/jni/*.hxx' "
72 echo " git config --add astyle.ignored 'scilab/modules/*/src/jni/*.cpp' "
73 echo " git config --add astyle.ignored 'scilab/modules/*/src/jni/*.c' "
74 echo " git config --add astyle.ignored 'scilab/modules/javasci/src/java/org/scilab/modules/javasci/Call_Scilab*.java' "
75 echo " git config --add astyle.ignored 'scilab/modules/renderer/src/java/org/scilab/modules/renderer/FigureScilabCall*.java' "
76 echo " git config --add astyle.ignored 'scilab/modules/helptools/src/java/org/scilab/modules/helptools/SynopsisLexer.java' "
77 echo " git config --add astyle.ignored 'scilab/modules/helptools/src/java/org/scilab/modules/helptools/XML/XMLLexer.java' "
78 echo " git config --add astyle.ignored 'scilab/modules/helptools/src/java/org/scilab/modules/helptools/c/CLexer.java' "
79 echo " git config --add astyle.ignored 'scilab/modules/helptools/src/java/org/scilab/modules/helptools/java/JavaLexer.java' "
80 echo " git config --add astyle.ignored 'scilab/modules/helptools/src/java/org/scilab/modules/helptools/scilab/ScilabLexer.java' "
81 echo " git config --add astyle.ignored 'scilab/modules/scinotes/src/java/org/scilab/modules/scinotes/FunctionScanner.java' "
82 echo " git config --add astyle.ignored 'scilab/modules/scinotes/src/java/org/scilab/modules/scinotes/IndentScanner.java' "
83 echo " git config --add astyle.ignored 'scilab/modules/scinotes/src/java/org/scilab/modules/scinotes/MatchingBlockScanner.java' "
84 echo " git config --add astyle.ignored 'scilab/modules/scinotes/src/java/org/scilab/modules/scinotes/ScilabLexer.java' "
85 echo " git config --add astyle.ignored 'scilab/modules/xcos/src/java/org/scilab/modules/xcos/Controller.java' "
86 echo " git config --add astyle.ignored 'scilab/modules/xcos/src/java/org/scilab/modules/xcos/JavaController.java' "
87 echo " git config --add astyle.ignored 'scilab/modules/xcos/src/java/org/scilab/modules/xcos/Kind.java' "
88 echo " git config --add astyle.ignored 'scilab/modules/xcos/src/java/org/scilab/modules/xcos/ObjectProperties.java' "
89 echo " git config --add astyle.ignored 'scilab/modules/scicos/src/scicos_sundials/*' "
95 ASTYLE_IGNORED="$(find $(git config --get-all astyle.ignored))"
98 # indent / format file by type
101 # getting against as the current commit
102 if git rev-parse --verify HEAD >/dev/null 2>&1
106 # Initial commit: diff against an empty tree object
107 local against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
110 # get the modified files per kind filtering out ignored files and call the
111 # __indent_XXX helper
113 FILES=$(git diff --cached --name-only --diff-filter=ACM $against |grep -E "\.(xcos|xml|xsl)$" |grep -v -F "$XMLINDENT_IGNORED")
114 [ -z "$FILES" ] || __indent_xml;
116 FILES=$(git diff --cached --name-only --diff-filter=ACM $against |grep -E "\.(h|c|hxx|cpp)$" |grep -v -F "$ASTYLE_IGNORED")
117 [ -z "$FILES" ] || __indent_C;
119 FILES=$(git diff --cached --name-only --diff-filter=ACM $against |grep -E "\.java$" |grep -v -F "$ASTYLE_IGNORED")
120 [ -z "$FILES" ] || __indent_java;
122 FILES=$(git diff --cached --name-only --diff-filter=ACM $against |grep -E "\.(sce|sci|tst)$")
123 [ -z "$FILES" ] || __indent_scilab;
128 # Indent the file with xmlindent if this is an xcos file
130 if test ! -x "$XMLINDENT"
135 echo "Formatting" "$FILES"
136 "$XMLINDENT" -w -i 4 $FILES || return 2;
137 git add $FILES || return 3;
140 # Pre process before the indent
142 if test ! -x "$ASTYLE"
147 echo "Indenting" $FILES
151 # post process after the indent
156 COMMON_ASTYLE_ARGS="--pad-header --suffix=none --pad-oper --indent-col1-comments --indent-switches --indent=spaces=4 --add-brackets --formatted"
158 # Indent the file with `astyle' if this is a C/CPP file
160 __pre_indent || return 1
161 $ASTYLE $COMMON_ASTYLE_ARGS --style=bsd $FILES || return 2
162 __post_indent || return 3
166 # Indent the file with `astyle' if this is a Java file
168 __pre_indent || return 1
169 $ASTYLE $COMMON_ASTYLE_ARGS --style=java $FILES || return 2
170 __post_indent || return 3
174 # Indent the file with `scinotes' if this is a Scilab file
176 __pre_indent || return 1
178 TMPFILE="scinotes_indent.sce"
179 echo "files = [" >$TMPFILE
180 printf "'%s'\n" $FILES >>$TMPFILE
183 echo "scinotes(files, ['indent','trailing','quote'])" >>$TMPFILE
184 echo "exit(0)" >>$TMPFILE
186 if test -f scilab/scilab-bin; then
187 scilab/bin/scilab -nw -f $TMPFILE || return 2
189 if test -f scilab/bin/WScilex.exe; then
190 scilab/bin/wscilex.exe -nw -f $TMPFILE || return 2
192 echo "Scilab has not been built."
199 __post_indent || return 3