summaryrefslogtreecommitdiffstats
path: root/git_hooks/pre-commit
diff options
context:
space:
mode:
authorSylvestre Ledru <sylvestre.ledru@scilab.org>2011-06-12 01:43:18 +0200
committerSylvestre Ledru <sylvestre.ledru@scilab.org>2011-06-20 11:03:18 +0200
commit0acc3b3a5f496096af5041dd5d45f1b5de14aaed (patch)
tree819be0fa373d252109934f36b718f1286f293ec4 /git_hooks/pre-commit
parent7440f8b4a37cc38d9beaa19c977d6348e3b103a7 (diff)
downloadscilab-0acc3b3a5f496096af5041dd5d45f1b5de14aaed.zip
scilab-0acc3b3a5f496096af5041dd5d45f1b5de14aaed.tar.gz
Add some Git hooks to ease dev.
Enabled by: mv .git/hooks /tmp/ cd .git/ ln -s ../git_hooks/ hooks Change-Id: I35afa478cb9baef5114e16251811e714f255e00e
Diffstat (limited to 'git_hooks/pre-commit')
-rwxr-xr-xgit_hooks/pre-commit96
1 files changed, 96 insertions, 0 deletions
diff --git a/git_hooks/pre-commit b/git_hooks/pre-commit
new file mode 100755
index 0000000..f7f0c99
--- /dev/null
+++ b/git_hooks/pre-commit
@@ -0,0 +1,96 @@
1#!/bin/sh
2#
3# Hook used to indent all xcos files before commiting
4#
5
6XMLLINT="$(git config hooks.xmllint)"
7if test ! -x "$XMLLINT"
8then
9 echo "Unable to find xmllint executable on the configuration."
10 echo
11 echo "Please configure it with :"
12 echo " git config hooks.xmllint C:/path/to/xmllint"
13 echo
14fi
15
16INDENT="$(git config hooks.indent)"
17if test ! -x "$INDENT"
18then
19 echo "Unable to find indent executable on the configuration."
20 echo
21 echo "Please configure it with :"
22 echo " git config hooks.indent C:/path/to/indent"
23 echo
24fi
25
26# indent / format file by type
27indent() {
28 # getting against as the current commit
29 if git rev-parse --verify HEAD >/dev/null 2>&1
30 then
31 local against=HEAD
32 else
33 # Initial commit: diff against an empty tree object
34 local against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
35 fi
36
37 # loop on modified files
38 git diff --cached --name-only $against |while read file;
39 do
40 local ext=$(expr "$file" : ".*\(\..*\)")
41 case $ext in
42 .xcos)
43 __indent_Xml;
44 ;;
45 .xml)
46 __indent_Xml;
47 ;;
48 .h)
49 __indent_C;
50 ;;
51 .c)
52 __indent_C;
53 ;;
54 .hxx)
55 __indent_C;
56 ;;
57 .cpp)
58 __indent_C;
59 ;;
60 esac
61 done
62}
63# Indent the file with xmllint if this is an xcos file
64__indent_Xml() {
65
66 if test ! -x "$XMLLINT"
67 then
68 return;
69 fi
70 if test ! -f $file
71 then
72 return;
73 fi
74
75 echo "Formatting " $file
76 "$XMLLINT" --format -o "$file" "$file"
77 git add "$file"
78}
79# Indent the file with `indent' if this is a C/CPP file
80__indent_C() {
81
82 if test ! -x "$INDENT"
83 then
84 return;
85 fi
86 if test ! -f $file
87 then
88 return;
89 fi
90
91 echo "Indenting " $file
92 "$INDENT" -npro --braces-after-if-line -i4 -ts4 -sob -ss -ncs -sc --no-space-after-parentheses -cp1 --no-tabs -bap -bad -npcs --dont-break-function-decl-args --dont-break-procedure-type -bli0 -l150 -il0 "$file"
93 git add "$file"
94}
95
96indent