From patchwork Fri Oct 15 09:43:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12560939 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CEA34C433F5 for ; Fri, 15 Oct 2021 09:44:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B346361027 for ; Fri, 15 Oct 2021 09:44:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233640AbhJOJqH (ORCPT ); Fri, 15 Oct 2021 05:46:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45848 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237570AbhJOJp7 (ORCPT ); Fri, 15 Oct 2021 05:45:59 -0400 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A38E8C061753 for ; Fri, 15 Oct 2021 02:43:53 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id i12so25422433wrb.7 for ; Fri, 15 Oct 2021 02:43:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=w0VYIMPf3h4Dy9sY6x5aGTTczxHpuvl5M1XMXT5QfGM=; b=mKjRcPSUHLU2R51K7rUvmC4Kdk/x3LonjqQej6s7HAGfFfHm9fO459a5VjWMzcJLkG 384fO6sc8jIyEfvW5ojaIwBBq7Z8QRIqAGMgGDMK/zIP1mXGzWIOrdol5cklE0C0xeHj IMtFlrhRQk8kp2DLXFzRmYq3KNusaFiolNd0lj5wmWs2SyqnNmBM/kLqoUhGMBKPRmEG Zgo/NfAypy7wdWQVeKSOnHzT5kGXtUl3cIP25xGzMERUbYTb/S6wmaJC0B814XI5KgiI xm3VgMKDWBItHDEs9/W1e2bdPHuQZF4G+UdsbhVc/zpuXpZ6w+t/oe2Ga3FM8PQEZhqZ dweA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=w0VYIMPf3h4Dy9sY6x5aGTTczxHpuvl5M1XMXT5QfGM=; b=3SW2yxpQaIw0uG597RK+0noKUGerZcJGEvRtHuQeY+XtAJy4oFDAp1Myjg81Yik5t1 MAeNEFAgyFJWwazFg9nFaiPMGUxjDu+cRMXhn3IC6FUWKsYdjbsnnKb7ocihRLPlgmDm M4YWbY9z9mZIjpuhKY9Tuiri1qdkdjAX0Quyz9bDc7qbkpJaqvWgZxfBFyEBSmg5xMLZ hoxdKFkIR+pSRuqUWi7PGLfwNBWbyCOAZaIFWz6hLtqjwbaRMKVWE8/RSUtkLKp+mDUl 6dfbLuh1apdrxTGivD0PtiCPp7/J8J86rGMBLT7iuEUmnsKhZifXKC1WYsG7Qd+Xe3Bf co9A== X-Gm-Message-State: AOAM532IGFr5vKKemvlSaAJx8liZ8TGvNduNAvI0K488Q5S8KvaAo95Q 744ttYLZ67Msi7IWOwU9VIfk72dA64YTNQ== X-Google-Smtp-Source: ABdhPJxFO356yS8Cxz33T/kwaRWFLWrbXqH1PnXigw3jW6k41nnFBjxnsPz9aSlkXZKD3Vc0UbHOBg== X-Received: by 2002:adf:f044:: with SMTP id t4mr12965444wro.406.1634291032030; Fri, 15 Oct 2021 02:43:52 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id r4sm5963648wrz.58.2021.10.15.02.43.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Oct 2021 02:43:51 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Phillip Wood , =?utf-8?q?Ren=C3=A9_Scharfe?= , Emily Shaffer , Bagas Sanjaya , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH v2 08/13] send-email: use 'git hook run' for 'sendemail-validate' Date: Fri, 15 Oct 2021 11:43:36 +0200 Message-Id: X-Mailer: git-send-email 2.33.1.1338.g20da966911a In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Emily Shaffer Change the "sendmail-validate" hook to be run via the "git hook run" wrapper instead of via a direct invocation. This is the smallest possibly change to get "send-email" using "git hook run". We still check the hook itself with "-x", and set a "GIT_DIR" variable, both of which are asserted by our tests. We'll need to get rid of this special behavior if we start running N hooks, but for now let's be as close to bug-for-bug compatible as possible. Signed-off-by: Emily Shaffer Signed-off-by: Ævar Arnfjörð Bjarmason Reviewed-by: Emily Shaffer --- git-send-email.perl | 22 ++++++++++++++-------- t/t9001-send-email.sh | 4 ++-- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/git-send-email.perl b/git-send-email.perl index 5262d88ee32..4c20c0bbb79 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -195,13 +195,13 @@ sub format_2822_time { my $editor; sub system_or_msg { - my ($args, $msg) = @_; + my ($args, $msg, $cmd_name) = @_; system(@$args); my $signalled = $? & 127; my $exit_code = $? >> 8; return unless $signalled or $exit_code; - my @sprintf_args = ($args->[0], $exit_code); + my @sprintf_args = ($cmd_name ? $cmd_name : $args->[0], $exit_code); if (defined $msg) { # Quiet the 'redundant' warning category, except we # need to support down to Perl 5.8, so we can't do a @@ -2039,10 +2039,10 @@ sub validate_patch { my ($fn, $xfer_encoding) = @_; if ($repo) { + my $hook_name = 'sendemail-validate'; my $hooks_path = $repo->command_oneline('rev-parse', '--git-path', 'hooks'); require File::Spec; - my $validate_hook = File::Spec->catfile($hooks_path, - 'sendemail-validate'); + my $validate_hook = File::Spec->catfile($hooks_path, $hook_name); my $hook_error; if (-x $validate_hook) { require Cwd; @@ -2052,13 +2052,19 @@ sub validate_patch { chdir($repo->wc_path() or $repo->repo_path()) or die("chdir: $!"); local $ENV{"GIT_DIR"} = $repo->repo_path(); - $hook_error = system_or_msg([$validate_hook, $target]); + my @cmd = ("git", "hook", "run", "--ignore-missing", + $hook_name, "--"); + my @cmd_msg = (@cmd, ""); + my @cmd_run = (@cmd, $target); + $hook_error = system_or_msg(\@cmd_run, undef, "@cmd_msg"); chdir($cwd_save) or die("chdir: $!"); } if ($hook_error) { - die sprintf(__("fatal: %s: rejected by sendemail-validate hook\n" . - "%s\n" . - "warning: no patches were sent\n"), $fn, $hook_error); + $hook_error = sprintf(__("fatal: %s: rejected by %s hook\n" . + $hook_error . "\n" . + "warning: no patches were sent\n"), + $fn, $hook_name); + die $hook_error; } } diff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh index aa0c20499ba..84d0f40d76a 100755 --- a/t/t9001-send-email.sh +++ b/t/t9001-send-email.sh @@ -539,7 +539,7 @@ test_expect_success $PREREQ "--validate respects relative core.hooksPath path" ' test_path_is_file my-hooks.ran && cat >expect <<-EOF && fatal: longline.patch: rejected by sendemail-validate hook - fatal: command '"'"'my-hooks/sendemail-validate'"'"' died with exit code 1 + fatal: command '"'"'git hook run --ignore-missing sendemail-validate -- '"'"' died with exit code 1 warning: no patches were sent EOF test_cmp expect actual @@ -558,7 +558,7 @@ test_expect_success $PREREQ "--validate respects absolute core.hooksPath path" ' test_path_is_file my-hooks.ran && cat >expect <<-EOF && fatal: longline.patch: rejected by sendemail-validate hook - fatal: command '"'"'$hooks_path/sendemail-validate'"'"' died with exit code 1 + fatal: command '"'"'git hook run --ignore-missing sendemail-validate -- '"'"' died with exit code 1 warning: no patches were sent EOF test_cmp expect actual