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 caf0c3d6 (make the message file name more specific) and 5df9fcf6 (interpret unknown files as revision lists). This commit provides a fix for both. Signed-off-by: Jay Soffian <jaysoffian@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jay Soffian committed
Feb 14, 2009 at 23:32 UTC
eed6ca7c402cb51ff6cfd3ecf1f1cac788579b5d
1 file changed
+11
-2
git-send-email.perl
+11
-2
@@ -23,7 +23,7 @@ use Getopt::Long;
23
use Text::ParseWords;
24
use Data::Dumper;
25
use Term::ANSIColor;
26
-use File::Temp qw/ tempdir /;
26
+use File::Temp qw/ tempdir tempfile /;
27
use Error qw(:try);
28
use Git;
29
@@ -156,7 +156,10 @@ if ($@) {
156
# Behavior modification variables
157
my ($quiet, $dry_run) = (0, 0);
158
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
+
163
164
# Handle interactive edition of files.
165
my $multiedit;
@@ -267,6 +270,9 @@ unless ($rc) {
270
usage();
271
}
272
273
+die "Cannot run git format-patch from outside a repository\n"
274
+ if $format_patch and not $repo;
275
+
276
# Now, let's fill any that aren't set in with defaults:
277
278
sub read_config {
@@ -404,6 +410,7 @@ if (@alias_files and $aliasfiletype and defined $parse_alias{$aliasfiletype}) {
410
411
# returns 1 if the conflict must be solved using it as a format-patch argument
412
sub check_file_rev_conflict($) {
413
+ return unless $repo;
414
my $f = shift;
415
try {
416
$repo->command('rev-parse', '--verify', '--quiet', $f);
@@ -445,6 +452,8 @@ while (defined(my $f = shift @ARGV)) {
452
}
453
454
if (@rev_list_opts) {
455
+ die "Cannot run git format-patch from outside a repository\n"
456
+ unless $repo;
457
push @files, $repo->command('format-patch', '-o', tempdir(CLEANUP => 1), @rev_list_opts);
458
}
459