Subject: [PATCH] git-completion.bash: always swallow error output of for-each-ref

From: Sebastian Schuberth <[email-masked]>
Date: Thu, 4 Feb 2016 11:34:59 +0100

This avoids output like

    warning: ignoring broken ref refs/remotes/origin/HEAD

while completing branch names.

Signed-off-by: Sebastian Schuberth <[email-masked]>
---
 contrib/completion/git-completion.bash | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 15ebba5..7c0549d 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -317,7 +317,7 @@ __git_heads ()
 	local dir="$(__gitdir)"
 	if [ -d "$dir" ]; then
 		git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
-			refs/heads
+			refs/heads 2>/dev/null
 		return
 	fi
 }
@@ -327,7 +327,7 @@ __git_tags ()
 	local dir="$(__gitdir)"
 	if [ -d "$dir" ]; then
 		git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
-			refs/tags
+			refs/tags 2>/dev/null
 		return
 	fi
 }
@@ -355,14 +355,14 @@ __git_refs ()
 			;;
 		esac
 		git --git-dir="$dir" for-each-ref --format="%($format)" \
-			$refs
+			$refs 2>/dev/null
 		if [ -n "$track" ]; then
 			# employ the heuristic used by git checkout
 			# Try to find a remote branch that matches the completion word
 			# but only output if the branch name is unique
 			local ref entry
 			git --git-dir="$dir" for-each-ref --shell --format="ref=%(refname:short)" \
-				"refs/remotes/" | \
+				"refs/remotes/" 2>/dev/null | \
 			while read -r entry; do
 				eval "$entry"
 				ref="${ref#*/}"
@@ -1835,7 +1835,7 @@ _git_config ()
 		remote="${remote%.push}"
 		__gitcomp_nl "$(git --git-dir="$(__gitdir)" \
 			for-each-ref --format='%(refname):%(refname)' \
-			refs/heads)"
+			refs/heads 2>/dev/null)"
 		return
 		;;
 	pull.twohead|pull.octopus)
-- 
2.7.0.windows.1