Whamcloud - gitweb
LU-12336 build: Update ZFS version to 0.8.1
[fs/lustre-release.git] / contrib / git-hooks / tests / test-commit-msg.sh
1 #!/bin/bash
2
3 program=$0
4 progdir=$(\cd $(dirname $0) >/dev/null && pwd)
5
6 die() {
7         echo "$program fatal error:  $*"
8         exit 1
9 } 1>&2
10
11 TEMPFILE=$(mktemp ${TMPDIR:-.}/commit-XXXXXX)
12 test -f "$TEMPFILE" || die "mktemp fails"
13 trap "rm -f $TEMPFILE COMMIT*" EXIT
14
15 # Pass through xtrace setting to commit-msg script
16 #
17 SHELL=${SHELL:-sh}
18 shopt -qo xtrace && SHELL+=' -x'
19
20 test $# -eq 0 && set -- ${progdir}/commit.*
21
22 export FAIL=""
23 readonly report_fmt='%-20s %s\n'
24 for f; do
25         case "$f" in
26         ( *.orig | *.rej ) continue ;;
27         esac
28
29         cp $f $TEMPFILE
30         results=$(exec 2>&1 ${SHELL} $progdir/../commit-msg $TEMPFILE)
31         case $'\n'"$results" in
32         ( *$'\nerror:'* ) OK=0 ;;
33         ( * ) OK=1 ;;
34         esac
35
36         f=$(basename $f)
37         case $OK${f#*commit.} in
38         1ok*)   printf "$report_fmt" $f: "PASS (was allowed)" ;;
39         0ok*)   printf "$report_fmt" $f: "FAIL (not allowed)"; FAIL="$FAIL $f";;
40         0*)     printf "$report_fmt" $f: "PASS (found error)" ;;
41         *)      printf "$report_fmt" $f: "FAIL (no error)"   ; FAIL="$FAIL $f";;
42         esac
43 done
44
45 if [ -n "$FAIL" ]; then
46         echo -e "\nerror: commit-msg test(s) failed!" 1>&2
47         echo "   $FAIL"
48 fi
49
50 rm -f $TEMPFILE $TEMPFILE.*
51
52 ## Local Variables:
53 ## Mode: shell-script
54 ## sh-basic-offset:          8
55 ## sh-indent-after-do:       8
56 ## sh-indentation:           8
57 ## sh-indent-for-case-label: 0
58 ## sh-indent-for-case-alt:   8
59 ## indent-tabs-mode:         t
60 ## End: