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

Re: [PATCH 2/3] bash completion: refactor --strategy completion

From
Shawn O. Pearce <spearce@spearce.org>
Date
Mar 6, 2009, 16:04 UTC
Message-ID
<20090306160452.GH16213@spearce.org>
In-Reply-To
<2d83927582e9eed004b9fd12b77105a184277229.1236314073.git.jaysoffian@gmail.com>
Jay Soffian <jaysoffian@gmail.com> wrote:
Show 5 quoted lines
> The code to complete --strategy was duplicated between _git_rebase and
> _git_merge, and is about to gain a third caller (_git_pull). This patch
> factors it into its own function.
> 
> Signed-off-by: Jay Soffian <jaysoffian@gmail.com>

Looks OK to me, but I had to squash this in to get it to work. Without this the patch breaks git merge completion entirely:

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 9e16576..80d464b 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -449,15 +449,15 @@ __git_complete_strategy ()
 	case "${COMP_WORDS[COMP_CWORD-1]}" in
 	-s|--strategy)
 		__gitcomp "$(__git_merge_strategies)"
-		return 1
+		return 0
 	esac
 	case "$cur" in
 	--strategy=*)
 		__gitcomp "$(__git_merge_strategies)" "" "${cur##--strategy=}"
-		return 1
+		return 0
 		;;
 	esac
-	return 0
+	return 1
 }
 
 __git_all_commands ()
@@ -1111,9 +1111,8 @@ _git_log ()
 
 _git_merge ()
 {
-	__git_complete_strategy && return
-
 	local cur="${COMP_WORDS[COMP_CWORD]}"
+	__git_complete_strategy && return
 	case "$cur" in
 	--*)
 		__gitcomp "

> ---
>  contrib/completion/git-completion.bash |   37 ++++++++++++++++---------------
>  1 files changed, 19 insertions(+), 18 deletions(-)
> 
> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
> index b347fdd..8924185 100755
> --- a/contrib/completion/git-completion.bash
> +++ b/contrib/completion/git-completion.bash
> @@ -440,6 +440,22 @@ __git_complete_remote_or_refspec ()
>  	esac
>  }
>  
> +__git_complete_strategy ()
> +{
> +	case "${COMP_WORDS[COMP_CWORD-1]}" in
> +	-s|--strategy)
> +		__gitcomp "$(__git_merge_strategies)"
> +		return 1
> +	esac
> +	case "$cur" in
> +	--strategy=*)
> +		__gitcomp "$(__git_merge_strategies)" "" "${cur##--strategy=}"
> +		return 1
> +		;;
> +	esac
> +	return 0
> +}
> +
>  __git_all_commands ()
>  {
>  	if [ -n "$__git_all_commandlist" ]; then
> @@ -1086,17 +1102,10 @@ _git_log ()
>  
>  _git_merge ()
>  {
> +	__git_complete_strategy && return
> +
>  	local cur="${COMP_WORDS[COMP_CWORD]}"
> -	case "${COMP_WORDS[COMP_CWORD-1]}" in
> -	-s|--strategy)
> -		__gitcomp "$(__git_merge_strategies)"
> -		return
> -	esac
>  	case "$cur" in
> -	--strategy=*)
> -		__gitcomp "$(__git_merge_strategies)" "" "${cur##--strategy=}"
> -		return
> -		;;
>  	--*)
>  		__gitcomp "
>  			--no-commit --no-stat --log --no-log --squash --strategy
> @@ -1165,16 +1174,8 @@ _git_rebase ()
>  		__gitcomp "--continue --skip --abort"
>  		return
>  	fi
> -	case "${COMP_WORDS[COMP_CWORD-1]}" in
> -	-s|--strategy)
> -		__gitcomp "$(__git_merge_strategies)"
> -		return
> -	esac
> +	__git_complete_strategy && return
>  	case "$cur" in
> -	--strategy=*)
> -		__gitcomp "$(__git_merge_strategies)" "" "${cur##--strategy=}"
> -		return
> -		;;
>  	--*)
>  		__gitcomp "--onto --merge --strategy --interactive"
>  		return
> -- 
> 1.6.2.rc2.332.g5d21b
> 
-- 
Shawn.
Previous: Jay SoffianNext: Jay Soffian
Message 7 of 14 in “improve bash completion of fetch, pull, and push”
  1. 0/3 improve bash completion of fetch, pull, and pushJay Soffian, Mar 6, 2009
  2. 1/3 bash completion: fix completion issues with fetch, pull, and pushJay Soffian, Mar 6, 2009
  3. Shawn O. PearceMar 6, 2009
  4. Nanako ShiraishiMar 11, 2009
  5. Jay SoffianMar 11, 2009
  6. 2/3 bash completion: refactor --strategy completionJay Soffian, Mar 6, 2009
  7. Shawn O. PearceMar 6, 2009
  8. Jay SoffianMar 6, 2009
  9. Shawn O. PearceMar 6, 2009
  10. Jay SoffianMar 6, 2009
  11. Shawn O. PearceMar 6, 2009
  12. 3/3 bash completion: teach fetch, pull, and push to complete their optionsJay Soffian, Mar 6, 2009
  13. Shawn O. PearceMar 6, 2009
  14. Sverre RabbelierMar 6, 2009

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.