From: Jonathan Tan <jonathantanmy@google.com>
To: git@vger.kernel.org
Cc: Jonathan Tan <jonathantanmy@google.com>,
bmwill@google.com, gitster@pobox.com, jacob.keller@gmail.com
Subject: [PATCH] send-email: check for repo before invoking hook
Date: Thu, 1 Jun 2017 16:50:55 -0700 [thread overview]
Message-ID: <20170601235055.22621-1-jonathantanmy@google.com> (raw)
In-Reply-To: <CA+P7+xr39qk9qHE0=uU3HZE2wOhU9X7rmENoDfP=bp09j9N9Mg@mail.gmail.com>
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>
---
Thanks for the notification. Here's a patch to fix that.
---
git-send-email.perl | 32 +++++++++++++++++---------------
t/t9001-send-email.sh | 8 ++++++++
2 files changed, 25 insertions(+), 15 deletions(-)
diff --git a/git-send-email.perl b/git-send-email.perl
index f0417f64e..94c54dc5a 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -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: $!");
- }
- 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, $!);
diff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh
index 15128c755..d1e4e8ad1 100755
--- a/t/t9001-send-email.sh
+++ b/t/t9001-send-email.sh
@@ -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
--
2.13.0.506.g27d5fe0cd-goog
next prev parent reply other threads:[~2017-06-01 23:51 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-01 22:45 git-send-email no longer works outside a repository? Jacob Keller
2017-06-01 23:00 ` Brandon Williams
2017-06-01 23:14 ` Junio C Hamano
2017-06-01 23:50 ` Jonathan Tan [this message]
2017-06-02 0:22 ` [PATCH] send-email: check for repo before invoking hook Todd Zullinger
2017-06-02 0:49 ` Jacob Keller
2017-06-02 1:59 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170601235055.22621-1-jonathantanmy@google.com \
--to=jonathantanmy@google.com \
--cc=bmwill@google.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jacob.keller@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).