Skip to content

Commit e15098a

Browse files
szedergitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1cd23e9 commit e15098a

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

contrib/completion/git-completion.bash

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ __gitdir ()
6666
__git ()
6767
{
6868
git ${__git_C_args:+"${__git_C_args[@]}"} \
69-
${__git_dir:+--git-dir="$__git_dir"} "$@"
69+
${__git_dir:+--git-dir="$__git_dir"} "$@" 2>/dev/null
7070
}
7171

7272
# The following function is based on code from:
@@ -300,7 +300,7 @@ __git_ls_files_helper ()
300300
else
301301
# NOTE: $2 is not quoted in order to support multiple options
302302
__git -C "$1" ls-files --exclude-standard $2
303-
fi 2>/dev/null
303+
fi
304304
}
305305

306306

@@ -410,7 +410,7 @@ __git_refs ()
410410
fi
411411
case "$cur" in
412412
refs|refs/*)
413-
__git ls-remote "$remote" "$cur*" 2>/dev/null | \
413+
__git ls-remote "$remote" "$cur*" | \
414414
while read -r hash i; do
415415
case "$i" in
416416
*^{}) ;;
@@ -422,10 +422,10 @@ __git_refs ()
422422
if [ "$list_refs_from" = remote ]; then
423423
echo "HEAD"
424424
__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/##"
426426
else
427427
__git ls-remote "$remote" HEAD \
428-
"refs/tags/*" "refs/heads/*" "refs/remotes/*" 2>/dev/null |
428+
"refs/tags/*" "refs/heads/*" "refs/remotes/*" |
429429
while read -r hash i; do
430430
case "$i" in
431431
*^{}) ;;
@@ -451,7 +451,7 @@ __git_refs2 ()
451451
__git_refs_remotes ()
452452
{
453453
local i hash
454-
__git ls-remote "$1" 'refs/heads/*' 2>/dev/null | \
454+
__git ls-remote "$1" 'refs/heads/*' | \
455455
while read -r hash i; do
456456
echo "$i:refs/remotes/$1/${i#refs/heads/}"
457457
done
@@ -527,7 +527,7 @@ __git_complete_revlist_file ()
527527
*) pfx="$ref:$pfx" ;;
528528
esac
529529

530-
__gitcomp_nl "$(__git ls-tree "$ls" 2>/dev/null \
530+
__gitcomp_nl "$(__git ls-tree "$ls" \
531531
| sed '/^100... blob /{
532532
s,^.* ,,
533533
s,$, ,
@@ -805,7 +805,7 @@ __git_compute_porcelain_commands ()
805805
__git_get_config_variables ()
806806
{
807807
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
809809
echo "${i#$section.}"
810810
done
811811
}
@@ -823,7 +823,7 @@ __git_aliases ()
823823
# __git_aliased_command requires 1 argument
824824
__git_aliased_command ()
825825
{
826-
local word cmdline=$(__git config --get "alias.$1" 2>/dev/null)
826+
local word cmdline=$(__git config --get "alias.$1")
827827
for word in $cmdline; do
828828
case "$word" in
829829
\!gitk|gitk)
@@ -1841,9 +1841,7 @@ _git_send_email ()
18411841
{
18421842
case "$prev" in
18431843
--to|--cc|--bcc|--from)
1844-
__gitcomp "
1845-
$(__git send-email --dump-aliases 2>/dev/null)
1846-
"
1844+
__gitcomp "$(__git send-email --dump-aliases)"
18471845
return
18481846
;;
18491847
esac
@@ -1873,9 +1871,7 @@ _git_send_email ()
18731871
return
18741872
;;
18751873
--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#--*=}"
18791875
return
18801876
;;
18811877
--*)
@@ -1969,7 +1965,7 @@ __git_config_get_set_variables ()
19691965
c=$((--c))
19701966
done
19711967

1972-
__git config $config_file --name-only --list 2>/dev/null
1968+
__git config $config_file --name-only --list
19731969
}
19741970

19751971
_git_config ()

0 commit comments

Comments
 (0)