git-send-email: Respect core.hooksPath setting

get-send-email currently makes the assumption that the 'sendemail-validate' hook exists inside of the repository. Since the introduction of 'core.hooksPath' configuration option in 867ad08a261 (hooks: allow customizing where the hook directory is, 2016-05-04), this is no longer true. Instead of assuming a hardcoded repo relative path, query git for the actual path of the hooks directory. Signed-off-by: Robert Foss <robert.foss@linaro.org> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Robert Foss committed Mar 23, 2021 at 18:33 UTC c8243933c74e0bebcc617f750ae3990ecca47759
3 files changed +46 -1
git-send-email.perl
+1 -1
@@ -1942,7 +1942,7 @@ sub validate_patch {
1942 my ($fn, $xfer_encoding) = @_;
1943
1944 if ($repo) {
1945 - my $validate_hook = catfile(catdir($repo->repo_path(), 'hooks'),
1945 + my $validate_hook = catfile($repo->hooks_path(),
1946 'sendemail-validate');
1947 my $hook_error;
1948 if (-x $validate_hook) {
perl/Git.pm
+13
@@ -619,6 +619,19 @@ Return path to the git repository. Must be called on a repository instance.
619
620 sub repo_path { $_[0]->{opts}->{Repository} }
621
622 +=item hooks_path ()
623 +
624 +Return path to the hooks directory. Must be called on a repository instance.
625 +
626 +=cut
627 +
628 +sub hooks_path {
629 + my ($self) = @_;
630 +
631 + my $dir = $self->command_oneline('rev-parse', '--git-path', 'hooks');
632 + my $abs = abs_path($dir);
633 + return $abs;
634 +}
635
636 =item wc_path ()
637
t/t9001-send-email.sh
+32
@@ -513,6 +513,38 @@ do
513
514 done
515
516 +test_expect_success $PREREQ "--validate respects relative core.hooksPath path" '
517 + clean_fake_sendmail &&
518 + mkdir my-hooks &&
519 + test_when_finished "rm my-hooks.ran" &&
520 + write_script my-hooks/sendemail-validate <<-\EOF &&
521 + >my-hooks.ran
522 + exit 1
523 + EOF
524 + test_config core.hooksPath "my-hooks" &&
525 + test_must_fail git send-email \
526 + --from="Example <nobody@example.com>" \
527 + --to=nobody@example.com \
528 + --smtp-server="$(pwd)/fake.sendmail" \
529 + --validate \
530 + longline.patch 2>err &&
531 + test_path_is_file my-hooks.ran &&
532 + grep "rejected by sendemail-validate" err
533 +'
534 +
535 +test_expect_success $PREREQ "--validate respects absolute core.hooksPath path" '
536 + test_config core.hooksPath "$(pwd)/my-hooks" &&
537 + test_when_finished "rm my-hooks.ran" &&
538 + test_must_fail git send-email \
539 + --from="Example <nobody@example.com>" \
540 + --to=nobody@example.com \
541 + --smtp-server="$(pwd)/fake.sendmail" \
542 + --validate \
543 + longline.patch 2>err &&
544 + test_path_is_file my-hooks.ran &&
545 + grep "rejected by sendemail-validate" err
546 +'
547 +
548 for enc in 7bit 8bit quoted-printable base64
549 do
550 test_expect_success $PREREQ "--transfer-encoding=$enc produces correct header" '