git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] completion: complete paths for git send-email

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 19, 2026, 17:04 UTC
Message-ID
<xmqqwluqnc5y.fsf@gitster.g>
In-Reply-To
<20260719134447.381835-1-yury.norov@gmail.com>
"Yury Norov (NVIDIA)" <yury.norov@gmail.com> writes:
Show 14 quoted lines
> 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

Wow. Even though I use nothing but 'git send-email' when sending my own patches, I have never noticed this behavior. I guess that is primarily because I only use the command via my own wrapper script, so the usual bash completion kicks in only for filenames in my workflow. Since I store my patches two levels deep in my working tree (for example, '+outgo/topic/0000-cover-letter.txt'), I suspect that even if I got rid of my wrapper, I would not suffer from this issue. An attempt to run 'git send-email +outgo/contrib-doc/0<TAB>' expanding the trailing '0' into a hexadecimal object name would indeed be quite annoying.

Good find.
> 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.

OK. I will need help from those who are more familiar with our completion code than I am to properly assess this change. Any assistance in reviewing this would be appreciated.

Show 14 quoted lines
> 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" &&

If the initial 'git tag' fails, 'test_when_finished' is never registered, and we end up failing to remove the '000?-example.patch' files. The usual way to write this is:

 - set up 'test_when_finished' with a body that is written to
   succeed even if the clean-up target is not present (your '-f' in
   'rm -f' is good, as it prevents 'rm' from failing even if
   '0001-example.patch' does not get created); then
 - write the test code that dirties the state (requiring clean-up)
   after registering the 'test_when_finished' handler.

That is, "Prepare the clean-up first, and then you do not have to worry about making a mess."

By the way, the use of a purely hexadecimal string as a tag or branch name is highly misleading. What happens if an object exists whose name is identical to that tag? Git offers ways to disambiguate if you really want to, but I do not see any reason for a sensible person or workflow to deliberately place oneself in a situation where such disambiguation becomes necessary.

Of course, that is no excuse for the bug. Our completion script should not misbehave, even when confronted with a workflow that uses funny-looking tags.

Previous: Yury Norov (NVIDIA)Next: D. Ben Knoble
Message 2 of 9 in “completion: complete paths for git send-email”
  1. completion: complete paths for git send-emailYury Norov (NVIDIA), Jul 19, 2026
  2. Junio C HamanoJul 19, 2026
  3. D. Ben KnobleJul 21, 2026
  4. Junio C HamanoJul 21, 2026
  5. Yury NorovJul 21, 2026
  6. Junio C HamanoJul 21, 2026
  7. Ben KnobleJul 22, 2026
  8. Junio C HamanoJul 22, 2026
  9. SZEDER GáborJul 21, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.