zsh-workers
 help / color / Atom feed
* [PATCH] vcs-info: Avoid error messages in bare git repositories
@ 2020-07-12 14:12 Frank Terbeck
  2020-07-12 20:53 ` Frank Terbeck
  0 siblings, 1 reply; 2+ messages in thread
From: Frank Terbeck @ 2020-07-12 14:12 UTC (permalink / raw)
  To: zsh-workers

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 () {
 
 gitdir=${vcs_comm[gitdir]}
 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=${gitdir:P}
+else
+    gitbase=$( ${vcs_comm[cmd]} rev-parse --show-toplevel 2> /dev/null )
 fi
 rrn=${gitbase:t}
 if zstyle -t ":vcs_info:${vcs}:${usercontext}:${rrn}" get-revision ; then
-- 
2.27.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] vcs-info: Avoid error messages in bare git repositories
  2020-07-12 14:12 [PATCH] vcs-info: Avoid error messages in bare git repositories Frank Terbeck
@ 2020-07-12 20:53 ` Frank Terbeck
  0 siblings, 0 replies; 2+ messages in thread
From: Frank Terbeck @ 2020-07-12 20:53 UTC (permalink / raw)
  To: zsh-workers

I wrote:
> 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
[...]
> 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?

I talked to Daniel  about this off-list. As it turns out,  I was using a
vendor package, and didn't bother to check the current code. So much for
being thorough. Thanks to Daniel for the nudge in the right direction!

Disregard the patch.


Regards, Frank

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-12 14:12 [PATCH] vcs-info: Avoid error messages in bare git repositories Frank Terbeck
2020-07-12 20:53 ` Frank Terbeck

zsh-workers

Archives are clonable: git clone --mirror http://inbox.vuxu.org/zsh-workers

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://inbox.vuxu.org/vuxu.archive.zsh.workers


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git