# [PATCH 1/1] git-send-email.perl: support executable scripts for recipient options

4 messages from 2026-03-19 to 2026-03-20. Participants: Jim Cromie, Kristoffer Haugsbakk, D. Ben Knoble, Junio C Hamano.
Thread: https://gitlist.dev/t/65302

## Jim Cromie, 2026-03-19 15:51

Subject: [PATCH 1/1] git-send-email.perl: support executable scripts for recipient options
Message-ID: <20260319155148.1145135-1-jim.cromie@gmail.com>
URL: https://gitlist.dev/e/20260319155148.1145135-1-jim.cromie%40gmail.com

```
Enhance git-send-email to recognize executable scripts passed to --to,
--cc, or --bcc. When a recipient argument is an executable file, run it
in a subshell and use its output as the recipient list.

This allows users to automate recipient selection using scripts like
get_maintainer.pl in the Linux kernel. The script is called with the
corresponding flag (--to, --cc, or --bcc) and all remaining command-line
arguments (typically the patches being sent).

Modify execute_cmd() to support multiple arguments safely using
quotemeta. Add test cases to verify the new functionality and ensure
arguments are correctly passed to the scripts.

Co-developed-by: Gemini CLI <gemini-cli@google.com>
Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
---
 git-send-email.perl   | 11 +++++++++--
 t/t9001-send-email.sh | 42 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 51 insertions(+), 2 deletions(-)

diff --git a/git-send-email.perl b/git-send-email.perl
index bb8ddd1eef..2d54d98304 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -579,8 +579,11 @@ sub config_regexp {
 
 # Munge any "either config or getopt, not both" variables
 my @initial_to = @getopt_to ? @getopt_to : ($no_to ? () : @config_to);
+@initial_to = map { (-x $_) ? execute_cmd("to-script", $_, "--to", @ARGV) : $_ } @initial_to;
 my @initial_cc = @getopt_cc ? @getopt_cc : ($no_cc ? () : @config_cc);
+@initial_cc = map { (-x $_) ? execute_cmd("cc-script", $_, "--cc", @ARGV) : $_ } @initial_cc;
 my @initial_bcc = @getopt_bcc ? @getopt_bcc : ($no_bcc ? () : @config_bcc);
+@initial_bcc = map { (-x $_) ? execute_cmd("bcc-script", $_, "--bcc", @ARGV) : $_ } @initial_bcc;
 
 usage() if $help;
 my %all_options = (%options, %dump_aliases_options, %identity_options);
@@ -2222,10 +2225,14 @@ sub initialize_modified_loop_vars {
 # lines which do not appear at the end of the output are reported as
 # errors.
 sub execute_cmd {
-	my ($prefix, $cmd, $file) = @_;
+	my ($prefix, $cmd, @args) = @_;
 	my @lines = ();
 	my $seen_blank_line = 0;
-	open my $fh, "-|", "$cmd \Q$file\E"
+	my $full_cmd = $cmd;
+	for my $arg (@args) {
+		$full_cmd .= " " . quotemeta($arg);
+	}
+	open my $fh, "-|", $full_cmd
 		or die sprintf(__("(%s) Could not execute '%s'"), $prefix, $cmd);
 	while (my $line = <$fh>) {
 		die sprintf(__("(%s) Malformed output from '%s'"), $prefix, $cmd)
diff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh
index 24f6c76aee..fed75c7669 100755
--- a/t/t9001-send-email.sh
+++ b/t/t9001-send-email.sh
@@ -2842,4 +2842,46 @@ test_expect_success $PREREQ '--compose handles to headers' '
 	test_cmp expect msgtxt2.to
 '
 
+test_expect_success $PREREQ '--cc=$script' '
+	git init repo &&
+	(
+		cd repo &&
+		test_commit commit &&
+		patches=$(git format-patch -1 HEAD) &&
+		write_script cc-script <<-\EOT &&
+		echo "cc-script@example.com"
+		EOT
+		PERL5LIB="$GIT_BUILD_DIR/perl" "$GIT_BUILD_DIR/git-send-email.perl" \
+			--from="Example <from@example.com>" \
+			--to=nobody@example.com \
+			--cc=./cc-script \
+			--smtp-server="$(pwd)/../fake.sendmail" \
+			--confirm=never \
+			--dry-run \
+			$patches >stdout 2>&1 &&
+		grep "^Cc: cc-script@example\.com" stdout
+	)
+'
+
+test_expect_success $PREREQ '--cc=$script with arguments' '
+	git init repo-args &&
+	(
+		cd repo-args &&
+		test_commit commit &&
+		patches=$(git format-patch -1 HEAD) &&
+		write_script cc-script-args <<-\EOT &&
+		echo "script-args-$2@example.com"
+		EOT
+		PERL5LIB="$GIT_BUILD_DIR/perl" "$GIT_BUILD_DIR/git-send-email.perl" \
+			--from="Example <from@example.com>" \
+			--to=nobody@example.com \
+			--cc=./cc-script-args \
+			--smtp-server="$(pwd)/../fake.sendmail" \
+			--confirm=never \
+			--dry-run \
+			$patches >stdout 2>&1 &&
+		grep "^Cc: script-args-0001-commit\.patch@example\.com" stdout
+	)
+'
+
 test_done
-- 
2.53.0


```

## Kristoffer Haugsbakk, 2026-03-19 16:05

Subject: Re: [PATCH 1/1] git-send-email.perl: support executable scripts for recipient options
Message-ID: <14840d8a-a1cb-4499-ba78-295c778e90d1@app.fastmail.com>
URL: https://gitlist.dev/e/14840d8a-a1cb-4499-ba78-295c778e90d1%40app.fastmail.com
In-Reply-To: <20260319155148.1145135-1-jim.cromie@gmail.com>

```
On Thu, Mar 19, 2026, at 16:51, Jim Cromie wrote:
> Enhance git-send-email to recognize executable scripts passed to --to,
> --cc, or --bcc. When a recipient argument is an executable file, run it
> in a subshell and use its output as the recipient list.
>
> This allows users to automate recipient selection using scripts like
> get_maintainer.pl in the Linux kernel. The script is called with the
> corresponding flag (--to, --cc, or --bcc) and all remaining command-line
> arguments (typically the patches being sent).
>
> Modify execute_cmd() to support multiple arguments safely using
> quotemeta. Add test cases to verify the new functionality and ensure
> arguments are correctly passed to the scripts.
>
> Co-developed-by: Gemini CLI <gemini-cli@google.com>

These are for people who can be emailed.

But you’ve CCd them as well. Or was that git-send-email(1)’s action?

> Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
> ---
>[snip]

What’s the difference between this and `--cc-cmd` and similar? I
wouldn’t know, I don’t use these `--*cmd` options.

```

## D. Ben Knoble, 2026-03-19 16:47

Subject: Re: [PATCH 1/1] git-send-email.perl: support executable scripts for recipient options
Message-ID: <CALnO6CAZqAacTPgwTzAyF-ryyQxaWahXmpfCt9R_+vLS0o5uAA@mail.gmail.com>
URL: https://gitlist.dev/e/CALnO6CAZqAacTPgwTzAyF-ryyQxaWahXmpfCt9R_%2BvLS0o5uAA%40mail.gmail.com
In-Reply-To: <14840d8a-a1cb-4499-ba78-295c778e90d1@app.fastmail.com>

```
On Thu, Mar 19, 2026 at 12:13 PM Kristoffer Haugsbakk
<kristofferhaugsbakk@fastmail.com> wrote:
>
> On Thu, Mar 19, 2026, at 16:51, Jim Cromie wrote:
> > Enhance git-send-email to recognize executable scripts passed to --to,
> > --cc, or --bcc. When a recipient argument is an executable file, run it
> > in a subshell and use its output as the recipient list.
> >
> > This allows users to automate recipient selection using scripts like
> > get_maintainer.pl in the Linux kernel. The script is called with the
> > corresponding flag (--to, --cc, or --bcc) and all remaining command-line
> > arguments (typically the patches being sent).
> >
> > Modify execute_cmd() to support multiple arguments safely using
> > quotemeta. Add test cases to verify the new functionality and ensure
> > arguments are correctly passed to the scripts.
> >
> > Co-developed-by: Gemini CLI <gemini-cli@google.com>
>
> These are for people who can be emailed.
>
> But you’ve CCd them as well. Or was that git-send-email(1)’s action?
>
> > Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
> > ---
> >[snip]
>
> What’s the difference between this and `--cc-cmd` and similar? I
> wouldn’t know, I don’t use these `--*cmd` options.

The only difference I can think of is that we have --cc-cmd, --to-cmd,
but not --bcc-cmd.

(I use --cc-cmd via config set to git-contacts for git.git so that
patches mostly CC the right folks, but I typically have to manually
track and add discussion participants, which is a bit of a pain.)

-- 
D. Ben Knoble

```

## Junio C Hamano, 2026-03-20 01:35

Subject: Re: [PATCH 1/1] git-send-email.perl: support executable scripts for recipient options
Message-ID: <xmqqms03gu4g.fsf@gitster.g>
URL: https://gitlist.dev/e/xmqqms03gu4g.fsf%40gitster.g
In-Reply-To: <CALnO6CAZqAacTPgwTzAyF-ryyQxaWahXmpfCt9R_+vLS0o5uAA@mail.gmail.com>

```
"D. Ben Knoble" <ben.knoble@gmail.com> writes:

>> What’s the difference between this and `--cc-cmd` and similar? I
>> wouldn’t know, I don’t use these `--*cmd` options.
>
> The only difference I can think of is that we have --cc-cmd, --to-cmd,
> but not --bcc-cmd.
>
> (I use --cc-cmd via config set to git-contacts for git.git so that
> patches mostly CC the right folks, but I typically have to manually
> track and add discussion participants, which is a bit of a pain.)

If we were inventing git-send-email today without existing users at
all, we might have appreciated the simplicity of "it is easy to tell
if the argument to --cc and other options is a name of an executable
file on disk, so do the obvious thing depending", but this came way
too late, I would have to say.

```
