Skip to content

Commit eed6ca7

Browse files
jaysoffiangitster
authored andcommitted
send-email: allow send-email to run outside a repo
send-email is supposed to be able to run from outside a repo. This ability was broken by commits caf0c3d (make the message file name more specific) and 5df9fcf (interpret unknown files as revision lists). This commit provides a fix for both. Signed-off-by: Jay Soffian <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e9cc02f commit eed6ca7

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

git-send-email.perl

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
use Text::ParseWords;
2424
use Data::Dumper;
2525
use Term::ANSIColor;
26-
use File::Temp qw/ tempdir /;
26+
use File::Temp qw/ tempdir tempfile /;
2727
use Error qw(:try);
2828
use Git;
2929

@@ -156,7 +156,10 @@ sub format_2822_time {
156156
# Behavior modification variables
157157
my ($quiet, $dry_run) = (0, 0);
158158
my $format_patch;
159-
my $compose_filename = $repo->repo_path() . "/.gitsendemail.msg.$$";
159+
my $compose_filename = ($repo ?
160+
tempfile(".gitsendemail.msg.XXXXXX", DIR => $repo->repo_path()) :
161+
tempfile(".gitsendemail.msg.XXXXXX", DIR => "."))[1];
162+
160163

161164
# Handle interactive edition of files.
162165
my $multiedit;
@@ -267,6 +270,9 @@ sub signal_handler {
267270
usage();
268271
}
269272

273+
die "Cannot run git format-patch from outside a repository\n"
274+
if $format_patch and not $repo;
275+
270276
# Now, let's fill any that aren't set in with defaults:
271277

272278
sub read_config {
@@ -404,6 +410,7 @@ sub split_addrs {
404410

405411
# returns 1 if the conflict must be solved using it as a format-patch argument
406412
sub check_file_rev_conflict($) {
413+
return unless $repo;
407414
my $f = shift;
408415
try {
409416
$repo->command('rev-parse', '--verify', '--quiet', $f);
@@ -445,6 +452,8 @@ ($)
445452
}
446453

447454
if (@rev_list_opts) {
455+
die "Cannot run git format-patch from outside a repository\n"
456+
unless $repo;
448457
push @files, $repo->command('format-patch', '-o', tempdir(CLEANUP => 1), @rev_list_opts);
449458
}
450459

0 commit comments

Comments
 (0)