Use FugitiveWorkTree() to find the git root

Fix #1586
This commit is contained in:
Junegunn Choi
2025-03-21 17:31:10 +09:00
parent 245eaf8e50
commit 1fff637559

View File

@@ -715,6 +715,9 @@ endfunction
" ------------------------------------------------------------------
function! s:get_git_root(dir)
if empty(a:dir) && exists('*FugitiveWorkTree')
return FugitiveWorkTree()
endif
let dir = len(a:dir) ? a:dir : substitute(split(expand('%:p:h'), '[/\\]\.git\([/\\]\|$\)')[0], '^fugitive://', '', '')
let root = systemlist('git -C ' . shellescape(dir) . ' rev-parse --show-toplevel')[0]
return v:shell_error ? '' : (len(a:dir) ? fnamemodify(a:dir, ':p') : root)