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

[PATCH] [kernel] completion: silence "fatal: Not a git repository" error

From
John Szakmeister <john@szakmeister.net>
Date
Oct 14, 2014, 10:49 UTC
Message-ID
<1413283785-505-1-git-send-email-john@szakmeister.net>

It is possible that a user is trying to run a git command and fail to realize that they are not in a git repository or working tree. When trying to complete an operation, __git_refs would fall to a degenerate case and attempt to use "git for-each-ref", which would emit the error.

Let's fix this by shunting the error message coming from "git for-each-ref".
Signed-off-by: John Szakmeister <john@szakmeister.net>
---
 contrib/completion/git-completion.bash | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 5ea5b82..31b4739 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -388,7 +388,8 @@ __git_refs ()
 		;;
 	*)
 		echo "HEAD"
-		git for-each-ref --format="%(refname:short)" -- "refs/remotes/$dir/" | sed -e "s#^$dir/##"
+		git for-each-ref --format="%(refname:short)" -- \
+			"refs/remotes/$dir/" 2>/dev/null | sed -e "s#^$dir/##"
 		;;
 	esac
 }
-- 
2.0.1
Next: John Szakmeister
Message 1 of 5 in “[kernel] completion: silence "fatal: Not a git repository" error”
  1. [kernel] completion: silence "fatal: Not a git repository" errorJohn Szakmeister, Oct 14, 2014
  2. John SzakmeisterOct 14, 2014
  3. Junio C HamanoOct 14, 2014
  4. John SzakmeisterOct 14, 2014
  5. Junio C HamanoOct 14, 2014

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.