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

Re: [PATCH 3/3] completion: fix bugs with slashes in remote names

From
D. Ben Knoble <ben.knoble@gmail.com>
Date
Mar 6, 2025, 20:24 UTC
Message-ID
<CALnO6CBDjQgc2TNaXbBWiUNqWV=RgrL2Ry-7HzRu3Ozuqazzvw@mail.gmail.com>
In-Reply-To
<42dfc06e-8eb1-46da-9971-9d102f1390ad@mandelberg.org>
On Mon, Mar 3, 2025 at 2:25 PM David Mandelberg <david@mandelberg.org> wrote:
Show 24 quoted lines
>
> Op 2025-03-03 om 11:36 schreef phillip.wood123@gmail.com:
> >>> local sed_cmd=
> >>> local remote
> >>> # ref names and therefore remote names cannot contain '*?[]^' so we
> >>> # only need to escape '.$/'. Using 'sort -r' means that if there is a
> >>> # remote called "github" and another called "github/alice" we will try
> >>> # and strip "github/alice" first.
> >>> for remote in $(__git_remotes | sort -r)
> >>> do
> >>>      remote="${remote//./\\./}"
> >>>      remote="${remote//\$/\\\$/}"
> >>>      remote="${remote//\//\\\//}"
> >>
> >> Just FYI since it took me hours to figure this out myself: I think
> >> this would break tests on macos because of an old version of bash that
> >> handles backslashes weirdly. I think removing the double quotes would
> >> work around that issue, and be safe because word splitting doesn't
> >> happen in assignments.
> >
> > Thanks, I'm not familiar with bash's extensions to parameter
> > substitution. The completions can also but used under zsh (git-
> > completion.zsh is pretty much abandoned I think) but it looks like bash
> > and zsh agree on this expansion.

I don't think "abandoned" is the right characterization—at least, it's the completion script that Homebrew-installed Git users will get for Zsh, and it does re-use the Bash completion scripts (which therefore ought to stay portable between both if possible, otherwise we get stuff like 8776470cf3 (completion: repair config completion for Zsh, 2025-01-06)). The Zsh script has seen some fixups over time (such as my own 3c20acdf46 (completion: zsh: stop leaking local cache variable, 2024-04-30)).

>
> The tests don't automatically run under zsh though, right? Maybe I
> should try to figure out how to do that in a separate patch...
Correct—which is how bugs sneak in ;)

I'm willing to manually test the patch if I can understand how to reproduce the issue—it sounds like having a remote name with a slash is sufficient?

I started trying to test Zsh completion a while back when working on one of the patches mentioned above; I got as far as this hack [1], which is to say, not very far at all.

[1]: https://github.com/git/git/commit/d8918195f18a503aa1a42fed3c66a0af8d04131f

-- D. Ben Knoble

Previous: D. Ben KnobleNext: Junio C Hamano
Message 11 of 44 in “completion: fix bugs with slashes in remote names”
  1. 0/3 completion: fix bugs with slashes in remote namesDavid Mandelberg via GitGitGadget, Mar 2, 2025
  2. 1/3 completion: add helper to escape strings for fnmatchDavid Mandelberg via GitGitGadget, Mar 2, 2025
  3. 2/3 completion: add helper to count path componentsDavid Mandelberg via GitGitGadget, Mar 2, 2025
  4. 3/3 completion: fix bugs with slashes in remote namesDavid Mandelberg via GitGitGadget, Mar 2, 2025
  5. Phillip WoodMar 2, 2025
  6. David MandelbergMar 2, 2025
  7. phillip.wood123@gmail.comMar 3, 2025
  8. David MandelbergMar 3, 2025
  9. Todd ZullingerMar 3, 2025
  10. D. Ben KnobleMar 6, 2025
  11. D. Ben KnobleMar 6, 2025
  12. Junio C HamanoMar 6, 2025
  13. phillip.wood123@gmail.comMar 7, 2025
  14. David MandelbergMar 7, 2025
  15. D. Ben KnobleMar 13, 2025
  16. David MandelbergMar 13, 2025
  17. Junio C HamanoMar 3, 2025
  18. SZEDER GáborMar 3, 2025
  19. David MandelbergMar 3, 2025
  20. Junio C HamanoMar 6, 2025
  21. David MandelbergMar 7, 2025
  22. Junio C HamanoMar 7, 2025
  23. David MandelbergMar 7, 2025
  24. Junio C HamanoMar 7, 2025
  25. 0/2 completion: fix bugs with slashes in remote namesDavid Mandelberg, Mar 5, 2025
  26. 1/2 completion: add helper to count path componentsDavid Mandelberg, Mar 5, 2025
  27. 2/2 completion: fix bugs with slashes in remote namesDavid Mandelberg, Mar 5, 2025
  28. David MandelbergMar 5, 2025
  29. Phillip WoodMar 6, 2025
  30. David MandelbergMar 6, 2025
  31. Phillip WoodMar 6, 2025
  32. 0/2 completion: fix bugs with slashes in remote namesDavid Mandelberg, Mar 14, 2025
  33. 1/2 completion: add helper to count path componentsDavid Mandelberg, Mar 14, 2025
  34. 2/2 completion: fix bugs with slashes in remote namesDavid Mandelberg, Mar 14, 2025
  35. Junio C HamanoMar 14, 2025
  36. David MandelbergMar 14, 2025
  37. Junio C HamanoMar 14, 2025
  38. Phillip WoodMar 18, 2025
  39. Junio C HamanoMar 18, 2025
  40. 0/2 completion: fix bugs with slashes in remote namesDavid Mandelberg, Mar 23, 2025
  41. 1/2 completion: add helper to count path componentsDavid Mandelberg, Mar 23, 2025
  42. 2/2 completion: fix bugs with slashes in remote namesDavid Mandelberg, Mar 23, 2025
  43. Phillip WoodApr 8, 2025
  44. David MandelbergApr 8, 2025

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.