Provide FugitiveGitDir()

This commit is contained in:
Tim Pope 2018-07-28 20:56:30 -04:00
parent f8fb5eafab
commit 248764f2c3

View File

@ -16,6 +16,18 @@ function! s:shellslash(path) abort
endif endif
endfunction endfunction
function! FugitiveGitDir(...) abort
if !a:0 || a:1 ==# -1
return get(b:, 'git_dir', '')
elseif type(a:1) == type(0)
return getbufvar(a:1, 'git_dir')
elseif type(a:1) == type('')
return substitute(s:shellslash(a:1), '/$', '', '')
else
return ''
endif
endfunction
function! FugitiveIsGitDir(path) abort function! FugitiveIsGitDir(path) abort
let path = substitute(a:path, '[\/]$', '', '') . '/' let path = substitute(a:path, '[\/]$', '', '') . '/'
return getfsize(path.'HEAD') > 10 && ( return getfsize(path.'HEAD') > 10 && (
@ -140,7 +152,7 @@ function! FugitiveStatusline(...) abort
endfunction endfunction
function! FugitiveHead(...) abort function! FugitiveHead(...) abort
let dir = a:0 > 1 ? a:2 : get(b:, 'git_dir', '') let dir = FugitiveGitDir(a:0 > 1 ? a:2 : -1)
if empty(dir) if empty(dir)
return '' return ''
endif endif
@ -159,14 +171,18 @@ function! FugitiveReal(...) abort
endfunction endfunction
function! FugitivePath(...) abort function! FugitivePath(...) abort
return call(a:0 > 1 ? 'fugitive#Path' : 'FugitiveReal', a:000) if a:0 > 1
return fugitive#Path(a:1, a:2, FugitiveGitDir(a:0 > 2 ? a:3 : -1))
else
return FugitiveReal(a:0 ? a:1 : @%)
endif
endfunction endfunction
function! FugitiveGenerate(...) abort function! FugitiveGenerate(...) abort
if a:0 && s:shellslash(a:0) =~# '^\%(\a\a\+:\)\=\%(a:\)\=/\|^[~$]' if a:0 && s:shellslash(a:0) =~# '^\%(\a\a\+:\)\=\%(a:\)\=/\|^[~$]'
return a:1 return a:1
endif endif
return fugitive#repo(a:0 > 1 ? a:2 : get(b:, 'git_dir', '')).translate(a:0 ? a:1 : '', 1) return fugitive#repo(FugitiveGitDir(a:0 > 1 ? a:2 : -1)).translate(a:0 ? a:1 : '', 1)
endfunction endfunction
function! FugitiveParse(...) abort function! FugitiveParse(...) abort
@ -179,12 +195,12 @@ function! FugitiveParse(...) abort
throw v:errmsg throw v:errmsg
endfunction endfunction
function! FugitiveConfig(...) abort function! FugitiveConfig(key, ...) abort
return call('fugitive#Config', a:000) return fugitive#Config(a:key, FugitiveGitDir(a:0 ? a:1 : -1))
endfunction endfunction
function! FugitiveRemoteUrl(...) abort function! FugitiveRemoteUrl(...) abort
return call('fugitive#RemoteUrl', a:000) return fugitive#RemoteUrl(a:0 ? a:1 : '', FugitiveGitDir(a:0 > 1 ? a:2 : -1))
endfunction endfunction
augroup fugitive augroup fugitive