[PATCH for comments] configure: install a whitespace checking pre-commit hook for developers
Ralph Böhme
slow at samba.org
Tue Apr 10 12:20:47 UTC 2018
On Tue, Apr 10, 2018 at 02:16:41PM +0200, Ralph Böhme wrote:
> On Tue, Apr 10, 2018 at 09:32:24PM +1000, Martin Schwenke wrote:
> > On Tue, 10 Apr 2018 11:58:18 +0200, Stefan Metzmacher via
> > samba-technical <samba-technical at lists.samba.org> wrote:
> >
> > > The logic for using a script that is part of the checkout and having a
> > > .git/hook/pre-commit script that just calls into the working tree
> > > is what I'd like to have (and maybe the logic to detect an outdated script)
> >
> > I think this is a good approach. This allows us to refine the tool or
> > even a choice/combination of tools. There is a question about how to do
> > this neatly...
>
> hold right there, I'll post something in a minute... :)
here we go.
With the attached patchset I get this:
[slow at kazak scratch]$ git diff --cached
diff --git a/source4/torture/smb2/durable_v2_open.c b/source4/torture/smb2/durable_v2_open.c
index 13316eb3f8b..f4df0a97983 100644
--- a/source4/torture/smb2/durable_v2_open.c
+++ b/source4/torture/smb2/durable_v2_open.c
@@ -2121,7 +2121,7 @@ static bool test_persistent_reconnect_lease(struct torture_context *tctx,
*/
// TALLOC_FREE(tree);
torture_comment(tctx, "Got PH, waiting for cluster kill...\n");
- getchar();
+ getchar();
torture_comment(tctx, "Trying to reconnect PH on new connection\n");
/*
[slow at kazak scratch]$ git commit
source4/torture/smb2/durable_v2_open.c:2124: trailing whitespace.
+ getchar();
The commit failed because it seems to introduce trailing whitespace
into C, Perl, or Python code.
If you are sure you want to do this, repeat the commit with the
--no-verify, like this:
git commit --no-verify
-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 76fb1110a62d25497252c863d2d6f6e33530dabe Mon Sep 17 00:00:00 2001
From: Ralph Boehme <slow at samba.org>
Date: Tue, 10 Apr 2018 13:04:27 +0200
Subject: [PATCH 1/2] Add a wrapper script as git pre-commit hook
When developer mode is enabled, the wrapper script
"script/git-hooks/pre-commit-hook" gets installed as
.git/hooks/pre-commit
and calls "script/git-hooks/pre-commit-script".
This way we can later modify the "script/git-hooks/pre-commit-script"
without the need to ever change the installed commit hook itself.
Signed-off-by: Ralph Boehme <slow at samba.org>
---
script/git-hooks/pre-commit-hook | 7 +++++++
script/git-hooks/pre-commit-script | 9 +++++++++
wscript | 9 ++++++++-
3 files changed, 24 insertions(+), 1 deletion(-)
create mode 100755 script/git-hooks/pre-commit-hook
create mode 100755 script/git-hooks/pre-commit-script
diff --git a/script/git-hooks/pre-commit-hook b/script/git-hooks/pre-commit-hook
new file mode 100755
index 00000000000..223a30dc53d
--- /dev/null
+++ b/script/git-hooks/pre-commit-hook
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+gitdir=$(git rev-parse --show-toplevel)
+
+${gitdir}/script/git-hooks/pre-commit-script || exit $?
+
+exit 0
diff --git a/script/git-hooks/pre-commit-script b/script/git-hooks/pre-commit-script
new file mode 100755
index 00000000000..eb4114e197d
--- /dev/null
+++ b/script/git-hooks/pre-commit-script
@@ -0,0 +1,9 @@
+#!/bin/sh
+
+gitdir=$(git rev-parse --show-toplevel)
+if [ $? -ne 0 ] ; then
+ echo "git rev-parse --show-toplevel failed"
+ exit 1
+fi
+
+exit 0
diff --git a/wscript b/wscript
index 0985aa94867..9c42f9a6ef6 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, 'script/git-hooks/pre-commit-hook'),
+ pre_commit_hook)
conf.ADD_EXTRA_INCLUDES('#include/public #source4 #lib #source4/lib #source4/include #include #lib/replace')
--
2.13.6
From e4488315622555ef6cb9885dbd45a2c12a2eafed Mon Sep 17 00:00:00 2001
From: Ralph Boehme <slow at samba.org>
Date: Tue, 10 Apr 2018 13:19:09 +0200
Subject: [PATCH 2/2] script/git-hooks: add check-trailing-whitespace
Signed-off-by: Ralph Boehme <slow at samba.org>
---
script/git-hooks/check-trailing-whitespace | 17 +++++++++++++++++
script/git-hooks/pre-commit-script | 2 ++
2 files changed, 19 insertions(+)
create mode 100755 script/git-hooks/check-trailing-whitespace
diff --git a/script/git-hooks/check-trailing-whitespace b/script/git-hooks/check-trailing-whitespace
new file mode 100755
index 00000000000..d98660018c5
--- /dev/null
+++ b/script/git-hooks/check-trailing-whitespace
@@ -0,0 +1,17 @@
+#!/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
+
+exit 0
diff --git a/script/git-hooks/pre-commit-script b/script/git-hooks/pre-commit-script
index eb4114e197d..98e1bd5269e 100755
--- a/script/git-hooks/pre-commit-script
+++ b/script/git-hooks/pre-commit-script
@@ -6,4 +6,6 @@ if [ $? -ne 0 ] ; then
exit 1
fi
+${gitdir}/script/git-hooks/check-trailing-whitespace || exit $?
+
exit 0
--
2.13.6
More information about the samba-technical
mailing list