From: Jonathan Nieder <jrnieder@gmail.com>
To: "Shawn O. Pearce" <spearce@spearce.org>
Cc: Ted Pavlic <ted@tedpavlic.com>,
Thomas Nilsson <thomas.nilsson@unixangst.com>,
git@vger.kernel.org
Subject: [PATCH] bash-completion: Support running with set -u in bash 4.0
Date: Sat, 6 Mar 2010 12:16:55 -0600 [thread overview]
Message-ID: <20100306181655.GA2261@progeny.tock> (raw)
From: Thomas Nilsson <thomas.nilsson@unixangst.com>
Date: Tue, 23 Feb 2010 12:13:00 +0100
Starting with bash 4.0-beta, under "set -u" semantics, accessing
undefined local variables is now an error. Some user environments
enable this setting in the interactive shell, with unpleasant results:
knirch@traktor:~/source/external/git (master)$ set -o unset
bash: w: unbound variable
knirch@traktor:~/source/external/git$ git ^Ibash: command: unbound variable
bash: w: unbound variable
knirch@traktor:~/source/external/git$
bash: w: unbound variable
knirch@traktor:~/source/external/git$
Most of these variables should be bound to "". In contexts where the
completion functions should access an undefined variable, accessing a
default empty string (as in "${1-}" instead of "$1") is a reasonable
way to cope, as it silences the undefined variable error while still
supplying an empty string.
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
Sent by Thomas to <http://bugs.debian.org/571087> (thanks!). One
might use 'set -u' in an interactive shell while manually
single-stepping through a shell script, perhaps.
contrib/completion/git-completion.bash | 16 ++++++++--------
1 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index fe93747..d97467e 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -84,8 +84,8 @@ __git_ps1 ()
{
local g="$(__gitdir)"
if [ -n "$g" ]; then
- local r
- local b
+ local r=""
+ local b=""
if [ -f "$g/rebase-merge/interactive" ]; then
r="|REBASE-i"
b="$(cat "$g/rebase-merge/head-name")"
@@ -127,11 +127,11 @@ __git_ps1 ()
}
fi
- local w
- local i
- local s
- local u
- local c
+ local w=""
+ local i=""
+ local s=""
+ local u=""
+ local c=""
if [ "true" = "$(git rev-parse --is-inside-git-dir 2>/dev/null)" ]; then
if [ "true" = "$(git rev-parse --is-bare-repository 2>/dev/null)" ]; then
@@ -2181,7 +2181,7 @@ _git ()
c=$((++c))
done
- if [ -z "$command" ]; then
+ if [ -z "${command-}" ]; then
case "${COMP_WORDS[COMP_CWORD]}" in
--*) __gitcomp "
--paginate
--
1.7.0
next reply other threads:[~2010-03-06 21:00 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-03-06 18:16 Jonathan Nieder [this message]
2010-03-06 19:29 ` [PATCH] bash-completion: Support running with set -u in bash 4.0 Junio C Hamano
2010-03-06 20:17 ` Jonathan Nieder
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20100306181655.GA2261@progeny.tock \
--to=jrnieder@gmail.com \
--cc=git@vger.kernel.org \
--cc=spearce@spearce.org \
--cc=ted@tedpavlic.com \
--cc=thomas.nilsson@unixangst.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).