Subject: Re: [PATCH v4 2/2] Use the new functions to get the current cword.

From: SZEDER Gábor <[email-masked]>
Date: Thu, 2 Dec 2010 23:36:01 +0100

Hi,

Here are my nits I mentioned yesterday.

On Wed, Dec 01, 2010 at 03:49:42PM -0500, Peter van der Does wrote:
> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
> index 0036e8b..f915e1f 100755
> --- a/contrib/completion/git-completion.bash
> +++ b/contrib/completion/git-completion.bash

> @@ -1064,9 +1073,10 @@ __git_find_on_cmdline ()
>  
>  __git_has_doubledash ()
>  {
> -	local c=1
> -	while [ $c -lt $COMP_CWORD ]; do
> -		if [ "--" = "${COMP_WORDS[c]}" ]; then
> +	local c=1, words cword

No comma, and ...

> +	_get_comp_words_by_ref words cword
> +	while [ $c -lt $cwords ]; do

... that should be $cword in the condition, without the s at the end.
These two typos caused some weird behaviors when completing long
options for commands understanding the '--' option-path separator,
e.g. git diff --<TAB<TAB>.

> @@ -1775,7 +1814,7 @@ _git_notes ()
>  	prune,*)
>  		;;
>  	*)
> -		case "${COMP_WORDS[COMP_CWORD-1]}" in
> +		case "${prev}" in

> @@ -2615,7 +2670,7 @@ _git_tag ()
>  		c=$((++c))
>  	done
>  
> -	case "${COMP_WORDS[COMP_CWORD-1]}" in
> +	case "${prev}" in

No {} are needed around prev.

> @@ -2639,15 +2694,16 @@ _git_whatchanged ()
>  
>  _git ()
>  {
> -	local i c=1 command __git_dir
> +	local i c=1 command __git_dir words cword
>  
> -	if [[ -n ${ZSH_VERSION-} ]]; then
> +	if [[ -n $ZSH_VERSION ]]; then

> @@ -2690,19 +2746,20 @@ _git ()
>  
>  _gitk ()
>  {
> -	if [[ -n ${ZSH_VERSION-} ]]; then
> +	if [[ -n $ZSH_VERSION ]]; then

> @@ -2730,7 +2787,7 @@ complete -o bashdefault -o default -o nospace -F _git git.exe 2>/dev/null \
>  	|| complete -o default -o nospace -F _git git.exe
>  fi
>  
> -if [[ -n ${ZSH_VERSION-} ]]; then
> +if [[ -n $ZSH_VERSION ]]; then

These three changes have nothing to do with bash4 issues, and they
break in 'set -u' environments, because $ZSH_VERSION is, of course,
undefined in bash.

Best,
Gábor