Skip to content

Commit 8f7ff5b

Browse files
jszakmeistergitster
authored andcommitted
completion: silence "fatal: Not a git repository" error
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. Hide this error message coming from "git for-each-ref". Signed-off-by: John Szakmeister <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 670a3c1 commit 8f7ff5b

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

contrib/completion/git-completion.bash

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,8 @@ __git_refs ()
388388
;;
389389
*)
390390
echo "HEAD"
391-
git for-each-ref --format="%(refname:short)" -- "refs/remotes/$dir/" | sed -e "s#^$dir/##"
391+
git for-each-ref --format="%(refname:short)" -- \
392+
"refs/remotes/$dir/" 2>/dev/null | sed -e "s#^$dir/##"
392393
;;
393394
esac
394395
}

0 commit comments

Comments
 (0)