summaryrefslogtreecommitdiff
path: root/git-send-email.perl
diff options
context:
space:
mode:
authorJonathan Tan <jonathantanmy@google.com>2017-05-12 15:38:26 -0700
committerJunio C Hamano <gitster@pobox.com>2017-05-16 11:13:00 +0900
commit6489660b4bba7456fac0d0a41f5d6295c5900c5f (patch)
treec8be3c5dbe895d9584dcab3fd704e7a8f2e84c97 /git-send-email.perl
parentb06d3643105c8758ed019125a4399cb7efdcce2c (diff)
downloadgit-6489660b4bba7456fac0d0a41f5d6295c5900c5f.tar.gz
send-email: support validate hook
Currently, send-email has support for rudimentary e-mail validation. Allow the user to add support for more validation by providing a sendemail-validate hook. Helped-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Jonathan Tan <jonathantanmy@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'git-send-email.perl')
-rwxr-xr-xgit-send-email.perl20
1 files changed, 19 insertions, 1 deletions
diff --git a/git-send-email.perl b/git-send-email.perl
index eea0a517f7..c314cc2b51 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -25,8 +25,9 @@ use Getopt::Long;
use Text::ParseWords;
use Term::ANSIColor;
use File::Temp qw/ tempdir tempfile /;
-use File::Spec::Functions qw(catfile);
+use File::Spec::Functions qw(catdir catfile);
use Error qw(:try);
+use Cwd qw(abs_path cwd);
use Git;
use Git::I18N;
@@ -1737,6 +1738,23 @@ sub unique_email_list {
sub validate_patch {
my $fn = shift;
+
+ my $validate_hook = catfile(catdir($repo->repo_path(), 'hooks'),
+ 'sendemail-validate');
+ my $hook_error;
+ if (-x $validate_hook) {
+ my $target = abs_path($fn);
+ # The hook needs a correct cwd and GIT_DIR.
+ my $cwd_save = cwd();
+ chdir($repo->wc_path() or $repo->repo_path())
+ or die("chdir: $!");
+ local $ENV{"GIT_DIR"} = $repo->repo_path();
+ $hook_error = "rejected by sendemail-validate hook"
+ if system($validate_hook, $target);
+ chdir($cwd_save) or die("chdir: $!");
+ }
+ return $hook_error if $hook_error;
+
open(my $fh, '<', $fn)
or die sprintf(__("unable to open %s: %s\n"), $fn, $!);
while (my $line = <$fh>) {