threads / patch / 20949

patch, 4 partsbash: rename __git_find_subcommand() to __git_find_on_cmdline()

Subject: [PATCH 1/4] bash: rename __git_find_subcommand() to __git_find_on_cmdline()

## tl;dr

7 messages between Sep 15, 2009 and Sep 24, 2009. Diffs are folded; open one to read it.

replies: 6people: 2as markdown or json

SZEDER Gábor· Sep 15, 2009, 10:21 UTC · lore

__git_find_subcommand() was originally meant to check whether subcommands are already present on the command line. But the code is general enough to be used for checking the presence of command line options as well, and the next commit will use it for that purpose, so let's give it a more general name.

Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
---
 contrib/completion/git-completion.bash |   14 +++++++-------
 1 files changed, 7 insertions(+), 7 deletions(-)
Show changes to contrib/completion/git-completion.bash +7 −7
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index f47c519..c539385 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -619,8 +619,8 @@ __git_aliased_command ()
 	done
 }
 
-# __git_find_subcommand requires 1 argument
-__git_find_subcommand ()
+# __git_find_on_cmdline requires 1 argument
+__git_find_on_cmdline ()
 {
 	local word subcommand c=1
 
@@ -739,7 +739,7 @@ _git_bisect ()
 	__git_has_doubledash && return
 
 	local subcommands="start bad good skip reset visualize replay log run"
-	local subcommand="$(__git_find_subcommand "$subcommands")"
+	local subcommand="$(__git_find_on_cmdline "$subcommands")"
 	if [ -z "$subcommand" ]; then
 		__gitcomp "$subcommands"
 		return
@@ -1751,7 +1751,7 @@ _git_config ()
 _git_remote ()
 {
 	local subcommands="add rename rm show prune update set-head"
-	local subcommand="$(__git_find_subcommand "$subcommands")"
+	local subcommand="$(__git_find_on_cmdline "$subcommands")"
 	if [ -z "$subcommand" ]; then
 		__gitcomp "$subcommands"
 		return
@@ -1879,7 +1879,7 @@ _git_show_branch ()
 _git_stash ()
 {
 	local subcommands='save list show apply clear drop pop create branch'
-	local subcommand="$(__git_find_subcommand "$subcommands")"
+	local subcommand="$(__git_find_on_cmdline "$subcommands")"
 	if [ -z "$subcommand" ]; then
 		__gitcomp "$subcommands"
 	else
@@ -1910,7 +1910,7 @@ _git_submodule ()
 	__git_has_doubledash && return
 
 	local subcommands="add status init update summary foreach sync"
-	if [ -z "$(__git_find_subcommand "$subcommands")" ]; then
+	if [ -z "$(__git_find_on_cmdline "$subcommands")" ]; then
 		local cur="${COMP_WORDS[COMP_CWORD]}"
 		case "$cur" in
 		--*)
@@ -1932,7 +1932,7 @@ _git_svn ()
 		proplist show-ignore show-externals branch tag blame
 		migrate
 		"
-	local subcommand="$(__git_find_subcommand "$subcommands")"
+	local subcommand="$(__git_find_on_cmdline "$subcommands")"
 	if [ -z "$subcommand" ]; then
 		__gitcomp "$subcommands"
 	else
-- 
1.6.5.rc1.92.gee3c1
SZEDER Gábor· Sep 15, 2009, 10:21 UTC · re: SZEDER Gábor · lore

[PATCH 2/4] bash: update 'git stash' completion

This update adds 'git stash (apply|pop) --quiet' and all options known to 'git stash save', and handles the DWIMery from 3c2eb80f (stash: simplify defaulting to "save" and reject unknown options, 2009-08-18). Care is taken to avoid offering subcommands in the DWIM case.

Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
---
 contrib/completion/git-completion.bash |   20 ++++++++++++++++----
 1 files changed, 16 insertions(+), 4 deletions(-)
Show changes to contrib/completion/git-completion.bash +16 −4
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index c539385..2529cec 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -1878,18 +1878,30 @@ _git_show_branch ()
 
 _git_stash ()
 {
+	local cur="${COMP_WORDS[COMP_CWORD]}"
+	local save_opts='--keep-index --no-keep-index --quiet --patch'
 	local subcommands='save list show apply clear drop pop create branch'
 	local subcommand="$(__git_find_on_cmdline "$subcommands")"
 	if [ -z "$subcommand" ]; then
-		__gitcomp "$subcommands"
+		case "$cur" in
+		--*)
+			__gitcomp "$save_opts"
+			;;
+		*)
+			if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
+				__gitcomp "$subcommands"
+			else
+				COMPREPLY=()
+			fi
+			;;
+		esac
 	else
-		local cur="${COMP_WORDS[COMP_CWORD]}"
 		case "$subcommand,$cur" in
 		save,--*)
-			__gitcomp "--keep-index"
+			__gitcomp "$save_opts"
 			;;
 		apply,--*|pop,--*)
-			__gitcomp "--index"
+			__gitcomp "--index --quiet"
 			;;
 		show,--*|drop,--*|branch,--*)
 			COMPREPLY=()
-- 
1.6.5.rc1.92.gee3c1
SZEDER Gábor· Sep 15, 2009, 10:21 UTC · re: SZEDER Gábor · lore

[PATCH 3/4] bash: teach 'git reset --patch'

Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
---
 contrib/completion/git-completion.bash |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
Show changes to contrib/completion/git-completion.bash +1 −1
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 2529cec..8c268a1 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -1782,7 +1782,7 @@ _git_reset ()
 	local cur="${COMP_WORDS[COMP_CWORD]}"
 	case "$cur" in
 	--*)
-		__gitcomp "--merge --mixed --hard --soft"
+		__gitcomp "--merge --mixed --hard --soft --patch"
 		return
 		;;
 	esac
-- 
1.6.5.rc1.92.gee3c1
SZEDER Gábor· Sep 15, 2009, 10:21 UTC · re: SZEDER Gábor · lore

[PATCH 4/4] bash: teach 'git checkout' options

Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
---
 contrib/completion/git-completion.bash |   13 ++++++++++++-
 1 files changed, 12 insertions(+), 1 deletions(-)
Show changes to contrib/completion/git-completion.bash +12 −1
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 8c268a1..8e3cdbd 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -809,7 +809,18 @@ _git_checkout ()
 {
 	__git_has_doubledash && return
 
-	__gitcomp "$(__git_refs)"
+	local cur="${COMP_WORDS[COMP_CWORD]}"
+	case "$cur" in
+	--*)
+		__gitcomp "
+			--quiet --ours --theirs --track --no-track --merge
+			--conflict= --patch
+			"
+		;;
+	*)
+		__gitcomp "$(__git_refs)"
+		;;
+	esac
 }
 
 _git_cherry ()
-- 
1.6.5.rc1.92.gee3c1
Shawn O. Pearce· Sep 22, 2009, 15:28 UTC · re: SZEDER Gábor · lore

Re: [PATCH 4/4] bash: teach 'git checkout' options

SZEDER G??bor <szeder@ira.uka.de> wrote:
Show 11 quoted lines
> @@ -809,7 +809,18 @@ _git_checkout ()
>  {
>  	__git_has_doubledash && return
>  
> -	__gitcomp "$(__git_refs)"
> +	local cur="${COMP_WORDS[COMP_CWORD]}"
> +	case "$cur" in
> +	--*)
> +		__gitcomp "
> +			--quiet --ours --theirs --track --no-track --merge
> +			--conflict= --patch

If we are completing long options, shouldn't we also complete the supported values for --conflict? According to the docs, this is 'merge' and 'diff3'.

-- 
Shawn.
SZEDER Gábor· Sep 24, 2009, 12:23 UTC · re: Shawn O. Pearce · lore

[PATCHv2] bash: teach 'git checkout' options

Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
---
 contrib/completion/git-completion.bash |   16 +++++++++++++++-
 1 files changed, 15 insertions(+), 1 deletions(-)
Show changes to contrib/completion/git-completion.bash +15 −1
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 8c268a1..a08e471 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -809,7 +809,21 @@ _git_checkout ()
 {
 	__git_has_doubledash && return
 
-	__gitcomp "$(__git_refs)"
+	local cur="${COMP_WORDS[COMP_CWORD]}"
+	case "$cur" in
+	--conflict=*)
+		__gitcomp "diff3 merge" "" "${cur##--conflict=}"
+		;;
+	--*)
+		__gitcomp "
+			--quiet --ours --theirs --track --no-track --merge
+			--conflict= --patch
+			"
+		;;
+	*)
+		__gitcomp "$(__git_refs)"
+		;;
+	esac
 }
 
 _git_cherry ()
-- 
1.6.5.rc2.85.gd02ad
Shawn O. Pearce· Sep 22, 2009, 15:29 UTC · re: SZEDER Gábor · lore

Re: [PATCH 3/4] bash: teach 'git reset --patch'

SZEDER G??bor <szeder@ira.uka.de> wrote:
> Signed-off-by: SZEDER G??bor <szeder@ira.uka.de>
> ---
>  contrib/completion/git-completion.bash |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
1-3 of this series are:
Trivially-acked-by: Shawn O. Pearce <spearce@spearce.org>
 
-- 
Shawn.

← back to recent threads