From patchwork Thu Jul 18 22:57:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josh Steadmon X-Patchwork-Id: 11049627 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DCA5614F6 for ; Thu, 18 Jul 2019 22:57:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CC2CB2886E for ; Thu, 18 Jul 2019 22:57:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BFC61288AA; Thu, 18 Jul 2019 22:57:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 945B42886E for ; Thu, 18 Jul 2019 22:57:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391683AbfGRW5q (ORCPT ); Thu, 18 Jul 2019 18:57:46 -0400 Received: from mail-pl1-f202.google.com ([209.85.214.202]:49205 "EHLO mail-pl1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728157AbfGRW5q (ORCPT ); Thu, 18 Jul 2019 18:57:46 -0400 Received: by mail-pl1-f202.google.com with SMTP id 65so14704303plf.16 for ; Thu, 18 Jul 2019 15:57:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=DIajGHrNK3Npd7GQVfTeYgeCH1+xoCJxtXGvMriPIBM=; b=cRrDF24FMWEUpe5N9jneB/YGjXjDWW3P+7OpWVrkFt6thgdQBF76mAidjlC+crCLEw 4UzjmAT57W9IrQxCG1Vba7ktsCpSaPOTTilQ9RRIxFEO7dND90KgOohVt4v4BRIpibg8 TuIHheYloKB1BYNCx+q5eQi/QJl4ZTDTz5W69XEldNOGcncVnR8WzeMQX0fLKpCxxeqo jL6Jmfx33yVJzbPO6jZc7NatPRrI8y/HFQdX02d85Apx6J3WjV/8pjZck77uU6QqCWNf SKnOXJHtIE7/d4ZKSHG+470MKxRCYN9vD+9T5/p4qcQEshx+a7GD+Z7VRmZk1vUpvB5C 55WA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=DIajGHrNK3Npd7GQVfTeYgeCH1+xoCJxtXGvMriPIBM=; b=IiWRweE0N5sjGmBep298C89NK7zmjDE4ruBmA1fdh9VjyRexNxvPv8+80h7MLHjh6x 00HJrOd+RbaJor7MjiB1UFfmXuk6c1tdlYDy8gA5uGk6jHKMytSWU3cPeh0D41Nnum3i te3OeQHB/g+ipKeuvfQcEEZogmaosqz7Rndqv8zwg+T7sX8e3/ahPdR6n5bhhhooKEyD Fw7BKpt+OzwpRccuBntNKb/GZjHO67JZ2MWs76ml0BOfS0eFwh/GJ91SdqPZ4bqeraaI fh+G7SUz8iCmpNZSxxvLr8epKgm6JkEdMF0uMa2z3wwrSSujptAGEN232uKv+N6s++9R ijjg== X-Gm-Message-State: APjAAAXsUU5u8cVlXKoQWSv7sge720kVafj4qTRAeUx6Dp8Aq222WJjc xKOKaDW1wZ01VXd9VsEMsZ8Rh+2hR0/hQ/onDqOjuwmC7y8X1/Yhrjjr7PbwGZ8lqTSOQRpjx9j 8N3T2lbgttqQFZ9jMjDnCA2DayupBzLoIMx+UVrhg3BY77sLBxbhEwLPeJWp9uHE= X-Google-Smtp-Source: APXvYqweFIGnGFJ4KAV9hNshZ2a2H1diYZs53rX0ILRv6ix52rtV3eYLPu1HAoj6dJxw1DY0t0jBm/8jCQND+A== X-Received: by 2002:a63:9a41:: with SMTP id e1mr51161811pgo.210.1563490665443; Thu, 18 Jul 2019 15:57:45 -0700 (PDT) Date: Thu, 18 Jul 2019 15:57:37 -0700 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.22.0.657.g960e92d24f-goog Subject: [PATCH v2 1/4] git-merge: Honor pre-merge hook From: Josh Steadmon To: git@vger.kernel.org Cc: gitster@pobox.com, git@grubix.eu, stefanbeller@gmail.com, martin.agren@gmail.com Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Michael J Gruber git-merge does not honor the pre-commit hook when doing automatic merge commits, and for compatibility reasons this is going to stay. Introduce a pre-merge hook which is called for an automatic merge commit just like pre-commit is called for a non-automatic merge commit (or any other commit). [js: addressed review comments: * clarified that hook should write messages to stderr * only discard the index if the hook is actually present ] Signed-off-by: Michael J Gruber Signed-off-by: Josh Steadmon --- Documentation/githooks.txt | 7 +++++++ builtin/merge.c | 12 ++++++++++++ templates/hooks--pre-merge.sample | 13 +++++++++++++ 3 files changed, 32 insertions(+) create mode 100755 templates/hooks--pre-merge.sample diff --git a/Documentation/githooks.txt b/Documentation/githooks.txt index 786e778ab8..dcc6606d44 100644 --- a/Documentation/githooks.txt +++ b/Documentation/githooks.txt @@ -103,6 +103,13 @@ The default 'pre-commit' hook, when enabled--and with the `hooks.allownonascii` config option unset or set to false--prevents the use of non-ASCII filenames. +pre-merge +~~~~~~~~~ + +This hook is invoked by 'git merge' when doing an automatic merge +commit; it is equivalent to 'pre-commit' for a non-automatic commit +for a merge. + prepare-commit-msg ~~~~~~~~~~~~~~~~~~ diff --git a/builtin/merge.c b/builtin/merge.c index 6e99aead46..5cd7752191 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -816,6 +816,18 @@ static void write_merge_heads(struct commit_list *); static void prepare_to_commit(struct commit_list *remoteheads) { struct strbuf msg = STRBUF_INIT; + const char *index_file = get_index_file(); + + if (run_commit_hook(0 < option_edit, index_file, "pre-merge", NULL)) + abort_commit(remoteheads, NULL); + /* + * Re-read the index as pre-merge hook could have updated it, + * and write it out as a tree. We must do this before we invoke + * the editor and after we invoke run_status above. + */ + if (find_hook("pre-merge")) + discard_cache(); + read_cache_from(index_file); strbuf_addbuf(&msg, &merge_msg); if (squash) BUG("the control must not reach here under --squash"); diff --git a/templates/hooks--pre-merge.sample b/templates/hooks--pre-merge.sample new file mode 100755 index 0000000000..f459b3db44 --- /dev/null +++ b/templates/hooks--pre-merge.sample @@ -0,0 +1,13 @@ +#!/bin/sh +# +# An example hook script to verify what is about to be committed. +# Called by "git merge" with no arguments. The hook should +# exit with non-zero status after issuing an appropriate message to +# stderr if it wants to stop the merge commit. +# +# To enable this hook, rename this file to "pre-merge". + +. git-sh-setup +test -x "$GIT_DIR/hooks/pre-commit" && + exec "$GIT_DIR/hooks/pre-commit" +: From patchwork Thu Jul 18 22:57:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josh Steadmon X-Patchwork-Id: 11049629 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D49F114F6 for ; Thu, 18 Jul 2019 22:57:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C50142886E for ; Thu, 18 Jul 2019 22:57:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B8F73288AA; Thu, 18 Jul 2019 22:57:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 535D92886E for ; Thu, 18 Jul 2019 22:57:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391701AbfGRW5t (ORCPT ); Thu, 18 Jul 2019 18:57:49 -0400 Received: from mail-pl1-f202.google.com ([209.85.214.202]:50699 "EHLO mail-pl1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391694AbfGRW5t (ORCPT ); Thu, 18 Jul 2019 18:57:49 -0400 Received: by mail-pl1-f202.google.com with SMTP id d6so14685592pls.17 for ; Thu, 18 Jul 2019 15:57:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=TwXFnN45bQNJGnf+JFRU3LRku9SErp7XAGlWfvtMdTg=; b=LwuVdUaEwUlgVGPwTqIsRqph3mYCBeK4IA9pyD5+qex4xijADT1kxxk4p5u65xrdTv oPFwHxhbWYJHnNAQtOaC/8rz9cg54R0OXFC08nns29xlDCLthFI0dwC9VM7+Q1nLIeNh ViPYAA2wP6BqtdrKXzEVibxJBcQKKdeuofRapSXTrRNd9W7l9KQlAePzIhxUBDnw/xY/ lBsJnOf7JGlvfE0ggKhqNGxMmn79qQ4kgFB2qdUOW2ys0P/EM7kPRsEDDpJjbKQsD3T7 UtKS6o8x3193AM2LcloZySIXD8skNdLl8BoTt2VvZadPkVsy2nU0QeF86ruzsGaLmLhT 1bsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=TwXFnN45bQNJGnf+JFRU3LRku9SErp7XAGlWfvtMdTg=; b=lO8x8DbO9kL8AqQ0SqirdSccleN2Bh1K75h+RS+G4tjy4kkp6F8HhP20y2ow4y4XjF bgBHeJqGneZdaSevyoMsPBM0KhG2SnIFURSeys+ugy0cvbBsqtKc7z2WSjYz2PVk4dmc tU/ovsd+8WlKQrGhiMrcrdZlRF8p4Z00YdApuN7ZNtFEnNWq64Hzam68S3vbUA4iiWC+ eulRzlJ0GK1B8UFzC2g1NV8zfTs3+SPrd/3EscKM2nlXaKd9OX1XPYGDY6WdX5vgANQ4 S3V0c9X6ppHCfNumwBhel9L81VX5/Xusy841dz+C7FgBiRDFjJ/uTOXbQ7glkdZpjSjb BkeQ== X-Gm-Message-State: APjAAAV3F9zVnZx1d/bOVMfSQFoJR/cy3nWQq7jkPEI6vHeD7aTQA32E xeK9ee8KhKpJjQ8XqKbvP7uYHJW73HdwePDAr43TbuLy/DLliJc3OTVE0cCqFyDiphUU6UfUpYP FR+pnpPd4d4tBa3wFF6iyeeG1EtjqiY0YY7afa2pVojzI73UHFrFfbLvexAC53dw= X-Google-Smtp-Source: APXvYqy7pcyaFm4U0xnFNzViCpGMh8vNizEGf1CdwYNLUgWz7iKNhG7tGZk1CFAzgkKlym4vecN0+OrKA/PuRA== X-Received: by 2002:a63:f401:: with SMTP id g1mr51705764pgi.314.1563490668072; Thu, 18 Jul 2019 15:57:48 -0700 (PDT) Date: Thu, 18 Jul 2019 15:57:38 -0700 In-Reply-To: Message-Id: <36406a85beaf63d356fa9818463f73140acf1ec9.1563490164.git.steadmon@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.22.0.657.g960e92d24f-goog Subject: [PATCH v2 2/4] merge: do no-verify like commit From: Josh Steadmon To: git@vger.kernel.org Cc: gitster@pobox.com, git@grubix.eu, stefanbeller@gmail.com, martin.agren@gmail.com Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Michael J Gruber f8b863598c ("builtin/merge: honor commit-msg hook for merges", 2017-09-07) introduced the no-verify flag to merge for bypassing the commit-msg hook, though in a different way from the implementation in commit.c. Change the implementation in merge.c to be the same as in commit.c so that both do the same in the same way. This also changes the output of "git merge --help" to be more clear that the hook return code is respected by default. [js: reworded commit message, and moved documentation changes from patch 3/4 to this commit.] Signed-off-by: Michael J Gruber Signed-off-by: Josh Steadmon --- Documentation/git-merge.txt | 2 +- Documentation/merge-options.txt | 4 ++++ builtin/merge.c | 6 +++--- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Documentation/git-merge.txt b/Documentation/git-merge.txt index c01cfa6595..f71ed1d0f9 100644 --- a/Documentation/git-merge.txt +++ b/Documentation/git-merge.txt @@ -10,7 +10,7 @@ SYNOPSIS -------- [verse] 'git merge' [-n] [--stat] [--no-commit] [--squash] [--[no-]edit] - [-s ] [-X ] [-S[]] + [--no-verify] [-s ] [-X ] [-S[]] [--[no-]allow-unrelated-histories] [--[no-]rerere-autoupdate] [-m ] [-F ] [...] 'git merge' --abort diff --git a/Documentation/merge-options.txt b/Documentation/merge-options.txt index 79a00d2a4a..d6a9f4b96f 100644 --- a/Documentation/merge-options.txt +++ b/Documentation/merge-options.txt @@ -105,6 +105,10 @@ option can be used to override --squash. + With --squash, --commit is not allowed, and will fail. +--no-verify:: + This option bypasses the pre-merge and commit-msg hooks. + See also linkgit:githooks[5]. + -s :: --strategy=:: Use the given merge strategy; can be supplied more than diff --git a/builtin/merge.c b/builtin/merge.c index 5cd7752191..5bbef203f3 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -81,7 +81,7 @@ static int show_progress = -1; static int default_to_upstream = 1; static int signoff; static const char *sign_commit; -static int verify_msg = 1; +static int no_verify; static struct strategy all_strategy[] = { { "recursive", DEFAULT_TWOHEAD | NO_TRIVIAL }, @@ -287,7 +287,7 @@ static struct option builtin_merge_options[] = { 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, "signoff", &signoff, N_("add Signed-off-by:")), - OPT_BOOL(0, "verify", &verify_msg, N_("verify commit-msg hook")), + OPT_BOOL(0, "no-verify", &no_verify, N_("bypass commit-msg hook")), OPT_END() }; @@ -854,7 +854,7 @@ static void prepare_to_commit(struct commit_list *remoteheads) abort_commit(remoteheads, NULL); } - if (verify_msg && run_commit_hook(0 < option_edit, get_index_file(), + if (!no_verify && run_commit_hook(0 < option_edit, get_index_file(), "commit-msg", git_path_merge_msg(the_repository), NULL)) abort_commit(remoteheads, NULL); From patchwork Thu Jul 18 22:57:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josh Steadmon X-Patchwork-Id: 11049631 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DEF1914DB for ; Thu, 18 Jul 2019 22:57:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CED3B28884 for ; Thu, 18 Jul 2019 22:57:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C1C0D2886E; Thu, 18 Jul 2019 22:57:53 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 645562886E for ; Thu, 18 Jul 2019 22:57:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391708AbfGRW5w (ORCPT ); Thu, 18 Jul 2019 18:57:52 -0400 Received: from mail-vk1-f202.google.com ([209.85.221.202]:43488 "EHLO mail-vk1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391694AbfGRW5v (ORCPT ); Thu, 18 Jul 2019 18:57:51 -0400 Received: by mail-vk1-f202.google.com with SMTP id j140so13144681vke.10 for ; Thu, 18 Jul 2019 15:57:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=4cU0LLDVKLhVe4AeBhhuQQwQ7kiukvWT8gMlsJwTZcY=; b=HDskbwvByb6O3sV3WNYvQ50c8xgJuhZcBOAeBNC/H50j9a4ifptZZU/3U5355NRS9V 5JAKCa8Ls/XJfK40M9tTLBr8hP/9p/asuAPvsKL6shr/xY4jbLj2ukyDFmLSMIHy//IQ dxBWwmK/tgbjdirYtMWuWGLgs7oyUd1DwI30swUZc07QVXdQncpNGESlQAsohlyqLEN3 EGVwhEOm7W5mHdWdiAXuHsiNJWRbAipev3drwFPaqyUFs0cFdts7spbRvdEcZGo/qGu6 pe/dqy8GlVI5mB95wRw+/ndB0ntF7G0oZnJTVe7hLsEXfnvbDyqXn4FjDJ23MaEq1fBo tXgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=4cU0LLDVKLhVe4AeBhhuQQwQ7kiukvWT8gMlsJwTZcY=; b=CsX/06Grn2l4cK9D2RI+TExYmalY+d+qX5Kc9MahnUxON6Ev5IfBZvA6JOJdbjE/1B yuxMsqHFgI8BlYe7TFBn9bhHS/3ChRxXFPdASEdkgDmd4x7WkW0kuD5wHMhwq25WI/CV ddnT/V+KPHVAy+mVXBcwbft4bctJ6qHafK/2LEMT6N2xZAwnjRUA0IgKiOh6rfnBgzXE 6t+pC848AZOTLC7+QTr5BA2Xr2KkOg9gWzhiVlsW9DFS5QpFaUj9AASnDhoDiUPHOKvU jFwNjLgUS81quj3ZfET6SMlRSyeT1gneuiptcpzCfYMQzj44BhM5jpJnj6HXI3FfAaJU csGQ== X-Gm-Message-State: APjAAAX56EDDVsYQfNEz2qbZst21+sBUt48zRlgybLvPy6e/T4R1ionH VoHFPaa8a4rJGveGPkR889MjpwJnH5AbfhzhjVETdrBmB4Z+AhZPQEsDa+HG1N8+DhUjYAhLkEG lOrPn27wtS+F0YbYElRm/X5pasBT79ngTFhS47k2eAcnj+X6A3eVSC/zvIqrPp/E= X-Google-Smtp-Source: APXvYqylgCDtyqwtM73MejpCmlP0NAG2c0BLwYNrPgeOecTLbB4gzQt7yilT5HO28mZ1mlNQE92D8N1ToAaAyQ== X-Received: by 2002:ac5:c907:: with SMTP id t7mr19537936vkl.30.1563490670481; Thu, 18 Jul 2019 15:57:50 -0700 (PDT) Date: Thu, 18 Jul 2019 15:57:39 -0700 In-Reply-To: Message-Id: <2440ad35e420db868596435dea3d634e37dbe671.1563490164.git.steadmon@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.22.0.657.g960e92d24f-goog Subject: [PATCH v2 3/4] merge: --no-verify to bypass pre-merge hook From: Josh Steadmon To: git@vger.kernel.org Cc: gitster@pobox.com, git@grubix.eu, stefanbeller@gmail.com, martin.agren@gmail.com Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Michael J Gruber Analogous to commit, introduce a '--no-verify' option which bypasses the pre-merge hook. The shorthand '-n' is taken by the (non-existing) '--no-stat' already. [js: cleaned up trailing whitespace, moved some documentation changes from this commit to 2/4.] Signed-off-by: Michael J Gruber Signed-off-by: Josh Steadmon --- Documentation/githooks.txt | 2 +- builtin/merge.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Documentation/githooks.txt b/Documentation/githooks.txt index dcc6606d44..6a93478dcf 100644 --- a/Documentation/githooks.txt +++ b/Documentation/githooks.txt @@ -108,7 +108,7 @@ pre-merge This hook is invoked by 'git merge' when doing an automatic merge commit; it is equivalent to 'pre-commit' for a non-automatic commit -for a merge. +for a merge, and can be bypassed with the `--no-verify` option. prepare-commit-msg ~~~~~~~~~~~~~~~~~~ diff --git a/builtin/merge.c b/builtin/merge.c index 5bbef203f3..5ed3472c84 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -287,7 +287,7 @@ static struct option builtin_merge_options[] = { 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, "signoff", &signoff, N_("add Signed-off-by:")), - OPT_BOOL(0, "no-verify", &no_verify, N_("bypass commit-msg hook")), + OPT_BOOL(0, "no-verify", &no_verify, N_("bypass pre-merge and commit-msg hooks")), OPT_END() }; @@ -818,7 +818,7 @@ static void prepare_to_commit(struct commit_list *remoteheads) struct strbuf msg = STRBUF_INIT; const char *index_file = get_index_file(); - if (run_commit_hook(0 < option_edit, index_file, "pre-merge", NULL)) + if (!no_verify && run_commit_hook(0 < option_edit, index_file, "pre-merge", NULL)) abort_commit(remoteheads, NULL); /* * Re-read the index as pre-merge hook could have updated it, From patchwork Thu Jul 18 22:57:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josh Steadmon X-Patchwork-Id: 11049633 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5593314F6 for ; Thu, 18 Jul 2019 22:57:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 44DF92886E for ; Thu, 18 Jul 2019 22:57:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 391EA288AA; Thu, 18 Jul 2019 22:57:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C2A1A2886E for ; Thu, 18 Jul 2019 22:57:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391716AbfGRW5y (ORCPT ); Thu, 18 Jul 2019 18:57:54 -0400 Received: from mail-qk1-f201.google.com ([209.85.222.201]:52404 "EHLO mail-qk1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728157AbfGRW5y (ORCPT ); Thu, 18 Jul 2019 18:57:54 -0400 Received: by mail-qk1-f201.google.com with SMTP id r200so24655945qke.19 for ; Thu, 18 Jul 2019 15:57:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=hr9nqW2VWjZHPz6vEmxxSuuVj7+YooS/haM098tyz+4=; b=c0o0A7kVdu912T/THBnmOHB1JgDWvPDuTtYomZPDeFMdZp+oC1NKREkPctuao2uaRN /bnt2AQXLiILS8tJI6xAMdUa8VKa4Y/GZ5ZGG3w1s4dHcwuLMFKKJPvDMMt3mNwEWyXS BNIIUQQy6FAWZC/QHEr1aXqwO15618eSJrbUUCZTZqZy5OgO+KICHfr0E6oTOlOklqGG Se8LvmbOMARr2VDcvy15Q+bnFnULXURFXx+xEaYuJ51Ld3sn9E/we9kLK9qDgq1P+Qm+ zXlPf9edSYUsMWq5Xg34qYqJePm1r9acmdPG3EpnPvfdzNL+0rC2jRtomUc6VBM5jwQI FpUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=hr9nqW2VWjZHPz6vEmxxSuuVj7+YooS/haM098tyz+4=; b=m0/q1LF2o3/NOlN7rUrra0EE05WGZdhu76rcuVsByL9yfPqt6coJh2KNjkyQymyNuQ tG1veHWuRMvKrrKw3FXFYh3JNuLJpUSlmzoOXietcotTcZ/RG6rb0zG6tMFtucgyyCAv gi6ggeZTlx2BM+dQukeb5tx9zrdQhM7X4apJU9Kdg3tkXgQx7CNTj0qHc/Fso+h4CW7N xo6QIJ7/0NIHlXFl+OkDwop+6C9yhNt8X/Iqxxqtk+uUEOINi2j2sI59ZTIXH51XVM/i HTYLA4iVJtQZcIhO1Pcq+ON8wGHP/14fGTF+qeArS6rXj0fbXY+YwAIhWI6IjqKz3IAR lKGg== X-Gm-Message-State: APjAAAVSGjlWrC0wJmM7kejAAMW6ZKquKPNnCHlZTZKCkvBTDuY1WHfL /hEcSfjzgg+qrOwQjGR+PqR4WUmxcQFrfhpsvuF8C1U6KaY/KUZC4IZDqein6B/zYRxe8bJCRnV LbXhkyr7+E2DFlKEJLvdcCadx4J3UyZv8EvJg+rZ+CQlzaF0QyRGPb9JE/kyAuFw= X-Google-Smtp-Source: APXvYqwTbdM0P1rX/MsHRLNdoEM2ObWxReU71ZCibUyb0IjJvDTaf6X/mt6KjvaUB0JSnumgBABEUIq6xs8EMg== X-Received: by 2002:a0c:e001:: with SMTP id j1mr35396820qvk.110.1563490673121; Thu, 18 Jul 2019 15:57:53 -0700 (PDT) Date: Thu, 18 Jul 2019 15:57:40 -0700 In-Reply-To: Message-Id: <69dc3696e715f9be9e545e0142244e16bdd489cc.1563490164.git.steadmon@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.22.0.657.g960e92d24f-goog Subject: [PATCH v2 4/4] t7503: add tests for pre-merge-hook From: Josh Steadmon To: git@vger.kernel.org Cc: gitster@pobox.com, git@grubix.eu, stefanbeller@gmail.com, martin.agren@gmail.com Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Michael J Gruber Add tests which make sure that the pre-merge-hook is called when present, allows/disallows merge commits depending on its return value and is suppressed by "--no-verify". [js: renamed test as suggested in review comments] Signed-off-by: Michael J Gruber Signed-off-by: Josh Steadmon --- ...> t7503-pre-commit-and-pre-merge-hooks.sh} | 66 ++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) rename t/{t7503-pre-commit-hook.sh => t7503-pre-commit-and-pre-merge-hooks.sh} (67%) diff --git a/t/t7503-pre-commit-hook.sh b/t/t7503-pre-commit-and-pre-merge-hooks.sh similarity index 67% rename from t/t7503-pre-commit-hook.sh rename to t/t7503-pre-commit-and-pre-merge-hooks.sh index 984889b39d..36ae87f7ef 100755 --- a/t/t7503-pre-commit-hook.sh +++ b/t/t7503-pre-commit-and-pre-merge-hooks.sh @@ -1,9 +1,22 @@ #!/bin/sh -test_description='pre-commit hook' +test_description='pre-commit and pre-merge hooks' . ./test-lib.sh +test_expect_success 'root commit' ' + + echo "root" > file && + git add file && + git commit -m "zeroth" && + git checkout -b side && + echo "foo" > foo && + git add foo && + git commit -m "make it non-ff" && + git checkout master + +' + test_expect_success 'with no hook' ' echo "foo" > file && @@ -12,6 +25,14 @@ test_expect_success 'with no hook' ' ' +test_expect_success 'with no hook (merge)' ' + + git checkout side && + git merge -m "merge master" master && + git checkout master + +' + test_expect_success '--no-verify with no hook' ' echo "bar" > file && @@ -20,15 +41,25 @@ test_expect_success '--no-verify with no hook' ' ' +test_expect_success '--no-verify with no hook (merge)' ' + + git checkout side && + git merge --no-verify -m "merge master" master && + git checkout master + +' + # now install hook that always succeeds HOOKDIR="$(git rev-parse --git-dir)/hooks" HOOK="$HOOKDIR/pre-commit" +MERGEHOOK="$HOOKDIR/pre-merge" mkdir -p "$HOOKDIR" cat > "$HOOK" <> file && @@ -46,11 +85,20 @@ test_expect_success '--no-verify with succeeding hook' ' ' +test_expect_success '--no-verify with succeeding hook (merge)' ' + + git checkout side && + git merge --no-verify -m "merge master" master && + git checkout master + +' + # now a hook that fails cat > "$HOOK" <