git-send-email: Respect core.hooksPath setting
PATCH 1/1 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 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.
---
This patch does not include a test for this bug fix. This is entirely due to me not being able to think up a way to test this. So I'm very much open to suggestions.
git-send-email.perl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
git-send-email.perl +3 -2
@@ -1942,8 +1942,9 @@ sub validate_patch { my ($fn, $xfer_encoding) = @_; if ($repo) { - my $validate_hook = catfile(catdir($repo->repo_path(), 'hooks'), - 'sendemail-validate'); + my $hook_path = $repo->command('rev-parse', '--git-path', 'hooks'); + chomp($hook_path); + my $validate_hook = catfile($hook_path, 'sendemail-validate'); my $hook_error; if (-x $validate_hook) { my $target = abs_path($fn);
Signature · 1 line
2.27.0
Quoted 9 lines · Robert Foss
get-send-email currently makes the assumption that the 'sendemail-validate' hook exists inside of the repository.
Since the introduction of
core.hooksPathconfiguration 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.
Quoted 7 lines
Signed-off-by Robert Foss <[email protected]>---
This patch does not include a test for this bug fix. This is entirely due to me not being able to think up a way to test this. So I'm very much open to suggestions.
There's an "invoke hook" test in t9001-send-email.sh which should be easy to tweak (or mostly copy/pasted to another test) to run the same way once the hook is moved from .git/hooks to somedir/ and -c core.hooksPath=somedir is set.
Quoted 8 lines
git-send-email.perl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)git-send-email.perl +0
-0
git-send-email.perl sub validate_patch { · line 1947
Quoted 8 lines
git-send-email.perl +3
-2@@ -1942,8 +1942,9 @@ sub validate_patch { my ($fn, $xfer_encoding) = @_; if ($repo) { - my $validate_hook = catfile(catdir($repo->repo_path(), 'hooks'), - 'sendemail-validate'); + my $hook_path = $repo->command('rev-parse', '--git-path', 'hooks'); + chomp($hook_path); + my $validate_hook = catfile($hook_path, 'sendemail-validate');
This looks like it work, small nits:
1. This would be better in perl/Git.pm, it already has various accessors etc. for these rev-parse'd values. You could just pass a a new GetHooksPath => 1 to Git->repository() and if so populate this, then call that as $repo->git_path_hooks.
2. FWIW it's more idiomatic in perl to just do : chomp(my $x = y()); not my $x = y(); chomp $x. The chomp operator works in-place, but once you'd use the helpers in Git.pm for this they'd do all that for you.
Quoted 3 lines
git-send-email.perl +0
-0my $hook_error; if (-x $validate_hook) { my $target = abs_path($fn);
Hey Ævar,
Thank you for the quick feedback.
Quoted 17 lines · Ævar Arnfjörð Bjarmason
Quoted 13 lines · Robert Foss
get-send-email currently makes the assumption that the 'sendemail-validate' hook exists inside of the repository.
Since the introduction of
core.hooksPathconfiguration 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 <[email protected]>---
Quoted 8 lines
Quoted 3 lines
This patch does not include a test for this bug fix. This is entirely due to me not being able to think up a way to test this. So I'm very much open to suggestions.
There's an "invoke hook" test in
t9001-send-email.shwhich should be easy to tweak (or mostly copy/pasted to another test) to run the same way once the hook is moved from .git/hooks to somedir/ and -c core.hooksPath=somedir is set.
Ack
Quoted 20 lines
Quoted 9 lines
git-send-email.perl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)git-send-email.perl +0
-0git-send-email.perl sub validate_patch { · line 1947
Quoted 8 lines
git-send-email.perl +3
-2@@ -1942,8 +1942,9 @@ sub validate_patch { my ($fn, $xfer_encoding) = @_; if ($repo) { - my $validate_hook = catfile(catdir($repo->repo_path(), 'hooks'), - 'sendemail-validate'); + my $hook_path = $repo->command('rev-parse', '--git-path', 'hooks'); + chomp($hook_path); + my $validate_hook = catfile($hook_path, 'sendemail-validate');This looks like it work, small nits:
Quoted 4 lines
1. This would be better in perl/Git.pm, it already has various accessors etc. for these rev-parse'd values. You could just pass a a new GetHooksPath => 1 to
Git->repository()and if so populate this, then call that as $repo->git_path_hooks.
I reworked this, but being a level 1 perl coder I don't quite grok the "GetHooksPath => 1 to Git->repository()" part of your suggestion.
https://github.com/robertfoss/git/commit/9388d1f66b8d182f0dcc869f627736596af382da
This is what I came up with.
Quoted 9 lines
2. FWIW it's more idiomatic in perl to just do : chomp(my $x =
y()); not my $x =y(); chomp $x. The chomp operator works in-place, but once you'd use the helpers in Git.pm for this they'd do all that for you.Quoted 3 lines
git-send-email.perl +0
-0my $hook_error; if (-x $validate_hook) { my $target = abs_path($fn);
Ack