File: git-pre-commit

package info (click to toggle)
gtk-doc 1.36.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,348 kB
  • sloc: python: 9,923; ansic: 915; xml: 889; makefile: 358; sh: 351; lisp: 137; perl: 109
file content (27 lines) | stat: -rwxr-xr-x 700 bytes parent folder | download | duplicates (3)
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
#!/bin/sh
# git hook to ensure code style
# cp tools/git-pre-commit .git/hooks/pre-commit
#
# TODO:
# pylint -r n -f parseable $files

which >/dev/null pep8 || (echo "please install pep8"; exit )
which >/dev/null autopep8 || (echo "please install autopep8"; exit )
which >/dev/null pyflakes || (echo "please install pyflakes"; exit )

files=$(git diff --name-only --staged --diff-filter=ACMRTUXB | egrep "*.py$")

if test -n "$files"; then
  pep8 --max-line-length=120 $files
  res=$?
  if [ $res -ne 0 ]; then
    echo
    autopep8 --max-line-length=120 --diff $files
    echo
    echo "To fix run: autopep8 --max-line-length=120 -i $files"
  else
    pyflakes $files
    res=$?
  fi
  exit $res
fi