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

Re: [PATCH v3 2/2] completion: bash: check for alias loop

From
SZEDER Gábor <szeder.dev@gmail.com>
Date
Nov 12, 2020, 10:02 UTC
Message-ID
<20201112100204.GC4270@szeder.dev>
In-Reply-To
<20201110020343.548848-3-felipe.contreras@gmail.com>
On Mon, Nov 09, 2020 at 08:03:43PM -0600, Felipe Contreras wrote:
Show 20 quoted lines
> We don't want to be stuck in an endless cycle.
> 
> Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
> ---
>  contrib/completion/git-completion.bash | 11 ++++++++---
>  1 file changed, 8 insertions(+), 3 deletions(-)
> 
> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
> index eb00d9ba22..ce0dc1e0f8 100644
> --- a/contrib/completion/git-completion.bash
> +++ b/contrib/completion/git-completion.bash
> @@ -1121,11 +1121,16 @@ __git_pretty_aliases ()
>  # __git_aliased_command requires 1 argument
>  __git_aliased_command ()
>  {
> -	local cur=$1 last word cmdline
> +	local cur=$1 list word cmdline
>  
>  	while [[ -n "$cur" ]]; do
> +		if [[ "$list" == *"$cur "* ]]; then
I suspect the right hand side should be *" $cur "* ...
Show 7 quoted lines
> +			# loop detected
> +			return
> +		fi
> +
>  		cmdline=$(__git config --get "alias.$cur")
> -		last=$cur
> +		list="$cur $list"

... and this should be list=" $cur $list", because otherwise a partial match is possible and would be mistaken for a loop (though I didn't actually test whether that's indeed the case).

Show 15 quoted lines
>  		cur=
>  
>  		for word in $cmdline; do
> @@ -1149,7 +1154,7 @@ __git_aliased_command ()
>  		done
>  	done
>  
> -	cur=$last
> +	cur="${list%% *}"
>  	if [[ "$cur" != "$1" ]]; then
>  		echo "$cur"
>  	fi
> -- 
> 2.29.2
> 
Previous: Felipe ContrerasNext: Junio C Hamano
Message 4 of 5 in “completion: bash: support for recursive aliases”
  1. 0/2 completion: bash: support for recursive aliasesFelipe Contreras, Nov 10, 2020
  2. 1/2 completion: bash: support recursive aliasesFelipe Contreras, Nov 10, 2020
  3. 2/2 completion: bash: check for alias loopFelipe Contreras, Nov 10, 2020
  4. SZEDER GáborNov 12, 2020
  5. Junio C HamanoNov 12, 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.