Skip to content

Commit

Permalink
Ungraceful behaviour when opening magit outside of a git repo fix #162
Browse files Browse the repository at this point in the history
The error was not catchup early enough withthe new shell error
management.

It mades a ciphered error message.

Now, no vim error is thrown. It could be improved, setting the magit
file with magit properties, and display the error message in the buffer.
  • Loading branch information
jreybert committed Oct 8, 2018
1 parent 95e7501 commit 18d9fc6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
10 changes: 4 additions & 6 deletions autoload/magit/git.vim
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,11 @@ function! magit#git#is_work_tree(path)
let dir = getcwd()
try
call magit#utils#chdir(a:path)
try
let top_dir=magit#utils#strip(
\ system(g:magit_git_cmd . " rev-parse --show-toplevel")) . "/"
catch 'shell_error'
let top_dir=system(g:magit_git_cmd . " rev-parse --show-toplevel")
if ( v:shell_error != 0 )
return ''
endtry
return top_dir
endif
return magit#utils#strip(top_dir) . "/"
finally
call magit#utils#chdir(dir)
endtry
Expand Down
4 changes: 2 additions & 2 deletions plugin/magit.vim
Original file line number Diff line number Diff line change
Expand Up @@ -732,13 +732,13 @@ function! magit#show_magit(display, ...)
if ( git_dir == '' )
echohl ErrorMsg
echom "magit can not find any git repository"
echohl None
echom "make sure that current opened file or vim current directory points to a git repository"
echom "search paths:"
for path in try_paths
echom path
endfor
echohl None
throw 'magit_not_in_git_repo'
return
endif

let buffer_name=fnameescape('magit://' . git_dir)
Expand Down

0 comments on commit 18d9fc6

Please sign in to comment.