Skip to content

Commit 2815326

Browse files
avargitster
authored andcommitted
send-email: don't needlessly abs_path() the core.hooksPath
In c824393 (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 c824393 itself, but was revealed by my ea7811b (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 53753a3 (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 53753a3 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/[email protected] Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 53753a3 commit 2815326

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

perl/Git.pm

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -629,8 +629,7 @@ sub hooks_path {
629629
my ($self) = @_;
630630

631631
my $dir = $self->command_oneline('rev-parse', '--git-path', 'hooks');
632-
my $abs = abs_path($dir);
633-
return $abs;
632+
return $dir;
634633
}
635634

636635
=item wc_path ()

t/t9001-send-email.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -539,14 +539,15 @@ test_expect_success $PREREQ "--validate respects relative core.hooksPath path" '
539539
test_path_is_file my-hooks.ran &&
540540
cat >expect <<-EOF &&
541541
fatal: longline.patch: rejected by sendemail-validate hook
542-
fatal: command '"'"'$PWD/my-hooks/sendemail-validate'"'"' died with exit code 1
542+
fatal: command '"'"'my-hooks/sendemail-validate'"'"' died with exit code 1
543543
warning: no patches were sent
544544
EOF
545545
test_cmp expect actual
546546
'
547547

548548
test_expect_success $PREREQ "--validate respects absolute core.hooksPath path" '
549-
test_config core.hooksPath "$(pwd)/my-hooks" &&
549+
hooks_path="$(pwd)/my-hooks" &&
550+
test_config core.hooksPath "$hooks_path" &&
550551
test_when_finished "rm my-hooks.ran" &&
551552
test_must_fail git send-email \
552553
--from="Example <[email protected]>" \
@@ -557,7 +558,7 @@ test_expect_success $PREREQ "--validate respects absolute core.hooksPath path" '
557558
test_path_is_file my-hooks.ran &&
558559
cat >expect <<-EOF &&
559560
fatal: longline.patch: rejected by sendemail-validate hook
560-
fatal: command '"'"'$PWD/my-hooks/sendemail-validate'"'"' died with exit code 1
561+
fatal: command '"'"'$hooks_path/sendemail-validate'"'"' died with exit code 1
561562
warning: no patches were sent
562563
EOF
563564
test_cmp expect actual

0 commit comments

Comments
 (0)