[PATCH for comments] configure: install a whitespace checking pre-commit hook for developers
Ralph Böhme
slow at samba.org
Tue Apr 10 06:36:41 UTC 2018
On Tue, Apr 10, 2018 at 08:20:55AM +0200, Ralph Böhme via samba-technical wrote:
> On Tue, Apr 10, 2018 at 12:35:07AM +1200, Douglas Bagnall via samba-technical wrote:
> > Martin wrote:
> >
> > > The problem is that the *initial* proposal is not for a checkpatch
> > > script that people can run *before* submitting their patch. The
> > > proposal is for something that runs at the submission gate.
> >
> > This patch shows a third way, still quite authoritarian but sort of
> > opt-out-able and entirely local. It makes it harder to *create*
> > patches that break the rules, not to submit them.
> >
> > It will also (I think) make it harder to `git am` a patch series that
> > contains whitespace errors, and will possibly annoy people who make a
> > lot of private WIP patches.
>
> [slow at kazak scratch]$ git am ~/patches/0001-configure-install-a-whitespace-checking-pre-commit-h.patch
> Applying: configure: install a whitespace checking pre-commit hook for developers
> .git/rebase-apply/patch:46: trailing whitespace.
> # simple default.
> warning: 1 line adds whitespace errors.
> [slow at kazak scratch]$
>
> :)))
besides that, this is really, really nice. Thanks Douglas!
Updated patch with fixed whitespace attached.
-slow
--
Ralph Boehme, Samba Team https://samba.org/
Samba Developer, SerNet GmbH https://sernet.de/en/samba/
GPG Key Fingerprint: FAE2 C608 8A24 2520 51C5
59E4 AA1E 9B71 2639 9E46
-------------- next part --------------
From b52690ded76b0d09847f44b6ec29e4c8f741c9b6 Mon Sep 17 00:00:00 2001
From: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
Date: Tue, 10 Apr 2018 00:03:55 +1200
Subject: [PATCH] configure: install a whitespace checking pre-commit hook for
developers
If you don't already have a pre-commit git hook,
configure --enable-developer
will give you one that checks for whitespace errors in changed lines
of Python, Perl and C.
Signed-off-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
Reviewed-by: Ralph Boehme <slow at samba.org>
---
examples/git-hooks/pre-commit | 15 +++++++++++++++
wscript | 9 ++++++++-
2 files changed, 23 insertions(+), 1 deletion(-)
create mode 100755 examples/git-hooks/pre-commit
diff --git a/examples/git-hooks/pre-commit b/examples/git-hooks/pre-commit
new file mode 100755
index 00000000000..68c6150cde6
--- /dev/null
+++ b/examples/git-hooks/pre-commit
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+git diff-index --check HEAD -- :/*.[ch] :/*.p[ylm]
+
+if [ $? != 0 ]; then
+ echo
+ echo "The commit failed because it seems to introduce trailing whitespace"
+ echo "into C, Perl, or Python code."
+ echo
+ echo "If you are sure you want to do this, repeat the commit with the "
+ echo "--no-verify, like this:"
+ echo
+ echo " git commit --no-verify"
+ exit 1
+fi
diff --git a/wscript b/wscript
index 0985aa94867..ce0b6f91e6e 100644
--- a/wscript
+++ b/wscript
@@ -10,7 +10,7 @@ import sys, os, tempfile
sys.path.insert(0, srcdir+"/buildtools/wafsamba")
import wafsamba, Options, samba_dist, samba_git, Scripting, Utils, samba_version
import Logs, samba_utils
-
+import shutil
samba_dist.DIST_DIRS('.')
samba_dist.DIST_BLACKLIST('.gitignore .bzrignore source4/selftest/provisions')
@@ -105,6 +105,13 @@ default_prefix = Options.default_prefix = '/usr/local/samba'
if Options.options.developer:
conf.ADD_CFLAGS('-DDEVELOPER -DDEBUG_PASSWORD')
conf.env.DEVELOPER = True
+ # if we are in a git tree without a pre-commit hook, install a
+ # simple default.
+ pre_commit_hook = os.path.join(srcdir, '.git/hooks/pre-commit')
+ if (os.path.isdir(os.path.dirname(pre_commit_hook)) and
+ not os.path.exists(pre_commit_hook)):
+ shutil.copy(os.path.join(srcdir, 'examples/git-hooks/pre-commit'),
+ pre_commit_hook)
conf.ADD_EXTRA_INCLUDES('#include/public #source4 #lib #source4/lib #source4/include #include #lib/replace')
--
2.13.6
More information about the samba-technical
mailing list