File: pre-commit

package info (click to toggle)
genometools 1.6.6%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 50,576 kB
  • sloc: ansic: 271,876; ruby: 29,930; python: 5,106; sh: 3,083; makefile: 1,213; perl: 219; pascal: 159; haskell: 37; sed: 5
file content (41 lines) | stat: -rwxr-xr-x 957 bytes parent folder | download | duplicates (8)
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
37
38
39
40
41
#!/bin/sh

# copy this file to .git/hooks (i.e., overwrite the file .git/hooks/pre-commit)
# to perform source checks before commits

check_source () {
  echo $1
  $PWD/scripts/src_check $1
  if [ $? -eq 0 ]
  then
    APIS=`echo "$1" | grep -F "_api.h"`
    if [ ${#APIS} -ne 0 ]; then
      echo "WARNING: you are committing API headers:"
      echo $APIS
      git diff --cached $APIS
      exec < /dev/tty
      echo
      read -p "Are you sure? [yn]" reply
      echo
      case $reply in
        [Yy]* ) return 0;;
        [Nn]* ) return 1;;
        * ) echo "Please answer yes or no.";;
      esac
    fi
  else
    return 1
  fi
  return 0
}

# different versions of git use different letters for deleted/removed files
FILES=`git diff --cached --name-status HEAD | \
  awk '$1 != "R" && $1 != "D" { print $2 }' | \
  grep -v -e 'src/external'                 | \
  grep -e '.*\.c$' -e '.*\.h$'`

if [ ${#FILES} -gt 0 ]
then
  check_source $FILES
fi