completion: consolidate silencing errors from git commands

Outputting error messages during completion is bad: they disrupt the command line, can't be deleted, and the user is forced to Ctrl-C and start over most of the time. We already silence stderr of many git commands in our Bash completion script, but there are still some in there that can spew error messages when something goes wrong. We could add the missing stderr redirections to all the remaining places, but instead let's leverage that git commands are now executed through the previously introduced __git() wrapper function, and redirect standard error to /dev/null only in that function. This way we need only one redirection to take care of errors from almost all git commands. Redirecting standard error of the __git() wrapper function thus became redundant, remove them. The exceptions, i.e. the repo-independent git executions and those in the __gitdir() function that don't go through __git() already have their standard error silenced. Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

SZEDER Gábor committed Feb 3, 2017 at 03:48 UTC e15098a314aa15b207bb08a11058855baaedbc37
1 file changed +12 -16
contrib/completion/git-completion.bash
+12 -16
@@ -66,7 +66,7 @@ __gitdir ()
66 __git ()
67 {
68 git ${__git_C_args:+"${__git_C_args[@]}"} \
69 - ${__git_dir:+--git-dir="$__git_dir"} "$@"
69 + ${__git_dir:+--git-dir="$__git_dir"} "$@" 2>/dev/null
70 }
71
72 # The following function is based on code from:
@@ -300,7 +300,7 @@ __git_ls_files_helper ()
300 else
301 # NOTE: $2 is not quoted in order to support multiple options
302 __git -C "$1" ls-files --exclude-standard $2
303 - fi 2>/dev/null
303 + fi
304 }
305
306
@@ -410,7 +410,7 @@ __git_refs ()
410 fi
411 case "$cur" in
412 refs|refs/*)
413 - __git ls-remote "$remote" "$cur*" 2>/dev/null | \
413 + __git ls-remote "$remote" "$cur*" | \
414 while read -r hash i; do
415 case "$i" in
416 *^{}) ;;
@@ -422,10 +422,10 @@ __git_refs ()
422 if [ "$list_refs_from" = remote ]; then
423 echo "HEAD"
424 __git for-each-ref --format="%(refname:short)" \
425 - "refs/remotes/$remote/" 2>/dev/null | sed -e "s#^$remote/##"
425 + "refs/remotes/$remote/" | sed -e "s#^$remote/##"
426 else
427 __git ls-remote "$remote" HEAD \
428 - "refs/tags/*" "refs/heads/*" "refs/remotes/*" 2>/dev/null |
428 + "refs/tags/*" "refs/heads/*" "refs/remotes/*" |
429 while read -r hash i; do
430 case "$i" in
431 *^{}) ;;
@@ -451,7 +451,7 @@ __git_refs2 ()
451 __git_refs_remotes ()
452 {
453 local i hash
454 - __git ls-remote "$1" 'refs/heads/*' 2>/dev/null | \
454 + __git ls-remote "$1" 'refs/heads/*' | \
455 while read -r hash i; do
456 echo "$i:refs/remotes/$1/${i#refs/heads/}"
457 done
@@ -527,7 +527,7 @@ __git_complete_revlist_file ()
527 *) pfx="$ref:$pfx" ;;
528 esac
529
530 - __gitcomp_nl "$(__git ls-tree "$ls" 2>/dev/null \
530 + __gitcomp_nl "$(__git ls-tree "$ls" \
531 | sed '/^100... blob /{
532 s,^.* ,,
533 s,$, ,
@@ -805,7 +805,7 @@ __git_compute_porcelain_commands ()
805 __git_get_config_variables ()
806 {
807 local section="$1" i IFS=$'\n'
808 - for i in $(__git config --name-only --get-regexp "^$section\..*" 2>/dev/null); do
808 + for i in $(__git config --name-only --get-regexp "^$section\..*"); do
809 echo "${i#$section.}"
810 done
811 }
@@ -823,7 +823,7 @@ __git_aliases ()
823 # __git_aliased_command requires 1 argument
824 __git_aliased_command ()
825 {
826 - local word cmdline=$(__git config --get "alias.$1" 2>/dev/null)
826 + local word cmdline=$(__git config --get "alias.$1")
827 for word in $cmdline; do
828 case "$word" in
829 \!gitk|gitk)
@@ -1841,9 +1841,7 @@ _git_send_email ()
1841 {
1842 case "$prev" in
1843 --to|--cc|--bcc|--from)
1844 - __gitcomp "
1845 - $(__git send-email --dump-aliases 2>/dev/null)
1846 - "
1844 + __gitcomp "$(__git send-email --dump-aliases)"
1845 return
1846 ;;
1847 esac
@@ -1873,9 +1871,7 @@ _git_send_email ()
1871 return
1872 ;;
1873 --to=*|--cc=*|--bcc=*|--from=*)
1876 - __gitcomp "
1877 - $(__git send-email --dump-aliases 2>/dev/null)
1878 - " "" "${cur#--*=}"
1874 + __gitcomp "$(__git send-email --dump-aliases)" "" "${cur#--*=}"
1875 return
1876 ;;
1877 --*)
@@ -1969,7 +1965,7 @@ __git_config_get_set_variables ()
1965 c=$((--c))
1966 done
1967
1972 - __git config $config_file --name-only --list 2>/dev/null
1968 + __git config $config_file --name-only --list
1969 }
1970
1971 _git_config ()