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

7 messages from 2009-09-15 to 2009-09-24. Participants: SZEDER Gábor, Shawn O. Pearce.
Thread: https://gitlist.dev/t/20949

## SZEDER Gábor, 2009-09-15 10:21

Subject: [PATCH 1/4] bash: rename __git_find_subcommand() to __git_find_on_cmdline()
Message-ID: <e927e4d3bfe50d93e5e6d65c46821158332b37f9.1253009868.git.szeder@ira.uka.de>
URL: https://gitlist.dev/e/e927e4d3bfe50d93e5e6d65c46821158332b37f9.1253009868.git.szeder%40ira.uka.de

```
__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(-)

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, 2009-09-15 10:21

Subject: [PATCH 2/4] bash: update 'git stash' completion
Message-ID: <0d125e60b97ab58ad51fef170fd36b707a271a10.1253009868.git.szeder@ira.uka.de>
URL: https://gitlist.dev/e/0d125e60b97ab58ad51fef170fd36b707a271a10.1253009868.git.szeder%40ira.uka.de
In-Reply-To: <e927e4d3bfe50d93e5e6d65c46821158332b37f9.1253009868.git.szeder@ira.uka.de>

```
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(-)

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, 2009-09-15 10:21

Subject: [PATCH 3/4] bash: teach 'git reset --patch'
Message-ID: <ccf129a01115027ee7438ac47f1bc35631a1b2bb.1253009868.git.szeder@ira.uka.de>
URL: https://gitlist.dev/e/ccf129a01115027ee7438ac47f1bc35631a1b2bb.1253009868.git.szeder%40ira.uka.de
In-Reply-To: <0d125e60b97ab58ad51fef170fd36b707a271a10.1253009868.git.szeder@ira.uka.de>

```
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
---
 contrib/completion/git-completion.bash |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

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, 2009-09-15 10:21

Subject: [PATCH 4/4] bash: teach 'git checkout' options
Message-ID: <7c8c4f6a4c581bcba101b8ca467d241738aa376e.1253009868.git.szeder@ira.uka.de>
URL: https://gitlist.dev/e/7c8c4f6a4c581bcba101b8ca467d241738aa376e.1253009868.git.szeder%40ira.uka.de
In-Reply-To: <ccf129a01115027ee7438ac47f1bc35631a1b2bb.1253009868.git.szeder@ira.uka.de>

```
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
---
 contrib/completion/git-completion.bash |   13 ++++++++++++-
 1 files changed, 12 insertions(+), 1 deletions(-)

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, 2009-09-22 15:28

Subject: Re: [PATCH 4/4] bash: teach 'git checkout' options
Message-ID: <20090922152846.GQ14660@spearce.org>
URL: https://gitlist.dev/e/20090922152846.GQ14660%40spearce.org
In-Reply-To: <7c8c4f6a4c581bcba101b8ca467d241738aa376e.1253009868.git.szeder@ira.uka.de>

```
SZEDER G??bor <szeder@ira.uka.de> wrote:
> @@ -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.

```

## Shawn O. Pearce, 2009-09-22 15:29

Subject: Re: [PATCH 3/4] bash: teach 'git reset --patch'
Message-ID: <20090922152916.GR14660@spearce.org>
URL: https://gitlist.dev/e/20090922152916.GR14660%40spearce.org
In-Reply-To: <ccf129a01115027ee7438ac47f1bc35631a1b2bb.1253009868.git.szeder@ira.uka.de>

```
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.

```

## SZEDER Gábor, 2009-09-24 12:23

Subject: [PATCHv2] bash: teach 'git checkout' options
Message-ID: <1253794995-9093-1-git-send-email-szeder@ira.uka.de>
URL: https://gitlist.dev/e/1253794995-9093-1-git-send-email-szeder%40ira.uka.de
In-Reply-To: <20090922152846.GQ14660@spearce.org>

```
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
---
 contrib/completion/git-completion.bash |   16 +++++++++++++++-
 1 files changed, 15 insertions(+), 1 deletions(-)

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

```
