@@ -1942,8 +1942,8 @@ sub validate_patch {
my ($fn, $xfer_encoding) = @_;
if ($repo) {
- my $validate_hook = catfile(catdir($repo->repo_path(), 'hooks'),
- 'sendemail-validate');
+ my $hook_path = $repo->hooks_path();
+ my $validate_hook = catfile($hook_path, 'sendemail-validate');
my $hook_error;
if (-x $validate_hook) {
my $target = abs_path($fn);
@@ -226,6 +226,8 @@ sub repository {
$opts{Repository} = abs_path($dir);
}
+ $opts{HooksPath} = $search->command_oneline('rev-parse', '--git-path', 'hooks');
+
delete $opts{Directory};
}
@@ -619,6 +621,13 @@ sub _prompt {
sub repo_path { $_[0]->{opts}->{Repository} }
+=item hooks_path ()
+
+Return path to the hooks directory. Must be called on a repository instance.
+
+=cut
+
+sub hooks_path { $_[0]->{opts}->{HooksPath} }
=item wc_path ()
@@ -513,6 +513,22 @@ do
done
+test_expect_success $PREREQ "--validate respects core.hooksPath setting" '
+ clean_fake_sendmail &&
+ tmp_dir=$(mktemp -d -t ci-XXXXXXXXXX) &&
+ printf "#!/bin/sh" >> $tmp_dir/sendemail-validate &&
+ printf "return 1" >> $tmp_dir/sendemail-validate &&
+ chmod a+x $tmp_dir/sendemail-validate &&
+ git -c core.hooksPath=$tmp_dir send-email \
+ --from="Example <nobody@example.com>" \
+ --to=nobody@example.com \
+ --smtp-server="$(pwd)/fake.sendmail" \
+ --validate \
+ longline.patch \
+ 2>&1 >/dev/null | \
+ grep "rejected by sendemail-validate"
+'
+
for enc in 7bit 8bit quoted-printable base64
do
test_expect_success $PREREQ "--transfer-encoding=$enc produces correct header" '
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 v2.9, 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> --- Changes since v1: - Ævar: Add unit test - Ævar: Add support for getting the hooks_path() from Git perl module - Ævar: Use new hooks_path() instread of issuing git rev-parse in git-send-email.perl Note: The test currently leaves a file in a mktemp directory in /tmp. git-send-email.perl | 4 ++-- perl/Git.pm | 9 +++++++++ t/t9001-send-email.sh | 16 ++++++++++++++++ 3 files changed, 27 insertions(+), 2 deletions(-)