File: pre-commit

package info (click to toggle)
p4est 2.3.6-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 8,536 kB
  • sloc: ansic: 87,528; makefile: 855; sh: 635; perl: 272; python: 226; awk: 40; javascript: 23
file content (36 lines) | stat: -rwxr-xr-x 851 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/bin/bash
#
# Called by git-commit with no arguments.  This checks to make
# sure that all .c and .h files are indented correctly before
# a commit is made.
#
# To enable this hook, make this file executable and place it
# in $GIT_DIR/hooks.

. git-sh-setup

CHFILES=$(git-diff-index -M --name-only --cached HEAD | \
          grep '.*\.[ch]$' | grep -v '^zlib/')

for CHFILE in $CHFILES;
do
  MKTEMPLATE=`basename $CHFILE`.XXXXXXXX
  TEMPFILE=`mktemp -t "$MKTEMPLATE"` || exit 1
  $GIT_DIR/../scindent $GIT_DIR/../$CHFILE -o $TEMPFILE
  if diff $GIT_DIR/../$CHFILE $TEMPFILE
  then
    rm -f $TEMPFILE
  else
    rm -f $TEMPFILE
    NEEDS_FORMAT=1
    echo >&2 "$CHFILE needs to be indented with:"
    echo >&2 "   $GIT_DIR/../scindent \\"
    echo >&2 "      $GIT_DIR/../$CHFILE"
  fi
done
if [ -z "$NEEDS_FORMAT" ]
then
  exit 0
else
  exit 1
fi