summaryrefslogtreecommitdiff
path: root/git-send-email.perl
diff options
context:
space:
mode:
authorJonathan Tan <jonathantanmy@google.com>2017-06-01 23:50:55 (GMT)
committerJunio C Hamano <gitster@pobox.com>2017-06-02 01:58:25 (GMT)
commit177409e5897988f03e0c8111c94db6ea0466b138 (patch)
tree3065e4a03620792a5796e4ea27b1ea34f6d4e699 /git-send-email.perl
parent6489660b4bba7456fac0d0a41f5d6295c5900c5f (diff)
downloadgit-177409e5897988f03e0c8111c94db6ea0466b138.zip
git-177409e5897988f03e0c8111c94db6ea0466b138.tar.gz
git-177409e5897988f03e0c8111c94db6ea0466b138.tar.bz2
send-email: check for repo before invoking hook
Unless --no-validate is passed, send-email will invoke $repo->repo_path() in its search for a validate hook regardless of whether a Git repo is actually present. Teach send-email to first check for repo existence. 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.perl32
1 files changed, 17 insertions, 15 deletions
diff --git a/git-send-email.perl b/git-send-email.perl
index c314cc2..fa559cc 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -1739,21 +1739,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;
+ if ($repo) {
+ 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, $!);