From: "Yury Norov (NVIDIA)" <yury.norov@gmail.com>
To: git@vger.kernel.org, "Thiago Perrotta" <tbperrotta@gmail.com>,
"Philippe Blain" <levraiphilippeblain@gmail.com>,
"Junio C Hamano" <gitster@pobox.com>,
"Rubén Justo" <rjusto@gmail.com>
Cc: Yury Norov <ynorov@nvidia.com>,
linux-kernel@vger.kernel.org, Yury Norov <yury.norov@gmail.com>,
Codex <codex@openai.com>
Subject: [PATCH] completion: complete paths for git send-email
Date: Sun, 19 Jul 2026 09:44:47 -0400 [thread overview]
Message-ID: <20260719134447.381835-1-yury.norov@gmail.com> (raw)
From: Yury Norov <ynorov@nvidia.com>
git send-email accepts either revisions or paths to patch files, but its
Bash completion only offers revisions. This prevents patch files from
being completed. It can also make a prefix such as "0" expand to an
unrelated hexadecimal ref even when matching 0001-*.patch files exist.
In my Linux tree, an attempt to autocomplete the standard-named patch
brings a random hashtag:
$ ls 0*
0001-bitmap-drop-bitmap_next_set_region.patch
$ git send-email 0<Tab>
$ git send-email 05c69d298c96703741cac9a5cbbf6c53bd55a6e2
Introduce an append variant of __gitcomp_file() and use it to add
filesystem candidates after the existing revision candidates. Keep the
latter because revisions remain valid send-email arguments.
Add a regression test covering patch files alongside a 40-hex ref.
Assisted-by: Codex <codex@openai.com>
Signed-off-by: Yury Norov <ynorov@nvidia.com>
---
contrib/completion/git-completion.bash | 29 +++++++++++++++++++-------
t/t9902-completion.sh | 12 ++++++++++-
2 files changed, 33 insertions(+), 8 deletions(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index e87578771..b7017488d 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -579,21 +579,18 @@ __gitcomp_file_direct ()
}
# Generates completion reply with compgen from newline-separated possible
-# completion filenames.
+# completion filenames by appending them to the existing list of completion
+# candidates, COMPREPLY.
# It accepts 1 to 3 arguments:
# 1: List of possible completion filenames, separated by a single newline.
# 2: A directory prefix to be added to each possible completion filename
# (optional).
# 3: Generate possible completion matches for this word (optional).
-__gitcomp_file ()
+__gitcomp_file_append ()
{
local IFS=$'\n'
- # XXX does not work when the directory prefix contains a tilde,
- # since tilde expansion is not applied.
- # This means that COMPREPLY will be empty and Bash default
- # completion will be used.
- __gitcompadd "$1" "${2-}" "${3-$cur}" ""
+ __gitcompappend "$1" "${2-}" "${3-$cur}" ""
# use a hack to enable file mode in bash < 4
compopt -o filenames +o nospace 2>/dev/null ||
@@ -601,6 +598,23 @@ __gitcomp_file ()
true
}
+# Generates completion reply with compgen from newline-separated possible
+# completion filenames.
+# It accepts 1 to 3 arguments:
+# 1: List of possible completion filenames, separated by a single newline.
+# 2: A directory prefix to be added to each possible completion filename
+# (optional).
+# 3: Generate possible completion matches for this word (optional).
+__gitcomp_file ()
+{
+ # XXX does not work when the directory prefix contains a tilde,
+ # since tilde expansion is not applied.
+ # This means that COMPREPLY will be empty and Bash default
+ # completion will be used.
+ COMPREPLY=()
+ __gitcomp_file_append "$@"
+}
+
# Find the current subcommand for commands that follow the syntax:
#
# git <command> <subcommand>
@@ -2634,6 +2648,7 @@ _git_send_email ()
;;
esac
__git_complete_revlist
+ __gitcomp_file_append "$(compgen -f -- "$cur")"
}
_git_stage ()
diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh
index 55dc9eabf..e87827f21 100755
--- a/t/t9902-completion.sh
+++ b/t/t9902-completion.sh
@@ -2777,7 +2777,17 @@ test_expect_success PERL 'send-email' '
test_completion "git send-email --val" <<-\EOF &&
--validate Z
EOF
- test_completion "git send-email ma" "main "
+ test_completion "git send-email ma" "main " &&
+
+ git tag 05c69d298c96703741cac9a5cbbf6c53bd55a6e2 &&
+ test_when_finished "git tag -d 05c69d298c96703741cac9a5cbbf6c53bd55a6e2 &&
+ rm -f 0001-example.patch 0002-example.patch" &&
+ touch 0001-example.patch 0002-example.patch &&
+ test_completion "git send-email 0" <<-\EOF
+ 0001-example.patch
+ 0002-example.patch
+ 05c69d298c96703741cac9a5cbbf6c53bd55a6e2 Z
+ EOF
'
test_expect_success 'complete files' '
--
2.53.0
next reply other threads:[~2026-07-19 13:44 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-19 13:44 Yury Norov (NVIDIA) [this message]
2026-07-19 17:04 ` [PATCH] completion: complete paths for git send-email Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260719134447.381835-1-yury.norov@gmail.com \
--to=yury.norov@gmail.com \
--cc=codex@openai.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=levraiphilippeblain@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=rjusto@gmail.com \
--cc=tbperrotta@gmail.com \
--cc=ynorov@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox