-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathverify_authors.sh
executable file
·100 lines (84 loc) · 2.08 KB
/
verify_authors.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
#!/bin/bash
#
# Copyright (c) 2022, 219 Design, LLC
# See LICENSE.txt
#
# https://www.219design.com
# Software | Electrical | Mechanical | Product Design
#
set -euo pipefail # https://vaneyckt.io/posts/safer_bash_scripts_with_set_euxo_pipefail/
IFS=$'\n\t'
function error() {
echo $@ >& /dev/stderr
}
function missing_primary_branch() {
error "Did you use the wrong branch?"
git branch -a
}
PRIMARY_BRANCH=origin/master
echo "Primary branch is ${PRIMARY_BRANCH}."
trap missing_primary_branch EXIT
ancestor_commit=$(git merge-base ${PRIMARY_BRANCH} HEAD)
trap "" EXIT
echo "The most recent common ancestor commit with the primary branch is ${ancestor_commit}."
authors=$(cat AUTHORS)
git_authors=$(git shortlog -se ${ancestor_commit}..HEAD | cut -f 2)
git_committers=$(git shortlog -se --committer ${ancestor_commit}..HEAD | cut -f 2)
echo
echo "AUTHORS file lines:"
for author in $authors
do
echo $author
done
echo
echo "git Authors:"
for git_author in $git_authors
do
echo $git_author
done
echo
echo "git Committers:"
for git_committer in $git_committers
do
echo $git_committer
done
echo
echo "Checking git Authors."
for git_author in $git_authors
do
found=0
for author in $authors
do
if [ "$git_author" == "$author" ]
then
found=1
fi
done
if [ 0 -eq $found ]
then
error "Failed to find git author \"${git_author}\" in AUTHORS file."
error "Note that \`git commit --amend\` is not sufficient to change a commit author."
exit -1
fi
done
echo "Verified git Authors."
echo "Checking git Committers."
for git_committer in $git_committers
do
found=0
for author in $authors
do
if [ "$git_committer" == "$author" ]
then
found=1
fi
done
if [ 0 -eq $found ]
then
error "Failed to find git committer \"${git_committer}\" in AUTHORS file."
error "Note that you can't see the committer with \`git log\` but can with \`git log --pretty=full\`."
exit -1
fi
done
echo "Verified git Committers."
echo "Contributions verified."