Skip to contentSkip to conversation

Support --strategy=x completion in addition to --strategy x.

PATCH New Shawn O. Pearce 1 participant 1 message Aug 11, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/4 Support --strategy=x completion in addition to --strategy x.

Because git-merge and git-rebase both accept -s, --strategy or --strategy= we should recognize all three formats in the bash completion functions and issue back all merge strategies on demand.

I also moved the prior word testing to be before the current word testing, as the current word cannot be completed with -- if the prior word was an option which requires a parameter, such as -s or --strategy.

---
 contrib/completion/git-completion.bash |   30 ++++++++++++++++++++----------
 1 files changed, 20 insertions(+), 10 deletions(-)
contrib/completion/git-completion.bash +20 -10
index a957165..e53f040 100755
@@ -455,18 +455,23 @@ _git_log ()
 _git_merge ()
 {
 	local cur="${COMP_WORDS[COMP_CWORD]}"
+	case "${COMP_WORDS[COMP_CWORD-1]}" in
+	-s|--strategy)
+		COMPREPLY=($(compgen -W "$(__git_merge_strategies)" -- "$cur"))
+		return
+	esac
 	case "$cur" in
+	--strategy=*)
+		COMPREPLY=($(compgen -W "$(__git_merge_strategies)" \
+			-- "${cur##--strategy=}"))
+		return
+		;;
 	--*)
 		COMPREPLY=($(compgen -W "
 			--no-commit --no-summary --squash --strategy
 			" -- "$cur"))
 		return
 	esac
-	case "${COMP_WORDS[COMP_CWORD-1]}" in
-	-s|--strategy)
-		COMPREPLY=($(compgen -W "$(__git_merge_strategies)" -- "$cur"))
-		return
-	esac
 	COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
 }
 
@@ -543,18 +548,23 @@ _git_rebase ()
 			" -- "$cur"))
 		return
 	fi
+	case "${COMP_WORDS[COMP_CWORD-1]}" in
+	-s|--strategy)
+		COMPREPLY=($(compgen -W "$(__git_merge_strategies)" -- "$cur"))
+		return
+	esac
 	case "$cur" in
+	--strategy=*)
+		COMPREPLY=($(compgen -W "$(__git_merge_strategies)" \
+			-- "${cur##--strategy=}"))
+		return
+		;;
 	--*)
 		COMPREPLY=($(compgen -W "
 			--onto --merge --strategy
 			" -- "$cur"))
 		return
 	esac
-	case "${COMP_WORDS[COMP_CWORD-1]}" in
-	-s|--strategy)
-		COMPREPLY=($(compgen -W "$(__git_merge_strategies)" -- "$cur"))
-		return
-	esac
 	COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
 }
 
Signature · 1 line
1.4.4.1.ge3fb