summaryrefslogtreecommitdiffstats
path: root/git_hooks
diff options
context:
space:
mode:
authorClément DAVID <clement.david@scilab-enterprises.com>2012-03-12 16:47:34 +0100
committerSylvestre Ledru <sylvestre.ledru@scilab-enterprises.com>2012-03-12 18:36:26 +0100
commitfcace30fd8436f4348a7c5e93d65066e1b14cbea (patch)
tree9f1b05095cc8d43269dbdab4cf6ece0b2bfc5799 /git_hooks
parent8a77f278b812df78eb0059ae6f66c80df9358b71 (diff)
downloadscilab-fcace30fd8436f4348a7c5e93d65066e1b14cbea.zip
scilab-fcace30fd8436f4348a7c5e93d65066e1b14cbea.tar.gz
Indent hooks: ignore generated files (#2)
Change-Id: I1504e655b559e9c042b4a83dc07358ad9f59bcee
Diffstat (limited to 'git_hooks')
-rwxr-xr-xgit_hooks/pre-commit221
1 files changed, 111 insertions, 110 deletions
diff --git a/git_hooks/pre-commit b/git_hooks/pre-commit
index 5853cb1..6776f15 100755
--- a/git_hooks/pre-commit
+++ b/git_hooks/pre-commit
@@ -13,7 +13,7 @@ if test -d ".git/rebase-merge" || \
13 test -f ".git/CHERRY_PICK_HEAD" || \ 13 test -f ".git/CHERRY_PICK_HEAD" || \
14 test -f ".git/BISECT_LOG" 14 test -f ".git/BISECT_LOG"
15then 15then
16 exit 0 16 exit 0
17fi 17fi
18 18
19# 19#
@@ -22,85 +22,86 @@ fi
22XMLINDENT="$(git config --get hooks.xmlindent)" 22XMLINDENT="$(git config --get hooks.xmlindent)"
23if test ! -x "$XMLINDENT" 23if test ! -x "$XMLINDENT"
24then 24then
25 echo "Unable to find xmlindent executable on the configuration." 25 echo "Unable to find xmlindent executable on the configuration."
26 echo 26 echo
27 echo "Please configure it with :" 27 echo "Please configure it with :"
28 echo " git config --global hooks.xmlindent C:/path/to/xmlindent" 28 echo " git config --global hooks.xmlindent C:/path/to/xmlindent"
29 echo " or " 29 echo " or "
30 echo " git config --global hooks.xmlindent /usr/bin/xmlindent" 30 echo " git config --global hooks.xmlindent /usr/bin/xmlindent"
31 echo 31 echo
32fi 32fi
33 33
34if test -z "$(git config --get-all xmlindent.ignored)" 34if test -z "$(git config --get-all xmlindent.ignored)"
35then 35then
36 echo "Unable to find xmlindent ignored list on the configuration, ignored" 36 echo "Unable to find xmlindent ignored list on the configuration, ignored"
37 echo 37 echo
38 echo "You can configure it with :" 38 echo "You can configure it with :"
39 echo " git config --add xmlindent.ignored 'scilab/Visual-Studio-settings/*.xml' " 39 echo " git config --add xmlindent.ignored 'scilab/Visual-Studio-settings/*.xml' "
40 echo " git config --add xmlindent.ignored 'scilab/checkstyle/*.xml' " 40 echo " git config --add xmlindent.ignored 'scilab/checkstyle/*.xml' "
41 echo 41 echo
42 42
43 XMLINDENT_IGNORED="" 43 XMLINDENT_IGNORED=""
44else 44else
45 XMLINDENT_IGNORED="$(find $(git config --get-all xmlindent.ignored))" 45 XMLINDENT_IGNORED="$(find $(git config --get-all xmlindent.ignored))"
46fi 46fi
47 47
48ASTYLE="$(git config --get hooks.astyle)" 48ASTYLE="$(git config --get hooks.astyle)"
49if test ! -x "$ASTYLE" 49if test ! -x "$ASTYLE"
50then 50then
51 echo "Unable to find astyle executable on the configuration." 51 echo "Unable to find astyle executable on the configuration."
52 echo 52 echo
53 echo "Please configure it with :" 53 echo "Please configure it with :"
54 echo " git config --global hooks.astyle C:/path/to/astyle" 54 echo " git config --global hooks.astyle C:/path/to/astyle"
55 echo " or " 55 echo " or "
56 echo " git config --global hooks.astyle /usr/bin/astyle" 56 echo " git config --global hooks.astyle /usr/bin/astyle"
57 echo 57 echo
58fi 58fi
59 59
60if test -z "$(git config --get-all astyle.ignored)" 60if test -z "$(git config --get-all astyle.ignored)"
61then 61then
62 echo "Unable to find astyle ignored list on the configuration, ignored" 62 echo "Unable to find astyle ignored list on the configuration, ignored"
63 echo 63 echo
64 echo "You can configure it with :" 64 echo "You can configure it with :"
65 echo " git config --add astyle.ignored 'scilab/modules/*/src/jni/*.hxx' " 65 echo " git config --add astyle.ignored 'scilab/modules/*/src/jni/*.hxx' "
66 echo " git config --add astyle.ignored 'scilab/modules/*/src/jni/*.cpp' " 66 echo " git config --add astyle.ignored 'scilab/modules/*/src/jni/*.cpp' "
67 echo " git config --add astyle.ignored 'scilab/modules/*/src/jni/*.c' " 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' " 68 echo " git config --add astyle.ignored 'scilab/modules/javasci/src/java/org/scilab/modules/javasci/Call_Scilab*.java' "
69 echo 69 echo " git config --add astyle.ignored 'scilab/modules/renderer/src/java/org/scilab/modules/renderer/FigureScilabCall*.java' "
70 70 echo
71 ASTYLE_IGNORED="" 71
72 ASTYLE_IGNORED=""
72else 73else
73 ASTYLE_IGNORED="$(find $(git config --get-all astyle.ignored))" 74 ASTYLE_IGNORED="$(find $(git config --get-all astyle.ignored))"
74fi 75fi
75 76
76# indent / format file by type 77# indent / format file by type
77# 78#
78indent() { 79indent() {
79 # getting against as the current commit 80 # getting against as the current commit
80 if git rev-parse --verify HEAD >/dev/null 2>&1 81 if git rev-parse --verify HEAD >/dev/null 2>&1
81 then 82 then
82 local against=HEAD 83 local against=HEAD
83 else 84 else
84 # Initial commit: diff against an empty tree object 85 # Initial commit: diff against an empty tree object
85 local against=4b825dc642cb6eb9a060e54bf8d69288fbee4904 86 local against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
86 fi 87 fi
87 88
88 # loop on modified files 89 # loop on modified files
89 git diff --cached --name-only $against |while read file; 90 git diff --cached --name-only $against |while read file;
90 do 91 do
91 local ext=$(expr "$file" : ".*\(\..*\)") 92 local ext=$(expr "$file" : ".*\(\..*\)")
92 case $ext in 93 case $ext in
93 .xcos|.xml) 94 .xcos|.xml)
94 __indent_Xml; 95 __indent_Xml;
95 ;; 96 ;;
96 .h|.c|.hxx|.cpp) 97 .h|.c|.hxx|.cpp)
97 __indent_C; 98 __indent_C;
98 ;; 99 ;;
99 .java) 100 .java)
100 __indent_java; 101 __indent_java;
101 ;; 102 ;;
102 esac 103 esac
103 done 104 done
104 105
105 return 0; 106 return 0;
106} 107}
@@ -108,77 +109,77 @@ indent() {
108# Indent the file with xmlindent if this is an xcos file 109# Indent the file with xmlindent if this is an xcos file
109__indent_Xml() { 110__indent_Xml() {
110 111
111 if test ! -x "$XMLINDENT" 112 if test ! -x "$XMLINDENT"
112 then 113 then
113 return 1; 114 return 1;
114 fi 115 fi
115 if test ! -f $file 116 if test ! -f $file
116 then 117 then
117 return 2; 118 return 2;
118 fi 119 fi
119 120
120 # ignored globs 121 # ignored globs
121 if test -n "$XMLINDENT_IGNORED" 122 if test -n "$XMLINDENT_IGNORED"
122 then 123 then
123 echo $XMLINDENT_IGNORED |grep -q $file 124 echo $XMLINDENT_IGNORED |grep -q $file
124 if test $? -eq 0 125 if test $? -eq 0
125 then 126 then
126 echo "Formatting" $file ": ignored" 127 echo "Formatting" $file ": ignored"
127 return 3; 128 return 3;
128 fi 129 fi
129 fi 130 fi
130 131
131 echo "Formatting" $file 132 echo "Formatting" $file
132 "$XMLINDENT" -i 2 -o "$file" "$file" || return 4; 133 "$XMLINDENT" -i 2 -o "$file" "$file" || return 4;
133 git add "$file" || return 5; 134 git add "$file" || return 5;
134} 135}
135 136
136# Pre process before the indent 137# Pre process before the indent
137__pre_indent() { 138__pre_indent() {
138 if test ! -x "$ASTYLE" 139 if test ! -x "$ASTYLE"
139 then 140 then
140 return 1; 141 return 1;
141 fi 142 fi
142 if test ! -f $file 143 if test ! -f $file
143 then 144 then
144 return 2; 145 return 2;
145 fi 146 fi
146 147
147 # ignored globs 148 # ignored globs
148 if test -n "$ASTYLE_IGNORED" 149 if test -n "$ASTYLE_IGNORED"
149 then 150 then
150 echo $ASTYLE_IGNORED |grep -q "$file" 151 echo $ASTYLE_IGNORED |grep -q "$file"
151 if test $? -eq 0 152 if test $? -eq 0
152 then 153 then
153 echo "Indenting" $file ": ignored" 154 echo "Indenting" $file ": ignored"
154 return 3; 155 return 3;
155 fi 156 fi
156 fi 157 fi
157 158
158 echo "Indenting" $file 159 echo "Indenting" $file
159 return 0; 160 return 0;
160} 161}
161 162
162# post process after the indent 163# post process after the indent
163__post_indent() { 164__post_indent() {
164 git add "$file" 165 git add "$file"
165} 166}
166 167
167COMMON_ASTYLE_ARGS="--pad-header -n --pad-oper --indent-col1-comments --indent-switches" 168COMMON_ASTYLE_ARGS="--pad-header -n --pad-oper --indent-col1-comments --indent-switches"
168 169
169# Indent the file with `astyle' if this is a C/CPP file 170# Indent the file with `astyle' if this is a C/CPP file
170__indent_C() { 171__indent_C() {
171 __pre_indent || return 1 172 __pre_indent || return 1
172 $ASTYLE $COMMON_ASTYLE_ARGS --style=linux --indent=spaces=4 -A1 "$file" || return 2 173 $ASTYLE $COMMON_ASTYLE_ARGS --style=linux --indent=spaces=4 -A1 "$file" || return 2
173 __post_indent || return 3 174 __post_indent || return 3
174 return 0 175 return 0
175} 176}
176 177
177# Indent the file with `astyle' if this is a Java file 178# Indent the file with `astyle' if this is a Java file
178__indent_java() { 179__indent_java() {
179 __pre_indent || return 1 180 __pre_indent || return 1
180 $ASTYLE $COMMON_ASTYLE_ARGS --style=java --indent=spaces=4 "$file" || return 2 181 $ASTYLE $COMMON_ASTYLE_ARGS --style=java --indent=spaces=4 "$file" || return 2
181 __post_indent || return 3 182 __post_indent || return 3
182 return 0 183 return 0
183} 184}
184 185