[PATCH for comments] configure: install a whitespace checking pre-commit hook for developers
jra at samba.org
Mon Apr 9 15:44:10 UTC 2018
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.
Thanks very much Douglas, this looks like it might be a great
solution that works for all ! Thanks very much for helping out
with this contentious issue.
I'll test it out and push if happy.
> From 126836d41d4154594805890557fbbb9f7d0ac04b 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
> 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>
> 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 @@
> +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
> diff --git a/wscript b/wscript
> index 0985aa94867..102b772428b 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_BLACKLIST('.gitignore .bzrignore source4/selftest/provisions')
> @@ -105,6 +105,13 @@ def configure(conf):
> 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')
More information about the samba-technical