Merge branch 'master' of git+ssh://pobry@repo.or.cz/srv/git/git-scripts
[git-scripts.git] / pre-commit
blobb97ae39eb9dc16db87b6745ca9fc4e7efe6a3806
1 #!/bin/sh
3 GNATROOT=/opt/gnat/2007
5 PATH=$GNATROOT/bin:$HOME/bin:$PATH
7 res=0
9 REP=/tmp/_$$
11 # Repository name
12 GIT_INDEX_DIR=`dirname $GIT_INDEX_FILE`
13 REPOSIT=`dirname $GIT_INDEX_DIR`
15 [ "$REPOSIT" == "" ] && echo No repository found && exit 1;
17 # Set Style_Checker options
19 OWEB="-H -cP -cY -l256"
21 case "$REPOSIT" in
22 *) SC_OPTS="-ign out -ign tmplt -ign sed -ign txt \
23 -lang Ada -cp -cy -sp -gnat05 -lang TXML $OWEB \
24 -lang XML $OWEB -lang HTML $OWEB -lang XSD $OWEB -lang CSS $OWEB"
26 esac
28 # Process each file
30 function check() {
31 id=$4
32 file=`basename $6`
33 mode=$5
34 # skip deleted files
35 if [ "$mode" = "D" ]; then
36 return 0;
38 git show $id > $REP/$file
39 ( cd $REP; style_checker $SC_OPTS -n "$6" "$file"; )
40 res=$(($res + $?))
41 rm -f $REP/$file
44 mkdir $REP
46 # Get files to be commited
47 # <N1> <N2> <Id-OLD> <Id-NEW> <status> <Filename>
48 git-diff-index -M --cached HEAD > $REP/files
50 while read list
52 check $list
53 done < $REP/files
55 rm -fr $REP
57 exit $res