From 99fffc6c2fbc00cdeb9edd07ebb580f55d0a3513 Mon Sep 17 00:00:00 2001 From: rl1987 Date: Mon, 21 Jan 2019 13:01:52 +0200 Subject: [PATCH 1/4] Add a pre-commit hook that runs code and changelog entry formatting checks --- changes/feature28976 | 4 ++++ scripts/maint/pre-commit.git-hook | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 changes/feature28976 create mode 100755 scripts/maint/pre-commit.git-hook diff --git a/changes/feature28976 b/changes/feature28976 new file mode 100644 index 0000000000..c7ebc207f7 --- /dev/null +++ b/changes/feature28976 @@ -0,0 +1,4 @@ + o Minor features (developer tooling): + - Provide a git pre-commit hook that disallows commiting if we have any + failures in our code and changelog formatting checks. It is now available + in scripts/maint/pre-commit.git-hook. Implements feature 28976. diff --git a/scripts/maint/pre-commit.git-hook b/scripts/maint/pre-commit.git-hook new file mode 100755 index 0000000000..0868559606 --- /dev/null +++ b/scripts/maint/pre-commit.git-hook @@ -0,0 +1,23 @@ +#!/bin/bash +# +# To install this script, copy it to .git/hooks/pre-commit in local copy of +# tor git repo and make sure it has permission to execute. +# +# This is pre-commit git hook script that prevents commiting your changeset if +# it fails our code formatting or changelog entry formatting checkers. + +workdir=$(git rev-parse --show-toplevel) + +cd "$workdir" || exit 1 + +python scripts/maint/lintChanges.py ./changes + +perl scripts/maint/checkSpace.pl -C \ +src/lib/*/*.[ch] \ +src/core/*/*.[ch] \ +src/feature/*/*.[ch] \ +src/app/*/*.[ch] \ +src/test/*.[ch] \ +src/test/*/*.[ch] \ +src/tools/*.[ch] + From 611e8dcda7e29617db0b78c6fc5a47f66e4d1842 Mon Sep 17 00:00:00 2001 From: rl1987 Date: Thu, 24 Jan 2019 12:22:28 +0200 Subject: [PATCH 2/4] Also run checkInclude.py before every commit --- scripts/maint/pre-commit.git-hook | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/maint/pre-commit.git-hook b/scripts/maint/pre-commit.git-hook index 0868559606..724cd77321 100755 --- a/scripts/maint/pre-commit.git-hook +++ b/scripts/maint/pre-commit.git-hook @@ -21,3 +21,5 @@ src/test/*.[ch] \ src/test/*/*.[ch] \ src/tools/*.[ch] +python scripts/maint/checkIncludes.py + From 107e50a90f67ed26a7a24cc6135e5191601184fb Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Thu, 24 Jan 2019 08:05:42 -0500 Subject: [PATCH 3/4] lintChanges.py didn't take a directory argument in 0.2.9 --- scripts/maint/pre-commit.git-hook | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/maint/pre-commit.git-hook b/scripts/maint/pre-commit.git-hook index 724cd77321..a0d0a8bb6c 100755 --- a/scripts/maint/pre-commit.git-hook +++ b/scripts/maint/pre-commit.git-hook @@ -10,7 +10,7 @@ workdir=$(git rev-parse --show-toplevel) cd "$workdir" || exit 1 -python scripts/maint/lintChanges.py ./changes +python scripts/maint/lintChanges.py ./changes/* perl scripts/maint/checkSpace.pl -C \ src/lib/*/*.[ch] \ From dd22c84ccf07214d3d57642c2ba161be496f3607 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Thu, 24 Jan 2019 08:06:09 -0500 Subject: [PATCH 4/4] Only run the checkIncludes.py script if it exists (It was added in 0.3.5) --- scripts/maint/pre-commit.git-hook | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/maint/pre-commit.git-hook b/scripts/maint/pre-commit.git-hook index a0d0a8bb6c..b4c4ce2061 100755 --- a/scripts/maint/pre-commit.git-hook +++ b/scripts/maint/pre-commit.git-hook @@ -21,5 +21,6 @@ src/test/*.[ch] \ src/test/*/*.[ch] \ src/tools/*.[ch] -python scripts/maint/checkIncludes.py - +if test -e scripts/maint/checkIncludes.py; then + python scripts/maint/checkIncludes.py +fi