{"thread":{"id":"42931","subject":"[PATCH v2] merge: Run commit-msg hook","startedAt":"2016-07-26T15:26:50Z","lastAt":"2016-07-26T15:26:50Z","messageCount":1,"participants":["orgads@gmail.com"],"isPatch":true,"patchVersion":2,"patchTotal":null},"messages":[{"id":"292214","messageId":"1469546785-23325-1-git-send-email-orgads@gmail.com","threadId":"42931","inReplyTo":"alpine.DEB.2.20.1607261614020.14111","subject":"[PATCH v2] merge: Run commit-msg hook","fromName":"","fromEmail":"orgads@gmail.com","sentAt":"2016-07-26T15:26:25Z","receivedAt":"2016-07-26T15:26:50Z","isPatch":true,"sender":{"key":"orgads@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1246544?v=4"},"body":"From: Orgad Shaneh <orgads@gmail.com>\n\ncommit-msg is needed to either validate the commit message or edit it.\n\nGerrit for instance uses this hook to append its Change-Id footer. The\nhook is installed on the user's machine, and it is expected to append\nthe footer for each commit that the user creates.\n\nThis is relevant to merge commit just like any other commit. Currently\nthis hook is only called for simple commits, so Gerrit user that tries\nto push a merge commit has to amend it first in order to execute the\nhook that appends the footer.\n\nprepare-commit-msg hook is already called on merge, but commit-msg isn't.\nIt looks like unlike pre-commit not being executed, which was a conscious\ndecision[1], commit-msg was never considered.\n\n[1] http://thread.gmane.org/gmane.comp.version-control.git/151297/focus=151435\n\nSigned-off-by: Orgad Shaneh <orgads@gmail.com>\n---\n Documentation/git-merge.txt | 6 +++++-\n builtin/merge.c             | 7 ++++++-\n 2 files changed, 11 insertions(+), 2 deletions(-)\n\ndiff --git a/Documentation/git-merge.txt b/Documentation/git-merge.txt\nindex b758d55..59508aa 100644\n--- a/Documentation/git-merge.txt\n+++ b/Documentation/git-merge.txt\n@@ -11,7 +11,7 @@ SYNOPSIS\n [verse]\n 'git merge' [-n] [--stat] [--no-commit] [--squash] [--[no-]edit]\n \t[-s <strategy>] [-X <strategy-option>] [-S[<keyid>]]\n-\t[--[no-]allow-unrelated-histories]\n+\t[--[no-]allow-unrelated-histories] [--no-verify]\n \t[--[no-]rerere-autoupdate] [-m <msg>] [<commit>...]\n 'git merge' <msg> HEAD <commit>...\n 'git merge' --abort\n@@ -87,6 +87,10 @@ invocations. The automated message can include the branch description.\n \tAllow the rerere mechanism to update the index with the\n \tresult of auto-conflict resolution if possible.\n \n+--no-verify::\n+\tThis option bypasses the commit-msg hook.\n+\tSee also linkgit:githooks[5].\n+\n --abort::\n \tAbort the current conflict resolution process, and\n \ttry to reconstruct the pre-merge state.\ndiff --git a/builtin/merge.c b/builtin/merge.c\nindex b555a1b..30c03c8 100644\n--- a/builtin/merge.c\n+++ b/builtin/merge.c\n@@ -51,7 +51,7 @@ static const char * const builtin_merge_usage[] = {\n static int show_diffstat = 1, shortlog_len = -1, squash;\n static int option_commit = 1;\n static int option_edit = -1;\n-static int allow_trivial = 1, have_message, verify_signatures;\n+static int allow_trivial = 1, have_message, verify_signatures, no_verify;\n static int overwrite_ignore = 1;\n static struct strbuf merge_msg = STRBUF_INIT;\n static struct strategy **use_strategies;\n@@ -228,6 +228,7 @@ static struct option builtin_merge_options[] = {\n \t{ OPTION_STRING, 'S', \"gpg-sign\", &sign_commit, N_(\"key-id\"),\n \t  N_(\"GPG sign commit\"), PARSE_OPT_OPTARG, NULL, (intptr_t) \"\" },\n \tOPT_BOOL(0, \"overwrite-ignore\", &overwrite_ignore, N_(\"update ignored files (default)\")),\n+\tOPT_BOOL(0, \"no-verify\", &no_verify, N_(\"bypass commit-msg hook\")),\n \tOPT_END()\n };\n \n@@ -809,6 +810,10 @@ static void prepare_to_commit(struct commit_list *remoteheads)\n \t\tif (launch_editor(git_path_merge_msg(), NULL, NULL))\n \t\t\tabort_commit(remoteheads, NULL);\n \t}\n+\tif (!no_verify &&\n+\t    run_commit_hook(0 < option_edit, get_index_file(), \"commit-msg\",\n+\t\t\t    git_path_merge_msg(), NULL))\n+\t\tabort_commit(remoteheads, NULL);\n \tread_merge_msg(&msg);\n \tstrbuf_stripspace(&msg, 0 < option_edit);\n \tif (!msg.len)\n-- \n2.8.1\n\n"}]}