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

Re: [PATCH 2/2] completion: complete tracked paths for "git checkout"

From
Ben Knoble <ben.knoble@gmail.com>
Date
Aug 11, 2026, 16:32 UTC
Message-ID
<834FE315-FB34-47B7-9ACF-FC8194FBE8D5@gmail.com>
In-Reply-To
<xmqqmrut4a1l.fsf@gitster.g>
Show 37 quoted lines
> 
> Le 10 août 2026 à 23:21, Junio C Hamano <gitster@pobox.com> a écrit :
> 
> When completing arguments for "git checkout", _git_checkout()
> delegates to __git_complete_refs(), which only completes revision
> references.  This is good, as mixing revisions and paths in a single
> list from which the user can choose is confusing.  However, if no
> reference matches, or if "--" is given, _git_checkout() leaves
> COMPREPLY empty.  Bash then falls back to the default filename
> completion in $PWD.
> 
> This fails when "git -C <path>" is used, as $PWD is not the target
> repository.
> 
> Update _git_checkout() to use __git_complete_index_file() when "--"
> is present, or when revision reference completion yields no matching
> candidates, so that tracked paths are offered as candidates.
> 
> Signed-off-by: Junio C Hamano <gitster@pobox.com>
> ---
> contrib/completion/git-completion.bash |  4 ++++
> t/t9902-completion.sh                  | 27 ++++++++++++++++++++++++++
> 2 files changed, 31 insertions(+)
> 
> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
> index 38dec1cabe..bd4b6e9247 100644
> --- a/contrib/completion/git-completion.bash
> +++ b/contrib/completion/git-completion.bash
> @@ -1780,6 +1780,10 @@ _git_checkout ()
>            ;;
>        esac
>    fi
> +
> +    if [ ${#COMPREPLY[@]} -eq 0 ]; then
> +        __git_complete_index_file
> +    fi
> }
Assuming the prior step was purely mechanical, which I did not validate, this looks reasonable to me. 
Previous: Junio C HamanoNext: Junio C Hamano
Message 4 of 19 in “completion of 'git [-C <dir>] checkout'”
  1. 0/2 completion of 'git [-C <dir>] checkout'Junio C Hamano, Aug 11, 2026
  2. 1/2 completion: no-op refactoring of checkout completionJunio C Hamano, Aug 11, 2026
  3. 2/2 completion: complete tracked paths for "git checkout"Junio C Hamano, Aug 11, 2026
  4. Ben KnobleAug 11, 2026
  5. Junio C HamanoAug 11, 2026
  6. Junio C HamanoAug 11, 2026
  7. Ben KnobleAug 11, 2026
  8. Junio C HamanoAug 12, 2026
  9. 0/3 completion of 'git [-C <dir>] checkout'Junio C Hamano, Aug 12, 2026
  10. 1/3 completion: no-op refactoring of checkout completionJunio C Hamano, Aug 12, 2026
  11. 2/3 completion: complete tracked paths for "git checkout"Junio C Hamano, Aug 12, 2026
  12. 3/3 completion: 'git checkout' completes untracked paths as a last resortJunio C Hamano, Aug 12, 2026
  13. Elijah NewrenAug 12, 2026
  14. Junio C HamanoAug 12, 2026
  15. 0/3 completion of 'git [-C <dir>] checkout'Junio C Hamano, Aug 13, 2026
  16. 1/3 completion: no-op refactoring of checkout completionJunio C Hamano, Aug 13, 2026
  17. 2/3 completion: complete tracked paths for "git checkout"Junio C Hamano, Aug 13, 2026
  18. 3/3 completion: 'git checkout' completes untracked paths as a last resortJunio C Hamano, Aug 13, 2026
  19. Elijah NewrenAug 14, 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.