File: git-pre-commit-hook

package info (click to toggle)
sndfile-tools 1.5-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 860 kB
  • sloc: ansic: 2,923; sh: 237; python: 212; makefile: 94
file content (78 lines) | stat: -rwxr-xr-x 2,051 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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/bin/sh
#

if git rev-parse --verify HEAD >/dev/null 2>&1 ; then
	against=HEAD
else
	# Initial commit: diff against an empty tree object
	against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
	fi

files=`git diff-index --name-only --cached $against`

# Redirect output to stderr.
exec 1>&2

#-------------------------------------------------------------------------------
# Check the copyright notice of all files to be commited.

user=`git config --global user.email`
year=`date +"%Y"`

missing_copyright_year=""
for f in $files ; do
	if test ! -f $f ; then
		# If file does not exist, it was probably part of a rename or something.
		echo > /dev/null
	elif test `head -5 $f | grep -c -i copyright` -gt 0 ; then
		user_copyright=`grep -i copyright $f | grep $user | grep -c $year`
		if test $user_copyright -lt 1 ; then
			missing_copyright_year="$missing_copyright_year $f"
			fi
		fi
	done

if test -n "$missing_copyright_year" ; then
	echo "Missing current year in the copyright notice of the following files:"
	for f in $missing_copyright_year ; do
		echo "    $f"
		done
	echo "Commit aborted."
	exit 1
	fi

#-------------------------------------------------------------------------------
# Check the formatting of all C files.

cfiles=""
for f in $files ; do
	if test `echo $f | grep -c "\.[ch]$"` -gt 0 ; then
		cfiles="$cfiles $f"
		fi
	done

if test -n "$cfiles" ; then
	Scripts/cstyle.py $cfiles
	if test $? -ne 0 ; then
		echo
		echo "Commit aborted. Fix the above error before trying again."
		exit 1
		fi
	fi

#-------------------------------------------------------------------------------
# Prevent files with non-ascii filenames from being committed.

if test $(git diff --cached --name-only --diff-filter=A -z $against | LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0 ; then
	echo "Error: Attempt to add a non-ascii file name."
	echo
	echo "This can cause problems if you want to work"
	echo "with people on other platforms."
	echo
	echo "To be portable it is advisable to rename the file ..."
	echo
	echo "Commit aborted."
	exit 1
	fi

exit 0