-
Notifications
You must be signed in to change notification settings - Fork 4
/
check-headers-valid.sh
executable file
·107 lines (103 loc) · 2.26 KB
/
check-headers-valid.sh
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
if [ "$1" = "--verify" ]
then
VERIFY="true"
else
VERIFY="false"
fi
for file in $(find -name '*.java')
do
date=$(git log -n 1 --pretty=format:%ad --date=format:%Y -- $file)
author=$(git log -n 1 --pretty=format:%an -- $file | sed 's/Colby/Cel/')
commit=$(git log -n 1 --pretty=format:%H -- $file)
filesha=$(sha256sum $file)
headdata=$(head -n 2 -- $file | tail -n 1)
if echo "$headdata" | grep -q "Copyright" -
then
if grep -q "^$filesha$" - <header-dates-ignore.txt
then
# don't check
true
else
if [ "$(git log --oneline $commit -n 2 | wc -l)" = 1 ]
then
# don't check: we can't see the parent commit from here
true
else
if [ "81395e30eaaa50287a3d920c631f294183e16f65" = "$commit" ]
then
# don't check: this was a name change commit that touched far too many things
true
else
FAIL="false"
if echo "$headdata" | grep -q "$author" -
then
# found
true
else
echo
echo "Uncredited author: $headdata"
FAIL="true"
fi
if echo "$headdata" | grep -qE "[-, ]$date " -
then
# found
true
else
echo
echo "Old date: $headdata"
FAIL="true"
fi
while $FAIL
do
echo
echo "$date $author <$commit $file>"
echo
if $VERIFY
then
echo "Failed."
exit 1
fi
read -e -p "(b)lame/ne(w) blame/(a)uthor blame/(e)dit/(i)gnore/e(x)it/(n)ext/(!)...> " cmd
cmdc="${cmd:0:1}"
if [ "$cmdc" = "b" ]
then
git blame -- $file
elif [ "$cmdc" = "w" ]
then
git blame -- $file | grep "$date"
elif [ "$cmdc" = "a" ]
then
git blame -- $file | grep "$author"
elif [ "$cmdc" = "e" ]
then
nano $file
elif [ "$cmdc" = "i" ]
then
echo "$filesha" >>header-dates-ignore.txt
echo "There are now $(wc -l header-dates-ignore.txt | cut -d ' ' -f 1) ignored entries."
FAIL="false"
elif [ "$cmdc" = "x" ]
then
exit 1
elif [ "$cmdc" = "n" ]
then
FAIL="false"
elif [ "$cmdc" = "!" ]
then
${cmd:1}
echo "Exit code: $?"
else
echo "unknown command '$cmdc'"
fi
done
fi
fi
fi
fi
done
if $VERIFY
then
echo "Success!"
else
echo "Done."
fi