]> git.ipfire.org Git - thirdparty/git.git/commitdiff
send-email: don't needlessly abs_path() the core.hooksPath
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>
Wed, 26 May 2021 11:21:06 +0000 (13:21 +0200)
committerJunio C Hamano <gitster@pobox.com>
Thu, 27 May 2021 00:00:57 +0000 (09:00 +0900)
In c8243933c74 (git-send-email: Respect core.hooksPath setting,
2021-03-23) we started supporting core.hooksPath in "send-email". It's
been reported that on Windows[1] doing this by calling abs_path()
results in different canonicalizations of the absolute path.

This wasn't an issue in c8243933c74 itself, but was revealed by my
ea7811b37e0 (git-send-email: improve --validate error output,
2021-04-06) when we started emitting the path to the hook, which was
previously only internal to git-send-email.perl.

The just-landed 53753a37d09 (t9001-send-email.sh: fix expected
absolute paths on Windows, 2021-05-24) narrowly fixed this issue, but
I believe we can do better here. We should not be relying on whatever
changes Perl's abs_path() makes to the path "rev-parse --git-path
hooks" hands to us. Let's instead trust it, and hand it to Perl's
system() in git-send-email.perl. It will handle either a relative or
absolute path.

So let's revert most of 53753a37d09 and just have "hooks_path" return
what we get from "rev-parse" directly without modification. This has
the added benefit of making the error message friendlier in the common
case, we'll no longer print an absolute path for repository-local hook
errors.

1. http://lore.kernel.org/git/bb30fe2b-cd75-4782-24a6-08bb002a0367@kdbg.org

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
perl/Git.pm
t/t9001-send-email.sh

index 73ebbf80cc6f42cff20acdb6f1d94bc03f28e71f..df6280ebab58ec7e36702a85cdc935ac3c3d9bac 100644 (file)
@@ -629,8 +629,7 @@ sub hooks_path {
        my ($self) = @_;
 
        my $dir = $self->command_oneline('rev-parse', '--git-path', 'hooks');
-       my $abs = abs_path($dir);
-       return $abs;
+       return $dir;
 }
 
 =item wc_path ()
index 68bebc505b6ac2e3943b51c18aa701335617bee3..9c518462c3e58dbb5936a8bc06564a8918a00066 100755 (executable)
@@ -539,14 +539,15 @@ test_expect_success $PREREQ "--validate respects relative core.hooksPath path" '
        test_path_is_file my-hooks.ran &&
        cat >expect <<-EOF &&
        fatal: longline.patch: rejected by sendemail-validate hook
-       fatal: command '"'"'$PWD/my-hooks/sendemail-validate'"'"' died with exit code 1
+       fatal: command '"'"'my-hooks/sendemail-validate'"'"' died with exit code 1
        warning: no patches were sent
        EOF
        test_cmp expect actual
 '
 
 test_expect_success $PREREQ "--validate respects absolute core.hooksPath path" '
-       test_config core.hooksPath "$(pwd)/my-hooks" &&
+       hooks_path="$(pwd)/my-hooks" &&
+       test_config core.hooksPath "$hooks_path" &&
        test_when_finished "rm my-hooks.ran" &&
        test_must_fail git send-email \
                --from="Example <nobody@example.com>" \
@@ -557,7 +558,7 @@ test_expect_success $PREREQ "--validate respects absolute core.hooksPath path" '
        test_path_is_file my-hooks.ran &&
        cat >expect <<-EOF &&
        fatal: longline.patch: rejected by sendemail-validate hook
-       fatal: command '"'"'$PWD/my-hooks/sendemail-validate'"'"' died with exit code 1
+       fatal: command '"'"'$hooks_path/sendemail-validate'"'"' died with exit code 1
        warning: no patches were sent
        EOF
        test_cmp expect actual