]> git.ipfire.org Git - thirdparty/git.git/commitdiff
git-send-email: Respect core.hooksPath setting
authorRobert Foss <robert.foss@linaro.org>
Tue, 23 Mar 2021 17:33:27 +0000 (18:33 +0100)
committerJunio C Hamano <gitster@pobox.com>
Tue, 23 Mar 2021 22:02:52 +0000 (15:02 -0700)
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>
git-send-email.perl
perl/Git.pm
t/t9001-send-email.sh

index 1f425c08091d400e1d2e94533411c1b778f561de..f5bbf1647e3bdac93a42d6bd63a43efb8bb65de9 100755 (executable)
@@ -1942,7 +1942,7 @@ sub validate_patch {
        my ($fn, $xfer_encoding) = @_;
 
        if ($repo) {
-               my $validate_hook = catfile(catdir($repo->repo_path(), 'hooks'),
+               my $validate_hook = catfile($repo->hooks_path(),
                                            'sendemail-validate');
                my $hook_error;
                if (-x $validate_hook) {
index 02eacef0c2a4a43058a74dda4cebe1ae16bdd2eb..73ebbf80cc6f42cff20acdb6f1d94bc03f28e71f 100644 (file)
@@ -619,6 +619,19 @@ Return path to the git repository. Must be called on a repository instance.
 
 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 {
+       my ($self) = @_;
+
+       my $dir = $self->command_oneline('rev-parse', '--git-path', 'hooks');
+       my $abs = abs_path($dir);
+       return $abs;
+}
 
 =item wc_path ()
 
index 4eee9c3dcb5383b2d709c6f7aac1e1416322426f..1a1caf8f2ed49c6dd792f81090a5315909c5c0ab 100755 (executable)
@@ -513,6 +513,38 @@ do
 
 done
 
+test_expect_success $PREREQ "--validate respects relative core.hooksPath path" '
+       clean_fake_sendmail &&
+       mkdir my-hooks &&
+       test_when_finished "rm my-hooks.ran" &&
+       write_script my-hooks/sendemail-validate <<-\EOF &&
+       >my-hooks.ran
+       exit 1
+       EOF
+       test_config core.hooksPath "my-hooks" &&
+       test_must_fail git send-email \
+               --from="Example <nobody@example.com>" \
+               --to=nobody@example.com \
+               --smtp-server="$(pwd)/fake.sendmail" \
+               --validate \
+               longline.patch 2>err &&
+       test_path_is_file my-hooks.ran &&
+       grep "rejected by sendemail-validate" err
+'
+
+test_expect_success $PREREQ "--validate respects absolute core.hooksPath path" '
+       test_config core.hooksPath "$(pwd)/my-hooks" &&
+       test_when_finished "rm my-hooks.ran" &&
+       test_must_fail git send-email \
+               --from="Example <nobody@example.com>" \
+               --to=nobody@example.com \
+               --smtp-server="$(pwd)/fake.sendmail" \
+               --validate \
+               longline.patch 2>err &&
+       test_path_is_file my-hooks.ran &&
+       grep "rejected by sendemail-validate" err
+'
+
 for enc in 7bit 8bit quoted-printable base64
 do
        test_expect_success $PREREQ "--transfer-encoding=$enc produces correct header" '