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>maint
parent
6489660b4b
commit
177409e589
|
@ -1739,21 +1739,23 @@ sub unique_email_list {
|
||||||
sub validate_patch {
|
sub validate_patch {
|
||||||
my $fn = shift;
|
my $fn = shift;
|
||||||
|
|
||||||
my $validate_hook = catfile(catdir($repo->repo_path(), 'hooks'),
|
if ($repo) {
|
||||||
'sendemail-validate');
|
my $validate_hook = catfile(catdir($repo->repo_path(), 'hooks'),
|
||||||
my $hook_error;
|
'sendemail-validate');
|
||||||
if (-x $validate_hook) {
|
my $hook_error;
|
||||||
my $target = abs_path($fn);
|
if (-x $validate_hook) {
|
||||||
# The hook needs a correct cwd and GIT_DIR.
|
my $target = abs_path($fn);
|
||||||
my $cwd_save = cwd();
|
# The hook needs a correct cwd and GIT_DIR.
|
||||||
chdir($repo->wc_path() or $repo->repo_path())
|
my $cwd_save = cwd();
|
||||||
or die("chdir: $!");
|
chdir($repo->wc_path() or $repo->repo_path())
|
||||||
local $ENV{"GIT_DIR"} = $repo->repo_path();
|
or die("chdir: $!");
|
||||||
$hook_error = "rejected by sendemail-validate hook"
|
local $ENV{"GIT_DIR"} = $repo->repo_path();
|
||||||
if system($validate_hook, $target);
|
$hook_error = "rejected by sendemail-validate hook"
|
||||||
chdir($cwd_save) or die("chdir: $!");
|
if system($validate_hook, $target);
|
||||||
|
chdir($cwd_save) or die("chdir: $!");
|
||||||
|
}
|
||||||
|
return $hook_error if $hook_error;
|
||||||
}
|
}
|
||||||
return $hook_error if $hook_error;
|
|
||||||
|
|
||||||
open(my $fh, '<', $fn)
|
open(my $fh, '<', $fn)
|
||||||
or die sprintf(__("unable to open %s: %s\n"), $fn, $!);
|
or die sprintf(__("unable to open %s: %s\n"), $fn, $!);
|
||||||
|
|
|
@ -1953,4 +1953,12 @@ test_expect_success $PREREQ 'invoke hook' '
|
||||||
)
|
)
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success $PREREQ 'test that send-email works outside a repo' '
|
||||||
|
nongit git send-email \
|
||||||
|
--from="Example <nobody@example.com>" \
|
||||||
|
--to=nobody@example.com \
|
||||||
|
--smtp-server="$(pwd)/fake.sendmail" \
|
||||||
|
"$(pwd)/0001-add-master.patch"
|
||||||
|
'
|
||||||
|
|
||||||
test_done
|
test_done
|
||||||
|
|
Loading…
Reference in New Issue