git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: orgads@gmail.com
To: git@vger.kernel.org
Cc: Orgad Shaneh <orgads@gmail.com>
Subject: [PATCH v2] merge: Run commit-msg hook
Date: Tue, 26 Jul 2016 18:26:25 +0300	[thread overview]
Message-ID: <1469546785-23325-1-git-send-email-orgads@gmail.com> (raw)
In-Reply-To: <alpine.DEB.2.20.1607261614020.14111>

From: Orgad Shaneh <orgads@gmail.com>

commit-msg is needed to either validate the commit message or edit it.

Gerrit for instance uses this hook to append its Change-Id footer. The
hook is installed on the user's machine, and it is expected to append
the footer for each commit that the user creates.

This is relevant to merge commit just like any other commit. Currently
this hook is only called for simple commits, so Gerrit user that tries
to push a merge commit has to amend it first in order to execute the
hook that appends the footer.

prepare-commit-msg hook is already called on merge, but commit-msg isn't.
It looks like unlike pre-commit not being executed, which was a conscious
decision[1], commit-msg was never considered.

[1] http://thread.gmane.org/gmane.comp.version-control.git/151297/focus=151435

Signed-off-by: Orgad Shaneh <orgads@gmail.com>
---
 Documentation/git-merge.txt | 6 +++++-
 builtin/merge.c             | 7 ++++++-
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/Documentation/git-merge.txt b/Documentation/git-merge.txt
index b758d55..59508aa 100644
--- a/Documentation/git-merge.txt
+++ b/Documentation/git-merge.txt
@@ -11,7 +11,7 @@ SYNOPSIS
 [verse]
 'git merge' [-n] [--stat] [--no-commit] [--squash] [--[no-]edit]
 	[-s <strategy>] [-X <strategy-option>] [-S[<keyid>]]
-	[--[no-]allow-unrelated-histories]
+	[--[no-]allow-unrelated-histories] [--no-verify]
 	[--[no-]rerere-autoupdate] [-m <msg>] [<commit>...]
 'git merge' <msg> HEAD <commit>...
 'git merge' --abort
@@ -87,6 +87,10 @@ invocations. The automated message can include the branch description.
 	Allow the rerere mechanism to update the index with the
 	result of auto-conflict resolution if possible.
 
+--no-verify::
+	This option bypasses the commit-msg hook.
+	See also linkgit:githooks[5].
+
 --abort::
 	Abort the current conflict resolution process, and
 	try to reconstruct the pre-merge state.
diff --git a/builtin/merge.c b/builtin/merge.c
index b555a1b..30c03c8 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -51,7 +51,7 @@ static const char * const builtin_merge_usage[] = {
 static int show_diffstat = 1, shortlog_len = -1, squash;
 static int option_commit = 1;
 static int option_edit = -1;
-static int allow_trivial = 1, have_message, verify_signatures;
+static int allow_trivial = 1, have_message, verify_signatures, no_verify;
 static int overwrite_ignore = 1;
 static struct strbuf merge_msg = STRBUF_INIT;
 static struct strategy **use_strategies;
@@ -228,6 +228,7 @@ static struct option builtin_merge_options[] = {
 	{ OPTION_STRING, 'S', "gpg-sign", &sign_commit, N_("key-id"),
 	  N_("GPG sign commit"), PARSE_OPT_OPTARG, NULL, (intptr_t) "" },
 	OPT_BOOL(0, "overwrite-ignore", &overwrite_ignore, N_("update ignored files (default)")),
+	OPT_BOOL(0, "no-verify", &no_verify, N_("bypass commit-msg hook")),
 	OPT_END()
 };
 
@@ -809,6 +810,10 @@ static void prepare_to_commit(struct commit_list *remoteheads)
 		if (launch_editor(git_path_merge_msg(), NULL, NULL))
 			abort_commit(remoteheads, NULL);
 	}
+	if (!no_verify &&
+	    run_commit_hook(0 < option_edit, get_index_file(), "commit-msg",
+			    git_path_merge_msg(), NULL))
+		abort_commit(remoteheads, NULL);
 	read_merge_msg(&msg);
 	strbuf_stripspace(&msg, 0 < option_edit);
 	if (!msg.len)
-- 
2.8.1


           reply	other threads:[~2016-07-26 15:26 UTC|newest]

Thread overview: expand[flat|nested]  mbox.gz  Atom feed
 [parent not found: <alpine.DEB.2.20.1607261614020.14111>]

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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=1469546785-23325-1-git-send-email-orgads@gmail.com \
    --to=orgads@gmail.com \
    --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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).