completion: nounset mode fixes

Accessing unset variables results an errors when the shell is in
nounset/-u mode. This fixes the cases I've come across while using git
completion in a shell running in that mode for a while. It's hard to
tell if this is the complete set, but at least it improves things.

Signed-off-by: Ville Skyttä <ville.skytta@iki.fi>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Ville Skyttä
2020-06-29 21:59:45 +03:00
committed by Junio C Hamano
parent a08a83db2b
commit c2dbcd206d

View File

@ -50,7 +50,7 @@ esac
# variable. # variable.
__git_find_repo_path () __git_find_repo_path ()
{ {
if [ -n "$__git_repo_path" ]; then if [ -n "${__git_repo_path-}" ]; then
# we already know where it is # we already know where it is
return return
fi fi
@ -404,12 +404,12 @@ __gitcomp_builtin ()
# spaces must be replaced with underscore for multi-word # spaces must be replaced with underscore for multi-word
# commands, e.g. "git remote add" becomes remote_add. # commands, e.g. "git remote add" becomes remote_add.
local cmd="$1" local cmd="$1"
local incl="$2" local incl="${2-}"
local excl="$3" local excl="${3-}"
local var=__gitcomp_builtin_"${cmd/-/_}" local var=__gitcomp_builtin_"${cmd/-/_}"
local options local options
eval "options=\$$var" eval "options=\${$var-}"
if [ -z "$options" ]; then if [ -z "$options" ]; then
# leading and trailing spaces are significant to make # leading and trailing spaces are significant to make
@ -801,7 +801,7 @@ __git_refs ()
# --remote is only compatible with --mode=refs. # --remote is only compatible with --mode=refs.
__git_complete_refs () __git_complete_refs ()
{ {
local remote dwim pfx cur_="$cur" sfx=" " mode="refs" local remote= dwim= pfx= cur_="$cur" sfx=" " mode="refs"
while test $# != 0; do while test $# != 0; do
case "$1" in case "$1" in
@ -1152,7 +1152,7 @@ __git_find_on_cmdline ()
while [ $c -lt $cword ]; do while [ $c -lt $cword ]; do
for word in $wordlist; do for word in $wordlist; do
if [ "$word" = "${words[c]}" ]; then if [ "$word" = "${words[c]}" ]; then
if [ -n "$show_idx" ]; then if [ -n "${show_idx-}" ]; then
echo "$c $word" echo "$c $word"
else else
echo "$word" echo "$word"
@ -1468,7 +1468,7 @@ __git_checkout_default_dwim_mode ()
{ {
local last_option dwim_opt="--dwim" local last_option dwim_opt="--dwim"
if [ "$GIT_COMPLETION_CHECKOUT_NO_GUESS" = "1" ]; then if [ "${GIT_COMPLETION_CHECKOUT_NO_GUESS-}" = "1" ]; then
dwim_opt="" dwim_opt=""
fi fi
@ -3350,7 +3350,7 @@ __git_main ()
((c++)) ((c++))
done done
if [ -z "$command" ]; then if [ -z "${command-}" ]; then
case "$prev" in case "$prev" in
--git-dir|-C|--work-tree) --git-dir|-C|--work-tree)
# these need a path argument, let's fall back to # these need a path argument, let's fall back to
@ -3385,7 +3385,7 @@ __git_main ()
" "
;; ;;
*) *)
if test -n "$GIT_TESTING_PORCELAIN_COMMAND_LIST" if test -n "${GIT_TESTING_PORCELAIN_COMMAND_LIST-}"
then then
__gitcomp "$GIT_TESTING_PORCELAIN_COMMAND_LIST" __gitcomp "$GIT_TESTING_PORCELAIN_COMMAND_LIST"
else else