# [PATCH 1/3] Purest update to bash completions to prevent unbounded variable errors.

6 messages from 2009-01-13 to 2009-01-14. Participants: Ted Pavlic, Shawn O. Pearce, Junio C Hamano.
Thread: https://gitlist.dev/t/17147

## Ted Pavlic, 2009-01-13 16:08

Subject: [PATCH 1/3] Purest update to bash completions to prevent unbounded variable errors.
Message-ID: <496CBC98.7090101@tedpavlic.com>
URL: https://gitlist.dev/e/496CBC98.7090101%40tedpavlic.com

```

First in a series of patches that make bash completions more robust to
different interactive shell configurations and editors.


Signed-off-by: Ted Pavlic <ted@tedpavlic.com>
---
  contrib/completion/git-completion.bash |   18 +++++++++---------
  1 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/contrib/completion/git-completion.bash 
b/contrib/completion/git-completion.bash
index 7b074d7..5d1515c 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -52,7 +52,7 @@ esac

  __gitdir ()
  {
-	if [ -z "$1" ]; then
+	if [ -z "${1-}" ]; then
  		if [ -n "$__git_dir" ]; then
  			echo "$__git_dir"
  		elif [ -d .git ]; then
@@ -111,7 +111,7 @@ __git_ps1 ()
  			fi
  		fi

-		if [ -n "$1" ]; then
+		if [ -n "${1-}" ]; then
  			printf "$1" "${b##refs/heads/}$r"
  		else
  			printf " (%s)" "${b##refs/heads/}$r"
@@ -143,8 +143,8 @@ __gitcomp ()
  		;;
  	*)
  		local IFS=$'\n'
-		COMPREPLY=($(compgen -P "$2" \
-			-W "$(__gitcomp_1 "$1" "$4")" \
+		COMPREPLY=($(compgen -P "${2-}" \
+			-W "$(__gitcomp_1 "${1-}" "${4-}")" \
  			-- "$cur"))
  		;;
  	esac
@@ -152,13 +152,13 @@ __gitcomp ()

  __git_heads ()
  {
-	local cmd i is_hash=y dir="$(__gitdir "$1")"
+	local cmd i is_hash=y dir="$(__gitdir "${1-}")"
  	if [ -d "$dir" ]; then
  		git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
  			refs/heads
  		return
  	fi
-	for i in $(git ls-remote "$1" 2>/dev/null); do
+	for i in $(git ls-remote "${1-}" 2>/dev/null); do
  		case "$is_hash,$i" in
  		y,*) is_hash=n ;;
  		n,*^{}) is_hash=y ;;
@@ -170,13 +170,13 @@ __git_heads ()

  __git_tags ()
  {
-	local cmd i is_hash=y dir="$(__gitdir "$1")"
+	local cmd i is_hash=y dir="$(__gitdir "${1-}")"
  	if [ -d "$dir" ]; then
  		git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
  			refs/tags
  		return
  	fi
-	for i in $(git ls-remote "$1" 2>/dev/null); do
+	for i in $(git ls-remote "${1-}" 2>/dev/null); do
  		case "$is_hash,$i" in
  		y,*) is_hash=n ;;
  		n,*^{}) is_hash=y ;;
@@ -188,7 +188,7 @@ __git_tags ()

  __git_refs ()
  {
-	local i is_hash=y dir="$(__gitdir "$1")"
+	local i is_hash=y dir="$(__gitdir "${1-}")"
  	local cur="${COMP_WORDS[COMP_CWORD]}" format refs
  	if [ -d "$dir" ]; then
  		case "$cur" in
-- 
1.6.1.87.g15624

```

## Shawn O. Pearce, 2009-01-13 16:34

Subject: Re: [PATCH 1/3] Purest update to bash completions to prevent unbounded variable errors.
Message-ID: <20090113163421.GQ10179@spearce.org>
URL: https://gitlist.dev/e/20090113163421.GQ10179%40spearce.org
In-Reply-To: <496CBC98.7090101@tedpavlic.com>

```
Ted Pavlic <ted@tedpavlic.com> wrote:
>
> First in a series of patches that make bash completions more robust to
> different interactive shell configurations and editors.
>
>
> Signed-off-by: Ted Pavlic <ted@tedpavlic.com>

Your commit message leaves a lot to be desired.  I would instead
have written something like this:

  bash-completion: Support running when set -u is enabled

  Under set -u semenatics it is an error to access undefined
  variables.  Some user environments may enable this in the
  interactive shell.

  In any context where the completion functions access an undefined
  variable, accessing a default empty string (aka "${1-}" instead of
  "$1") is a reasonable way to code the function, as it silences
  the undefined variable error while still supplying an empty string.

Acked-by: Shawn O. Pearce <spearce@spearce.org>

> ---
>  contrib/completion/git-completion.bash |   18 +++++++++---------
>  1 files changed, 9 insertions(+), 9 deletions(-)

-- 
Shawn.

```

## Ted Pavlic, 2009-01-13 16:40

Subject: Re: [PATCH 1/3] Purest update to bash completions to prevent unbounded variable errors.
Message-ID: <496CC3E7.8060805@tedpavlic.com>
URL: https://gitlist.dev/e/496CC3E7.8060805%40tedpavlic.com
In-Reply-To: <20090113163421.GQ10179@spearce.org>

```
> Your commit message leaves a lot to be desired.  I would instead
> have written something like this:

I agree completely. Sorry about that. stg fired off vim to edit the 
commit message, and I just wasn't thinking.

Would you like me to modify the commit message and resubmit?

--Ted

-- 
Ted Pavlic <ted@tedpavlic.com>

   Please visit my ALS association page:
         http://web.alsa.org/goto/tedpavlic
   My family appreciates your support in the fight to defeat ALS.

```

## Shawn O. Pearce, 2009-01-13 16:46

Subject: Re: [PATCH 1/3] Purest update to bash completions to prevent unbounded variable errors.
Message-ID: <20090113164624.GT10179@spearce.org>
URL: https://gitlist.dev/e/20090113164624.GT10179%40spearce.org
In-Reply-To: <496CC3E7.8060805@tedpavlic.com>

```
Ted Pavlic <ted@tedpavlic.com> wrote:
>> Your commit message leaves a lot to be desired.  I would instead
>> have written something like this:
>
> I agree completely. Sorry about that. stg fired off vim to edit the  
> commit message, and I just wasn't thinking.
>
> Would you like me to modify the commit message and resubmit?

You probably should, to be nice to Junio.  Its far easier for the
maintainer to save off well formatted messages to an mbox and run
"git am" than it is to stitch it together from different emails
and/or hand edit messages to make them work.

-- 
Shawn.

```

## Junio C Hamano, 2009-01-13 19:43

Subject: Re: [PATCH 1/3] Purest update to bash completions to prevent unbounded variable errors.
Message-ID: <7vvdsj6lfq.fsf@gitster.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vvdsj6lfq.fsf%40gitster.siamese.dyndns.org
In-Reply-To: <496CC3E7.8060805@tedpavlic.com>

```
Ted Pavlic <ted@tedpavlic.com> writes:

>> Your commit message leaves a lot to be desired.  I would instead
>> have written something like this:
>
> I agree completely. Sorry about that. stg fired off vim to edit the
> commit message, and I just wasn't thinking.
>
> Would you like me to modify the commit message and resubmit?

Luckily or unluckily, you need to do that anyway, as your patches are
whitespace damaged.

Please don't send "format=flowed".

```

## Ted Pavlic, 2009-01-14 20:08

Subject: Re: [PATCH 1/3] Purest update to bash completions to prevent unbounded variable errors.
Message-ID: <496E4646.5070809@tedpavlic.com>
URL: https://gitlist.dev/e/496E4646.5070809%40tedpavlic.com
In-Reply-To: <7vvdsj6lfq.fsf@gitster.siamese.dyndns.org>

```
>> Would you like me to modify the commit message and resubmit?
>
> Luckily or unluckily, you need to do that anyway, as your patches are
> whitespace damaged.
>
> Please don't send "format=flowed".

Ok. Resubmitted using 'git send-email'. I think the submissions look 
much better now.<?>

--Ted


-- 
Ted Pavlic <ted@tedpavlic.com>

   Please visit my ALS association page:
         http://web.alsa.org/goto/tedpavlic
   My family appreciates your support in the fight to defeat ALS.

```
