{"thread":{"id":"65302","subject":"[PATCH 1/1] git-send-email.perl: support executable scripts for recipient options","startedAt":"2026-03-19T15:52:05Z","lastAt":"2026-03-20T01:36:01Z","messageCount":4,"participants":["Jim Cromie","Kristoffer Haugsbakk","D. Ben Knoble","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":1},"messages":[{"id":"539392","messageId":"20260319155148.1145135-1-jim.cromie@gmail.com","threadId":"65302","inReplyTo":null,"subject":"[PATCH 1/1] git-send-email.perl: support executable scripts for recipient options","fromName":"Jim Cromie","fromEmail":"jim.cromie@gmail.com","sentAt":"2026-03-19T15:51:48Z","receivedAt":"2026-03-19T15:52:05Z","isPatch":true,"sender":{"key":"jim.cromie@gmail.com","avatar":null},"body":"Enhance git-send-email to recognize executable scripts passed to --to,\n--cc, or --bcc. When a recipient argument is an executable file, run it\nin a subshell and use its output as the recipient list.\n\nThis allows users to automate recipient selection using scripts like\nget_maintainer.pl in the Linux kernel. The script is called with the\ncorresponding flag (--to, --cc, or --bcc) and all remaining command-line\narguments (typically the patches being sent).\n\nModify execute_cmd() to support multiple arguments safely using\nquotemeta. Add test cases to verify the new functionality and ensure\narguments are correctly passed to the scripts.\n\nCo-developed-by: Gemini CLI <gemini-cli@google.com>\nSigned-off-by: Jim Cromie <jim.cromie@gmail.com>\n---\n git-send-email.perl   | 11 +++++++++--\n t/t9001-send-email.sh | 42 ++++++++++++++++++++++++++++++++++++++++++\n 2 files changed, 51 insertions(+), 2 deletions(-)\n\ndiff --git a/git-send-email.perl b/git-send-email.perl\nindex bb8ddd1eef..2d54d98304 100755\n--- a/git-send-email.perl\n+++ b/git-send-email.perl\n@@ -579,8 +579,11 @@ sub config_regexp {\n \n # Munge any \"either config or getopt, not both\" variables\n my @initial_to = @getopt_to ? @getopt_to : ($no_to ? () : @config_to);\n+@initial_to = map { (-x $_) ? execute_cmd(\"to-script\", $_, \"--to\", @ARGV) : $_ } @initial_to;\n my @initial_cc = @getopt_cc ? @getopt_cc : ($no_cc ? () : @config_cc);\n+@initial_cc = map { (-x $_) ? execute_cmd(\"cc-script\", $_, \"--cc\", @ARGV) : $_ } @initial_cc;\n my @initial_bcc = @getopt_bcc ? @getopt_bcc : ($no_bcc ? () : @config_bcc);\n+@initial_bcc = map { (-x $_) ? execute_cmd(\"bcc-script\", $_, \"--bcc\", @ARGV) : $_ } @initial_bcc;\n \n usage() if $help;\n my %all_options = (%options, %dump_aliases_options, %identity_options);\n@@ -2222,10 +2225,14 @@ sub initialize_modified_loop_vars {\n # lines which do not appear at the end of the output are reported as\n # errors.\n sub execute_cmd {\n-\tmy ($prefix, $cmd, $file) = @_;\n+\tmy ($prefix, $cmd, @args) = @_;\n \tmy @lines = ();\n \tmy $seen_blank_line = 0;\n-\topen my $fh, \"-|\", \"$cmd \\Q$file\\E\"\n+\tmy $full_cmd = $cmd;\n+\tfor my $arg (@args) {\n+\t\t$full_cmd .= \" \" . quotemeta($arg);\n+\t}\n+\topen my $fh, \"-|\", $full_cmd\n \t\tor die sprintf(__(\"(%s) Could not execute '%s'\"), $prefix, $cmd);\n \twhile (my $line = <$fh>) {\n \t\tdie sprintf(__(\"(%s) Malformed output from '%s'\"), $prefix, $cmd)\ndiff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh\nindex 24f6c76aee..fed75c7669 100755\n--- a/t/t9001-send-email.sh\n+++ b/t/t9001-send-email.sh\n@@ -2842,4 +2842,46 @@ test_expect_success $PREREQ '--compose handles to headers' '\n \ttest_cmp expect msgtxt2.to\n '\n \n+test_expect_success $PREREQ '--cc=$script' '\n+\tgit init repo &&\n+\t(\n+\t\tcd repo &&\n+\t\ttest_commit commit &&\n+\t\tpatches=$(git format-patch -1 HEAD) &&\n+\t\twrite_script cc-script <<-\\EOT &&\n+\t\techo \"cc-script@example.com\"\n+\t\tEOT\n+\t\tPERL5LIB=\"$GIT_BUILD_DIR/perl\" \"$GIT_BUILD_DIR/git-send-email.perl\" \\\n+\t\t\t--from=\"Example <from@example.com>\" \\\n+\t\t\t--to=nobody@example.com \\\n+\t\t\t--cc=./cc-script \\\n+\t\t\t--smtp-server=\"$(pwd)/../fake.sendmail\" \\\n+\t\t\t--confirm=never \\\n+\t\t\t--dry-run \\\n+\t\t\t$patches >stdout 2>&1 &&\n+\t\tgrep \"^Cc: cc-script@example\\.com\" stdout\n+\t)\n+'\n+\n+test_expect_success $PREREQ '--cc=$script with arguments' '\n+\tgit init repo-args &&\n+\t(\n+\t\tcd repo-args &&\n+\t\ttest_commit commit &&\n+\t\tpatches=$(git format-patch -1 HEAD) &&\n+\t\twrite_script cc-script-args <<-\\EOT &&\n+\t\techo \"script-args-$2@example.com\"\n+\t\tEOT\n+\t\tPERL5LIB=\"$GIT_BUILD_DIR/perl\" \"$GIT_BUILD_DIR/git-send-email.perl\" \\\n+\t\t\t--from=\"Example <from@example.com>\" \\\n+\t\t\t--to=nobody@example.com \\\n+\t\t\t--cc=./cc-script-args \\\n+\t\t\t--smtp-server=\"$(pwd)/../fake.sendmail\" \\\n+\t\t\t--confirm=never \\\n+\t\t\t--dry-run \\\n+\t\t\t$patches >stdout 2>&1 &&\n+\t\tgrep \"^Cc: script-args-0001-commit\\.patch@example\\.com\" stdout\n+\t)\n+'\n+\n test_done\n-- \n2.53.0\n\n"},{"id":"539395","messageId":"14840d8a-a1cb-4499-ba78-295c778e90d1@app.fastmail.com","threadId":"65302","inReplyTo":"20260319155148.1145135-1-jim.cromie@gmail.com","subject":"Re: [PATCH 1/1] git-send-email.perl: support executable scripts for recipient options","fromName":"Kristoffer Haugsbakk","fromEmail":"kristofferhaugsbakk@fastmail.com","sentAt":"2026-03-19T16:05:37Z","receivedAt":"2026-03-19T16:06:09Z","isPatch":true,"sender":{"key":"kristofferhaugsbakk@fastmail.com","avatar":null},"body":"On Thu, Mar 19, 2026, at 16:51, Jim Cromie wrote:\n> Enhance git-send-email to recognize executable scripts passed to --to,\n> --cc, or --bcc. When a recipient argument is an executable file, run it\n> in a subshell and use its output as the recipient list.\n>\n> This allows users to automate recipient selection using scripts like\n> get_maintainer.pl in the Linux kernel. The script is called with the\n> corresponding flag (--to, --cc, or --bcc) and all remaining command-line\n> arguments (typically the patches being sent).\n>\n> Modify execute_cmd() to support multiple arguments safely using\n> quotemeta. Add test cases to verify the new functionality and ensure\n> arguments are correctly passed to the scripts.\n>\n> Co-developed-by: Gemini CLI <gemini-cli@google.com>\n\nThese are for people who can be emailed.\n\nBut you’ve CCd them as well. Or was that git-send-email(1)’s action?\n\n> Signed-off-by: Jim Cromie <jim.cromie@gmail.com>\n> ---\n>[snip]\n\nWhat’s the difference between this and `--cc-cmd` and similar? I\nwouldn’t know, I don’t use these `--*cmd` options.\n"},{"id":"539404","messageId":"CALnO6CAZqAacTPgwTzAyF-ryyQxaWahXmpfCt9R_+vLS0o5uAA@mail.gmail.com","threadId":"65302","inReplyTo":"14840d8a-a1cb-4499-ba78-295c778e90d1@app.fastmail.com","subject":"Re: [PATCH 1/1] git-send-email.perl: support executable scripts for recipient options","fromName":"D. Ben Knoble","fromEmail":"ben.knoble@gmail.com","sentAt":"2026-03-19T16:47:58Z","receivedAt":"2026-03-19T16:48:10Z","isPatch":true,"sender":{"key":"ben.knoble@gmail.com","avatar":"https://avatars.githubusercontent.com/u/22802209?v=4"},"body":"On Thu, Mar 19, 2026 at 12:13 PM Kristoffer Haugsbakk\n<kristofferhaugsbakk@fastmail.com> wrote:\n>\n> On Thu, Mar 19, 2026, at 16:51, Jim Cromie wrote:\n> > Enhance git-send-email to recognize executable scripts passed to --to,\n> > --cc, or --bcc. When a recipient argument is an executable file, run it\n> > in a subshell and use its output as the recipient list.\n> >\n> > This allows users to automate recipient selection using scripts like\n> > get_maintainer.pl in the Linux kernel. The script is called with the\n> > corresponding flag (--to, --cc, or --bcc) and all remaining command-line\n> > arguments (typically the patches being sent).\n> >\n> > Modify execute_cmd() to support multiple arguments safely using\n> > quotemeta. Add test cases to verify the new functionality and ensure\n> > arguments are correctly passed to the scripts.\n> >\n> > Co-developed-by: Gemini CLI <gemini-cli@google.com>\n>\n> These are for people who can be emailed.\n>\n> But you’ve CCd them as well. Or was that git-send-email(1)’s action?\n>\n> > Signed-off-by: Jim Cromie <jim.cromie@gmail.com>\n> > ---\n> >[snip]\n>\n> What’s the difference between this and `--cc-cmd` and similar? I\n> wouldn’t know, I don’t use these `--*cmd` options.\n\nThe only difference I can think of is that we have --cc-cmd, --to-cmd,\nbut not --bcc-cmd.\n\n(I use --cc-cmd via config set to git-contacts for git.git so that\npatches mostly CC the right folks, but I typically have to manually\ntrack and add discussion participants, which is a bit of a pain.)\n\n-- \nD. Ben Knoble\n"},{"id":"539463","messageId":"xmqqms03gu4g.fsf@gitster.g","threadId":"65302","inReplyTo":"CALnO6CAZqAacTPgwTzAyF-ryyQxaWahXmpfCt9R_+vLS0o5uAA@mail.gmail.com","subject":"Re: [PATCH 1/1] git-send-email.perl: support executable scripts for recipient options","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-03-20T01:35:59Z","receivedAt":"2026-03-20T01:36:01Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"D. Ben Knoble\" <ben.knoble@gmail.com> writes:\n\n>> What’s the difference between this and `--cc-cmd` and similar? I\n>> wouldn’t know, I don’t use these `--*cmd` options.\n>\n> The only difference I can think of is that we have --cc-cmd, --to-cmd,\n> but not --bcc-cmd.\n>\n> (I use --cc-cmd via config set to git-contacts for git.git so that\n> patches mostly CC the right folks, but I typically have to manually\n> track and add discussion participants, which is a bit of a pain.)\n\nIf we were inventing git-send-email today without existing users at\nall, we might have appreciated the simplicity of \"it is easy to tell\nif the argument to --cc and other options is a name of an executable\nfile on disk, so do the obvious thing depending\", but this came way\ntoo late, I would have to say.\n"}]}