Skip to content

Commit 8e6a904

Browse files
committed
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
2 parents b85b881 + 177409e commit 8e6a904

File tree

2 files changed

+25
-15
lines changed

2 files changed

+25
-15
lines changed

git-send-email.perl

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1755,21 +1755,23 @@ sub unique_email_list {
17551755
sub validate_patch {
17561756
my $fn = shift;
17571757

1758-
my $validate_hook = catfile(catdir($repo->repo_path(), 'hooks'),
1759-
'sendemail-validate');
1760-
my $hook_error;
1761-
if (-x $validate_hook) {
1762-
my $target = abs_path($fn);
1763-
# The hook needs a correct cwd and GIT_DIR.
1764-
my $cwd_save = cwd();
1765-
chdir($repo->wc_path() or $repo->repo_path())
1766-
or die("chdir: $!");
1767-
local $ENV{"GIT_DIR"} = $repo->repo_path();
1768-
$hook_error = "rejected by sendemail-validate hook"
1769-
if system($validate_hook, $target);
1770-
chdir($cwd_save) or die("chdir: $!");
1771-
}
1772-
return $hook_error if $hook_error;
1758+
if ($repo) {
1759+
my $validate_hook = catfile(catdir($repo->repo_path(), 'hooks'),
1760+
'sendemail-validate');
1761+
my $hook_error;
1762+
if (-x $validate_hook) {
1763+
my $target = abs_path($fn);
1764+
# The hook needs a correct cwd and GIT_DIR.
1765+
my $cwd_save = cwd();
1766+
chdir($repo->wc_path() or $repo->repo_path())
1767+
or die("chdir: $!");
1768+
local $ENV{"GIT_DIR"} = $repo->repo_path();
1769+
$hook_error = "rejected by sendemail-validate hook"
1770+
if system($validate_hook, $target);
1771+
chdir($cwd_save) or die("chdir: $!");
1772+
}
1773+
return $hook_error if $hook_error;
1774+
}
17731775

17741776
open(my $fh, '<', $fn)
17751777
or die sprintf(__("unable to open %s: %s\n"), $fn, $!);

t/t9001-send-email.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1953,4 +1953,12 @@ test_expect_success $PREREQ 'invoke hook' '
19531953
)
19541954
'
19551955

1956+
test_expect_success $PREREQ 'test that send-email works outside a repo' '
1957+
nongit git send-email \
1958+
--from="Example <[email protected]>" \
1959+
1960+
--smtp-server="$(pwd)/fake.sendmail" \
1961+
"$(pwd)/0001-add-master.patch"
1962+
'
1963+
19561964
test_done

0 commit comments

Comments
 (0)