git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Sebastian Schuberth <sschuberth@gmail.com>
Date
Feb 4, 2016, 10:34 UTC
Message-ID
<56B32953.2010908@gmail.com>
This avoids output like
    warning: ignoring broken ref refs/remotes/origin/HEAD
while completing branch names.
Signed-off-by: Sebastian Schuberth <sschuberth@gmail.com>
---
 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
Next: Jeff King
Message 1 of 24 in “git-completion.bash: always swallow error output of for-each-ref”
  1. git-completion.bash: always swallow error output of for-each-refSebastian Schuberth, Feb 4, 2016
  2. Jeff KingFeb 4, 2016
  3. Johannes SchindelinFeb 4, 2016
  4. Jeff KingFeb 4, 2016
  5. Junio C HamanoFeb 4, 2016
  6. SZEDER GáborFeb 12, 2016
  7. Jeff KingFeb 12, 2016
  8. SZEDER GáborFeb 13, 2016
  9. Johannes SchindelinFeb 13, 2016
  10. SZEDER GáborFeb 13, 2016
  11. Johannes SchindelinFeb 13, 2016
  12. Jeff KingFeb 13, 2016
  13. SZEDER GáborFeb 12, 2016
  14. Jeff KingFeb 12, 2016
  15. Duy NguyenFeb 13, 2016
  16. Junio C HamanoFeb 12, 2016
  17. Jeff KingFeb 12, 2016
  18. Junio C HamanoFeb 12, 2016
  19. SZEDER GáborFeb 12, 2016
  20. Jeff KingFeb 12, 2016
  21. Junio C HamanoFeb 12, 2016
  22. Junio C HamanoFeb 23, 2016
  23. Sebastian SchuberthFeb 24, 2016
  24. Sebastian SchuberthFeb 12, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.