This repository has been archived by the owner on Jun 10, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
pre-commit
executable file
·80 lines (76 loc) · 2.6 KB
/
pre-commit
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
79
80
#!/usr/local/bin/tcsh -f
#
#################################################################
# #
# Copyright (c) 2020 YottaDB LLC and/or its subsidiaries. #
# All rights reserved. #
# #
# This source code contains the intellectual property #
# of its copyright holder(s), and is made available #
# under a license. If you do not know the terms of #
# the license, please stop and do not read further. #
# #
#################################################################
#
# -----------------------------------------------------------------
# Pre-commit hook that
# 1) Enforces YottaDB Copyright in changed modules
#
set nocopyright_extensions = "" # List of extensions that cannot have copyrights. Currently none.
set filelist = `git diff --name-only HEAD`
set fixlist = ""
set curyear = `date +%Y`
@ exitstatus = 0
foreach file ($filelist)
test/needs_copyright.sh $file
if ($status != 0) then
continue
endif
grep 'Copyright (c) .*'$curyear' YottaDB LLC' $file >& /dev/null
if ($status != 0) then
set fixlist = "$fixlist $file"
endif
end
if ("" != "$fixlist") then
echo " --> Hook $0 returned non-zero status"
echo " --> Below files are missing YottaDB Copyright notice and/or current year $curyear. Fix and retry commit"
foreach file ($fixlist)
echo " $file"
end
@ exitstatus = 1
endif
# -----------------------------------------------------------------
# 2) Removes trailing white space
# -----------------------------------------------------------------
set nowhitespace_extensions = "" # List of extensions that cannot have trailing white space removed. Currently none.
set filelist = `git diff --name-only HEAD` # recompute "filelist" in case Step (1) had regenerated new files
foreach file ($filelist)
if (! -e $file) then
# If file is being deleted as part of this commit, skip whitespace conversion on it
continue
endif
if ("" != "$nowhitespace_extensions") then
set extension = $file:e
set skip = 0
foreach ext ($nowhitespace_extensions)
if ($ext == $extension) then
set skip = 1
break
endif
end
if ($skip) then
continue
endif
endif
grep -q '[ ][ ]*$' $file
if ! ($status) then
echo $file
sed -i 's/[ ][ ]*$//' $file
git add $file
if ($status) then
@ exitstatus = 1
echo "GITADD-E-FAIL : Command failed after removing trailing whitespace : git add $file"
endif
endif
end
exit $exitstatus