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

Subsystems: the rest

DORMANTno replies

2 messages, 1 author, 2016-06-15 · open the first message on its own page

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

From: John Szakmeister <hidden>
Date: 2016-06-15 23:02:42

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 <redacted>
---
 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

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

From: John Szakmeister <hidden>
Date: 2016-06-15 23:02:42

On Tue, Oct 14, 2014 at 6:49 AM, John Szakmeister [off-list ref] wrote:
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 <redacted>
---
Sorry for the "[kernel]" in the subject.  I must have forgotten to
remove that off of my format-patch invocation.  If you need me to
resubmit without it, I can do that.

Thanks!

-John
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help