All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
From: Alan Clucas <alan.clucas@teamwpc.co.uk>
To: <git@vger.kernel.org>
Subject: [PATCH] Pass amend to pre-commit hook
Date: Mon, 14 Sep 2015 13:14:20 +0100	[thread overview]
Message-ID: <55F6BA1C.7080507@teamwpc.co.uk> (raw)

Pass a single parameter 'amend' to the pre-commit hook when performing a
commit amend.

This allows 'incremental improvement' pre-commit hooks to prevent new
code from violating a rule, but also allow the pre-commit hook to pass an
amended commit where the amend has reverted back to the original
code (which may not pass that same rule).

Example:
I have a new whitespace rule. Old code violates this rule and will not
be fixed up for blame reasons.
My pre-commit hook detects _new_ lines which violate the rule and
rejects them, however, my original commit passes.
I amend the code to revert back to the original code (which violates the
rule). Without this change I cannot detect this is an amend and reject the
change (unless --no-verify).
With this I can detect this is an amend and verify the patch as a whole
is not in violation of the rule.

Signed-off-by: Alan Clucas <alan.clucas@teamwpc.co.uk>
---
Hello,
This is my first submission to git, so hopefully I've managed to get the 
formatting right. This patch should be explained above, and would also
help out the folks at overcommit who have this (pretty horrid) solution to
the same issue:
https://github.com/brigade/overcommit/issues/146
https://github.com/brigade/overcommit/pull/167
Thanks,
Alan Clucas

 Documentation/githooks.txt | 10 ++++++----
 builtin/commit.c           |  2 +-
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/Documentation/githooks.txt b/Documentation/githooks.txt
index 7ba0ac9..49d7adb 100644
--- a/Documentation/githooks.txt
+++ b/Documentation/githooks.txt
@@ -73,10 +73,12 @@ pre-commit
 ~~~~~~~~~~
 
 This hook is invoked by 'git commit', and can be bypassed
-with `--no-verify` option.  It takes no parameter, and is
-invoked before obtaining the proposed commit log message and
-making a commit.  Exiting with non-zero status from this script
-causes the 'git commit' to abort.
+with `--no-verify` option.  It takes zero or one parameters.
+If a parameter is given it will be 'amend' indicating this is
+a commit amend (if an `--amend` option was given). It is invoked
+before obtaining the proposed commit log message and making a
+commit.  Exiting with non-zero status from this script causes the
+'git commit' to abort.
 
 The default 'pre-commit' hook, when enabled, catches introduction
 of lines with trailing whitespaces and aborts the commit when
diff --git a/builtin/commit.c b/builtin/commit.c
index 63772d0..936a614 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -671,7 +671,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
 	/* This checks and barfs if author is badly specified */
 	determine_author_info(author_ident);
 
-	if (!no_verify && run_commit_hook(use_editor, index_file, "pre-commit", NULL))
+	if (!no_verify && run_commit_hook(use_editor, index_file, "pre-commit", amend?"amend":NULL, NULL))
 		return 0;
 
 	if (squash_message) {
-- 
2.4.1.168.g1ea28e1

             reply	other threads:[~2015-09-14 12:30 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-14 12:14 Alan Clucas [this message]
2015-09-14 14:47 ` [PATCH] Pass amend to pre-commit hook Jeff King
2015-09-14 16:49   ` Alan Clucas
2015-09-27 22:09   ` Øystein Walle

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=55F6BA1C.7080507@teamwpc.co.uk \
    --to=alan.clucas@teamwpc.co.uk \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.