summaryrefslogtreecommitdiff
path: root/tools/check_commit.sh
diff options
context:
space:
mode:
authorDave Hibberd <d@vehibberd.com>2023-10-16 21:37:27 +0100
committerDave Hibberd <d@vehibberd.com>2023-10-16 21:37:27 +0100
commit91dbf844ad923e3c4bca1252dd104d8fc8ce5475 (patch)
tree93c4db659daf278db034b304e4cd910454504ec1 /tools/check_commit.sh
parent6f19923a918f7fb63a444b0c99950fdbe9d2f74c (diff)
New upstream version 20231016upstream/20231016
Diffstat (limited to 'tools/check_commit.sh')
-rwxr-xr-xtools/check_commit.sh93
1 files changed, 93 insertions, 0 deletions
diff --git a/tools/check_commit.sh b/tools/check_commit.sh
new file mode 100755
index 0000000..c92c2b0
--- /dev/null
+++ b/tools/check_commit.sh
@@ -0,0 +1,93 @@
+#!/bin/bash
+
+BASE=${1:-origin/master}
+RETCODE=0
+
+RED='\033[1;31m'
+GREEN='\033[1;32m'
+NC='\033[0m'
+
+function fail() {
+ echo -e "${RED}$*${NC}"
+ RETCODE=1
+}
+
+echo -e "${GREEN}Checking from $(git rev-parse --short ${BASE}):${NC}"
+git log --pretty=oneline --no-merges --abbrev-commit ${BASE}..
+echo
+
+git diff ${BASE}.. '*.py' | grep '^+' > added_lines
+
+if grep -E '(from|import).*six' added_lines; then
+ fail No new uses of future
+fi
+
+if grep -E '\wsix\w' added_lines; then
+ fail No new uses of six
+fi
+
+if grep -E '(from|import).*builtins' added_lines; then
+ fail No new uses of future
+fi
+
+if grep -E '\wfuture\w' added_lines; then
+ fail No new uses of future
+fi
+
+if grep -E '(from|import).*past' added_lines; then
+ fail Use of past library not allowed
+fi
+
+if grep -E 'MemoryMap\(' added_lines; then
+ fail New uses of MemoryMap should be MemoryMapBytes
+fi
+
+if grep -E "[^_]_\([^\"']" added_lines; then
+ fail 'Translated strings must be literals!'
+fi
+
+if grep '/cpep8.manifest' added_lines; then
+ fail 'Do not add new files to cpep8.manifest; no longer needed'
+fi
+
+if grep '/cpep8.blacklist' added_lines; then
+ fail 'Do not add new files to cpep8.blacklist'
+fi
+
+grep -i 'license' added_lines > license_lines
+if grep -ivE '(GNU General Public License|Free Software Foundation|gnu.org.licenses)' license_lines; then
+ fail 'Files must be GPLv3 licensed (or not contain any license language)'
+fi
+
+for file in $(git diff --name-only ${BASE}..); do
+ if file $file | grep -q CRLF; then
+ fail "$file : Files should be LF (Unix) format, not CR (Mac) or CRLF (Windows)"
+ fi
+done
+
+if git log ${BASE}.. --merges | grep .; then
+ fail Please do not include merge commits in your PR
+fi
+
+make -C chirp/locale clean all >/dev/null 2>&1
+if git diff chirp/locale | grep '^\+[^#+]' | grep -v POT-Creation; then
+ fail Locale files need updating
+fi
+
+added_files=$(git diff --name-only --diff-filter=A ${BASE}.. 2>&1)
+if echo $added_files | grep -q chirp.drivers && ! echo $added_files | grep -q tests.images; then
+ fail All new drivers should include a test image
+fi
+
+existing_drivers=$(git ls-tree --name-only $BASE chirp/drivers/)
+limit=20
+for nf in $added_files; do
+ for of in $existing_drivers; do
+ change=$(wdiff -s $of $nf | grep $of | sed -r 's/.* ([0-9]+)% changed/\1/')
+ if [ "$change" -lt "$limit" ]; then
+ fail "New file $nf shares at least $((100 - $change))% with $of!"
+ fi
+ done
+done
+
+exit $RETCODE