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

[PATCH v2 0/2] completion: add a GIT_COMPLETION_SHOW_ALL_COMMANDS

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Feb 2, 2022, 11:15 UTC
Message-ID
<cover-v2-0.2-00000000000-20220202T111228Z-avarab@gmail.com>
In-Reply-To
<patch-1.1-5f18305ca08-20220125T124757Z-avarab@gmail.com>

This series adds an opt-in configuration to make "git <TAB>" complete the likes of "cat-file" (plumbing), in addition to the existing completion for the likes of "status" (porcelain).

This v2 addresses feedback from Junio on the v1, I also added a preceding patch to change the re-sourcing of git-completion.bash in some existing tests to use a subshell, which is a pattern I'd buggily copied in the v1.

Ævar Arnfjörð Bjarmason (2):
  completion tests: re-source git-completion.bash in a subshell
  completion: add a GIT_COMPLETION_SHOW_ALL_COMMANDS
 contrib/completion/git-completion.bash | 13 ++++-
 t/t9902-completion.sh                  | 81 +++++++++++++++++++-------
 2 files changed, 72 insertions(+), 22 deletions(-)
Range-diff against v1:
-:  ----------- > 1:  cf09546e079 completion tests: re-source git-completion.bash in a subshell
1:  5f18305ca08 ! 2:  2e2e3569e02 completion: add a GIT_COMPLETION_SHOW_ALL_COMMANDS
    @@ Commit message
         completion with git <TAB>, respectively.
     
         It was already possible to do this by tweaking
    -    GIT_COMPLETION_SHOW_ALL_COMMANDS from the outside, that testing
    +    GIT_TESTING_PORCELAIN_COMMAND_LIST= from the outside, that testing
         variable was added in 84a97131065 (completion: let git provide the
         completable command list, 2018-05-20). Doing this before loading
         git-completion.bash worked:
    @@ Commit message
         and we make no guarantees that those internal won't change. So let's
         expose this as a dedicated configuration knob.
     
    +    It would be better to teach --list-cmds=* a new category which would
    +    include all of these groups, but that's a larger change that we can
    +    leave for some other time.
    +
         1. https://lore.kernel.org/git/CAGP6POJ9gwp+t-eP3TPkivBLLbNb2+qj=61Mehcj=1BgrVOSLA@mail.gmail.com/
     
         Reported-by: Hongyi Zhao <hongyi.zhao@gmail.com>
    @@ contrib/completion/git-completion.bash: __git_main ()
     
      ## t/t9902-completion.sh ##
     @@ t/t9902-completion.sh: test_expect_success 'option aliases are shown with GIT_COMPLETION_SHOW_ALL' '
    - 	EOF
    + 	)
      '
      
     +test_expect_success 'plumbing commands are excluded without GIT_COMPLETION_SHOW_ALL_COMMANDS' '
    -+	. "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" &&
    -+	sane_unset GIT_TESTING_PORCELAIN_COMMAND_LIST &&
    ++	(
    ++		. "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" &&
    ++		sane_unset GIT_TESTING_PORCELAIN_COMMAND_LIST &&
     +
    -+	# Just mainporcelain, not plumbing commands
    -+	run_completion "git c" &&
    -+	grep checkout out &&
    -+	! grep cat-file out
    ++		# Just mainporcelain, not plumbing commands
    ++		run_completion "git c" &&
    ++		grep checkout out &&
    ++		! grep cat-file out
    ++	)
     +'
     +
     +test_expect_success 'all commands are shown with GIT_COMPLETION_SHOW_ALL_COMMANDS (also main non-builtin)' '
    -+	. "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" &&
    -+	GIT_COMPLETION_SHOW_ALL_COMMANDS=1 &&
    -+	export GIT_COMPLETION_SHOW_ALL_COMMANDS &&
    -+	sane_unset GIT_TESTING_PORCELAIN_COMMAND_LIST &&
    ++	(
    ++		. "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" &&
    ++		GIT_COMPLETION_SHOW_ALL_COMMANDS=1 &&
    ++		export GIT_COMPLETION_SHOW_ALL_COMMANDS &&
    ++		sane_unset GIT_TESTING_PORCELAIN_COMMAND_LIST &&
     +
    -+	# Both mainporcelain and plumbing commands
    -+	run_completion "git c" &&
    -+	grep checkout out &&
    -+	grep cat-file out &&
    ++		# Both mainporcelain and plumbing commands
    ++		run_completion "git c" &&
    ++		grep checkout out &&
    ++		grep cat-file out &&
     +
    -+	# Check "gitk", a "main" command, but not a built-in + more plumbing
    -+	run_completion "git g" &&
    -+	grep gitk out &&
    -+	grep get-tar-commit-id out
    ++		# Check "gitk", a "main" command, but not a built-in + more plumbing
    ++		run_completion "git g" &&
    ++		grep gitk out &&
    ++		grep get-tar-commit-id out
    ++	)
     +'
     +
      test_expect_success '__git_complete' '
-- 
2.35.0.913.g12b4baa2536
Previous: Junio C HamanoNext: Ævar Arnfjörð Bjarmason
Message 11 of 17 in “Some sub-commands can't be completed by TAB key.”
  1. Hongyi ZhaoJan 22, 2022
  2. Johannes SixtJan 22, 2022
  3. Hongyi ZhaoJan 23, 2022
  4. Philippe BlainJan 23, 2022
  5. Junio C HamanoJan 23, 2022
  6. Hongyi ZhaoJan 24, 2022
  7. João Victor BonfimJan 24, 2022
  8. Junio C HamanoJan 25, 2022
  9. completion: add a GIT_COMPLETION_SHOW_ALL_COMMANDSÆvar Arnfjörð Bjarmason, Jan 25, 2022
  10. Junio C HamanoJan 26, 2022
  11. 0/2 completion: add a GIT_COMPLETION_SHOW_ALL_COMMANDSÆvar Arnfjörð Bjarmason, Feb 2, 2022
  12. 1/2 completion tests: re-source git-completion.bash in a subshellÆvar Arnfjörð Bjarmason, Feb 2, 2022
  13. 2/2 completion: add a GIT_COMPLETION_SHOW_ALL_COMMANDSÆvar Arnfjörð Bjarmason, Feb 2, 2022
  14. SZEDER GáborFeb 6, 2022
  15. Junio C HamanoFeb 6, 2022
  16. SZEDER GáborFeb 6, 2022
  17. Junio C HamanoFeb 7, 2022

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.