Skip to content

Commit c824393

Browse files
robertfossgitster
authored andcommitted
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 867ad08 (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 <[email protected]> Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1424303 commit c824393

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

git-send-email.perl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1942,7 +1942,7 @@ sub validate_patch {
19421942
my ($fn, $xfer_encoding) = @_;
19431943

19441944
if ($repo) {
1945-
my $validate_hook = catfile(catdir($repo->repo_path(), 'hooks'),
1945+
my $validate_hook = catfile($repo->hooks_path(),
19461946
'sendemail-validate');
19471947
my $hook_error;
19481948
if (-x $validate_hook) {

perl/Git.pm

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,19 @@ Return path to the git repository. Must be called on a repository instance.
619619

620620
sub repo_path { $_[0]->{opts}->{Repository} }
621621

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+
}
622635

623636
=item wc_path ()
624637

t/t9001-send-email.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,38 @@ do
513513

514514
done
515515

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 <[email protected]>" \
527+
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 <[email protected]>" \
540+
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+
516548
for enc in 7bit 8bit quoted-printable base64
517549
do
518550
test_expect_success $PREREQ "--transfer-encoding=$enc produces correct header" '

0 commit comments

Comments
 (0)