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

Re: [RESEND PATCH 2/3] git-completion.bash: fix `git <args>... stash branch` bug

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 19, 2021, 15:53 UTC
Message-ID
<xmqqy2ejnnqp.fsf@gitster.g>
In-Reply-To
<YFRbM1st0yINtScF@generichostname>
Denton Liu <liu.denton@gmail.com> writes:
> Good observation. _git_stash() is called in the body of
> __git_complete_command() which is called by __git_main(). There is
> currently no mechanism by which to pass the index of the command over to
> _git_*() completion functions.

I think, given that "set | grep _git" tells us we use many globals already, it would be OK to introduce another variable, call it $__git_subcmd_pos, and assign to it when the command dispatcher discovers which token on the command line is the subcommand name and decides to call the subcommand specific completion helper function.

Or does the command dispatcher not exactly know the position (e.g. iterates with "for w" and knows $w==stash in the current iteration but it is not counting the position in the array)? If so, then we'd need a surgery larger than that.

But if we only need to set a variable, we won't have to change the calling convention of these helpers (well, we shouldn't be changing the arguments to completion functions lightly anyway---third-party completion functions can be called from __git_complete_command, if I am reading the code correctly, and we cannot update them all even if we wanted to).

And most subcommands that do not care where on the command line the subcommand name is won't have to change anything.

> That being said, passing in the index to all functions would definitely
> be doable. I can work on a series in the future that passes in the index
> of the command so that working with $cword is more robust but I'd prefer
> if that were handled outside this series to keep it focused.

If the breakage of "stash branch" were a serious show-stopper bug that needs to be fixed right away, I would agree that a band-aid solution that would work most of the time would be fine, but I didn't get an impression that it is so urgent and we can afford to fix it right this time, together with the other completion that share the same problem (you mentioned _git_worktree IIRC).

Thanks.
Previous: Denton LiuNext: Denton Liu
Message 9 of 22 in “git-completion.bash: improvements to _git_stash()”
  1. 0/3 git-completion.bash: improvements to _git_stash()Denton Liu, Mar 16, 2021
  2. 1/3 git-completion.bash: extract from else in _git_stash()Denton Liu, Mar 16, 2021
  3. 2/3 git-completion.bash: fix `git <args>... stash branch` bugDenton Liu, Mar 16, 2021
  4. 3/3 git-completion.bash: use __gitcomp_builtin() in _git_stash()Denton Liu, Mar 16, 2021
  5. 0/3 git-completion.bash: improvements to _git_stash()Denton Liu, Mar 18, 2021
  6. 2/3 git-completion.bash: fix `git <args>... stash branch` bugDenton Liu, Mar 18, 2021
  7. Junio C HamanoMar 18, 2021
  8. Denton LiuMar 19, 2021
  9. Junio C HamanoMar 19, 2021
  10. 1/3 git-completion.bash: extract from else in _git_stash()Denton Liu, Mar 18, 2021
  11. 3/3 git-completion.bash: use __gitcomp_builtin() in _git_stash()Denton Liu, Mar 18, 2021
  12. Junio C HamanoMar 18, 2021
  13. Denton LiuMar 19, 2021
  14. Junio C HamanoMar 19, 2021
  15. 0/3 git-completion.bash: improvements to _git_stash()Denton Liu, Mar 24, 2021
  16. 1/3 git-completion.bash: pass $__git_subcommand_idx from __git_main()Denton Liu, Mar 24, 2021
  17. SZEDER GáborMar 27, 2021
  18. SZEDER GáborMar 28, 2021
  19. 3/3 git-completion.bash: use __gitcomp_builtin() in _git_stash()Denton Liu, Mar 24, 2021
  20. SZEDER GáborMar 28, 2021
  21. 2/3 git-completion.bash: extract from else in _git_stash()Denton Liu, Mar 24, 2021
  22. SZEDER GáborMar 28, 2021

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.