summaryrefslogtreecommitdiffstats
path: root/git_hooks
diff options
context:
space:
mode:
authorClément DAVID <clement.david@scilab-enterprises.com>2012-03-08 15:43:06 +0100
committerSylvestre Ledru <sylvestre.ledru@scilab-enterprises.com>2012-03-08 17:12:33 +0100
commit84da3bb7972c6b418b3ee58bcc069d6de08805c7 (patch)
treeda3c683c1411e7460e2898ed9eee04868debe6dc /git_hooks
parent6fb37ed1364207042e0df8acced87fc935085543 (diff)
downloadscilab-84da3bb7972c6b418b3ee58bcc069d6de08805c7.zip
scilab-84da3bb7972c6b418b3ee58bcc069d6de08805c7.tar.gz
Git hooks: fix C/C++/Java indentation
Change-Id: I7ad9203a0c06ca68e7e33e0d29db9c73be9fc168
Diffstat (limited to 'git_hooks')
-rwxr-xr-xgit_hooks/pre-commit44
1 files changed, 23 insertions, 21 deletions
diff --git a/git_hooks/pre-commit b/git_hooks/pre-commit
index 54411fc..3c0bdb1 100755
--- a/git_hooks/pre-commit
+++ b/git_hooks/pre-commit
@@ -1,4 +1,4 @@
1#!/bin/sh 1#!/usr/bin/env sh
2# 2#
3# Hook used to indent all xcos files before commiting 3# Hook used to indent all xcos files before commiting
4# 4#
@@ -20,7 +20,6 @@ fi
20# Configuration check 20# Configuration check
21# 21#
22XMLINDENT="$(git config --get hooks.xmlindent)" 22XMLINDENT="$(git config --get hooks.xmlindent)"
23
24if test ! -x "$XMLINDENT" 23if test ! -x "$XMLINDENT"
25then 24then
26 echo "Unable to find xmlindent executable on the configuration." 25 echo "Unable to find xmlindent executable on the configuration."
@@ -46,8 +45,8 @@ else
46 XMLINDENT_IGNORED="$(find $(git config --get-all xmlindent.ignored))" 45 XMLINDENT_IGNORED="$(find $(git config --get-all xmlindent.ignored))"
47fi 46fi
48 47
49INDENT="$(git config --get hooks.astyle)" 48ASTYLE="$(git config --get hooks.astyle)"
50if test ! -x "$INDENT" 49if test ! -x "$ASTYLE"
51then 50then
52 echo "Unable to find astyle executable on the configuration." 51 echo "Unable to find astyle executable on the configuration."
53 echo 52 echo
@@ -101,6 +100,8 @@ indent() {
101 ;; 100 ;;
102 esac 101 esac
103 done 102 done
103
104 return 0;
104} 105}
105 106
106# Indent the file with xmlindent if this is an xcos file 107# Indent the file with xmlindent if this is an xcos file
@@ -108,11 +109,11 @@ __indent_Xml() {
108 109
109 if test ! -x "$XMLINDENT" 110 if test ! -x "$XMLINDENT"
110 then 111 then
111 return; 112 return 1;
112 fi 113 fi
113 if test ! -f $file 114 if test ! -f $file
114 then 115 then
115 return; 116 return 2;
116 fi 117 fi
117 118
118 # ignored globs 119 # ignored globs
@@ -122,25 +123,24 @@ __indent_Xml() {
122 if test $? -eq 0 123 if test $? -eq 0
123 then 124 then
124 echo "Formatting" $file ": ignored" 125 echo "Formatting" $file ": ignored"
125 return 126 return 3;
126 fi 127 fi
127 fi 128 fi
128 129
129 echo "Formatting" $file 130 echo "Formatting" $file
130 "$XMLINDENT" -i 2 -o "$file" "$file" 131 "$XMLINDENT" -i 2 -o "$file" "$file" || return 4;
131 git add "$file" 132 git add "$file" || return 5;
132} 133}
133 134
134# Pre process before the indent 135# Pre process before the indent
135__pre_indent() { 136__pre_indent() {
136
137 if test ! -x "$ASTYLE" 137 if test ! -x "$ASTYLE"
138 then 138 then
139 return; 139 return 1;
140 fi 140 fi
141 if test ! -f $file 141 if test ! -f $file
142 then 142 then
143 return; 143 return 2;
144 fi 144 fi
145 145
146 # ignored globs 146 # ignored globs
@@ -150,12 +150,12 @@ __pre_indent() {
150 if test $? -eq 0 150 if test $? -eq 0
151 then 151 then
152 echo "Indenting" $file ": ignored" 152 echo "Indenting" $file ": ignored"
153 return 153 return 3;
154 fi 154 fi
155 fi 155 fi
156 156
157 echo "Indenting" $file 157 echo "Indenting" $file
158 158 return 0;
159} 159}
160 160
161# post process after the indent 161# post process after the indent
@@ -167,17 +167,19 @@ COMMON_ASTYLE_ARGS="--pad-header -n --pad-oper --indent-col1-comments --indent-s
167 167
168# Indent the file with `astyle' if this is a C/CPP file 168# Indent the file with `astyle' if this is a C/CPP file
169__indent_C() { 169__indent_C() {
170 __pre_indent 170 __pre_indent || return 1
171 astyle $COMMON_ASTYLE_ARGS --style=linux --indent=spaces=4 -A1 "$file" 171 $ASTYLE $COMMON_ASTYLE_ARGS --style=linux --indent=spaces=4 -A1 "$file" || return 2
172 __post_indent 172 __post_indent || return 3
173 return 0
173} 174}
174 175
175# Indent the file with `astyle' if this is a Java file 176# Indent the file with `astyle' if this is a Java file
176__indent_java() { 177__indent_java() {
177 __pre_indent 178 __pre_indent || return 1
178 astyle $COMMON_ASTYLE_ARGS --style=java --indent=spaces=4 "$file" 179 $ASTYLE $COMMON_ASTYLE_ARGS --style=java --indent=spaces=4 "$file" || return 2
179 __post_indent 180 __post_indent || return 3
180 181 return 0
181} 182}
182 183
183indent 184indent
185