From patchwork Wed Aug 7 18:57:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josh Steadmon X-Patchwork-Id: 11082565 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 74BDD13B1 for ; Wed, 7 Aug 2019 18:57:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6692426BE9 for ; Wed, 7 Aug 2019 18:57:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5B21A28A60; Wed, 7 Aug 2019 18:57:28 +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 E85F528A61 for ; Wed, 7 Aug 2019 18:57:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389421AbfHGS5Z (ORCPT ); Wed, 7 Aug 2019 14:57:25 -0400 Received: from mail-pl1-f201.google.com ([209.85.214.201]:49618 "EHLO mail-pl1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388849AbfHGS5Z (ORCPT ); Wed, 7 Aug 2019 14:57:25 -0400 Received: by mail-pl1-f201.google.com with SMTP id 65so53554137plf.16 for ; Wed, 07 Aug 2019 11:57:25 -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=8pWHU0VX2sxqhaQaw0+jKNS+pFgW2uare0LdAauOU/Y=; b=tSnRN223xCN8QX5DUe+uD6rWc+47qe5StnGJAwFpLufG4mKGbBXoTiUe4ed698tyrd vVy8o2hprTlJWNG2bc4vFb2kC5keM9/JhA0iLMVlBz5GrE87v4XgQS19PYluF1ngk053 X/YkIb7obOm+SGBOgABMt7nwkFDrOSOm8lHPaZtx/LHiSgii3+clEGPo+i+sMgBjEkjD vs4Z3bOjrEyxGJHZQhvhjIDN3XduBv6v2vs6mjsBxDM6/eAd5Hm5+vGIXZl7M1jgiWUl 6QCxjuNn0M1qQpkMPwvmb+9a3Xn3UxGybzpXfEbuMb3klT2PvW5pH8MLPOdUtw4yYYsH tRzg== 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=8pWHU0VX2sxqhaQaw0+jKNS+pFgW2uare0LdAauOU/Y=; b=N+5ZvvUuAMas6B22QFNpLLveSOeiZxqroQAi6jZb2Jk9kH7LRSVxPgL1m786v62B70 qMsbdxycO6n23RIMGFuxIQZ7WY8JCi9koMosrAdtdMcvmYKjtK7W9OWyHf6LHgF4DuC5 PqkPSL0BYA81nEHJirEVqa2GEaQ2ZSBEkQ9xcsBrczIdQ0FnCrATtGo24A2/3ua1AX19 pUOQEFpNsVQd+Ov5vNfyBN7xQEJ3QtU26YDYu/AslGKmwN7++quvFGlFDhC1DLB4xC0E wupyVYyOGVgVF8qRxXxK9TGHtZSAhItPVOfQJAL75b/zLHdJdx4gNNSZKsgz+dy7ceZN BFYQ== X-Gm-Message-State: APjAAAVVWKg7EvgK2eol7CUzVpFyKR4txmVzV+2ELSQjwYel+9Jskvgx PCekUZ/dFLGL4WH2Wmx0laNSvqyggwZKlEwPzjrQKTqgT5qpLCZzZA6OAii62pbE8OAIYbtjZj5 Py1Cs0Ka5D2jQ8m2fAHYi7j4KzYUqgUQNvWog/FJlwF9yHCLhAjefmVsgpsxkueQ= X-Google-Smtp-Source: APXvYqxNu9GK6yMK9zYgmBE+RTc3ZN0CvwhhkIycwLrsVloEtBrwWTl0Z2q/2NKvyGpZSegncEl8I+lS++yxAw== X-Received: by 2002:a63:29c4:: with SMTP id p187mr9157667pgp.330.1565204244671; Wed, 07 Aug 2019 11:57:24 -0700 (PDT) Date: Wed, 7 Aug 2019 11:57:06 -0700 In-Reply-To: Message-Id: <02a97eb369e7f99c426a4d8fd5efd2c9d1af1e5f.1565203880.git.steadmon@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.22.0.770.g0f2c4a37fd-goog Subject: [PATCH v5 2/4] merge: do no-verify like commit From: Josh Steadmon To: git@vger.kernel.org Cc: gitster@pobox.com, git@grubix.eu, 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 * squashed documentation changes from original series' patch 3/4 ] 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 01fd52dc70..092529c619 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' (--continue | --abort | --quit) 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 e2ccbc44e2..4425a7a12e 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() }; @@ -842,7 +842,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 Wed Aug 7 18:57:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Josh Steadmon X-Patchwork-Id: 11082567 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 E90A313B1 for ; Wed, 7 Aug 2019 18:57:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D71EF26BE9 for ; Wed, 7 Aug 2019 18:57:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CB9D728A61; Wed, 7 Aug 2019 18:57:30 +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 05E1026BE9 for ; Wed, 7 Aug 2019 18:57:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389424AbfHGS53 (ORCPT ); Wed, 7 Aug 2019 14:57:29 -0400 Received: from mail-qk1-f202.google.com ([209.85.222.202]:36985 "EHLO mail-qk1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388849AbfHGS52 (ORCPT ); Wed, 7 Aug 2019 14:57:28 -0400 Received: by mail-qk1-f202.google.com with SMTP id d203so1795267qke.4 for ; Wed, 07 Aug 2019 11:57:28 -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:content-transfer-encoding; bh=XBuIcQkcjZziHviF1FqOsbl0fxTgpxuscXgB1S4/zO4=; b=Fu26ya2/O96TT5haWyEGiId/vsUBu7uaiqFis6fyc2PNzZKBmzE9C4jUVqhjnH3qYe 0Xhsugnv4p9Xg6YCWkRC0msT9a9Ylr2H9HWOOfPgTCCtaPzrq++OZY9s6+z1vyCNqu8M xBFMlhtSaUsisEh/O3Oa8xjmFR6oRFo5f/qzx22JwPdnyvYvc7/g45VgtEMPD1V/OYFB BBf5pLvNmjdNrNMVF8QOmF87ZwAQxrv1DHckZKilC9T/XbCcHgdUk2O2LKBn2Zhtb/vY KTa6bqMelDVPmugkVsgKQbDpRhjGGrVikNDQ12styszq2sjlTm9vxTCJsqMGbRin0veJ CeUA== 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:content-transfer-encoding; bh=XBuIcQkcjZziHviF1FqOsbl0fxTgpxuscXgB1S4/zO4=; b=XgCSxLafTqwl86JxVuTx4o1F8sKPKnwJBGBx2+C7j8dux/EEjA3bL2+gjH8jCRq9Lc RCKHPOLBKezVx88ra6Y+yL3EAy7UG7Ji4U3yF8pIAFC5hoT/tTo3D+9Ad9M0vsV9C2O5 kPSPEYmUDbQis1aSJJg8BdcU/oqGk2SzsHbXMRscfngrfwTf3KjKD3aoe5rVRtTyefUN aGI09xOycSff8JbZsqD71vwt0olkVl1x2CbVh6MWClMh9fmTfajXjtnbD9kvzNW/7jMf DJBWDu8wUclDn1lMNZQOJGSjI0eUwegs2QM8VGKCl4KS5NcQWgLa8WYtMgK4n9mZy0Vf 2bIg== X-Gm-Message-State: APjAAAU0rvFz/6RhT6JNHypl4ggao6+WEkotlkw9/QxcPxfWEGKJWwww ntbodtK/rPFpGNzKQZo/YWOxIiUds9IoX94toGTqdfBqwcjPdLOUjy1ZniFsPtAaBhmy8WJ/VKl xVDvQ9ZdiwFuyjnYHyuobHOHYH1Bd4Is2xVaLTaDpQFthl8+p/ZsC1l0u7ay9Ygw= X-Google-Smtp-Source: APXvYqwmZ3RRb4OUei5SOuNKJvkoZHGwaYYaIfpwewfI6ct6+NI1+0UumBk9VX5QHUiqUd839oMHOSKHxOF1lA== X-Received: by 2002:a37:c40b:: with SMTP id d11mr8865045qki.78.1565204247471; Wed, 07 Aug 2019 11:57:27 -0700 (PDT) Date: Wed, 7 Aug 2019 11:57:07 -0700 In-Reply-To: Message-Id: <2d41e0ff79045a3a0abf83d8f580e958023fb331.1565203880.git.steadmon@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.22.0.770.g0f2c4a37fd-goog Subject: [PATCH v5 3/4] git-merge: honor pre-merge-commit hook From: Josh Steadmon To: git@vger.kernel.org Cc: gitster@pobox.com, git@grubix.eu, 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-commit 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: * renamed hook from "pre-merge" to "pre-merge-commit" * only discard the index if the hook is actually present * expanded githooks documentation entry * clarified that hook should write messages to stderr * squashed test changes from the original series' patch 4/4 * modified tests to follow new pattern from this series' patch 1/4 * added a test case for non-executable merge hooks * added a test case for failed merges * when testing that the merge hook did not run, make sure we actually have a merge to perform (by resetting the "side" branch to its original state). * reworded commit message ] Improved-by: Martin Ågren Signed-off-by: Michael J Gruber Signed-off-by: Martin Ågren Signed-off-by: Josh Steadmon --- Documentation/githooks.txt | 21 +++++ builtin/merge.c | 12 +++ ...-pre-commit-and-pre-merge-commit-hooks.sh} | 84 ++++++++++++++++++- templates/hooks--pre-merge-commit.sample | 13 +++ 4 files changed, 129 insertions(+), 1 deletion(-) rename t/{t7503-pre-commit-hook.sh => t7503-pre-commit-and-pre-merge-commit-hooks.sh} (63%) create mode 100755 templates/hooks--pre-merge-commit.sample diff --git a/Documentation/githooks.txt b/Documentation/githooks.txt index 82cd573776..d9da474fb0 100644 --- a/Documentation/githooks.txt +++ b/Documentation/githooks.txt @@ -103,6 +103,27 @@ 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-commit +~~~~~~~~~~~~~~~~ + +This hook is invoked by linkgit:git-merge[1]. It takes no parameters, and is +invoked after the merge has been carried out successfully and before +obtaining the proposed commit log message to +make a commit. Exiting with a non-zero status from this script +causes the `git merge` command to abort before creating a commit. + +The default 'pre-merge-commit' hook, when enabled, runs the +'pre-commit' hook, if the latter is enabled. + +This hook is invoked with the environment variable +`GIT_EDITOR=:` if the command will not bring up an editor +to modify the commit message. + +If the merge cannot be carried out automatically, the conflicts +need to be resolved and the result committed separately (see +linkgit:git-merge[1]). At that point, this hook will not be executed, +but the 'pre-commit' hook will, if it is enabled. + prepare-commit-msg ~~~~~~~~~~~~~~~~~~ diff --git a/builtin/merge.c b/builtin/merge.c index 4425a7a12e..bf0ae68c40 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-commit", NULL)) + abort_commit(remoteheads, NULL); + /* + * Re-read the index as pre-merge-commit 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-commit")) + 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/t/t7503-pre-commit-hook.sh b/t/t7503-pre-commit-and-pre-merge-commit-hooks.sh similarity index 63% rename from t/t7503-pre-commit-hook.sh rename to t/t7503-pre-commit-and-pre-merge-commit-hooks.sh index 6aa83204c2..7a5434c7ab 100755 --- a/t/t7503-pre-commit-hook.sh +++ b/t/t7503-pre-commit-and-pre-merge-commit-hooks.sh @@ -1,11 +1,12 @@ #!/bin/sh -test_description='pre-commit hook' +test_description='pre-commit and pre-merge-commit hooks' . ./test-lib.sh HOOKDIR="$(git rev-parse --git-dir)/hooks" PRECOMMIT="$HOOKDIR/pre-commit" +PREMERGE="$HOOKDIR/pre-merge-commit" # Prepare sample scripts that write their $0 to actual_hooks test_expect_success 'sample script setup' ' @@ -34,6 +35,30 @@ test_expect_success 'sample script setup' ' EOF ' +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 branch side-orig side && + git checkout master +' + +test_expect_success 'setup conflicting branches' ' + test_when_finished "git checkout master" && + git checkout -b conflicting-a master && + echo a >conflicting && + git add conflicting && + git commit -m conflicting-a && + git checkout -b conflicting-b master && + echo b >conflicting && + git add conflicting && + git commit -m conflicting-b +' + test_expect_success 'with no hook' ' test_when_finished "rm -f actual_hooks" && echo "foo" >file && @@ -42,6 +67,15 @@ test_expect_success 'with no hook' ' test_path_is_missing actual_hooks ' +test_expect_success 'with no hook (merge)' ' + test_when_finished "rm -f actual_hooks" && + git branch -f side side-orig && + git checkout side && + git merge -m "merge master" master && + git checkout master && + test_path_is_missing actual_hooks +' + test_expect_success '--no-verify with no hook' ' test_when_finished "rm -f actual_hooks" && echo "bar" >file && @@ -60,6 +94,34 @@ test_expect_success 'with succeeding hook' ' test_cmp expected_hooks actual_hooks ' +test_expect_success 'with succeeding hook (merge)' ' + test_when_finished "rm -f \"$PREMERGE\" expected_hooks actual_hooks" && + cp "$HOOKDIR/success.sample" "$PREMERGE" && + echo "$PREMERGE" >expected_hooks && + git checkout side && + git merge -m "merge master" master && + git checkout master && + test_cmp expected_hooks actual_hooks +' + +test_expect_success 'automatic merge fails; both hooks are available' ' + test_when_finished "rm -f \"$PREMERGE\" \"$PRECOMMIT\"" && + test_when_finished "rm -f expected_hooks actual_hooks" && + test_when_finished "git checkout master" && + cp "$HOOKDIR/success.sample" "$PREMERGE" && + cp "$HOOKDIR/success.sample" "$PRECOMMIT" && + + git checkout conflicting-a && + test_must_fail git merge -m "merge conflicting-b" conflicting-b && + test_path_is_missing actual_hooks && + + echo "$PRECOMMIT" >expected_hooks && + echo a+b >conflicting && + git add conflicting && + git commit -m "resolve conflict" && + test_cmp expected_hooks actual_hooks +' + test_expect_success '--no-verify with succeeding hook' ' test_when_finished "rm -f \"$PRECOMMIT\" actual_hooks" && cp "$HOOKDIR/success.sample" "$PRECOMMIT" && @@ -88,6 +150,16 @@ test_expect_success '--no-verify with failing hook' ' test_path_is_missing actual_hooks ' +test_expect_success 'with failing hook (merge)' ' + test_when_finished "rm -f \"$PREMERGE\" expected_hooks actual_hooks" && + cp "$HOOKDIR/fail.sample" "$PREMERGE" && + echo "$PREMERGE" >expected_hooks && + git checkout side && + test_must_fail git merge -m "merge master" master && + git checkout master && + test_cmp expected_hooks actual_hooks +' + test_expect_success POSIXPERM 'with non-executable hook' ' test_when_finished "rm -f \"$PRECOMMIT\" actual_hooks" && cp "$HOOKDIR/non-exec.sample" "$PRECOMMIT" && @@ -106,6 +178,16 @@ test_expect_success POSIXPERM '--no-verify with non-executable hook' ' test_path_is_missing actual_hooks ' +test_expect_success POSIXPERM 'with non-executable hook (merge)' ' + test_when_finished "rm -f \"$PREMERGE\" actual_hooks" && + cp "$HOOKDIR/non-exec.sample" "$PREMERGE" && + git branch -f side side-orig && + git checkout side && + git merge -m "merge master" master && + git checkout master && + test_path_is_missing actual_hooks +' + test_expect_success 'with hook requiring GIT_PREFIX' ' test_when_finished "rm -rf \"$PRECOMMIT\" expected_hooks actual_hooks success" && cp "$HOOKDIR/require-prefix.sample" "$PRECOMMIT" && diff --git a/templates/hooks--pre-merge-commit.sample b/templates/hooks--pre-merge-commit.sample new file mode 100755 index 0000000000..399eab1924 --- /dev/null +++ b/templates/hooks--pre-merge-commit.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-commit". + +. git-sh-setup +test -x "$GIT_DIR/hooks/pre-commit" && + exec "$GIT_DIR/hooks/pre-commit" +: From patchwork Wed Aug 7 18:57:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Josh Steadmon X-Patchwork-Id: 11082569 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 E99EB13B1 for ; Wed, 7 Aug 2019 18:57:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DA0C926BE9 for ; Wed, 7 Aug 2019 18:57:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CD35528A61; Wed, 7 Aug 2019 18:57:32 +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 3966126BE9 for ; Wed, 7 Aug 2019 18:57:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389427AbfHGS5b (ORCPT ); Wed, 7 Aug 2019 14:57:31 -0400 Received: from mail-pl1-f202.google.com ([209.85.214.202]:37700 "EHLO mail-pl1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388849AbfHGS5a (ORCPT ); Wed, 7 Aug 2019 14:57:30 -0400 Received: by mail-pl1-f202.google.com with SMTP id n4so53057215plp.4 for ; Wed, 07 Aug 2019 11:57:30 -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:content-transfer-encoding; bh=tg7/n0F05+e3DGZh+6SpWaJFccmjnkwj17Aa/5mkLz8=; b=UTUB5p+r9aKDznAsnk4gMeTyA2ib0bw3+LD0GGcbY0N3so8LbLOdVw7z70UlqtEE9k y9aNyffYjSgtY3OAWZbbyjjeC0uTbyJm5ZqzHR9jYGXEXKJNTt6K2teSNtYKQIAkP7kW AQbx6ZbT+mxdTkiX9ZpbbG0HJ6aDH/wGD53LpCc4cXAgFxlJCqP7YFzvEiebOgZI22og zutLsY/YSZ57IKEnnFfR4v66uzzKwKVbAe7ZYtGWvCIMhikf17/9WJ5HldlQ1xoX3zF9 iU4RcX7uwMWDiTS9w5UF7Y1Qmj4eWHjQGfHh23Gl9jhz5oKuV14SKFuX1/Oa7IfxLl9f LaXA== 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:content-transfer-encoding; bh=tg7/n0F05+e3DGZh+6SpWaJFccmjnkwj17Aa/5mkLz8=; b=Z3genxVcSmsJOn6NseH4zW4ejlbkNpTid0am58cE5PbhJvAt9tzE7XtaAjXn3sgwkn Vf6I+Qe55LJR6KGaxz77ktlUAhlXCqx+dR2DSgTw4sG3ZhEX5Pi+NOshohxwcAUEFO7V ynzRTc98AWfeJ9a2Zj5v35P4Spj/vtCa3FGgTuW+yg89UWDhnIuUosp61vFr6+wf/URk xn54qNgze8ne9CiVM6aciiJl+VfC8SdrQfU+no3VUJsnC++/o8yuMUBUab8wEleP/YXP 3W+nArTy+IMfcHH3/k/yg/SQzFgUyGzYAV3XvBBfhSfveOpBsh94SX094LTKld2JP2QM njug== X-Gm-Message-State: APjAAAVRUoKOdKun3Ir2qhUactAWh5pDKwhebX562yPA6kVMlq1Ny0P2 6YOalF9BWYB2WUaF1YIc2x2jRo9JouI+Bt/PdZEf9C3S9O4aNq5THSPums5I8CvonPXsnj574eL H0zDuqVNwTtYGosm/nAYse/i3rIDs/xSPIfWoMTyNRjxIgXBg7iIOMRKD/H2hlGA= X-Google-Smtp-Source: APXvYqxGRvjfeTBlPjfKnZVogRRV7J4Fk69W+boSXnmj1KYKOQ9tXvy/suoxoFKw0PlJsdIjAbXTxd/M5gDoJg== X-Received: by 2002:a63:d84e:: with SMTP id k14mr9006182pgj.234.1565204249776; Wed, 07 Aug 2019 11:57:29 -0700 (PDT) Date: Wed, 7 Aug 2019 11:57:08 -0700 In-Reply-To: Message-Id: <7b81e2717f739a92dea10eaf570407c742d30533.1565203880.git.steadmon@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.22.0.770.g0f2c4a37fd-goog Subject: [PATCH v5 4/4] merge: --no-verify to bypass pre-merge-commit hook From: Josh Steadmon To: git@vger.kernel.org Cc: gitster@pobox.com, git@grubix.eu, 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-commit hook. The shorthand '-n' is taken by '--no-stat' already. [js: * reworded commit message to reflect current state of --no-stat flag and new hook name * fixed flag documentation to reflect new hook name * cleaned up trailing whitespace * squashed test changes from the original series' patch 4/4 * modified tests to follow pattern from this series' patch 1/4 * added a test case for --no-verify with non-executable hook * when testing that the merge hook did not run, make sure we actually have a merge to perform (by resetting the "side" branch to its original state). ] Improved-by: Martin Ågren Signed-off-by: Michael J Gruber Signed-off-by: Martin Ågren Signed-off-by: Josh Steadmon --- Documentation/githooks.txt | 3 +- builtin/merge.c | 4 +- ...3-pre-commit-and-pre-merge-commit-hooks.sh | 39 +++++++++++++++++++ 3 files changed, 43 insertions(+), 3 deletions(-) diff --git a/Documentation/githooks.txt b/Documentation/githooks.txt index d9da474fb0..57d6e2b98d 100644 --- a/Documentation/githooks.txt +++ b/Documentation/githooks.txt @@ -106,7 +106,8 @@ the use of non-ASCII filenames. pre-merge-commit ~~~~~~~~~~~~~~~~ -This hook is invoked by linkgit:git-merge[1]. It takes no parameters, and is +This hook is invoked by linkgit:git-merge[1], and can be bypassed +with the `--no-verify` option. It takes no parameters, and is invoked after the merge has been carried out successfully and before obtaining the proposed commit log message to make a commit. Exiting with a non-zero status from this script diff --git a/builtin/merge.c b/builtin/merge.c index bf0ae68c40..c9746e37b8 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-commit 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-commit", NULL)) + if (!no_verify && run_commit_hook(0 < option_edit, index_file, "pre-merge-commit", NULL)) abort_commit(remoteheads, NULL); /* * Re-read the index as pre-merge-commit hook could have updated it, diff --git a/t/t7503-pre-commit-and-pre-merge-commit-hooks.sh b/t/t7503-pre-commit-and-pre-merge-commit-hooks.sh index 7a5434c7ab..b3485450a2 100755 --- a/t/t7503-pre-commit-and-pre-merge-commit-hooks.sh +++ b/t/t7503-pre-commit-and-pre-merge-commit-hooks.sh @@ -84,6 +84,15 @@ test_expect_success '--no-verify with no hook' ' test_path_is_missing actual_hooks ' +test_expect_success '--no-verify with no hook (merge)' ' + test_when_finished "rm -f actual_hooks" && + git branch -f side side-orig && + git checkout side && + git merge --no-verify -m "merge master" master && + git checkout master && + test_path_is_missing actual_hooks +' + test_expect_success 'with succeeding hook' ' test_when_finished "rm -f \"$PRECOMMIT\" expected_hooks actual_hooks" && cp "$HOOKDIR/success.sample" "$PRECOMMIT" && @@ -131,6 +140,16 @@ test_expect_success '--no-verify with succeeding hook' ' test_path_is_missing actual_hooks ' +test_expect_success '--no-verify with succeeding hook (merge)' ' + test_when_finished "rm -f \"$PREMERGE\" actual_hooks" && + cp "$HOOKDIR/success.sample" "$PREMERGE" && + git branch -f side side-orig && + git checkout side && + git merge --no-verify -m "merge master" master && + git checkout master && + test_path_is_missing actual_hooks +' + test_expect_success 'with failing hook' ' test_when_finished "rm -f \"$PRECOMMIT\" expected_hooks actual_hooks" && cp "$HOOKDIR/fail.sample" "$PRECOMMIT" && @@ -160,6 +179,16 @@ test_expect_success 'with failing hook (merge)' ' test_cmp expected_hooks actual_hooks ' +test_expect_success '--no-verify with failing hook (merge)' ' + test_when_finished "rm -f \"$PREMERGE\" actual_hooks" && + cp "$HOOKDIR/fail.sample" "$PREMERGE" && + git branch -f side side-orig && + git checkout side && + git merge --no-verify -m "merge master" master && + git checkout master && + test_path_is_missing actual_hooks +' + test_expect_success POSIXPERM 'with non-executable hook' ' test_when_finished "rm -f \"$PRECOMMIT\" actual_hooks" && cp "$HOOKDIR/non-exec.sample" "$PRECOMMIT" && @@ -188,6 +217,16 @@ test_expect_success POSIXPERM 'with non-executable hook (merge)' ' test_path_is_missing actual_hooks ' +test_expect_success POSIXPERM '--no-verify with non-executable hook (merge)' ' + test_when_finished "rm -f \"$PREMERGE\" actual_hooks" && + cp "$HOOKDIR/non-exec.sample" "$PREMERGE" && + git branch -f side side-orig && + git checkout side && + git merge --no-verify -m "merge master" master && + git checkout master && + test_path_is_missing actual_hooks +' + test_expect_success 'with hook requiring GIT_PREFIX' ' test_when_finished "rm -rf \"$PRECOMMIT\" expected_hooks actual_hooks success" && cp "$HOOKDIR/require-prefix.sample" "$PRECOMMIT" &&