Skip to content

Commit 7c2abf1

Browse files
committed
Merge branch 'tp/send-email-completion'
The command line complation for "git send-email" options have been tweaked to make it easier to keep it in sync with the command itself. * tp/send-email-completion: send-email docs: add format-patch options send-email: programmatically generate bash completions
2 parents 0ae8743 + a2ce608 commit 7c2abf1

File tree

4 files changed

+54
-22
lines changed

4 files changed

+54
-22
lines changed

Documentation/git-send-email.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ git-send-email - Send a collection of patches as emails
99
SYNOPSIS
1010
--------
1111
[verse]
12-
'git send-email' [<options>] <file|directory|rev-list options>...
12+
'git send-email' [<options>] <file|directory>...
13+
'git send-email' [<options>] <format-patch options>
1314
'git send-email' --dump-aliases
1415

1516

@@ -19,7 +20,8 @@ Takes the patches given on the command line and emails them out.
1920
Patches can be specified as files, directories (which will send all
2021
files in the directory), or directly as a revision list. In the
2122
last case, any format accepted by linkgit:git-format-patch[1] can
22-
be passed to git send-email.
23+
be passed to git send-email, as well as options understood by
24+
linkgit:git-format-patch[1].
2325

2426
The header of the email is configurable via command-line options. If not
2527
specified on the command line, the user will be prompted with a ReadLine

contrib/completion/git-completion.bash

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2359,16 +2359,7 @@ _git_send_email ()
23592359
return
23602360
;;
23612361
--*)
2362-
__gitcomp_builtin send-email "--annotate --bcc --cc --cc-cmd --chain-reply-to
2363-
--compose --confirm= --dry-run --envelope-sender
2364-
--from --identity
2365-
--in-reply-to --no-chain-reply-to --no-signed-off-by-cc
2366-
--no-suppress-from --no-thread --quiet --reply-to
2367-
--signed-off-by-cc --smtp-pass --smtp-server
2368-
--smtp-server-port --smtp-encryption= --smtp-user
2369-
--subject --suppress-cc= --suppress-from --thread --to
2370-
--validate --no-validate
2371-
$__git_format_patch_extra_options"
2362+
__gitcomp_builtin send-email "$__git_format_patch_extra_options"
23722363
return
23732364
;;
23742365
esac

git-send-email.perl

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ package main;
4040

4141
sub usage {
4242
print <<EOT;
43-
git send-email [options] <file | directory | rev-list options >
43+
git send-email' [<options>] <file|directory>
44+
git send-email' [<options>] <format-patch options>
4445
git send-email --dump-aliases
4546
4647
Composing:
@@ -113,9 +114,38 @@ sub usage {
113114
exit(1);
114115
}
115116

117+
sub uniq {
118+
my %seen;
119+
grep !$seen{$_}++, @_;
120+
}
121+
116122
sub completion_helper {
117-
print Git::command('format-patch', '--git-completion-helper');
118-
exit(0);
123+
my ($original_opts) = @_;
124+
my %not_for_completion = (
125+
"git-completion-helper" => undef,
126+
"h" => undef,
127+
);
128+
my @send_email_opts = ();
129+
130+
foreach my $key (keys %$original_opts) {
131+
unless (exists $not_for_completion{$key}) {
132+
$key =~ s/!$//;
133+
134+
if ($key =~ /[:=][si]$/) {
135+
$key =~ s/[:=][si]$//;
136+
push (@send_email_opts, "--$_=") foreach (split (/\|/, $key));
137+
} else {
138+
push (@send_email_opts, "--$_") foreach (split (/\|/, $key));
139+
}
140+
}
141+
}
142+
143+
my @format_patch_opts = split(/ /, Git::command('format-patch', '--git-completion-helper'));
144+
my @opts = (@send_email_opts, @format_patch_opts);
145+
@opts = uniq (grep !/^$/, @opts);
146+
# There's an implicit '\n' here already, no need to add an explicit one.
147+
print "@opts";
148+
exit(0);
119149
}
120150

121151
# most mail servers generate the Date: header, but not all...
@@ -425,10 +455,11 @@ sub config_regexp {
425455
my $key = "sendemail.identity";
426456
$identity = Git::config(@repo, $key) if exists $known_config_keys{$key};
427457
}
428-
my $rc = GetOptions(
458+
my %identity_options = (
429459
"identity=s" => \$identity,
430460
"no-identity" => \$no_identity,
431461
);
462+
my $rc = GetOptions(%identity_options);
432463
usage() unless $rc;
433464
undef $identity if $no_identity;
434465

@@ -444,14 +475,17 @@ sub config_regexp {
444475

445476
my $help;
446477
my $git_completion_helper;
447-
$rc = GetOptions("h" => \$help,
448-
"dump-aliases" => \$dump_aliases);
478+
my %dump_aliases_options = (
479+
"h" => \$help,
480+
"dump-aliases" => \$dump_aliases,
481+
);
482+
$rc = GetOptions(%dump_aliases_options);
449483
usage() unless $rc;
450484
die __("--dump-aliases incompatible with other options\n")
451485
if !$help and $dump_aliases and @ARGV;
452-
$rc = GetOptions(
486+
my %options = (
453487
"sender|from=s" => \$sender,
454-
"in-reply-to=s" => \$initial_in_reply_to,
488+
"in-reply-to=s" => \$initial_in_reply_to,
455489
"reply-to=s" => \$reply_to,
456490
"subject=s" => \$initial_subject,
457491
"to=s" => \@getopt_to,
@@ -508,15 +542,17 @@ sub config_regexp {
508542
"batch-size=i" => \$batch_size,
509543
"relogin-delay=i" => \$relogin_delay,
510544
"git-completion-helper" => \$git_completion_helper,
511-
);
545+
);
546+
$rc = GetOptions(%options);
512547

513548
# Munge any "either config or getopt, not both" variables
514549
my @initial_to = @getopt_to ? @getopt_to : ($no_to ? () : @config_to);
515550
my @initial_cc = @getopt_cc ? @getopt_cc : ($no_cc ? () : @config_cc);
516551
my @initial_bcc = @getopt_bcc ? @getopt_bcc : ($no_bcc ? () : @config_bcc);
517552

518553
usage() if $help;
519-
completion_helper() if $git_completion_helper;
554+
my %all_options = (%options, %dump_aliases_options, %identity_options);
555+
completion_helper(\%all_options) if $git_completion_helper;
520556
unless ($rc) {
521557
usage();
522558
}

t/t9902-completion.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2148,6 +2148,9 @@ test_expect_success PERL 'send-email' '
21482148
--cover-from-description=Z
21492149
--cover-letter Z
21502150
EOF
2151+
test_completion "git send-email --val" <<-\EOF &&
2152+
--validate Z
2153+
EOF
21512154
test_completion "git send-email ma" "main "
21522155
'
21532156

0 commit comments

Comments
 (0)