agnoster / agnoster-zsh-theme

A ZSH theme designed to disclose information contextually, with a powerline aesthetic
4.02k stars 590 forks source link

inside .git folders Agnoster produces "fatal: this operation must be run in a work tree" #162

Open rzarajczyk opened 2 years ago

rzarajczyk commented 2 years ago

Hi, When I'm inside .git directory (this special hidden dir in any git repo which store git-related data) the Agnoster produces

fatal: this operation must be run in a work tree

every time the command line is show. It is because Agnoster's git integration try to execute some git commands, like git status, in this repo - but it ends with this message produced to stderr.

guntern commented 1 month ago

I just ran into the same issue. Surprisingly I never had seen it before. Did you find a solution? Is this really related to the agnoster-theme or is something else causing this, maybe?

rzarajczyk commented 1 month ago

Oh wow, this issue is almost 3 years old :-) Since then I've stopped using Agnoster, and the details have vanished from my memory... however, as far as I remember, I wasn't able to fix it using the original Agnoster theme, but I made a fork of the code and fixed it just for me.

The fork is here: https://github.com/rzarajczyk/agnoster-zsh-theme The link to the changes: https://github.com/agnoster/agnoster-zsh-theme/compare/master...rzarajczyk:agnoster-zsh-theme:master

It should be either the line 96 of the original file

-    test -n "$(git status --porcelain --ignore-submodules)"
+    test -n "$(git status --porcelain --ignore-submodules 2> /dev/null)"

Or 155

-  vcs_info
+  vcs_info 2> /dev/null

Or both, I don't remember :-)

guntern commented 1 month ago

Thanks. Maybe it is time to replace agnoster then as well.

guntern commented 1 month ago

Just for documentation purposes: I dug around and it appears that the issue is not tied to agnoster, but more to zsh itself: https://github.com/spaceship-prompt/spaceship-prompt/issues/821, which in the end leads to a similar solution as you proposed: https://github.com/zsh-users/zsh/commit/bacad965238158b9ae6ff438ba923725ec128020 Testing in bash worked without the error, which indicates that it is related to zsh. I am currently using zsh 5.8. But also in a test-container with zsh 5.9 I have the same issue. Let's see where this leads me.