3 GNATROOT
=/opt
/gnat
/2015
5 PATH
=$GNATROOT/bin
:$HOME/bin
:$PATH
12 # Either we are in a Git repository or in a submodule. Note that only
13 # submodules into the root directory are supported.
14 if [ -d .git
-o -d ..
/.git
/modules
/$
(basename $PWD) ]; then
22 REPOSIT_NAME
=`basename $PWD`
24 [ "$REPOSIT_NAME" == "" ] && echo No repository found
&& exit 1;
26 # Set Style_Checker options
28 OWEB
="-H -cP -cY -l256"
30 # The copyright pattern to check
33 # Pathnames matching the regexp will be excluded from the test
36 case "$REPOSIT_NAME" in
37 v2p
) SC_OPTS
="-ign out -ign tmplt -ign sed -ign txt \
38 -lang Ada -d -cp -cy -sp -gnat05 -lang TXML $OWEB -lang Script -H \
39 -lang XML $OWEB -lang HTML $OWEB -lang XSD $OWEB -lang CSS $OWEB"
42 *) SC_OPTS
="-ign out -ign tmplt -ign sed -ign txt \
43 -lang Ada -H -cP -cY -sp -gnat05 -lang TXML $OWEB \
44 -lang XML $OWEB -lang HTML $OWEB -lang XSD $OWEB -lang CSS $OWEB"
48 # Source .git-pre-commit hook for user's defined rules
50 [ -f $HOME/.git-pre-commit
] && source $HOME/.git-pre-commit
$REPOSIT_NAME
52 [ -z "$PSTATUS" ] && \
53 echo "not project status, add entry for $REPOSIT_NAME in ~/.git-pre-commit" && exit 1
55 [ "$PSTATUS" == "false" ] && exit 0
62 mode
=$
(echo $5 | cut
-c1)
66 if [[ "$mode" = "R" ]]; then
72 # Check if a sub-module, in this case nothing to do
74 if [[ ! $2 < 160000 ]]; then
78 bfile
=$
(basename $nfile)
80 # Check if it is a file to ignore
82 if [[ -n "$EXCLUDE" && `echo "$nfile" | grep --regexp="$EXCLUDE"` ]]; then
86 # Skip deleted files as no check to be done
88 if [[ "$mode" = "D" ]]; then
89 echo $ofile >> $REP/.files.removed
93 # A renamed file is removed and added
95 if [[ "$mode" = "R" ]]; then
96 echo $ofile >> $REP/.files.removed
97 echo $nfile >> $REP/.files.added
100 git show
$id > $REP/$bfile
102 # If the MANIFEST keep it around
104 if [[ "$nfile" = "$MANIFEST" ]]; then
105 cp $REP/$bfile $REP/.manifest
108 # If a new file, record it
110 if [[ "$mode" == "A" ]]; then
111 echo $nfile >> $REP/.files.added
114 # For Ada file, check change status, we normalize the old and new version
115 # of the unit and check the diff. No diff means that the changes are only
116 # reformatting and/or style fixes.
118 if [[ ! -z $
(which normalize
) && "$mode" != "A" ]]; then
119 file_ext
=${bfile##*.}
120 if [[ "$file_ext" == "adb" ||
"$file_ext" == "ads" ]]; then
121 git show
$oid > $REP/ofile
122 normalize
$REP/ofile
> $REP/n_ofile
123 normalize
$REP/$bfile > $REP/n_nfile
124 diff -q $REP/n_ofile
$REP/n_nfile
> /dev
/null
126 echo "$nfile: has no semantic changes (style changes only)"
133 ( cd $REP; style_checker
$SC_OPTS -n "$nfile" "$bfile"; )
138 if [[ -z $COMMIT_EMAIL ]]; then
139 COMMIT_EMAIL
=$
(git log
-1 --reverse --format="%ce")
142 CURRENT_EMAIL
=$
(git config user.email
)
144 [[ "$CURRENT_EMAIL" != "$COMMIT_EMAIL" ]] && \
145 echo "wrong e-mail: expected $COMMIT_EMAIL found $CURRENT_EMAIL" && exit 1
149 # Get files to be commited
150 # <N1> <N2> <Id-OLD> <Id-NEW> <status> <Filename>
151 git diff-index
-M --cached HEAD
> $REP/.files
158 # Check for MANIFEST if needed
160 if [[ -n "$MANIFEST" && -f $REP/.files.added
]]; then
161 if [[ ! -f $REP/.manifest
]]; then
163 echo Files added
, but
$MANIFEST not updated
, consider adding
:
164 git
diff --cached --name-only --diff-filter=A
169 grep --quiet ^
$fadded\$
$REP/.manifest
170 if [[ $?
= 1 ]]; then
171 echo File
$fadded added but missing
in $MANIFEST
174 done < $REP/.files.added
178 if [[ -n "$MANIFEST" && -f $REP/.files.removed
]]; then
179 if [[ ! -f $REP/.manifest
]]; then
181 echo Files removed
, but
$MANIFEST not updated
, condider removing
:
182 git
diff --cached --name-only --diff-filter=D
187 grep --quiet ^
$fremoved\$
$REP/.manifest
188 if [[ $?
= 0 ]]; then
189 echo File
$fremoved removed but still
in $MANIFEST
192 done < $REP/.files.removed