|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# |
| 4 | +# Copyright (c) 2022, 219 Design, LLC |
| 5 | +# See LICENSE.txt |
| 6 | +# |
| 7 | +# https://www.219design.com |
| 8 | +# Software | Electrical | Mechanical | Product Design |
| 9 | +# |
| 10 | + |
| 11 | +set -euo pipefail # https://vaneyckt.io/posts/safer_bash_scripts_with_set_euxo_pipefail/ |
| 12 | +IFS=$'\n\t' |
| 13 | + |
| 14 | +function error() { |
| 15 | + echo $@ >& /dev/stderr |
| 16 | +} |
| 17 | + |
| 18 | +function missing_primary_branch() { |
| 19 | + error "Did you use the wrong branch?" |
| 20 | + git branch -a |
| 21 | +} |
| 22 | + |
| 23 | +PRIMARY_BRANCH=origin/master |
| 24 | +echo "Primary branch is ${PRIMARY_BRANCH}." |
| 25 | + |
| 26 | +trap missing_primary_branch EXIT |
| 27 | +ancestor_commit=$(git merge-base ${PRIMARY_BRANCH} HEAD) |
| 28 | +trap "" EXIT |
| 29 | +echo "The most recent common ancestor commit with the primary branch is ${ancestor_commit}." |
| 30 | + |
| 31 | +authors=$(cat AUTHORS) |
| 32 | +git_authors=$(git shortlog -se ${ancestor_commit}..HEAD | cut -f 2) |
| 33 | +git_committers=$(git shortlog -se --committer ${ancestor_commit}..HEAD | cut -f 2) |
| 34 | + |
| 35 | +echo |
| 36 | +echo "AUTHORS file lines:" |
| 37 | +for author in $authors |
| 38 | +do |
| 39 | + echo $author |
| 40 | +done |
| 41 | + |
| 42 | +echo |
| 43 | +echo "git Authors:" |
| 44 | +for git_author in $git_authors |
| 45 | +do |
| 46 | + echo $git_author |
| 47 | +done |
| 48 | + |
| 49 | +echo |
| 50 | +echo "git Committers:" |
| 51 | +for git_committer in $git_committers |
| 52 | +do |
| 53 | + echo $git_committer |
| 54 | +done |
| 55 | + |
| 56 | +echo |
| 57 | + |
| 58 | +echo "Checking git Authors." |
| 59 | +for git_author in $git_authors |
| 60 | +do |
| 61 | + found=0 |
| 62 | + for author in $authors |
| 63 | + do |
| 64 | + if [ "$git_author" == "$author" ] |
| 65 | + then |
| 66 | + found=1 |
| 67 | + fi |
| 68 | + done |
| 69 | + |
| 70 | + if [ 0 -eq $found ] |
| 71 | + then |
| 72 | + error "Failed to find git author \"${git_author}\" in AUTHORS file." |
| 73 | + error "Note that \`git commit --amend\` is not sufficient to change a commit author." |
| 74 | + exit -1 |
| 75 | + fi |
| 76 | +done |
| 77 | +echo "Verified git Authors." |
| 78 | + |
| 79 | +echo "Checking git Committers." |
| 80 | +for git_committer in $git_committers |
| 81 | +do |
| 82 | + found=0 |
| 83 | + for author in $authors |
| 84 | + do |
| 85 | + if [ "$git_committer" == "$author" ] |
| 86 | + then |
| 87 | + found=1 |
| 88 | + fi |
| 89 | + done |
| 90 | + |
| 91 | + if [ 0 -eq $found ] |
| 92 | + then |
| 93 | + error "Failed to find git committer \"${git_committer}\" in AUTHORS file." |
| 94 | + error "Note that you can't see the committer with \`git log\` but can with \`git log --pretty=full\`." |
| 95 | + exit -1 |
| 96 | + fi |
| 97 | +done |
| 98 | +echo "Verified git Committers." |
| 99 | + |
| 100 | +echo "Contributions verified." |
0 commit comments