@matheusbsbs / matheus-bagliano / commits / c2dbcd206d
Fork 0

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>

Ville Skyttä committed Jun 29, 2020 at 21:59 UTC c2dbcd206d2d654c1d934501a7f03a5a0f452b92
1 file changed +9 -9
contrib/completion/git-completion.bash
+9 -9
@@ -50,7 +50,7 @@ esac
50 # variable.
51 __git_find_repo_path ()
52 {
53 - if [ -n "$__git_repo_path" ]; then
53 + if [ -n "${__git_repo_path-}" ]; then
54 # we already know where it is
55 return
56 fi
@@ -404,12 +404,12 @@ __gitcomp_builtin ()
404 # spaces must be replaced with underscore for multi-word
405 # commands, e.g. "git remote add" becomes remote_add.
406 local cmd="$1"
407 - local incl="$2"
408 - local excl="$3"
407 + local incl="${2-}"
408 + local excl="${3-}"
409
410 local var=__gitcomp_builtin_"${cmd/-/_}"
411 local options
412 - eval "options=\$$var"
412 + eval "options=\${$var-}"
413
414 if [ -z "$options" ]; then
415 # leading and trailing spaces are significant to make
@@ -801,7 +801,7 @@ __git_refs ()
801 # --remote is only compatible with --mode=refs.
802 __git_complete_refs ()
803 {
804 - local remote dwim pfx cur_="$cur" sfx=" " mode="refs"
804 + local remote= dwim= pfx= cur_="$cur" sfx=" " mode="refs"
805
806 while test $# != 0; do
807 case "$1" in
@@ -1152,7 +1152,7 @@ __git_find_on_cmdline ()
1152 while [ $c -lt $cword ]; do
1153 for word in $wordlist; do
1154 if [ "$word" = "${words[c]}" ]; then
1155 - if [ -n "$show_idx" ]; then
1155 + if [ -n "${show_idx-}" ]; then
1156 echo "$c $word"
1157 else
1158 echo "$word"
@@ -1468,7 +1468,7 @@ __git_checkout_default_dwim_mode ()
1468 {
1469 local last_option dwim_opt="--dwim"
1470
1471 - if [ "$GIT_COMPLETION_CHECKOUT_NO_GUESS" = "1" ]; then
1471 + if [ "${GIT_COMPLETION_CHECKOUT_NO_GUESS-}" = "1" ]; then
1472 dwim_opt=""
1473 fi
1474
@@ -3350,7 +3350,7 @@ __git_main ()
3350 ((c++))
3351 done
3352
3353 - if [ -z "$command" ]; then
3353 + if [ -z "${command-}" ]; then
3354 case "$prev" in
3355 --git-dir|-C|--work-tree)
3356 # these need a path argument, let's fall back to
@@ -3385,7 +3385,7 @@ __git_main ()
3385 "
3386 ;;
3387 *)
3388 - if test -n "$GIT_TESTING_PORCELAIN_COMMAND_LIST"
3388 + if test -n "${GIT_TESTING_PORCELAIN_COMMAND_LIST-}"
3389 then
3390 __gitcomp "$GIT_TESTING_PORCELAIN_COMMAND_LIST"
3391 else