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

Re: [PATCH] commit: correctly escape @ of stashes

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 6, 2020, 06:39 UTC
Message-ID
<xmqqv9j19mgn.fsf@gitster.c.googlers.com>
In-Reply-To
<pull.815.git.git.1593768655179.gitgitgadget@gmail.com>
"Martin Bektchiev via GitGitGadget" <gitgitgadget@gmail.com> writes:
> From: Martin Bektchiev <martin.bektchiev@progress.com>
>
> Autocomplete suggestions for stashes are broken due to `stash@`
> being suggested without escaping.

What is unclear to readers of this sentence is why '@' needs to be quoted in the first place. '@' is not like '$' that has a syntactic significance to the shell.

In fact, I just tried
    $ git stash show stas<TAB>

in a test repository where there is only one stash entry and got it completed to

    $ git stash show stash@{0}

and pressing <Enter> from this state did exactly what I expected to see.

> Reproducible on `GNU bash, version 3.2.57(1)-release` and
> `macOS Catalina 10.15.5`.

What did you reproduce? The completion gave me "stash@{0}" (without surrounding double quotes) in my above experiment? If so, that does seem reproducible, but I do not see "suggestions ... are broken" here.

Show 7 quoted lines
> @@ -2999,12 +2999,14 @@ _git_stash ()
>  				__git_complete_refs
>  			else
>  				__gitcomp_nl "$(__git stash list \
> -						| sed -n -e 's/:.*//p')"
> +						| sed -n -e 's/:.*//p' \
> +						| sed 's/@/\\@/')"

This is not a new problem introduced by this patch, but we should get rid of these unnecessary backslashes and pipe at the beginning of the second line, both of which make the resulting code harder than necessary to read. Ending the line with '|' pipe would give enough clue to the shell that you haven't finished talking to it, and you can continue to the next line without any backslashes just fine.

Show 7 quoted lines
>  			fi
>  			;;
>  		show,*|apply,*|drop,*|pop,*)
>  			__gitcomp_nl "$(__git stash list \
> -					| sed -n -e 's/:.*//p')"
> +					| sed -n -e 's/:.*//p' \
> +					| sed 's/@/\\@/')"
Ditto.
Show 5 quoted lines
>  			;;
>  		*)
>  			;;
>
> base-commit: a08a83db2bf27f015bec9a435f6d73e223c21c5e
Previous: Martin Bektchiev via GitGitGadgetNext: Johannes Schindelin
Message 2 of 5 in “commit: correctly escape @ of stashes”
  1. commit: correctly escape @ of stashesMartin Bektchiev via GitGitGadget, Jul 3, 2020
  2. Junio C HamanoJul 6, 2020
  3. Johannes SchindelinJul 6, 2020
  4. Junio C HamanoJul 8, 2020
  5. Johannes SchindelinJul 9, 2020

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.