jreybert / vimagit

Ease your git workflow within Vim
1.31k stars 49 forks source link

Ungraceful behaviour when opening magit outside of a git repo #162

Closed ashishnargundkar closed 6 years ago

ashishnargundkar commented 6 years ago

Short description of the problem

With the code in vimagit's master branch, I get the following error message:

magit can not find any git repository
make sure that current opened file or vim current directory points to a git repository
search paths:
.
/Users/apnargundkar
Error detected while processing function magit#show_magit:
line   27:
E605: Exception not caught: magit_not_in_git_repo

I'm not quite familiar with the codebase yet, but here are my two cents. Changing https://github.com/jreybert/vimagit/blob/8c7c01298d2d2793f9aa81d370f0de88bf9c4625/plugin/magit.vim#L712 to a simple return not only silences the uncaught exception complaint (E605) but also keeps the upper part of the helpful error message which originates from magit.

==========================================================================

For code in next, the behaviour is slightly different. It gives a poorer error message and also opens a completely blank magit buffer (doesn't happen with master). The error message is:

Error detected while processing function magit#show_magit[61]..magit#git#set_top_dir[3]..magit#utils#chdir:
line    8:
E344: Can't find directory "fatal: Not a git repository (or any of the parent directories): .git/" in cdpath
E472: Command failed

Steps to reproduce

Open vim from a directory which is not part of a git repo and then open vimagit (<leader>M).

Environment

Thanks for the awesome plugin!

jreybert commented 6 years ago

Thanks for the advice, it is actually a good one. I just discover you ticket, I don't know how I missed it...