Skip to content

Commit a755530

Browse files
nasamuffingitster
authored andcommitted
send-email: use 'git hook run' for 'sendemail-validate'
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 <[email protected]> Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Reviewed-by: Emily Shaffer <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0d3979c commit a755530

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

git-send-email.perl

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -225,13 +225,13 @@ sub format_2822_time {
225225
my $editor;
226226

227227
sub system_or_msg {
228-
my ($args, $msg) = @_;
228+
my ($args, $msg, $cmd_name) = @_;
229229
system(@$args);
230230
my $signalled = $? & 127;
231231
my $exit_code = $? >> 8;
232232
return unless $signalled or $exit_code;
233233

234-
my @sprintf_args = ($args->[0], $exit_code);
234+
my @sprintf_args = ($cmd_name ? $cmd_name : $args->[0], $exit_code);
235235
if (defined $msg) {
236236
# Quiet the 'redundant' warning category, except we
237237
# need to support down to Perl 5.8, so we can't do a
@@ -2075,10 +2075,10 @@ sub validate_patch {
20752075
my ($fn, $xfer_encoding) = @_;
20762076

20772077
if ($repo) {
2078+
my $hook_name = 'sendemail-validate';
20782079
my $hooks_path = $repo->command_oneline('rev-parse', '--git-path', 'hooks');
20792080
require File::Spec;
2080-
my $validate_hook = File::Spec->catfile($hooks_path,
2081-
'sendemail-validate');
2081+
my $validate_hook = File::Spec->catfile($hooks_path, $hook_name);
20822082
my $hook_error;
20832083
if (-x $validate_hook) {
20842084
require Cwd;
@@ -2088,13 +2088,19 @@ sub validate_patch {
20882088
chdir($repo->wc_path() or $repo->repo_path())
20892089
or die("chdir: $!");
20902090
local $ENV{"GIT_DIR"} = $repo->repo_path();
2091-
$hook_error = system_or_msg([$validate_hook, $target]);
2091+
my @cmd = ("git", "hook", "run", "--ignore-missing",
2092+
$hook_name, "--");
2093+
my @cmd_msg = (@cmd, "<patch>");
2094+
my @cmd_run = (@cmd, $target);
2095+
$hook_error = system_or_msg(\@cmd_run, undef, "@cmd_msg");
20922096
chdir($cwd_save) or die("chdir: $!");
20932097
}
20942098
if ($hook_error) {
2095-
die sprintf(__("fatal: %s: rejected by sendemail-validate hook\n" .
2096-
"%s\n" .
2097-
"warning: no patches were sent\n"), $fn, $hook_error);
2099+
$hook_error = sprintf(__("fatal: %s: rejected by %s hook\n" .
2100+
$hook_error . "\n" .
2101+
"warning: no patches were sent\n"),
2102+
$fn, $hook_name);
2103+
die $hook_error;
20982104
}
20992105
}
21002106

t/t9001-send-email.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ test_expect_success $PREREQ "--validate respects relative core.hooksPath path" '
539539
test_path_is_file my-hooks.ran &&
540540
cat >expect <<-EOF &&
541541
fatal: longline.patch: rejected by sendemail-validate hook
542-
fatal: command '"'"'my-hooks/sendemail-validate'"'"' died with exit code 1
542+
fatal: command '"'"'git hook run --ignore-missing sendemail-validate -- <patch>'"'"' died with exit code 1
543543
warning: no patches were sent
544544
EOF
545545
test_cmp expect actual
@@ -558,7 +558,7 @@ test_expect_success $PREREQ "--validate respects absolute core.hooksPath path" '
558558
test_path_is_file my-hooks.ran &&
559559
cat >expect <<-EOF &&
560560
fatal: longline.patch: rejected by sendemail-validate hook
561-
fatal: command '"'"'$hooks_path/sendemail-validate'"'"' died with exit code 1
561+
fatal: command '"'"'git hook run --ignore-missing sendemail-validate -- <patch>'"'"' died with exit code 1
562562
warning: no patches were sent
563563
EOF
564564
test_cmp expect actual

0 commit comments

Comments
 (0)