4 STYLECHECKER
=style_checker
7 TRACENV
=/home
/trac
/rootenv
8 TRACURL
=http
://localhost
:8000
10 # Path needed by some tools (style_checker)
12 PATH
=/opt
/gnat
/bin
:/opt
/bin
:/usr
/bin
:/bin
:/usr
/local
/bin
:$PATH
15 # Style Check all files for a specific transaction
17 root
=$
(mktemp
-d /tmp
/git-update-hook-XXXXXX
)
20 frem
=$root/files-removed
21 fadd
=$root/files-added
24 # Set Style_Checker options
26 OWEB
="-H -cP -cY -l256"
28 # The copyright pattern to check
31 # Pathnames matching the regexp will be excluded from the test
34 SC_OPTS
="-H -ign out -ign tmplt -ign sed -ign txt \
35 -lang Ada -H -cP -cY -sp -gnat05 -lang TXML $OWEB \
36 -lang XML $OWEB -lang HTML $OWEB -lang XSD $OWEB -lang CSS $OWEB"
38 # To be set with the name of the MANIFEST file if any, this script will check
39 # if an added or removed file is properly added or removed from MANIFEST.
47 mode
=$
(echo $3 | cut
-c1)
49 # Check if it is a file to ignore
51 if [[ -n "$EXCLUDE" && `echo "$6" | grep --regexp="$EXCLUDE"` ]]; then
55 # skip deleted/renamed files
57 if [[ "$mode" = "D" ||
"$mode" = "R" ]]; then
62 git show
$id > $root/$file
64 # If the MANIFEST keep it around
66 if [[ "$4" = "$MANIFEST" ]]; then
70 # If a new file, record it
72 if [[ "$mode" == "A" ]]; then
76 (cd $root; $STYLECHECKER $SC_OPTS -n "$4" "$file" )
82 # Process the changeset
89 git diff-tree
-r "$oldrev" "$newrev" > $tree
93 while read old_mode new_mode old_sha1 new_sha1 status name
; do
95 if [ "$new_mode" != 160000 ]; then
96 check_file
$old_sha1 $new_sha1 $status $name 2>&1 >> $log
97 if [[ $?
!= 0 ]]; then
100 echo -e "For details run: git diff ${old_sha1:0:7} ${new_sha1:0:7}" >&2
107 # Check for MANIFEST if needed
109 if [[ -n "$MANIFEST" && -f $fadd ]]; then
110 if [[ ! -f $fman ]]; then
112 echo Files added
, but
$MANIFEST not updated
, consider adding
:
113 git diff-tree
--name-only --diff-filter=A
-r $oldrev $newrev
118 grep --quiet "$fadded\$" $fman
119 if [[ $?
= 1 ]]; then
120 echo File
$fadded added but missing
in $MANIFEST
127 if [[ -n "$MANIFEST" && -f $frem ]]; then
128 if [[ ! -f $fman ]]; then
130 echo Files removed
, but
$MANIFEST not updated
, condider removing
:
131 git diff-tree
--name-only --diff-filter=D
-r $oldrev $newrev
136 grep --quiet "$fremoved\$" $fman
137 if [[ $?
= 0 ]]; then
138 echo File
$fremoved removed but still
in $MANIFEST
149 # Clean tmp directory
155 # Check log not empty
157 function log_not_empty
() {
160 RES
=$
(git log
-1 --pretty="%s%n%b" $REV |
grep "[a-zA-Z0-9]")
162 if [ "$RES" = "" ]; then
163 echo "Won't commit with an empty log message." 1>&2
170 # Post receive action to log message in Trac
172 function trac_post_receive_record_log
() {
178 if expr "$oldrev" : "0*$" >/dev
/null
180 git-rev-list
"$newrev"
182 git-rev-list
"$newrev" "^$oldrev"
183 fi |
tac |
while read csha
; do
184 AUTHOR
="$(git-rev-list -n 1 $csha --pretty=format:%an | sed '1d')"
185 LOG
="$(git-rev-list -n 1 $csha --pretty=medium | sed '1,3d;s:^ ::')"
187 $PYTHON /home
/git
/scripts
/trac-post-commit-hook \
188 -p "${TRACENV}/$MODULE" \
192 -s "${TRACURL}/$MODULE" 2> $root/post_commit_err_
$csha
196 # Pre update action to check for proper ticket
198 function is_merge_commit
() {
199 git rev-parse
--verify --quiet $1^
2 > /dev
/null
202 function trac_update_check_log
() {
207 for csha
in $
(git-rev-list
$oldrev..
$newrev); do
208 is_merge_commit
$csha
210 echo $csha is a merge commit
, skip checks
212 LOG
="$(git-rev-list -n 1 $csha --pretty=medium | sed '1,3d;s:^ ::')"
214 $PYTHON /home
/git
/scripts
/trac-pre-commit-hook \
215 "$TRACENV/$MODULE" "$LOG" ||
return 1
222 # Post commit send mail
223 # Can be called with $4 = "--diff n" to skip log diff in e-mail
225 function send_mail_post_receive
() {
231 if expr "$oldrev" : "0*$" >/dev
/null
233 git-rev-list
"$newrev"
235 git-rev-list
--reverse "$newrev" "^$oldrev"
236 fi |
while read csha
;
238 git-show
$csha |
mail -s "[$MODULE] $ref commit $csha" $5 $6 $7 $8 $9
242 # Post commit send xmpp
244 function send_xmpp_post_commit
() {
250 AUTHOR
=$
(git log
-1 --pretty="%an")
251 LOG
=$
(git log
-1 --pretty="%s%n%b")
253 echo $AUTHOR $LOG | sendxmpp
-f $XMPPRC -s $SUBJECT $5 $6 $7