Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

[PATCH] vcs-info: Avoid error messages in bare git repositories

A user reported error messages in bare repositories. I tracked this down to:

    gitbase=$( ${vcs_comm[cmd]} rev-parse --show-toplevel 2> /dev/null )
    fatal: this operation must be run in a work tree

This fixes the issue by avoiding the call in bare repositories.

I do wonder though, why this happens. Git didn't stop printing the error
to stderr. Shouldn't the redirection to /dev/null inside the command
substitution take care of this?

 Functions/VCS_Info/Backends/VCS_INFO_get_data_git | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git
index 79429c8e0..932a13423 100644
--- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git
+++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git
@@ -138,10 +138,10 @@ VCS_INFO_git_handle_patches () {
 VCS_INFO_git_getbranch ${gitdir}
-gitbase=$( ${vcs_comm[cmd]} rev-parse --show-toplevel 2> /dev/null )
-if [[ -z ${gitbase} ]]; then
-    # Bare repository
+if [[ "$(${vcs_comm[cmd]} rev-parse --is-bare-repository 2> /dev/null)" == 'true' ]]; then
+    gitbase=$( ${vcs_comm[cmd]} rev-parse --show-toplevel 2> /dev/null )
 if zstyle -t ":vcs_info:${vcs}:${usercontext}:${rrn}" get-revision ; then

Messages sorted by: Reverse Date, Date, Thread, Author