1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-05-22 07:26:26 +02:00

Merge branch 'jt/send-email-validate-hook'

A hotfix for a topic already in 'master'.

* jt/send-email-validate-hook:
  send-email: check for repo before invoking hook
This commit is contained in:
Junio C Hamano 2017-06-02 15:05:59 +09:00
commit 8e6a904dd8
2 changed files with 24 additions and 14 deletions

View File

@ -1755,21 +1755,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: $!");
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;
}
return $hook_error if $hook_error;
open(my $fh, '<', $fn)
or die sprintf(__("unable to open %s: %s\n"), $fn, $!);

View File

@ -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