Volume XXII, number 279Tuesday, October 6, 2026Latest message 40 minutes ago

The Git List

News and archive of git@vger.kernel.org, since April 2005

patchcompletion: complete paths for git send-email

9 messages between Jul 19, 2026 and Jul 22, 2026, from Yury Norov (NVIDIA), Junio C Hamano, D. Ben Knoble, Yury Norov, SZEDER Gábor, Ben Knoble.

Plain Markdown or JSON for tools and agents. Diffs are folded; open one to read it.

Yury Norov (NVIDIA)Jul 19, 2026, 13:44 UTC on lore
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(-)
Show changes to 2 files +33 −8

contrib/completion/git-completion.bash, t/t9902-completion.sh

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
Junio C HamanoJul 19, 2026, 17:04 UTC in reply to Yury Norov (NVIDIA) on lore

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

"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.

D. Ben KnobleJul 21, 2026, 12:49 UTC in reply to Yury Norov (NVIDIA) on lore

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

On Sun, Jul 19, 2026 at 9:45 AM Yury Norov (NVIDIA) <yury.norov@gmail.com> wrote:

Show 10 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:

It is unusual to call this a "hashtag." Perhaps "hash" or "object name" (or id) based on the glossary and datamodel docs?

Show 69 quoted lines
>  $ 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 "$@"
> +}
> +

Curious; the diff itself is much more readable for me when applied locally (it shows the addition of __gitcomp_file_append and the replacement of a few lines in __gitcomp_file).

Nonetheless, this follows the pattern established by __gitcompadd and __gitcompappend, so that part at least looks like it functions as expected. (I can't comment too much on the code that existed there already.)

Show 8 quoted lines
>  # 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")"

At least with Bash with compgen, this looks to me like it does append file names to the COMPREPLY.

But, with the "hack" comment in the modified function, do we also need to account for older bash? It looks like that comes from 3ffa4df4b2 (completion: add hack to enable file mode in bash < 4, 2013-04-27). After studying a bit more, that hack is to make Bash do the right thing during file completion, not to workaround different methods of generating filenames (unlike Zsh, which has a newer and an older completion system, Bash's seems relatively stable?).

So, I think this looks good.
Show 28 quoted lines
>  }
>
>  _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
Junio commented on the test, so I'll stop here.
Pending a commit message tweak for "hashtag," I'm satisfied enough for
Reviewed-by: D. Ben Knoble <ben.knoble@gmail.com>

(Or feel free to use "Acked-by" if this is not a strong enough review for you/the project!)

-- 
D. Ben Knoble
Junio C HamanoJul 21, 2026, 17:09 UTC in reply to D. Ben Knoble on lore

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

"D. Ben Knoble" <ben.knoble@gmail.com> writes:
Show 15 quoted lines
> On Sun, Jul 19, 2026 at 9:45 AM Yury Norov (NVIDIA)
> <yury.norov@gmail.com> wrote:
>>
>> 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:
>
> It is unusual to call this a "hashtag." Perhaps "hash" or "object
> name" (or id) based on the glossary and datamodel docs?

Very good point, but I am not sure if the author truly meant object names here. The reproduction test uses a long hexadecimal string, but that is not an object name; it is an unusual-looking tag name. It is like naming a topic branch '012345' and complaining that:

    $ git send-email 0<TAB>

completes the input to the branch name while ignoring the 0001-changes.patch file.

When you have a branch named '0-tolerance-policy' and:
    $ git send-email 0<TAB>

completes to that branch name, you would not dream of complaining about the completion. IOW, I think the complaint is somewhat unfair to begin with.

Actually, I do not know if the completion script really expands an abbreviated object name to a full one. I tried:

    $ git rev-parse seen^2
    179eccf0d01729c19a3238905b951b1880aa4ba1
    $ git checkout master
    $ . contrib/completion/git-completion.bash
    $ git send-email 17<TAB>
and waited for some time, but it did not complete to anything.

In any case, when both a '0001-my-changes.patch' file and a '0-tolerance-policy' branch exist in your repository and current working directory, running:

    $ git send-email 0<TAB>

should offer both as candidates, I thihk. Since I only ever pass filenames to the command, I personally do not think it is a huge loss if the completion script stops looking at refs and sticks to filenames only, but others may have a use for that feature.

Yury NorovJul 21, 2026, 18:03 UTC in reply to Junio C Hamano on lore

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

On Tue, Jul 21, 2026 at 10:09:56AM -0700, Junio C Hamano wrote:
Show 19 quoted lines
> "D. Ben Knoble" <ben.knoble@gmail.com> writes:
> 
> > On Sun, Jul 19, 2026 at 9:45 AM Yury Norov (NVIDIA)
> > <yury.norov@gmail.com> wrote:
> >>
> >> 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:
> >
> > It is unusual to call this a "hashtag." Perhaps "hash" or "object
> 
> Very good point, but I am not sure if the author truly meant object
> names here.   > name" (or id) based on the glossary and datamodel docs?
I said hashtag because for me it's a hash of the tag:

git send-email 0<TAB> git send-email 05c69d298c96703741cac9a5cbbf6c53bd55a6e2

But also it's a name of the tag, and git warns about it:
  $ git show 05c69d298c96703741cac9a5cbbf6c53bd55a6e2
  warning: refname '05c69d298c96703741cac9a5cbbf6c53bd55a6e2' is ambiguous.
  Git normally never creates a ref that ends with 40 hex characters
  because it will be ignored when you just specify 40-hex. These refs
  may be created by mistake. For example,
  
    git switch -c $br $(git rev-parse ...)
  
  where "$br" is somehow empty and a 40-hex ref is created. Please
  examine these refs and maybe delete them. Turn this message off by
  running "git config set advice.objectNameWarning false"
  commit 05c69d298c96703741cac9a5cbbf6c53bd55a6e2 (tag: 05c69d298c96703741cac9a5cbbf6c53bd55a6e2)
  Author: Tejun Heo <tj@kernel.org>
  Date:   Tue May 15 08:22:04 2012 +0200
  ...

I have no local branch or local file with that name, but the tag exists for 14 years, and will not go away. And yes, it breaks autocompletion.

So, after rethinking, the problem looks like this: if autocompletion logic finds a tag beginning with that pattern, it doesn't attempt to search for the matching files, which is wrong

Show 38 quoted lines
> The reproduction test uses a long hexadecimal string,
> but that is not an object name; it is an unusual-looking tag name.
> It is like naming a topic branch '012345' and complaining that:
> 
>     $ git send-email 0<TAB>
> 
> completes the input to the branch name while ignoring the
> 0001-changes.patch file.
> 
> When you have a branch named '0-tolerance-policy' and:
> 
>     $ git send-email 0<TAB>
> 
> completes to that branch name, you would not dream of complaining
> about the completion.  IOW, I think the complaint is somewhat unfair
> to begin with.
> 
> Actually, I do not know if the completion script really expands an
> abbreviated object name to a full one.  I tried:
> 
>     $ git rev-parse seen^2
>     179eccf0d01729c19a3238905b951b1880aa4ba1
>     $ git checkout master
>     $ . contrib/completion/git-completion.bash
>     $ git send-email 17<TAB>
> 
> and waited for some time, but it did not complete to anything.
> 
> In any case, when both a '0001-my-changes.patch' file and a
> '0-tolerance-policy' branch exist in your repository and current
> working directory, running:
> 
>     $ git send-email 0<TAB>
> 
> should offer both as candidates, I thihk.  Since I only ever pass
> filenames to the command, I personally do not think it is a huge
> loss if the completion script stops looking at refs and sticks to
> filenames only, but others may have a use for that feature.

Agree. The test should create a file 0001.patch, then a tag 0-tag, then a branch 0-branch, maybe something else that is relevant; and then make sure every option is correctly offered by autocompletion.

Guys please let me know if everything else is needed before I send v2.

Thanks, Yury

Junio C HamanoJul 21, 2026, 19:22 UTC in reply to Yury Norov on lore

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

Yury Norov <ynorov@nvidia.com> writes:
Show 17 quoted lines
>> In any case, when both a '0001-my-changes.patch' file and a
>> '0-tolerance-policy' branch exist in your repository and current
>> working directory, running:
>> 
>>     $ git send-email 0<TAB>
>> 
>> should offer both as candidates, I thihk.  Since I only ever pass
>> filenames to the command, I personally do not think it is a huge
>> loss if the completion script stops looking at refs and sticks to
>> filenames only, but others may have a use for that feature.
>
> Agree. The test should create a file 0001.patch, then a tag
> 0-tag, then a branch 0-branch, maybe something else that is
> relevant; and then make sure every option is correctly offered
> by autocompletion.
>
> Guys please let me know if everything else is needed before I send v2.

So in short, we want the problem description updated to something like:

   When branches and tags whose names share the same prefix as a
   file (or a directory???) that stores a patch exist, the attempt
   to complete that shared prefix
       $ git send-email that-shared-prefix<TAB>
   should offer both branches, tags, and files (and directories???).
   But the completion only offers branches and tags and fails to
   offer files.

And the description of the solution would follow after that in the proposed log message.

As to the tests, using 40-hex is misleading, and 0-branch as you said would be sufficient to reproduce and demonstrate the issue, and that your code change fixes it.

Ben, anything I missed?
Thanks.
SZEDER GáborJul 21, 2026, 22:21 UTC in reply to Junio C Hamano on lore

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

On Tue, Jul 21, 2026 at 10:09:56AM -0700, Junio C Hamano wrote:
Show 46 quoted lines
> "D. Ben Knoble" <ben.knoble@gmail.com> writes:
> 
> > On Sun, Jul 19, 2026 at 9:45 AM Yury Norov (NVIDIA)
> > <yury.norov@gmail.com> wrote:
> >>
> >> 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:
> >
> > It is unusual to call this a "hashtag." Perhaps "hash" or "object
> > name" (or id) based on the glossary and datamodel docs?
> 
> Very good point, but I am not sure if the author truly meant object
> names here.  The reproduction test uses a long hexadecimal string,
> but that is not an object name; it is an unusual-looking tag name.
> It is like naming a topic branch '012345' and complaining that:
> 
>     $ git send-email 0<TAB>
> 
> completes the input to the branch name while ignoring the
> 0001-changes.patch file.
> 
> When you have a branch named '0-tolerance-policy' and:
> 
>     $ git send-email 0<TAB>
> 
> completes to that branch name, you would not dream of complaining
> about the completion.  IOW, I think the complaint is somewhat unfair
> to begin with.
> 
> Actually, I do not know if the completion script really expands an
> abbreviated object name to a full one.  I tried:
> 
>     $ git rev-parse seen^2
>     179eccf0d01729c19a3238905b951b1880aa4ba1
>     $ git checkout master
>     $ . contrib/completion/git-completion.bash
>     $ git send-email 17<TAB>
> 
> and waited for some time, but it did not complete to anything.

We definietely don't do that. I'm not sure what the use-case would be for completing full object names, but considering how many objects a repo might contain, I doubt it can be usable for anything.

Show 10 quoted lines
> In any case, when both a '0001-my-changes.patch' file and a
> '0-tolerance-policy' branch exist in your repository and current
> working directory, running:
> 
>     $ git send-email 0<TAB>
> 
> should offer both as candidates, I thihk.  Since I only ever pass
> filenames to the command, I personally do not think it is a huge
> loss if the completion script stops looking at refs and sticks to
> filenames only, but others may have a use for that feature.

There are a couple of similar Git commands that accept both refs and paths, "diff" and "log" being the obvious examples, and our completion script doesn't list refs and paths for any of them, only refs [1].

I think that's intentional, because:
  - It's easier to pick the ref you want from a list containing only
    refs than from a list of refs and paths mixed together, because
    the list to choose from is shorter, and the unique prefix is
    likely shorter as well.
    The same goes for picking the path you want from a list containing
    only paths.
  - Even when our completion script only lists refs for a particular
    command, it's easy to trigger Bash's filename completion via one
    of the following methods:
      - git diff ./foo<TAB>  # No ref can start with "./".
      - git log foo<ALT-/>   # Bash/readline's keybinding to trigger
                             # filename completion.
      - git log -- foo<TAB>  # No --options or refs after the
                             # disambiguating doubledash.
    Although I'm not sure "git send-email" supports the disambiguating
    doubledash; its completion function surely doesn't.
  - There is no similarly easy way to trigger refs completion.
[1] There are a couple of (sub)commands, like "git worktree add" or
    "git bungle create", where our completion script lists either
    paths or refs (but never both) depending on what's already on the
    command line.  But both of these expect a single path followed by
    a single ref or any revision arguments, so we can unambigously
    figure out when to list paths and when to list refs.  With "diff",
    "log" and "send-email" this is not possible, because they accept
    any revision arguments followed by paths.
Ben KnobleJul 22, 2026, 10:29 UTC in reply to Junio C Hamano on lore

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

Show 41 quoted lines
> Le 21 juil. 2026 à 15:22, Junio C Hamano <gitster@pobox.com> a écrit :
> 
> Yury Norov <ynorov@nvidia.com> writes:
> 
>>> In any case, when both a '0001-my-changes.patch' file and a
>>> '0-tolerance-policy' branch exist in your repository and current
>>> working directory, running:
>>>   $ git send-email 0<TAB>
>>> should offer both as candidates, I thihk.  Since I only ever pass
>>> filenames to the command, I personally do not think it is a huge
>>> loss if the completion script stops looking at refs and sticks to
>>> filenames only, but others may have a use for that feature.
>> Agree. The test should create a file 0001.patch, then a tag
>> 0-tag, then a branch 0-branch, maybe something else that is
>> relevant; and then make sure every option is correctly offered
>> by autocompletion.
>> Guys please let me know if everything else is needed before I send v2.
> 
> So in short, we want the problem description updated to something
> like:
> 
>  When branches and tags whose names share the same prefix as a
>  file (or a directory???) that stores a patch exist, the attempt
>  to complete that shared prefix
> 
>      $ git send-email that-shared-prefix<TAB>
> 
>  should offer both branches, tags, and files (and directories???).
>  But the completion only offers branches and tags and fails to
>  offer files.
> 
> And the description of the solution would follow after that in the
> proposed log message.
> 
> As to the tests, using 40-hex is misleading, and 0-branch as you
> said would be sufficient to reproduce and demonstrate the issue, and
> that your code change fixes it.
> 
> Ben, anything I missed?
> 
> Thanks.
Not from my end, though SZEDER’s review merits some thinking.
Traveling the next week+; replies may be slower (than usual, hah).
Junio C HamanoJul 22, 2026, 15:32 UTC in reply to Ben Knoble on lore

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

Ben Knoble <ben.knoble@gmail.com> writes:
Show 9 quoted lines
>> As to the tests, using 40-hex is misleading, and 0-branch as you
>> said would be sufficient to reproduce and demonstrate the issue, and
>> that your code change fixes it.
>> 
>> Ben, anything I missed?
>> 
>> Thanks.
>
> Not from my end, though SZEDER’s review merits some thinking.

I agree that presenting both refs and paths cleanly will require a much better structure than a flat list. I also agree that hiding paths when we have ref matches may give us a cleaner layout than mixing them alphabetically into a single, flat list. While I am still not convinced it is the best way, at least that is the principle current completion implementations use for other commands, and it makes sense to model the updated completion for send-email after it.

That said, since I never feed refs to send-email myself, 'if we have matches with refs, do not show paths at all' rule makes send-email completion completely useless, at least to me.

> Traveling the next week+; replies may be slower (than usual, hah).
Have a great trip, and have fun!
Thanks.

Back to recent threads